intel_display.c 380 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797
  1. /*
  2. * Copyright © 2006-2007 Intel Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  21. * DEALINGS IN THE SOFTWARE.
  22. *
  23. * Authors:
  24. * Eric Anholt <eric@anholt.net>
  25. */
  26. #include <linux/dmi.h>
  27. #include <linux/module.h>
  28. #include <linux/input.h>
  29. #include <linux/i2c.h>
  30. #include <linux/kernel.h>
  31. #include <linux/slab.h>
  32. #include <linux/vgaarb.h>
  33. #include <drm/drm_edid.h>
  34. #include <drm/drmP.h>
  35. #include "intel_drv.h"
  36. #include <drm/i915_drm.h>
  37. #include "i915_drv.h"
  38. #include "i915_trace.h"
  39. #include <drm/drm_dp_helper.h>
  40. #include <drm/drm_crtc_helper.h>
  41. #include <drm/drm_plane_helper.h>
  42. #include <drm/drm_rect.h>
  43. #include <linux/dma_remapping.h>
  44. /* Primary plane formats supported by all gen */
  45. #define COMMON_PRIMARY_FORMATS \
  46. DRM_FORMAT_C8, \
  47. DRM_FORMAT_RGB565, \
  48. DRM_FORMAT_XRGB8888, \
  49. DRM_FORMAT_ARGB8888
  50. /* Primary plane formats for gen <= 3 */
  51. static const uint32_t intel_primary_formats_gen2[] = {
  52. COMMON_PRIMARY_FORMATS,
  53. DRM_FORMAT_XRGB1555,
  54. DRM_FORMAT_ARGB1555,
  55. };
  56. /* Primary plane formats for gen >= 4 */
  57. static const uint32_t intel_primary_formats_gen4[] = {
  58. COMMON_PRIMARY_FORMATS, \
  59. DRM_FORMAT_XBGR8888,
  60. DRM_FORMAT_ABGR8888,
  61. DRM_FORMAT_XRGB2101010,
  62. DRM_FORMAT_ARGB2101010,
  63. DRM_FORMAT_XBGR2101010,
  64. DRM_FORMAT_ABGR2101010,
  65. };
  66. /* Cursor formats */
  67. static const uint32_t intel_cursor_formats[] = {
  68. DRM_FORMAT_ARGB8888,
  69. };
  70. #define DIV_ROUND_CLOSEST_ULL(ll, d) \
  71. ({ unsigned long long _tmp = (ll)+(d)/2; do_div(_tmp, d); _tmp; })
  72. static void intel_increase_pllclock(struct drm_device *dev,
  73. enum pipe pipe);
  74. static void intel_crtc_update_cursor(struct drm_crtc *crtc, bool on);
  75. static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
  76. struct intel_crtc_config *pipe_config);
  77. static void ironlake_pch_clock_get(struct intel_crtc *crtc,
  78. struct intel_crtc_config *pipe_config);
  79. static int intel_set_mode(struct drm_crtc *crtc, struct drm_display_mode *mode,
  80. int x, int y, struct drm_framebuffer *old_fb);
  81. static int intel_framebuffer_init(struct drm_device *dev,
  82. struct intel_framebuffer *ifb,
  83. struct drm_mode_fb_cmd2 *mode_cmd,
  84. struct drm_i915_gem_object *obj);
  85. static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc);
  86. static void intel_set_pipe_timings(struct intel_crtc *intel_crtc);
  87. static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc,
  88. struct intel_link_m_n *m_n,
  89. struct intel_link_m_n *m2_n2);
  90. static void ironlake_set_pipeconf(struct drm_crtc *crtc);
  91. static void haswell_set_pipeconf(struct drm_crtc *crtc);
  92. static void intel_set_pipe_csc(struct drm_crtc *crtc);
  93. static void vlv_prepare_pll(struct intel_crtc *crtc);
  94. static void chv_prepare_pll(struct intel_crtc *crtc);
  95. static struct intel_encoder *intel_find_encoder(struct intel_connector *connector, int pipe)
  96. {
  97. if (!connector->mst_port)
  98. return connector->encoder;
  99. else
  100. return &connector->mst_port->mst_encoders[pipe]->base;
  101. }
  102. typedef struct {
  103. int min, max;
  104. } intel_range_t;
  105. typedef struct {
  106. int dot_limit;
  107. int p2_slow, p2_fast;
  108. } intel_p2_t;
  109. typedef struct intel_limit intel_limit_t;
  110. struct intel_limit {
  111. intel_range_t dot, vco, n, m, m1, m2, p, p1;
  112. intel_p2_t p2;
  113. };
  114. int
  115. intel_pch_rawclk(struct drm_device *dev)
  116. {
  117. struct drm_i915_private *dev_priv = dev->dev_private;
  118. WARN_ON(!HAS_PCH_SPLIT(dev));
  119. return I915_READ(PCH_RAWCLK_FREQ) & RAWCLK_FREQ_MASK;
  120. }
  121. static inline u32 /* units of 100MHz */
  122. intel_fdi_link_freq(struct drm_device *dev)
  123. {
  124. if (IS_GEN5(dev)) {
  125. struct drm_i915_private *dev_priv = dev->dev_private;
  126. return (I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK) + 2;
  127. } else
  128. return 27;
  129. }
  130. static const intel_limit_t intel_limits_i8xx_dac = {
  131. .dot = { .min = 25000, .max = 350000 },
  132. .vco = { .min = 908000, .max = 1512000 },
  133. .n = { .min = 2, .max = 16 },
  134. .m = { .min = 96, .max = 140 },
  135. .m1 = { .min = 18, .max = 26 },
  136. .m2 = { .min = 6, .max = 16 },
  137. .p = { .min = 4, .max = 128 },
  138. .p1 = { .min = 2, .max = 33 },
  139. .p2 = { .dot_limit = 165000,
  140. .p2_slow = 4, .p2_fast = 2 },
  141. };
  142. static const intel_limit_t intel_limits_i8xx_dvo = {
  143. .dot = { .min = 25000, .max = 350000 },
  144. .vco = { .min = 908000, .max = 1512000 },
  145. .n = { .min = 2, .max = 16 },
  146. .m = { .min = 96, .max = 140 },
  147. .m1 = { .min = 18, .max = 26 },
  148. .m2 = { .min = 6, .max = 16 },
  149. .p = { .min = 4, .max = 128 },
  150. .p1 = { .min = 2, .max = 33 },
  151. .p2 = { .dot_limit = 165000,
  152. .p2_slow = 4, .p2_fast = 4 },
  153. };
  154. static const intel_limit_t intel_limits_i8xx_lvds = {
  155. .dot = { .min = 25000, .max = 350000 },
  156. .vco = { .min = 908000, .max = 1512000 },
  157. .n = { .min = 2, .max = 16 },
  158. .m = { .min = 96, .max = 140 },
  159. .m1 = { .min = 18, .max = 26 },
  160. .m2 = { .min = 6, .max = 16 },
  161. .p = { .min = 4, .max = 128 },
  162. .p1 = { .min = 1, .max = 6 },
  163. .p2 = { .dot_limit = 165000,
  164. .p2_slow = 14, .p2_fast = 7 },
  165. };
  166. static const intel_limit_t intel_limits_i9xx_sdvo = {
  167. .dot = { .min = 20000, .max = 400000 },
  168. .vco = { .min = 1400000, .max = 2800000 },
  169. .n = { .min = 1, .max = 6 },
  170. .m = { .min = 70, .max = 120 },
  171. .m1 = { .min = 8, .max = 18 },
  172. .m2 = { .min = 3, .max = 7 },
  173. .p = { .min = 5, .max = 80 },
  174. .p1 = { .min = 1, .max = 8 },
  175. .p2 = { .dot_limit = 200000,
  176. .p2_slow = 10, .p2_fast = 5 },
  177. };
  178. static const intel_limit_t intel_limits_i9xx_lvds = {
  179. .dot = { .min = 20000, .max = 400000 },
  180. .vco = { .min = 1400000, .max = 2800000 },
  181. .n = { .min = 1, .max = 6 },
  182. .m = { .min = 70, .max = 120 },
  183. .m1 = { .min = 8, .max = 18 },
  184. .m2 = { .min = 3, .max = 7 },
  185. .p = { .min = 7, .max = 98 },
  186. .p1 = { .min = 1, .max = 8 },
  187. .p2 = { .dot_limit = 112000,
  188. .p2_slow = 14, .p2_fast = 7 },
  189. };
  190. static const intel_limit_t intel_limits_g4x_sdvo = {
  191. .dot = { .min = 25000, .max = 270000 },
  192. .vco = { .min = 1750000, .max = 3500000},
  193. .n = { .min = 1, .max = 4 },
  194. .m = { .min = 104, .max = 138 },
  195. .m1 = { .min = 17, .max = 23 },
  196. .m2 = { .min = 5, .max = 11 },
  197. .p = { .min = 10, .max = 30 },
  198. .p1 = { .min = 1, .max = 3},
  199. .p2 = { .dot_limit = 270000,
  200. .p2_slow = 10,
  201. .p2_fast = 10
  202. },
  203. };
  204. static const intel_limit_t intel_limits_g4x_hdmi = {
  205. .dot = { .min = 22000, .max = 400000 },
  206. .vco = { .min = 1750000, .max = 3500000},
  207. .n = { .min = 1, .max = 4 },
  208. .m = { .min = 104, .max = 138 },
  209. .m1 = { .min = 16, .max = 23 },
  210. .m2 = { .min = 5, .max = 11 },
  211. .p = { .min = 5, .max = 80 },
  212. .p1 = { .min = 1, .max = 8},
  213. .p2 = { .dot_limit = 165000,
  214. .p2_slow = 10, .p2_fast = 5 },
  215. };
  216. static const intel_limit_t intel_limits_g4x_single_channel_lvds = {
  217. .dot = { .min = 20000, .max = 115000 },
  218. .vco = { .min = 1750000, .max = 3500000 },
  219. .n = { .min = 1, .max = 3 },
  220. .m = { .min = 104, .max = 138 },
  221. .m1 = { .min = 17, .max = 23 },
  222. .m2 = { .min = 5, .max = 11 },
  223. .p = { .min = 28, .max = 112 },
  224. .p1 = { .min = 2, .max = 8 },
  225. .p2 = { .dot_limit = 0,
  226. .p2_slow = 14, .p2_fast = 14
  227. },
  228. };
  229. static const intel_limit_t intel_limits_g4x_dual_channel_lvds = {
  230. .dot = { .min = 80000, .max = 224000 },
  231. .vco = { .min = 1750000, .max = 3500000 },
  232. .n = { .min = 1, .max = 3 },
  233. .m = { .min = 104, .max = 138 },
  234. .m1 = { .min = 17, .max = 23 },
  235. .m2 = { .min = 5, .max = 11 },
  236. .p = { .min = 14, .max = 42 },
  237. .p1 = { .min = 2, .max = 6 },
  238. .p2 = { .dot_limit = 0,
  239. .p2_slow = 7, .p2_fast = 7
  240. },
  241. };
  242. static const intel_limit_t intel_limits_pineview_sdvo = {
  243. .dot = { .min = 20000, .max = 400000},
  244. .vco = { .min = 1700000, .max = 3500000 },
  245. /* Pineview's Ncounter is a ring counter */
  246. .n = { .min = 3, .max = 6 },
  247. .m = { .min = 2, .max = 256 },
  248. /* Pineview only has one combined m divider, which we treat as m2. */
  249. .m1 = { .min = 0, .max = 0 },
  250. .m2 = { .min = 0, .max = 254 },
  251. .p = { .min = 5, .max = 80 },
  252. .p1 = { .min = 1, .max = 8 },
  253. .p2 = { .dot_limit = 200000,
  254. .p2_slow = 10, .p2_fast = 5 },
  255. };
  256. static const intel_limit_t intel_limits_pineview_lvds = {
  257. .dot = { .min = 20000, .max = 400000 },
  258. .vco = { .min = 1700000, .max = 3500000 },
  259. .n = { .min = 3, .max = 6 },
  260. .m = { .min = 2, .max = 256 },
  261. .m1 = { .min = 0, .max = 0 },
  262. .m2 = { .min = 0, .max = 254 },
  263. .p = { .min = 7, .max = 112 },
  264. .p1 = { .min = 1, .max = 8 },
  265. .p2 = { .dot_limit = 112000,
  266. .p2_slow = 14, .p2_fast = 14 },
  267. };
  268. /* Ironlake / Sandybridge
  269. *
  270. * We calculate clock using (register_value + 2) for N/M1/M2, so here
  271. * the range value for them is (actual_value - 2).
  272. */
  273. static const intel_limit_t intel_limits_ironlake_dac = {
  274. .dot = { .min = 25000, .max = 350000 },
  275. .vco = { .min = 1760000, .max = 3510000 },
  276. .n = { .min = 1, .max = 5 },
  277. .m = { .min = 79, .max = 127 },
  278. .m1 = { .min = 12, .max = 22 },
  279. .m2 = { .min = 5, .max = 9 },
  280. .p = { .min = 5, .max = 80 },
  281. .p1 = { .min = 1, .max = 8 },
  282. .p2 = { .dot_limit = 225000,
  283. .p2_slow = 10, .p2_fast = 5 },
  284. };
  285. static const intel_limit_t intel_limits_ironlake_single_lvds = {
  286. .dot = { .min = 25000, .max = 350000 },
  287. .vco = { .min = 1760000, .max = 3510000 },
  288. .n = { .min = 1, .max = 3 },
  289. .m = { .min = 79, .max = 118 },
  290. .m1 = { .min = 12, .max = 22 },
  291. .m2 = { .min = 5, .max = 9 },
  292. .p = { .min = 28, .max = 112 },
  293. .p1 = { .min = 2, .max = 8 },
  294. .p2 = { .dot_limit = 225000,
  295. .p2_slow = 14, .p2_fast = 14 },
  296. };
  297. static const intel_limit_t intel_limits_ironlake_dual_lvds = {
  298. .dot = { .min = 25000, .max = 350000 },
  299. .vco = { .min = 1760000, .max = 3510000 },
  300. .n = { .min = 1, .max = 3 },
  301. .m = { .min = 79, .max = 127 },
  302. .m1 = { .min = 12, .max = 22 },
  303. .m2 = { .min = 5, .max = 9 },
  304. .p = { .min = 14, .max = 56 },
  305. .p1 = { .min = 2, .max = 8 },
  306. .p2 = { .dot_limit = 225000,
  307. .p2_slow = 7, .p2_fast = 7 },
  308. };
  309. /* LVDS 100mhz refclk limits. */
  310. static const intel_limit_t intel_limits_ironlake_single_lvds_100m = {
  311. .dot = { .min = 25000, .max = 350000 },
  312. .vco = { .min = 1760000, .max = 3510000 },
  313. .n = { .min = 1, .max = 2 },
  314. .m = { .min = 79, .max = 126 },
  315. .m1 = { .min = 12, .max = 22 },
  316. .m2 = { .min = 5, .max = 9 },
  317. .p = { .min = 28, .max = 112 },
  318. .p1 = { .min = 2, .max = 8 },
  319. .p2 = { .dot_limit = 225000,
  320. .p2_slow = 14, .p2_fast = 14 },
  321. };
  322. static const intel_limit_t intel_limits_ironlake_dual_lvds_100m = {
  323. .dot = { .min = 25000, .max = 350000 },
  324. .vco = { .min = 1760000, .max = 3510000 },
  325. .n = { .min = 1, .max = 3 },
  326. .m = { .min = 79, .max = 126 },
  327. .m1 = { .min = 12, .max = 22 },
  328. .m2 = { .min = 5, .max = 9 },
  329. .p = { .min = 14, .max = 42 },
  330. .p1 = { .min = 2, .max = 6 },
  331. .p2 = { .dot_limit = 225000,
  332. .p2_slow = 7, .p2_fast = 7 },
  333. };
  334. static const intel_limit_t intel_limits_vlv = {
  335. /*
  336. * These are the data rate limits (measured in fast clocks)
  337. * since those are the strictest limits we have. The fast
  338. * clock and actual rate limits are more relaxed, so checking
  339. * them would make no difference.
  340. */
  341. .dot = { .min = 25000 * 5, .max = 270000 * 5 },
  342. .vco = { .min = 4000000, .max = 6000000 },
  343. .n = { .min = 1, .max = 7 },
  344. .m1 = { .min = 2, .max = 3 },
  345. .m2 = { .min = 11, .max = 156 },
  346. .p1 = { .min = 2, .max = 3 },
  347. .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */
  348. };
  349. static const intel_limit_t intel_limits_chv = {
  350. /*
  351. * These are the data rate limits (measured in fast clocks)
  352. * since those are the strictest limits we have. The fast
  353. * clock and actual rate limits are more relaxed, so checking
  354. * them would make no difference.
  355. */
  356. .dot = { .min = 25000 * 5, .max = 540000 * 5},
  357. .vco = { .min = 4860000, .max = 6700000 },
  358. .n = { .min = 1, .max = 1 },
  359. .m1 = { .min = 2, .max = 2 },
  360. .m2 = { .min = 24 << 22, .max = 175 << 22 },
  361. .p1 = { .min = 2, .max = 4 },
  362. .p2 = { .p2_slow = 1, .p2_fast = 14 },
  363. };
  364. static void vlv_clock(int refclk, intel_clock_t *clock)
  365. {
  366. clock->m = clock->m1 * clock->m2;
  367. clock->p = clock->p1 * clock->p2;
  368. if (WARN_ON(clock->n == 0 || clock->p == 0))
  369. return;
  370. clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
  371. clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
  372. }
  373. /**
  374. * Returns whether any output on the specified pipe is of the specified type
  375. */
  376. static bool intel_pipe_has_type(struct drm_crtc *crtc, int type)
  377. {
  378. struct drm_device *dev = crtc->dev;
  379. struct intel_encoder *encoder;
  380. for_each_encoder_on_crtc(dev, crtc, encoder)
  381. if (encoder->type == type)
  382. return true;
  383. return false;
  384. }
  385. static const intel_limit_t *intel_ironlake_limit(struct drm_crtc *crtc,
  386. int refclk)
  387. {
  388. struct drm_device *dev = crtc->dev;
  389. const intel_limit_t *limit;
  390. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  391. if (intel_is_dual_link_lvds(dev)) {
  392. if (refclk == 100000)
  393. limit = &intel_limits_ironlake_dual_lvds_100m;
  394. else
  395. limit = &intel_limits_ironlake_dual_lvds;
  396. } else {
  397. if (refclk == 100000)
  398. limit = &intel_limits_ironlake_single_lvds_100m;
  399. else
  400. limit = &intel_limits_ironlake_single_lvds;
  401. }
  402. } else
  403. limit = &intel_limits_ironlake_dac;
  404. return limit;
  405. }
  406. static const intel_limit_t *intel_g4x_limit(struct drm_crtc *crtc)
  407. {
  408. struct drm_device *dev = crtc->dev;
  409. const intel_limit_t *limit;
  410. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  411. if (intel_is_dual_link_lvds(dev))
  412. limit = &intel_limits_g4x_dual_channel_lvds;
  413. else
  414. limit = &intel_limits_g4x_single_channel_lvds;
  415. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI) ||
  416. intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG)) {
  417. limit = &intel_limits_g4x_hdmi;
  418. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO)) {
  419. limit = &intel_limits_g4x_sdvo;
  420. } else /* The option is for other outputs */
  421. limit = &intel_limits_i9xx_sdvo;
  422. return limit;
  423. }
  424. static const intel_limit_t *intel_limit(struct drm_crtc *crtc, int refclk)
  425. {
  426. struct drm_device *dev = crtc->dev;
  427. const intel_limit_t *limit;
  428. if (HAS_PCH_SPLIT(dev))
  429. limit = intel_ironlake_limit(crtc, refclk);
  430. else if (IS_G4X(dev)) {
  431. limit = intel_g4x_limit(crtc);
  432. } else if (IS_PINEVIEW(dev)) {
  433. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  434. limit = &intel_limits_pineview_lvds;
  435. else
  436. limit = &intel_limits_pineview_sdvo;
  437. } else if (IS_CHERRYVIEW(dev)) {
  438. limit = &intel_limits_chv;
  439. } else if (IS_VALLEYVIEW(dev)) {
  440. limit = &intel_limits_vlv;
  441. } else if (!IS_GEN2(dev)) {
  442. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  443. limit = &intel_limits_i9xx_lvds;
  444. else
  445. limit = &intel_limits_i9xx_sdvo;
  446. } else {
  447. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  448. limit = &intel_limits_i8xx_lvds;
  449. else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO))
  450. limit = &intel_limits_i8xx_dvo;
  451. else
  452. limit = &intel_limits_i8xx_dac;
  453. }
  454. return limit;
  455. }
  456. /* m1 is reserved as 0 in Pineview, n is a ring counter */
  457. static void pineview_clock(int refclk, intel_clock_t *clock)
  458. {
  459. clock->m = clock->m2 + 2;
  460. clock->p = clock->p1 * clock->p2;
  461. if (WARN_ON(clock->n == 0 || clock->p == 0))
  462. return;
  463. clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
  464. clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
  465. }
  466. static uint32_t i9xx_dpll_compute_m(struct dpll *dpll)
  467. {
  468. return 5 * (dpll->m1 + 2) + (dpll->m2 + 2);
  469. }
  470. static void i9xx_clock(int refclk, intel_clock_t *clock)
  471. {
  472. clock->m = i9xx_dpll_compute_m(clock);
  473. clock->p = clock->p1 * clock->p2;
  474. if (WARN_ON(clock->n + 2 == 0 || clock->p == 0))
  475. return;
  476. clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2);
  477. clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
  478. }
  479. static void chv_clock(int refclk, intel_clock_t *clock)
  480. {
  481. clock->m = clock->m1 * clock->m2;
  482. clock->p = clock->p1 * clock->p2;
  483. if (WARN_ON(clock->n == 0 || clock->p == 0))
  484. return;
  485. clock->vco = DIV_ROUND_CLOSEST_ULL((uint64_t)refclk * clock->m,
  486. clock->n << 22);
  487. clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
  488. }
  489. #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
  490. /**
  491. * Returns whether the given set of divisors are valid for a given refclk with
  492. * the given connectors.
  493. */
  494. static bool intel_PLL_is_valid(struct drm_device *dev,
  495. const intel_limit_t *limit,
  496. const intel_clock_t *clock)
  497. {
  498. if (clock->n < limit->n.min || limit->n.max < clock->n)
  499. INTELPllInvalid("n out of range\n");
  500. if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1)
  501. INTELPllInvalid("p1 out of range\n");
  502. if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2)
  503. INTELPllInvalid("m2 out of range\n");
  504. if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1)
  505. INTELPllInvalid("m1 out of range\n");
  506. if (!IS_PINEVIEW(dev) && !IS_VALLEYVIEW(dev))
  507. if (clock->m1 <= clock->m2)
  508. INTELPllInvalid("m1 <= m2\n");
  509. if (!IS_VALLEYVIEW(dev)) {
  510. if (clock->p < limit->p.min || limit->p.max < clock->p)
  511. INTELPllInvalid("p out of range\n");
  512. if (clock->m < limit->m.min || limit->m.max < clock->m)
  513. INTELPllInvalid("m out of range\n");
  514. }
  515. if (clock->vco < limit->vco.min || limit->vco.max < clock->vco)
  516. INTELPllInvalid("vco out of range\n");
  517. /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
  518. * connector, etc., rather than just a single range.
  519. */
  520. if (clock->dot < limit->dot.min || limit->dot.max < clock->dot)
  521. INTELPllInvalid("dot out of range\n");
  522. return true;
  523. }
  524. static bool
  525. i9xx_find_best_dpll(const intel_limit_t *limit, struct drm_crtc *crtc,
  526. int target, int refclk, intel_clock_t *match_clock,
  527. intel_clock_t *best_clock)
  528. {
  529. struct drm_device *dev = crtc->dev;
  530. intel_clock_t clock;
  531. int err = target;
  532. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  533. /*
  534. * For LVDS just rely on its current settings for dual-channel.
  535. * We haven't figured out how to reliably set up different
  536. * single/dual channel state, if we even can.
  537. */
  538. if (intel_is_dual_link_lvds(dev))
  539. clock.p2 = limit->p2.p2_fast;
  540. else
  541. clock.p2 = limit->p2.p2_slow;
  542. } else {
  543. if (target < limit->p2.dot_limit)
  544. clock.p2 = limit->p2.p2_slow;
  545. else
  546. clock.p2 = limit->p2.p2_fast;
  547. }
  548. memset(best_clock, 0, sizeof(*best_clock));
  549. for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
  550. clock.m1++) {
  551. for (clock.m2 = limit->m2.min;
  552. clock.m2 <= limit->m2.max; clock.m2++) {
  553. if (clock.m2 >= clock.m1)
  554. break;
  555. for (clock.n = limit->n.min;
  556. clock.n <= limit->n.max; clock.n++) {
  557. for (clock.p1 = limit->p1.min;
  558. clock.p1 <= limit->p1.max; clock.p1++) {
  559. int this_err;
  560. i9xx_clock(refclk, &clock);
  561. if (!intel_PLL_is_valid(dev, limit,
  562. &clock))
  563. continue;
  564. if (match_clock &&
  565. clock.p != match_clock->p)
  566. continue;
  567. this_err = abs(clock.dot - target);
  568. if (this_err < err) {
  569. *best_clock = clock;
  570. err = this_err;
  571. }
  572. }
  573. }
  574. }
  575. }
  576. return (err != target);
  577. }
  578. static bool
  579. pnv_find_best_dpll(const intel_limit_t *limit, struct drm_crtc *crtc,
  580. int target, int refclk, intel_clock_t *match_clock,
  581. intel_clock_t *best_clock)
  582. {
  583. struct drm_device *dev = crtc->dev;
  584. intel_clock_t clock;
  585. int err = target;
  586. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  587. /*
  588. * For LVDS just rely on its current settings for dual-channel.
  589. * We haven't figured out how to reliably set up different
  590. * single/dual channel state, if we even can.
  591. */
  592. if (intel_is_dual_link_lvds(dev))
  593. clock.p2 = limit->p2.p2_fast;
  594. else
  595. clock.p2 = limit->p2.p2_slow;
  596. } else {
  597. if (target < limit->p2.dot_limit)
  598. clock.p2 = limit->p2.p2_slow;
  599. else
  600. clock.p2 = limit->p2.p2_fast;
  601. }
  602. memset(best_clock, 0, sizeof(*best_clock));
  603. for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
  604. clock.m1++) {
  605. for (clock.m2 = limit->m2.min;
  606. clock.m2 <= limit->m2.max; clock.m2++) {
  607. for (clock.n = limit->n.min;
  608. clock.n <= limit->n.max; clock.n++) {
  609. for (clock.p1 = limit->p1.min;
  610. clock.p1 <= limit->p1.max; clock.p1++) {
  611. int this_err;
  612. pineview_clock(refclk, &clock);
  613. if (!intel_PLL_is_valid(dev, limit,
  614. &clock))
  615. continue;
  616. if (match_clock &&
  617. clock.p != match_clock->p)
  618. continue;
  619. this_err = abs(clock.dot - target);
  620. if (this_err < err) {
  621. *best_clock = clock;
  622. err = this_err;
  623. }
  624. }
  625. }
  626. }
  627. }
  628. return (err != target);
  629. }
  630. static bool
  631. g4x_find_best_dpll(const intel_limit_t *limit, struct drm_crtc *crtc,
  632. int target, int refclk, intel_clock_t *match_clock,
  633. intel_clock_t *best_clock)
  634. {
  635. struct drm_device *dev = crtc->dev;
  636. intel_clock_t clock;
  637. int max_n;
  638. bool found;
  639. /* approximately equals target * 0.00585 */
  640. int err_most = (target >> 8) + (target >> 9);
  641. found = false;
  642. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  643. if (intel_is_dual_link_lvds(dev))
  644. clock.p2 = limit->p2.p2_fast;
  645. else
  646. clock.p2 = limit->p2.p2_slow;
  647. } else {
  648. if (target < limit->p2.dot_limit)
  649. clock.p2 = limit->p2.p2_slow;
  650. else
  651. clock.p2 = limit->p2.p2_fast;
  652. }
  653. memset(best_clock, 0, sizeof(*best_clock));
  654. max_n = limit->n.max;
  655. /* based on hardware requirement, prefer smaller n to precision */
  656. for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
  657. /* based on hardware requirement, prefere larger m1,m2 */
  658. for (clock.m1 = limit->m1.max;
  659. clock.m1 >= limit->m1.min; clock.m1--) {
  660. for (clock.m2 = limit->m2.max;
  661. clock.m2 >= limit->m2.min; clock.m2--) {
  662. for (clock.p1 = limit->p1.max;
  663. clock.p1 >= limit->p1.min; clock.p1--) {
  664. int this_err;
  665. i9xx_clock(refclk, &clock);
  666. if (!intel_PLL_is_valid(dev, limit,
  667. &clock))
  668. continue;
  669. this_err = abs(clock.dot - target);
  670. if (this_err < err_most) {
  671. *best_clock = clock;
  672. err_most = this_err;
  673. max_n = clock.n;
  674. found = true;
  675. }
  676. }
  677. }
  678. }
  679. }
  680. return found;
  681. }
  682. static bool
  683. vlv_find_best_dpll(const intel_limit_t *limit, struct drm_crtc *crtc,
  684. int target, int refclk, intel_clock_t *match_clock,
  685. intel_clock_t *best_clock)
  686. {
  687. struct drm_device *dev = crtc->dev;
  688. intel_clock_t clock;
  689. unsigned int bestppm = 1000000;
  690. /* min update 19.2 MHz */
  691. int max_n = min(limit->n.max, refclk / 19200);
  692. bool found = false;
  693. target *= 5; /* fast clock */
  694. memset(best_clock, 0, sizeof(*best_clock));
  695. /* based on hardware requirement, prefer smaller n to precision */
  696. for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
  697. for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
  698. for (clock.p2 = limit->p2.p2_fast; clock.p2 >= limit->p2.p2_slow;
  699. clock.p2 -= clock.p2 > 10 ? 2 : 1) {
  700. clock.p = clock.p1 * clock.p2;
  701. /* based on hardware requirement, prefer bigger m1,m2 values */
  702. for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) {
  703. unsigned int ppm, diff;
  704. clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n,
  705. refclk * clock.m1);
  706. vlv_clock(refclk, &clock);
  707. if (!intel_PLL_is_valid(dev, limit,
  708. &clock))
  709. continue;
  710. diff = abs(clock.dot - target);
  711. ppm = div_u64(1000000ULL * diff, target);
  712. if (ppm < 100 && clock.p > best_clock->p) {
  713. bestppm = 0;
  714. *best_clock = clock;
  715. found = true;
  716. }
  717. if (bestppm >= 10 && ppm < bestppm - 10) {
  718. bestppm = ppm;
  719. *best_clock = clock;
  720. found = true;
  721. }
  722. }
  723. }
  724. }
  725. }
  726. return found;
  727. }
  728. static bool
  729. chv_find_best_dpll(const intel_limit_t *limit, struct drm_crtc *crtc,
  730. int target, int refclk, intel_clock_t *match_clock,
  731. intel_clock_t *best_clock)
  732. {
  733. struct drm_device *dev = crtc->dev;
  734. intel_clock_t clock;
  735. uint64_t m2;
  736. int found = false;
  737. memset(best_clock, 0, sizeof(*best_clock));
  738. /*
  739. * Based on hardware doc, the n always set to 1, and m1 always
  740. * set to 2. If requires to support 200Mhz refclk, we need to
  741. * revisit this because n may not 1 anymore.
  742. */
  743. clock.n = 1, clock.m1 = 2;
  744. target *= 5; /* fast clock */
  745. for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
  746. for (clock.p2 = limit->p2.p2_fast;
  747. clock.p2 >= limit->p2.p2_slow;
  748. clock.p2 -= clock.p2 > 10 ? 2 : 1) {
  749. clock.p = clock.p1 * clock.p2;
  750. m2 = DIV_ROUND_CLOSEST_ULL(((uint64_t)target * clock.p *
  751. clock.n) << 22, refclk * clock.m1);
  752. if (m2 > INT_MAX/clock.m1)
  753. continue;
  754. clock.m2 = m2;
  755. chv_clock(refclk, &clock);
  756. if (!intel_PLL_is_valid(dev, limit, &clock))
  757. continue;
  758. /* based on hardware requirement, prefer bigger p
  759. */
  760. if (clock.p > best_clock->p) {
  761. *best_clock = clock;
  762. found = true;
  763. }
  764. }
  765. }
  766. return found;
  767. }
  768. bool intel_crtc_active(struct drm_crtc *crtc)
  769. {
  770. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  771. /* Be paranoid as we can arrive here with only partial
  772. * state retrieved from the hardware during setup.
  773. *
  774. * We can ditch the adjusted_mode.crtc_clock check as soon
  775. * as Haswell has gained clock readout/fastboot support.
  776. *
  777. * We can ditch the crtc->primary->fb check as soon as we can
  778. * properly reconstruct framebuffers.
  779. */
  780. return intel_crtc->active && crtc->primary->fb &&
  781. intel_crtc->config.adjusted_mode.crtc_clock;
  782. }
  783. enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv,
  784. enum pipe pipe)
  785. {
  786. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  787. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  788. return intel_crtc->config.cpu_transcoder;
  789. }
  790. static void g4x_wait_for_vblank(struct drm_device *dev, int pipe)
  791. {
  792. struct drm_i915_private *dev_priv = dev->dev_private;
  793. u32 frame, frame_reg = PIPE_FRMCOUNT_GM45(pipe);
  794. frame = I915_READ(frame_reg);
  795. if (wait_for(I915_READ_NOTRACE(frame_reg) != frame, 50))
  796. WARN(1, "vblank wait on pipe %c timed out\n",
  797. pipe_name(pipe));
  798. }
  799. /**
  800. * intel_wait_for_vblank - wait for vblank on a given pipe
  801. * @dev: drm device
  802. * @pipe: pipe to wait for
  803. *
  804. * Wait for vblank to occur on a given pipe. Needed for various bits of
  805. * mode setting code.
  806. */
  807. void intel_wait_for_vblank(struct drm_device *dev, int pipe)
  808. {
  809. struct drm_i915_private *dev_priv = dev->dev_private;
  810. int pipestat_reg = PIPESTAT(pipe);
  811. if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
  812. g4x_wait_for_vblank(dev, pipe);
  813. return;
  814. }
  815. /* Clear existing vblank status. Note this will clear any other
  816. * sticky status fields as well.
  817. *
  818. * This races with i915_driver_irq_handler() with the result
  819. * that either function could miss a vblank event. Here it is not
  820. * fatal, as we will either wait upon the next vblank interrupt or
  821. * timeout. Generally speaking intel_wait_for_vblank() is only
  822. * called during modeset at which time the GPU should be idle and
  823. * should *not* be performing page flips and thus not waiting on
  824. * vblanks...
  825. * Currently, the result of us stealing a vblank from the irq
  826. * handler is that a single frame will be skipped during swapbuffers.
  827. */
  828. I915_WRITE(pipestat_reg,
  829. I915_READ(pipestat_reg) | PIPE_VBLANK_INTERRUPT_STATUS);
  830. /* Wait for vblank interrupt bit to set */
  831. if (wait_for(I915_READ(pipestat_reg) &
  832. PIPE_VBLANK_INTERRUPT_STATUS,
  833. 50))
  834. DRM_DEBUG_KMS("vblank wait on pipe %c timed out\n",
  835. pipe_name(pipe));
  836. }
  837. static bool pipe_dsl_stopped(struct drm_device *dev, enum pipe pipe)
  838. {
  839. struct drm_i915_private *dev_priv = dev->dev_private;
  840. u32 reg = PIPEDSL(pipe);
  841. u32 line1, line2;
  842. u32 line_mask;
  843. if (IS_GEN2(dev))
  844. line_mask = DSL_LINEMASK_GEN2;
  845. else
  846. line_mask = DSL_LINEMASK_GEN3;
  847. line1 = I915_READ(reg) & line_mask;
  848. mdelay(5);
  849. line2 = I915_READ(reg) & line_mask;
  850. return line1 == line2;
  851. }
  852. /*
  853. * intel_wait_for_pipe_off - wait for pipe to turn off
  854. * @crtc: crtc whose pipe to wait for
  855. *
  856. * After disabling a pipe, we can't wait for vblank in the usual way,
  857. * spinning on the vblank interrupt status bit, since we won't actually
  858. * see an interrupt when the pipe is disabled.
  859. *
  860. * On Gen4 and above:
  861. * wait for the pipe register state bit to turn off
  862. *
  863. * Otherwise:
  864. * wait for the display line value to settle (it usually
  865. * ends up stopping at the start of the next frame).
  866. *
  867. */
  868. static void intel_wait_for_pipe_off(struct intel_crtc *crtc)
  869. {
  870. struct drm_device *dev = crtc->base.dev;
  871. struct drm_i915_private *dev_priv = dev->dev_private;
  872. enum transcoder cpu_transcoder = crtc->config.cpu_transcoder;
  873. enum pipe pipe = crtc->pipe;
  874. if (INTEL_INFO(dev)->gen >= 4) {
  875. int reg = PIPECONF(cpu_transcoder);
  876. /* Wait for the Pipe State to go off */
  877. if (wait_for((I915_READ(reg) & I965_PIPECONF_ACTIVE) == 0,
  878. 100))
  879. WARN(1, "pipe_off wait timed out\n");
  880. } else {
  881. /* Wait for the display line to settle */
  882. if (wait_for(pipe_dsl_stopped(dev, pipe), 100))
  883. WARN(1, "pipe_off wait timed out\n");
  884. }
  885. }
  886. /*
  887. * ibx_digital_port_connected - is the specified port connected?
  888. * @dev_priv: i915 private structure
  889. * @port: the port to test
  890. *
  891. * Returns true if @port is connected, false otherwise.
  892. */
  893. bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
  894. struct intel_digital_port *port)
  895. {
  896. u32 bit;
  897. if (HAS_PCH_IBX(dev_priv->dev)) {
  898. switch (port->port) {
  899. case PORT_B:
  900. bit = SDE_PORTB_HOTPLUG;
  901. break;
  902. case PORT_C:
  903. bit = SDE_PORTC_HOTPLUG;
  904. break;
  905. case PORT_D:
  906. bit = SDE_PORTD_HOTPLUG;
  907. break;
  908. default:
  909. return true;
  910. }
  911. } else {
  912. switch (port->port) {
  913. case PORT_B:
  914. bit = SDE_PORTB_HOTPLUG_CPT;
  915. break;
  916. case PORT_C:
  917. bit = SDE_PORTC_HOTPLUG_CPT;
  918. break;
  919. case PORT_D:
  920. bit = SDE_PORTD_HOTPLUG_CPT;
  921. break;
  922. default:
  923. return true;
  924. }
  925. }
  926. return I915_READ(SDEISR) & bit;
  927. }
  928. static const char *state_string(bool enabled)
  929. {
  930. return enabled ? "on" : "off";
  931. }
  932. /* Only for pre-ILK configs */
  933. void assert_pll(struct drm_i915_private *dev_priv,
  934. enum pipe pipe, bool state)
  935. {
  936. int reg;
  937. u32 val;
  938. bool cur_state;
  939. reg = DPLL(pipe);
  940. val = I915_READ(reg);
  941. cur_state = !!(val & DPLL_VCO_ENABLE);
  942. WARN(cur_state != state,
  943. "PLL state assertion failure (expected %s, current %s)\n",
  944. state_string(state), state_string(cur_state));
  945. }
  946. /* XXX: the dsi pll is shared between MIPI DSI ports */
  947. static void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state)
  948. {
  949. u32 val;
  950. bool cur_state;
  951. mutex_lock(&dev_priv->dpio_lock);
  952. val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL);
  953. mutex_unlock(&dev_priv->dpio_lock);
  954. cur_state = val & DSI_PLL_VCO_EN;
  955. WARN(cur_state != state,
  956. "DSI PLL state assertion failure (expected %s, current %s)\n",
  957. state_string(state), state_string(cur_state));
  958. }
  959. #define assert_dsi_pll_enabled(d) assert_dsi_pll(d, true)
  960. #define assert_dsi_pll_disabled(d) assert_dsi_pll(d, false)
  961. struct intel_shared_dpll *
  962. intel_crtc_to_shared_dpll(struct intel_crtc *crtc)
  963. {
  964. struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
  965. if (crtc->config.shared_dpll < 0)
  966. return NULL;
  967. return &dev_priv->shared_dplls[crtc->config.shared_dpll];
  968. }
  969. /* For ILK+ */
  970. void assert_shared_dpll(struct drm_i915_private *dev_priv,
  971. struct intel_shared_dpll *pll,
  972. bool state)
  973. {
  974. bool cur_state;
  975. struct intel_dpll_hw_state hw_state;
  976. if (WARN (!pll,
  977. "asserting DPLL %s with no DPLL\n", state_string(state)))
  978. return;
  979. cur_state = pll->get_hw_state(dev_priv, pll, &hw_state);
  980. WARN(cur_state != state,
  981. "%s assertion failure (expected %s, current %s)\n",
  982. pll->name, state_string(state), state_string(cur_state));
  983. }
  984. static void assert_fdi_tx(struct drm_i915_private *dev_priv,
  985. enum pipe pipe, bool state)
  986. {
  987. int reg;
  988. u32 val;
  989. bool cur_state;
  990. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  991. pipe);
  992. if (HAS_DDI(dev_priv->dev)) {
  993. /* DDI does not have a specific FDI_TX register */
  994. reg = TRANS_DDI_FUNC_CTL(cpu_transcoder);
  995. val = I915_READ(reg);
  996. cur_state = !!(val & TRANS_DDI_FUNC_ENABLE);
  997. } else {
  998. reg = FDI_TX_CTL(pipe);
  999. val = I915_READ(reg);
  1000. cur_state = !!(val & FDI_TX_ENABLE);
  1001. }
  1002. WARN(cur_state != state,
  1003. "FDI TX state assertion failure (expected %s, current %s)\n",
  1004. state_string(state), state_string(cur_state));
  1005. }
  1006. #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
  1007. #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
  1008. static void assert_fdi_rx(struct drm_i915_private *dev_priv,
  1009. enum pipe pipe, bool state)
  1010. {
  1011. int reg;
  1012. u32 val;
  1013. bool cur_state;
  1014. reg = FDI_RX_CTL(pipe);
  1015. val = I915_READ(reg);
  1016. cur_state = !!(val & FDI_RX_ENABLE);
  1017. WARN(cur_state != state,
  1018. "FDI RX state assertion failure (expected %s, current %s)\n",
  1019. state_string(state), state_string(cur_state));
  1020. }
  1021. #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
  1022. #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
  1023. static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv,
  1024. enum pipe pipe)
  1025. {
  1026. int reg;
  1027. u32 val;
  1028. /* ILK FDI PLL is always enabled */
  1029. if (INTEL_INFO(dev_priv->dev)->gen == 5)
  1030. return;
  1031. /* On Haswell, DDI ports are responsible for the FDI PLL setup */
  1032. if (HAS_DDI(dev_priv->dev))
  1033. return;
  1034. reg = FDI_TX_CTL(pipe);
  1035. val = I915_READ(reg);
  1036. WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n");
  1037. }
  1038. void assert_fdi_rx_pll(struct drm_i915_private *dev_priv,
  1039. enum pipe pipe, bool state)
  1040. {
  1041. int reg;
  1042. u32 val;
  1043. bool cur_state;
  1044. reg = FDI_RX_CTL(pipe);
  1045. val = I915_READ(reg);
  1046. cur_state = !!(val & FDI_RX_PLL_ENABLE);
  1047. WARN(cur_state != state,
  1048. "FDI RX PLL assertion failure (expected %s, current %s)\n",
  1049. state_string(state), state_string(cur_state));
  1050. }
  1051. static void assert_panel_unlocked(struct drm_i915_private *dev_priv,
  1052. enum pipe pipe)
  1053. {
  1054. struct drm_device *dev = dev_priv->dev;
  1055. int pp_reg;
  1056. u32 val;
  1057. enum pipe panel_pipe = PIPE_A;
  1058. bool locked = true;
  1059. if (WARN_ON(HAS_DDI(dev)))
  1060. return;
  1061. if (HAS_PCH_SPLIT(dev)) {
  1062. u32 port_sel;
  1063. pp_reg = PCH_PP_CONTROL;
  1064. port_sel = I915_READ(PCH_PP_ON_DELAYS) & PANEL_PORT_SELECT_MASK;
  1065. if (port_sel == PANEL_PORT_SELECT_LVDS &&
  1066. I915_READ(PCH_LVDS) & LVDS_PIPEB_SELECT)
  1067. panel_pipe = PIPE_B;
  1068. /* XXX: else fix for eDP */
  1069. } else if (IS_VALLEYVIEW(dev)) {
  1070. /* presumably write lock depends on pipe, not port select */
  1071. pp_reg = VLV_PIPE_PP_CONTROL(pipe);
  1072. panel_pipe = pipe;
  1073. } else {
  1074. pp_reg = PP_CONTROL;
  1075. if (I915_READ(LVDS) & LVDS_PIPEB_SELECT)
  1076. panel_pipe = PIPE_B;
  1077. }
  1078. val = I915_READ(pp_reg);
  1079. if (!(val & PANEL_POWER_ON) ||
  1080. ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS))
  1081. locked = false;
  1082. WARN(panel_pipe == pipe && locked,
  1083. "panel assertion failure, pipe %c regs locked\n",
  1084. pipe_name(pipe));
  1085. }
  1086. static void assert_cursor(struct drm_i915_private *dev_priv,
  1087. enum pipe pipe, bool state)
  1088. {
  1089. struct drm_device *dev = dev_priv->dev;
  1090. bool cur_state;
  1091. if (IS_845G(dev) || IS_I865G(dev))
  1092. cur_state = I915_READ(_CURACNTR) & CURSOR_ENABLE;
  1093. else
  1094. cur_state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
  1095. WARN(cur_state != state,
  1096. "cursor on pipe %c assertion failure (expected %s, current %s)\n",
  1097. pipe_name(pipe), state_string(state), state_string(cur_state));
  1098. }
  1099. #define assert_cursor_enabled(d, p) assert_cursor(d, p, true)
  1100. #define assert_cursor_disabled(d, p) assert_cursor(d, p, false)
  1101. void assert_pipe(struct drm_i915_private *dev_priv,
  1102. enum pipe pipe, bool state)
  1103. {
  1104. int reg;
  1105. u32 val;
  1106. bool cur_state;
  1107. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  1108. pipe);
  1109. /* if we need the pipe quirk it must be always on */
  1110. if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) ||
  1111. (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))
  1112. state = true;
  1113. if (!intel_display_power_enabled(dev_priv,
  1114. POWER_DOMAIN_TRANSCODER(cpu_transcoder))) {
  1115. cur_state = false;
  1116. } else {
  1117. reg = PIPECONF(cpu_transcoder);
  1118. val = I915_READ(reg);
  1119. cur_state = !!(val & PIPECONF_ENABLE);
  1120. }
  1121. WARN(cur_state != state,
  1122. "pipe %c assertion failure (expected %s, current %s)\n",
  1123. pipe_name(pipe), state_string(state), state_string(cur_state));
  1124. }
  1125. static void assert_plane(struct drm_i915_private *dev_priv,
  1126. enum plane plane, bool state)
  1127. {
  1128. int reg;
  1129. u32 val;
  1130. bool cur_state;
  1131. reg = DSPCNTR(plane);
  1132. val = I915_READ(reg);
  1133. cur_state = !!(val & DISPLAY_PLANE_ENABLE);
  1134. WARN(cur_state != state,
  1135. "plane %c assertion failure (expected %s, current %s)\n",
  1136. plane_name(plane), state_string(state), state_string(cur_state));
  1137. }
  1138. #define assert_plane_enabled(d, p) assert_plane(d, p, true)
  1139. #define assert_plane_disabled(d, p) assert_plane(d, p, false)
  1140. static void assert_planes_disabled(struct drm_i915_private *dev_priv,
  1141. enum pipe pipe)
  1142. {
  1143. struct drm_device *dev = dev_priv->dev;
  1144. int reg, i;
  1145. u32 val;
  1146. int cur_pipe;
  1147. /* Primary planes are fixed to pipes on gen4+ */
  1148. if (INTEL_INFO(dev)->gen >= 4) {
  1149. reg = DSPCNTR(pipe);
  1150. val = I915_READ(reg);
  1151. WARN(val & DISPLAY_PLANE_ENABLE,
  1152. "plane %c assertion failure, should be disabled but not\n",
  1153. plane_name(pipe));
  1154. return;
  1155. }
  1156. /* Need to check both planes against the pipe */
  1157. for_each_pipe(dev_priv, i) {
  1158. reg = DSPCNTR(i);
  1159. val = I915_READ(reg);
  1160. cur_pipe = (val & DISPPLANE_SEL_PIPE_MASK) >>
  1161. DISPPLANE_SEL_PIPE_SHIFT;
  1162. WARN((val & DISPLAY_PLANE_ENABLE) && pipe == cur_pipe,
  1163. "plane %c assertion failure, should be off on pipe %c but is still active\n",
  1164. plane_name(i), pipe_name(pipe));
  1165. }
  1166. }
  1167. static void assert_sprites_disabled(struct drm_i915_private *dev_priv,
  1168. enum pipe pipe)
  1169. {
  1170. struct drm_device *dev = dev_priv->dev;
  1171. int reg, sprite;
  1172. u32 val;
  1173. if (IS_VALLEYVIEW(dev)) {
  1174. for_each_sprite(pipe, sprite) {
  1175. reg = SPCNTR(pipe, sprite);
  1176. val = I915_READ(reg);
  1177. WARN(val & SP_ENABLE,
  1178. "sprite %c assertion failure, should be off on pipe %c but is still active\n",
  1179. sprite_name(pipe, sprite), pipe_name(pipe));
  1180. }
  1181. } else if (INTEL_INFO(dev)->gen >= 7) {
  1182. reg = SPRCTL(pipe);
  1183. val = I915_READ(reg);
  1184. WARN(val & SPRITE_ENABLE,
  1185. "sprite %c assertion failure, should be off on pipe %c but is still active\n",
  1186. plane_name(pipe), pipe_name(pipe));
  1187. } else if (INTEL_INFO(dev)->gen >= 5) {
  1188. reg = DVSCNTR(pipe);
  1189. val = I915_READ(reg);
  1190. WARN(val & DVS_ENABLE,
  1191. "sprite %c assertion failure, should be off on pipe %c but is still active\n",
  1192. plane_name(pipe), pipe_name(pipe));
  1193. }
  1194. }
  1195. static void assert_vblank_disabled(struct drm_crtc *crtc)
  1196. {
  1197. if (WARN_ON(drm_crtc_vblank_get(crtc) == 0))
  1198. drm_crtc_vblank_put(crtc);
  1199. }
  1200. static void ibx_assert_pch_refclk_enabled(struct drm_i915_private *dev_priv)
  1201. {
  1202. u32 val;
  1203. bool enabled;
  1204. WARN_ON(!(HAS_PCH_IBX(dev_priv->dev) || HAS_PCH_CPT(dev_priv->dev)));
  1205. val = I915_READ(PCH_DREF_CONTROL);
  1206. enabled = !!(val & (DREF_SSC_SOURCE_MASK | DREF_NONSPREAD_SOURCE_MASK |
  1207. DREF_SUPERSPREAD_SOURCE_MASK));
  1208. WARN(!enabled, "PCH refclk assertion failure, should be active but is disabled\n");
  1209. }
  1210. static void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv,
  1211. enum pipe pipe)
  1212. {
  1213. int reg;
  1214. u32 val;
  1215. bool enabled;
  1216. reg = PCH_TRANSCONF(pipe);
  1217. val = I915_READ(reg);
  1218. enabled = !!(val & TRANS_ENABLE);
  1219. WARN(enabled,
  1220. "transcoder assertion failed, should be off on pipe %c but is still active\n",
  1221. pipe_name(pipe));
  1222. }
  1223. static bool dp_pipe_enabled(struct drm_i915_private *dev_priv,
  1224. enum pipe pipe, u32 port_sel, u32 val)
  1225. {
  1226. if ((val & DP_PORT_EN) == 0)
  1227. return false;
  1228. if (HAS_PCH_CPT(dev_priv->dev)) {
  1229. u32 trans_dp_ctl_reg = TRANS_DP_CTL(pipe);
  1230. u32 trans_dp_ctl = I915_READ(trans_dp_ctl_reg);
  1231. if ((trans_dp_ctl & TRANS_DP_PORT_SEL_MASK) != port_sel)
  1232. return false;
  1233. } else if (IS_CHERRYVIEW(dev_priv->dev)) {
  1234. if ((val & DP_PIPE_MASK_CHV) != DP_PIPE_SELECT_CHV(pipe))
  1235. return false;
  1236. } else {
  1237. if ((val & DP_PIPE_MASK) != (pipe << 30))
  1238. return false;
  1239. }
  1240. return true;
  1241. }
  1242. static bool hdmi_pipe_enabled(struct drm_i915_private *dev_priv,
  1243. enum pipe pipe, u32 val)
  1244. {
  1245. if ((val & SDVO_ENABLE) == 0)
  1246. return false;
  1247. if (HAS_PCH_CPT(dev_priv->dev)) {
  1248. if ((val & SDVO_PIPE_SEL_MASK_CPT) != SDVO_PIPE_SEL_CPT(pipe))
  1249. return false;
  1250. } else if (IS_CHERRYVIEW(dev_priv->dev)) {
  1251. if ((val & SDVO_PIPE_SEL_MASK_CHV) != SDVO_PIPE_SEL_CHV(pipe))
  1252. return false;
  1253. } else {
  1254. if ((val & SDVO_PIPE_SEL_MASK) != SDVO_PIPE_SEL(pipe))
  1255. return false;
  1256. }
  1257. return true;
  1258. }
  1259. static bool lvds_pipe_enabled(struct drm_i915_private *dev_priv,
  1260. enum pipe pipe, u32 val)
  1261. {
  1262. if ((val & LVDS_PORT_EN) == 0)
  1263. return false;
  1264. if (HAS_PCH_CPT(dev_priv->dev)) {
  1265. if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe))
  1266. return false;
  1267. } else {
  1268. if ((val & LVDS_PIPE_MASK) != LVDS_PIPE(pipe))
  1269. return false;
  1270. }
  1271. return true;
  1272. }
  1273. static bool adpa_pipe_enabled(struct drm_i915_private *dev_priv,
  1274. enum pipe pipe, u32 val)
  1275. {
  1276. if ((val & ADPA_DAC_ENABLE) == 0)
  1277. return false;
  1278. if (HAS_PCH_CPT(dev_priv->dev)) {
  1279. if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe))
  1280. return false;
  1281. } else {
  1282. if ((val & ADPA_PIPE_SELECT_MASK) != ADPA_PIPE_SELECT(pipe))
  1283. return false;
  1284. }
  1285. return true;
  1286. }
  1287. static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv,
  1288. enum pipe pipe, int reg, u32 port_sel)
  1289. {
  1290. u32 val = I915_READ(reg);
  1291. WARN(dp_pipe_enabled(dev_priv, pipe, port_sel, val),
  1292. "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n",
  1293. reg, pipe_name(pipe));
  1294. WARN(HAS_PCH_IBX(dev_priv->dev) && (val & DP_PORT_EN) == 0
  1295. && (val & DP_PIPEB_SELECT),
  1296. "IBX PCH dp port still using transcoder B\n");
  1297. }
  1298. static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv,
  1299. enum pipe pipe, int reg)
  1300. {
  1301. u32 val = I915_READ(reg);
  1302. WARN(hdmi_pipe_enabled(dev_priv, pipe, val),
  1303. "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n",
  1304. reg, pipe_name(pipe));
  1305. WARN(HAS_PCH_IBX(dev_priv->dev) && (val & SDVO_ENABLE) == 0
  1306. && (val & SDVO_PIPE_B_SELECT),
  1307. "IBX PCH hdmi port still using transcoder B\n");
  1308. }
  1309. static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv,
  1310. enum pipe pipe)
  1311. {
  1312. int reg;
  1313. u32 val;
  1314. assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_B, TRANS_DP_PORT_SEL_B);
  1315. assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_C, TRANS_DP_PORT_SEL_C);
  1316. assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_D, TRANS_DP_PORT_SEL_D);
  1317. reg = PCH_ADPA;
  1318. val = I915_READ(reg);
  1319. WARN(adpa_pipe_enabled(dev_priv, pipe, val),
  1320. "PCH VGA enabled on transcoder %c, should be disabled\n",
  1321. pipe_name(pipe));
  1322. reg = PCH_LVDS;
  1323. val = I915_READ(reg);
  1324. WARN(lvds_pipe_enabled(dev_priv, pipe, val),
  1325. "PCH LVDS enabled on transcoder %c, should be disabled\n",
  1326. pipe_name(pipe));
  1327. assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIB);
  1328. assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIC);
  1329. assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMID);
  1330. }
  1331. static void intel_init_dpio(struct drm_device *dev)
  1332. {
  1333. struct drm_i915_private *dev_priv = dev->dev_private;
  1334. if (!IS_VALLEYVIEW(dev))
  1335. return;
  1336. /*
  1337. * IOSF_PORT_DPIO is used for VLV x2 PHY (DP/HDMI B and C),
  1338. * CHV x1 PHY (DP/HDMI D)
  1339. * IOSF_PORT_DPIO_2 is used for CHV x2 PHY (DP/HDMI B and C)
  1340. */
  1341. if (IS_CHERRYVIEW(dev)) {
  1342. DPIO_PHY_IOSF_PORT(DPIO_PHY0) = IOSF_PORT_DPIO_2;
  1343. DPIO_PHY_IOSF_PORT(DPIO_PHY1) = IOSF_PORT_DPIO;
  1344. } else {
  1345. DPIO_PHY_IOSF_PORT(DPIO_PHY0) = IOSF_PORT_DPIO;
  1346. }
  1347. }
  1348. static void vlv_enable_pll(struct intel_crtc *crtc)
  1349. {
  1350. struct drm_device *dev = crtc->base.dev;
  1351. struct drm_i915_private *dev_priv = dev->dev_private;
  1352. int reg = DPLL(crtc->pipe);
  1353. u32 dpll = crtc->config.dpll_hw_state.dpll;
  1354. assert_pipe_disabled(dev_priv, crtc->pipe);
  1355. /* No really, not for ILK+ */
  1356. BUG_ON(!IS_VALLEYVIEW(dev_priv->dev));
  1357. /* PLL is protected by panel, make sure we can write it */
  1358. if (IS_MOBILE(dev_priv->dev))
  1359. assert_panel_unlocked(dev_priv, crtc->pipe);
  1360. I915_WRITE(reg, dpll);
  1361. POSTING_READ(reg);
  1362. udelay(150);
  1363. if (wait_for(((I915_READ(reg) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1))
  1364. DRM_ERROR("DPLL %d failed to lock\n", crtc->pipe);
  1365. I915_WRITE(DPLL_MD(crtc->pipe), crtc->config.dpll_hw_state.dpll_md);
  1366. POSTING_READ(DPLL_MD(crtc->pipe));
  1367. /* We do this three times for luck */
  1368. I915_WRITE(reg, dpll);
  1369. POSTING_READ(reg);
  1370. udelay(150); /* wait for warmup */
  1371. I915_WRITE(reg, dpll);
  1372. POSTING_READ(reg);
  1373. udelay(150); /* wait for warmup */
  1374. I915_WRITE(reg, dpll);
  1375. POSTING_READ(reg);
  1376. udelay(150); /* wait for warmup */
  1377. }
  1378. static void chv_enable_pll(struct intel_crtc *crtc)
  1379. {
  1380. struct drm_device *dev = crtc->base.dev;
  1381. struct drm_i915_private *dev_priv = dev->dev_private;
  1382. int pipe = crtc->pipe;
  1383. enum dpio_channel port = vlv_pipe_to_channel(pipe);
  1384. u32 tmp;
  1385. assert_pipe_disabled(dev_priv, crtc->pipe);
  1386. BUG_ON(!IS_CHERRYVIEW(dev_priv->dev));
  1387. mutex_lock(&dev_priv->dpio_lock);
  1388. /* Enable back the 10bit clock to display controller */
  1389. tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
  1390. tmp |= DPIO_DCLKP_EN;
  1391. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp);
  1392. /*
  1393. * Need to wait > 100ns between dclkp clock enable bit and PLL enable.
  1394. */
  1395. udelay(1);
  1396. /* Enable PLL */
  1397. I915_WRITE(DPLL(pipe), crtc->config.dpll_hw_state.dpll);
  1398. /* Check PLL is locked */
  1399. if (wait_for(((I915_READ(DPLL(pipe)) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1))
  1400. DRM_ERROR("PLL %d failed to lock\n", pipe);
  1401. /* not sure when this should be written */
  1402. I915_WRITE(DPLL_MD(pipe), crtc->config.dpll_hw_state.dpll_md);
  1403. POSTING_READ(DPLL_MD(pipe));
  1404. mutex_unlock(&dev_priv->dpio_lock);
  1405. }
  1406. static int intel_num_dvo_pipes(struct drm_device *dev)
  1407. {
  1408. struct intel_crtc *crtc;
  1409. int count = 0;
  1410. for_each_intel_crtc(dev, crtc)
  1411. count += crtc->active &&
  1412. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DVO);
  1413. return count;
  1414. }
  1415. static void i9xx_enable_pll(struct intel_crtc *crtc)
  1416. {
  1417. struct drm_device *dev = crtc->base.dev;
  1418. struct drm_i915_private *dev_priv = dev->dev_private;
  1419. int reg = DPLL(crtc->pipe);
  1420. u32 dpll = crtc->config.dpll_hw_state.dpll;
  1421. assert_pipe_disabled(dev_priv, crtc->pipe);
  1422. /* No really, not for ILK+ */
  1423. BUG_ON(INTEL_INFO(dev)->gen >= 5);
  1424. /* PLL is protected by panel, make sure we can write it */
  1425. if (IS_MOBILE(dev) && !IS_I830(dev))
  1426. assert_panel_unlocked(dev_priv, crtc->pipe);
  1427. /* Enable DVO 2x clock on both PLLs if necessary */
  1428. if (IS_I830(dev) && intel_num_dvo_pipes(dev) > 0) {
  1429. /*
  1430. * It appears to be important that we don't enable this
  1431. * for the current pipe before otherwise configuring the
  1432. * PLL. No idea how this should be handled if multiple
  1433. * DVO outputs are enabled simultaneosly.
  1434. */
  1435. dpll |= DPLL_DVO_2X_MODE;
  1436. I915_WRITE(DPLL(!crtc->pipe),
  1437. I915_READ(DPLL(!crtc->pipe)) | DPLL_DVO_2X_MODE);
  1438. }
  1439. /* Wait for the clocks to stabilize. */
  1440. POSTING_READ(reg);
  1441. udelay(150);
  1442. if (INTEL_INFO(dev)->gen >= 4) {
  1443. I915_WRITE(DPLL_MD(crtc->pipe),
  1444. crtc->config.dpll_hw_state.dpll_md);
  1445. } else {
  1446. /* The pixel multiplier can only be updated once the
  1447. * DPLL is enabled and the clocks are stable.
  1448. *
  1449. * So write it again.
  1450. */
  1451. I915_WRITE(reg, dpll);
  1452. }
  1453. /* We do this three times for luck */
  1454. I915_WRITE(reg, dpll);
  1455. POSTING_READ(reg);
  1456. udelay(150); /* wait for warmup */
  1457. I915_WRITE(reg, dpll);
  1458. POSTING_READ(reg);
  1459. udelay(150); /* wait for warmup */
  1460. I915_WRITE(reg, dpll);
  1461. POSTING_READ(reg);
  1462. udelay(150); /* wait for warmup */
  1463. }
  1464. /**
  1465. * i9xx_disable_pll - disable a PLL
  1466. * @dev_priv: i915 private structure
  1467. * @pipe: pipe PLL to disable
  1468. *
  1469. * Disable the PLL for @pipe, making sure the pipe is off first.
  1470. *
  1471. * Note! This is for pre-ILK only.
  1472. */
  1473. static void i9xx_disable_pll(struct intel_crtc *crtc)
  1474. {
  1475. struct drm_device *dev = crtc->base.dev;
  1476. struct drm_i915_private *dev_priv = dev->dev_private;
  1477. enum pipe pipe = crtc->pipe;
  1478. /* Disable DVO 2x clock on both PLLs if necessary */
  1479. if (IS_I830(dev) &&
  1480. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DVO) &&
  1481. intel_num_dvo_pipes(dev) == 1) {
  1482. I915_WRITE(DPLL(PIPE_B),
  1483. I915_READ(DPLL(PIPE_B)) & ~DPLL_DVO_2X_MODE);
  1484. I915_WRITE(DPLL(PIPE_A),
  1485. I915_READ(DPLL(PIPE_A)) & ~DPLL_DVO_2X_MODE);
  1486. }
  1487. /* Don't disable pipe or pipe PLLs if needed */
  1488. if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) ||
  1489. (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))
  1490. return;
  1491. /* Make sure the pipe isn't still relying on us */
  1492. assert_pipe_disabled(dev_priv, pipe);
  1493. I915_WRITE(DPLL(pipe), 0);
  1494. POSTING_READ(DPLL(pipe));
  1495. }
  1496. static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
  1497. {
  1498. u32 val = 0;
  1499. /* Make sure the pipe isn't still relying on us */
  1500. assert_pipe_disabled(dev_priv, pipe);
  1501. /*
  1502. * Leave integrated clock source and reference clock enabled for pipe B.
  1503. * The latter is needed for VGA hotplug / manual detection.
  1504. */
  1505. if (pipe == PIPE_B)
  1506. val = DPLL_INTEGRATED_CRI_CLK_VLV | DPLL_REFA_CLK_ENABLE_VLV;
  1507. I915_WRITE(DPLL(pipe), val);
  1508. POSTING_READ(DPLL(pipe));
  1509. }
  1510. static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
  1511. {
  1512. enum dpio_channel port = vlv_pipe_to_channel(pipe);
  1513. u32 val;
  1514. /* Make sure the pipe isn't still relying on us */
  1515. assert_pipe_disabled(dev_priv, pipe);
  1516. /* Set PLL en = 0 */
  1517. val = DPLL_SSC_REF_CLOCK_CHV | DPLL_REFA_CLK_ENABLE_VLV;
  1518. if (pipe != PIPE_A)
  1519. val |= DPLL_INTEGRATED_CRI_CLK_VLV;
  1520. I915_WRITE(DPLL(pipe), val);
  1521. POSTING_READ(DPLL(pipe));
  1522. mutex_lock(&dev_priv->dpio_lock);
  1523. /* Disable 10bit clock to display controller */
  1524. val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
  1525. val &= ~DPIO_DCLKP_EN;
  1526. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val);
  1527. /* disable left/right clock distribution */
  1528. if (pipe != PIPE_B) {
  1529. val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW5_CH0);
  1530. val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK);
  1531. vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW5_CH0, val);
  1532. } else {
  1533. val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW1_CH1);
  1534. val &= ~(CHV_BUFLEFTENA2_MASK | CHV_BUFRIGHTENA2_MASK);
  1535. vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW1_CH1, val);
  1536. }
  1537. mutex_unlock(&dev_priv->dpio_lock);
  1538. }
  1539. void vlv_wait_port_ready(struct drm_i915_private *dev_priv,
  1540. struct intel_digital_port *dport)
  1541. {
  1542. u32 port_mask;
  1543. int dpll_reg;
  1544. switch (dport->port) {
  1545. case PORT_B:
  1546. port_mask = DPLL_PORTB_READY_MASK;
  1547. dpll_reg = DPLL(0);
  1548. break;
  1549. case PORT_C:
  1550. port_mask = DPLL_PORTC_READY_MASK;
  1551. dpll_reg = DPLL(0);
  1552. break;
  1553. case PORT_D:
  1554. port_mask = DPLL_PORTD_READY_MASK;
  1555. dpll_reg = DPIO_PHY_STATUS;
  1556. break;
  1557. default:
  1558. BUG();
  1559. }
  1560. if (wait_for((I915_READ(dpll_reg) & port_mask) == 0, 1000))
  1561. WARN(1, "timed out waiting for port %c ready: 0x%08x\n",
  1562. port_name(dport->port), I915_READ(dpll_reg));
  1563. }
  1564. static void intel_prepare_shared_dpll(struct intel_crtc *crtc)
  1565. {
  1566. struct drm_device *dev = crtc->base.dev;
  1567. struct drm_i915_private *dev_priv = dev->dev_private;
  1568. struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
  1569. if (WARN_ON(pll == NULL))
  1570. return;
  1571. WARN_ON(!pll->refcount);
  1572. if (pll->active == 0) {
  1573. DRM_DEBUG_DRIVER("setting up %s\n", pll->name);
  1574. WARN_ON(pll->on);
  1575. assert_shared_dpll_disabled(dev_priv, pll);
  1576. pll->mode_set(dev_priv, pll);
  1577. }
  1578. }
  1579. /**
  1580. * intel_enable_shared_dpll - enable PCH PLL
  1581. * @dev_priv: i915 private structure
  1582. * @pipe: pipe PLL to enable
  1583. *
  1584. * The PCH PLL needs to be enabled before the PCH transcoder, since it
  1585. * drives the transcoder clock.
  1586. */
  1587. static void intel_enable_shared_dpll(struct intel_crtc *crtc)
  1588. {
  1589. struct drm_device *dev = crtc->base.dev;
  1590. struct drm_i915_private *dev_priv = dev->dev_private;
  1591. struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
  1592. if (WARN_ON(pll == NULL))
  1593. return;
  1594. if (WARN_ON(pll->refcount == 0))
  1595. return;
  1596. DRM_DEBUG_KMS("enable %s (active %d, on? %d) for crtc %d\n",
  1597. pll->name, pll->active, pll->on,
  1598. crtc->base.base.id);
  1599. if (pll->active++) {
  1600. WARN_ON(!pll->on);
  1601. assert_shared_dpll_enabled(dev_priv, pll);
  1602. return;
  1603. }
  1604. WARN_ON(pll->on);
  1605. intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS);
  1606. DRM_DEBUG_KMS("enabling %s\n", pll->name);
  1607. pll->enable(dev_priv, pll);
  1608. pll->on = true;
  1609. }
  1610. static void intel_disable_shared_dpll(struct intel_crtc *crtc)
  1611. {
  1612. struct drm_device *dev = crtc->base.dev;
  1613. struct drm_i915_private *dev_priv = dev->dev_private;
  1614. struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
  1615. /* PCH only available on ILK+ */
  1616. BUG_ON(INTEL_INFO(dev)->gen < 5);
  1617. if (WARN_ON(pll == NULL))
  1618. return;
  1619. if (WARN_ON(pll->refcount == 0))
  1620. return;
  1621. DRM_DEBUG_KMS("disable %s (active %d, on? %d) for crtc %d\n",
  1622. pll->name, pll->active, pll->on,
  1623. crtc->base.base.id);
  1624. if (WARN_ON(pll->active == 0)) {
  1625. assert_shared_dpll_disabled(dev_priv, pll);
  1626. return;
  1627. }
  1628. assert_shared_dpll_enabled(dev_priv, pll);
  1629. WARN_ON(!pll->on);
  1630. if (--pll->active)
  1631. return;
  1632. DRM_DEBUG_KMS("disabling %s\n", pll->name);
  1633. pll->disable(dev_priv, pll);
  1634. pll->on = false;
  1635. intel_display_power_put(dev_priv, POWER_DOMAIN_PLLS);
  1636. }
  1637. static void ironlake_enable_pch_transcoder(struct drm_i915_private *dev_priv,
  1638. enum pipe pipe)
  1639. {
  1640. struct drm_device *dev = dev_priv->dev;
  1641. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  1642. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1643. uint32_t reg, val, pipeconf_val;
  1644. /* PCH only available on ILK+ */
  1645. BUG_ON(!HAS_PCH_SPLIT(dev));
  1646. /* Make sure PCH DPLL is enabled */
  1647. assert_shared_dpll_enabled(dev_priv,
  1648. intel_crtc_to_shared_dpll(intel_crtc));
  1649. /* FDI must be feeding us bits for PCH ports */
  1650. assert_fdi_tx_enabled(dev_priv, pipe);
  1651. assert_fdi_rx_enabled(dev_priv, pipe);
  1652. if (HAS_PCH_CPT(dev)) {
  1653. /* Workaround: Set the timing override bit before enabling the
  1654. * pch transcoder. */
  1655. reg = TRANS_CHICKEN2(pipe);
  1656. val = I915_READ(reg);
  1657. val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
  1658. I915_WRITE(reg, val);
  1659. }
  1660. reg = PCH_TRANSCONF(pipe);
  1661. val = I915_READ(reg);
  1662. pipeconf_val = I915_READ(PIPECONF(pipe));
  1663. if (HAS_PCH_IBX(dev_priv->dev)) {
  1664. /*
  1665. * make the BPC in transcoder be consistent with
  1666. * that in pipeconf reg.
  1667. */
  1668. val &= ~PIPECONF_BPC_MASK;
  1669. val |= pipeconf_val & PIPECONF_BPC_MASK;
  1670. }
  1671. val &= ~TRANS_INTERLACE_MASK;
  1672. if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK)
  1673. if (HAS_PCH_IBX(dev_priv->dev) &&
  1674. intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO))
  1675. val |= TRANS_LEGACY_INTERLACED_ILK;
  1676. else
  1677. val |= TRANS_INTERLACED;
  1678. else
  1679. val |= TRANS_PROGRESSIVE;
  1680. I915_WRITE(reg, val | TRANS_ENABLE);
  1681. if (wait_for(I915_READ(reg) & TRANS_STATE_ENABLE, 100))
  1682. DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe));
  1683. }
  1684. static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv,
  1685. enum transcoder cpu_transcoder)
  1686. {
  1687. u32 val, pipeconf_val;
  1688. /* PCH only available on ILK+ */
  1689. BUG_ON(!HAS_PCH_SPLIT(dev_priv->dev));
  1690. /* FDI must be feeding us bits for PCH ports */
  1691. assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder);
  1692. assert_fdi_rx_enabled(dev_priv, TRANSCODER_A);
  1693. /* Workaround: set timing override bit. */
  1694. val = I915_READ(_TRANSA_CHICKEN2);
  1695. val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
  1696. I915_WRITE(_TRANSA_CHICKEN2, val);
  1697. val = TRANS_ENABLE;
  1698. pipeconf_val = I915_READ(PIPECONF(cpu_transcoder));
  1699. if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) ==
  1700. PIPECONF_INTERLACED_ILK)
  1701. val |= TRANS_INTERLACED;
  1702. else
  1703. val |= TRANS_PROGRESSIVE;
  1704. I915_WRITE(LPT_TRANSCONF, val);
  1705. if (wait_for(I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE, 100))
  1706. DRM_ERROR("Failed to enable PCH transcoder\n");
  1707. }
  1708. static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv,
  1709. enum pipe pipe)
  1710. {
  1711. struct drm_device *dev = dev_priv->dev;
  1712. uint32_t reg, val;
  1713. /* FDI relies on the transcoder */
  1714. assert_fdi_tx_disabled(dev_priv, pipe);
  1715. assert_fdi_rx_disabled(dev_priv, pipe);
  1716. /* Ports must be off as well */
  1717. assert_pch_ports_disabled(dev_priv, pipe);
  1718. reg = PCH_TRANSCONF(pipe);
  1719. val = I915_READ(reg);
  1720. val &= ~TRANS_ENABLE;
  1721. I915_WRITE(reg, val);
  1722. /* wait for PCH transcoder off, transcoder state */
  1723. if (wait_for((I915_READ(reg) & TRANS_STATE_ENABLE) == 0, 50))
  1724. DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe));
  1725. if (!HAS_PCH_IBX(dev)) {
  1726. /* Workaround: Clear the timing override chicken bit again. */
  1727. reg = TRANS_CHICKEN2(pipe);
  1728. val = I915_READ(reg);
  1729. val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
  1730. I915_WRITE(reg, val);
  1731. }
  1732. }
  1733. static void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv)
  1734. {
  1735. u32 val;
  1736. val = I915_READ(LPT_TRANSCONF);
  1737. val &= ~TRANS_ENABLE;
  1738. I915_WRITE(LPT_TRANSCONF, val);
  1739. /* wait for PCH transcoder off, transcoder state */
  1740. if (wait_for((I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE) == 0, 50))
  1741. DRM_ERROR("Failed to disable PCH transcoder\n");
  1742. /* Workaround: clear timing override bit. */
  1743. val = I915_READ(_TRANSA_CHICKEN2);
  1744. val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
  1745. I915_WRITE(_TRANSA_CHICKEN2, val);
  1746. }
  1747. /**
  1748. * intel_enable_pipe - enable a pipe, asserting requirements
  1749. * @crtc: crtc responsible for the pipe
  1750. *
  1751. * Enable @crtc's pipe, making sure that various hardware specific requirements
  1752. * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc.
  1753. */
  1754. static void intel_enable_pipe(struct intel_crtc *crtc)
  1755. {
  1756. struct drm_device *dev = crtc->base.dev;
  1757. struct drm_i915_private *dev_priv = dev->dev_private;
  1758. enum pipe pipe = crtc->pipe;
  1759. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  1760. pipe);
  1761. enum pipe pch_transcoder;
  1762. int reg;
  1763. u32 val;
  1764. assert_planes_disabled(dev_priv, pipe);
  1765. assert_cursor_disabled(dev_priv, pipe);
  1766. assert_sprites_disabled(dev_priv, pipe);
  1767. if (HAS_PCH_LPT(dev_priv->dev))
  1768. pch_transcoder = TRANSCODER_A;
  1769. else
  1770. pch_transcoder = pipe;
  1771. /*
  1772. * A pipe without a PLL won't actually be able to drive bits from
  1773. * a plane. On ILK+ the pipe PLLs are integrated, so we don't
  1774. * need the check.
  1775. */
  1776. if (!HAS_PCH_SPLIT(dev_priv->dev))
  1777. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DSI))
  1778. assert_dsi_pll_enabled(dev_priv);
  1779. else
  1780. assert_pll_enabled(dev_priv, pipe);
  1781. else {
  1782. if (crtc->config.has_pch_encoder) {
  1783. /* if driving the PCH, we need FDI enabled */
  1784. assert_fdi_rx_pll_enabled(dev_priv, pch_transcoder);
  1785. assert_fdi_tx_pll_enabled(dev_priv,
  1786. (enum pipe) cpu_transcoder);
  1787. }
  1788. /* FIXME: assert CPU port conditions for SNB+ */
  1789. }
  1790. reg = PIPECONF(cpu_transcoder);
  1791. val = I915_READ(reg);
  1792. if (val & PIPECONF_ENABLE) {
  1793. WARN_ON(!((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) ||
  1794. (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)));
  1795. return;
  1796. }
  1797. I915_WRITE(reg, val | PIPECONF_ENABLE);
  1798. POSTING_READ(reg);
  1799. }
  1800. /**
  1801. * intel_disable_pipe - disable a pipe, asserting requirements
  1802. * @crtc: crtc whose pipes is to be disabled
  1803. *
  1804. * Disable the pipe of @crtc, making sure that various hardware
  1805. * specific requirements are met, if applicable, e.g. plane
  1806. * disabled, panel fitter off, etc.
  1807. *
  1808. * Will wait until the pipe has shut down before returning.
  1809. */
  1810. static void intel_disable_pipe(struct intel_crtc *crtc)
  1811. {
  1812. struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
  1813. enum transcoder cpu_transcoder = crtc->config.cpu_transcoder;
  1814. enum pipe pipe = crtc->pipe;
  1815. int reg;
  1816. u32 val;
  1817. /*
  1818. * Make sure planes won't keep trying to pump pixels to us,
  1819. * or we might hang the display.
  1820. */
  1821. assert_planes_disabled(dev_priv, pipe);
  1822. assert_cursor_disabled(dev_priv, pipe);
  1823. assert_sprites_disabled(dev_priv, pipe);
  1824. reg = PIPECONF(cpu_transcoder);
  1825. val = I915_READ(reg);
  1826. if ((val & PIPECONF_ENABLE) == 0)
  1827. return;
  1828. /*
  1829. * Double wide has implications for planes
  1830. * so best keep it disabled when not needed.
  1831. */
  1832. if (crtc->config.double_wide)
  1833. val &= ~PIPECONF_DOUBLE_WIDE;
  1834. /* Don't disable pipe or pipe PLLs if needed */
  1835. if (!(pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) &&
  1836. !(pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))
  1837. val &= ~PIPECONF_ENABLE;
  1838. I915_WRITE(reg, val);
  1839. if ((val & PIPECONF_ENABLE) == 0)
  1840. intel_wait_for_pipe_off(crtc);
  1841. }
  1842. /*
  1843. * Plane regs are double buffered, going from enabled->disabled needs a
  1844. * trigger in order to latch. The display address reg provides this.
  1845. */
  1846. void intel_flush_primary_plane(struct drm_i915_private *dev_priv,
  1847. enum plane plane)
  1848. {
  1849. struct drm_device *dev = dev_priv->dev;
  1850. u32 reg = INTEL_INFO(dev)->gen >= 4 ? DSPSURF(plane) : DSPADDR(plane);
  1851. I915_WRITE(reg, I915_READ(reg));
  1852. POSTING_READ(reg);
  1853. }
  1854. /**
  1855. * intel_enable_primary_hw_plane - enable the primary plane on a given pipe
  1856. * @plane: plane to be enabled
  1857. * @crtc: crtc for the plane
  1858. *
  1859. * Enable @plane on @crtc, making sure that the pipe is running first.
  1860. */
  1861. static void intel_enable_primary_hw_plane(struct drm_plane *plane,
  1862. struct drm_crtc *crtc)
  1863. {
  1864. struct drm_device *dev = plane->dev;
  1865. struct drm_i915_private *dev_priv = dev->dev_private;
  1866. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1867. /* If the pipe isn't enabled, we can't pump pixels and may hang */
  1868. assert_pipe_enabled(dev_priv, intel_crtc->pipe);
  1869. if (intel_crtc->primary_enabled)
  1870. return;
  1871. intel_crtc->primary_enabled = true;
  1872. dev_priv->display.update_primary_plane(crtc, plane->fb,
  1873. crtc->x, crtc->y);
  1874. /*
  1875. * BDW signals flip done immediately if the plane
  1876. * is disabled, even if the plane enable is already
  1877. * armed to occur at the next vblank :(
  1878. */
  1879. if (IS_BROADWELL(dev))
  1880. intel_wait_for_vblank(dev, intel_crtc->pipe);
  1881. }
  1882. /**
  1883. * intel_disable_primary_hw_plane - disable the primary hardware plane
  1884. * @plane: plane to be disabled
  1885. * @crtc: crtc for the plane
  1886. *
  1887. * Disable @plane on @crtc, making sure that the pipe is running first.
  1888. */
  1889. static void intel_disable_primary_hw_plane(struct drm_plane *plane,
  1890. struct drm_crtc *crtc)
  1891. {
  1892. struct drm_device *dev = plane->dev;
  1893. struct drm_i915_private *dev_priv = dev->dev_private;
  1894. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1895. assert_pipe_enabled(dev_priv, intel_crtc->pipe);
  1896. if (!intel_crtc->primary_enabled)
  1897. return;
  1898. intel_crtc->primary_enabled = false;
  1899. dev_priv->display.update_primary_plane(crtc, plane->fb,
  1900. crtc->x, crtc->y);
  1901. }
  1902. static bool need_vtd_wa(struct drm_device *dev)
  1903. {
  1904. #ifdef CONFIG_INTEL_IOMMU
  1905. if (INTEL_INFO(dev)->gen >= 6 && intel_iommu_gfx_mapped)
  1906. return true;
  1907. #endif
  1908. return false;
  1909. }
  1910. static int intel_align_height(struct drm_device *dev, int height, bool tiled)
  1911. {
  1912. int tile_height;
  1913. tile_height = tiled ? (IS_GEN2(dev) ? 16 : 8) : 1;
  1914. return ALIGN(height, tile_height);
  1915. }
  1916. int
  1917. intel_pin_and_fence_fb_obj(struct drm_device *dev,
  1918. struct drm_i915_gem_object *obj,
  1919. struct intel_engine_cs *pipelined)
  1920. {
  1921. struct drm_i915_private *dev_priv = dev->dev_private;
  1922. u32 alignment;
  1923. int ret;
  1924. WARN_ON(!mutex_is_locked(&dev->struct_mutex));
  1925. switch (obj->tiling_mode) {
  1926. case I915_TILING_NONE:
  1927. if (IS_BROADWATER(dev) || IS_CRESTLINE(dev))
  1928. alignment = 128 * 1024;
  1929. else if (INTEL_INFO(dev)->gen >= 4)
  1930. alignment = 4 * 1024;
  1931. else
  1932. alignment = 64 * 1024;
  1933. break;
  1934. case I915_TILING_X:
  1935. /* pin() will align the object as required by fence */
  1936. alignment = 0;
  1937. break;
  1938. case I915_TILING_Y:
  1939. WARN(1, "Y tiled bo slipped through, driver bug!\n");
  1940. return -EINVAL;
  1941. default:
  1942. BUG();
  1943. }
  1944. /* Note that the w/a also requires 64 PTE of padding following the
  1945. * bo. We currently fill all unused PTE with the shadow page and so
  1946. * we should always have valid PTE following the scanout preventing
  1947. * the VT-d warning.
  1948. */
  1949. if (need_vtd_wa(dev) && alignment < 256 * 1024)
  1950. alignment = 256 * 1024;
  1951. /*
  1952. * Global gtt pte registers are special registers which actually forward
  1953. * writes to a chunk of system memory. Which means that there is no risk
  1954. * that the register values disappear as soon as we call
  1955. * intel_runtime_pm_put(), so it is correct to wrap only the
  1956. * pin/unpin/fence and not more.
  1957. */
  1958. intel_runtime_pm_get(dev_priv);
  1959. dev_priv->mm.interruptible = false;
  1960. ret = i915_gem_object_pin_to_display_plane(obj, alignment, pipelined);
  1961. if (ret)
  1962. goto err_interruptible;
  1963. /* Install a fence for tiled scan-out. Pre-i965 always needs a
  1964. * fence, whereas 965+ only requires a fence if using
  1965. * framebuffer compression. For simplicity, we always install
  1966. * a fence as the cost is not that onerous.
  1967. */
  1968. ret = i915_gem_object_get_fence(obj);
  1969. if (ret)
  1970. goto err_unpin;
  1971. i915_gem_object_pin_fence(obj);
  1972. dev_priv->mm.interruptible = true;
  1973. intel_runtime_pm_put(dev_priv);
  1974. return 0;
  1975. err_unpin:
  1976. i915_gem_object_unpin_from_display_plane(obj);
  1977. err_interruptible:
  1978. dev_priv->mm.interruptible = true;
  1979. intel_runtime_pm_put(dev_priv);
  1980. return ret;
  1981. }
  1982. void intel_unpin_fb_obj(struct drm_i915_gem_object *obj)
  1983. {
  1984. WARN_ON(!mutex_is_locked(&obj->base.dev->struct_mutex));
  1985. i915_gem_object_unpin_fence(obj);
  1986. i915_gem_object_unpin_from_display_plane(obj);
  1987. }
  1988. /* Computes the linear offset to the base tile and adjusts x, y. bytes per pixel
  1989. * is assumed to be a power-of-two. */
  1990. unsigned long intel_gen4_compute_page_offset(int *x, int *y,
  1991. unsigned int tiling_mode,
  1992. unsigned int cpp,
  1993. unsigned int pitch)
  1994. {
  1995. if (tiling_mode != I915_TILING_NONE) {
  1996. unsigned int tile_rows, tiles;
  1997. tile_rows = *y / 8;
  1998. *y %= 8;
  1999. tiles = *x / (512/cpp);
  2000. *x %= 512/cpp;
  2001. return tile_rows * pitch * 8 + tiles * 4096;
  2002. } else {
  2003. unsigned int offset;
  2004. offset = *y * pitch + *x * cpp;
  2005. *y = 0;
  2006. *x = (offset & 4095) / cpp;
  2007. return offset & -4096;
  2008. }
  2009. }
  2010. int intel_format_to_fourcc(int format)
  2011. {
  2012. switch (format) {
  2013. case DISPPLANE_8BPP:
  2014. return DRM_FORMAT_C8;
  2015. case DISPPLANE_BGRX555:
  2016. return DRM_FORMAT_XRGB1555;
  2017. case DISPPLANE_BGRX565:
  2018. return DRM_FORMAT_RGB565;
  2019. default:
  2020. case DISPPLANE_BGRX888:
  2021. return DRM_FORMAT_XRGB8888;
  2022. case DISPPLANE_RGBX888:
  2023. return DRM_FORMAT_XBGR8888;
  2024. case DISPPLANE_BGRX101010:
  2025. return DRM_FORMAT_XRGB2101010;
  2026. case DISPPLANE_RGBX101010:
  2027. return DRM_FORMAT_XBGR2101010;
  2028. }
  2029. }
  2030. static bool intel_alloc_plane_obj(struct intel_crtc *crtc,
  2031. struct intel_plane_config *plane_config)
  2032. {
  2033. struct drm_device *dev = crtc->base.dev;
  2034. struct drm_i915_gem_object *obj = NULL;
  2035. struct drm_mode_fb_cmd2 mode_cmd = { 0 };
  2036. u32 base = plane_config->base;
  2037. if (plane_config->size == 0)
  2038. return false;
  2039. obj = i915_gem_object_create_stolen_for_preallocated(dev, base, base,
  2040. plane_config->size);
  2041. if (!obj)
  2042. return false;
  2043. if (plane_config->tiled) {
  2044. obj->tiling_mode = I915_TILING_X;
  2045. obj->stride = crtc->base.primary->fb->pitches[0];
  2046. }
  2047. mode_cmd.pixel_format = crtc->base.primary->fb->pixel_format;
  2048. mode_cmd.width = crtc->base.primary->fb->width;
  2049. mode_cmd.height = crtc->base.primary->fb->height;
  2050. mode_cmd.pitches[0] = crtc->base.primary->fb->pitches[0];
  2051. mutex_lock(&dev->struct_mutex);
  2052. if (intel_framebuffer_init(dev, to_intel_framebuffer(crtc->base.primary->fb),
  2053. &mode_cmd, obj)) {
  2054. DRM_DEBUG_KMS("intel fb init failed\n");
  2055. goto out_unref_obj;
  2056. }
  2057. obj->frontbuffer_bits = INTEL_FRONTBUFFER_PRIMARY(crtc->pipe);
  2058. mutex_unlock(&dev->struct_mutex);
  2059. DRM_DEBUG_KMS("plane fb obj %p\n", obj);
  2060. return true;
  2061. out_unref_obj:
  2062. drm_gem_object_unreference(&obj->base);
  2063. mutex_unlock(&dev->struct_mutex);
  2064. return false;
  2065. }
  2066. static void intel_find_plane_obj(struct intel_crtc *intel_crtc,
  2067. struct intel_plane_config *plane_config)
  2068. {
  2069. struct drm_device *dev = intel_crtc->base.dev;
  2070. struct drm_crtc *c;
  2071. struct intel_crtc *i;
  2072. struct drm_i915_gem_object *obj;
  2073. if (!intel_crtc->base.primary->fb)
  2074. return;
  2075. if (intel_alloc_plane_obj(intel_crtc, plane_config))
  2076. return;
  2077. kfree(intel_crtc->base.primary->fb);
  2078. intel_crtc->base.primary->fb = NULL;
  2079. /*
  2080. * Failed to alloc the obj, check to see if we should share
  2081. * an fb with another CRTC instead
  2082. */
  2083. for_each_crtc(dev, c) {
  2084. i = to_intel_crtc(c);
  2085. if (c == &intel_crtc->base)
  2086. continue;
  2087. if (!i->active)
  2088. continue;
  2089. obj = intel_fb_obj(c->primary->fb);
  2090. if (obj == NULL)
  2091. continue;
  2092. if (i915_gem_obj_ggtt_offset(obj) == plane_config->base) {
  2093. drm_framebuffer_reference(c->primary->fb);
  2094. intel_crtc->base.primary->fb = c->primary->fb;
  2095. obj->frontbuffer_bits |= INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe);
  2096. break;
  2097. }
  2098. }
  2099. }
  2100. static void i9xx_update_primary_plane(struct drm_crtc *crtc,
  2101. struct drm_framebuffer *fb,
  2102. int x, int y)
  2103. {
  2104. struct drm_device *dev = crtc->dev;
  2105. struct drm_i915_private *dev_priv = dev->dev_private;
  2106. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2107. struct drm_i915_gem_object *obj;
  2108. int plane = intel_crtc->plane;
  2109. unsigned long linear_offset;
  2110. u32 dspcntr;
  2111. u32 reg = DSPCNTR(plane);
  2112. int pixel_size;
  2113. if (!intel_crtc->primary_enabled) {
  2114. I915_WRITE(reg, 0);
  2115. if (INTEL_INFO(dev)->gen >= 4)
  2116. I915_WRITE(DSPSURF(plane), 0);
  2117. else
  2118. I915_WRITE(DSPADDR(plane), 0);
  2119. POSTING_READ(reg);
  2120. return;
  2121. }
  2122. obj = intel_fb_obj(fb);
  2123. if (WARN_ON(obj == NULL))
  2124. return;
  2125. pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
  2126. dspcntr = DISPPLANE_GAMMA_ENABLE;
  2127. dspcntr |= DISPLAY_PLANE_ENABLE;
  2128. if (INTEL_INFO(dev)->gen < 4) {
  2129. if (intel_crtc->pipe == PIPE_B)
  2130. dspcntr |= DISPPLANE_SEL_PIPE_B;
  2131. /* pipesrc and dspsize control the size that is scaled from,
  2132. * which should always be the user's requested size.
  2133. */
  2134. I915_WRITE(DSPSIZE(plane),
  2135. ((intel_crtc->config.pipe_src_h - 1) << 16) |
  2136. (intel_crtc->config.pipe_src_w - 1));
  2137. I915_WRITE(DSPPOS(plane), 0);
  2138. }
  2139. switch (fb->pixel_format) {
  2140. case DRM_FORMAT_C8:
  2141. dspcntr |= DISPPLANE_8BPP;
  2142. break;
  2143. case DRM_FORMAT_XRGB1555:
  2144. case DRM_FORMAT_ARGB1555:
  2145. dspcntr |= DISPPLANE_BGRX555;
  2146. break;
  2147. case DRM_FORMAT_RGB565:
  2148. dspcntr |= DISPPLANE_BGRX565;
  2149. break;
  2150. case DRM_FORMAT_XRGB8888:
  2151. case DRM_FORMAT_ARGB8888:
  2152. dspcntr |= DISPPLANE_BGRX888;
  2153. break;
  2154. case DRM_FORMAT_XBGR8888:
  2155. case DRM_FORMAT_ABGR8888:
  2156. dspcntr |= DISPPLANE_RGBX888;
  2157. break;
  2158. case DRM_FORMAT_XRGB2101010:
  2159. case DRM_FORMAT_ARGB2101010:
  2160. dspcntr |= DISPPLANE_BGRX101010;
  2161. break;
  2162. case DRM_FORMAT_XBGR2101010:
  2163. case DRM_FORMAT_ABGR2101010:
  2164. dspcntr |= DISPPLANE_RGBX101010;
  2165. break;
  2166. default:
  2167. BUG();
  2168. }
  2169. if (INTEL_INFO(dev)->gen >= 4 &&
  2170. obj->tiling_mode != I915_TILING_NONE)
  2171. dspcntr |= DISPPLANE_TILED;
  2172. if (IS_G4X(dev))
  2173. dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
  2174. linear_offset = y * fb->pitches[0] + x * pixel_size;
  2175. if (INTEL_INFO(dev)->gen >= 4) {
  2176. intel_crtc->dspaddr_offset =
  2177. intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
  2178. pixel_size,
  2179. fb->pitches[0]);
  2180. linear_offset -= intel_crtc->dspaddr_offset;
  2181. } else {
  2182. intel_crtc->dspaddr_offset = linear_offset;
  2183. }
  2184. if (to_intel_plane(crtc->primary)->rotation == BIT(DRM_ROTATE_180)) {
  2185. dspcntr |= DISPPLANE_ROTATE_180;
  2186. x += (intel_crtc->config.pipe_src_w - 1);
  2187. y += (intel_crtc->config.pipe_src_h - 1);
  2188. /* Finding the last pixel of the last line of the display
  2189. data and adding to linear_offset*/
  2190. linear_offset +=
  2191. (intel_crtc->config.pipe_src_h - 1) * fb->pitches[0] +
  2192. (intel_crtc->config.pipe_src_w - 1) * pixel_size;
  2193. }
  2194. I915_WRITE(reg, dspcntr);
  2195. DRM_DEBUG_KMS("Writing base %08lX %08lX %d %d %d\n",
  2196. i915_gem_obj_ggtt_offset(obj), linear_offset, x, y,
  2197. fb->pitches[0]);
  2198. I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]);
  2199. if (INTEL_INFO(dev)->gen >= 4) {
  2200. I915_WRITE(DSPSURF(plane),
  2201. i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset);
  2202. I915_WRITE(DSPTILEOFF(plane), (y << 16) | x);
  2203. I915_WRITE(DSPLINOFF(plane), linear_offset);
  2204. } else
  2205. I915_WRITE(DSPADDR(plane), i915_gem_obj_ggtt_offset(obj) + linear_offset);
  2206. POSTING_READ(reg);
  2207. }
  2208. static void ironlake_update_primary_plane(struct drm_crtc *crtc,
  2209. struct drm_framebuffer *fb,
  2210. int x, int y)
  2211. {
  2212. struct drm_device *dev = crtc->dev;
  2213. struct drm_i915_private *dev_priv = dev->dev_private;
  2214. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2215. struct drm_i915_gem_object *obj;
  2216. int plane = intel_crtc->plane;
  2217. unsigned long linear_offset;
  2218. u32 dspcntr;
  2219. u32 reg = DSPCNTR(plane);
  2220. int pixel_size;
  2221. if (!intel_crtc->primary_enabled) {
  2222. I915_WRITE(reg, 0);
  2223. I915_WRITE(DSPSURF(plane), 0);
  2224. POSTING_READ(reg);
  2225. return;
  2226. }
  2227. obj = intel_fb_obj(fb);
  2228. if (WARN_ON(obj == NULL))
  2229. return;
  2230. pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
  2231. dspcntr = DISPPLANE_GAMMA_ENABLE;
  2232. dspcntr |= DISPLAY_PLANE_ENABLE;
  2233. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  2234. dspcntr |= DISPPLANE_PIPE_CSC_ENABLE;
  2235. switch (fb->pixel_format) {
  2236. case DRM_FORMAT_C8:
  2237. dspcntr |= DISPPLANE_8BPP;
  2238. break;
  2239. case DRM_FORMAT_RGB565:
  2240. dspcntr |= DISPPLANE_BGRX565;
  2241. break;
  2242. case DRM_FORMAT_XRGB8888:
  2243. case DRM_FORMAT_ARGB8888:
  2244. dspcntr |= DISPPLANE_BGRX888;
  2245. break;
  2246. case DRM_FORMAT_XBGR8888:
  2247. case DRM_FORMAT_ABGR8888:
  2248. dspcntr |= DISPPLANE_RGBX888;
  2249. break;
  2250. case DRM_FORMAT_XRGB2101010:
  2251. case DRM_FORMAT_ARGB2101010:
  2252. dspcntr |= DISPPLANE_BGRX101010;
  2253. break;
  2254. case DRM_FORMAT_XBGR2101010:
  2255. case DRM_FORMAT_ABGR2101010:
  2256. dspcntr |= DISPPLANE_RGBX101010;
  2257. break;
  2258. default:
  2259. BUG();
  2260. }
  2261. if (obj->tiling_mode != I915_TILING_NONE)
  2262. dspcntr |= DISPPLANE_TILED;
  2263. if (!IS_HASWELL(dev) && !IS_BROADWELL(dev))
  2264. dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
  2265. linear_offset = y * fb->pitches[0] + x * pixel_size;
  2266. intel_crtc->dspaddr_offset =
  2267. intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
  2268. pixel_size,
  2269. fb->pitches[0]);
  2270. linear_offset -= intel_crtc->dspaddr_offset;
  2271. if (to_intel_plane(crtc->primary)->rotation == BIT(DRM_ROTATE_180)) {
  2272. dspcntr |= DISPPLANE_ROTATE_180;
  2273. if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) {
  2274. x += (intel_crtc->config.pipe_src_w - 1);
  2275. y += (intel_crtc->config.pipe_src_h - 1);
  2276. /* Finding the last pixel of the last line of the display
  2277. data and adding to linear_offset*/
  2278. linear_offset +=
  2279. (intel_crtc->config.pipe_src_h - 1) * fb->pitches[0] +
  2280. (intel_crtc->config.pipe_src_w - 1) * pixel_size;
  2281. }
  2282. }
  2283. I915_WRITE(reg, dspcntr);
  2284. DRM_DEBUG_KMS("Writing base %08lX %08lX %d %d %d\n",
  2285. i915_gem_obj_ggtt_offset(obj), linear_offset, x, y,
  2286. fb->pitches[0]);
  2287. I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]);
  2288. I915_WRITE(DSPSURF(plane),
  2289. i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset);
  2290. if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
  2291. I915_WRITE(DSPOFFSET(plane), (y << 16) | x);
  2292. } else {
  2293. I915_WRITE(DSPTILEOFF(plane), (y << 16) | x);
  2294. I915_WRITE(DSPLINOFF(plane), linear_offset);
  2295. }
  2296. POSTING_READ(reg);
  2297. }
  2298. /* Assume fb object is pinned & idle & fenced and just update base pointers */
  2299. static int
  2300. intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb,
  2301. int x, int y, enum mode_set_atomic state)
  2302. {
  2303. struct drm_device *dev = crtc->dev;
  2304. struct drm_i915_private *dev_priv = dev->dev_private;
  2305. if (dev_priv->display.disable_fbc)
  2306. dev_priv->display.disable_fbc(dev);
  2307. intel_increase_pllclock(dev, to_intel_crtc(crtc)->pipe);
  2308. dev_priv->display.update_primary_plane(crtc, fb, x, y);
  2309. return 0;
  2310. }
  2311. void intel_display_handle_reset(struct drm_device *dev)
  2312. {
  2313. struct drm_i915_private *dev_priv = dev->dev_private;
  2314. struct drm_crtc *crtc;
  2315. /*
  2316. * Flips in the rings have been nuked by the reset,
  2317. * so complete all pending flips so that user space
  2318. * will get its events and not get stuck.
  2319. *
  2320. * Also update the base address of all primary
  2321. * planes to the the last fb to make sure we're
  2322. * showing the correct fb after a reset.
  2323. *
  2324. * Need to make two loops over the crtcs so that we
  2325. * don't try to grab a crtc mutex before the
  2326. * pending_flip_queue really got woken up.
  2327. */
  2328. for_each_crtc(dev, crtc) {
  2329. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2330. enum plane plane = intel_crtc->plane;
  2331. intel_prepare_page_flip(dev, plane);
  2332. intel_finish_page_flip_plane(dev, plane);
  2333. }
  2334. for_each_crtc(dev, crtc) {
  2335. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2336. drm_modeset_lock(&crtc->mutex, NULL);
  2337. /*
  2338. * FIXME: Once we have proper support for primary planes (and
  2339. * disabling them without disabling the entire crtc) allow again
  2340. * a NULL crtc->primary->fb.
  2341. */
  2342. if (intel_crtc->active && crtc->primary->fb)
  2343. dev_priv->display.update_primary_plane(crtc,
  2344. crtc->primary->fb,
  2345. crtc->x,
  2346. crtc->y);
  2347. drm_modeset_unlock(&crtc->mutex);
  2348. }
  2349. }
  2350. static int
  2351. intel_finish_fb(struct drm_framebuffer *old_fb)
  2352. {
  2353. struct drm_i915_gem_object *obj = intel_fb_obj(old_fb);
  2354. struct drm_i915_private *dev_priv = obj->base.dev->dev_private;
  2355. bool was_interruptible = dev_priv->mm.interruptible;
  2356. int ret;
  2357. /* Big Hammer, we also need to ensure that any pending
  2358. * MI_WAIT_FOR_EVENT inside a user batch buffer on the
  2359. * current scanout is retired before unpinning the old
  2360. * framebuffer.
  2361. *
  2362. * This should only fail upon a hung GPU, in which case we
  2363. * can safely continue.
  2364. */
  2365. dev_priv->mm.interruptible = false;
  2366. ret = i915_gem_object_finish_gpu(obj);
  2367. dev_priv->mm.interruptible = was_interruptible;
  2368. return ret;
  2369. }
  2370. static bool intel_crtc_has_pending_flip(struct drm_crtc *crtc)
  2371. {
  2372. struct drm_device *dev = crtc->dev;
  2373. struct drm_i915_private *dev_priv = dev->dev_private;
  2374. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2375. unsigned long flags;
  2376. bool pending;
  2377. if (i915_reset_in_progress(&dev_priv->gpu_error) ||
  2378. intel_crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter))
  2379. return false;
  2380. spin_lock_irqsave(&dev->event_lock, flags);
  2381. pending = to_intel_crtc(crtc)->unpin_work != NULL;
  2382. spin_unlock_irqrestore(&dev->event_lock, flags);
  2383. return pending;
  2384. }
  2385. static int
  2386. intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
  2387. struct drm_framebuffer *fb)
  2388. {
  2389. struct drm_device *dev = crtc->dev;
  2390. struct drm_i915_private *dev_priv = dev->dev_private;
  2391. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2392. enum pipe pipe = intel_crtc->pipe;
  2393. struct drm_framebuffer *old_fb = crtc->primary->fb;
  2394. struct drm_i915_gem_object *obj = intel_fb_obj(fb);
  2395. struct drm_i915_gem_object *old_obj = intel_fb_obj(old_fb);
  2396. int ret;
  2397. if (intel_crtc_has_pending_flip(crtc)) {
  2398. DRM_ERROR("pipe is still busy with an old pageflip\n");
  2399. return -EBUSY;
  2400. }
  2401. /* no fb bound */
  2402. if (!fb) {
  2403. DRM_ERROR("No FB bound\n");
  2404. return 0;
  2405. }
  2406. if (intel_crtc->plane > INTEL_INFO(dev)->num_pipes) {
  2407. DRM_ERROR("no plane for crtc: plane %c, num_pipes %d\n",
  2408. plane_name(intel_crtc->plane),
  2409. INTEL_INFO(dev)->num_pipes);
  2410. return -EINVAL;
  2411. }
  2412. mutex_lock(&dev->struct_mutex);
  2413. ret = intel_pin_and_fence_fb_obj(dev, obj, NULL);
  2414. if (ret == 0)
  2415. i915_gem_track_fb(old_obj, obj,
  2416. INTEL_FRONTBUFFER_PRIMARY(pipe));
  2417. mutex_unlock(&dev->struct_mutex);
  2418. if (ret != 0) {
  2419. DRM_ERROR("pin & fence failed\n");
  2420. return ret;
  2421. }
  2422. /*
  2423. * Update pipe size and adjust fitter if needed: the reason for this is
  2424. * that in compute_mode_changes we check the native mode (not the pfit
  2425. * mode) to see if we can flip rather than do a full mode set. In the
  2426. * fastboot case, we'll flip, but if we don't update the pipesrc and
  2427. * pfit state, we'll end up with a big fb scanned out into the wrong
  2428. * sized surface.
  2429. *
  2430. * To fix this properly, we need to hoist the checks up into
  2431. * compute_mode_changes (or above), check the actual pfit state and
  2432. * whether the platform allows pfit disable with pipe active, and only
  2433. * then update the pipesrc and pfit state, even on the flip path.
  2434. */
  2435. if (i915.fastboot) {
  2436. const struct drm_display_mode *adjusted_mode =
  2437. &intel_crtc->config.adjusted_mode;
  2438. I915_WRITE(PIPESRC(intel_crtc->pipe),
  2439. ((adjusted_mode->crtc_hdisplay - 1) << 16) |
  2440. (adjusted_mode->crtc_vdisplay - 1));
  2441. if (!intel_crtc->config.pch_pfit.enabled &&
  2442. (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) ||
  2443. intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) {
  2444. I915_WRITE(PF_CTL(intel_crtc->pipe), 0);
  2445. I915_WRITE(PF_WIN_POS(intel_crtc->pipe), 0);
  2446. I915_WRITE(PF_WIN_SZ(intel_crtc->pipe), 0);
  2447. }
  2448. intel_crtc->config.pipe_src_w = adjusted_mode->crtc_hdisplay;
  2449. intel_crtc->config.pipe_src_h = adjusted_mode->crtc_vdisplay;
  2450. }
  2451. dev_priv->display.update_primary_plane(crtc, fb, x, y);
  2452. if (intel_crtc->active)
  2453. intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_PRIMARY(pipe));
  2454. crtc->primary->fb = fb;
  2455. crtc->x = x;
  2456. crtc->y = y;
  2457. if (old_fb) {
  2458. if (intel_crtc->active && old_fb != fb)
  2459. intel_wait_for_vblank(dev, intel_crtc->pipe);
  2460. mutex_lock(&dev->struct_mutex);
  2461. intel_unpin_fb_obj(old_obj);
  2462. mutex_unlock(&dev->struct_mutex);
  2463. }
  2464. mutex_lock(&dev->struct_mutex);
  2465. intel_update_fbc(dev);
  2466. mutex_unlock(&dev->struct_mutex);
  2467. return 0;
  2468. }
  2469. static void intel_fdi_normal_train(struct drm_crtc *crtc)
  2470. {
  2471. struct drm_device *dev = crtc->dev;
  2472. struct drm_i915_private *dev_priv = dev->dev_private;
  2473. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2474. int pipe = intel_crtc->pipe;
  2475. u32 reg, temp;
  2476. /* enable normal train */
  2477. reg = FDI_TX_CTL(pipe);
  2478. temp = I915_READ(reg);
  2479. if (IS_IVYBRIDGE(dev)) {
  2480. temp &= ~FDI_LINK_TRAIN_NONE_IVB;
  2481. temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE;
  2482. } else {
  2483. temp &= ~FDI_LINK_TRAIN_NONE;
  2484. temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
  2485. }
  2486. I915_WRITE(reg, temp);
  2487. reg = FDI_RX_CTL(pipe);
  2488. temp = I915_READ(reg);
  2489. if (HAS_PCH_CPT(dev)) {
  2490. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2491. temp |= FDI_LINK_TRAIN_NORMAL_CPT;
  2492. } else {
  2493. temp &= ~FDI_LINK_TRAIN_NONE;
  2494. temp |= FDI_LINK_TRAIN_NONE;
  2495. }
  2496. I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
  2497. /* wait one idle pattern time */
  2498. POSTING_READ(reg);
  2499. udelay(1000);
  2500. /* IVB wants error correction enabled */
  2501. if (IS_IVYBRIDGE(dev))
  2502. I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE |
  2503. FDI_FE_ERRC_ENABLE);
  2504. }
  2505. static bool pipe_has_enabled_pch(struct intel_crtc *crtc)
  2506. {
  2507. return crtc->base.enabled && crtc->active &&
  2508. crtc->config.has_pch_encoder;
  2509. }
  2510. static void ivb_modeset_global_resources(struct drm_device *dev)
  2511. {
  2512. struct drm_i915_private *dev_priv = dev->dev_private;
  2513. struct intel_crtc *pipe_B_crtc =
  2514. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_B]);
  2515. struct intel_crtc *pipe_C_crtc =
  2516. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_C]);
  2517. uint32_t temp;
  2518. /*
  2519. * When everything is off disable fdi C so that we could enable fdi B
  2520. * with all lanes. Note that we don't care about enabled pipes without
  2521. * an enabled pch encoder.
  2522. */
  2523. if (!pipe_has_enabled_pch(pipe_B_crtc) &&
  2524. !pipe_has_enabled_pch(pipe_C_crtc)) {
  2525. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
  2526. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
  2527. temp = I915_READ(SOUTH_CHICKEN1);
  2528. temp &= ~FDI_BC_BIFURCATION_SELECT;
  2529. DRM_DEBUG_KMS("disabling fdi C rx\n");
  2530. I915_WRITE(SOUTH_CHICKEN1, temp);
  2531. }
  2532. }
  2533. /* The FDI link training functions for ILK/Ibexpeak. */
  2534. static void ironlake_fdi_link_train(struct drm_crtc *crtc)
  2535. {
  2536. struct drm_device *dev = crtc->dev;
  2537. struct drm_i915_private *dev_priv = dev->dev_private;
  2538. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2539. int pipe = intel_crtc->pipe;
  2540. u32 reg, temp, tries;
  2541. /* FDI needs bits from pipe first */
  2542. assert_pipe_enabled(dev_priv, pipe);
  2543. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  2544. for train result */
  2545. reg = FDI_RX_IMR(pipe);
  2546. temp = I915_READ(reg);
  2547. temp &= ~FDI_RX_SYMBOL_LOCK;
  2548. temp &= ~FDI_RX_BIT_LOCK;
  2549. I915_WRITE(reg, temp);
  2550. I915_READ(reg);
  2551. udelay(150);
  2552. /* enable CPU FDI TX and PCH FDI RX */
  2553. reg = FDI_TX_CTL(pipe);
  2554. temp = I915_READ(reg);
  2555. temp &= ~FDI_DP_PORT_WIDTH_MASK;
  2556. temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes);
  2557. temp &= ~FDI_LINK_TRAIN_NONE;
  2558. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2559. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  2560. reg = FDI_RX_CTL(pipe);
  2561. temp = I915_READ(reg);
  2562. temp &= ~FDI_LINK_TRAIN_NONE;
  2563. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2564. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  2565. POSTING_READ(reg);
  2566. udelay(150);
  2567. /* Ironlake workaround, enable clock pointer after FDI enable*/
  2568. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
  2569. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR |
  2570. FDI_RX_PHASE_SYNC_POINTER_EN);
  2571. reg = FDI_RX_IIR(pipe);
  2572. for (tries = 0; tries < 5; tries++) {
  2573. temp = I915_READ(reg);
  2574. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2575. if ((temp & FDI_RX_BIT_LOCK)) {
  2576. DRM_DEBUG_KMS("FDI train 1 done.\n");
  2577. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  2578. break;
  2579. }
  2580. }
  2581. if (tries == 5)
  2582. DRM_ERROR("FDI train 1 fail!\n");
  2583. /* Train 2 */
  2584. reg = FDI_TX_CTL(pipe);
  2585. temp = I915_READ(reg);
  2586. temp &= ~FDI_LINK_TRAIN_NONE;
  2587. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2588. I915_WRITE(reg, temp);
  2589. reg = FDI_RX_CTL(pipe);
  2590. temp = I915_READ(reg);
  2591. temp &= ~FDI_LINK_TRAIN_NONE;
  2592. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2593. I915_WRITE(reg, temp);
  2594. POSTING_READ(reg);
  2595. udelay(150);
  2596. reg = FDI_RX_IIR(pipe);
  2597. for (tries = 0; tries < 5; tries++) {
  2598. temp = I915_READ(reg);
  2599. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2600. if (temp & FDI_RX_SYMBOL_LOCK) {
  2601. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  2602. DRM_DEBUG_KMS("FDI train 2 done.\n");
  2603. break;
  2604. }
  2605. }
  2606. if (tries == 5)
  2607. DRM_ERROR("FDI train 2 fail!\n");
  2608. DRM_DEBUG_KMS("FDI train done\n");
  2609. }
  2610. static const int snb_b_fdi_train_param[] = {
  2611. FDI_LINK_TRAIN_400MV_0DB_SNB_B,
  2612. FDI_LINK_TRAIN_400MV_6DB_SNB_B,
  2613. FDI_LINK_TRAIN_600MV_3_5DB_SNB_B,
  2614. FDI_LINK_TRAIN_800MV_0DB_SNB_B,
  2615. };
  2616. /* The FDI link training functions for SNB/Cougarpoint. */
  2617. static void gen6_fdi_link_train(struct drm_crtc *crtc)
  2618. {
  2619. struct drm_device *dev = crtc->dev;
  2620. struct drm_i915_private *dev_priv = dev->dev_private;
  2621. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2622. int pipe = intel_crtc->pipe;
  2623. u32 reg, temp, i, retry;
  2624. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  2625. for train result */
  2626. reg = FDI_RX_IMR(pipe);
  2627. temp = I915_READ(reg);
  2628. temp &= ~FDI_RX_SYMBOL_LOCK;
  2629. temp &= ~FDI_RX_BIT_LOCK;
  2630. I915_WRITE(reg, temp);
  2631. POSTING_READ(reg);
  2632. udelay(150);
  2633. /* enable CPU FDI TX and PCH FDI RX */
  2634. reg = FDI_TX_CTL(pipe);
  2635. temp = I915_READ(reg);
  2636. temp &= ~FDI_DP_PORT_WIDTH_MASK;
  2637. temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes);
  2638. temp &= ~FDI_LINK_TRAIN_NONE;
  2639. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2640. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2641. /* SNB-B */
  2642. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  2643. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  2644. I915_WRITE(FDI_RX_MISC(pipe),
  2645. FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
  2646. reg = FDI_RX_CTL(pipe);
  2647. temp = I915_READ(reg);
  2648. if (HAS_PCH_CPT(dev)) {
  2649. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2650. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2651. } else {
  2652. temp &= ~FDI_LINK_TRAIN_NONE;
  2653. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2654. }
  2655. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  2656. POSTING_READ(reg);
  2657. udelay(150);
  2658. for (i = 0; i < 4; i++) {
  2659. reg = FDI_TX_CTL(pipe);
  2660. temp = I915_READ(reg);
  2661. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2662. temp |= snb_b_fdi_train_param[i];
  2663. I915_WRITE(reg, temp);
  2664. POSTING_READ(reg);
  2665. udelay(500);
  2666. for (retry = 0; retry < 5; retry++) {
  2667. reg = FDI_RX_IIR(pipe);
  2668. temp = I915_READ(reg);
  2669. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2670. if (temp & FDI_RX_BIT_LOCK) {
  2671. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  2672. DRM_DEBUG_KMS("FDI train 1 done.\n");
  2673. break;
  2674. }
  2675. udelay(50);
  2676. }
  2677. if (retry < 5)
  2678. break;
  2679. }
  2680. if (i == 4)
  2681. DRM_ERROR("FDI train 1 fail!\n");
  2682. /* Train 2 */
  2683. reg = FDI_TX_CTL(pipe);
  2684. temp = I915_READ(reg);
  2685. temp &= ~FDI_LINK_TRAIN_NONE;
  2686. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2687. if (IS_GEN6(dev)) {
  2688. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2689. /* SNB-B */
  2690. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  2691. }
  2692. I915_WRITE(reg, temp);
  2693. reg = FDI_RX_CTL(pipe);
  2694. temp = I915_READ(reg);
  2695. if (HAS_PCH_CPT(dev)) {
  2696. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2697. temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
  2698. } else {
  2699. temp &= ~FDI_LINK_TRAIN_NONE;
  2700. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2701. }
  2702. I915_WRITE(reg, temp);
  2703. POSTING_READ(reg);
  2704. udelay(150);
  2705. for (i = 0; i < 4; i++) {
  2706. reg = FDI_TX_CTL(pipe);
  2707. temp = I915_READ(reg);
  2708. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2709. temp |= snb_b_fdi_train_param[i];
  2710. I915_WRITE(reg, temp);
  2711. POSTING_READ(reg);
  2712. udelay(500);
  2713. for (retry = 0; retry < 5; retry++) {
  2714. reg = FDI_RX_IIR(pipe);
  2715. temp = I915_READ(reg);
  2716. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2717. if (temp & FDI_RX_SYMBOL_LOCK) {
  2718. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  2719. DRM_DEBUG_KMS("FDI train 2 done.\n");
  2720. break;
  2721. }
  2722. udelay(50);
  2723. }
  2724. if (retry < 5)
  2725. break;
  2726. }
  2727. if (i == 4)
  2728. DRM_ERROR("FDI train 2 fail!\n");
  2729. DRM_DEBUG_KMS("FDI train done.\n");
  2730. }
  2731. /* Manual link training for Ivy Bridge A0 parts */
  2732. static void ivb_manual_fdi_link_train(struct drm_crtc *crtc)
  2733. {
  2734. struct drm_device *dev = crtc->dev;
  2735. struct drm_i915_private *dev_priv = dev->dev_private;
  2736. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2737. int pipe = intel_crtc->pipe;
  2738. u32 reg, temp, i, j;
  2739. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  2740. for train result */
  2741. reg = FDI_RX_IMR(pipe);
  2742. temp = I915_READ(reg);
  2743. temp &= ~FDI_RX_SYMBOL_LOCK;
  2744. temp &= ~FDI_RX_BIT_LOCK;
  2745. I915_WRITE(reg, temp);
  2746. POSTING_READ(reg);
  2747. udelay(150);
  2748. DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
  2749. I915_READ(FDI_RX_IIR(pipe)));
  2750. /* Try each vswing and preemphasis setting twice before moving on */
  2751. for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) {
  2752. /* disable first in case we need to retry */
  2753. reg = FDI_TX_CTL(pipe);
  2754. temp = I915_READ(reg);
  2755. temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB);
  2756. temp &= ~FDI_TX_ENABLE;
  2757. I915_WRITE(reg, temp);
  2758. reg = FDI_RX_CTL(pipe);
  2759. temp = I915_READ(reg);
  2760. temp &= ~FDI_LINK_TRAIN_AUTO;
  2761. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2762. temp &= ~FDI_RX_ENABLE;
  2763. I915_WRITE(reg, temp);
  2764. /* enable CPU FDI TX and PCH FDI RX */
  2765. reg = FDI_TX_CTL(pipe);
  2766. temp = I915_READ(reg);
  2767. temp &= ~FDI_DP_PORT_WIDTH_MASK;
  2768. temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes);
  2769. temp |= FDI_LINK_TRAIN_PATTERN_1_IVB;
  2770. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2771. temp |= snb_b_fdi_train_param[j/2];
  2772. temp |= FDI_COMPOSITE_SYNC;
  2773. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  2774. I915_WRITE(FDI_RX_MISC(pipe),
  2775. FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
  2776. reg = FDI_RX_CTL(pipe);
  2777. temp = I915_READ(reg);
  2778. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2779. temp |= FDI_COMPOSITE_SYNC;
  2780. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  2781. POSTING_READ(reg);
  2782. udelay(1); /* should be 0.5us */
  2783. for (i = 0; i < 4; i++) {
  2784. reg = FDI_RX_IIR(pipe);
  2785. temp = I915_READ(reg);
  2786. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2787. if (temp & FDI_RX_BIT_LOCK ||
  2788. (I915_READ(reg) & FDI_RX_BIT_LOCK)) {
  2789. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  2790. DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
  2791. i);
  2792. break;
  2793. }
  2794. udelay(1); /* should be 0.5us */
  2795. }
  2796. if (i == 4) {
  2797. DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2);
  2798. continue;
  2799. }
  2800. /* Train 2 */
  2801. reg = FDI_TX_CTL(pipe);
  2802. temp = I915_READ(reg);
  2803. temp &= ~FDI_LINK_TRAIN_NONE_IVB;
  2804. temp |= FDI_LINK_TRAIN_PATTERN_2_IVB;
  2805. I915_WRITE(reg, temp);
  2806. reg = FDI_RX_CTL(pipe);
  2807. temp = I915_READ(reg);
  2808. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2809. temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
  2810. I915_WRITE(reg, temp);
  2811. POSTING_READ(reg);
  2812. udelay(2); /* should be 1.5us */
  2813. for (i = 0; i < 4; i++) {
  2814. reg = FDI_RX_IIR(pipe);
  2815. temp = I915_READ(reg);
  2816. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2817. if (temp & FDI_RX_SYMBOL_LOCK ||
  2818. (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) {
  2819. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  2820. DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
  2821. i);
  2822. goto train_done;
  2823. }
  2824. udelay(2); /* should be 1.5us */
  2825. }
  2826. if (i == 4)
  2827. DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j / 2);
  2828. }
  2829. train_done:
  2830. DRM_DEBUG_KMS("FDI train done.\n");
  2831. }
  2832. static void ironlake_fdi_pll_enable(struct intel_crtc *intel_crtc)
  2833. {
  2834. struct drm_device *dev = intel_crtc->base.dev;
  2835. struct drm_i915_private *dev_priv = dev->dev_private;
  2836. int pipe = intel_crtc->pipe;
  2837. u32 reg, temp;
  2838. /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
  2839. reg = FDI_RX_CTL(pipe);
  2840. temp = I915_READ(reg);
  2841. temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16));
  2842. temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes);
  2843. temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
  2844. I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE);
  2845. POSTING_READ(reg);
  2846. udelay(200);
  2847. /* Switch from Rawclk to PCDclk */
  2848. temp = I915_READ(reg);
  2849. I915_WRITE(reg, temp | FDI_PCDCLK);
  2850. POSTING_READ(reg);
  2851. udelay(200);
  2852. /* Enable CPU FDI TX PLL, always on for Ironlake */
  2853. reg = FDI_TX_CTL(pipe);
  2854. temp = I915_READ(reg);
  2855. if ((temp & FDI_TX_PLL_ENABLE) == 0) {
  2856. I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE);
  2857. POSTING_READ(reg);
  2858. udelay(100);
  2859. }
  2860. }
  2861. static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc)
  2862. {
  2863. struct drm_device *dev = intel_crtc->base.dev;
  2864. struct drm_i915_private *dev_priv = dev->dev_private;
  2865. int pipe = intel_crtc->pipe;
  2866. u32 reg, temp;
  2867. /* Switch from PCDclk to Rawclk */
  2868. reg = FDI_RX_CTL(pipe);
  2869. temp = I915_READ(reg);
  2870. I915_WRITE(reg, temp & ~FDI_PCDCLK);
  2871. /* Disable CPU FDI TX PLL */
  2872. reg = FDI_TX_CTL(pipe);
  2873. temp = I915_READ(reg);
  2874. I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE);
  2875. POSTING_READ(reg);
  2876. udelay(100);
  2877. reg = FDI_RX_CTL(pipe);
  2878. temp = I915_READ(reg);
  2879. I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE);
  2880. /* Wait for the clocks to turn off. */
  2881. POSTING_READ(reg);
  2882. udelay(100);
  2883. }
  2884. static void ironlake_fdi_disable(struct drm_crtc *crtc)
  2885. {
  2886. struct drm_device *dev = crtc->dev;
  2887. struct drm_i915_private *dev_priv = dev->dev_private;
  2888. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2889. int pipe = intel_crtc->pipe;
  2890. u32 reg, temp;
  2891. /* disable CPU FDI tx and PCH FDI rx */
  2892. reg = FDI_TX_CTL(pipe);
  2893. temp = I915_READ(reg);
  2894. I915_WRITE(reg, temp & ~FDI_TX_ENABLE);
  2895. POSTING_READ(reg);
  2896. reg = FDI_RX_CTL(pipe);
  2897. temp = I915_READ(reg);
  2898. temp &= ~(0x7 << 16);
  2899. temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
  2900. I915_WRITE(reg, temp & ~FDI_RX_ENABLE);
  2901. POSTING_READ(reg);
  2902. udelay(100);
  2903. /* Ironlake workaround, disable clock pointer after downing FDI */
  2904. if (HAS_PCH_IBX(dev))
  2905. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
  2906. /* still set train pattern 1 */
  2907. reg = FDI_TX_CTL(pipe);
  2908. temp = I915_READ(reg);
  2909. temp &= ~FDI_LINK_TRAIN_NONE;
  2910. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2911. I915_WRITE(reg, temp);
  2912. reg = FDI_RX_CTL(pipe);
  2913. temp = I915_READ(reg);
  2914. if (HAS_PCH_CPT(dev)) {
  2915. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2916. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2917. } else {
  2918. temp &= ~FDI_LINK_TRAIN_NONE;
  2919. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2920. }
  2921. /* BPC in FDI rx is consistent with that in PIPECONF */
  2922. temp &= ~(0x07 << 16);
  2923. temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
  2924. I915_WRITE(reg, temp);
  2925. POSTING_READ(reg);
  2926. udelay(100);
  2927. }
  2928. bool intel_has_pending_fb_unpin(struct drm_device *dev)
  2929. {
  2930. struct intel_crtc *crtc;
  2931. /* Note that we don't need to be called with mode_config.lock here
  2932. * as our list of CRTC objects is static for the lifetime of the
  2933. * device and so cannot disappear as we iterate. Similarly, we can
  2934. * happily treat the predicates as racy, atomic checks as userspace
  2935. * cannot claim and pin a new fb without at least acquring the
  2936. * struct_mutex and so serialising with us.
  2937. */
  2938. for_each_intel_crtc(dev, crtc) {
  2939. if (atomic_read(&crtc->unpin_work_count) == 0)
  2940. continue;
  2941. if (crtc->unpin_work)
  2942. intel_wait_for_vblank(dev, crtc->pipe);
  2943. return true;
  2944. }
  2945. return false;
  2946. }
  2947. static void page_flip_completed(struct intel_crtc *intel_crtc)
  2948. {
  2949. struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
  2950. struct intel_unpin_work *work = intel_crtc->unpin_work;
  2951. /* ensure that the unpin work is consistent wrt ->pending. */
  2952. smp_rmb();
  2953. intel_crtc->unpin_work = NULL;
  2954. if (work->event)
  2955. drm_send_vblank_event(intel_crtc->base.dev,
  2956. intel_crtc->pipe,
  2957. work->event);
  2958. drm_crtc_vblank_put(&intel_crtc->base);
  2959. wake_up_all(&dev_priv->pending_flip_queue);
  2960. queue_work(dev_priv->wq, &work->work);
  2961. trace_i915_flip_complete(intel_crtc->plane,
  2962. work->pending_flip_obj);
  2963. }
  2964. void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
  2965. {
  2966. struct drm_device *dev = crtc->dev;
  2967. struct drm_i915_private *dev_priv = dev->dev_private;
  2968. WARN_ON(waitqueue_active(&dev_priv->pending_flip_queue));
  2969. if (WARN_ON(wait_event_timeout(dev_priv->pending_flip_queue,
  2970. !intel_crtc_has_pending_flip(crtc),
  2971. 60*HZ) == 0)) {
  2972. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2973. unsigned long flags;
  2974. spin_lock_irqsave(&dev->event_lock, flags);
  2975. if (intel_crtc->unpin_work) {
  2976. WARN_ONCE(1, "Removing stuck page flip\n");
  2977. page_flip_completed(intel_crtc);
  2978. }
  2979. spin_unlock_irqrestore(&dev->event_lock, flags);
  2980. }
  2981. if (crtc->primary->fb) {
  2982. mutex_lock(&dev->struct_mutex);
  2983. intel_finish_fb(crtc->primary->fb);
  2984. mutex_unlock(&dev->struct_mutex);
  2985. }
  2986. }
  2987. /* Program iCLKIP clock to the desired frequency */
  2988. static void lpt_program_iclkip(struct drm_crtc *crtc)
  2989. {
  2990. struct drm_device *dev = crtc->dev;
  2991. struct drm_i915_private *dev_priv = dev->dev_private;
  2992. int clock = to_intel_crtc(crtc)->config.adjusted_mode.crtc_clock;
  2993. u32 divsel, phaseinc, auxdiv, phasedir = 0;
  2994. u32 temp;
  2995. mutex_lock(&dev_priv->dpio_lock);
  2996. /* It is necessary to ungate the pixclk gate prior to programming
  2997. * the divisors, and gate it back when it is done.
  2998. */
  2999. I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE);
  3000. /* Disable SSCCTL */
  3001. intel_sbi_write(dev_priv, SBI_SSCCTL6,
  3002. intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK) |
  3003. SBI_SSCCTL_DISABLE,
  3004. SBI_ICLK);
  3005. /* 20MHz is a corner case which is out of range for the 7-bit divisor */
  3006. if (clock == 20000) {
  3007. auxdiv = 1;
  3008. divsel = 0x41;
  3009. phaseinc = 0x20;
  3010. } else {
  3011. /* The iCLK virtual clock root frequency is in MHz,
  3012. * but the adjusted_mode->crtc_clock in in KHz. To get the
  3013. * divisors, it is necessary to divide one by another, so we
  3014. * convert the virtual clock precision to KHz here for higher
  3015. * precision.
  3016. */
  3017. u32 iclk_virtual_root_freq = 172800 * 1000;
  3018. u32 iclk_pi_range = 64;
  3019. u32 desired_divisor, msb_divisor_value, pi_value;
  3020. desired_divisor = (iclk_virtual_root_freq / clock);
  3021. msb_divisor_value = desired_divisor / iclk_pi_range;
  3022. pi_value = desired_divisor % iclk_pi_range;
  3023. auxdiv = 0;
  3024. divsel = msb_divisor_value - 2;
  3025. phaseinc = pi_value;
  3026. }
  3027. /* This should not happen with any sane values */
  3028. WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) &
  3029. ~SBI_SSCDIVINTPHASE_DIVSEL_MASK);
  3030. WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) &
  3031. ~SBI_SSCDIVINTPHASE_INCVAL_MASK);
  3032. DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
  3033. clock,
  3034. auxdiv,
  3035. divsel,
  3036. phasedir,
  3037. phaseinc);
  3038. /* Program SSCDIVINTPHASE6 */
  3039. temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
  3040. temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK;
  3041. temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel);
  3042. temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK;
  3043. temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc);
  3044. temp |= SBI_SSCDIVINTPHASE_DIR(phasedir);
  3045. temp |= SBI_SSCDIVINTPHASE_PROPAGATE;
  3046. intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK);
  3047. /* Program SSCAUXDIV */
  3048. temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
  3049. temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
  3050. temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv);
  3051. intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK);
  3052. /* Enable modulator and associated divider */
  3053. temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
  3054. temp &= ~SBI_SSCCTL_DISABLE;
  3055. intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
  3056. /* Wait for initialization time */
  3057. udelay(24);
  3058. I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE);
  3059. mutex_unlock(&dev_priv->dpio_lock);
  3060. }
  3061. static void ironlake_pch_transcoder_set_timings(struct intel_crtc *crtc,
  3062. enum pipe pch_transcoder)
  3063. {
  3064. struct drm_device *dev = crtc->base.dev;
  3065. struct drm_i915_private *dev_priv = dev->dev_private;
  3066. enum transcoder cpu_transcoder = crtc->config.cpu_transcoder;
  3067. I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder),
  3068. I915_READ(HTOTAL(cpu_transcoder)));
  3069. I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder),
  3070. I915_READ(HBLANK(cpu_transcoder)));
  3071. I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder),
  3072. I915_READ(HSYNC(cpu_transcoder)));
  3073. I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder),
  3074. I915_READ(VTOTAL(cpu_transcoder)));
  3075. I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder),
  3076. I915_READ(VBLANK(cpu_transcoder)));
  3077. I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder),
  3078. I915_READ(VSYNC(cpu_transcoder)));
  3079. I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder),
  3080. I915_READ(VSYNCSHIFT(cpu_transcoder)));
  3081. }
  3082. static void cpt_enable_fdi_bc_bifurcation(struct drm_device *dev)
  3083. {
  3084. struct drm_i915_private *dev_priv = dev->dev_private;
  3085. uint32_t temp;
  3086. temp = I915_READ(SOUTH_CHICKEN1);
  3087. if (temp & FDI_BC_BIFURCATION_SELECT)
  3088. return;
  3089. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
  3090. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
  3091. temp |= FDI_BC_BIFURCATION_SELECT;
  3092. DRM_DEBUG_KMS("enabling fdi C rx\n");
  3093. I915_WRITE(SOUTH_CHICKEN1, temp);
  3094. POSTING_READ(SOUTH_CHICKEN1);
  3095. }
  3096. static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc *intel_crtc)
  3097. {
  3098. struct drm_device *dev = intel_crtc->base.dev;
  3099. struct drm_i915_private *dev_priv = dev->dev_private;
  3100. switch (intel_crtc->pipe) {
  3101. case PIPE_A:
  3102. break;
  3103. case PIPE_B:
  3104. if (intel_crtc->config.fdi_lanes > 2)
  3105. WARN_ON(I915_READ(SOUTH_CHICKEN1) & FDI_BC_BIFURCATION_SELECT);
  3106. else
  3107. cpt_enable_fdi_bc_bifurcation(dev);
  3108. break;
  3109. case PIPE_C:
  3110. cpt_enable_fdi_bc_bifurcation(dev);
  3111. break;
  3112. default:
  3113. BUG();
  3114. }
  3115. }
  3116. /*
  3117. * Enable PCH resources required for PCH ports:
  3118. * - PCH PLLs
  3119. * - FDI training & RX/TX
  3120. * - update transcoder timings
  3121. * - DP transcoding bits
  3122. * - transcoder
  3123. */
  3124. static void ironlake_pch_enable(struct drm_crtc *crtc)
  3125. {
  3126. struct drm_device *dev = crtc->dev;
  3127. struct drm_i915_private *dev_priv = dev->dev_private;
  3128. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3129. int pipe = intel_crtc->pipe;
  3130. u32 reg, temp;
  3131. assert_pch_transcoder_disabled(dev_priv, pipe);
  3132. if (IS_IVYBRIDGE(dev))
  3133. ivybridge_update_fdi_bc_bifurcation(intel_crtc);
  3134. /* Write the TU size bits before fdi link training, so that error
  3135. * detection works. */
  3136. I915_WRITE(FDI_RX_TUSIZE1(pipe),
  3137. I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
  3138. /* For PCH output, training FDI link */
  3139. dev_priv->display.fdi_link_train(crtc);
  3140. /* We need to program the right clock selection before writing the pixel
  3141. * mutliplier into the DPLL. */
  3142. if (HAS_PCH_CPT(dev)) {
  3143. u32 sel;
  3144. temp = I915_READ(PCH_DPLL_SEL);
  3145. temp |= TRANS_DPLL_ENABLE(pipe);
  3146. sel = TRANS_DPLLB_SEL(pipe);
  3147. if (intel_crtc->config.shared_dpll == DPLL_ID_PCH_PLL_B)
  3148. temp |= sel;
  3149. else
  3150. temp &= ~sel;
  3151. I915_WRITE(PCH_DPLL_SEL, temp);
  3152. }
  3153. /* XXX: pch pll's can be enabled any time before we enable the PCH
  3154. * transcoder, and we actually should do this to not upset any PCH
  3155. * transcoder that already use the clock when we share it.
  3156. *
  3157. * Note that enable_shared_dpll tries to do the right thing, but
  3158. * get_shared_dpll unconditionally resets the pll - we need that to have
  3159. * the right LVDS enable sequence. */
  3160. intel_enable_shared_dpll(intel_crtc);
  3161. /* set transcoder timing, panel must allow it */
  3162. assert_panel_unlocked(dev_priv, pipe);
  3163. ironlake_pch_transcoder_set_timings(intel_crtc, pipe);
  3164. intel_fdi_normal_train(crtc);
  3165. /* For PCH DP, enable TRANS_DP_CTL */
  3166. if (HAS_PCH_CPT(dev) &&
  3167. (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) ||
  3168. intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) {
  3169. u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5;
  3170. reg = TRANS_DP_CTL(pipe);
  3171. temp = I915_READ(reg);
  3172. temp &= ~(TRANS_DP_PORT_SEL_MASK |
  3173. TRANS_DP_SYNC_MASK |
  3174. TRANS_DP_BPC_MASK);
  3175. temp |= (TRANS_DP_OUTPUT_ENABLE |
  3176. TRANS_DP_ENH_FRAMING);
  3177. temp |= bpc << 9; /* same format but at 11:9 */
  3178. if (crtc->mode.flags & DRM_MODE_FLAG_PHSYNC)
  3179. temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
  3180. if (crtc->mode.flags & DRM_MODE_FLAG_PVSYNC)
  3181. temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
  3182. switch (intel_trans_dp_port_sel(crtc)) {
  3183. case PCH_DP_B:
  3184. temp |= TRANS_DP_PORT_SEL_B;
  3185. break;
  3186. case PCH_DP_C:
  3187. temp |= TRANS_DP_PORT_SEL_C;
  3188. break;
  3189. case PCH_DP_D:
  3190. temp |= TRANS_DP_PORT_SEL_D;
  3191. break;
  3192. default:
  3193. BUG();
  3194. }
  3195. I915_WRITE(reg, temp);
  3196. }
  3197. ironlake_enable_pch_transcoder(dev_priv, pipe);
  3198. }
  3199. static void lpt_pch_enable(struct drm_crtc *crtc)
  3200. {
  3201. struct drm_device *dev = crtc->dev;
  3202. struct drm_i915_private *dev_priv = dev->dev_private;
  3203. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3204. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  3205. assert_pch_transcoder_disabled(dev_priv, TRANSCODER_A);
  3206. lpt_program_iclkip(crtc);
  3207. /* Set transcoder timing. */
  3208. ironlake_pch_transcoder_set_timings(intel_crtc, PIPE_A);
  3209. lpt_enable_pch_transcoder(dev_priv, cpu_transcoder);
  3210. }
  3211. void intel_put_shared_dpll(struct intel_crtc *crtc)
  3212. {
  3213. struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
  3214. if (pll == NULL)
  3215. return;
  3216. if (pll->refcount == 0) {
  3217. WARN(1, "bad %s refcount\n", pll->name);
  3218. return;
  3219. }
  3220. if (--pll->refcount == 0) {
  3221. WARN_ON(pll->on);
  3222. WARN_ON(pll->active);
  3223. }
  3224. crtc->config.shared_dpll = DPLL_ID_PRIVATE;
  3225. }
  3226. struct intel_shared_dpll *intel_get_shared_dpll(struct intel_crtc *crtc)
  3227. {
  3228. struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
  3229. struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
  3230. enum intel_dpll_id i;
  3231. if (pll) {
  3232. DRM_DEBUG_KMS("CRTC:%d dropping existing %s\n",
  3233. crtc->base.base.id, pll->name);
  3234. intel_put_shared_dpll(crtc);
  3235. }
  3236. if (HAS_PCH_IBX(dev_priv->dev)) {
  3237. /* Ironlake PCH has a fixed PLL->PCH pipe mapping. */
  3238. i = (enum intel_dpll_id) crtc->pipe;
  3239. pll = &dev_priv->shared_dplls[i];
  3240. DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n",
  3241. crtc->base.base.id, pll->name);
  3242. WARN_ON(pll->refcount);
  3243. goto found;
  3244. }
  3245. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  3246. pll = &dev_priv->shared_dplls[i];
  3247. /* Only want to check enabled timings first */
  3248. if (pll->refcount == 0)
  3249. continue;
  3250. if (memcmp(&crtc->config.dpll_hw_state, &pll->hw_state,
  3251. sizeof(pll->hw_state)) == 0) {
  3252. DRM_DEBUG_KMS("CRTC:%d sharing existing %s (refcount %d, ative %d)\n",
  3253. crtc->base.base.id,
  3254. pll->name, pll->refcount, pll->active);
  3255. goto found;
  3256. }
  3257. }
  3258. /* Ok no matching timings, maybe there's a free one? */
  3259. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  3260. pll = &dev_priv->shared_dplls[i];
  3261. if (pll->refcount == 0) {
  3262. DRM_DEBUG_KMS("CRTC:%d allocated %s\n",
  3263. crtc->base.base.id, pll->name);
  3264. goto found;
  3265. }
  3266. }
  3267. return NULL;
  3268. found:
  3269. if (pll->refcount == 0)
  3270. pll->hw_state = crtc->config.dpll_hw_state;
  3271. crtc->config.shared_dpll = i;
  3272. DRM_DEBUG_DRIVER("using %s for pipe %c\n", pll->name,
  3273. pipe_name(crtc->pipe));
  3274. pll->refcount++;
  3275. return pll;
  3276. }
  3277. static void cpt_verify_modeset(struct drm_device *dev, int pipe)
  3278. {
  3279. struct drm_i915_private *dev_priv = dev->dev_private;
  3280. int dslreg = PIPEDSL(pipe);
  3281. u32 temp;
  3282. temp = I915_READ(dslreg);
  3283. udelay(500);
  3284. if (wait_for(I915_READ(dslreg) != temp, 5)) {
  3285. if (wait_for(I915_READ(dslreg) != temp, 5))
  3286. DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe));
  3287. }
  3288. }
  3289. static void ironlake_pfit_enable(struct intel_crtc *crtc)
  3290. {
  3291. struct drm_device *dev = crtc->base.dev;
  3292. struct drm_i915_private *dev_priv = dev->dev_private;
  3293. int pipe = crtc->pipe;
  3294. if (crtc->config.pch_pfit.enabled) {
  3295. /* Force use of hard-coded filter coefficients
  3296. * as some pre-programmed values are broken,
  3297. * e.g. x201.
  3298. */
  3299. if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev))
  3300. I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 |
  3301. PF_PIPE_SEL_IVB(pipe));
  3302. else
  3303. I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3);
  3304. I915_WRITE(PF_WIN_POS(pipe), crtc->config.pch_pfit.pos);
  3305. I915_WRITE(PF_WIN_SZ(pipe), crtc->config.pch_pfit.size);
  3306. }
  3307. }
  3308. static void intel_enable_planes(struct drm_crtc *crtc)
  3309. {
  3310. struct drm_device *dev = crtc->dev;
  3311. enum pipe pipe = to_intel_crtc(crtc)->pipe;
  3312. struct drm_plane *plane;
  3313. struct intel_plane *intel_plane;
  3314. drm_for_each_legacy_plane(plane, &dev->mode_config.plane_list) {
  3315. intel_plane = to_intel_plane(plane);
  3316. if (intel_plane->pipe == pipe)
  3317. intel_plane_restore(&intel_plane->base);
  3318. }
  3319. }
  3320. static void intel_disable_planes(struct drm_crtc *crtc)
  3321. {
  3322. struct drm_device *dev = crtc->dev;
  3323. enum pipe pipe = to_intel_crtc(crtc)->pipe;
  3324. struct drm_plane *plane;
  3325. struct intel_plane *intel_plane;
  3326. drm_for_each_legacy_plane(plane, &dev->mode_config.plane_list) {
  3327. intel_plane = to_intel_plane(plane);
  3328. if (intel_plane->pipe == pipe)
  3329. intel_plane_disable(&intel_plane->base);
  3330. }
  3331. }
  3332. void hsw_enable_ips(struct intel_crtc *crtc)
  3333. {
  3334. struct drm_device *dev = crtc->base.dev;
  3335. struct drm_i915_private *dev_priv = dev->dev_private;
  3336. if (!crtc->config.ips_enabled)
  3337. return;
  3338. /* We can only enable IPS after we enable a plane and wait for a vblank */
  3339. intel_wait_for_vblank(dev, crtc->pipe);
  3340. assert_plane_enabled(dev_priv, crtc->plane);
  3341. if (IS_BROADWELL(dev)) {
  3342. mutex_lock(&dev_priv->rps.hw_lock);
  3343. WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0xc0000000));
  3344. mutex_unlock(&dev_priv->rps.hw_lock);
  3345. /* Quoting Art Runyan: "its not safe to expect any particular
  3346. * value in IPS_CTL bit 31 after enabling IPS through the
  3347. * mailbox." Moreover, the mailbox may return a bogus state,
  3348. * so we need to just enable it and continue on.
  3349. */
  3350. } else {
  3351. I915_WRITE(IPS_CTL, IPS_ENABLE);
  3352. /* The bit only becomes 1 in the next vblank, so this wait here
  3353. * is essentially intel_wait_for_vblank. If we don't have this
  3354. * and don't wait for vblanks until the end of crtc_enable, then
  3355. * the HW state readout code will complain that the expected
  3356. * IPS_CTL value is not the one we read. */
  3357. if (wait_for(I915_READ_NOTRACE(IPS_CTL) & IPS_ENABLE, 50))
  3358. DRM_ERROR("Timed out waiting for IPS enable\n");
  3359. }
  3360. }
  3361. void hsw_disable_ips(struct intel_crtc *crtc)
  3362. {
  3363. struct drm_device *dev = crtc->base.dev;
  3364. struct drm_i915_private *dev_priv = dev->dev_private;
  3365. if (!crtc->config.ips_enabled)
  3366. return;
  3367. assert_plane_enabled(dev_priv, crtc->plane);
  3368. if (IS_BROADWELL(dev)) {
  3369. mutex_lock(&dev_priv->rps.hw_lock);
  3370. WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0));
  3371. mutex_unlock(&dev_priv->rps.hw_lock);
  3372. /* wait for pcode to finish disabling IPS, which may take up to 42ms */
  3373. if (wait_for((I915_READ(IPS_CTL) & IPS_ENABLE) == 0, 42))
  3374. DRM_ERROR("Timed out waiting for IPS disable\n");
  3375. } else {
  3376. I915_WRITE(IPS_CTL, 0);
  3377. POSTING_READ(IPS_CTL);
  3378. }
  3379. /* We need to wait for a vblank before we can disable the plane. */
  3380. intel_wait_for_vblank(dev, crtc->pipe);
  3381. }
  3382. /** Loads the palette/gamma unit for the CRTC with the prepared values */
  3383. static void intel_crtc_load_lut(struct drm_crtc *crtc)
  3384. {
  3385. struct drm_device *dev = crtc->dev;
  3386. struct drm_i915_private *dev_priv = dev->dev_private;
  3387. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3388. enum pipe pipe = intel_crtc->pipe;
  3389. int palreg = PALETTE(pipe);
  3390. int i;
  3391. bool reenable_ips = false;
  3392. /* The clocks have to be on to load the palette. */
  3393. if (!crtc->enabled || !intel_crtc->active)
  3394. return;
  3395. if (!HAS_PCH_SPLIT(dev_priv->dev)) {
  3396. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DSI))
  3397. assert_dsi_pll_enabled(dev_priv);
  3398. else
  3399. assert_pll_enabled(dev_priv, pipe);
  3400. }
  3401. /* use legacy palette for Ironlake */
  3402. if (!HAS_GMCH_DISPLAY(dev))
  3403. palreg = LGC_PALETTE(pipe);
  3404. /* Workaround : Do not read or write the pipe palette/gamma data while
  3405. * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
  3406. */
  3407. if (IS_HASWELL(dev) && intel_crtc->config.ips_enabled &&
  3408. ((I915_READ(GAMMA_MODE(pipe)) & GAMMA_MODE_MODE_MASK) ==
  3409. GAMMA_MODE_MODE_SPLIT)) {
  3410. hsw_disable_ips(intel_crtc);
  3411. reenable_ips = true;
  3412. }
  3413. for (i = 0; i < 256; i++) {
  3414. I915_WRITE(palreg + 4 * i,
  3415. (intel_crtc->lut_r[i] << 16) |
  3416. (intel_crtc->lut_g[i] << 8) |
  3417. intel_crtc->lut_b[i]);
  3418. }
  3419. if (reenable_ips)
  3420. hsw_enable_ips(intel_crtc);
  3421. }
  3422. static void intel_crtc_dpms_overlay(struct intel_crtc *intel_crtc, bool enable)
  3423. {
  3424. if (!enable && intel_crtc->overlay) {
  3425. struct drm_device *dev = intel_crtc->base.dev;
  3426. struct drm_i915_private *dev_priv = dev->dev_private;
  3427. mutex_lock(&dev->struct_mutex);
  3428. dev_priv->mm.interruptible = false;
  3429. (void) intel_overlay_switch_off(intel_crtc->overlay);
  3430. dev_priv->mm.interruptible = true;
  3431. mutex_unlock(&dev->struct_mutex);
  3432. }
  3433. /* Let userspace switch the overlay on again. In most cases userspace
  3434. * has to recompute where to put it anyway.
  3435. */
  3436. }
  3437. static void intel_crtc_enable_planes(struct drm_crtc *crtc)
  3438. {
  3439. struct drm_device *dev = crtc->dev;
  3440. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3441. int pipe = intel_crtc->pipe;
  3442. assert_vblank_disabled(crtc);
  3443. drm_vblank_on(dev, pipe);
  3444. intel_enable_primary_hw_plane(crtc->primary, crtc);
  3445. intel_enable_planes(crtc);
  3446. intel_crtc_update_cursor(crtc, true);
  3447. intel_crtc_dpms_overlay(intel_crtc, true);
  3448. hsw_enable_ips(intel_crtc);
  3449. mutex_lock(&dev->struct_mutex);
  3450. intel_update_fbc(dev);
  3451. mutex_unlock(&dev->struct_mutex);
  3452. /*
  3453. * FIXME: Once we grow proper nuclear flip support out of this we need
  3454. * to compute the mask of flip planes precisely. For the time being
  3455. * consider this a flip from a NULL plane.
  3456. */
  3457. intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_ALL_MASK(pipe));
  3458. }
  3459. static void intel_crtc_disable_planes(struct drm_crtc *crtc)
  3460. {
  3461. struct drm_device *dev = crtc->dev;
  3462. struct drm_i915_private *dev_priv = dev->dev_private;
  3463. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3464. int pipe = intel_crtc->pipe;
  3465. int plane = intel_crtc->plane;
  3466. intel_crtc_wait_for_pending_flips(crtc);
  3467. if (dev_priv->fbc.plane == plane)
  3468. intel_disable_fbc(dev);
  3469. hsw_disable_ips(intel_crtc);
  3470. intel_crtc_dpms_overlay(intel_crtc, false);
  3471. intel_crtc_update_cursor(crtc, false);
  3472. intel_disable_planes(crtc);
  3473. intel_disable_primary_hw_plane(crtc->primary, crtc);
  3474. /*
  3475. * FIXME: Once we grow proper nuclear flip support out of this we need
  3476. * to compute the mask of flip planes precisely. For the time being
  3477. * consider this a flip to a NULL plane.
  3478. */
  3479. intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_ALL_MASK(pipe));
  3480. drm_vblank_off(dev, pipe);
  3481. assert_vblank_disabled(crtc);
  3482. }
  3483. static void ironlake_crtc_enable(struct drm_crtc *crtc)
  3484. {
  3485. struct drm_device *dev = crtc->dev;
  3486. struct drm_i915_private *dev_priv = dev->dev_private;
  3487. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3488. struct intel_encoder *encoder;
  3489. int pipe = intel_crtc->pipe;
  3490. WARN_ON(!crtc->enabled);
  3491. if (intel_crtc->active)
  3492. return;
  3493. if (intel_crtc->config.has_pch_encoder)
  3494. intel_prepare_shared_dpll(intel_crtc);
  3495. if (intel_crtc->config.has_dp_encoder)
  3496. intel_dp_set_m_n(intel_crtc);
  3497. intel_set_pipe_timings(intel_crtc);
  3498. if (intel_crtc->config.has_pch_encoder) {
  3499. intel_cpu_transcoder_set_m_n(intel_crtc,
  3500. &intel_crtc->config.fdi_m_n, NULL);
  3501. }
  3502. ironlake_set_pipeconf(crtc);
  3503. intel_crtc->active = true;
  3504. intel_set_cpu_fifo_underrun_reporting(dev, pipe, true);
  3505. intel_set_pch_fifo_underrun_reporting(dev, pipe, true);
  3506. for_each_encoder_on_crtc(dev, crtc, encoder)
  3507. if (encoder->pre_enable)
  3508. encoder->pre_enable(encoder);
  3509. if (intel_crtc->config.has_pch_encoder) {
  3510. /* Note: FDI PLL enabling _must_ be done before we enable the
  3511. * cpu pipes, hence this is separate from all the other fdi/pch
  3512. * enabling. */
  3513. ironlake_fdi_pll_enable(intel_crtc);
  3514. } else {
  3515. assert_fdi_tx_disabled(dev_priv, pipe);
  3516. assert_fdi_rx_disabled(dev_priv, pipe);
  3517. }
  3518. ironlake_pfit_enable(intel_crtc);
  3519. /*
  3520. * On ILK+ LUT must be loaded before the pipe is running but with
  3521. * clocks enabled
  3522. */
  3523. intel_crtc_load_lut(crtc);
  3524. intel_update_watermarks(crtc);
  3525. intel_enable_pipe(intel_crtc);
  3526. if (intel_crtc->config.has_pch_encoder)
  3527. ironlake_pch_enable(crtc);
  3528. for_each_encoder_on_crtc(dev, crtc, encoder)
  3529. encoder->enable(encoder);
  3530. if (HAS_PCH_CPT(dev))
  3531. cpt_verify_modeset(dev, intel_crtc->pipe);
  3532. intel_crtc_enable_planes(crtc);
  3533. }
  3534. /* IPS only exists on ULT machines and is tied to pipe A. */
  3535. static bool hsw_crtc_supports_ips(struct intel_crtc *crtc)
  3536. {
  3537. return HAS_IPS(crtc->base.dev) && crtc->pipe == PIPE_A;
  3538. }
  3539. /*
  3540. * This implements the workaround described in the "notes" section of the mode
  3541. * set sequence documentation. When going from no pipes or single pipe to
  3542. * multiple pipes, and planes are enabled after the pipe, we need to wait at
  3543. * least 2 vblanks on the first pipe before enabling planes on the second pipe.
  3544. */
  3545. static void haswell_mode_set_planes_workaround(struct intel_crtc *crtc)
  3546. {
  3547. struct drm_device *dev = crtc->base.dev;
  3548. struct intel_crtc *crtc_it, *other_active_crtc = NULL;
  3549. /* We want to get the other_active_crtc only if there's only 1 other
  3550. * active crtc. */
  3551. for_each_intel_crtc(dev, crtc_it) {
  3552. if (!crtc_it->active || crtc_it == crtc)
  3553. continue;
  3554. if (other_active_crtc)
  3555. return;
  3556. other_active_crtc = crtc_it;
  3557. }
  3558. if (!other_active_crtc)
  3559. return;
  3560. intel_wait_for_vblank(dev, other_active_crtc->pipe);
  3561. intel_wait_for_vblank(dev, other_active_crtc->pipe);
  3562. }
  3563. static void haswell_crtc_enable(struct drm_crtc *crtc)
  3564. {
  3565. struct drm_device *dev = crtc->dev;
  3566. struct drm_i915_private *dev_priv = dev->dev_private;
  3567. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3568. struct intel_encoder *encoder;
  3569. int pipe = intel_crtc->pipe;
  3570. WARN_ON(!crtc->enabled);
  3571. if (intel_crtc->active)
  3572. return;
  3573. if (intel_crtc_to_shared_dpll(intel_crtc))
  3574. intel_enable_shared_dpll(intel_crtc);
  3575. if (intel_crtc->config.has_dp_encoder)
  3576. intel_dp_set_m_n(intel_crtc);
  3577. intel_set_pipe_timings(intel_crtc);
  3578. if (intel_crtc->config.cpu_transcoder != TRANSCODER_EDP) {
  3579. I915_WRITE(PIPE_MULT(intel_crtc->config.cpu_transcoder),
  3580. intel_crtc->config.pixel_multiplier - 1);
  3581. }
  3582. if (intel_crtc->config.has_pch_encoder) {
  3583. intel_cpu_transcoder_set_m_n(intel_crtc,
  3584. &intel_crtc->config.fdi_m_n, NULL);
  3585. }
  3586. haswell_set_pipeconf(crtc);
  3587. intel_set_pipe_csc(crtc);
  3588. intel_crtc->active = true;
  3589. intel_set_cpu_fifo_underrun_reporting(dev, pipe, true);
  3590. for_each_encoder_on_crtc(dev, crtc, encoder)
  3591. if (encoder->pre_enable)
  3592. encoder->pre_enable(encoder);
  3593. if (intel_crtc->config.has_pch_encoder) {
  3594. intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, true);
  3595. dev_priv->display.fdi_link_train(crtc);
  3596. }
  3597. intel_ddi_enable_pipe_clock(intel_crtc);
  3598. ironlake_pfit_enable(intel_crtc);
  3599. /*
  3600. * On ILK+ LUT must be loaded before the pipe is running but with
  3601. * clocks enabled
  3602. */
  3603. intel_crtc_load_lut(crtc);
  3604. intel_ddi_set_pipe_settings(crtc);
  3605. intel_ddi_enable_transcoder_func(crtc);
  3606. intel_update_watermarks(crtc);
  3607. intel_enable_pipe(intel_crtc);
  3608. if (intel_crtc->config.has_pch_encoder)
  3609. lpt_pch_enable(crtc);
  3610. if (intel_crtc->config.dp_encoder_is_mst)
  3611. intel_ddi_set_vc_payload_alloc(crtc, true);
  3612. for_each_encoder_on_crtc(dev, crtc, encoder) {
  3613. encoder->enable(encoder);
  3614. intel_opregion_notify_encoder(encoder, true);
  3615. }
  3616. /* If we change the relative order between pipe/planes enabling, we need
  3617. * to change the workaround. */
  3618. haswell_mode_set_planes_workaround(intel_crtc);
  3619. intel_crtc_enable_planes(crtc);
  3620. }
  3621. static void ironlake_pfit_disable(struct intel_crtc *crtc)
  3622. {
  3623. struct drm_device *dev = crtc->base.dev;
  3624. struct drm_i915_private *dev_priv = dev->dev_private;
  3625. int pipe = crtc->pipe;
  3626. /* To avoid upsetting the power well on haswell only disable the pfit if
  3627. * it's in use. The hw state code will make sure we get this right. */
  3628. if (crtc->config.pch_pfit.enabled) {
  3629. I915_WRITE(PF_CTL(pipe), 0);
  3630. I915_WRITE(PF_WIN_POS(pipe), 0);
  3631. I915_WRITE(PF_WIN_SZ(pipe), 0);
  3632. }
  3633. }
  3634. static void ironlake_crtc_disable(struct drm_crtc *crtc)
  3635. {
  3636. struct drm_device *dev = crtc->dev;
  3637. struct drm_i915_private *dev_priv = dev->dev_private;
  3638. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3639. struct intel_encoder *encoder;
  3640. int pipe = intel_crtc->pipe;
  3641. u32 reg, temp;
  3642. if (!intel_crtc->active)
  3643. return;
  3644. intel_crtc_disable_planes(crtc);
  3645. for_each_encoder_on_crtc(dev, crtc, encoder)
  3646. encoder->disable(encoder);
  3647. if (intel_crtc->config.has_pch_encoder)
  3648. intel_set_pch_fifo_underrun_reporting(dev, pipe, false);
  3649. intel_disable_pipe(intel_crtc);
  3650. ironlake_pfit_disable(intel_crtc);
  3651. for_each_encoder_on_crtc(dev, crtc, encoder)
  3652. if (encoder->post_disable)
  3653. encoder->post_disable(encoder);
  3654. if (intel_crtc->config.has_pch_encoder) {
  3655. ironlake_fdi_disable(crtc);
  3656. ironlake_disable_pch_transcoder(dev_priv, pipe);
  3657. intel_set_pch_fifo_underrun_reporting(dev, pipe, true);
  3658. if (HAS_PCH_CPT(dev)) {
  3659. /* disable TRANS_DP_CTL */
  3660. reg = TRANS_DP_CTL(pipe);
  3661. temp = I915_READ(reg);
  3662. temp &= ~(TRANS_DP_OUTPUT_ENABLE |
  3663. TRANS_DP_PORT_SEL_MASK);
  3664. temp |= TRANS_DP_PORT_SEL_NONE;
  3665. I915_WRITE(reg, temp);
  3666. /* disable DPLL_SEL */
  3667. temp = I915_READ(PCH_DPLL_SEL);
  3668. temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe));
  3669. I915_WRITE(PCH_DPLL_SEL, temp);
  3670. }
  3671. /* disable PCH DPLL */
  3672. intel_disable_shared_dpll(intel_crtc);
  3673. ironlake_fdi_pll_disable(intel_crtc);
  3674. }
  3675. intel_crtc->active = false;
  3676. intel_update_watermarks(crtc);
  3677. mutex_lock(&dev->struct_mutex);
  3678. intel_update_fbc(dev);
  3679. mutex_unlock(&dev->struct_mutex);
  3680. }
  3681. static void haswell_crtc_disable(struct drm_crtc *crtc)
  3682. {
  3683. struct drm_device *dev = crtc->dev;
  3684. struct drm_i915_private *dev_priv = dev->dev_private;
  3685. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3686. struct intel_encoder *encoder;
  3687. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  3688. if (!intel_crtc->active)
  3689. return;
  3690. intel_crtc_disable_planes(crtc);
  3691. for_each_encoder_on_crtc(dev, crtc, encoder) {
  3692. intel_opregion_notify_encoder(encoder, false);
  3693. encoder->disable(encoder);
  3694. }
  3695. if (intel_crtc->config.has_pch_encoder)
  3696. intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, false);
  3697. intel_disable_pipe(intel_crtc);
  3698. if (intel_crtc->config.dp_encoder_is_mst)
  3699. intel_ddi_set_vc_payload_alloc(crtc, false);
  3700. intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder);
  3701. ironlake_pfit_disable(intel_crtc);
  3702. intel_ddi_disable_pipe_clock(intel_crtc);
  3703. if (intel_crtc->config.has_pch_encoder) {
  3704. lpt_disable_pch_transcoder(dev_priv);
  3705. intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, true);
  3706. intel_ddi_fdi_disable(crtc);
  3707. }
  3708. for_each_encoder_on_crtc(dev, crtc, encoder)
  3709. if (encoder->post_disable)
  3710. encoder->post_disable(encoder);
  3711. intel_crtc->active = false;
  3712. intel_update_watermarks(crtc);
  3713. mutex_lock(&dev->struct_mutex);
  3714. intel_update_fbc(dev);
  3715. mutex_unlock(&dev->struct_mutex);
  3716. if (intel_crtc_to_shared_dpll(intel_crtc))
  3717. intel_disable_shared_dpll(intel_crtc);
  3718. }
  3719. static void ironlake_crtc_off(struct drm_crtc *crtc)
  3720. {
  3721. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3722. intel_put_shared_dpll(intel_crtc);
  3723. }
  3724. static void i9xx_pfit_enable(struct intel_crtc *crtc)
  3725. {
  3726. struct drm_device *dev = crtc->base.dev;
  3727. struct drm_i915_private *dev_priv = dev->dev_private;
  3728. struct intel_crtc_config *pipe_config = &crtc->config;
  3729. if (!crtc->config.gmch_pfit.control)
  3730. return;
  3731. /*
  3732. * The panel fitter should only be adjusted whilst the pipe is disabled,
  3733. * according to register description and PRM.
  3734. */
  3735. WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE);
  3736. assert_pipe_disabled(dev_priv, crtc->pipe);
  3737. I915_WRITE(PFIT_PGM_RATIOS, pipe_config->gmch_pfit.pgm_ratios);
  3738. I915_WRITE(PFIT_CONTROL, pipe_config->gmch_pfit.control);
  3739. /* Border color in case we don't scale up to the full screen. Black by
  3740. * default, change to something else for debugging. */
  3741. I915_WRITE(BCLRPAT(crtc->pipe), 0);
  3742. }
  3743. static enum intel_display_power_domain port_to_power_domain(enum port port)
  3744. {
  3745. switch (port) {
  3746. case PORT_A:
  3747. return POWER_DOMAIN_PORT_DDI_A_4_LANES;
  3748. case PORT_B:
  3749. return POWER_DOMAIN_PORT_DDI_B_4_LANES;
  3750. case PORT_C:
  3751. return POWER_DOMAIN_PORT_DDI_C_4_LANES;
  3752. case PORT_D:
  3753. return POWER_DOMAIN_PORT_DDI_D_4_LANES;
  3754. default:
  3755. WARN_ON_ONCE(1);
  3756. return POWER_DOMAIN_PORT_OTHER;
  3757. }
  3758. }
  3759. #define for_each_power_domain(domain, mask) \
  3760. for ((domain) = 0; (domain) < POWER_DOMAIN_NUM; (domain)++) \
  3761. if ((1 << (domain)) & (mask))
  3762. enum intel_display_power_domain
  3763. intel_display_port_power_domain(struct intel_encoder *intel_encoder)
  3764. {
  3765. struct drm_device *dev = intel_encoder->base.dev;
  3766. struct intel_digital_port *intel_dig_port;
  3767. switch (intel_encoder->type) {
  3768. case INTEL_OUTPUT_UNKNOWN:
  3769. /* Only DDI platforms should ever use this output type */
  3770. WARN_ON_ONCE(!HAS_DDI(dev));
  3771. case INTEL_OUTPUT_DISPLAYPORT:
  3772. case INTEL_OUTPUT_HDMI:
  3773. case INTEL_OUTPUT_EDP:
  3774. intel_dig_port = enc_to_dig_port(&intel_encoder->base);
  3775. return port_to_power_domain(intel_dig_port->port);
  3776. case INTEL_OUTPUT_DP_MST:
  3777. intel_dig_port = enc_to_mst(&intel_encoder->base)->primary;
  3778. return port_to_power_domain(intel_dig_port->port);
  3779. case INTEL_OUTPUT_ANALOG:
  3780. return POWER_DOMAIN_PORT_CRT;
  3781. case INTEL_OUTPUT_DSI:
  3782. return POWER_DOMAIN_PORT_DSI;
  3783. default:
  3784. return POWER_DOMAIN_PORT_OTHER;
  3785. }
  3786. }
  3787. static unsigned long get_crtc_power_domains(struct drm_crtc *crtc)
  3788. {
  3789. struct drm_device *dev = crtc->dev;
  3790. struct intel_encoder *intel_encoder;
  3791. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3792. enum pipe pipe = intel_crtc->pipe;
  3793. unsigned long mask;
  3794. enum transcoder transcoder;
  3795. transcoder = intel_pipe_to_cpu_transcoder(dev->dev_private, pipe);
  3796. mask = BIT(POWER_DOMAIN_PIPE(pipe));
  3797. mask |= BIT(POWER_DOMAIN_TRANSCODER(transcoder));
  3798. if (intel_crtc->config.pch_pfit.enabled ||
  3799. intel_crtc->config.pch_pfit.force_thru)
  3800. mask |= BIT(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe));
  3801. for_each_encoder_on_crtc(dev, crtc, intel_encoder)
  3802. mask |= BIT(intel_display_port_power_domain(intel_encoder));
  3803. return mask;
  3804. }
  3805. void intel_display_set_init_power(struct drm_i915_private *dev_priv,
  3806. bool enable)
  3807. {
  3808. if (dev_priv->power_domains.init_power_on == enable)
  3809. return;
  3810. if (enable)
  3811. intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
  3812. else
  3813. intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
  3814. dev_priv->power_domains.init_power_on = enable;
  3815. }
  3816. static void modeset_update_crtc_power_domains(struct drm_device *dev)
  3817. {
  3818. struct drm_i915_private *dev_priv = dev->dev_private;
  3819. unsigned long pipe_domains[I915_MAX_PIPES] = { 0, };
  3820. struct intel_crtc *crtc;
  3821. /*
  3822. * First get all needed power domains, then put all unneeded, to avoid
  3823. * any unnecessary toggling of the power wells.
  3824. */
  3825. for_each_intel_crtc(dev, crtc) {
  3826. enum intel_display_power_domain domain;
  3827. if (!crtc->base.enabled)
  3828. continue;
  3829. pipe_domains[crtc->pipe] = get_crtc_power_domains(&crtc->base);
  3830. for_each_power_domain(domain, pipe_domains[crtc->pipe])
  3831. intel_display_power_get(dev_priv, domain);
  3832. }
  3833. for_each_intel_crtc(dev, crtc) {
  3834. enum intel_display_power_domain domain;
  3835. for_each_power_domain(domain, crtc->enabled_power_domains)
  3836. intel_display_power_put(dev_priv, domain);
  3837. crtc->enabled_power_domains = pipe_domains[crtc->pipe];
  3838. }
  3839. intel_display_set_init_power(dev_priv, false);
  3840. }
  3841. /* returns HPLL frequency in kHz */
  3842. static int valleyview_get_vco(struct drm_i915_private *dev_priv)
  3843. {
  3844. int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 };
  3845. /* Obtain SKU information */
  3846. mutex_lock(&dev_priv->dpio_lock);
  3847. hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) &
  3848. CCK_FUSE_HPLL_FREQ_MASK;
  3849. mutex_unlock(&dev_priv->dpio_lock);
  3850. return vco_freq[hpll_freq] * 1000;
  3851. }
  3852. static void vlv_update_cdclk(struct drm_device *dev)
  3853. {
  3854. struct drm_i915_private *dev_priv = dev->dev_private;
  3855. dev_priv->vlv_cdclk_freq = dev_priv->display.get_display_clock_speed(dev);
  3856. DRM_DEBUG_DRIVER("Current CD clock rate: %d kHz",
  3857. dev_priv->vlv_cdclk_freq);
  3858. /*
  3859. * Program the gmbus_freq based on the cdclk frequency.
  3860. * BSpec erroneously claims we should aim for 4MHz, but
  3861. * in fact 1MHz is the correct frequency.
  3862. */
  3863. I915_WRITE(GMBUSFREQ_VLV, dev_priv->vlv_cdclk_freq);
  3864. }
  3865. /* Adjust CDclk dividers to allow high res or save power if possible */
  3866. static void valleyview_set_cdclk(struct drm_device *dev, int cdclk)
  3867. {
  3868. struct drm_i915_private *dev_priv = dev->dev_private;
  3869. u32 val, cmd;
  3870. WARN_ON(dev_priv->display.get_display_clock_speed(dev) != dev_priv->vlv_cdclk_freq);
  3871. if (cdclk >= 320000) /* jump to highest voltage for 400MHz too */
  3872. cmd = 2;
  3873. else if (cdclk == 266667)
  3874. cmd = 1;
  3875. else
  3876. cmd = 0;
  3877. mutex_lock(&dev_priv->rps.hw_lock);
  3878. val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
  3879. val &= ~DSPFREQGUAR_MASK;
  3880. val |= (cmd << DSPFREQGUAR_SHIFT);
  3881. vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val);
  3882. if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) &
  3883. DSPFREQSTAT_MASK) == (cmd << DSPFREQSTAT_SHIFT),
  3884. 50)) {
  3885. DRM_ERROR("timed out waiting for CDclk change\n");
  3886. }
  3887. mutex_unlock(&dev_priv->rps.hw_lock);
  3888. if (cdclk == 400000) {
  3889. u32 divider, vco;
  3890. vco = valleyview_get_vco(dev_priv);
  3891. divider = DIV_ROUND_CLOSEST(vco << 1, cdclk) - 1;
  3892. mutex_lock(&dev_priv->dpio_lock);
  3893. /* adjust cdclk divider */
  3894. val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL);
  3895. val &= ~DISPLAY_FREQUENCY_VALUES;
  3896. val |= divider;
  3897. vlv_cck_write(dev_priv, CCK_DISPLAY_CLOCK_CONTROL, val);
  3898. if (wait_for((vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL) &
  3899. DISPLAY_FREQUENCY_STATUS) == (divider << DISPLAY_FREQUENCY_STATUS_SHIFT),
  3900. 50))
  3901. DRM_ERROR("timed out waiting for CDclk change\n");
  3902. mutex_unlock(&dev_priv->dpio_lock);
  3903. }
  3904. mutex_lock(&dev_priv->dpio_lock);
  3905. /* adjust self-refresh exit latency value */
  3906. val = vlv_bunit_read(dev_priv, BUNIT_REG_BISOC);
  3907. val &= ~0x7f;
  3908. /*
  3909. * For high bandwidth configs, we set a higher latency in the bunit
  3910. * so that the core display fetch happens in time to avoid underruns.
  3911. */
  3912. if (cdclk == 400000)
  3913. val |= 4500 / 250; /* 4.5 usec */
  3914. else
  3915. val |= 3000 / 250; /* 3.0 usec */
  3916. vlv_bunit_write(dev_priv, BUNIT_REG_BISOC, val);
  3917. mutex_unlock(&dev_priv->dpio_lock);
  3918. vlv_update_cdclk(dev);
  3919. }
  3920. static void cherryview_set_cdclk(struct drm_device *dev, int cdclk)
  3921. {
  3922. struct drm_i915_private *dev_priv = dev->dev_private;
  3923. u32 val, cmd;
  3924. WARN_ON(dev_priv->display.get_display_clock_speed(dev) != dev_priv->vlv_cdclk_freq);
  3925. switch (cdclk) {
  3926. case 400000:
  3927. cmd = 3;
  3928. break;
  3929. case 333333:
  3930. case 320000:
  3931. cmd = 2;
  3932. break;
  3933. case 266667:
  3934. cmd = 1;
  3935. break;
  3936. case 200000:
  3937. cmd = 0;
  3938. break;
  3939. default:
  3940. WARN_ON(1);
  3941. return;
  3942. }
  3943. mutex_lock(&dev_priv->rps.hw_lock);
  3944. val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
  3945. val &= ~DSPFREQGUAR_MASK_CHV;
  3946. val |= (cmd << DSPFREQGUAR_SHIFT_CHV);
  3947. vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val);
  3948. if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) &
  3949. DSPFREQSTAT_MASK_CHV) == (cmd << DSPFREQSTAT_SHIFT_CHV),
  3950. 50)) {
  3951. DRM_ERROR("timed out waiting for CDclk change\n");
  3952. }
  3953. mutex_unlock(&dev_priv->rps.hw_lock);
  3954. vlv_update_cdclk(dev);
  3955. }
  3956. static int valleyview_calc_cdclk(struct drm_i915_private *dev_priv,
  3957. int max_pixclk)
  3958. {
  3959. int vco = valleyview_get_vco(dev_priv);
  3960. int freq_320 = (vco << 1) % 320000 != 0 ? 333333 : 320000;
  3961. /* FIXME: Punit isn't quite ready yet */
  3962. if (IS_CHERRYVIEW(dev_priv->dev))
  3963. return 400000;
  3964. /*
  3965. * Really only a few cases to deal with, as only 4 CDclks are supported:
  3966. * 200MHz
  3967. * 267MHz
  3968. * 320/333MHz (depends on HPLL freq)
  3969. * 400MHz
  3970. * So we check to see whether we're above 90% of the lower bin and
  3971. * adjust if needed.
  3972. *
  3973. * We seem to get an unstable or solid color picture at 200MHz.
  3974. * Not sure what's wrong. For now use 200MHz only when all pipes
  3975. * are off.
  3976. */
  3977. if (max_pixclk > freq_320*9/10)
  3978. return 400000;
  3979. else if (max_pixclk > 266667*9/10)
  3980. return freq_320;
  3981. else if (max_pixclk > 0)
  3982. return 266667;
  3983. else
  3984. return 200000;
  3985. }
  3986. /* compute the max pixel clock for new configuration */
  3987. static int intel_mode_max_pixclk(struct drm_i915_private *dev_priv)
  3988. {
  3989. struct drm_device *dev = dev_priv->dev;
  3990. struct intel_crtc *intel_crtc;
  3991. int max_pixclk = 0;
  3992. for_each_intel_crtc(dev, intel_crtc) {
  3993. if (intel_crtc->new_enabled)
  3994. max_pixclk = max(max_pixclk,
  3995. intel_crtc->new_config->adjusted_mode.crtc_clock);
  3996. }
  3997. return max_pixclk;
  3998. }
  3999. static void valleyview_modeset_global_pipes(struct drm_device *dev,
  4000. unsigned *prepare_pipes)
  4001. {
  4002. struct drm_i915_private *dev_priv = dev->dev_private;
  4003. struct intel_crtc *intel_crtc;
  4004. int max_pixclk = intel_mode_max_pixclk(dev_priv);
  4005. if (valleyview_calc_cdclk(dev_priv, max_pixclk) ==
  4006. dev_priv->vlv_cdclk_freq)
  4007. return;
  4008. /* disable/enable all currently active pipes while we change cdclk */
  4009. for_each_intel_crtc(dev, intel_crtc)
  4010. if (intel_crtc->base.enabled)
  4011. *prepare_pipes |= (1 << intel_crtc->pipe);
  4012. }
  4013. static void valleyview_modeset_global_resources(struct drm_device *dev)
  4014. {
  4015. struct drm_i915_private *dev_priv = dev->dev_private;
  4016. int max_pixclk = intel_mode_max_pixclk(dev_priv);
  4017. int req_cdclk = valleyview_calc_cdclk(dev_priv, max_pixclk);
  4018. if (req_cdclk != dev_priv->vlv_cdclk_freq) {
  4019. if (IS_CHERRYVIEW(dev))
  4020. cherryview_set_cdclk(dev, req_cdclk);
  4021. else
  4022. valleyview_set_cdclk(dev, req_cdclk);
  4023. }
  4024. modeset_update_crtc_power_domains(dev);
  4025. }
  4026. static void valleyview_crtc_enable(struct drm_crtc *crtc)
  4027. {
  4028. struct drm_device *dev = crtc->dev;
  4029. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4030. struct intel_encoder *encoder;
  4031. int pipe = intel_crtc->pipe;
  4032. bool is_dsi;
  4033. WARN_ON(!crtc->enabled);
  4034. if (intel_crtc->active)
  4035. return;
  4036. is_dsi = intel_pipe_has_type(crtc, INTEL_OUTPUT_DSI);
  4037. if (!is_dsi) {
  4038. if (IS_CHERRYVIEW(dev))
  4039. chv_prepare_pll(intel_crtc);
  4040. else
  4041. vlv_prepare_pll(intel_crtc);
  4042. }
  4043. if (intel_crtc->config.has_dp_encoder)
  4044. intel_dp_set_m_n(intel_crtc);
  4045. intel_set_pipe_timings(intel_crtc);
  4046. i9xx_set_pipeconf(intel_crtc);
  4047. intel_crtc->active = true;
  4048. intel_set_cpu_fifo_underrun_reporting(dev, pipe, true);
  4049. for_each_encoder_on_crtc(dev, crtc, encoder)
  4050. if (encoder->pre_pll_enable)
  4051. encoder->pre_pll_enable(encoder);
  4052. if (!is_dsi) {
  4053. if (IS_CHERRYVIEW(dev))
  4054. chv_enable_pll(intel_crtc);
  4055. else
  4056. vlv_enable_pll(intel_crtc);
  4057. }
  4058. for_each_encoder_on_crtc(dev, crtc, encoder)
  4059. if (encoder->pre_enable)
  4060. encoder->pre_enable(encoder);
  4061. i9xx_pfit_enable(intel_crtc);
  4062. intel_crtc_load_lut(crtc);
  4063. intel_update_watermarks(crtc);
  4064. intel_enable_pipe(intel_crtc);
  4065. for_each_encoder_on_crtc(dev, crtc, encoder)
  4066. encoder->enable(encoder);
  4067. intel_crtc_enable_planes(crtc);
  4068. /* Underruns don't raise interrupts, so check manually. */
  4069. i9xx_check_fifo_underruns(dev);
  4070. }
  4071. static void i9xx_set_pll_dividers(struct intel_crtc *crtc)
  4072. {
  4073. struct drm_device *dev = crtc->base.dev;
  4074. struct drm_i915_private *dev_priv = dev->dev_private;
  4075. I915_WRITE(FP0(crtc->pipe), crtc->config.dpll_hw_state.fp0);
  4076. I915_WRITE(FP1(crtc->pipe), crtc->config.dpll_hw_state.fp1);
  4077. }
  4078. static void i9xx_crtc_enable(struct drm_crtc *crtc)
  4079. {
  4080. struct drm_device *dev = crtc->dev;
  4081. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4082. struct intel_encoder *encoder;
  4083. int pipe = intel_crtc->pipe;
  4084. WARN_ON(!crtc->enabled);
  4085. if (intel_crtc->active)
  4086. return;
  4087. i9xx_set_pll_dividers(intel_crtc);
  4088. if (intel_crtc->config.has_dp_encoder)
  4089. intel_dp_set_m_n(intel_crtc);
  4090. intel_set_pipe_timings(intel_crtc);
  4091. i9xx_set_pipeconf(intel_crtc);
  4092. intel_crtc->active = true;
  4093. if (!IS_GEN2(dev))
  4094. intel_set_cpu_fifo_underrun_reporting(dev, pipe, true);
  4095. for_each_encoder_on_crtc(dev, crtc, encoder)
  4096. if (encoder->pre_enable)
  4097. encoder->pre_enable(encoder);
  4098. i9xx_enable_pll(intel_crtc);
  4099. i9xx_pfit_enable(intel_crtc);
  4100. intel_crtc_load_lut(crtc);
  4101. intel_update_watermarks(crtc);
  4102. intel_enable_pipe(intel_crtc);
  4103. for_each_encoder_on_crtc(dev, crtc, encoder)
  4104. encoder->enable(encoder);
  4105. intel_crtc_enable_planes(crtc);
  4106. /*
  4107. * Gen2 reports pipe underruns whenever all planes are disabled.
  4108. * So don't enable underrun reporting before at least some planes
  4109. * are enabled.
  4110. * FIXME: Need to fix the logic to work when we turn off all planes
  4111. * but leave the pipe running.
  4112. */
  4113. if (IS_GEN2(dev))
  4114. intel_set_cpu_fifo_underrun_reporting(dev, pipe, true);
  4115. /* Underruns don't raise interrupts, so check manually. */
  4116. i9xx_check_fifo_underruns(dev);
  4117. }
  4118. static void i9xx_pfit_disable(struct intel_crtc *crtc)
  4119. {
  4120. struct drm_device *dev = crtc->base.dev;
  4121. struct drm_i915_private *dev_priv = dev->dev_private;
  4122. if (!crtc->config.gmch_pfit.control)
  4123. return;
  4124. assert_pipe_disabled(dev_priv, crtc->pipe);
  4125. DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n",
  4126. I915_READ(PFIT_CONTROL));
  4127. I915_WRITE(PFIT_CONTROL, 0);
  4128. }
  4129. static void i9xx_crtc_disable(struct drm_crtc *crtc)
  4130. {
  4131. struct drm_device *dev = crtc->dev;
  4132. struct drm_i915_private *dev_priv = dev->dev_private;
  4133. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4134. struct intel_encoder *encoder;
  4135. int pipe = intel_crtc->pipe;
  4136. if (!intel_crtc->active)
  4137. return;
  4138. /*
  4139. * Gen2 reports pipe underruns whenever all planes are disabled.
  4140. * So diasble underrun reporting before all the planes get disabled.
  4141. * FIXME: Need to fix the logic to work when we turn off all planes
  4142. * but leave the pipe running.
  4143. */
  4144. if (IS_GEN2(dev))
  4145. intel_set_cpu_fifo_underrun_reporting(dev, pipe, false);
  4146. /*
  4147. * Vblank time updates from the shadow to live plane control register
  4148. * are blocked if the memory self-refresh mode is active at that
  4149. * moment. So to make sure the plane gets truly disabled, disable
  4150. * first the self-refresh mode. The self-refresh enable bit in turn
  4151. * will be checked/applied by the HW only at the next frame start
  4152. * event which is after the vblank start event, so we need to have a
  4153. * wait-for-vblank between disabling the plane and the pipe.
  4154. */
  4155. intel_set_memory_cxsr(dev_priv, false);
  4156. intel_crtc_disable_planes(crtc);
  4157. for_each_encoder_on_crtc(dev, crtc, encoder)
  4158. encoder->disable(encoder);
  4159. /*
  4160. * On gen2 planes are double buffered but the pipe isn't, so we must
  4161. * wait for planes to fully turn off before disabling the pipe.
  4162. * We also need to wait on all gmch platforms because of the
  4163. * self-refresh mode constraint explained above.
  4164. */
  4165. intel_wait_for_vblank(dev, pipe);
  4166. intel_disable_pipe(intel_crtc);
  4167. i9xx_pfit_disable(intel_crtc);
  4168. for_each_encoder_on_crtc(dev, crtc, encoder)
  4169. if (encoder->post_disable)
  4170. encoder->post_disable(encoder);
  4171. if (!intel_pipe_has_type(crtc, INTEL_OUTPUT_DSI)) {
  4172. if (IS_CHERRYVIEW(dev))
  4173. chv_disable_pll(dev_priv, pipe);
  4174. else if (IS_VALLEYVIEW(dev))
  4175. vlv_disable_pll(dev_priv, pipe);
  4176. else
  4177. i9xx_disable_pll(intel_crtc);
  4178. }
  4179. if (!IS_GEN2(dev))
  4180. intel_set_cpu_fifo_underrun_reporting(dev, pipe, false);
  4181. intel_crtc->active = false;
  4182. intel_update_watermarks(crtc);
  4183. mutex_lock(&dev->struct_mutex);
  4184. intel_update_fbc(dev);
  4185. mutex_unlock(&dev->struct_mutex);
  4186. }
  4187. static void i9xx_crtc_off(struct drm_crtc *crtc)
  4188. {
  4189. }
  4190. static void intel_crtc_update_sarea(struct drm_crtc *crtc,
  4191. bool enabled)
  4192. {
  4193. struct drm_device *dev = crtc->dev;
  4194. struct drm_i915_master_private *master_priv;
  4195. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4196. int pipe = intel_crtc->pipe;
  4197. if (!dev->primary->master)
  4198. return;
  4199. master_priv = dev->primary->master->driver_priv;
  4200. if (!master_priv->sarea_priv)
  4201. return;
  4202. switch (pipe) {
  4203. case 0:
  4204. master_priv->sarea_priv->pipeA_w = enabled ? crtc->mode.hdisplay : 0;
  4205. master_priv->sarea_priv->pipeA_h = enabled ? crtc->mode.vdisplay : 0;
  4206. break;
  4207. case 1:
  4208. master_priv->sarea_priv->pipeB_w = enabled ? crtc->mode.hdisplay : 0;
  4209. master_priv->sarea_priv->pipeB_h = enabled ? crtc->mode.vdisplay : 0;
  4210. break;
  4211. default:
  4212. DRM_ERROR("Can't update pipe %c in SAREA\n", pipe_name(pipe));
  4213. break;
  4214. }
  4215. }
  4216. /* Master function to enable/disable CRTC and corresponding power wells */
  4217. void intel_crtc_control(struct drm_crtc *crtc, bool enable)
  4218. {
  4219. struct drm_device *dev = crtc->dev;
  4220. struct drm_i915_private *dev_priv = dev->dev_private;
  4221. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4222. enum intel_display_power_domain domain;
  4223. unsigned long domains;
  4224. if (enable) {
  4225. if (!intel_crtc->active) {
  4226. domains = get_crtc_power_domains(crtc);
  4227. for_each_power_domain(domain, domains)
  4228. intel_display_power_get(dev_priv, domain);
  4229. intel_crtc->enabled_power_domains = domains;
  4230. dev_priv->display.crtc_enable(crtc);
  4231. }
  4232. } else {
  4233. if (intel_crtc->active) {
  4234. dev_priv->display.crtc_disable(crtc);
  4235. domains = intel_crtc->enabled_power_domains;
  4236. for_each_power_domain(domain, domains)
  4237. intel_display_power_put(dev_priv, domain);
  4238. intel_crtc->enabled_power_domains = 0;
  4239. }
  4240. }
  4241. }
  4242. /**
  4243. * Sets the power management mode of the pipe and plane.
  4244. */
  4245. void intel_crtc_update_dpms(struct drm_crtc *crtc)
  4246. {
  4247. struct drm_device *dev = crtc->dev;
  4248. struct intel_encoder *intel_encoder;
  4249. bool enable = false;
  4250. for_each_encoder_on_crtc(dev, crtc, intel_encoder)
  4251. enable |= intel_encoder->connectors_active;
  4252. intel_crtc_control(crtc, enable);
  4253. intel_crtc_update_sarea(crtc, enable);
  4254. }
  4255. static void intel_crtc_disable(struct drm_crtc *crtc)
  4256. {
  4257. struct drm_device *dev = crtc->dev;
  4258. struct drm_connector *connector;
  4259. struct drm_i915_private *dev_priv = dev->dev_private;
  4260. struct drm_i915_gem_object *old_obj = intel_fb_obj(crtc->primary->fb);
  4261. enum pipe pipe = to_intel_crtc(crtc)->pipe;
  4262. /* crtc should still be enabled when we disable it. */
  4263. WARN_ON(!crtc->enabled);
  4264. dev_priv->display.crtc_disable(crtc);
  4265. intel_crtc_update_sarea(crtc, false);
  4266. dev_priv->display.off(crtc);
  4267. if (crtc->primary->fb) {
  4268. mutex_lock(&dev->struct_mutex);
  4269. intel_unpin_fb_obj(old_obj);
  4270. i915_gem_track_fb(old_obj, NULL,
  4271. INTEL_FRONTBUFFER_PRIMARY(pipe));
  4272. mutex_unlock(&dev->struct_mutex);
  4273. crtc->primary->fb = NULL;
  4274. }
  4275. /* Update computed state. */
  4276. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  4277. if (!connector->encoder || !connector->encoder->crtc)
  4278. continue;
  4279. if (connector->encoder->crtc != crtc)
  4280. continue;
  4281. connector->dpms = DRM_MODE_DPMS_OFF;
  4282. to_intel_encoder(connector->encoder)->connectors_active = false;
  4283. }
  4284. }
  4285. void intel_encoder_destroy(struct drm_encoder *encoder)
  4286. {
  4287. struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
  4288. drm_encoder_cleanup(encoder);
  4289. kfree(intel_encoder);
  4290. }
  4291. /* Simple dpms helper for encoders with just one connector, no cloning and only
  4292. * one kind of off state. It clamps all !ON modes to fully OFF and changes the
  4293. * state of the entire output pipe. */
  4294. static void intel_encoder_dpms(struct intel_encoder *encoder, int mode)
  4295. {
  4296. if (mode == DRM_MODE_DPMS_ON) {
  4297. encoder->connectors_active = true;
  4298. intel_crtc_update_dpms(encoder->base.crtc);
  4299. } else {
  4300. encoder->connectors_active = false;
  4301. intel_crtc_update_dpms(encoder->base.crtc);
  4302. }
  4303. }
  4304. /* Cross check the actual hw state with our own modeset state tracking (and it's
  4305. * internal consistency). */
  4306. static void intel_connector_check_state(struct intel_connector *connector)
  4307. {
  4308. if (connector->get_hw_state(connector)) {
  4309. struct intel_encoder *encoder = connector->encoder;
  4310. struct drm_crtc *crtc;
  4311. bool encoder_enabled;
  4312. enum pipe pipe;
  4313. DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
  4314. connector->base.base.id,
  4315. connector->base.name);
  4316. /* there is no real hw state for MST connectors */
  4317. if (connector->mst_port)
  4318. return;
  4319. WARN(connector->base.dpms == DRM_MODE_DPMS_OFF,
  4320. "wrong connector dpms state\n");
  4321. WARN(connector->base.encoder != &encoder->base,
  4322. "active connector not linked to encoder\n");
  4323. if (encoder) {
  4324. WARN(!encoder->connectors_active,
  4325. "encoder->connectors_active not set\n");
  4326. encoder_enabled = encoder->get_hw_state(encoder, &pipe);
  4327. WARN(!encoder_enabled, "encoder not enabled\n");
  4328. if (WARN_ON(!encoder->base.crtc))
  4329. return;
  4330. crtc = encoder->base.crtc;
  4331. WARN(!crtc->enabled, "crtc not enabled\n");
  4332. WARN(!to_intel_crtc(crtc)->active, "crtc not active\n");
  4333. WARN(pipe != to_intel_crtc(crtc)->pipe,
  4334. "encoder active on the wrong pipe\n");
  4335. }
  4336. }
  4337. }
  4338. /* Even simpler default implementation, if there's really no special case to
  4339. * consider. */
  4340. void intel_connector_dpms(struct drm_connector *connector, int mode)
  4341. {
  4342. /* All the simple cases only support two dpms states. */
  4343. if (mode != DRM_MODE_DPMS_ON)
  4344. mode = DRM_MODE_DPMS_OFF;
  4345. if (mode == connector->dpms)
  4346. return;
  4347. connector->dpms = mode;
  4348. /* Only need to change hw state when actually enabled */
  4349. if (connector->encoder)
  4350. intel_encoder_dpms(to_intel_encoder(connector->encoder), mode);
  4351. intel_modeset_check_state(connector->dev);
  4352. }
  4353. /* Simple connector->get_hw_state implementation for encoders that support only
  4354. * one connector and no cloning and hence the encoder state determines the state
  4355. * of the connector. */
  4356. bool intel_connector_get_hw_state(struct intel_connector *connector)
  4357. {
  4358. enum pipe pipe = 0;
  4359. struct intel_encoder *encoder = connector->encoder;
  4360. return encoder->get_hw_state(encoder, &pipe);
  4361. }
  4362. static bool ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe,
  4363. struct intel_crtc_config *pipe_config)
  4364. {
  4365. struct drm_i915_private *dev_priv = dev->dev_private;
  4366. struct intel_crtc *pipe_B_crtc =
  4367. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_B]);
  4368. DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
  4369. pipe_name(pipe), pipe_config->fdi_lanes);
  4370. if (pipe_config->fdi_lanes > 4) {
  4371. DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
  4372. pipe_name(pipe), pipe_config->fdi_lanes);
  4373. return false;
  4374. }
  4375. if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
  4376. if (pipe_config->fdi_lanes > 2) {
  4377. DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
  4378. pipe_config->fdi_lanes);
  4379. return false;
  4380. } else {
  4381. return true;
  4382. }
  4383. }
  4384. if (INTEL_INFO(dev)->num_pipes == 2)
  4385. return true;
  4386. /* Ivybridge 3 pipe is really complicated */
  4387. switch (pipe) {
  4388. case PIPE_A:
  4389. return true;
  4390. case PIPE_B:
  4391. if (dev_priv->pipe_to_crtc_mapping[PIPE_C]->enabled &&
  4392. pipe_config->fdi_lanes > 2) {
  4393. DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
  4394. pipe_name(pipe), pipe_config->fdi_lanes);
  4395. return false;
  4396. }
  4397. return true;
  4398. case PIPE_C:
  4399. if (!pipe_has_enabled_pch(pipe_B_crtc) ||
  4400. pipe_B_crtc->config.fdi_lanes <= 2) {
  4401. if (pipe_config->fdi_lanes > 2) {
  4402. DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
  4403. pipe_name(pipe), pipe_config->fdi_lanes);
  4404. return false;
  4405. }
  4406. } else {
  4407. DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
  4408. return false;
  4409. }
  4410. return true;
  4411. default:
  4412. BUG();
  4413. }
  4414. }
  4415. #define RETRY 1
  4416. static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc,
  4417. struct intel_crtc_config *pipe_config)
  4418. {
  4419. struct drm_device *dev = intel_crtc->base.dev;
  4420. struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
  4421. int lane, link_bw, fdi_dotclock;
  4422. bool setup_ok, needs_recompute = false;
  4423. retry:
  4424. /* FDI is a binary signal running at ~2.7GHz, encoding
  4425. * each output octet as 10 bits. The actual frequency
  4426. * is stored as a divider into a 100MHz clock, and the
  4427. * mode pixel clock is stored in units of 1KHz.
  4428. * Hence the bw of each lane in terms of the mode signal
  4429. * is:
  4430. */
  4431. link_bw = intel_fdi_link_freq(dev) * MHz(100)/KHz(1)/10;
  4432. fdi_dotclock = adjusted_mode->crtc_clock;
  4433. lane = ironlake_get_lanes_required(fdi_dotclock, link_bw,
  4434. pipe_config->pipe_bpp);
  4435. pipe_config->fdi_lanes = lane;
  4436. intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock,
  4437. link_bw, &pipe_config->fdi_m_n);
  4438. setup_ok = ironlake_check_fdi_lanes(intel_crtc->base.dev,
  4439. intel_crtc->pipe, pipe_config);
  4440. if (!setup_ok && pipe_config->pipe_bpp > 6*3) {
  4441. pipe_config->pipe_bpp -= 2*3;
  4442. DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
  4443. pipe_config->pipe_bpp);
  4444. needs_recompute = true;
  4445. pipe_config->bw_constrained = true;
  4446. goto retry;
  4447. }
  4448. if (needs_recompute)
  4449. return RETRY;
  4450. return setup_ok ? 0 : -EINVAL;
  4451. }
  4452. static void hsw_compute_ips_config(struct intel_crtc *crtc,
  4453. struct intel_crtc_config *pipe_config)
  4454. {
  4455. pipe_config->ips_enabled = i915.enable_ips &&
  4456. hsw_crtc_supports_ips(crtc) &&
  4457. pipe_config->pipe_bpp <= 24;
  4458. }
  4459. static int intel_crtc_compute_config(struct intel_crtc *crtc,
  4460. struct intel_crtc_config *pipe_config)
  4461. {
  4462. struct drm_device *dev = crtc->base.dev;
  4463. struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
  4464. /* FIXME should check pixel clock limits on all platforms */
  4465. if (INTEL_INFO(dev)->gen < 4) {
  4466. struct drm_i915_private *dev_priv = dev->dev_private;
  4467. int clock_limit =
  4468. dev_priv->display.get_display_clock_speed(dev);
  4469. /*
  4470. * Enable pixel doubling when the dot clock
  4471. * is > 90% of the (display) core speed.
  4472. *
  4473. * GDG double wide on either pipe,
  4474. * otherwise pipe A only.
  4475. */
  4476. if ((crtc->pipe == PIPE_A || IS_I915G(dev)) &&
  4477. adjusted_mode->crtc_clock > clock_limit * 9 / 10) {
  4478. clock_limit *= 2;
  4479. pipe_config->double_wide = true;
  4480. }
  4481. if (adjusted_mode->crtc_clock > clock_limit * 9 / 10)
  4482. return -EINVAL;
  4483. }
  4484. /*
  4485. * Pipe horizontal size must be even in:
  4486. * - DVO ganged mode
  4487. * - LVDS dual channel mode
  4488. * - Double wide pipe
  4489. */
  4490. if ((intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) &&
  4491. intel_is_dual_link_lvds(dev)) || pipe_config->double_wide)
  4492. pipe_config->pipe_src_w &= ~1;
  4493. /* Cantiga+ cannot handle modes with a hsync front porch of 0.
  4494. * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
  4495. */
  4496. if ((INTEL_INFO(dev)->gen > 4 || IS_G4X(dev)) &&
  4497. adjusted_mode->hsync_start == adjusted_mode->hdisplay)
  4498. return -EINVAL;
  4499. if ((IS_G4X(dev) || IS_VALLEYVIEW(dev)) && pipe_config->pipe_bpp > 10*3) {
  4500. pipe_config->pipe_bpp = 10*3; /* 12bpc is gen5+ */
  4501. } else if (INTEL_INFO(dev)->gen <= 4 && pipe_config->pipe_bpp > 8*3) {
  4502. /* only a 8bpc pipe, with 6bpc dither through the panel fitter
  4503. * for lvds. */
  4504. pipe_config->pipe_bpp = 8*3;
  4505. }
  4506. if (HAS_IPS(dev))
  4507. hsw_compute_ips_config(crtc, pipe_config);
  4508. /*
  4509. * XXX: PCH/WRPLL clock sharing is done in ->mode_set, so make sure the
  4510. * old clock survives for now.
  4511. */
  4512. if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev) || HAS_DDI(dev))
  4513. pipe_config->shared_dpll = crtc->config.shared_dpll;
  4514. if (pipe_config->has_pch_encoder)
  4515. return ironlake_fdi_compute_config(crtc, pipe_config);
  4516. return 0;
  4517. }
  4518. static int valleyview_get_display_clock_speed(struct drm_device *dev)
  4519. {
  4520. struct drm_i915_private *dev_priv = dev->dev_private;
  4521. int vco = valleyview_get_vco(dev_priv);
  4522. u32 val;
  4523. int divider;
  4524. /* FIXME: Punit isn't quite ready yet */
  4525. if (IS_CHERRYVIEW(dev))
  4526. return 400000;
  4527. mutex_lock(&dev_priv->dpio_lock);
  4528. val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL);
  4529. mutex_unlock(&dev_priv->dpio_lock);
  4530. divider = val & DISPLAY_FREQUENCY_VALUES;
  4531. WARN((val & DISPLAY_FREQUENCY_STATUS) !=
  4532. (divider << DISPLAY_FREQUENCY_STATUS_SHIFT),
  4533. "cdclk change in progress\n");
  4534. return DIV_ROUND_CLOSEST(vco << 1, divider + 1);
  4535. }
  4536. static int i945_get_display_clock_speed(struct drm_device *dev)
  4537. {
  4538. return 400000;
  4539. }
  4540. static int i915_get_display_clock_speed(struct drm_device *dev)
  4541. {
  4542. return 333000;
  4543. }
  4544. static int i9xx_misc_get_display_clock_speed(struct drm_device *dev)
  4545. {
  4546. return 200000;
  4547. }
  4548. static int pnv_get_display_clock_speed(struct drm_device *dev)
  4549. {
  4550. u16 gcfgc = 0;
  4551. pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
  4552. switch (gcfgc & GC_DISPLAY_CLOCK_MASK) {
  4553. case GC_DISPLAY_CLOCK_267_MHZ_PNV:
  4554. return 267000;
  4555. case GC_DISPLAY_CLOCK_333_MHZ_PNV:
  4556. return 333000;
  4557. case GC_DISPLAY_CLOCK_444_MHZ_PNV:
  4558. return 444000;
  4559. case GC_DISPLAY_CLOCK_200_MHZ_PNV:
  4560. return 200000;
  4561. default:
  4562. DRM_ERROR("Unknown pnv display core clock 0x%04x\n", gcfgc);
  4563. case GC_DISPLAY_CLOCK_133_MHZ_PNV:
  4564. return 133000;
  4565. case GC_DISPLAY_CLOCK_167_MHZ_PNV:
  4566. return 167000;
  4567. }
  4568. }
  4569. static int i915gm_get_display_clock_speed(struct drm_device *dev)
  4570. {
  4571. u16 gcfgc = 0;
  4572. pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
  4573. if (gcfgc & GC_LOW_FREQUENCY_ENABLE)
  4574. return 133000;
  4575. else {
  4576. switch (gcfgc & GC_DISPLAY_CLOCK_MASK) {
  4577. case GC_DISPLAY_CLOCK_333_MHZ:
  4578. return 333000;
  4579. default:
  4580. case GC_DISPLAY_CLOCK_190_200_MHZ:
  4581. return 190000;
  4582. }
  4583. }
  4584. }
  4585. static int i865_get_display_clock_speed(struct drm_device *dev)
  4586. {
  4587. return 266000;
  4588. }
  4589. static int i855_get_display_clock_speed(struct drm_device *dev)
  4590. {
  4591. u16 hpllcc = 0;
  4592. /* Assume that the hardware is in the high speed state. This
  4593. * should be the default.
  4594. */
  4595. switch (hpllcc & GC_CLOCK_CONTROL_MASK) {
  4596. case GC_CLOCK_133_200:
  4597. case GC_CLOCK_100_200:
  4598. return 200000;
  4599. case GC_CLOCK_166_250:
  4600. return 250000;
  4601. case GC_CLOCK_100_133:
  4602. return 133000;
  4603. }
  4604. /* Shouldn't happen */
  4605. return 0;
  4606. }
  4607. static int i830_get_display_clock_speed(struct drm_device *dev)
  4608. {
  4609. return 133000;
  4610. }
  4611. static void
  4612. intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den)
  4613. {
  4614. while (*num > DATA_LINK_M_N_MASK ||
  4615. *den > DATA_LINK_M_N_MASK) {
  4616. *num >>= 1;
  4617. *den >>= 1;
  4618. }
  4619. }
  4620. static void compute_m_n(unsigned int m, unsigned int n,
  4621. uint32_t *ret_m, uint32_t *ret_n)
  4622. {
  4623. *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
  4624. *ret_m = div_u64((uint64_t) m * *ret_n, n);
  4625. intel_reduce_m_n_ratio(ret_m, ret_n);
  4626. }
  4627. void
  4628. intel_link_compute_m_n(int bits_per_pixel, int nlanes,
  4629. int pixel_clock, int link_clock,
  4630. struct intel_link_m_n *m_n)
  4631. {
  4632. m_n->tu = 64;
  4633. compute_m_n(bits_per_pixel * pixel_clock,
  4634. link_clock * nlanes * 8,
  4635. &m_n->gmch_m, &m_n->gmch_n);
  4636. compute_m_n(pixel_clock, link_clock,
  4637. &m_n->link_m, &m_n->link_n);
  4638. }
  4639. static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
  4640. {
  4641. if (i915.panel_use_ssc >= 0)
  4642. return i915.panel_use_ssc != 0;
  4643. return dev_priv->vbt.lvds_use_ssc
  4644. && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE);
  4645. }
  4646. static int i9xx_get_refclk(struct drm_crtc *crtc, int num_connectors)
  4647. {
  4648. struct drm_device *dev = crtc->dev;
  4649. struct drm_i915_private *dev_priv = dev->dev_private;
  4650. int refclk;
  4651. if (IS_VALLEYVIEW(dev)) {
  4652. refclk = 100000;
  4653. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
  4654. intel_panel_use_ssc(dev_priv) && num_connectors < 2) {
  4655. refclk = dev_priv->vbt.lvds_ssc_freq;
  4656. DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
  4657. } else if (!IS_GEN2(dev)) {
  4658. refclk = 96000;
  4659. } else {
  4660. refclk = 48000;
  4661. }
  4662. return refclk;
  4663. }
  4664. static uint32_t pnv_dpll_compute_fp(struct dpll *dpll)
  4665. {
  4666. return (1 << dpll->n) << 16 | dpll->m2;
  4667. }
  4668. static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll)
  4669. {
  4670. return dpll->n << 16 | dpll->m1 << 8 | dpll->m2;
  4671. }
  4672. static void i9xx_update_pll_dividers(struct intel_crtc *crtc,
  4673. intel_clock_t *reduced_clock)
  4674. {
  4675. struct drm_device *dev = crtc->base.dev;
  4676. u32 fp, fp2 = 0;
  4677. if (IS_PINEVIEW(dev)) {
  4678. fp = pnv_dpll_compute_fp(&crtc->config.dpll);
  4679. if (reduced_clock)
  4680. fp2 = pnv_dpll_compute_fp(reduced_clock);
  4681. } else {
  4682. fp = i9xx_dpll_compute_fp(&crtc->config.dpll);
  4683. if (reduced_clock)
  4684. fp2 = i9xx_dpll_compute_fp(reduced_clock);
  4685. }
  4686. crtc->config.dpll_hw_state.fp0 = fp;
  4687. crtc->lowfreq_avail = false;
  4688. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) &&
  4689. reduced_clock && i915.powersave) {
  4690. crtc->config.dpll_hw_state.fp1 = fp2;
  4691. crtc->lowfreq_avail = true;
  4692. } else {
  4693. crtc->config.dpll_hw_state.fp1 = fp;
  4694. }
  4695. }
  4696. static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe
  4697. pipe)
  4698. {
  4699. u32 reg_val;
  4700. /*
  4701. * PLLB opamp always calibrates to max value of 0x3f, force enable it
  4702. * and set it to a reasonable value instead.
  4703. */
  4704. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
  4705. reg_val &= 0xffffff00;
  4706. reg_val |= 0x00000030;
  4707. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
  4708. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
  4709. reg_val &= 0x8cffffff;
  4710. reg_val = 0x8c000000;
  4711. vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
  4712. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
  4713. reg_val &= 0xffffff00;
  4714. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
  4715. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
  4716. reg_val &= 0x00ffffff;
  4717. reg_val |= 0xb0000000;
  4718. vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
  4719. }
  4720. static void intel_pch_transcoder_set_m_n(struct intel_crtc *crtc,
  4721. struct intel_link_m_n *m_n)
  4722. {
  4723. struct drm_device *dev = crtc->base.dev;
  4724. struct drm_i915_private *dev_priv = dev->dev_private;
  4725. int pipe = crtc->pipe;
  4726. I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
  4727. I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n);
  4728. I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m);
  4729. I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n);
  4730. }
  4731. static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc,
  4732. struct intel_link_m_n *m_n,
  4733. struct intel_link_m_n *m2_n2)
  4734. {
  4735. struct drm_device *dev = crtc->base.dev;
  4736. struct drm_i915_private *dev_priv = dev->dev_private;
  4737. int pipe = crtc->pipe;
  4738. enum transcoder transcoder = crtc->config.cpu_transcoder;
  4739. if (INTEL_INFO(dev)->gen >= 5) {
  4740. I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m);
  4741. I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n);
  4742. I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m);
  4743. I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n);
  4744. /* M2_N2 registers to be set only for gen < 8 (M2_N2 available
  4745. * for gen < 8) and if DRRS is supported (to make sure the
  4746. * registers are not unnecessarily accessed).
  4747. */
  4748. if (m2_n2 && INTEL_INFO(dev)->gen < 8 &&
  4749. crtc->config.has_drrs) {
  4750. I915_WRITE(PIPE_DATA_M2(transcoder),
  4751. TU_SIZE(m2_n2->tu) | m2_n2->gmch_m);
  4752. I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n);
  4753. I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m);
  4754. I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n);
  4755. }
  4756. } else {
  4757. I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
  4758. I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n);
  4759. I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m);
  4760. I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n);
  4761. }
  4762. }
  4763. void intel_dp_set_m_n(struct intel_crtc *crtc)
  4764. {
  4765. if (crtc->config.has_pch_encoder)
  4766. intel_pch_transcoder_set_m_n(crtc, &crtc->config.dp_m_n);
  4767. else
  4768. intel_cpu_transcoder_set_m_n(crtc, &crtc->config.dp_m_n,
  4769. &crtc->config.dp_m2_n2);
  4770. }
  4771. static void vlv_update_pll(struct intel_crtc *crtc)
  4772. {
  4773. u32 dpll, dpll_md;
  4774. /*
  4775. * Enable DPIO clock input. We should never disable the reference
  4776. * clock for pipe B, since VGA hotplug / manual detection depends
  4777. * on it.
  4778. */
  4779. dpll = DPLL_EXT_BUFFER_ENABLE_VLV | DPLL_REFA_CLK_ENABLE_VLV |
  4780. DPLL_VGA_MODE_DIS | DPLL_INTEGRATED_CLOCK_VLV;
  4781. /* We should never disable this, set it here for state tracking */
  4782. if (crtc->pipe == PIPE_B)
  4783. dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
  4784. dpll |= DPLL_VCO_ENABLE;
  4785. crtc->config.dpll_hw_state.dpll = dpll;
  4786. dpll_md = (crtc->config.pixel_multiplier - 1)
  4787. << DPLL_MD_UDI_MULTIPLIER_SHIFT;
  4788. crtc->config.dpll_hw_state.dpll_md = dpll_md;
  4789. }
  4790. static void vlv_prepare_pll(struct intel_crtc *crtc)
  4791. {
  4792. struct drm_device *dev = crtc->base.dev;
  4793. struct drm_i915_private *dev_priv = dev->dev_private;
  4794. int pipe = crtc->pipe;
  4795. u32 mdiv;
  4796. u32 bestn, bestm1, bestm2, bestp1, bestp2;
  4797. u32 coreclk, reg_val;
  4798. mutex_lock(&dev_priv->dpio_lock);
  4799. bestn = crtc->config.dpll.n;
  4800. bestm1 = crtc->config.dpll.m1;
  4801. bestm2 = crtc->config.dpll.m2;
  4802. bestp1 = crtc->config.dpll.p1;
  4803. bestp2 = crtc->config.dpll.p2;
  4804. /* See eDP HDMI DPIO driver vbios notes doc */
  4805. /* PLL B needs special handling */
  4806. if (pipe == PIPE_B)
  4807. vlv_pllb_recal_opamp(dev_priv, pipe);
  4808. /* Set up Tx target for periodic Rcomp update */
  4809. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f);
  4810. /* Disable target IRef on PLL */
  4811. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe));
  4812. reg_val &= 0x00ffffff;
  4813. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val);
  4814. /* Disable fast lock */
  4815. vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610);
  4816. /* Set idtafcrecal before PLL is enabled */
  4817. mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK));
  4818. mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT));
  4819. mdiv |= ((bestn << DPIO_N_SHIFT));
  4820. mdiv |= (1 << DPIO_K_SHIFT);
  4821. /*
  4822. * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
  4823. * but we don't support that).
  4824. * Note: don't use the DAC post divider as it seems unstable.
  4825. */
  4826. mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT);
  4827. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
  4828. mdiv |= DPIO_ENABLE_CALIBRATION;
  4829. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
  4830. /* Set HBR and RBR LPF coefficients */
  4831. if (crtc->config.port_clock == 162000 ||
  4832. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_ANALOG) ||
  4833. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_HDMI))
  4834. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
  4835. 0x009f0003);
  4836. else
  4837. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
  4838. 0x00d0000f);
  4839. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_EDP) ||
  4840. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DISPLAYPORT)) {
  4841. /* Use SSC source */
  4842. if (pipe == PIPE_A)
  4843. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
  4844. 0x0df40000);
  4845. else
  4846. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
  4847. 0x0df70000);
  4848. } else { /* HDMI or VGA */
  4849. /* Use bend source */
  4850. if (pipe == PIPE_A)
  4851. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
  4852. 0x0df70000);
  4853. else
  4854. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
  4855. 0x0df40000);
  4856. }
  4857. coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe));
  4858. coreclk = (coreclk & 0x0000ff00) | 0x01c00000;
  4859. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DISPLAYPORT) ||
  4860. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_EDP))
  4861. coreclk |= 0x01000000;
  4862. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk);
  4863. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000);
  4864. mutex_unlock(&dev_priv->dpio_lock);
  4865. }
  4866. static void chv_update_pll(struct intel_crtc *crtc)
  4867. {
  4868. crtc->config.dpll_hw_state.dpll = DPLL_SSC_REF_CLOCK_CHV |
  4869. DPLL_REFA_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS |
  4870. DPLL_VCO_ENABLE;
  4871. if (crtc->pipe != PIPE_A)
  4872. crtc->config.dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
  4873. crtc->config.dpll_hw_state.dpll_md =
  4874. (crtc->config.pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
  4875. }
  4876. static void chv_prepare_pll(struct intel_crtc *crtc)
  4877. {
  4878. struct drm_device *dev = crtc->base.dev;
  4879. struct drm_i915_private *dev_priv = dev->dev_private;
  4880. int pipe = crtc->pipe;
  4881. int dpll_reg = DPLL(crtc->pipe);
  4882. enum dpio_channel port = vlv_pipe_to_channel(pipe);
  4883. u32 loopfilter, intcoeff;
  4884. u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac;
  4885. int refclk;
  4886. bestn = crtc->config.dpll.n;
  4887. bestm2_frac = crtc->config.dpll.m2 & 0x3fffff;
  4888. bestm1 = crtc->config.dpll.m1;
  4889. bestm2 = crtc->config.dpll.m2 >> 22;
  4890. bestp1 = crtc->config.dpll.p1;
  4891. bestp2 = crtc->config.dpll.p2;
  4892. /*
  4893. * Enable Refclk and SSC
  4894. */
  4895. I915_WRITE(dpll_reg,
  4896. crtc->config.dpll_hw_state.dpll & ~DPLL_VCO_ENABLE);
  4897. mutex_lock(&dev_priv->dpio_lock);
  4898. /* p1 and p2 divider */
  4899. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port),
  4900. 5 << DPIO_CHV_S1_DIV_SHIFT |
  4901. bestp1 << DPIO_CHV_P1_DIV_SHIFT |
  4902. bestp2 << DPIO_CHV_P2_DIV_SHIFT |
  4903. 1 << DPIO_CHV_K_DIV_SHIFT);
  4904. /* Feedback post-divider - m2 */
  4905. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2);
  4906. /* Feedback refclk divider - n and m1 */
  4907. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port),
  4908. DPIO_CHV_M1_DIV_BY_2 |
  4909. 1 << DPIO_CHV_N_DIV_SHIFT);
  4910. /* M2 fraction division */
  4911. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac);
  4912. /* M2 fraction division enable */
  4913. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port),
  4914. DPIO_CHV_FRAC_DIV_EN |
  4915. (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT));
  4916. /* Loop filter */
  4917. refclk = i9xx_get_refclk(&crtc->base, 0);
  4918. loopfilter = 5 << DPIO_CHV_PROP_COEFF_SHIFT |
  4919. 2 << DPIO_CHV_GAIN_CTRL_SHIFT;
  4920. if (refclk == 100000)
  4921. intcoeff = 11;
  4922. else if (refclk == 38400)
  4923. intcoeff = 10;
  4924. else
  4925. intcoeff = 9;
  4926. loopfilter |= intcoeff << DPIO_CHV_INT_COEFF_SHIFT;
  4927. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter);
  4928. /* AFC Recal */
  4929. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port),
  4930. vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) |
  4931. DPIO_AFC_RECAL);
  4932. mutex_unlock(&dev_priv->dpio_lock);
  4933. }
  4934. static void i9xx_update_pll(struct intel_crtc *crtc,
  4935. intel_clock_t *reduced_clock,
  4936. int num_connectors)
  4937. {
  4938. struct drm_device *dev = crtc->base.dev;
  4939. struct drm_i915_private *dev_priv = dev->dev_private;
  4940. u32 dpll;
  4941. bool is_sdvo;
  4942. struct dpll *clock = &crtc->config.dpll;
  4943. i9xx_update_pll_dividers(crtc, reduced_clock);
  4944. is_sdvo = intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_SDVO) ||
  4945. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_HDMI);
  4946. dpll = DPLL_VGA_MODE_DIS;
  4947. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS))
  4948. dpll |= DPLLB_MODE_LVDS;
  4949. else
  4950. dpll |= DPLLB_MODE_DAC_SERIAL;
  4951. if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) {
  4952. dpll |= (crtc->config.pixel_multiplier - 1)
  4953. << SDVO_MULTIPLIER_SHIFT_HIRES;
  4954. }
  4955. if (is_sdvo)
  4956. dpll |= DPLL_SDVO_HIGH_SPEED;
  4957. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DISPLAYPORT))
  4958. dpll |= DPLL_SDVO_HIGH_SPEED;
  4959. /* compute bitmask from p1 value */
  4960. if (IS_PINEVIEW(dev))
  4961. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
  4962. else {
  4963. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  4964. if (IS_G4X(dev) && reduced_clock)
  4965. dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
  4966. }
  4967. switch (clock->p2) {
  4968. case 5:
  4969. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
  4970. break;
  4971. case 7:
  4972. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
  4973. break;
  4974. case 10:
  4975. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
  4976. break;
  4977. case 14:
  4978. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
  4979. break;
  4980. }
  4981. if (INTEL_INFO(dev)->gen >= 4)
  4982. dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
  4983. if (crtc->config.sdvo_tv_clock)
  4984. dpll |= PLL_REF_INPUT_TVCLKINBC;
  4985. else if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) &&
  4986. intel_panel_use_ssc(dev_priv) && num_connectors < 2)
  4987. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  4988. else
  4989. dpll |= PLL_REF_INPUT_DREFCLK;
  4990. dpll |= DPLL_VCO_ENABLE;
  4991. crtc->config.dpll_hw_state.dpll = dpll;
  4992. if (INTEL_INFO(dev)->gen >= 4) {
  4993. u32 dpll_md = (crtc->config.pixel_multiplier - 1)
  4994. << DPLL_MD_UDI_MULTIPLIER_SHIFT;
  4995. crtc->config.dpll_hw_state.dpll_md = dpll_md;
  4996. }
  4997. }
  4998. static void i8xx_update_pll(struct intel_crtc *crtc,
  4999. intel_clock_t *reduced_clock,
  5000. int num_connectors)
  5001. {
  5002. struct drm_device *dev = crtc->base.dev;
  5003. struct drm_i915_private *dev_priv = dev->dev_private;
  5004. u32 dpll;
  5005. struct dpll *clock = &crtc->config.dpll;
  5006. i9xx_update_pll_dividers(crtc, reduced_clock);
  5007. dpll = DPLL_VGA_MODE_DIS;
  5008. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS)) {
  5009. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  5010. } else {
  5011. if (clock->p1 == 2)
  5012. dpll |= PLL_P1_DIVIDE_BY_TWO;
  5013. else
  5014. dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  5015. if (clock->p2 == 4)
  5016. dpll |= PLL_P2_DIVIDE_BY_4;
  5017. }
  5018. if (!IS_I830(dev) && intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DVO))
  5019. dpll |= DPLL_DVO_2X_MODE;
  5020. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) &&
  5021. intel_panel_use_ssc(dev_priv) && num_connectors < 2)
  5022. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  5023. else
  5024. dpll |= PLL_REF_INPUT_DREFCLK;
  5025. dpll |= DPLL_VCO_ENABLE;
  5026. crtc->config.dpll_hw_state.dpll = dpll;
  5027. }
  5028. static void intel_set_pipe_timings(struct intel_crtc *intel_crtc)
  5029. {
  5030. struct drm_device *dev = intel_crtc->base.dev;
  5031. struct drm_i915_private *dev_priv = dev->dev_private;
  5032. enum pipe pipe = intel_crtc->pipe;
  5033. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  5034. struct drm_display_mode *adjusted_mode =
  5035. &intel_crtc->config.adjusted_mode;
  5036. uint32_t crtc_vtotal, crtc_vblank_end;
  5037. int vsyncshift = 0;
  5038. /* We need to be careful not to changed the adjusted mode, for otherwise
  5039. * the hw state checker will get angry at the mismatch. */
  5040. crtc_vtotal = adjusted_mode->crtc_vtotal;
  5041. crtc_vblank_end = adjusted_mode->crtc_vblank_end;
  5042. if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
  5043. /* the chip adds 2 halflines automatically */
  5044. crtc_vtotal -= 1;
  5045. crtc_vblank_end -= 1;
  5046. if (intel_pipe_has_type(&intel_crtc->base, INTEL_OUTPUT_SDVO))
  5047. vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2;
  5048. else
  5049. vsyncshift = adjusted_mode->crtc_hsync_start -
  5050. adjusted_mode->crtc_htotal / 2;
  5051. if (vsyncshift < 0)
  5052. vsyncshift += adjusted_mode->crtc_htotal;
  5053. }
  5054. if (INTEL_INFO(dev)->gen > 3)
  5055. I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift);
  5056. I915_WRITE(HTOTAL(cpu_transcoder),
  5057. (adjusted_mode->crtc_hdisplay - 1) |
  5058. ((adjusted_mode->crtc_htotal - 1) << 16));
  5059. I915_WRITE(HBLANK(cpu_transcoder),
  5060. (adjusted_mode->crtc_hblank_start - 1) |
  5061. ((adjusted_mode->crtc_hblank_end - 1) << 16));
  5062. I915_WRITE(HSYNC(cpu_transcoder),
  5063. (adjusted_mode->crtc_hsync_start - 1) |
  5064. ((adjusted_mode->crtc_hsync_end - 1) << 16));
  5065. I915_WRITE(VTOTAL(cpu_transcoder),
  5066. (adjusted_mode->crtc_vdisplay - 1) |
  5067. ((crtc_vtotal - 1) << 16));
  5068. I915_WRITE(VBLANK(cpu_transcoder),
  5069. (adjusted_mode->crtc_vblank_start - 1) |
  5070. ((crtc_vblank_end - 1) << 16));
  5071. I915_WRITE(VSYNC(cpu_transcoder),
  5072. (adjusted_mode->crtc_vsync_start - 1) |
  5073. ((adjusted_mode->crtc_vsync_end - 1) << 16));
  5074. /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
  5075. * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
  5076. * documented on the DDI_FUNC_CTL register description, EDP Input Select
  5077. * bits. */
  5078. if (IS_HASWELL(dev) && cpu_transcoder == TRANSCODER_EDP &&
  5079. (pipe == PIPE_B || pipe == PIPE_C))
  5080. I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder)));
  5081. /* pipesrc controls the size that is scaled from, which should
  5082. * always be the user's requested size.
  5083. */
  5084. I915_WRITE(PIPESRC(pipe),
  5085. ((intel_crtc->config.pipe_src_w - 1) << 16) |
  5086. (intel_crtc->config.pipe_src_h - 1));
  5087. }
  5088. static void intel_get_pipe_timings(struct intel_crtc *crtc,
  5089. struct intel_crtc_config *pipe_config)
  5090. {
  5091. struct drm_device *dev = crtc->base.dev;
  5092. struct drm_i915_private *dev_priv = dev->dev_private;
  5093. enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
  5094. uint32_t tmp;
  5095. tmp = I915_READ(HTOTAL(cpu_transcoder));
  5096. pipe_config->adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1;
  5097. pipe_config->adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1;
  5098. tmp = I915_READ(HBLANK(cpu_transcoder));
  5099. pipe_config->adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1;
  5100. pipe_config->adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1;
  5101. tmp = I915_READ(HSYNC(cpu_transcoder));
  5102. pipe_config->adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1;
  5103. pipe_config->adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1;
  5104. tmp = I915_READ(VTOTAL(cpu_transcoder));
  5105. pipe_config->adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1;
  5106. pipe_config->adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1;
  5107. tmp = I915_READ(VBLANK(cpu_transcoder));
  5108. pipe_config->adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1;
  5109. pipe_config->adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1;
  5110. tmp = I915_READ(VSYNC(cpu_transcoder));
  5111. pipe_config->adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1;
  5112. pipe_config->adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1;
  5113. if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) {
  5114. pipe_config->adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE;
  5115. pipe_config->adjusted_mode.crtc_vtotal += 1;
  5116. pipe_config->adjusted_mode.crtc_vblank_end += 1;
  5117. }
  5118. tmp = I915_READ(PIPESRC(crtc->pipe));
  5119. pipe_config->pipe_src_h = (tmp & 0xffff) + 1;
  5120. pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1;
  5121. pipe_config->requested_mode.vdisplay = pipe_config->pipe_src_h;
  5122. pipe_config->requested_mode.hdisplay = pipe_config->pipe_src_w;
  5123. }
  5124. void intel_mode_from_pipe_config(struct drm_display_mode *mode,
  5125. struct intel_crtc_config *pipe_config)
  5126. {
  5127. mode->hdisplay = pipe_config->adjusted_mode.crtc_hdisplay;
  5128. mode->htotal = pipe_config->adjusted_mode.crtc_htotal;
  5129. mode->hsync_start = pipe_config->adjusted_mode.crtc_hsync_start;
  5130. mode->hsync_end = pipe_config->adjusted_mode.crtc_hsync_end;
  5131. mode->vdisplay = pipe_config->adjusted_mode.crtc_vdisplay;
  5132. mode->vtotal = pipe_config->adjusted_mode.crtc_vtotal;
  5133. mode->vsync_start = pipe_config->adjusted_mode.crtc_vsync_start;
  5134. mode->vsync_end = pipe_config->adjusted_mode.crtc_vsync_end;
  5135. mode->flags = pipe_config->adjusted_mode.flags;
  5136. mode->clock = pipe_config->adjusted_mode.crtc_clock;
  5137. mode->flags |= pipe_config->adjusted_mode.flags;
  5138. }
  5139. static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc)
  5140. {
  5141. struct drm_device *dev = intel_crtc->base.dev;
  5142. struct drm_i915_private *dev_priv = dev->dev_private;
  5143. uint32_t pipeconf;
  5144. pipeconf = 0;
  5145. if ((intel_crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) ||
  5146. (intel_crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))
  5147. pipeconf |= I915_READ(PIPECONF(intel_crtc->pipe)) & PIPECONF_ENABLE;
  5148. if (intel_crtc->config.double_wide)
  5149. pipeconf |= PIPECONF_DOUBLE_WIDE;
  5150. /* only g4x and later have fancy bpc/dither controls */
  5151. if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) {
  5152. /* Bspec claims that we can't use dithering for 30bpp pipes. */
  5153. if (intel_crtc->config.dither && intel_crtc->config.pipe_bpp != 30)
  5154. pipeconf |= PIPECONF_DITHER_EN |
  5155. PIPECONF_DITHER_TYPE_SP;
  5156. switch (intel_crtc->config.pipe_bpp) {
  5157. case 18:
  5158. pipeconf |= PIPECONF_6BPC;
  5159. break;
  5160. case 24:
  5161. pipeconf |= PIPECONF_8BPC;
  5162. break;
  5163. case 30:
  5164. pipeconf |= PIPECONF_10BPC;
  5165. break;
  5166. default:
  5167. /* Case prevented by intel_choose_pipe_bpp_dither. */
  5168. BUG();
  5169. }
  5170. }
  5171. if (HAS_PIPE_CXSR(dev)) {
  5172. if (intel_crtc->lowfreq_avail) {
  5173. DRM_DEBUG_KMS("enabling CxSR downclocking\n");
  5174. pipeconf |= PIPECONF_CXSR_DOWNCLOCK;
  5175. } else {
  5176. DRM_DEBUG_KMS("disabling CxSR downclocking\n");
  5177. }
  5178. }
  5179. if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
  5180. if (INTEL_INFO(dev)->gen < 4 ||
  5181. intel_pipe_has_type(&intel_crtc->base, INTEL_OUTPUT_SDVO))
  5182. pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
  5183. else
  5184. pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT;
  5185. } else
  5186. pipeconf |= PIPECONF_PROGRESSIVE;
  5187. if (IS_VALLEYVIEW(dev) && intel_crtc->config.limited_color_range)
  5188. pipeconf |= PIPECONF_COLOR_RANGE_SELECT;
  5189. I915_WRITE(PIPECONF(intel_crtc->pipe), pipeconf);
  5190. POSTING_READ(PIPECONF(intel_crtc->pipe));
  5191. }
  5192. static int i9xx_crtc_mode_set(struct drm_crtc *crtc,
  5193. int x, int y,
  5194. struct drm_framebuffer *fb)
  5195. {
  5196. struct drm_device *dev = crtc->dev;
  5197. struct drm_i915_private *dev_priv = dev->dev_private;
  5198. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5199. int refclk, num_connectors = 0;
  5200. intel_clock_t clock, reduced_clock;
  5201. bool ok, has_reduced_clock = false;
  5202. bool is_lvds = false, is_dsi = false;
  5203. struct intel_encoder *encoder;
  5204. const intel_limit_t *limit;
  5205. for_each_encoder_on_crtc(dev, crtc, encoder) {
  5206. switch (encoder->type) {
  5207. case INTEL_OUTPUT_LVDS:
  5208. is_lvds = true;
  5209. break;
  5210. case INTEL_OUTPUT_DSI:
  5211. is_dsi = true;
  5212. break;
  5213. }
  5214. num_connectors++;
  5215. }
  5216. if (is_dsi)
  5217. return 0;
  5218. if (!intel_crtc->config.clock_set) {
  5219. refclk = i9xx_get_refclk(crtc, num_connectors);
  5220. /*
  5221. * Returns a set of divisors for the desired target clock with
  5222. * the given refclk, or FALSE. The returned values represent
  5223. * the clock equation: reflck * (5 * (m1 + 2) + (m2 + 2)) / (n +
  5224. * 2) / p1 / p2.
  5225. */
  5226. limit = intel_limit(crtc, refclk);
  5227. ok = dev_priv->display.find_dpll(limit, crtc,
  5228. intel_crtc->config.port_clock,
  5229. refclk, NULL, &clock);
  5230. if (!ok) {
  5231. DRM_ERROR("Couldn't find PLL settings for mode!\n");
  5232. return -EINVAL;
  5233. }
  5234. if (is_lvds && dev_priv->lvds_downclock_avail) {
  5235. /*
  5236. * Ensure we match the reduced clock's P to the target
  5237. * clock. If the clocks don't match, we can't switch
  5238. * the display clock by using the FP0/FP1. In such case
  5239. * we will disable the LVDS downclock feature.
  5240. */
  5241. has_reduced_clock =
  5242. dev_priv->display.find_dpll(limit, crtc,
  5243. dev_priv->lvds_downclock,
  5244. refclk, &clock,
  5245. &reduced_clock);
  5246. }
  5247. /* Compat-code for transition, will disappear. */
  5248. intel_crtc->config.dpll.n = clock.n;
  5249. intel_crtc->config.dpll.m1 = clock.m1;
  5250. intel_crtc->config.dpll.m2 = clock.m2;
  5251. intel_crtc->config.dpll.p1 = clock.p1;
  5252. intel_crtc->config.dpll.p2 = clock.p2;
  5253. }
  5254. if (IS_GEN2(dev)) {
  5255. i8xx_update_pll(intel_crtc,
  5256. has_reduced_clock ? &reduced_clock : NULL,
  5257. num_connectors);
  5258. } else if (IS_CHERRYVIEW(dev)) {
  5259. chv_update_pll(intel_crtc);
  5260. } else if (IS_VALLEYVIEW(dev)) {
  5261. vlv_update_pll(intel_crtc);
  5262. } else {
  5263. i9xx_update_pll(intel_crtc,
  5264. has_reduced_clock ? &reduced_clock : NULL,
  5265. num_connectors);
  5266. }
  5267. return 0;
  5268. }
  5269. static void i9xx_get_pfit_config(struct intel_crtc *crtc,
  5270. struct intel_crtc_config *pipe_config)
  5271. {
  5272. struct drm_device *dev = crtc->base.dev;
  5273. struct drm_i915_private *dev_priv = dev->dev_private;
  5274. uint32_t tmp;
  5275. if (INTEL_INFO(dev)->gen <= 3 && (IS_I830(dev) || !IS_MOBILE(dev)))
  5276. return;
  5277. tmp = I915_READ(PFIT_CONTROL);
  5278. if (!(tmp & PFIT_ENABLE))
  5279. return;
  5280. /* Check whether the pfit is attached to our pipe. */
  5281. if (INTEL_INFO(dev)->gen < 4) {
  5282. if (crtc->pipe != PIPE_B)
  5283. return;
  5284. } else {
  5285. if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT))
  5286. return;
  5287. }
  5288. pipe_config->gmch_pfit.control = tmp;
  5289. pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS);
  5290. if (INTEL_INFO(dev)->gen < 5)
  5291. pipe_config->gmch_pfit.lvds_border_bits =
  5292. I915_READ(LVDS) & LVDS_BORDER_ENABLE;
  5293. }
  5294. static void vlv_crtc_clock_get(struct intel_crtc *crtc,
  5295. struct intel_crtc_config *pipe_config)
  5296. {
  5297. struct drm_device *dev = crtc->base.dev;
  5298. struct drm_i915_private *dev_priv = dev->dev_private;
  5299. int pipe = pipe_config->cpu_transcoder;
  5300. intel_clock_t clock;
  5301. u32 mdiv;
  5302. int refclk = 100000;
  5303. /* In case of MIPI DPLL will not even be used */
  5304. if (!(pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE))
  5305. return;
  5306. mutex_lock(&dev_priv->dpio_lock);
  5307. mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe));
  5308. mutex_unlock(&dev_priv->dpio_lock);
  5309. clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7;
  5310. clock.m2 = mdiv & DPIO_M2DIV_MASK;
  5311. clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf;
  5312. clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7;
  5313. clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f;
  5314. vlv_clock(refclk, &clock);
  5315. /* clock.dot is the fast clock */
  5316. pipe_config->port_clock = clock.dot / 5;
  5317. }
  5318. static void i9xx_get_plane_config(struct intel_crtc *crtc,
  5319. struct intel_plane_config *plane_config)
  5320. {
  5321. struct drm_device *dev = crtc->base.dev;
  5322. struct drm_i915_private *dev_priv = dev->dev_private;
  5323. u32 val, base, offset;
  5324. int pipe = crtc->pipe, plane = crtc->plane;
  5325. int fourcc, pixel_format;
  5326. int aligned_height;
  5327. crtc->base.primary->fb = kzalloc(sizeof(struct intel_framebuffer), GFP_KERNEL);
  5328. if (!crtc->base.primary->fb) {
  5329. DRM_DEBUG_KMS("failed to alloc fb\n");
  5330. return;
  5331. }
  5332. val = I915_READ(DSPCNTR(plane));
  5333. if (INTEL_INFO(dev)->gen >= 4)
  5334. if (val & DISPPLANE_TILED)
  5335. plane_config->tiled = true;
  5336. pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
  5337. fourcc = intel_format_to_fourcc(pixel_format);
  5338. crtc->base.primary->fb->pixel_format = fourcc;
  5339. crtc->base.primary->fb->bits_per_pixel =
  5340. drm_format_plane_cpp(fourcc, 0) * 8;
  5341. if (INTEL_INFO(dev)->gen >= 4) {
  5342. if (plane_config->tiled)
  5343. offset = I915_READ(DSPTILEOFF(plane));
  5344. else
  5345. offset = I915_READ(DSPLINOFF(plane));
  5346. base = I915_READ(DSPSURF(plane)) & 0xfffff000;
  5347. } else {
  5348. base = I915_READ(DSPADDR(plane));
  5349. }
  5350. plane_config->base = base;
  5351. val = I915_READ(PIPESRC(pipe));
  5352. crtc->base.primary->fb->width = ((val >> 16) & 0xfff) + 1;
  5353. crtc->base.primary->fb->height = ((val >> 0) & 0xfff) + 1;
  5354. val = I915_READ(DSPSTRIDE(pipe));
  5355. crtc->base.primary->fb->pitches[0] = val & 0xffffffc0;
  5356. aligned_height = intel_align_height(dev, crtc->base.primary->fb->height,
  5357. plane_config->tiled);
  5358. plane_config->size = PAGE_ALIGN(crtc->base.primary->fb->pitches[0] *
  5359. aligned_height);
  5360. DRM_DEBUG_KMS("pipe/plane %d/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
  5361. pipe, plane, crtc->base.primary->fb->width,
  5362. crtc->base.primary->fb->height,
  5363. crtc->base.primary->fb->bits_per_pixel, base,
  5364. crtc->base.primary->fb->pitches[0],
  5365. plane_config->size);
  5366. }
  5367. static void chv_crtc_clock_get(struct intel_crtc *crtc,
  5368. struct intel_crtc_config *pipe_config)
  5369. {
  5370. struct drm_device *dev = crtc->base.dev;
  5371. struct drm_i915_private *dev_priv = dev->dev_private;
  5372. int pipe = pipe_config->cpu_transcoder;
  5373. enum dpio_channel port = vlv_pipe_to_channel(pipe);
  5374. intel_clock_t clock;
  5375. u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2;
  5376. int refclk = 100000;
  5377. mutex_lock(&dev_priv->dpio_lock);
  5378. cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port));
  5379. pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port));
  5380. pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port));
  5381. pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port));
  5382. mutex_unlock(&dev_priv->dpio_lock);
  5383. clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0;
  5384. clock.m2 = ((pll_dw0 & 0xff) << 22) | (pll_dw2 & 0x3fffff);
  5385. clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf;
  5386. clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7;
  5387. clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f;
  5388. chv_clock(refclk, &clock);
  5389. /* clock.dot is the fast clock */
  5390. pipe_config->port_clock = clock.dot / 5;
  5391. }
  5392. static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
  5393. struct intel_crtc_config *pipe_config)
  5394. {
  5395. struct drm_device *dev = crtc->base.dev;
  5396. struct drm_i915_private *dev_priv = dev->dev_private;
  5397. uint32_t tmp;
  5398. if (!intel_display_power_enabled(dev_priv,
  5399. POWER_DOMAIN_PIPE(crtc->pipe)))
  5400. return false;
  5401. pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
  5402. pipe_config->shared_dpll = DPLL_ID_PRIVATE;
  5403. tmp = I915_READ(PIPECONF(crtc->pipe));
  5404. if (!(tmp & PIPECONF_ENABLE))
  5405. return false;
  5406. if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) {
  5407. switch (tmp & PIPECONF_BPC_MASK) {
  5408. case PIPECONF_6BPC:
  5409. pipe_config->pipe_bpp = 18;
  5410. break;
  5411. case PIPECONF_8BPC:
  5412. pipe_config->pipe_bpp = 24;
  5413. break;
  5414. case PIPECONF_10BPC:
  5415. pipe_config->pipe_bpp = 30;
  5416. break;
  5417. default:
  5418. break;
  5419. }
  5420. }
  5421. if (IS_VALLEYVIEW(dev) && (tmp & PIPECONF_COLOR_RANGE_SELECT))
  5422. pipe_config->limited_color_range = true;
  5423. if (INTEL_INFO(dev)->gen < 4)
  5424. pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE;
  5425. intel_get_pipe_timings(crtc, pipe_config);
  5426. i9xx_get_pfit_config(crtc, pipe_config);
  5427. if (INTEL_INFO(dev)->gen >= 4) {
  5428. tmp = I915_READ(DPLL_MD(crtc->pipe));
  5429. pipe_config->pixel_multiplier =
  5430. ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK)
  5431. >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1;
  5432. pipe_config->dpll_hw_state.dpll_md = tmp;
  5433. } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) {
  5434. tmp = I915_READ(DPLL(crtc->pipe));
  5435. pipe_config->pixel_multiplier =
  5436. ((tmp & SDVO_MULTIPLIER_MASK)
  5437. >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1;
  5438. } else {
  5439. /* Note that on i915G/GM the pixel multiplier is in the sdvo
  5440. * port and will be fixed up in the encoder->get_config
  5441. * function. */
  5442. pipe_config->pixel_multiplier = 1;
  5443. }
  5444. pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe));
  5445. if (!IS_VALLEYVIEW(dev)) {
  5446. /*
  5447. * DPLL_DVO_2X_MODE must be enabled for both DPLLs
  5448. * on 830. Filter it out here so that we don't
  5449. * report errors due to that.
  5450. */
  5451. if (IS_I830(dev))
  5452. pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE;
  5453. pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe));
  5454. pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe));
  5455. } else {
  5456. /* Mask out read-only status bits. */
  5457. pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV |
  5458. DPLL_PORTC_READY_MASK |
  5459. DPLL_PORTB_READY_MASK);
  5460. }
  5461. if (IS_CHERRYVIEW(dev))
  5462. chv_crtc_clock_get(crtc, pipe_config);
  5463. else if (IS_VALLEYVIEW(dev))
  5464. vlv_crtc_clock_get(crtc, pipe_config);
  5465. else
  5466. i9xx_crtc_clock_get(crtc, pipe_config);
  5467. return true;
  5468. }
  5469. static void ironlake_init_pch_refclk(struct drm_device *dev)
  5470. {
  5471. struct drm_i915_private *dev_priv = dev->dev_private;
  5472. struct intel_encoder *encoder;
  5473. u32 val, final;
  5474. bool has_lvds = false;
  5475. bool has_cpu_edp = false;
  5476. bool has_panel = false;
  5477. bool has_ck505 = false;
  5478. bool can_ssc = false;
  5479. /* We need to take the global config into account */
  5480. for_each_intel_encoder(dev, encoder) {
  5481. switch (encoder->type) {
  5482. case INTEL_OUTPUT_LVDS:
  5483. has_panel = true;
  5484. has_lvds = true;
  5485. break;
  5486. case INTEL_OUTPUT_EDP:
  5487. has_panel = true;
  5488. if (enc_to_dig_port(&encoder->base)->port == PORT_A)
  5489. has_cpu_edp = true;
  5490. break;
  5491. }
  5492. }
  5493. if (HAS_PCH_IBX(dev)) {
  5494. has_ck505 = dev_priv->vbt.display_clock_mode;
  5495. can_ssc = has_ck505;
  5496. } else {
  5497. has_ck505 = false;
  5498. can_ssc = true;
  5499. }
  5500. DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d\n",
  5501. has_panel, has_lvds, has_ck505);
  5502. /* Ironlake: try to setup display ref clock before DPLL
  5503. * enabling. This is only under driver's control after
  5504. * PCH B stepping, previous chipset stepping should be
  5505. * ignoring this setting.
  5506. */
  5507. val = I915_READ(PCH_DREF_CONTROL);
  5508. /* As we must carefully and slowly disable/enable each source in turn,
  5509. * compute the final state we want first and check if we need to
  5510. * make any changes at all.
  5511. */
  5512. final = val;
  5513. final &= ~DREF_NONSPREAD_SOURCE_MASK;
  5514. if (has_ck505)
  5515. final |= DREF_NONSPREAD_CK505_ENABLE;
  5516. else
  5517. final |= DREF_NONSPREAD_SOURCE_ENABLE;
  5518. final &= ~DREF_SSC_SOURCE_MASK;
  5519. final &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
  5520. final &= ~DREF_SSC1_ENABLE;
  5521. if (has_panel) {
  5522. final |= DREF_SSC_SOURCE_ENABLE;
  5523. if (intel_panel_use_ssc(dev_priv) && can_ssc)
  5524. final |= DREF_SSC1_ENABLE;
  5525. if (has_cpu_edp) {
  5526. if (intel_panel_use_ssc(dev_priv) && can_ssc)
  5527. final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
  5528. else
  5529. final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
  5530. } else
  5531. final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  5532. } else {
  5533. final |= DREF_SSC_SOURCE_DISABLE;
  5534. final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  5535. }
  5536. if (final == val)
  5537. return;
  5538. /* Always enable nonspread source */
  5539. val &= ~DREF_NONSPREAD_SOURCE_MASK;
  5540. if (has_ck505)
  5541. val |= DREF_NONSPREAD_CK505_ENABLE;
  5542. else
  5543. val |= DREF_NONSPREAD_SOURCE_ENABLE;
  5544. if (has_panel) {
  5545. val &= ~DREF_SSC_SOURCE_MASK;
  5546. val |= DREF_SSC_SOURCE_ENABLE;
  5547. /* SSC must be turned on before enabling the CPU output */
  5548. if (intel_panel_use_ssc(dev_priv) && can_ssc) {
  5549. DRM_DEBUG_KMS("Using SSC on panel\n");
  5550. val |= DREF_SSC1_ENABLE;
  5551. } else
  5552. val &= ~DREF_SSC1_ENABLE;
  5553. /* Get SSC going before enabling the outputs */
  5554. I915_WRITE(PCH_DREF_CONTROL, val);
  5555. POSTING_READ(PCH_DREF_CONTROL);
  5556. udelay(200);
  5557. val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
  5558. /* Enable CPU source on CPU attached eDP */
  5559. if (has_cpu_edp) {
  5560. if (intel_panel_use_ssc(dev_priv) && can_ssc) {
  5561. DRM_DEBUG_KMS("Using SSC on eDP\n");
  5562. val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
  5563. } else
  5564. val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
  5565. } else
  5566. val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  5567. I915_WRITE(PCH_DREF_CONTROL, val);
  5568. POSTING_READ(PCH_DREF_CONTROL);
  5569. udelay(200);
  5570. } else {
  5571. DRM_DEBUG_KMS("Disabling SSC entirely\n");
  5572. val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
  5573. /* Turn off CPU output */
  5574. val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  5575. I915_WRITE(PCH_DREF_CONTROL, val);
  5576. POSTING_READ(PCH_DREF_CONTROL);
  5577. udelay(200);
  5578. /* Turn off the SSC source */
  5579. val &= ~DREF_SSC_SOURCE_MASK;
  5580. val |= DREF_SSC_SOURCE_DISABLE;
  5581. /* Turn off SSC1 */
  5582. val &= ~DREF_SSC1_ENABLE;
  5583. I915_WRITE(PCH_DREF_CONTROL, val);
  5584. POSTING_READ(PCH_DREF_CONTROL);
  5585. udelay(200);
  5586. }
  5587. BUG_ON(val != final);
  5588. }
  5589. static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv)
  5590. {
  5591. uint32_t tmp;
  5592. tmp = I915_READ(SOUTH_CHICKEN2);
  5593. tmp |= FDI_MPHY_IOSFSB_RESET_CTL;
  5594. I915_WRITE(SOUTH_CHICKEN2, tmp);
  5595. if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2) &
  5596. FDI_MPHY_IOSFSB_RESET_STATUS, 100))
  5597. DRM_ERROR("FDI mPHY reset assert timeout\n");
  5598. tmp = I915_READ(SOUTH_CHICKEN2);
  5599. tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL;
  5600. I915_WRITE(SOUTH_CHICKEN2, tmp);
  5601. if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2) &
  5602. FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100))
  5603. DRM_ERROR("FDI mPHY reset de-assert timeout\n");
  5604. }
  5605. /* WaMPhyProgramming:hsw */
  5606. static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv)
  5607. {
  5608. uint32_t tmp;
  5609. tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY);
  5610. tmp &= ~(0xFF << 24);
  5611. tmp |= (0x12 << 24);
  5612. intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY);
  5613. tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY);
  5614. tmp |= (1 << 11);
  5615. intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY);
  5616. tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY);
  5617. tmp |= (1 << 11);
  5618. intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY);
  5619. tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY);
  5620. tmp |= (1 << 24) | (1 << 21) | (1 << 18);
  5621. intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY);
  5622. tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY);
  5623. tmp |= (1 << 24) | (1 << 21) | (1 << 18);
  5624. intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY);
  5625. tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY);
  5626. tmp &= ~(7 << 13);
  5627. tmp |= (5 << 13);
  5628. intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY);
  5629. tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY);
  5630. tmp &= ~(7 << 13);
  5631. tmp |= (5 << 13);
  5632. intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY);
  5633. tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY);
  5634. tmp &= ~0xFF;
  5635. tmp |= 0x1C;
  5636. intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY);
  5637. tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY);
  5638. tmp &= ~0xFF;
  5639. tmp |= 0x1C;
  5640. intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY);
  5641. tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY);
  5642. tmp &= ~(0xFF << 16);
  5643. tmp |= (0x1C << 16);
  5644. intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY);
  5645. tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY);
  5646. tmp &= ~(0xFF << 16);
  5647. tmp |= (0x1C << 16);
  5648. intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY);
  5649. tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY);
  5650. tmp |= (1 << 27);
  5651. intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY);
  5652. tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY);
  5653. tmp |= (1 << 27);
  5654. intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY);
  5655. tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY);
  5656. tmp &= ~(0xF << 28);
  5657. tmp |= (4 << 28);
  5658. intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY);
  5659. tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY);
  5660. tmp &= ~(0xF << 28);
  5661. tmp |= (4 << 28);
  5662. intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY);
  5663. }
  5664. /* Implements 3 different sequences from BSpec chapter "Display iCLK
  5665. * Programming" based on the parameters passed:
  5666. * - Sequence to enable CLKOUT_DP
  5667. * - Sequence to enable CLKOUT_DP without spread
  5668. * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
  5669. */
  5670. static void lpt_enable_clkout_dp(struct drm_device *dev, bool with_spread,
  5671. bool with_fdi)
  5672. {
  5673. struct drm_i915_private *dev_priv = dev->dev_private;
  5674. uint32_t reg, tmp;
  5675. if (WARN(with_fdi && !with_spread, "FDI requires downspread\n"))
  5676. with_spread = true;
  5677. if (WARN(dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE &&
  5678. with_fdi, "LP PCH doesn't have FDI\n"))
  5679. with_fdi = false;
  5680. mutex_lock(&dev_priv->dpio_lock);
  5681. tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
  5682. tmp &= ~SBI_SSCCTL_DISABLE;
  5683. tmp |= SBI_SSCCTL_PATHALT;
  5684. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  5685. udelay(24);
  5686. if (with_spread) {
  5687. tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
  5688. tmp &= ~SBI_SSCCTL_PATHALT;
  5689. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  5690. if (with_fdi) {
  5691. lpt_reset_fdi_mphy(dev_priv);
  5692. lpt_program_fdi_mphy(dev_priv);
  5693. }
  5694. }
  5695. reg = (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) ?
  5696. SBI_GEN0 : SBI_DBUFF0;
  5697. tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
  5698. tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE;
  5699. intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
  5700. mutex_unlock(&dev_priv->dpio_lock);
  5701. }
  5702. /* Sequence to disable CLKOUT_DP */
  5703. static void lpt_disable_clkout_dp(struct drm_device *dev)
  5704. {
  5705. struct drm_i915_private *dev_priv = dev->dev_private;
  5706. uint32_t reg, tmp;
  5707. mutex_lock(&dev_priv->dpio_lock);
  5708. reg = (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) ?
  5709. SBI_GEN0 : SBI_DBUFF0;
  5710. tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
  5711. tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE;
  5712. intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
  5713. tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
  5714. if (!(tmp & SBI_SSCCTL_DISABLE)) {
  5715. if (!(tmp & SBI_SSCCTL_PATHALT)) {
  5716. tmp |= SBI_SSCCTL_PATHALT;
  5717. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  5718. udelay(32);
  5719. }
  5720. tmp |= SBI_SSCCTL_DISABLE;
  5721. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  5722. }
  5723. mutex_unlock(&dev_priv->dpio_lock);
  5724. }
  5725. static void lpt_init_pch_refclk(struct drm_device *dev)
  5726. {
  5727. struct intel_encoder *encoder;
  5728. bool has_vga = false;
  5729. for_each_intel_encoder(dev, encoder) {
  5730. switch (encoder->type) {
  5731. case INTEL_OUTPUT_ANALOG:
  5732. has_vga = true;
  5733. break;
  5734. }
  5735. }
  5736. if (has_vga)
  5737. lpt_enable_clkout_dp(dev, true, true);
  5738. else
  5739. lpt_disable_clkout_dp(dev);
  5740. }
  5741. /*
  5742. * Initialize reference clocks when the driver loads
  5743. */
  5744. void intel_init_pch_refclk(struct drm_device *dev)
  5745. {
  5746. if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
  5747. ironlake_init_pch_refclk(dev);
  5748. else if (HAS_PCH_LPT(dev))
  5749. lpt_init_pch_refclk(dev);
  5750. }
  5751. static int ironlake_get_refclk(struct drm_crtc *crtc)
  5752. {
  5753. struct drm_device *dev = crtc->dev;
  5754. struct drm_i915_private *dev_priv = dev->dev_private;
  5755. struct intel_encoder *encoder;
  5756. int num_connectors = 0;
  5757. bool is_lvds = false;
  5758. for_each_encoder_on_crtc(dev, crtc, encoder) {
  5759. switch (encoder->type) {
  5760. case INTEL_OUTPUT_LVDS:
  5761. is_lvds = true;
  5762. break;
  5763. }
  5764. num_connectors++;
  5765. }
  5766. if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) {
  5767. DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
  5768. dev_priv->vbt.lvds_ssc_freq);
  5769. return dev_priv->vbt.lvds_ssc_freq;
  5770. }
  5771. return 120000;
  5772. }
  5773. static void ironlake_set_pipeconf(struct drm_crtc *crtc)
  5774. {
  5775. struct drm_i915_private *dev_priv = crtc->dev->dev_private;
  5776. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5777. int pipe = intel_crtc->pipe;
  5778. uint32_t val;
  5779. val = 0;
  5780. switch (intel_crtc->config.pipe_bpp) {
  5781. case 18:
  5782. val |= PIPECONF_6BPC;
  5783. break;
  5784. case 24:
  5785. val |= PIPECONF_8BPC;
  5786. break;
  5787. case 30:
  5788. val |= PIPECONF_10BPC;
  5789. break;
  5790. case 36:
  5791. val |= PIPECONF_12BPC;
  5792. break;
  5793. default:
  5794. /* Case prevented by intel_choose_pipe_bpp_dither. */
  5795. BUG();
  5796. }
  5797. if (intel_crtc->config.dither)
  5798. val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
  5799. if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
  5800. val |= PIPECONF_INTERLACED_ILK;
  5801. else
  5802. val |= PIPECONF_PROGRESSIVE;
  5803. if (intel_crtc->config.limited_color_range)
  5804. val |= PIPECONF_COLOR_RANGE_SELECT;
  5805. I915_WRITE(PIPECONF(pipe), val);
  5806. POSTING_READ(PIPECONF(pipe));
  5807. }
  5808. /*
  5809. * Set up the pipe CSC unit.
  5810. *
  5811. * Currently only full range RGB to limited range RGB conversion
  5812. * is supported, but eventually this should handle various
  5813. * RGB<->YCbCr scenarios as well.
  5814. */
  5815. static void intel_set_pipe_csc(struct drm_crtc *crtc)
  5816. {
  5817. struct drm_device *dev = crtc->dev;
  5818. struct drm_i915_private *dev_priv = dev->dev_private;
  5819. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5820. int pipe = intel_crtc->pipe;
  5821. uint16_t coeff = 0x7800; /* 1.0 */
  5822. /*
  5823. * TODO: Check what kind of values actually come out of the pipe
  5824. * with these coeff/postoff values and adjust to get the best
  5825. * accuracy. Perhaps we even need to take the bpc value into
  5826. * consideration.
  5827. */
  5828. if (intel_crtc->config.limited_color_range)
  5829. coeff = ((235 - 16) * (1 << 12) / 255) & 0xff8; /* 0.xxx... */
  5830. /*
  5831. * GY/GU and RY/RU should be the other way around according
  5832. * to BSpec, but reality doesn't agree. Just set them up in
  5833. * a way that results in the correct picture.
  5834. */
  5835. I915_WRITE(PIPE_CSC_COEFF_RY_GY(pipe), coeff << 16);
  5836. I915_WRITE(PIPE_CSC_COEFF_BY(pipe), 0);
  5837. I915_WRITE(PIPE_CSC_COEFF_RU_GU(pipe), coeff);
  5838. I915_WRITE(PIPE_CSC_COEFF_BU(pipe), 0);
  5839. I915_WRITE(PIPE_CSC_COEFF_RV_GV(pipe), 0);
  5840. I915_WRITE(PIPE_CSC_COEFF_BV(pipe), coeff << 16);
  5841. I915_WRITE(PIPE_CSC_PREOFF_HI(pipe), 0);
  5842. I915_WRITE(PIPE_CSC_PREOFF_ME(pipe), 0);
  5843. I915_WRITE(PIPE_CSC_PREOFF_LO(pipe), 0);
  5844. if (INTEL_INFO(dev)->gen > 6) {
  5845. uint16_t postoff = 0;
  5846. if (intel_crtc->config.limited_color_range)
  5847. postoff = (16 * (1 << 12) / 255) & 0x1fff;
  5848. I915_WRITE(PIPE_CSC_POSTOFF_HI(pipe), postoff);
  5849. I915_WRITE(PIPE_CSC_POSTOFF_ME(pipe), postoff);
  5850. I915_WRITE(PIPE_CSC_POSTOFF_LO(pipe), postoff);
  5851. I915_WRITE(PIPE_CSC_MODE(pipe), 0);
  5852. } else {
  5853. uint32_t mode = CSC_MODE_YUV_TO_RGB;
  5854. if (intel_crtc->config.limited_color_range)
  5855. mode |= CSC_BLACK_SCREEN_OFFSET;
  5856. I915_WRITE(PIPE_CSC_MODE(pipe), mode);
  5857. }
  5858. }
  5859. static void haswell_set_pipeconf(struct drm_crtc *crtc)
  5860. {
  5861. struct drm_device *dev = crtc->dev;
  5862. struct drm_i915_private *dev_priv = dev->dev_private;
  5863. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5864. enum pipe pipe = intel_crtc->pipe;
  5865. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  5866. uint32_t val;
  5867. val = 0;
  5868. if (IS_HASWELL(dev) && intel_crtc->config.dither)
  5869. val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
  5870. if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
  5871. val |= PIPECONF_INTERLACED_ILK;
  5872. else
  5873. val |= PIPECONF_PROGRESSIVE;
  5874. I915_WRITE(PIPECONF(cpu_transcoder), val);
  5875. POSTING_READ(PIPECONF(cpu_transcoder));
  5876. I915_WRITE(GAMMA_MODE(intel_crtc->pipe), GAMMA_MODE_MODE_8BIT);
  5877. POSTING_READ(GAMMA_MODE(intel_crtc->pipe));
  5878. if (IS_BROADWELL(dev)) {
  5879. val = 0;
  5880. switch (intel_crtc->config.pipe_bpp) {
  5881. case 18:
  5882. val |= PIPEMISC_DITHER_6_BPC;
  5883. break;
  5884. case 24:
  5885. val |= PIPEMISC_DITHER_8_BPC;
  5886. break;
  5887. case 30:
  5888. val |= PIPEMISC_DITHER_10_BPC;
  5889. break;
  5890. case 36:
  5891. val |= PIPEMISC_DITHER_12_BPC;
  5892. break;
  5893. default:
  5894. /* Case prevented by pipe_config_set_bpp. */
  5895. BUG();
  5896. }
  5897. if (intel_crtc->config.dither)
  5898. val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP;
  5899. I915_WRITE(PIPEMISC(pipe), val);
  5900. }
  5901. }
  5902. static bool ironlake_compute_clocks(struct drm_crtc *crtc,
  5903. intel_clock_t *clock,
  5904. bool *has_reduced_clock,
  5905. intel_clock_t *reduced_clock)
  5906. {
  5907. struct drm_device *dev = crtc->dev;
  5908. struct drm_i915_private *dev_priv = dev->dev_private;
  5909. struct intel_encoder *intel_encoder;
  5910. int refclk;
  5911. const intel_limit_t *limit;
  5912. bool ret, is_lvds = false;
  5913. for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
  5914. switch (intel_encoder->type) {
  5915. case INTEL_OUTPUT_LVDS:
  5916. is_lvds = true;
  5917. break;
  5918. }
  5919. }
  5920. refclk = ironlake_get_refclk(crtc);
  5921. /*
  5922. * Returns a set of divisors for the desired target clock with the given
  5923. * refclk, or FALSE. The returned values represent the clock equation:
  5924. * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
  5925. */
  5926. limit = intel_limit(crtc, refclk);
  5927. ret = dev_priv->display.find_dpll(limit, crtc,
  5928. to_intel_crtc(crtc)->config.port_clock,
  5929. refclk, NULL, clock);
  5930. if (!ret)
  5931. return false;
  5932. if (is_lvds && dev_priv->lvds_downclock_avail) {
  5933. /*
  5934. * Ensure we match the reduced clock's P to the target clock.
  5935. * If the clocks don't match, we can't switch the display clock
  5936. * by using the FP0/FP1. In such case we will disable the LVDS
  5937. * downclock feature.
  5938. */
  5939. *has_reduced_clock =
  5940. dev_priv->display.find_dpll(limit, crtc,
  5941. dev_priv->lvds_downclock,
  5942. refclk, clock,
  5943. reduced_clock);
  5944. }
  5945. return true;
  5946. }
  5947. int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp)
  5948. {
  5949. /*
  5950. * Account for spread spectrum to avoid
  5951. * oversubscribing the link. Max center spread
  5952. * is 2.5%; use 5% for safety's sake.
  5953. */
  5954. u32 bps = target_clock * bpp * 21 / 20;
  5955. return DIV_ROUND_UP(bps, link_bw * 8);
  5956. }
  5957. static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor)
  5958. {
  5959. return i9xx_dpll_compute_m(dpll) < factor * dpll->n;
  5960. }
  5961. static uint32_t ironlake_compute_dpll(struct intel_crtc *intel_crtc,
  5962. u32 *fp,
  5963. intel_clock_t *reduced_clock, u32 *fp2)
  5964. {
  5965. struct drm_crtc *crtc = &intel_crtc->base;
  5966. struct drm_device *dev = crtc->dev;
  5967. struct drm_i915_private *dev_priv = dev->dev_private;
  5968. struct intel_encoder *intel_encoder;
  5969. uint32_t dpll;
  5970. int factor, num_connectors = 0;
  5971. bool is_lvds = false, is_sdvo = false;
  5972. for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
  5973. switch (intel_encoder->type) {
  5974. case INTEL_OUTPUT_LVDS:
  5975. is_lvds = true;
  5976. break;
  5977. case INTEL_OUTPUT_SDVO:
  5978. case INTEL_OUTPUT_HDMI:
  5979. is_sdvo = true;
  5980. break;
  5981. }
  5982. num_connectors++;
  5983. }
  5984. /* Enable autotuning of the PLL clock (if permissible) */
  5985. factor = 21;
  5986. if (is_lvds) {
  5987. if ((intel_panel_use_ssc(dev_priv) &&
  5988. dev_priv->vbt.lvds_ssc_freq == 100000) ||
  5989. (HAS_PCH_IBX(dev) && intel_is_dual_link_lvds(dev)))
  5990. factor = 25;
  5991. } else if (intel_crtc->config.sdvo_tv_clock)
  5992. factor = 20;
  5993. if (ironlake_needs_fb_cb_tune(&intel_crtc->config.dpll, factor))
  5994. *fp |= FP_CB_TUNE;
  5995. if (fp2 && (reduced_clock->m < factor * reduced_clock->n))
  5996. *fp2 |= FP_CB_TUNE;
  5997. dpll = 0;
  5998. if (is_lvds)
  5999. dpll |= DPLLB_MODE_LVDS;
  6000. else
  6001. dpll |= DPLLB_MODE_DAC_SERIAL;
  6002. dpll |= (intel_crtc->config.pixel_multiplier - 1)
  6003. << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
  6004. if (is_sdvo)
  6005. dpll |= DPLL_SDVO_HIGH_SPEED;
  6006. if (intel_crtc->config.has_dp_encoder)
  6007. dpll |= DPLL_SDVO_HIGH_SPEED;
  6008. /* compute bitmask from p1 value */
  6009. dpll |= (1 << (intel_crtc->config.dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  6010. /* also FPA1 */
  6011. dpll |= (1 << (intel_crtc->config.dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
  6012. switch (intel_crtc->config.dpll.p2) {
  6013. case 5:
  6014. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
  6015. break;
  6016. case 7:
  6017. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
  6018. break;
  6019. case 10:
  6020. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
  6021. break;
  6022. case 14:
  6023. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
  6024. break;
  6025. }
  6026. if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2)
  6027. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  6028. else
  6029. dpll |= PLL_REF_INPUT_DREFCLK;
  6030. return dpll | DPLL_VCO_ENABLE;
  6031. }
  6032. static int ironlake_crtc_mode_set(struct drm_crtc *crtc,
  6033. int x, int y,
  6034. struct drm_framebuffer *fb)
  6035. {
  6036. struct drm_device *dev = crtc->dev;
  6037. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6038. int num_connectors = 0;
  6039. intel_clock_t clock, reduced_clock;
  6040. u32 dpll = 0, fp = 0, fp2 = 0;
  6041. bool ok, has_reduced_clock = false;
  6042. bool is_lvds = false;
  6043. struct intel_encoder *encoder;
  6044. struct intel_shared_dpll *pll;
  6045. for_each_encoder_on_crtc(dev, crtc, encoder) {
  6046. switch (encoder->type) {
  6047. case INTEL_OUTPUT_LVDS:
  6048. is_lvds = true;
  6049. break;
  6050. }
  6051. num_connectors++;
  6052. }
  6053. WARN(!(HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)),
  6054. "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev));
  6055. ok = ironlake_compute_clocks(crtc, &clock,
  6056. &has_reduced_clock, &reduced_clock);
  6057. if (!ok && !intel_crtc->config.clock_set) {
  6058. DRM_ERROR("Couldn't find PLL settings for mode!\n");
  6059. return -EINVAL;
  6060. }
  6061. /* Compat-code for transition, will disappear. */
  6062. if (!intel_crtc->config.clock_set) {
  6063. intel_crtc->config.dpll.n = clock.n;
  6064. intel_crtc->config.dpll.m1 = clock.m1;
  6065. intel_crtc->config.dpll.m2 = clock.m2;
  6066. intel_crtc->config.dpll.p1 = clock.p1;
  6067. intel_crtc->config.dpll.p2 = clock.p2;
  6068. }
  6069. /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
  6070. if (intel_crtc->config.has_pch_encoder) {
  6071. fp = i9xx_dpll_compute_fp(&intel_crtc->config.dpll);
  6072. if (has_reduced_clock)
  6073. fp2 = i9xx_dpll_compute_fp(&reduced_clock);
  6074. dpll = ironlake_compute_dpll(intel_crtc,
  6075. &fp, &reduced_clock,
  6076. has_reduced_clock ? &fp2 : NULL);
  6077. intel_crtc->config.dpll_hw_state.dpll = dpll;
  6078. intel_crtc->config.dpll_hw_state.fp0 = fp;
  6079. if (has_reduced_clock)
  6080. intel_crtc->config.dpll_hw_state.fp1 = fp2;
  6081. else
  6082. intel_crtc->config.dpll_hw_state.fp1 = fp;
  6083. pll = intel_get_shared_dpll(intel_crtc);
  6084. if (pll == NULL) {
  6085. DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
  6086. pipe_name(intel_crtc->pipe));
  6087. return -EINVAL;
  6088. }
  6089. } else
  6090. intel_put_shared_dpll(intel_crtc);
  6091. if (is_lvds && has_reduced_clock && i915.powersave)
  6092. intel_crtc->lowfreq_avail = true;
  6093. else
  6094. intel_crtc->lowfreq_avail = false;
  6095. return 0;
  6096. }
  6097. static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc,
  6098. struct intel_link_m_n *m_n)
  6099. {
  6100. struct drm_device *dev = crtc->base.dev;
  6101. struct drm_i915_private *dev_priv = dev->dev_private;
  6102. enum pipe pipe = crtc->pipe;
  6103. m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe));
  6104. m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe));
  6105. m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe))
  6106. & ~TU_SIZE_MASK;
  6107. m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe));
  6108. m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe))
  6109. & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
  6110. }
  6111. static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc,
  6112. enum transcoder transcoder,
  6113. struct intel_link_m_n *m_n,
  6114. struct intel_link_m_n *m2_n2)
  6115. {
  6116. struct drm_device *dev = crtc->base.dev;
  6117. struct drm_i915_private *dev_priv = dev->dev_private;
  6118. enum pipe pipe = crtc->pipe;
  6119. if (INTEL_INFO(dev)->gen >= 5) {
  6120. m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder));
  6121. m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder));
  6122. m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder))
  6123. & ~TU_SIZE_MASK;
  6124. m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder));
  6125. m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder))
  6126. & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
  6127. /* Read M2_N2 registers only for gen < 8 (M2_N2 available for
  6128. * gen < 8) and if DRRS is supported (to make sure the
  6129. * registers are not unnecessarily read).
  6130. */
  6131. if (m2_n2 && INTEL_INFO(dev)->gen < 8 &&
  6132. crtc->config.has_drrs) {
  6133. m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder));
  6134. m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder));
  6135. m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder))
  6136. & ~TU_SIZE_MASK;
  6137. m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder));
  6138. m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder))
  6139. & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
  6140. }
  6141. } else {
  6142. m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe));
  6143. m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe));
  6144. m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe))
  6145. & ~TU_SIZE_MASK;
  6146. m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe));
  6147. m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe))
  6148. & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
  6149. }
  6150. }
  6151. void intel_dp_get_m_n(struct intel_crtc *crtc,
  6152. struct intel_crtc_config *pipe_config)
  6153. {
  6154. if (crtc->config.has_pch_encoder)
  6155. intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n);
  6156. else
  6157. intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
  6158. &pipe_config->dp_m_n,
  6159. &pipe_config->dp_m2_n2);
  6160. }
  6161. static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc,
  6162. struct intel_crtc_config *pipe_config)
  6163. {
  6164. intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
  6165. &pipe_config->fdi_m_n, NULL);
  6166. }
  6167. static void ironlake_get_pfit_config(struct intel_crtc *crtc,
  6168. struct intel_crtc_config *pipe_config)
  6169. {
  6170. struct drm_device *dev = crtc->base.dev;
  6171. struct drm_i915_private *dev_priv = dev->dev_private;
  6172. uint32_t tmp;
  6173. tmp = I915_READ(PF_CTL(crtc->pipe));
  6174. if (tmp & PF_ENABLE) {
  6175. pipe_config->pch_pfit.enabled = true;
  6176. pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe));
  6177. pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe));
  6178. /* We currently do not free assignements of panel fitters on
  6179. * ivb/hsw (since we don't use the higher upscaling modes which
  6180. * differentiates them) so just WARN about this case for now. */
  6181. if (IS_GEN7(dev)) {
  6182. WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) !=
  6183. PF_PIPE_SEL_IVB(crtc->pipe));
  6184. }
  6185. }
  6186. }
  6187. static void ironlake_get_plane_config(struct intel_crtc *crtc,
  6188. struct intel_plane_config *plane_config)
  6189. {
  6190. struct drm_device *dev = crtc->base.dev;
  6191. struct drm_i915_private *dev_priv = dev->dev_private;
  6192. u32 val, base, offset;
  6193. int pipe = crtc->pipe, plane = crtc->plane;
  6194. int fourcc, pixel_format;
  6195. int aligned_height;
  6196. crtc->base.primary->fb = kzalloc(sizeof(struct intel_framebuffer), GFP_KERNEL);
  6197. if (!crtc->base.primary->fb) {
  6198. DRM_DEBUG_KMS("failed to alloc fb\n");
  6199. return;
  6200. }
  6201. val = I915_READ(DSPCNTR(plane));
  6202. if (INTEL_INFO(dev)->gen >= 4)
  6203. if (val & DISPPLANE_TILED)
  6204. plane_config->tiled = true;
  6205. pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
  6206. fourcc = intel_format_to_fourcc(pixel_format);
  6207. crtc->base.primary->fb->pixel_format = fourcc;
  6208. crtc->base.primary->fb->bits_per_pixel =
  6209. drm_format_plane_cpp(fourcc, 0) * 8;
  6210. base = I915_READ(DSPSURF(plane)) & 0xfffff000;
  6211. if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
  6212. offset = I915_READ(DSPOFFSET(plane));
  6213. } else {
  6214. if (plane_config->tiled)
  6215. offset = I915_READ(DSPTILEOFF(plane));
  6216. else
  6217. offset = I915_READ(DSPLINOFF(plane));
  6218. }
  6219. plane_config->base = base;
  6220. val = I915_READ(PIPESRC(pipe));
  6221. crtc->base.primary->fb->width = ((val >> 16) & 0xfff) + 1;
  6222. crtc->base.primary->fb->height = ((val >> 0) & 0xfff) + 1;
  6223. val = I915_READ(DSPSTRIDE(pipe));
  6224. crtc->base.primary->fb->pitches[0] = val & 0xffffffc0;
  6225. aligned_height = intel_align_height(dev, crtc->base.primary->fb->height,
  6226. plane_config->tiled);
  6227. plane_config->size = PAGE_ALIGN(crtc->base.primary->fb->pitches[0] *
  6228. aligned_height);
  6229. DRM_DEBUG_KMS("pipe/plane %d/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
  6230. pipe, plane, crtc->base.primary->fb->width,
  6231. crtc->base.primary->fb->height,
  6232. crtc->base.primary->fb->bits_per_pixel, base,
  6233. crtc->base.primary->fb->pitches[0],
  6234. plane_config->size);
  6235. }
  6236. static bool ironlake_get_pipe_config(struct intel_crtc *crtc,
  6237. struct intel_crtc_config *pipe_config)
  6238. {
  6239. struct drm_device *dev = crtc->base.dev;
  6240. struct drm_i915_private *dev_priv = dev->dev_private;
  6241. uint32_t tmp;
  6242. if (!intel_display_power_enabled(dev_priv,
  6243. POWER_DOMAIN_PIPE(crtc->pipe)))
  6244. return false;
  6245. pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
  6246. pipe_config->shared_dpll = DPLL_ID_PRIVATE;
  6247. tmp = I915_READ(PIPECONF(crtc->pipe));
  6248. if (!(tmp & PIPECONF_ENABLE))
  6249. return false;
  6250. switch (tmp & PIPECONF_BPC_MASK) {
  6251. case PIPECONF_6BPC:
  6252. pipe_config->pipe_bpp = 18;
  6253. break;
  6254. case PIPECONF_8BPC:
  6255. pipe_config->pipe_bpp = 24;
  6256. break;
  6257. case PIPECONF_10BPC:
  6258. pipe_config->pipe_bpp = 30;
  6259. break;
  6260. case PIPECONF_12BPC:
  6261. pipe_config->pipe_bpp = 36;
  6262. break;
  6263. default:
  6264. break;
  6265. }
  6266. if (tmp & PIPECONF_COLOR_RANGE_SELECT)
  6267. pipe_config->limited_color_range = true;
  6268. if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) {
  6269. struct intel_shared_dpll *pll;
  6270. pipe_config->has_pch_encoder = true;
  6271. tmp = I915_READ(FDI_RX_CTL(crtc->pipe));
  6272. pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
  6273. FDI_DP_PORT_WIDTH_SHIFT) + 1;
  6274. ironlake_get_fdi_m_n_config(crtc, pipe_config);
  6275. if (HAS_PCH_IBX(dev_priv->dev)) {
  6276. pipe_config->shared_dpll =
  6277. (enum intel_dpll_id) crtc->pipe;
  6278. } else {
  6279. tmp = I915_READ(PCH_DPLL_SEL);
  6280. if (tmp & TRANS_DPLLB_SEL(crtc->pipe))
  6281. pipe_config->shared_dpll = DPLL_ID_PCH_PLL_B;
  6282. else
  6283. pipe_config->shared_dpll = DPLL_ID_PCH_PLL_A;
  6284. }
  6285. pll = &dev_priv->shared_dplls[pipe_config->shared_dpll];
  6286. WARN_ON(!pll->get_hw_state(dev_priv, pll,
  6287. &pipe_config->dpll_hw_state));
  6288. tmp = pipe_config->dpll_hw_state.dpll;
  6289. pipe_config->pixel_multiplier =
  6290. ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK)
  6291. >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1;
  6292. ironlake_pch_clock_get(crtc, pipe_config);
  6293. } else {
  6294. pipe_config->pixel_multiplier = 1;
  6295. }
  6296. intel_get_pipe_timings(crtc, pipe_config);
  6297. ironlake_get_pfit_config(crtc, pipe_config);
  6298. return true;
  6299. }
  6300. static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv)
  6301. {
  6302. struct drm_device *dev = dev_priv->dev;
  6303. struct intel_crtc *crtc;
  6304. for_each_intel_crtc(dev, crtc)
  6305. WARN(crtc->active, "CRTC for pipe %c enabled\n",
  6306. pipe_name(crtc->pipe));
  6307. WARN(I915_READ(HSW_PWR_WELL_DRIVER), "Power well on\n");
  6308. WARN(I915_READ(SPLL_CTL) & SPLL_PLL_ENABLE, "SPLL enabled\n");
  6309. WARN(I915_READ(WRPLL_CTL1) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n");
  6310. WARN(I915_READ(WRPLL_CTL2) & WRPLL_PLL_ENABLE, "WRPLL2 enabled\n");
  6311. WARN(I915_READ(PCH_PP_STATUS) & PP_ON, "Panel power on\n");
  6312. WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE,
  6313. "CPU PWM1 enabled\n");
  6314. if (IS_HASWELL(dev))
  6315. WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE,
  6316. "CPU PWM2 enabled\n");
  6317. WARN(I915_READ(BLC_PWM_PCH_CTL1) & BLM_PCH_PWM_ENABLE,
  6318. "PCH PWM1 enabled\n");
  6319. WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
  6320. "Utility pin enabled\n");
  6321. WARN(I915_READ(PCH_GTC_CTL) & PCH_GTC_ENABLE, "PCH GTC enabled\n");
  6322. /*
  6323. * In theory we can still leave IRQs enabled, as long as only the HPD
  6324. * interrupts remain enabled. We used to check for that, but since it's
  6325. * gen-specific and since we only disable LCPLL after we fully disable
  6326. * the interrupts, the check below should be enough.
  6327. */
  6328. WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n");
  6329. }
  6330. static uint32_t hsw_read_dcomp(struct drm_i915_private *dev_priv)
  6331. {
  6332. struct drm_device *dev = dev_priv->dev;
  6333. if (IS_HASWELL(dev))
  6334. return I915_READ(D_COMP_HSW);
  6335. else
  6336. return I915_READ(D_COMP_BDW);
  6337. }
  6338. static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val)
  6339. {
  6340. struct drm_device *dev = dev_priv->dev;
  6341. if (IS_HASWELL(dev)) {
  6342. mutex_lock(&dev_priv->rps.hw_lock);
  6343. if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP,
  6344. val))
  6345. DRM_ERROR("Failed to write to D_COMP\n");
  6346. mutex_unlock(&dev_priv->rps.hw_lock);
  6347. } else {
  6348. I915_WRITE(D_COMP_BDW, val);
  6349. POSTING_READ(D_COMP_BDW);
  6350. }
  6351. }
  6352. /*
  6353. * This function implements pieces of two sequences from BSpec:
  6354. * - Sequence for display software to disable LCPLL
  6355. * - Sequence for display software to allow package C8+
  6356. * The steps implemented here are just the steps that actually touch the LCPLL
  6357. * register. Callers should take care of disabling all the display engine
  6358. * functions, doing the mode unset, fixing interrupts, etc.
  6359. */
  6360. static void hsw_disable_lcpll(struct drm_i915_private *dev_priv,
  6361. bool switch_to_fclk, bool allow_power_down)
  6362. {
  6363. uint32_t val;
  6364. assert_can_disable_lcpll(dev_priv);
  6365. val = I915_READ(LCPLL_CTL);
  6366. if (switch_to_fclk) {
  6367. val |= LCPLL_CD_SOURCE_FCLK;
  6368. I915_WRITE(LCPLL_CTL, val);
  6369. if (wait_for_atomic_us(I915_READ(LCPLL_CTL) &
  6370. LCPLL_CD_SOURCE_FCLK_DONE, 1))
  6371. DRM_ERROR("Switching to FCLK failed\n");
  6372. val = I915_READ(LCPLL_CTL);
  6373. }
  6374. val |= LCPLL_PLL_DISABLE;
  6375. I915_WRITE(LCPLL_CTL, val);
  6376. POSTING_READ(LCPLL_CTL);
  6377. if (wait_for((I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK) == 0, 1))
  6378. DRM_ERROR("LCPLL still locked\n");
  6379. val = hsw_read_dcomp(dev_priv);
  6380. val |= D_COMP_COMP_DISABLE;
  6381. hsw_write_dcomp(dev_priv, val);
  6382. ndelay(100);
  6383. if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0,
  6384. 1))
  6385. DRM_ERROR("D_COMP RCOMP still in progress\n");
  6386. if (allow_power_down) {
  6387. val = I915_READ(LCPLL_CTL);
  6388. val |= LCPLL_POWER_DOWN_ALLOW;
  6389. I915_WRITE(LCPLL_CTL, val);
  6390. POSTING_READ(LCPLL_CTL);
  6391. }
  6392. }
  6393. /*
  6394. * Fully restores LCPLL, disallowing power down and switching back to LCPLL
  6395. * source.
  6396. */
  6397. static void hsw_restore_lcpll(struct drm_i915_private *dev_priv)
  6398. {
  6399. uint32_t val;
  6400. unsigned long irqflags;
  6401. val = I915_READ(LCPLL_CTL);
  6402. if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK |
  6403. LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK)
  6404. return;
  6405. /*
  6406. * Make sure we're not on PC8 state before disabling PC8, otherwise
  6407. * we'll hang the machine. To prevent PC8 state, just enable force_wake.
  6408. *
  6409. * The other problem is that hsw_restore_lcpll() is called as part of
  6410. * the runtime PM resume sequence, so we can't just call
  6411. * gen6_gt_force_wake_get() because that function calls
  6412. * intel_runtime_pm_get(), and we can't change the runtime PM refcount
  6413. * while we are on the resume sequence. So to solve this problem we have
  6414. * to call special forcewake code that doesn't touch runtime PM and
  6415. * doesn't enable the forcewake delayed work.
  6416. */
  6417. spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
  6418. if (dev_priv->uncore.forcewake_count++ == 0)
  6419. dev_priv->uncore.funcs.force_wake_get(dev_priv, FORCEWAKE_ALL);
  6420. spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
  6421. if (val & LCPLL_POWER_DOWN_ALLOW) {
  6422. val &= ~LCPLL_POWER_DOWN_ALLOW;
  6423. I915_WRITE(LCPLL_CTL, val);
  6424. POSTING_READ(LCPLL_CTL);
  6425. }
  6426. val = hsw_read_dcomp(dev_priv);
  6427. val |= D_COMP_COMP_FORCE;
  6428. val &= ~D_COMP_COMP_DISABLE;
  6429. hsw_write_dcomp(dev_priv, val);
  6430. val = I915_READ(LCPLL_CTL);
  6431. val &= ~LCPLL_PLL_DISABLE;
  6432. I915_WRITE(LCPLL_CTL, val);
  6433. if (wait_for(I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK, 5))
  6434. DRM_ERROR("LCPLL not locked yet\n");
  6435. if (val & LCPLL_CD_SOURCE_FCLK) {
  6436. val = I915_READ(LCPLL_CTL);
  6437. val &= ~LCPLL_CD_SOURCE_FCLK;
  6438. I915_WRITE(LCPLL_CTL, val);
  6439. if (wait_for_atomic_us((I915_READ(LCPLL_CTL) &
  6440. LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1))
  6441. DRM_ERROR("Switching back to LCPLL failed\n");
  6442. }
  6443. /* See the big comment above. */
  6444. spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
  6445. if (--dev_priv->uncore.forcewake_count == 0)
  6446. dev_priv->uncore.funcs.force_wake_put(dev_priv, FORCEWAKE_ALL);
  6447. spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
  6448. }
  6449. /*
  6450. * Package states C8 and deeper are really deep PC states that can only be
  6451. * reached when all the devices on the system allow it, so even if the graphics
  6452. * device allows PC8+, it doesn't mean the system will actually get to these
  6453. * states. Our driver only allows PC8+ when going into runtime PM.
  6454. *
  6455. * The requirements for PC8+ are that all the outputs are disabled, the power
  6456. * well is disabled and most interrupts are disabled, and these are also
  6457. * requirements for runtime PM. When these conditions are met, we manually do
  6458. * the other conditions: disable the interrupts, clocks and switch LCPLL refclk
  6459. * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard
  6460. * hang the machine.
  6461. *
  6462. * When we really reach PC8 or deeper states (not just when we allow it) we lose
  6463. * the state of some registers, so when we come back from PC8+ we need to
  6464. * restore this state. We don't get into PC8+ if we're not in RC6, so we don't
  6465. * need to take care of the registers kept by RC6. Notice that this happens even
  6466. * if we don't put the device in PCI D3 state (which is what currently happens
  6467. * because of the runtime PM support).
  6468. *
  6469. * For more, read "Display Sequences for Package C8" on the hardware
  6470. * documentation.
  6471. */
  6472. void hsw_enable_pc8(struct drm_i915_private *dev_priv)
  6473. {
  6474. struct drm_device *dev = dev_priv->dev;
  6475. uint32_t val;
  6476. DRM_DEBUG_KMS("Enabling package C8+\n");
  6477. if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) {
  6478. val = I915_READ(SOUTH_DSPCLK_GATE_D);
  6479. val &= ~PCH_LP_PARTITION_LEVEL_DISABLE;
  6480. I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
  6481. }
  6482. lpt_disable_clkout_dp(dev);
  6483. hsw_disable_lcpll(dev_priv, true, true);
  6484. }
  6485. void hsw_disable_pc8(struct drm_i915_private *dev_priv)
  6486. {
  6487. struct drm_device *dev = dev_priv->dev;
  6488. uint32_t val;
  6489. DRM_DEBUG_KMS("Disabling package C8+\n");
  6490. hsw_restore_lcpll(dev_priv);
  6491. lpt_init_pch_refclk(dev);
  6492. if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) {
  6493. val = I915_READ(SOUTH_DSPCLK_GATE_D);
  6494. val |= PCH_LP_PARTITION_LEVEL_DISABLE;
  6495. I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
  6496. }
  6497. intel_prepare_ddi(dev);
  6498. }
  6499. static void snb_modeset_global_resources(struct drm_device *dev)
  6500. {
  6501. modeset_update_crtc_power_domains(dev);
  6502. }
  6503. static void haswell_modeset_global_resources(struct drm_device *dev)
  6504. {
  6505. modeset_update_crtc_power_domains(dev);
  6506. }
  6507. static int haswell_crtc_mode_set(struct drm_crtc *crtc,
  6508. int x, int y,
  6509. struct drm_framebuffer *fb)
  6510. {
  6511. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6512. if (!intel_ddi_pll_select(intel_crtc))
  6513. return -EINVAL;
  6514. intel_crtc->lowfreq_avail = false;
  6515. return 0;
  6516. }
  6517. static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv,
  6518. enum port port,
  6519. struct intel_crtc_config *pipe_config)
  6520. {
  6521. pipe_config->ddi_pll_sel = I915_READ(PORT_CLK_SEL(port));
  6522. switch (pipe_config->ddi_pll_sel) {
  6523. case PORT_CLK_SEL_WRPLL1:
  6524. pipe_config->shared_dpll = DPLL_ID_WRPLL1;
  6525. break;
  6526. case PORT_CLK_SEL_WRPLL2:
  6527. pipe_config->shared_dpll = DPLL_ID_WRPLL2;
  6528. break;
  6529. }
  6530. }
  6531. static void haswell_get_ddi_port_state(struct intel_crtc *crtc,
  6532. struct intel_crtc_config *pipe_config)
  6533. {
  6534. struct drm_device *dev = crtc->base.dev;
  6535. struct drm_i915_private *dev_priv = dev->dev_private;
  6536. struct intel_shared_dpll *pll;
  6537. enum port port;
  6538. uint32_t tmp;
  6539. tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder));
  6540. port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT;
  6541. haswell_get_ddi_pll(dev_priv, port, pipe_config);
  6542. if (pipe_config->shared_dpll >= 0) {
  6543. pll = &dev_priv->shared_dplls[pipe_config->shared_dpll];
  6544. WARN_ON(!pll->get_hw_state(dev_priv, pll,
  6545. &pipe_config->dpll_hw_state));
  6546. }
  6547. /*
  6548. * Haswell has only FDI/PCH transcoder A. It is which is connected to
  6549. * DDI E. So just check whether this pipe is wired to DDI E and whether
  6550. * the PCH transcoder is on.
  6551. */
  6552. if ((port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) {
  6553. pipe_config->has_pch_encoder = true;
  6554. tmp = I915_READ(FDI_RX_CTL(PIPE_A));
  6555. pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
  6556. FDI_DP_PORT_WIDTH_SHIFT) + 1;
  6557. ironlake_get_fdi_m_n_config(crtc, pipe_config);
  6558. }
  6559. }
  6560. static bool haswell_get_pipe_config(struct intel_crtc *crtc,
  6561. struct intel_crtc_config *pipe_config)
  6562. {
  6563. struct drm_device *dev = crtc->base.dev;
  6564. struct drm_i915_private *dev_priv = dev->dev_private;
  6565. enum intel_display_power_domain pfit_domain;
  6566. uint32_t tmp;
  6567. if (!intel_display_power_enabled(dev_priv,
  6568. POWER_DOMAIN_PIPE(crtc->pipe)))
  6569. return false;
  6570. pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
  6571. pipe_config->shared_dpll = DPLL_ID_PRIVATE;
  6572. tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
  6573. if (tmp & TRANS_DDI_FUNC_ENABLE) {
  6574. enum pipe trans_edp_pipe;
  6575. switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
  6576. default:
  6577. WARN(1, "unknown pipe linked to edp transcoder\n");
  6578. case TRANS_DDI_EDP_INPUT_A_ONOFF:
  6579. case TRANS_DDI_EDP_INPUT_A_ON:
  6580. trans_edp_pipe = PIPE_A;
  6581. break;
  6582. case TRANS_DDI_EDP_INPUT_B_ONOFF:
  6583. trans_edp_pipe = PIPE_B;
  6584. break;
  6585. case TRANS_DDI_EDP_INPUT_C_ONOFF:
  6586. trans_edp_pipe = PIPE_C;
  6587. break;
  6588. }
  6589. if (trans_edp_pipe == crtc->pipe)
  6590. pipe_config->cpu_transcoder = TRANSCODER_EDP;
  6591. }
  6592. if (!intel_display_power_enabled(dev_priv,
  6593. POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder)))
  6594. return false;
  6595. tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder));
  6596. if (!(tmp & PIPECONF_ENABLE))
  6597. return false;
  6598. haswell_get_ddi_port_state(crtc, pipe_config);
  6599. intel_get_pipe_timings(crtc, pipe_config);
  6600. pfit_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe);
  6601. if (intel_display_power_enabled(dev_priv, pfit_domain))
  6602. ironlake_get_pfit_config(crtc, pipe_config);
  6603. if (IS_HASWELL(dev))
  6604. pipe_config->ips_enabled = hsw_crtc_supports_ips(crtc) &&
  6605. (I915_READ(IPS_CTL) & IPS_ENABLE);
  6606. if (pipe_config->cpu_transcoder != TRANSCODER_EDP) {
  6607. pipe_config->pixel_multiplier =
  6608. I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1;
  6609. } else {
  6610. pipe_config->pixel_multiplier = 1;
  6611. }
  6612. return true;
  6613. }
  6614. static struct {
  6615. int clock;
  6616. u32 config;
  6617. } hdmi_audio_clock[] = {
  6618. { DIV_ROUND_UP(25200 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_25175 },
  6619. { 25200, AUD_CONFIG_PIXEL_CLOCK_HDMI_25200 }, /* default per bspec */
  6620. { 27000, AUD_CONFIG_PIXEL_CLOCK_HDMI_27000 },
  6621. { 27000 * 1001 / 1000, AUD_CONFIG_PIXEL_CLOCK_HDMI_27027 },
  6622. { 54000, AUD_CONFIG_PIXEL_CLOCK_HDMI_54000 },
  6623. { 54000 * 1001 / 1000, AUD_CONFIG_PIXEL_CLOCK_HDMI_54054 },
  6624. { DIV_ROUND_UP(74250 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_74176 },
  6625. { 74250, AUD_CONFIG_PIXEL_CLOCK_HDMI_74250 },
  6626. { DIV_ROUND_UP(148500 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_148352 },
  6627. { 148500, AUD_CONFIG_PIXEL_CLOCK_HDMI_148500 },
  6628. };
  6629. /* get AUD_CONFIG_PIXEL_CLOCK_HDMI_* value for mode */
  6630. static u32 audio_config_hdmi_pixel_clock(struct drm_display_mode *mode)
  6631. {
  6632. int i;
  6633. for (i = 0; i < ARRAY_SIZE(hdmi_audio_clock); i++) {
  6634. if (mode->clock == hdmi_audio_clock[i].clock)
  6635. break;
  6636. }
  6637. if (i == ARRAY_SIZE(hdmi_audio_clock)) {
  6638. DRM_DEBUG_KMS("HDMI audio pixel clock setting for %d not found, falling back to defaults\n", mode->clock);
  6639. i = 1;
  6640. }
  6641. DRM_DEBUG_KMS("Configuring HDMI audio for pixel clock %d (0x%08x)\n",
  6642. hdmi_audio_clock[i].clock,
  6643. hdmi_audio_clock[i].config);
  6644. return hdmi_audio_clock[i].config;
  6645. }
  6646. static bool intel_eld_uptodate(struct drm_connector *connector,
  6647. int reg_eldv, uint32_t bits_eldv,
  6648. int reg_elda, uint32_t bits_elda,
  6649. int reg_edid)
  6650. {
  6651. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  6652. uint8_t *eld = connector->eld;
  6653. uint32_t i;
  6654. i = I915_READ(reg_eldv);
  6655. i &= bits_eldv;
  6656. if (!eld[0])
  6657. return !i;
  6658. if (!i)
  6659. return false;
  6660. i = I915_READ(reg_elda);
  6661. i &= ~bits_elda;
  6662. I915_WRITE(reg_elda, i);
  6663. for (i = 0; i < eld[2]; i++)
  6664. if (I915_READ(reg_edid) != *((uint32_t *)eld + i))
  6665. return false;
  6666. return true;
  6667. }
  6668. static void g4x_write_eld(struct drm_connector *connector,
  6669. struct drm_crtc *crtc,
  6670. struct drm_display_mode *mode)
  6671. {
  6672. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  6673. uint8_t *eld = connector->eld;
  6674. uint32_t eldv;
  6675. uint32_t len;
  6676. uint32_t i;
  6677. i = I915_READ(G4X_AUD_VID_DID);
  6678. if (i == INTEL_AUDIO_DEVBLC || i == INTEL_AUDIO_DEVCL)
  6679. eldv = G4X_ELDV_DEVCL_DEVBLC;
  6680. else
  6681. eldv = G4X_ELDV_DEVCTG;
  6682. if (intel_eld_uptodate(connector,
  6683. G4X_AUD_CNTL_ST, eldv,
  6684. G4X_AUD_CNTL_ST, G4X_ELD_ADDR,
  6685. G4X_HDMIW_HDMIEDID))
  6686. return;
  6687. i = I915_READ(G4X_AUD_CNTL_ST);
  6688. i &= ~(eldv | G4X_ELD_ADDR);
  6689. len = (i >> 9) & 0x1f; /* ELD buffer size */
  6690. I915_WRITE(G4X_AUD_CNTL_ST, i);
  6691. if (!eld[0])
  6692. return;
  6693. len = min_t(uint8_t, eld[2], len);
  6694. DRM_DEBUG_DRIVER("ELD size %d\n", len);
  6695. for (i = 0; i < len; i++)
  6696. I915_WRITE(G4X_HDMIW_HDMIEDID, *((uint32_t *)eld + i));
  6697. i = I915_READ(G4X_AUD_CNTL_ST);
  6698. i |= eldv;
  6699. I915_WRITE(G4X_AUD_CNTL_ST, i);
  6700. }
  6701. static void haswell_write_eld(struct drm_connector *connector,
  6702. struct drm_crtc *crtc,
  6703. struct drm_display_mode *mode)
  6704. {
  6705. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  6706. uint8_t *eld = connector->eld;
  6707. uint32_t eldv;
  6708. uint32_t i;
  6709. int len;
  6710. int pipe = to_intel_crtc(crtc)->pipe;
  6711. int tmp;
  6712. int hdmiw_hdmiedid = HSW_AUD_EDID_DATA(pipe);
  6713. int aud_cntl_st = HSW_AUD_DIP_ELD_CTRL(pipe);
  6714. int aud_config = HSW_AUD_CFG(pipe);
  6715. int aud_cntrl_st2 = HSW_AUD_PIN_ELD_CP_VLD;
  6716. /* Audio output enable */
  6717. DRM_DEBUG_DRIVER("HDMI audio: enable codec\n");
  6718. tmp = I915_READ(aud_cntrl_st2);
  6719. tmp |= (AUDIO_OUTPUT_ENABLE_A << (pipe * 4));
  6720. I915_WRITE(aud_cntrl_st2, tmp);
  6721. POSTING_READ(aud_cntrl_st2);
  6722. assert_pipe_disabled(dev_priv, to_intel_crtc(crtc)->pipe);
  6723. /* Set ELD valid state */
  6724. tmp = I915_READ(aud_cntrl_st2);
  6725. DRM_DEBUG_DRIVER("HDMI audio: pin eld vld status=0x%08x\n", tmp);
  6726. tmp |= (AUDIO_ELD_VALID_A << (pipe * 4));
  6727. I915_WRITE(aud_cntrl_st2, tmp);
  6728. tmp = I915_READ(aud_cntrl_st2);
  6729. DRM_DEBUG_DRIVER("HDMI audio: eld vld status=0x%08x\n", tmp);
  6730. /* Enable HDMI mode */
  6731. tmp = I915_READ(aud_config);
  6732. DRM_DEBUG_DRIVER("HDMI audio: audio conf: 0x%08x\n", tmp);
  6733. /* clear N_programing_enable and N_value_index */
  6734. tmp &= ~(AUD_CONFIG_N_VALUE_INDEX | AUD_CONFIG_N_PROG_ENABLE);
  6735. I915_WRITE(aud_config, tmp);
  6736. DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe));
  6737. eldv = AUDIO_ELD_VALID_A << (pipe * 4);
  6738. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) {
  6739. DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
  6740. eld[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
  6741. I915_WRITE(aud_config, AUD_CONFIG_N_VALUE_INDEX); /* 0x1 = DP */
  6742. } else {
  6743. I915_WRITE(aud_config, audio_config_hdmi_pixel_clock(mode));
  6744. }
  6745. if (intel_eld_uptodate(connector,
  6746. aud_cntrl_st2, eldv,
  6747. aud_cntl_st, IBX_ELD_ADDRESS,
  6748. hdmiw_hdmiedid))
  6749. return;
  6750. i = I915_READ(aud_cntrl_st2);
  6751. i &= ~eldv;
  6752. I915_WRITE(aud_cntrl_st2, i);
  6753. if (!eld[0])
  6754. return;
  6755. i = I915_READ(aud_cntl_st);
  6756. i &= ~IBX_ELD_ADDRESS;
  6757. I915_WRITE(aud_cntl_st, i);
  6758. i = (i >> 29) & DIP_PORT_SEL_MASK; /* DIP_Port_Select, 0x1 = PortB */
  6759. DRM_DEBUG_DRIVER("port num:%d\n", i);
  6760. len = min_t(uint8_t, eld[2], 21); /* 84 bytes of hw ELD buffer */
  6761. DRM_DEBUG_DRIVER("ELD size %d\n", len);
  6762. for (i = 0; i < len; i++)
  6763. I915_WRITE(hdmiw_hdmiedid, *((uint32_t *)eld + i));
  6764. i = I915_READ(aud_cntrl_st2);
  6765. i |= eldv;
  6766. I915_WRITE(aud_cntrl_st2, i);
  6767. }
  6768. static void ironlake_write_eld(struct drm_connector *connector,
  6769. struct drm_crtc *crtc,
  6770. struct drm_display_mode *mode)
  6771. {
  6772. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  6773. uint8_t *eld = connector->eld;
  6774. uint32_t eldv;
  6775. uint32_t i;
  6776. int len;
  6777. int hdmiw_hdmiedid;
  6778. int aud_config;
  6779. int aud_cntl_st;
  6780. int aud_cntrl_st2;
  6781. int pipe = to_intel_crtc(crtc)->pipe;
  6782. if (HAS_PCH_IBX(connector->dev)) {
  6783. hdmiw_hdmiedid = IBX_HDMIW_HDMIEDID(pipe);
  6784. aud_config = IBX_AUD_CFG(pipe);
  6785. aud_cntl_st = IBX_AUD_CNTL_ST(pipe);
  6786. aud_cntrl_st2 = IBX_AUD_CNTL_ST2;
  6787. } else if (IS_VALLEYVIEW(connector->dev)) {
  6788. hdmiw_hdmiedid = VLV_HDMIW_HDMIEDID(pipe);
  6789. aud_config = VLV_AUD_CFG(pipe);
  6790. aud_cntl_st = VLV_AUD_CNTL_ST(pipe);
  6791. aud_cntrl_st2 = VLV_AUD_CNTL_ST2;
  6792. } else {
  6793. hdmiw_hdmiedid = CPT_HDMIW_HDMIEDID(pipe);
  6794. aud_config = CPT_AUD_CFG(pipe);
  6795. aud_cntl_st = CPT_AUD_CNTL_ST(pipe);
  6796. aud_cntrl_st2 = CPT_AUD_CNTRL_ST2;
  6797. }
  6798. DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe));
  6799. if (IS_VALLEYVIEW(connector->dev)) {
  6800. struct intel_encoder *intel_encoder;
  6801. struct intel_digital_port *intel_dig_port;
  6802. intel_encoder = intel_attached_encoder(connector);
  6803. intel_dig_port = enc_to_dig_port(&intel_encoder->base);
  6804. i = intel_dig_port->port;
  6805. } else {
  6806. i = I915_READ(aud_cntl_st);
  6807. i = (i >> 29) & DIP_PORT_SEL_MASK;
  6808. /* DIP_Port_Select, 0x1 = PortB */
  6809. }
  6810. if (!i) {
  6811. DRM_DEBUG_DRIVER("Audio directed to unknown port\n");
  6812. /* operate blindly on all ports */
  6813. eldv = IBX_ELD_VALIDB;
  6814. eldv |= IBX_ELD_VALIDB << 4;
  6815. eldv |= IBX_ELD_VALIDB << 8;
  6816. } else {
  6817. DRM_DEBUG_DRIVER("ELD on port %c\n", port_name(i));
  6818. eldv = IBX_ELD_VALIDB << ((i - 1) * 4);
  6819. }
  6820. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) {
  6821. DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
  6822. eld[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
  6823. I915_WRITE(aud_config, AUD_CONFIG_N_VALUE_INDEX); /* 0x1 = DP */
  6824. } else {
  6825. I915_WRITE(aud_config, audio_config_hdmi_pixel_clock(mode));
  6826. }
  6827. if (intel_eld_uptodate(connector,
  6828. aud_cntrl_st2, eldv,
  6829. aud_cntl_st, IBX_ELD_ADDRESS,
  6830. hdmiw_hdmiedid))
  6831. return;
  6832. i = I915_READ(aud_cntrl_st2);
  6833. i &= ~eldv;
  6834. I915_WRITE(aud_cntrl_st2, i);
  6835. if (!eld[0])
  6836. return;
  6837. i = I915_READ(aud_cntl_st);
  6838. i &= ~IBX_ELD_ADDRESS;
  6839. I915_WRITE(aud_cntl_st, i);
  6840. len = min_t(uint8_t, eld[2], 21); /* 84 bytes of hw ELD buffer */
  6841. DRM_DEBUG_DRIVER("ELD size %d\n", len);
  6842. for (i = 0; i < len; i++)
  6843. I915_WRITE(hdmiw_hdmiedid, *((uint32_t *)eld + i));
  6844. i = I915_READ(aud_cntrl_st2);
  6845. i |= eldv;
  6846. I915_WRITE(aud_cntrl_st2, i);
  6847. }
  6848. void intel_write_eld(struct drm_encoder *encoder,
  6849. struct drm_display_mode *mode)
  6850. {
  6851. struct drm_crtc *crtc = encoder->crtc;
  6852. struct drm_connector *connector;
  6853. struct drm_device *dev = encoder->dev;
  6854. struct drm_i915_private *dev_priv = dev->dev_private;
  6855. connector = drm_select_eld(encoder, mode);
  6856. if (!connector)
  6857. return;
  6858. DRM_DEBUG_DRIVER("ELD on [CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
  6859. connector->base.id,
  6860. connector->name,
  6861. connector->encoder->base.id,
  6862. connector->encoder->name);
  6863. connector->eld[6] = drm_av_sync_delay(connector, mode) / 2;
  6864. if (dev_priv->display.write_eld)
  6865. dev_priv->display.write_eld(connector, crtc, mode);
  6866. }
  6867. static void i845_update_cursor(struct drm_crtc *crtc, u32 base)
  6868. {
  6869. struct drm_device *dev = crtc->dev;
  6870. struct drm_i915_private *dev_priv = dev->dev_private;
  6871. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6872. uint32_t cntl = 0, size = 0;
  6873. if (base) {
  6874. unsigned int width = intel_crtc->cursor_width;
  6875. unsigned int height = intel_crtc->cursor_height;
  6876. unsigned int stride = roundup_pow_of_two(width) * 4;
  6877. switch (stride) {
  6878. default:
  6879. WARN_ONCE(1, "Invalid cursor width/stride, width=%u, stride=%u\n",
  6880. width, stride);
  6881. stride = 256;
  6882. /* fallthrough */
  6883. case 256:
  6884. case 512:
  6885. case 1024:
  6886. case 2048:
  6887. break;
  6888. }
  6889. cntl |= CURSOR_ENABLE |
  6890. CURSOR_GAMMA_ENABLE |
  6891. CURSOR_FORMAT_ARGB |
  6892. CURSOR_STRIDE(stride);
  6893. size = (height << 12) | width;
  6894. }
  6895. if (intel_crtc->cursor_cntl != 0 &&
  6896. (intel_crtc->cursor_base != base ||
  6897. intel_crtc->cursor_size != size ||
  6898. intel_crtc->cursor_cntl != cntl)) {
  6899. /* On these chipsets we can only modify the base/size/stride
  6900. * whilst the cursor is disabled.
  6901. */
  6902. I915_WRITE(_CURACNTR, 0);
  6903. POSTING_READ(_CURACNTR);
  6904. intel_crtc->cursor_cntl = 0;
  6905. }
  6906. if (intel_crtc->cursor_base != base)
  6907. I915_WRITE(_CURABASE, base);
  6908. if (intel_crtc->cursor_size != size) {
  6909. I915_WRITE(CURSIZE, size);
  6910. intel_crtc->cursor_size = size;
  6911. }
  6912. if (intel_crtc->cursor_cntl != cntl) {
  6913. I915_WRITE(_CURACNTR, cntl);
  6914. POSTING_READ(_CURACNTR);
  6915. intel_crtc->cursor_cntl = cntl;
  6916. }
  6917. }
  6918. static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base)
  6919. {
  6920. struct drm_device *dev = crtc->dev;
  6921. struct drm_i915_private *dev_priv = dev->dev_private;
  6922. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6923. int pipe = intel_crtc->pipe;
  6924. uint32_t cntl;
  6925. cntl = 0;
  6926. if (base) {
  6927. cntl = MCURSOR_GAMMA_ENABLE;
  6928. switch (intel_crtc->cursor_width) {
  6929. case 64:
  6930. cntl |= CURSOR_MODE_64_ARGB_AX;
  6931. break;
  6932. case 128:
  6933. cntl |= CURSOR_MODE_128_ARGB_AX;
  6934. break;
  6935. case 256:
  6936. cntl |= CURSOR_MODE_256_ARGB_AX;
  6937. break;
  6938. default:
  6939. WARN_ON(1);
  6940. return;
  6941. }
  6942. cntl |= pipe << 28; /* Connect to correct pipe */
  6943. }
  6944. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  6945. cntl |= CURSOR_PIPE_CSC_ENABLE;
  6946. if (intel_crtc->cursor_cntl != cntl) {
  6947. I915_WRITE(CURCNTR(pipe), cntl);
  6948. POSTING_READ(CURCNTR(pipe));
  6949. intel_crtc->cursor_cntl = cntl;
  6950. }
  6951. /* and commit changes on next vblank */
  6952. I915_WRITE(CURBASE(pipe), base);
  6953. POSTING_READ(CURBASE(pipe));
  6954. }
  6955. /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */
  6956. static void intel_crtc_update_cursor(struct drm_crtc *crtc,
  6957. bool on)
  6958. {
  6959. struct drm_device *dev = crtc->dev;
  6960. struct drm_i915_private *dev_priv = dev->dev_private;
  6961. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6962. int pipe = intel_crtc->pipe;
  6963. int x = crtc->cursor_x;
  6964. int y = crtc->cursor_y;
  6965. u32 base = 0, pos = 0;
  6966. if (on)
  6967. base = intel_crtc->cursor_addr;
  6968. if (x >= intel_crtc->config.pipe_src_w)
  6969. base = 0;
  6970. if (y >= intel_crtc->config.pipe_src_h)
  6971. base = 0;
  6972. if (x < 0) {
  6973. if (x + intel_crtc->cursor_width <= 0)
  6974. base = 0;
  6975. pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
  6976. x = -x;
  6977. }
  6978. pos |= x << CURSOR_X_SHIFT;
  6979. if (y < 0) {
  6980. if (y + intel_crtc->cursor_height <= 0)
  6981. base = 0;
  6982. pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
  6983. y = -y;
  6984. }
  6985. pos |= y << CURSOR_Y_SHIFT;
  6986. if (base == 0 && intel_crtc->cursor_base == 0)
  6987. return;
  6988. I915_WRITE(CURPOS(pipe), pos);
  6989. if (IS_845G(dev) || IS_I865G(dev))
  6990. i845_update_cursor(crtc, base);
  6991. else
  6992. i9xx_update_cursor(crtc, base);
  6993. intel_crtc->cursor_base = base;
  6994. }
  6995. static bool cursor_size_ok(struct drm_device *dev,
  6996. uint32_t width, uint32_t height)
  6997. {
  6998. if (width == 0 || height == 0)
  6999. return false;
  7000. /*
  7001. * 845g/865g are special in that they are only limited by
  7002. * the width of their cursors, the height is arbitrary up to
  7003. * the precision of the register. Everything else requires
  7004. * square cursors, limited to a few power-of-two sizes.
  7005. */
  7006. if (IS_845G(dev) || IS_I865G(dev)) {
  7007. if ((width & 63) != 0)
  7008. return false;
  7009. if (width > (IS_845G(dev) ? 64 : 512))
  7010. return false;
  7011. if (height > 1023)
  7012. return false;
  7013. } else {
  7014. switch (width | height) {
  7015. case 256:
  7016. case 128:
  7017. if (IS_GEN2(dev))
  7018. return false;
  7019. case 64:
  7020. break;
  7021. default:
  7022. return false;
  7023. }
  7024. }
  7025. return true;
  7026. }
  7027. /*
  7028. * intel_crtc_cursor_set_obj - Set cursor to specified GEM object
  7029. *
  7030. * Note that the object's reference will be consumed if the update fails. If
  7031. * the update succeeds, the reference of the old object (if any) will be
  7032. * consumed.
  7033. */
  7034. static int intel_crtc_cursor_set_obj(struct drm_crtc *crtc,
  7035. struct drm_i915_gem_object *obj,
  7036. uint32_t width, uint32_t height)
  7037. {
  7038. struct drm_device *dev = crtc->dev;
  7039. struct drm_i915_private *dev_priv = dev->dev_private;
  7040. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7041. enum pipe pipe = intel_crtc->pipe;
  7042. unsigned old_width, stride;
  7043. uint32_t addr;
  7044. int ret;
  7045. /* if we want to turn off the cursor ignore width and height */
  7046. if (!obj) {
  7047. DRM_DEBUG_KMS("cursor off\n");
  7048. addr = 0;
  7049. mutex_lock(&dev->struct_mutex);
  7050. goto finish;
  7051. }
  7052. /* Check for which cursor types we support */
  7053. if (!cursor_size_ok(dev, width, height)) {
  7054. DRM_DEBUG("Cursor dimension not supported\n");
  7055. return -EINVAL;
  7056. }
  7057. stride = roundup_pow_of_two(width) * 4;
  7058. if (obj->base.size < stride * height) {
  7059. DRM_DEBUG_KMS("buffer is too small\n");
  7060. ret = -ENOMEM;
  7061. goto fail;
  7062. }
  7063. /* we only need to pin inside GTT if cursor is non-phy */
  7064. mutex_lock(&dev->struct_mutex);
  7065. if (!INTEL_INFO(dev)->cursor_needs_physical) {
  7066. unsigned alignment;
  7067. if (obj->tiling_mode) {
  7068. DRM_DEBUG_KMS("cursor cannot be tiled\n");
  7069. ret = -EINVAL;
  7070. goto fail_locked;
  7071. }
  7072. /*
  7073. * Global gtt pte registers are special registers which actually
  7074. * forward writes to a chunk of system memory. Which means that
  7075. * there is no risk that the register values disappear as soon
  7076. * as we call intel_runtime_pm_put(), so it is correct to wrap
  7077. * only the pin/unpin/fence and not more.
  7078. */
  7079. intel_runtime_pm_get(dev_priv);
  7080. /* Note that the w/a also requires 2 PTE of padding following
  7081. * the bo. We currently fill all unused PTE with the shadow
  7082. * page and so we should always have valid PTE following the
  7083. * cursor preventing the VT-d warning.
  7084. */
  7085. alignment = 0;
  7086. if (need_vtd_wa(dev))
  7087. alignment = 64*1024;
  7088. ret = i915_gem_object_pin_to_display_plane(obj, alignment, NULL);
  7089. if (ret) {
  7090. DRM_DEBUG_KMS("failed to move cursor bo into the GTT\n");
  7091. intel_runtime_pm_put(dev_priv);
  7092. goto fail_locked;
  7093. }
  7094. ret = i915_gem_object_put_fence(obj);
  7095. if (ret) {
  7096. DRM_DEBUG_KMS("failed to release fence for cursor");
  7097. intel_runtime_pm_put(dev_priv);
  7098. goto fail_unpin;
  7099. }
  7100. addr = i915_gem_obj_ggtt_offset(obj);
  7101. intel_runtime_pm_put(dev_priv);
  7102. } else {
  7103. int align = IS_I830(dev) ? 16 * 1024 : 256;
  7104. ret = i915_gem_object_attach_phys(obj, align);
  7105. if (ret) {
  7106. DRM_DEBUG_KMS("failed to attach phys object\n");
  7107. goto fail_locked;
  7108. }
  7109. addr = obj->phys_handle->busaddr;
  7110. }
  7111. finish:
  7112. if (intel_crtc->cursor_bo) {
  7113. if (!INTEL_INFO(dev)->cursor_needs_physical)
  7114. i915_gem_object_unpin_from_display_plane(intel_crtc->cursor_bo);
  7115. }
  7116. i915_gem_track_fb(intel_crtc->cursor_bo, obj,
  7117. INTEL_FRONTBUFFER_CURSOR(pipe));
  7118. mutex_unlock(&dev->struct_mutex);
  7119. old_width = intel_crtc->cursor_width;
  7120. intel_crtc->cursor_addr = addr;
  7121. intel_crtc->cursor_bo = obj;
  7122. intel_crtc->cursor_width = width;
  7123. intel_crtc->cursor_height = height;
  7124. if (intel_crtc->active) {
  7125. if (old_width != width)
  7126. intel_update_watermarks(crtc);
  7127. intel_crtc_update_cursor(crtc, intel_crtc->cursor_bo != NULL);
  7128. }
  7129. intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_CURSOR(pipe));
  7130. return 0;
  7131. fail_unpin:
  7132. i915_gem_object_unpin_from_display_plane(obj);
  7133. fail_locked:
  7134. mutex_unlock(&dev->struct_mutex);
  7135. fail:
  7136. drm_gem_object_unreference_unlocked(&obj->base);
  7137. return ret;
  7138. }
  7139. static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
  7140. u16 *blue, uint32_t start, uint32_t size)
  7141. {
  7142. int end = (start + size > 256) ? 256 : start + size, i;
  7143. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7144. for (i = start; i < end; i++) {
  7145. intel_crtc->lut_r[i] = red[i] >> 8;
  7146. intel_crtc->lut_g[i] = green[i] >> 8;
  7147. intel_crtc->lut_b[i] = blue[i] >> 8;
  7148. }
  7149. intel_crtc_load_lut(crtc);
  7150. }
  7151. /* VESA 640x480x72Hz mode to set on the pipe */
  7152. static struct drm_display_mode load_detect_mode = {
  7153. DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
  7154. 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  7155. };
  7156. struct drm_framebuffer *
  7157. __intel_framebuffer_create(struct drm_device *dev,
  7158. struct drm_mode_fb_cmd2 *mode_cmd,
  7159. struct drm_i915_gem_object *obj)
  7160. {
  7161. struct intel_framebuffer *intel_fb;
  7162. int ret;
  7163. intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
  7164. if (!intel_fb) {
  7165. drm_gem_object_unreference_unlocked(&obj->base);
  7166. return ERR_PTR(-ENOMEM);
  7167. }
  7168. ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj);
  7169. if (ret)
  7170. goto err;
  7171. return &intel_fb->base;
  7172. err:
  7173. drm_gem_object_unreference_unlocked(&obj->base);
  7174. kfree(intel_fb);
  7175. return ERR_PTR(ret);
  7176. }
  7177. static struct drm_framebuffer *
  7178. intel_framebuffer_create(struct drm_device *dev,
  7179. struct drm_mode_fb_cmd2 *mode_cmd,
  7180. struct drm_i915_gem_object *obj)
  7181. {
  7182. struct drm_framebuffer *fb;
  7183. int ret;
  7184. ret = i915_mutex_lock_interruptible(dev);
  7185. if (ret)
  7186. return ERR_PTR(ret);
  7187. fb = __intel_framebuffer_create(dev, mode_cmd, obj);
  7188. mutex_unlock(&dev->struct_mutex);
  7189. return fb;
  7190. }
  7191. static u32
  7192. intel_framebuffer_pitch_for_width(int width, int bpp)
  7193. {
  7194. u32 pitch = DIV_ROUND_UP(width * bpp, 8);
  7195. return ALIGN(pitch, 64);
  7196. }
  7197. static u32
  7198. intel_framebuffer_size_for_mode(struct drm_display_mode *mode, int bpp)
  7199. {
  7200. u32 pitch = intel_framebuffer_pitch_for_width(mode->hdisplay, bpp);
  7201. return PAGE_ALIGN(pitch * mode->vdisplay);
  7202. }
  7203. static struct drm_framebuffer *
  7204. intel_framebuffer_create_for_mode(struct drm_device *dev,
  7205. struct drm_display_mode *mode,
  7206. int depth, int bpp)
  7207. {
  7208. struct drm_i915_gem_object *obj;
  7209. struct drm_mode_fb_cmd2 mode_cmd = { 0 };
  7210. obj = i915_gem_alloc_object(dev,
  7211. intel_framebuffer_size_for_mode(mode, bpp));
  7212. if (obj == NULL)
  7213. return ERR_PTR(-ENOMEM);
  7214. mode_cmd.width = mode->hdisplay;
  7215. mode_cmd.height = mode->vdisplay;
  7216. mode_cmd.pitches[0] = intel_framebuffer_pitch_for_width(mode_cmd.width,
  7217. bpp);
  7218. mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth);
  7219. return intel_framebuffer_create(dev, &mode_cmd, obj);
  7220. }
  7221. static struct drm_framebuffer *
  7222. mode_fits_in_fbdev(struct drm_device *dev,
  7223. struct drm_display_mode *mode)
  7224. {
  7225. #ifdef CONFIG_DRM_I915_FBDEV
  7226. struct drm_i915_private *dev_priv = dev->dev_private;
  7227. struct drm_i915_gem_object *obj;
  7228. struct drm_framebuffer *fb;
  7229. if (!dev_priv->fbdev)
  7230. return NULL;
  7231. if (!dev_priv->fbdev->fb)
  7232. return NULL;
  7233. obj = dev_priv->fbdev->fb->obj;
  7234. BUG_ON(!obj);
  7235. fb = &dev_priv->fbdev->fb->base;
  7236. if (fb->pitches[0] < intel_framebuffer_pitch_for_width(mode->hdisplay,
  7237. fb->bits_per_pixel))
  7238. return NULL;
  7239. if (obj->base.size < mode->vdisplay * fb->pitches[0])
  7240. return NULL;
  7241. return fb;
  7242. #else
  7243. return NULL;
  7244. #endif
  7245. }
  7246. bool intel_get_load_detect_pipe(struct drm_connector *connector,
  7247. struct drm_display_mode *mode,
  7248. struct intel_load_detect_pipe *old,
  7249. struct drm_modeset_acquire_ctx *ctx)
  7250. {
  7251. struct intel_crtc *intel_crtc;
  7252. struct intel_encoder *intel_encoder =
  7253. intel_attached_encoder(connector);
  7254. struct drm_crtc *possible_crtc;
  7255. struct drm_encoder *encoder = &intel_encoder->base;
  7256. struct drm_crtc *crtc = NULL;
  7257. struct drm_device *dev = encoder->dev;
  7258. struct drm_framebuffer *fb;
  7259. struct drm_mode_config *config = &dev->mode_config;
  7260. int ret, i = -1;
  7261. DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
  7262. connector->base.id, connector->name,
  7263. encoder->base.id, encoder->name);
  7264. retry:
  7265. ret = drm_modeset_lock(&config->connection_mutex, ctx);
  7266. if (ret)
  7267. goto fail_unlock;
  7268. /*
  7269. * Algorithm gets a little messy:
  7270. *
  7271. * - if the connector already has an assigned crtc, use it (but make
  7272. * sure it's on first)
  7273. *
  7274. * - try to find the first unused crtc that can drive this connector,
  7275. * and use that if we find one
  7276. */
  7277. /* See if we already have a CRTC for this connector */
  7278. if (encoder->crtc) {
  7279. crtc = encoder->crtc;
  7280. ret = drm_modeset_lock(&crtc->mutex, ctx);
  7281. if (ret)
  7282. goto fail_unlock;
  7283. old->dpms_mode = connector->dpms;
  7284. old->load_detect_temp = false;
  7285. /* Make sure the crtc and connector are running */
  7286. if (connector->dpms != DRM_MODE_DPMS_ON)
  7287. connector->funcs->dpms(connector, DRM_MODE_DPMS_ON);
  7288. return true;
  7289. }
  7290. /* Find an unused one (if possible) */
  7291. for_each_crtc(dev, possible_crtc) {
  7292. i++;
  7293. if (!(encoder->possible_crtcs & (1 << i)))
  7294. continue;
  7295. if (possible_crtc->enabled)
  7296. continue;
  7297. /* This can occur when applying the pipe A quirk on resume. */
  7298. if (to_intel_crtc(possible_crtc)->new_enabled)
  7299. continue;
  7300. crtc = possible_crtc;
  7301. break;
  7302. }
  7303. /*
  7304. * If we didn't find an unused CRTC, don't use any.
  7305. */
  7306. if (!crtc) {
  7307. DRM_DEBUG_KMS("no pipe available for load-detect\n");
  7308. goto fail_unlock;
  7309. }
  7310. ret = drm_modeset_lock(&crtc->mutex, ctx);
  7311. if (ret)
  7312. goto fail_unlock;
  7313. intel_encoder->new_crtc = to_intel_crtc(crtc);
  7314. to_intel_connector(connector)->new_encoder = intel_encoder;
  7315. intel_crtc = to_intel_crtc(crtc);
  7316. intel_crtc->new_enabled = true;
  7317. intel_crtc->new_config = &intel_crtc->config;
  7318. old->dpms_mode = connector->dpms;
  7319. old->load_detect_temp = true;
  7320. old->release_fb = NULL;
  7321. if (!mode)
  7322. mode = &load_detect_mode;
  7323. /* We need a framebuffer large enough to accommodate all accesses
  7324. * that the plane may generate whilst we perform load detection.
  7325. * We can not rely on the fbcon either being present (we get called
  7326. * during its initialisation to detect all boot displays, or it may
  7327. * not even exist) or that it is large enough to satisfy the
  7328. * requested mode.
  7329. */
  7330. fb = mode_fits_in_fbdev(dev, mode);
  7331. if (fb == NULL) {
  7332. DRM_DEBUG_KMS("creating tmp fb for load-detection\n");
  7333. fb = intel_framebuffer_create_for_mode(dev, mode, 24, 32);
  7334. old->release_fb = fb;
  7335. } else
  7336. DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n");
  7337. if (IS_ERR(fb)) {
  7338. DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n");
  7339. goto fail;
  7340. }
  7341. if (intel_set_mode(crtc, mode, 0, 0, fb)) {
  7342. DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
  7343. if (old->release_fb)
  7344. old->release_fb->funcs->destroy(old->release_fb);
  7345. goto fail;
  7346. }
  7347. /* let the connector get through one full cycle before testing */
  7348. intel_wait_for_vblank(dev, intel_crtc->pipe);
  7349. return true;
  7350. fail:
  7351. intel_crtc->new_enabled = crtc->enabled;
  7352. if (intel_crtc->new_enabled)
  7353. intel_crtc->new_config = &intel_crtc->config;
  7354. else
  7355. intel_crtc->new_config = NULL;
  7356. fail_unlock:
  7357. if (ret == -EDEADLK) {
  7358. drm_modeset_backoff(ctx);
  7359. goto retry;
  7360. }
  7361. return false;
  7362. }
  7363. void intel_release_load_detect_pipe(struct drm_connector *connector,
  7364. struct intel_load_detect_pipe *old)
  7365. {
  7366. struct intel_encoder *intel_encoder =
  7367. intel_attached_encoder(connector);
  7368. struct drm_encoder *encoder = &intel_encoder->base;
  7369. struct drm_crtc *crtc = encoder->crtc;
  7370. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7371. DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
  7372. connector->base.id, connector->name,
  7373. encoder->base.id, encoder->name);
  7374. if (old->load_detect_temp) {
  7375. to_intel_connector(connector)->new_encoder = NULL;
  7376. intel_encoder->new_crtc = NULL;
  7377. intel_crtc->new_enabled = false;
  7378. intel_crtc->new_config = NULL;
  7379. intel_set_mode(crtc, NULL, 0, 0, NULL);
  7380. if (old->release_fb) {
  7381. drm_framebuffer_unregister_private(old->release_fb);
  7382. drm_framebuffer_unreference(old->release_fb);
  7383. }
  7384. return;
  7385. }
  7386. /* Switch crtc and encoder back off if necessary */
  7387. if (old->dpms_mode != DRM_MODE_DPMS_ON)
  7388. connector->funcs->dpms(connector, old->dpms_mode);
  7389. }
  7390. static int i9xx_pll_refclk(struct drm_device *dev,
  7391. const struct intel_crtc_config *pipe_config)
  7392. {
  7393. struct drm_i915_private *dev_priv = dev->dev_private;
  7394. u32 dpll = pipe_config->dpll_hw_state.dpll;
  7395. if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN)
  7396. return dev_priv->vbt.lvds_ssc_freq;
  7397. else if (HAS_PCH_SPLIT(dev))
  7398. return 120000;
  7399. else if (!IS_GEN2(dev))
  7400. return 96000;
  7401. else
  7402. return 48000;
  7403. }
  7404. /* Returns the clock of the currently programmed mode of the given pipe. */
  7405. static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
  7406. struct intel_crtc_config *pipe_config)
  7407. {
  7408. struct drm_device *dev = crtc->base.dev;
  7409. struct drm_i915_private *dev_priv = dev->dev_private;
  7410. int pipe = pipe_config->cpu_transcoder;
  7411. u32 dpll = pipe_config->dpll_hw_state.dpll;
  7412. u32 fp;
  7413. intel_clock_t clock;
  7414. int refclk = i9xx_pll_refclk(dev, pipe_config);
  7415. if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
  7416. fp = pipe_config->dpll_hw_state.fp0;
  7417. else
  7418. fp = pipe_config->dpll_hw_state.fp1;
  7419. clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
  7420. if (IS_PINEVIEW(dev)) {
  7421. clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
  7422. clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
  7423. } else {
  7424. clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
  7425. clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
  7426. }
  7427. if (!IS_GEN2(dev)) {
  7428. if (IS_PINEVIEW(dev))
  7429. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
  7430. DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
  7431. else
  7432. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
  7433. DPLL_FPA01_P1_POST_DIV_SHIFT);
  7434. switch (dpll & DPLL_MODE_MASK) {
  7435. case DPLLB_MODE_DAC_SERIAL:
  7436. clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
  7437. 5 : 10;
  7438. break;
  7439. case DPLLB_MODE_LVDS:
  7440. clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
  7441. 7 : 14;
  7442. break;
  7443. default:
  7444. DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
  7445. "mode\n", (int)(dpll & DPLL_MODE_MASK));
  7446. return;
  7447. }
  7448. if (IS_PINEVIEW(dev))
  7449. pineview_clock(refclk, &clock);
  7450. else
  7451. i9xx_clock(refclk, &clock);
  7452. } else {
  7453. u32 lvds = IS_I830(dev) ? 0 : I915_READ(LVDS);
  7454. bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN);
  7455. if (is_lvds) {
  7456. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
  7457. DPLL_FPA01_P1_POST_DIV_SHIFT);
  7458. if (lvds & LVDS_CLKB_POWER_UP)
  7459. clock.p2 = 7;
  7460. else
  7461. clock.p2 = 14;
  7462. } else {
  7463. if (dpll & PLL_P1_DIVIDE_BY_TWO)
  7464. clock.p1 = 2;
  7465. else {
  7466. clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
  7467. DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
  7468. }
  7469. if (dpll & PLL_P2_DIVIDE_BY_4)
  7470. clock.p2 = 4;
  7471. else
  7472. clock.p2 = 2;
  7473. }
  7474. i9xx_clock(refclk, &clock);
  7475. }
  7476. /*
  7477. * This value includes pixel_multiplier. We will use
  7478. * port_clock to compute adjusted_mode.crtc_clock in the
  7479. * encoder's get_config() function.
  7480. */
  7481. pipe_config->port_clock = clock.dot;
  7482. }
  7483. int intel_dotclock_calculate(int link_freq,
  7484. const struct intel_link_m_n *m_n)
  7485. {
  7486. /*
  7487. * The calculation for the data clock is:
  7488. * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
  7489. * But we want to avoid losing precison if possible, so:
  7490. * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
  7491. *
  7492. * and the link clock is simpler:
  7493. * link_clock = (m * link_clock) / n
  7494. */
  7495. if (!m_n->link_n)
  7496. return 0;
  7497. return div_u64((u64)m_n->link_m * link_freq, m_n->link_n);
  7498. }
  7499. static void ironlake_pch_clock_get(struct intel_crtc *crtc,
  7500. struct intel_crtc_config *pipe_config)
  7501. {
  7502. struct drm_device *dev = crtc->base.dev;
  7503. /* read out port_clock from the DPLL */
  7504. i9xx_crtc_clock_get(crtc, pipe_config);
  7505. /*
  7506. * This value does not include pixel_multiplier.
  7507. * We will check that port_clock and adjusted_mode.crtc_clock
  7508. * agree once we know their relationship in the encoder's
  7509. * get_config() function.
  7510. */
  7511. pipe_config->adjusted_mode.crtc_clock =
  7512. intel_dotclock_calculate(intel_fdi_link_freq(dev) * 10000,
  7513. &pipe_config->fdi_m_n);
  7514. }
  7515. /** Returns the currently programmed mode of the given pipe. */
  7516. struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev,
  7517. struct drm_crtc *crtc)
  7518. {
  7519. struct drm_i915_private *dev_priv = dev->dev_private;
  7520. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7521. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  7522. struct drm_display_mode *mode;
  7523. struct intel_crtc_config pipe_config;
  7524. int htot = I915_READ(HTOTAL(cpu_transcoder));
  7525. int hsync = I915_READ(HSYNC(cpu_transcoder));
  7526. int vtot = I915_READ(VTOTAL(cpu_transcoder));
  7527. int vsync = I915_READ(VSYNC(cpu_transcoder));
  7528. enum pipe pipe = intel_crtc->pipe;
  7529. mode = kzalloc(sizeof(*mode), GFP_KERNEL);
  7530. if (!mode)
  7531. return NULL;
  7532. /*
  7533. * Construct a pipe_config sufficient for getting the clock info
  7534. * back out of crtc_clock_get.
  7535. *
  7536. * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need
  7537. * to use a real value here instead.
  7538. */
  7539. pipe_config.cpu_transcoder = (enum transcoder) pipe;
  7540. pipe_config.pixel_multiplier = 1;
  7541. pipe_config.dpll_hw_state.dpll = I915_READ(DPLL(pipe));
  7542. pipe_config.dpll_hw_state.fp0 = I915_READ(FP0(pipe));
  7543. pipe_config.dpll_hw_state.fp1 = I915_READ(FP1(pipe));
  7544. i9xx_crtc_clock_get(intel_crtc, &pipe_config);
  7545. mode->clock = pipe_config.port_clock / pipe_config.pixel_multiplier;
  7546. mode->hdisplay = (htot & 0xffff) + 1;
  7547. mode->htotal = ((htot & 0xffff0000) >> 16) + 1;
  7548. mode->hsync_start = (hsync & 0xffff) + 1;
  7549. mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1;
  7550. mode->vdisplay = (vtot & 0xffff) + 1;
  7551. mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1;
  7552. mode->vsync_start = (vsync & 0xffff) + 1;
  7553. mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1;
  7554. drm_mode_set_name(mode);
  7555. return mode;
  7556. }
  7557. static void intel_increase_pllclock(struct drm_device *dev,
  7558. enum pipe pipe)
  7559. {
  7560. struct drm_i915_private *dev_priv = dev->dev_private;
  7561. int dpll_reg = DPLL(pipe);
  7562. int dpll;
  7563. if (!HAS_GMCH_DISPLAY(dev))
  7564. return;
  7565. if (!dev_priv->lvds_downclock_avail)
  7566. return;
  7567. dpll = I915_READ(dpll_reg);
  7568. if (!HAS_PIPE_CXSR(dev) && (dpll & DISPLAY_RATE_SELECT_FPA1)) {
  7569. DRM_DEBUG_DRIVER("upclocking LVDS\n");
  7570. assert_panel_unlocked(dev_priv, pipe);
  7571. dpll &= ~DISPLAY_RATE_SELECT_FPA1;
  7572. I915_WRITE(dpll_reg, dpll);
  7573. intel_wait_for_vblank(dev, pipe);
  7574. dpll = I915_READ(dpll_reg);
  7575. if (dpll & DISPLAY_RATE_SELECT_FPA1)
  7576. DRM_DEBUG_DRIVER("failed to upclock LVDS!\n");
  7577. }
  7578. }
  7579. static void intel_decrease_pllclock(struct drm_crtc *crtc)
  7580. {
  7581. struct drm_device *dev = crtc->dev;
  7582. struct drm_i915_private *dev_priv = dev->dev_private;
  7583. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7584. if (!HAS_GMCH_DISPLAY(dev))
  7585. return;
  7586. if (!dev_priv->lvds_downclock_avail)
  7587. return;
  7588. /*
  7589. * Since this is called by a timer, we should never get here in
  7590. * the manual case.
  7591. */
  7592. if (!HAS_PIPE_CXSR(dev) && intel_crtc->lowfreq_avail) {
  7593. int pipe = intel_crtc->pipe;
  7594. int dpll_reg = DPLL(pipe);
  7595. int dpll;
  7596. DRM_DEBUG_DRIVER("downclocking LVDS\n");
  7597. assert_panel_unlocked(dev_priv, pipe);
  7598. dpll = I915_READ(dpll_reg);
  7599. dpll |= DISPLAY_RATE_SELECT_FPA1;
  7600. I915_WRITE(dpll_reg, dpll);
  7601. intel_wait_for_vblank(dev, pipe);
  7602. dpll = I915_READ(dpll_reg);
  7603. if (!(dpll & DISPLAY_RATE_SELECT_FPA1))
  7604. DRM_DEBUG_DRIVER("failed to downclock LVDS!\n");
  7605. }
  7606. }
  7607. void intel_mark_busy(struct drm_device *dev)
  7608. {
  7609. struct drm_i915_private *dev_priv = dev->dev_private;
  7610. if (dev_priv->mm.busy)
  7611. return;
  7612. intel_runtime_pm_get(dev_priv);
  7613. i915_update_gfx_val(dev_priv);
  7614. dev_priv->mm.busy = true;
  7615. }
  7616. void intel_mark_idle(struct drm_device *dev)
  7617. {
  7618. struct drm_i915_private *dev_priv = dev->dev_private;
  7619. struct drm_crtc *crtc;
  7620. if (!dev_priv->mm.busy)
  7621. return;
  7622. dev_priv->mm.busy = false;
  7623. if (!i915.powersave)
  7624. goto out;
  7625. for_each_crtc(dev, crtc) {
  7626. if (!crtc->primary->fb)
  7627. continue;
  7628. intel_decrease_pllclock(crtc);
  7629. }
  7630. if (INTEL_INFO(dev)->gen >= 6)
  7631. gen6_rps_idle(dev->dev_private);
  7632. out:
  7633. intel_runtime_pm_put(dev_priv);
  7634. }
  7635. /**
  7636. * intel_mark_fb_busy - mark given planes as busy
  7637. * @dev: DRM device
  7638. * @frontbuffer_bits: bits for the affected planes
  7639. * @ring: optional ring for asynchronous commands
  7640. *
  7641. * This function gets called every time the screen contents change. It can be
  7642. * used to keep e.g. the update rate at the nominal refresh rate with DRRS.
  7643. */
  7644. static void intel_mark_fb_busy(struct drm_device *dev,
  7645. unsigned frontbuffer_bits,
  7646. struct intel_engine_cs *ring)
  7647. {
  7648. struct drm_i915_private *dev_priv = dev->dev_private;
  7649. enum pipe pipe;
  7650. if (!i915.powersave)
  7651. return;
  7652. for_each_pipe(dev_priv, pipe) {
  7653. if (!(frontbuffer_bits & INTEL_FRONTBUFFER_ALL_MASK(pipe)))
  7654. continue;
  7655. intel_increase_pllclock(dev, pipe);
  7656. if (ring && intel_fbc_enabled(dev))
  7657. ring->fbc_dirty = true;
  7658. }
  7659. }
  7660. /**
  7661. * intel_fb_obj_invalidate - invalidate frontbuffer object
  7662. * @obj: GEM object to invalidate
  7663. * @ring: set for asynchronous rendering
  7664. *
  7665. * This function gets called every time rendering on the given object starts and
  7666. * frontbuffer caching (fbc, low refresh rate for DRRS, panel self refresh) must
  7667. * be invalidated. If @ring is non-NULL any subsequent invalidation will be delayed
  7668. * until the rendering completes or a flip on this frontbuffer plane is
  7669. * scheduled.
  7670. */
  7671. void intel_fb_obj_invalidate(struct drm_i915_gem_object *obj,
  7672. struct intel_engine_cs *ring)
  7673. {
  7674. struct drm_device *dev = obj->base.dev;
  7675. struct drm_i915_private *dev_priv = dev->dev_private;
  7676. WARN_ON(!mutex_is_locked(&dev->struct_mutex));
  7677. if (!obj->frontbuffer_bits)
  7678. return;
  7679. if (ring) {
  7680. mutex_lock(&dev_priv->fb_tracking.lock);
  7681. dev_priv->fb_tracking.busy_bits
  7682. |= obj->frontbuffer_bits;
  7683. dev_priv->fb_tracking.flip_bits
  7684. &= ~obj->frontbuffer_bits;
  7685. mutex_unlock(&dev_priv->fb_tracking.lock);
  7686. }
  7687. intel_mark_fb_busy(dev, obj->frontbuffer_bits, ring);
  7688. intel_edp_psr_invalidate(dev, obj->frontbuffer_bits);
  7689. }
  7690. /**
  7691. * intel_frontbuffer_flush - flush frontbuffer
  7692. * @dev: DRM device
  7693. * @frontbuffer_bits: frontbuffer plane tracking bits
  7694. *
  7695. * This function gets called every time rendering on the given planes has
  7696. * completed and frontbuffer caching can be started again. Flushes will get
  7697. * delayed if they're blocked by some oustanding asynchronous rendering.
  7698. *
  7699. * Can be called without any locks held.
  7700. */
  7701. void intel_frontbuffer_flush(struct drm_device *dev,
  7702. unsigned frontbuffer_bits)
  7703. {
  7704. struct drm_i915_private *dev_priv = dev->dev_private;
  7705. /* Delay flushing when rings are still busy.*/
  7706. mutex_lock(&dev_priv->fb_tracking.lock);
  7707. frontbuffer_bits &= ~dev_priv->fb_tracking.busy_bits;
  7708. mutex_unlock(&dev_priv->fb_tracking.lock);
  7709. intel_mark_fb_busy(dev, frontbuffer_bits, NULL);
  7710. intel_edp_psr_flush(dev, frontbuffer_bits);
  7711. /*
  7712. * FIXME: Unconditional fbc flushing here is a rather gross hack and
  7713. * needs to be reworked into a proper frontbuffer tracking scheme like
  7714. * psr employs.
  7715. */
  7716. if (IS_BROADWELL(dev))
  7717. gen8_fbc_sw_flush(dev, FBC_REND_CACHE_CLEAN);
  7718. }
  7719. /**
  7720. * intel_fb_obj_flush - flush frontbuffer object
  7721. * @obj: GEM object to flush
  7722. * @retire: set when retiring asynchronous rendering
  7723. *
  7724. * This function gets called every time rendering on the given object has
  7725. * completed and frontbuffer caching can be started again. If @retire is true
  7726. * then any delayed flushes will be unblocked.
  7727. */
  7728. void intel_fb_obj_flush(struct drm_i915_gem_object *obj,
  7729. bool retire)
  7730. {
  7731. struct drm_device *dev = obj->base.dev;
  7732. struct drm_i915_private *dev_priv = dev->dev_private;
  7733. unsigned frontbuffer_bits;
  7734. WARN_ON(!mutex_is_locked(&dev->struct_mutex));
  7735. if (!obj->frontbuffer_bits)
  7736. return;
  7737. frontbuffer_bits = obj->frontbuffer_bits;
  7738. if (retire) {
  7739. mutex_lock(&dev_priv->fb_tracking.lock);
  7740. /* Filter out new bits since rendering started. */
  7741. frontbuffer_bits &= dev_priv->fb_tracking.busy_bits;
  7742. dev_priv->fb_tracking.busy_bits &= ~frontbuffer_bits;
  7743. mutex_unlock(&dev_priv->fb_tracking.lock);
  7744. }
  7745. intel_frontbuffer_flush(dev, frontbuffer_bits);
  7746. }
  7747. /**
  7748. * intel_frontbuffer_flip_prepare - prepare asnychronous frontbuffer flip
  7749. * @dev: DRM device
  7750. * @frontbuffer_bits: frontbuffer plane tracking bits
  7751. *
  7752. * This function gets called after scheduling a flip on @obj. The actual
  7753. * frontbuffer flushing will be delayed until completion is signalled with
  7754. * intel_frontbuffer_flip_complete. If an invalidate happens in between this
  7755. * flush will be cancelled.
  7756. *
  7757. * Can be called without any locks held.
  7758. */
  7759. void intel_frontbuffer_flip_prepare(struct drm_device *dev,
  7760. unsigned frontbuffer_bits)
  7761. {
  7762. struct drm_i915_private *dev_priv = dev->dev_private;
  7763. mutex_lock(&dev_priv->fb_tracking.lock);
  7764. dev_priv->fb_tracking.flip_bits
  7765. |= frontbuffer_bits;
  7766. mutex_unlock(&dev_priv->fb_tracking.lock);
  7767. }
  7768. /**
  7769. * intel_frontbuffer_flip_complete - complete asynchronous frontbuffer flush
  7770. * @dev: DRM device
  7771. * @frontbuffer_bits: frontbuffer plane tracking bits
  7772. *
  7773. * This function gets called after the flip has been latched and will complete
  7774. * on the next vblank. It will execute the fush if it hasn't been cancalled yet.
  7775. *
  7776. * Can be called without any locks held.
  7777. */
  7778. void intel_frontbuffer_flip_complete(struct drm_device *dev,
  7779. unsigned frontbuffer_bits)
  7780. {
  7781. struct drm_i915_private *dev_priv = dev->dev_private;
  7782. mutex_lock(&dev_priv->fb_tracking.lock);
  7783. /* Mask any cancelled flips. */
  7784. frontbuffer_bits &= dev_priv->fb_tracking.flip_bits;
  7785. dev_priv->fb_tracking.flip_bits &= ~frontbuffer_bits;
  7786. mutex_unlock(&dev_priv->fb_tracking.lock);
  7787. intel_frontbuffer_flush(dev, frontbuffer_bits);
  7788. }
  7789. static void intel_crtc_destroy(struct drm_crtc *crtc)
  7790. {
  7791. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7792. struct drm_device *dev = crtc->dev;
  7793. struct intel_unpin_work *work;
  7794. unsigned long flags;
  7795. spin_lock_irqsave(&dev->event_lock, flags);
  7796. work = intel_crtc->unpin_work;
  7797. intel_crtc->unpin_work = NULL;
  7798. spin_unlock_irqrestore(&dev->event_lock, flags);
  7799. if (work) {
  7800. cancel_work_sync(&work->work);
  7801. kfree(work);
  7802. }
  7803. drm_crtc_cleanup(crtc);
  7804. kfree(intel_crtc);
  7805. }
  7806. static void intel_unpin_work_fn(struct work_struct *__work)
  7807. {
  7808. struct intel_unpin_work *work =
  7809. container_of(__work, struct intel_unpin_work, work);
  7810. struct drm_device *dev = work->crtc->dev;
  7811. enum pipe pipe = to_intel_crtc(work->crtc)->pipe;
  7812. mutex_lock(&dev->struct_mutex);
  7813. intel_unpin_fb_obj(work->old_fb_obj);
  7814. drm_gem_object_unreference(&work->pending_flip_obj->base);
  7815. drm_gem_object_unreference(&work->old_fb_obj->base);
  7816. intel_update_fbc(dev);
  7817. mutex_unlock(&dev->struct_mutex);
  7818. intel_frontbuffer_flip_complete(dev, INTEL_FRONTBUFFER_PRIMARY(pipe));
  7819. BUG_ON(atomic_read(&to_intel_crtc(work->crtc)->unpin_work_count) == 0);
  7820. atomic_dec(&to_intel_crtc(work->crtc)->unpin_work_count);
  7821. kfree(work);
  7822. }
  7823. static void do_intel_finish_page_flip(struct drm_device *dev,
  7824. struct drm_crtc *crtc)
  7825. {
  7826. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7827. struct intel_unpin_work *work;
  7828. unsigned long flags;
  7829. /* Ignore early vblank irqs */
  7830. if (intel_crtc == NULL)
  7831. return;
  7832. spin_lock_irqsave(&dev->event_lock, flags);
  7833. work = intel_crtc->unpin_work;
  7834. /* Ensure we don't miss a work->pending update ... */
  7835. smp_rmb();
  7836. if (work == NULL || atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) {
  7837. spin_unlock_irqrestore(&dev->event_lock, flags);
  7838. return;
  7839. }
  7840. page_flip_completed(intel_crtc);
  7841. spin_unlock_irqrestore(&dev->event_lock, flags);
  7842. }
  7843. void intel_finish_page_flip(struct drm_device *dev, int pipe)
  7844. {
  7845. struct drm_i915_private *dev_priv = dev->dev_private;
  7846. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  7847. do_intel_finish_page_flip(dev, crtc);
  7848. }
  7849. void intel_finish_page_flip_plane(struct drm_device *dev, int plane)
  7850. {
  7851. struct drm_i915_private *dev_priv = dev->dev_private;
  7852. struct drm_crtc *crtc = dev_priv->plane_to_crtc_mapping[plane];
  7853. do_intel_finish_page_flip(dev, crtc);
  7854. }
  7855. /* Is 'a' after or equal to 'b'? */
  7856. static bool g4x_flip_count_after_eq(u32 a, u32 b)
  7857. {
  7858. return !((a - b) & 0x80000000);
  7859. }
  7860. static bool page_flip_finished(struct intel_crtc *crtc)
  7861. {
  7862. struct drm_device *dev = crtc->base.dev;
  7863. struct drm_i915_private *dev_priv = dev->dev_private;
  7864. /*
  7865. * The relevant registers doen't exist on pre-ctg.
  7866. * As the flip done interrupt doesn't trigger for mmio
  7867. * flips on gmch platforms, a flip count check isn't
  7868. * really needed there. But since ctg has the registers,
  7869. * include it in the check anyway.
  7870. */
  7871. if (INTEL_INFO(dev)->gen < 5 && !IS_G4X(dev))
  7872. return true;
  7873. /*
  7874. * A DSPSURFLIVE check isn't enough in case the mmio and CS flips
  7875. * used the same base address. In that case the mmio flip might
  7876. * have completed, but the CS hasn't even executed the flip yet.
  7877. *
  7878. * A flip count check isn't enough as the CS might have updated
  7879. * the base address just after start of vblank, but before we
  7880. * managed to process the interrupt. This means we'd complete the
  7881. * CS flip too soon.
  7882. *
  7883. * Combining both checks should get us a good enough result. It may
  7884. * still happen that the CS flip has been executed, but has not
  7885. * yet actually completed. But in case the base address is the same
  7886. * anyway, we don't really care.
  7887. */
  7888. return (I915_READ(DSPSURFLIVE(crtc->plane)) & ~0xfff) ==
  7889. crtc->unpin_work->gtt_offset &&
  7890. g4x_flip_count_after_eq(I915_READ(PIPE_FLIPCOUNT_GM45(crtc->pipe)),
  7891. crtc->unpin_work->flip_count);
  7892. }
  7893. void intel_prepare_page_flip(struct drm_device *dev, int plane)
  7894. {
  7895. struct drm_i915_private *dev_priv = dev->dev_private;
  7896. struct intel_crtc *intel_crtc =
  7897. to_intel_crtc(dev_priv->plane_to_crtc_mapping[plane]);
  7898. unsigned long flags;
  7899. /* NB: An MMIO update of the plane base pointer will also
  7900. * generate a page-flip completion irq, i.e. every modeset
  7901. * is also accompanied by a spurious intel_prepare_page_flip().
  7902. */
  7903. spin_lock_irqsave(&dev->event_lock, flags);
  7904. if (intel_crtc->unpin_work && page_flip_finished(intel_crtc))
  7905. atomic_inc_not_zero(&intel_crtc->unpin_work->pending);
  7906. spin_unlock_irqrestore(&dev->event_lock, flags);
  7907. }
  7908. static inline void intel_mark_page_flip_active(struct intel_crtc *intel_crtc)
  7909. {
  7910. /* Ensure that the work item is consistent when activating it ... */
  7911. smp_wmb();
  7912. atomic_set(&intel_crtc->unpin_work->pending, INTEL_FLIP_PENDING);
  7913. /* and that it is marked active as soon as the irq could fire. */
  7914. smp_wmb();
  7915. }
  7916. static int intel_gen2_queue_flip(struct drm_device *dev,
  7917. struct drm_crtc *crtc,
  7918. struct drm_framebuffer *fb,
  7919. struct drm_i915_gem_object *obj,
  7920. struct intel_engine_cs *ring,
  7921. uint32_t flags)
  7922. {
  7923. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7924. u32 flip_mask;
  7925. int ret;
  7926. ret = intel_ring_begin(ring, 6);
  7927. if (ret)
  7928. return ret;
  7929. /* Can't queue multiple flips, so wait for the previous
  7930. * one to finish before executing the next.
  7931. */
  7932. if (intel_crtc->plane)
  7933. flip_mask = MI_WAIT_FOR_PLANE_B_FLIP;
  7934. else
  7935. flip_mask = MI_WAIT_FOR_PLANE_A_FLIP;
  7936. intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask);
  7937. intel_ring_emit(ring, MI_NOOP);
  7938. intel_ring_emit(ring, MI_DISPLAY_FLIP |
  7939. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  7940. intel_ring_emit(ring, fb->pitches[0]);
  7941. intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset);
  7942. intel_ring_emit(ring, 0); /* aux display base address, unused */
  7943. intel_mark_page_flip_active(intel_crtc);
  7944. __intel_ring_advance(ring);
  7945. return 0;
  7946. }
  7947. static int intel_gen3_queue_flip(struct drm_device *dev,
  7948. struct drm_crtc *crtc,
  7949. struct drm_framebuffer *fb,
  7950. struct drm_i915_gem_object *obj,
  7951. struct intel_engine_cs *ring,
  7952. uint32_t flags)
  7953. {
  7954. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7955. u32 flip_mask;
  7956. int ret;
  7957. ret = intel_ring_begin(ring, 6);
  7958. if (ret)
  7959. return ret;
  7960. if (intel_crtc->plane)
  7961. flip_mask = MI_WAIT_FOR_PLANE_B_FLIP;
  7962. else
  7963. flip_mask = MI_WAIT_FOR_PLANE_A_FLIP;
  7964. intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask);
  7965. intel_ring_emit(ring, MI_NOOP);
  7966. intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 |
  7967. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  7968. intel_ring_emit(ring, fb->pitches[0]);
  7969. intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset);
  7970. intel_ring_emit(ring, MI_NOOP);
  7971. intel_mark_page_flip_active(intel_crtc);
  7972. __intel_ring_advance(ring);
  7973. return 0;
  7974. }
  7975. static int intel_gen4_queue_flip(struct drm_device *dev,
  7976. struct drm_crtc *crtc,
  7977. struct drm_framebuffer *fb,
  7978. struct drm_i915_gem_object *obj,
  7979. struct intel_engine_cs *ring,
  7980. uint32_t flags)
  7981. {
  7982. struct drm_i915_private *dev_priv = dev->dev_private;
  7983. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7984. uint32_t pf, pipesrc;
  7985. int ret;
  7986. ret = intel_ring_begin(ring, 4);
  7987. if (ret)
  7988. return ret;
  7989. /* i965+ uses the linear or tiled offsets from the
  7990. * Display Registers (which do not change across a page-flip)
  7991. * so we need only reprogram the base address.
  7992. */
  7993. intel_ring_emit(ring, MI_DISPLAY_FLIP |
  7994. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  7995. intel_ring_emit(ring, fb->pitches[0]);
  7996. intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset |
  7997. obj->tiling_mode);
  7998. /* XXX Enabling the panel-fitter across page-flip is so far
  7999. * untested on non-native modes, so ignore it for now.
  8000. * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE;
  8001. */
  8002. pf = 0;
  8003. pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
  8004. intel_ring_emit(ring, pf | pipesrc);
  8005. intel_mark_page_flip_active(intel_crtc);
  8006. __intel_ring_advance(ring);
  8007. return 0;
  8008. }
  8009. static int intel_gen6_queue_flip(struct drm_device *dev,
  8010. struct drm_crtc *crtc,
  8011. struct drm_framebuffer *fb,
  8012. struct drm_i915_gem_object *obj,
  8013. struct intel_engine_cs *ring,
  8014. uint32_t flags)
  8015. {
  8016. struct drm_i915_private *dev_priv = dev->dev_private;
  8017. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  8018. uint32_t pf, pipesrc;
  8019. int ret;
  8020. ret = intel_ring_begin(ring, 4);
  8021. if (ret)
  8022. return ret;
  8023. intel_ring_emit(ring, MI_DISPLAY_FLIP |
  8024. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  8025. intel_ring_emit(ring, fb->pitches[0] | obj->tiling_mode);
  8026. intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset);
  8027. /* Contrary to the suggestions in the documentation,
  8028. * "Enable Panel Fitter" does not seem to be required when page
  8029. * flipping with a non-native mode, and worse causes a normal
  8030. * modeset to fail.
  8031. * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE;
  8032. */
  8033. pf = 0;
  8034. pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
  8035. intel_ring_emit(ring, pf | pipesrc);
  8036. intel_mark_page_flip_active(intel_crtc);
  8037. __intel_ring_advance(ring);
  8038. return 0;
  8039. }
  8040. static int intel_gen7_queue_flip(struct drm_device *dev,
  8041. struct drm_crtc *crtc,
  8042. struct drm_framebuffer *fb,
  8043. struct drm_i915_gem_object *obj,
  8044. struct intel_engine_cs *ring,
  8045. uint32_t flags)
  8046. {
  8047. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  8048. uint32_t plane_bit = 0;
  8049. int len, ret;
  8050. switch (intel_crtc->plane) {
  8051. case PLANE_A:
  8052. plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_A;
  8053. break;
  8054. case PLANE_B:
  8055. plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_B;
  8056. break;
  8057. case PLANE_C:
  8058. plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_C;
  8059. break;
  8060. default:
  8061. WARN_ONCE(1, "unknown plane in flip command\n");
  8062. return -ENODEV;
  8063. }
  8064. len = 4;
  8065. if (ring->id == RCS) {
  8066. len += 6;
  8067. /*
  8068. * On Gen 8, SRM is now taking an extra dword to accommodate
  8069. * 48bits addresses, and we need a NOOP for the batch size to
  8070. * stay even.
  8071. */
  8072. if (IS_GEN8(dev))
  8073. len += 2;
  8074. }
  8075. /*
  8076. * BSpec MI_DISPLAY_FLIP for IVB:
  8077. * "The full packet must be contained within the same cache line."
  8078. *
  8079. * Currently the LRI+SRM+MI_DISPLAY_FLIP all fit within the same
  8080. * cacheline, if we ever start emitting more commands before
  8081. * the MI_DISPLAY_FLIP we may need to first emit everything else,
  8082. * then do the cacheline alignment, and finally emit the
  8083. * MI_DISPLAY_FLIP.
  8084. */
  8085. ret = intel_ring_cacheline_align(ring);
  8086. if (ret)
  8087. return ret;
  8088. ret = intel_ring_begin(ring, len);
  8089. if (ret)
  8090. return ret;
  8091. /* Unmask the flip-done completion message. Note that the bspec says that
  8092. * we should do this for both the BCS and RCS, and that we must not unmask
  8093. * more than one flip event at any time (or ensure that one flip message
  8094. * can be sent by waiting for flip-done prior to queueing new flips).
  8095. * Experimentation says that BCS works despite DERRMR masking all
  8096. * flip-done completion events and that unmasking all planes at once
  8097. * for the RCS also doesn't appear to drop events. Setting the DERRMR
  8098. * to zero does lead to lockups within MI_DISPLAY_FLIP.
  8099. */
  8100. if (ring->id == RCS) {
  8101. intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1));
  8102. intel_ring_emit(ring, DERRMR);
  8103. intel_ring_emit(ring, ~(DERRMR_PIPEA_PRI_FLIP_DONE |
  8104. DERRMR_PIPEB_PRI_FLIP_DONE |
  8105. DERRMR_PIPEC_PRI_FLIP_DONE));
  8106. if (IS_GEN8(dev))
  8107. intel_ring_emit(ring, MI_STORE_REGISTER_MEM_GEN8(1) |
  8108. MI_SRM_LRM_GLOBAL_GTT);
  8109. else
  8110. intel_ring_emit(ring, MI_STORE_REGISTER_MEM(1) |
  8111. MI_SRM_LRM_GLOBAL_GTT);
  8112. intel_ring_emit(ring, DERRMR);
  8113. intel_ring_emit(ring, ring->scratch.gtt_offset + 256);
  8114. if (IS_GEN8(dev)) {
  8115. intel_ring_emit(ring, 0);
  8116. intel_ring_emit(ring, MI_NOOP);
  8117. }
  8118. }
  8119. intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | plane_bit);
  8120. intel_ring_emit(ring, (fb->pitches[0] | obj->tiling_mode));
  8121. intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset);
  8122. intel_ring_emit(ring, (MI_NOOP));
  8123. intel_mark_page_flip_active(intel_crtc);
  8124. __intel_ring_advance(ring);
  8125. return 0;
  8126. }
  8127. static bool use_mmio_flip(struct intel_engine_cs *ring,
  8128. struct drm_i915_gem_object *obj)
  8129. {
  8130. /*
  8131. * This is not being used for older platforms, because
  8132. * non-availability of flip done interrupt forces us to use
  8133. * CS flips. Older platforms derive flip done using some clever
  8134. * tricks involving the flip_pending status bits and vblank irqs.
  8135. * So using MMIO flips there would disrupt this mechanism.
  8136. */
  8137. if (ring == NULL)
  8138. return true;
  8139. if (INTEL_INFO(ring->dev)->gen < 5)
  8140. return false;
  8141. if (i915.use_mmio_flip < 0)
  8142. return false;
  8143. else if (i915.use_mmio_flip > 0)
  8144. return true;
  8145. else if (i915.enable_execlists)
  8146. return true;
  8147. else
  8148. return ring != obj->ring;
  8149. }
  8150. static void intel_do_mmio_flip(struct intel_crtc *intel_crtc)
  8151. {
  8152. struct drm_device *dev = intel_crtc->base.dev;
  8153. struct drm_i915_private *dev_priv = dev->dev_private;
  8154. struct intel_framebuffer *intel_fb =
  8155. to_intel_framebuffer(intel_crtc->base.primary->fb);
  8156. struct drm_i915_gem_object *obj = intel_fb->obj;
  8157. u32 dspcntr;
  8158. u32 reg;
  8159. intel_mark_page_flip_active(intel_crtc);
  8160. reg = DSPCNTR(intel_crtc->plane);
  8161. dspcntr = I915_READ(reg);
  8162. if (INTEL_INFO(dev)->gen >= 4) {
  8163. if (obj->tiling_mode != I915_TILING_NONE)
  8164. dspcntr |= DISPPLANE_TILED;
  8165. else
  8166. dspcntr &= ~DISPPLANE_TILED;
  8167. }
  8168. I915_WRITE(reg, dspcntr);
  8169. I915_WRITE(DSPSURF(intel_crtc->plane),
  8170. intel_crtc->unpin_work->gtt_offset);
  8171. POSTING_READ(DSPSURF(intel_crtc->plane));
  8172. }
  8173. static int intel_postpone_flip(struct drm_i915_gem_object *obj)
  8174. {
  8175. struct intel_engine_cs *ring;
  8176. int ret;
  8177. lockdep_assert_held(&obj->base.dev->struct_mutex);
  8178. if (!obj->last_write_seqno)
  8179. return 0;
  8180. ring = obj->ring;
  8181. if (i915_seqno_passed(ring->get_seqno(ring, true),
  8182. obj->last_write_seqno))
  8183. return 0;
  8184. ret = i915_gem_check_olr(ring, obj->last_write_seqno);
  8185. if (ret)
  8186. return ret;
  8187. if (WARN_ON(!ring->irq_get(ring)))
  8188. return 0;
  8189. return 1;
  8190. }
  8191. void intel_notify_mmio_flip(struct intel_engine_cs *ring)
  8192. {
  8193. struct drm_i915_private *dev_priv = to_i915(ring->dev);
  8194. struct intel_crtc *intel_crtc;
  8195. unsigned long irq_flags;
  8196. u32 seqno;
  8197. seqno = ring->get_seqno(ring, false);
  8198. spin_lock_irqsave(&dev_priv->mmio_flip_lock, irq_flags);
  8199. for_each_intel_crtc(ring->dev, intel_crtc) {
  8200. struct intel_mmio_flip *mmio_flip;
  8201. mmio_flip = &intel_crtc->mmio_flip;
  8202. if (mmio_flip->seqno == 0)
  8203. continue;
  8204. if (ring->id != mmio_flip->ring_id)
  8205. continue;
  8206. if (i915_seqno_passed(seqno, mmio_flip->seqno)) {
  8207. intel_do_mmio_flip(intel_crtc);
  8208. mmio_flip->seqno = 0;
  8209. ring->irq_put(ring);
  8210. }
  8211. }
  8212. spin_unlock_irqrestore(&dev_priv->mmio_flip_lock, irq_flags);
  8213. }
  8214. static int intel_queue_mmio_flip(struct drm_device *dev,
  8215. struct drm_crtc *crtc,
  8216. struct drm_framebuffer *fb,
  8217. struct drm_i915_gem_object *obj,
  8218. struct intel_engine_cs *ring,
  8219. uint32_t flags)
  8220. {
  8221. struct drm_i915_private *dev_priv = dev->dev_private;
  8222. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  8223. unsigned long irq_flags;
  8224. int ret;
  8225. if (WARN_ON(intel_crtc->mmio_flip.seqno))
  8226. return -EBUSY;
  8227. ret = intel_postpone_flip(obj);
  8228. if (ret < 0)
  8229. return ret;
  8230. if (ret == 0) {
  8231. intel_do_mmio_flip(intel_crtc);
  8232. return 0;
  8233. }
  8234. spin_lock_irqsave(&dev_priv->mmio_flip_lock, irq_flags);
  8235. intel_crtc->mmio_flip.seqno = obj->last_write_seqno;
  8236. intel_crtc->mmio_flip.ring_id = obj->ring->id;
  8237. spin_unlock_irqrestore(&dev_priv->mmio_flip_lock, irq_flags);
  8238. /*
  8239. * Double check to catch cases where irq fired before
  8240. * mmio flip data was ready
  8241. */
  8242. intel_notify_mmio_flip(obj->ring);
  8243. return 0;
  8244. }
  8245. static int intel_default_queue_flip(struct drm_device *dev,
  8246. struct drm_crtc *crtc,
  8247. struct drm_framebuffer *fb,
  8248. struct drm_i915_gem_object *obj,
  8249. struct intel_engine_cs *ring,
  8250. uint32_t flags)
  8251. {
  8252. return -ENODEV;
  8253. }
  8254. static bool __intel_pageflip_stall_check(struct drm_device *dev,
  8255. struct drm_crtc *crtc)
  8256. {
  8257. struct drm_i915_private *dev_priv = dev->dev_private;
  8258. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  8259. struct intel_unpin_work *work = intel_crtc->unpin_work;
  8260. u32 addr;
  8261. if (atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE)
  8262. return true;
  8263. if (!work->enable_stall_check)
  8264. return false;
  8265. if (work->flip_ready_vblank == 0) {
  8266. if (work->flip_queued_ring &&
  8267. !i915_seqno_passed(work->flip_queued_ring->get_seqno(work->flip_queued_ring, true),
  8268. work->flip_queued_seqno))
  8269. return false;
  8270. work->flip_ready_vblank = drm_vblank_count(dev, intel_crtc->pipe);
  8271. }
  8272. if (drm_vblank_count(dev, intel_crtc->pipe) - work->flip_ready_vblank < 3)
  8273. return false;
  8274. /* Potential stall - if we see that the flip has happened,
  8275. * assume a missed interrupt. */
  8276. if (INTEL_INFO(dev)->gen >= 4)
  8277. addr = I915_HI_DISPBASE(I915_READ(DSPSURF(intel_crtc->plane)));
  8278. else
  8279. addr = I915_READ(DSPADDR(intel_crtc->plane));
  8280. /* There is a potential issue here with a false positive after a flip
  8281. * to the same address. We could address this by checking for a
  8282. * non-incrementing frame counter.
  8283. */
  8284. return addr == work->gtt_offset;
  8285. }
  8286. void intel_check_page_flip(struct drm_device *dev, int pipe)
  8287. {
  8288. struct drm_i915_private *dev_priv = dev->dev_private;
  8289. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  8290. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  8291. unsigned long flags;
  8292. if (crtc == NULL)
  8293. return;
  8294. spin_lock_irqsave(&dev->event_lock, flags);
  8295. if (intel_crtc->unpin_work && __intel_pageflip_stall_check(dev, crtc)) {
  8296. WARN_ONCE(1, "Kicking stuck page flip: queued at %d, now %d\n",
  8297. intel_crtc->unpin_work->flip_queued_vblank, drm_vblank_count(dev, pipe));
  8298. page_flip_completed(intel_crtc);
  8299. }
  8300. spin_unlock_irqrestore(&dev->event_lock, flags);
  8301. }
  8302. static int intel_crtc_page_flip(struct drm_crtc *crtc,
  8303. struct drm_framebuffer *fb,
  8304. struct drm_pending_vblank_event *event,
  8305. uint32_t page_flip_flags)
  8306. {
  8307. struct drm_device *dev = crtc->dev;
  8308. struct drm_i915_private *dev_priv = dev->dev_private;
  8309. struct drm_framebuffer *old_fb = crtc->primary->fb;
  8310. struct drm_i915_gem_object *obj = intel_fb_obj(fb);
  8311. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  8312. enum pipe pipe = intel_crtc->pipe;
  8313. struct intel_unpin_work *work;
  8314. struct intel_engine_cs *ring;
  8315. unsigned long flags;
  8316. int ret;
  8317. /*
  8318. * drm_mode_page_flip_ioctl() should already catch this, but double
  8319. * check to be safe. In the future we may enable pageflipping from
  8320. * a disabled primary plane.
  8321. */
  8322. if (WARN_ON(intel_fb_obj(old_fb) == NULL))
  8323. return -EBUSY;
  8324. /* Can't change pixel format via MI display flips. */
  8325. if (fb->pixel_format != crtc->primary->fb->pixel_format)
  8326. return -EINVAL;
  8327. /*
  8328. * TILEOFF/LINOFF registers can't be changed via MI display flips.
  8329. * Note that pitch changes could also affect these register.
  8330. */
  8331. if (INTEL_INFO(dev)->gen > 3 &&
  8332. (fb->offsets[0] != crtc->primary->fb->offsets[0] ||
  8333. fb->pitches[0] != crtc->primary->fb->pitches[0]))
  8334. return -EINVAL;
  8335. if (i915_terminally_wedged(&dev_priv->gpu_error))
  8336. goto out_hang;
  8337. work = kzalloc(sizeof(*work), GFP_KERNEL);
  8338. if (work == NULL)
  8339. return -ENOMEM;
  8340. work->event = event;
  8341. work->crtc = crtc;
  8342. work->old_fb_obj = intel_fb_obj(old_fb);
  8343. INIT_WORK(&work->work, intel_unpin_work_fn);
  8344. ret = drm_crtc_vblank_get(crtc);
  8345. if (ret)
  8346. goto free_work;
  8347. /* We borrow the event spin lock for protecting unpin_work */
  8348. spin_lock_irqsave(&dev->event_lock, flags);
  8349. if (intel_crtc->unpin_work) {
  8350. /* Before declaring the flip queue wedged, check if
  8351. * the hardware completed the operation behind our backs.
  8352. */
  8353. if (__intel_pageflip_stall_check(dev, crtc)) {
  8354. DRM_DEBUG_DRIVER("flip queue: previous flip completed, continuing\n");
  8355. page_flip_completed(intel_crtc);
  8356. } else {
  8357. DRM_DEBUG_DRIVER("flip queue: crtc already busy\n");
  8358. spin_unlock_irqrestore(&dev->event_lock, flags);
  8359. drm_crtc_vblank_put(crtc);
  8360. kfree(work);
  8361. return -EBUSY;
  8362. }
  8363. }
  8364. intel_crtc->unpin_work = work;
  8365. spin_unlock_irqrestore(&dev->event_lock, flags);
  8366. if (atomic_read(&intel_crtc->unpin_work_count) >= 2)
  8367. flush_workqueue(dev_priv->wq);
  8368. ret = i915_mutex_lock_interruptible(dev);
  8369. if (ret)
  8370. goto cleanup;
  8371. /* Reference the objects for the scheduled work. */
  8372. drm_gem_object_reference(&work->old_fb_obj->base);
  8373. drm_gem_object_reference(&obj->base);
  8374. crtc->primary->fb = fb;
  8375. work->pending_flip_obj = obj;
  8376. atomic_inc(&intel_crtc->unpin_work_count);
  8377. intel_crtc->reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter);
  8378. if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev))
  8379. work->flip_count = I915_READ(PIPE_FLIPCOUNT_GM45(pipe)) + 1;
  8380. if (IS_VALLEYVIEW(dev)) {
  8381. ring = &dev_priv->ring[BCS];
  8382. if (obj->tiling_mode != work->old_fb_obj->tiling_mode)
  8383. /* vlv: DISPLAY_FLIP fails to change tiling */
  8384. ring = NULL;
  8385. } else if (IS_IVYBRIDGE(dev)) {
  8386. ring = &dev_priv->ring[BCS];
  8387. } else if (INTEL_INFO(dev)->gen >= 7) {
  8388. ring = obj->ring;
  8389. if (ring == NULL || ring->id != RCS)
  8390. ring = &dev_priv->ring[BCS];
  8391. } else {
  8392. ring = &dev_priv->ring[RCS];
  8393. }
  8394. ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
  8395. if (ret)
  8396. goto cleanup_pending;
  8397. work->gtt_offset =
  8398. i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset;
  8399. if (use_mmio_flip(ring, obj)) {
  8400. ret = intel_queue_mmio_flip(dev, crtc, fb, obj, ring,
  8401. page_flip_flags);
  8402. if (ret)
  8403. goto cleanup_unpin;
  8404. work->flip_queued_seqno = obj->last_write_seqno;
  8405. work->flip_queued_ring = obj->ring;
  8406. } else {
  8407. ret = dev_priv->display.queue_flip(dev, crtc, fb, obj, ring,
  8408. page_flip_flags);
  8409. if (ret)
  8410. goto cleanup_unpin;
  8411. work->flip_queued_seqno = intel_ring_get_seqno(ring);
  8412. work->flip_queued_ring = ring;
  8413. }
  8414. work->flip_queued_vblank = drm_vblank_count(dev, intel_crtc->pipe);
  8415. work->enable_stall_check = true;
  8416. i915_gem_track_fb(work->old_fb_obj, obj,
  8417. INTEL_FRONTBUFFER_PRIMARY(pipe));
  8418. intel_disable_fbc(dev);
  8419. intel_frontbuffer_flip_prepare(dev, INTEL_FRONTBUFFER_PRIMARY(pipe));
  8420. mutex_unlock(&dev->struct_mutex);
  8421. trace_i915_flip_request(intel_crtc->plane, obj);
  8422. return 0;
  8423. cleanup_unpin:
  8424. intel_unpin_fb_obj(obj);
  8425. cleanup_pending:
  8426. atomic_dec(&intel_crtc->unpin_work_count);
  8427. crtc->primary->fb = old_fb;
  8428. drm_gem_object_unreference(&work->old_fb_obj->base);
  8429. drm_gem_object_unreference(&obj->base);
  8430. mutex_unlock(&dev->struct_mutex);
  8431. cleanup:
  8432. spin_lock_irqsave(&dev->event_lock, flags);
  8433. intel_crtc->unpin_work = NULL;
  8434. spin_unlock_irqrestore(&dev->event_lock, flags);
  8435. drm_crtc_vblank_put(crtc);
  8436. free_work:
  8437. kfree(work);
  8438. if (ret == -EIO) {
  8439. out_hang:
  8440. intel_crtc_wait_for_pending_flips(crtc);
  8441. ret = intel_pipe_set_base(crtc, crtc->x, crtc->y, fb);
  8442. if (ret == 0 && event) {
  8443. spin_lock_irqsave(&dev->event_lock, flags);
  8444. drm_send_vblank_event(dev, pipe, event);
  8445. spin_unlock_irqrestore(&dev->event_lock, flags);
  8446. }
  8447. }
  8448. return ret;
  8449. }
  8450. static struct drm_crtc_helper_funcs intel_helper_funcs = {
  8451. .mode_set_base_atomic = intel_pipe_set_base_atomic,
  8452. .load_lut = intel_crtc_load_lut,
  8453. };
  8454. /**
  8455. * intel_modeset_update_staged_output_state
  8456. *
  8457. * Updates the staged output configuration state, e.g. after we've read out the
  8458. * current hw state.
  8459. */
  8460. static void intel_modeset_update_staged_output_state(struct drm_device *dev)
  8461. {
  8462. struct intel_crtc *crtc;
  8463. struct intel_encoder *encoder;
  8464. struct intel_connector *connector;
  8465. list_for_each_entry(connector, &dev->mode_config.connector_list,
  8466. base.head) {
  8467. connector->new_encoder =
  8468. to_intel_encoder(connector->base.encoder);
  8469. }
  8470. for_each_intel_encoder(dev, encoder) {
  8471. encoder->new_crtc =
  8472. to_intel_crtc(encoder->base.crtc);
  8473. }
  8474. for_each_intel_crtc(dev, crtc) {
  8475. crtc->new_enabled = crtc->base.enabled;
  8476. if (crtc->new_enabled)
  8477. crtc->new_config = &crtc->config;
  8478. else
  8479. crtc->new_config = NULL;
  8480. }
  8481. }
  8482. /**
  8483. * intel_modeset_commit_output_state
  8484. *
  8485. * This function copies the stage display pipe configuration to the real one.
  8486. */
  8487. static void intel_modeset_commit_output_state(struct drm_device *dev)
  8488. {
  8489. struct intel_crtc *crtc;
  8490. struct intel_encoder *encoder;
  8491. struct intel_connector *connector;
  8492. list_for_each_entry(connector, &dev->mode_config.connector_list,
  8493. base.head) {
  8494. connector->base.encoder = &connector->new_encoder->base;
  8495. }
  8496. for_each_intel_encoder(dev, encoder) {
  8497. encoder->base.crtc = &encoder->new_crtc->base;
  8498. }
  8499. for_each_intel_crtc(dev, crtc) {
  8500. crtc->base.enabled = crtc->new_enabled;
  8501. }
  8502. }
  8503. static void
  8504. connected_sink_compute_bpp(struct intel_connector *connector,
  8505. struct intel_crtc_config *pipe_config)
  8506. {
  8507. int bpp = pipe_config->pipe_bpp;
  8508. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n",
  8509. connector->base.base.id,
  8510. connector->base.name);
  8511. /* Don't use an invalid EDID bpc value */
  8512. if (connector->base.display_info.bpc &&
  8513. connector->base.display_info.bpc * 3 < bpp) {
  8514. DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n",
  8515. bpp, connector->base.display_info.bpc*3);
  8516. pipe_config->pipe_bpp = connector->base.display_info.bpc*3;
  8517. }
  8518. /* Clamp bpp to 8 on screens without EDID 1.4 */
  8519. if (connector->base.display_info.bpc == 0 && bpp > 24) {
  8520. DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n",
  8521. bpp);
  8522. pipe_config->pipe_bpp = 24;
  8523. }
  8524. }
  8525. static int
  8526. compute_baseline_pipe_bpp(struct intel_crtc *crtc,
  8527. struct drm_framebuffer *fb,
  8528. struct intel_crtc_config *pipe_config)
  8529. {
  8530. struct drm_device *dev = crtc->base.dev;
  8531. struct intel_connector *connector;
  8532. int bpp;
  8533. switch (fb->pixel_format) {
  8534. case DRM_FORMAT_C8:
  8535. bpp = 8*3; /* since we go through a colormap */
  8536. break;
  8537. case DRM_FORMAT_XRGB1555:
  8538. case DRM_FORMAT_ARGB1555:
  8539. /* checked in intel_framebuffer_init already */
  8540. if (WARN_ON(INTEL_INFO(dev)->gen > 3))
  8541. return -EINVAL;
  8542. case DRM_FORMAT_RGB565:
  8543. bpp = 6*3; /* min is 18bpp */
  8544. break;
  8545. case DRM_FORMAT_XBGR8888:
  8546. case DRM_FORMAT_ABGR8888:
  8547. /* checked in intel_framebuffer_init already */
  8548. if (WARN_ON(INTEL_INFO(dev)->gen < 4))
  8549. return -EINVAL;
  8550. case DRM_FORMAT_XRGB8888:
  8551. case DRM_FORMAT_ARGB8888:
  8552. bpp = 8*3;
  8553. break;
  8554. case DRM_FORMAT_XRGB2101010:
  8555. case DRM_FORMAT_ARGB2101010:
  8556. case DRM_FORMAT_XBGR2101010:
  8557. case DRM_FORMAT_ABGR2101010:
  8558. /* checked in intel_framebuffer_init already */
  8559. if (WARN_ON(INTEL_INFO(dev)->gen < 4))
  8560. return -EINVAL;
  8561. bpp = 10*3;
  8562. break;
  8563. /* TODO: gen4+ supports 16 bpc floating point, too. */
  8564. default:
  8565. DRM_DEBUG_KMS("unsupported depth\n");
  8566. return -EINVAL;
  8567. }
  8568. pipe_config->pipe_bpp = bpp;
  8569. /* Clamp display bpp to EDID value */
  8570. list_for_each_entry(connector, &dev->mode_config.connector_list,
  8571. base.head) {
  8572. if (!connector->new_encoder ||
  8573. connector->new_encoder->new_crtc != crtc)
  8574. continue;
  8575. connected_sink_compute_bpp(connector, pipe_config);
  8576. }
  8577. return bpp;
  8578. }
  8579. static void intel_dump_crtc_timings(const struct drm_display_mode *mode)
  8580. {
  8581. DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
  8582. "type: 0x%x flags: 0x%x\n",
  8583. mode->crtc_clock,
  8584. mode->crtc_hdisplay, mode->crtc_hsync_start,
  8585. mode->crtc_hsync_end, mode->crtc_htotal,
  8586. mode->crtc_vdisplay, mode->crtc_vsync_start,
  8587. mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags);
  8588. }
  8589. static void intel_dump_pipe_config(struct intel_crtc *crtc,
  8590. struct intel_crtc_config *pipe_config,
  8591. const char *context)
  8592. {
  8593. DRM_DEBUG_KMS("[CRTC:%d]%s config for pipe %c\n", crtc->base.base.id,
  8594. context, pipe_name(crtc->pipe));
  8595. DRM_DEBUG_KMS("cpu_transcoder: %c\n", transcoder_name(pipe_config->cpu_transcoder));
  8596. DRM_DEBUG_KMS("pipe bpp: %i, dithering: %i\n",
  8597. pipe_config->pipe_bpp, pipe_config->dither);
  8598. DRM_DEBUG_KMS("fdi/pch: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
  8599. pipe_config->has_pch_encoder,
  8600. pipe_config->fdi_lanes,
  8601. pipe_config->fdi_m_n.gmch_m, pipe_config->fdi_m_n.gmch_n,
  8602. pipe_config->fdi_m_n.link_m, pipe_config->fdi_m_n.link_n,
  8603. pipe_config->fdi_m_n.tu);
  8604. DRM_DEBUG_KMS("dp: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
  8605. pipe_config->has_dp_encoder,
  8606. pipe_config->dp_m_n.gmch_m, pipe_config->dp_m_n.gmch_n,
  8607. pipe_config->dp_m_n.link_m, pipe_config->dp_m_n.link_n,
  8608. pipe_config->dp_m_n.tu);
  8609. DRM_DEBUG_KMS("dp: %i, gmch_m2: %u, gmch_n2: %u, link_m2: %u, link_n2: %u, tu2: %u\n",
  8610. pipe_config->has_dp_encoder,
  8611. pipe_config->dp_m2_n2.gmch_m,
  8612. pipe_config->dp_m2_n2.gmch_n,
  8613. pipe_config->dp_m2_n2.link_m,
  8614. pipe_config->dp_m2_n2.link_n,
  8615. pipe_config->dp_m2_n2.tu);
  8616. DRM_DEBUG_KMS("requested mode:\n");
  8617. drm_mode_debug_printmodeline(&pipe_config->requested_mode);
  8618. DRM_DEBUG_KMS("adjusted mode:\n");
  8619. drm_mode_debug_printmodeline(&pipe_config->adjusted_mode);
  8620. intel_dump_crtc_timings(&pipe_config->adjusted_mode);
  8621. DRM_DEBUG_KMS("port clock: %d\n", pipe_config->port_clock);
  8622. DRM_DEBUG_KMS("pipe src size: %dx%d\n",
  8623. pipe_config->pipe_src_w, pipe_config->pipe_src_h);
  8624. DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
  8625. pipe_config->gmch_pfit.control,
  8626. pipe_config->gmch_pfit.pgm_ratios,
  8627. pipe_config->gmch_pfit.lvds_border_bits);
  8628. DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n",
  8629. pipe_config->pch_pfit.pos,
  8630. pipe_config->pch_pfit.size,
  8631. pipe_config->pch_pfit.enabled ? "enabled" : "disabled");
  8632. DRM_DEBUG_KMS("ips: %i\n", pipe_config->ips_enabled);
  8633. DRM_DEBUG_KMS("double wide: %i\n", pipe_config->double_wide);
  8634. }
  8635. static bool encoders_cloneable(const struct intel_encoder *a,
  8636. const struct intel_encoder *b)
  8637. {
  8638. /* masks could be asymmetric, so check both ways */
  8639. return a == b || (a->cloneable & (1 << b->type) &&
  8640. b->cloneable & (1 << a->type));
  8641. }
  8642. static bool check_single_encoder_cloning(struct intel_crtc *crtc,
  8643. struct intel_encoder *encoder)
  8644. {
  8645. struct drm_device *dev = crtc->base.dev;
  8646. struct intel_encoder *source_encoder;
  8647. for_each_intel_encoder(dev, source_encoder) {
  8648. if (source_encoder->new_crtc != crtc)
  8649. continue;
  8650. if (!encoders_cloneable(encoder, source_encoder))
  8651. return false;
  8652. }
  8653. return true;
  8654. }
  8655. static bool check_encoder_cloning(struct intel_crtc *crtc)
  8656. {
  8657. struct drm_device *dev = crtc->base.dev;
  8658. struct intel_encoder *encoder;
  8659. for_each_intel_encoder(dev, encoder) {
  8660. if (encoder->new_crtc != crtc)
  8661. continue;
  8662. if (!check_single_encoder_cloning(crtc, encoder))
  8663. return false;
  8664. }
  8665. return true;
  8666. }
  8667. static struct intel_crtc_config *
  8668. intel_modeset_pipe_config(struct drm_crtc *crtc,
  8669. struct drm_framebuffer *fb,
  8670. struct drm_display_mode *mode)
  8671. {
  8672. struct drm_device *dev = crtc->dev;
  8673. struct intel_encoder *encoder;
  8674. struct intel_crtc_config *pipe_config;
  8675. int plane_bpp, ret = -EINVAL;
  8676. bool retry = true;
  8677. if (!check_encoder_cloning(to_intel_crtc(crtc))) {
  8678. DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
  8679. return ERR_PTR(-EINVAL);
  8680. }
  8681. pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL);
  8682. if (!pipe_config)
  8683. return ERR_PTR(-ENOMEM);
  8684. drm_mode_copy(&pipe_config->adjusted_mode, mode);
  8685. drm_mode_copy(&pipe_config->requested_mode, mode);
  8686. pipe_config->cpu_transcoder =
  8687. (enum transcoder) to_intel_crtc(crtc)->pipe;
  8688. pipe_config->shared_dpll = DPLL_ID_PRIVATE;
  8689. /*
  8690. * Sanitize sync polarity flags based on requested ones. If neither
  8691. * positive or negative polarity is requested, treat this as meaning
  8692. * negative polarity.
  8693. */
  8694. if (!(pipe_config->adjusted_mode.flags &
  8695. (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC)))
  8696. pipe_config->adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC;
  8697. if (!(pipe_config->adjusted_mode.flags &
  8698. (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC)))
  8699. pipe_config->adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC;
  8700. /* Compute a starting value for pipe_config->pipe_bpp taking the source
  8701. * plane pixel format and any sink constraints into account. Returns the
  8702. * source plane bpp so that dithering can be selected on mismatches
  8703. * after encoders and crtc also have had their say. */
  8704. plane_bpp = compute_baseline_pipe_bpp(to_intel_crtc(crtc),
  8705. fb, pipe_config);
  8706. if (plane_bpp < 0)
  8707. goto fail;
  8708. /*
  8709. * Determine the real pipe dimensions. Note that stereo modes can
  8710. * increase the actual pipe size due to the frame doubling and
  8711. * insertion of additional space for blanks between the frame. This
  8712. * is stored in the crtc timings. We use the requested mode to do this
  8713. * computation to clearly distinguish it from the adjusted mode, which
  8714. * can be changed by the connectors in the below retry loop.
  8715. */
  8716. drm_mode_set_crtcinfo(&pipe_config->requested_mode, CRTC_STEREO_DOUBLE);
  8717. pipe_config->pipe_src_w = pipe_config->requested_mode.crtc_hdisplay;
  8718. pipe_config->pipe_src_h = pipe_config->requested_mode.crtc_vdisplay;
  8719. encoder_retry:
  8720. /* Ensure the port clock defaults are reset when retrying. */
  8721. pipe_config->port_clock = 0;
  8722. pipe_config->pixel_multiplier = 1;
  8723. /* Fill in default crtc timings, allow encoders to overwrite them. */
  8724. drm_mode_set_crtcinfo(&pipe_config->adjusted_mode, CRTC_STEREO_DOUBLE);
  8725. /* Pass our mode to the connectors and the CRTC to give them a chance to
  8726. * adjust it according to limitations or connector properties, and also
  8727. * a chance to reject the mode entirely.
  8728. */
  8729. for_each_intel_encoder(dev, encoder) {
  8730. if (&encoder->new_crtc->base != crtc)
  8731. continue;
  8732. if (!(encoder->compute_config(encoder, pipe_config))) {
  8733. DRM_DEBUG_KMS("Encoder config failure\n");
  8734. goto fail;
  8735. }
  8736. }
  8737. /* Set default port clock if not overwritten by the encoder. Needs to be
  8738. * done afterwards in case the encoder adjusts the mode. */
  8739. if (!pipe_config->port_clock)
  8740. pipe_config->port_clock = pipe_config->adjusted_mode.crtc_clock
  8741. * pipe_config->pixel_multiplier;
  8742. ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config);
  8743. if (ret < 0) {
  8744. DRM_DEBUG_KMS("CRTC fixup failed\n");
  8745. goto fail;
  8746. }
  8747. if (ret == RETRY) {
  8748. if (WARN(!retry, "loop in pipe configuration computation\n")) {
  8749. ret = -EINVAL;
  8750. goto fail;
  8751. }
  8752. DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
  8753. retry = false;
  8754. goto encoder_retry;
  8755. }
  8756. pipe_config->dither = pipe_config->pipe_bpp != plane_bpp;
  8757. DRM_DEBUG_KMS("plane bpp: %i, pipe bpp: %i, dithering: %i\n",
  8758. plane_bpp, pipe_config->pipe_bpp, pipe_config->dither);
  8759. return pipe_config;
  8760. fail:
  8761. kfree(pipe_config);
  8762. return ERR_PTR(ret);
  8763. }
  8764. /* Computes which crtcs are affected and sets the relevant bits in the mask. For
  8765. * simplicity we use the crtc's pipe number (because it's easier to obtain). */
  8766. static void
  8767. intel_modeset_affected_pipes(struct drm_crtc *crtc, unsigned *modeset_pipes,
  8768. unsigned *prepare_pipes, unsigned *disable_pipes)
  8769. {
  8770. struct intel_crtc *intel_crtc;
  8771. struct drm_device *dev = crtc->dev;
  8772. struct intel_encoder *encoder;
  8773. struct intel_connector *connector;
  8774. struct drm_crtc *tmp_crtc;
  8775. *disable_pipes = *modeset_pipes = *prepare_pipes = 0;
  8776. /* Check which crtcs have changed outputs connected to them, these need
  8777. * to be part of the prepare_pipes mask. We don't (yet) support global
  8778. * modeset across multiple crtcs, so modeset_pipes will only have one
  8779. * bit set at most. */
  8780. list_for_each_entry(connector, &dev->mode_config.connector_list,
  8781. base.head) {
  8782. if (connector->base.encoder == &connector->new_encoder->base)
  8783. continue;
  8784. if (connector->base.encoder) {
  8785. tmp_crtc = connector->base.encoder->crtc;
  8786. *prepare_pipes |= 1 << to_intel_crtc(tmp_crtc)->pipe;
  8787. }
  8788. if (connector->new_encoder)
  8789. *prepare_pipes |=
  8790. 1 << connector->new_encoder->new_crtc->pipe;
  8791. }
  8792. for_each_intel_encoder(dev, encoder) {
  8793. if (encoder->base.crtc == &encoder->new_crtc->base)
  8794. continue;
  8795. if (encoder->base.crtc) {
  8796. tmp_crtc = encoder->base.crtc;
  8797. *prepare_pipes |= 1 << to_intel_crtc(tmp_crtc)->pipe;
  8798. }
  8799. if (encoder->new_crtc)
  8800. *prepare_pipes |= 1 << encoder->new_crtc->pipe;
  8801. }
  8802. /* Check for pipes that will be enabled/disabled ... */
  8803. for_each_intel_crtc(dev, intel_crtc) {
  8804. if (intel_crtc->base.enabled == intel_crtc->new_enabled)
  8805. continue;
  8806. if (!intel_crtc->new_enabled)
  8807. *disable_pipes |= 1 << intel_crtc->pipe;
  8808. else
  8809. *prepare_pipes |= 1 << intel_crtc->pipe;
  8810. }
  8811. /* set_mode is also used to update properties on life display pipes. */
  8812. intel_crtc = to_intel_crtc(crtc);
  8813. if (intel_crtc->new_enabled)
  8814. *prepare_pipes |= 1 << intel_crtc->pipe;
  8815. /*
  8816. * For simplicity do a full modeset on any pipe where the output routing
  8817. * changed. We could be more clever, but that would require us to be
  8818. * more careful with calling the relevant encoder->mode_set functions.
  8819. */
  8820. if (*prepare_pipes)
  8821. *modeset_pipes = *prepare_pipes;
  8822. /* ... and mask these out. */
  8823. *modeset_pipes &= ~(*disable_pipes);
  8824. *prepare_pipes &= ~(*disable_pipes);
  8825. /*
  8826. * HACK: We don't (yet) fully support global modesets. intel_set_config
  8827. * obies this rule, but the modeset restore mode of
  8828. * intel_modeset_setup_hw_state does not.
  8829. */
  8830. *modeset_pipes &= 1 << intel_crtc->pipe;
  8831. *prepare_pipes &= 1 << intel_crtc->pipe;
  8832. DRM_DEBUG_KMS("set mode pipe masks: modeset: %x, prepare: %x, disable: %x\n",
  8833. *modeset_pipes, *prepare_pipes, *disable_pipes);
  8834. }
  8835. static bool intel_crtc_in_use(struct drm_crtc *crtc)
  8836. {
  8837. struct drm_encoder *encoder;
  8838. struct drm_device *dev = crtc->dev;
  8839. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head)
  8840. if (encoder->crtc == crtc)
  8841. return true;
  8842. return false;
  8843. }
  8844. static void
  8845. intel_modeset_update_state(struct drm_device *dev, unsigned prepare_pipes)
  8846. {
  8847. struct intel_encoder *intel_encoder;
  8848. struct intel_crtc *intel_crtc;
  8849. struct drm_connector *connector;
  8850. for_each_intel_encoder(dev, intel_encoder) {
  8851. if (!intel_encoder->base.crtc)
  8852. continue;
  8853. intel_crtc = to_intel_crtc(intel_encoder->base.crtc);
  8854. if (prepare_pipes & (1 << intel_crtc->pipe))
  8855. intel_encoder->connectors_active = false;
  8856. }
  8857. intel_modeset_commit_output_state(dev);
  8858. /* Double check state. */
  8859. for_each_intel_crtc(dev, intel_crtc) {
  8860. WARN_ON(intel_crtc->base.enabled != intel_crtc_in_use(&intel_crtc->base));
  8861. WARN_ON(intel_crtc->new_config &&
  8862. intel_crtc->new_config != &intel_crtc->config);
  8863. WARN_ON(intel_crtc->base.enabled != !!intel_crtc->new_config);
  8864. }
  8865. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  8866. if (!connector->encoder || !connector->encoder->crtc)
  8867. continue;
  8868. intel_crtc = to_intel_crtc(connector->encoder->crtc);
  8869. if (prepare_pipes & (1 << intel_crtc->pipe)) {
  8870. struct drm_property *dpms_property =
  8871. dev->mode_config.dpms_property;
  8872. connector->dpms = DRM_MODE_DPMS_ON;
  8873. drm_object_property_set_value(&connector->base,
  8874. dpms_property,
  8875. DRM_MODE_DPMS_ON);
  8876. intel_encoder = to_intel_encoder(connector->encoder);
  8877. intel_encoder->connectors_active = true;
  8878. }
  8879. }
  8880. }
  8881. static bool intel_fuzzy_clock_check(int clock1, int clock2)
  8882. {
  8883. int diff;
  8884. if (clock1 == clock2)
  8885. return true;
  8886. if (!clock1 || !clock2)
  8887. return false;
  8888. diff = abs(clock1 - clock2);
  8889. if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105)
  8890. return true;
  8891. return false;
  8892. }
  8893. #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \
  8894. list_for_each_entry((intel_crtc), \
  8895. &(dev)->mode_config.crtc_list, \
  8896. base.head) \
  8897. if (mask & (1 <<(intel_crtc)->pipe))
  8898. static bool
  8899. intel_pipe_config_compare(struct drm_device *dev,
  8900. struct intel_crtc_config *current_config,
  8901. struct intel_crtc_config *pipe_config)
  8902. {
  8903. #define PIPE_CONF_CHECK_X(name) \
  8904. if (current_config->name != pipe_config->name) { \
  8905. DRM_ERROR("mismatch in " #name " " \
  8906. "(expected 0x%08x, found 0x%08x)\n", \
  8907. current_config->name, \
  8908. pipe_config->name); \
  8909. return false; \
  8910. }
  8911. #define PIPE_CONF_CHECK_I(name) \
  8912. if (current_config->name != pipe_config->name) { \
  8913. DRM_ERROR("mismatch in " #name " " \
  8914. "(expected %i, found %i)\n", \
  8915. current_config->name, \
  8916. pipe_config->name); \
  8917. return false; \
  8918. }
  8919. /* This is required for BDW+ where there is only one set of registers for
  8920. * switching between high and low RR.
  8921. * This macro can be used whenever a comparison has to be made between one
  8922. * hw state and multiple sw state variables.
  8923. */
  8924. #define PIPE_CONF_CHECK_I_ALT(name, alt_name) \
  8925. if ((current_config->name != pipe_config->name) && \
  8926. (current_config->alt_name != pipe_config->name)) { \
  8927. DRM_ERROR("mismatch in " #name " " \
  8928. "(expected %i or %i, found %i)\n", \
  8929. current_config->name, \
  8930. current_config->alt_name, \
  8931. pipe_config->name); \
  8932. return false; \
  8933. }
  8934. #define PIPE_CONF_CHECK_FLAGS(name, mask) \
  8935. if ((current_config->name ^ pipe_config->name) & (mask)) { \
  8936. DRM_ERROR("mismatch in " #name "(" #mask ") " \
  8937. "(expected %i, found %i)\n", \
  8938. current_config->name & (mask), \
  8939. pipe_config->name & (mask)); \
  8940. return false; \
  8941. }
  8942. #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \
  8943. if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
  8944. DRM_ERROR("mismatch in " #name " " \
  8945. "(expected %i, found %i)\n", \
  8946. current_config->name, \
  8947. pipe_config->name); \
  8948. return false; \
  8949. }
  8950. #define PIPE_CONF_QUIRK(quirk) \
  8951. ((current_config->quirks | pipe_config->quirks) & (quirk))
  8952. PIPE_CONF_CHECK_I(cpu_transcoder);
  8953. PIPE_CONF_CHECK_I(has_pch_encoder);
  8954. PIPE_CONF_CHECK_I(fdi_lanes);
  8955. PIPE_CONF_CHECK_I(fdi_m_n.gmch_m);
  8956. PIPE_CONF_CHECK_I(fdi_m_n.gmch_n);
  8957. PIPE_CONF_CHECK_I(fdi_m_n.link_m);
  8958. PIPE_CONF_CHECK_I(fdi_m_n.link_n);
  8959. PIPE_CONF_CHECK_I(fdi_m_n.tu);
  8960. PIPE_CONF_CHECK_I(has_dp_encoder);
  8961. if (INTEL_INFO(dev)->gen < 8) {
  8962. PIPE_CONF_CHECK_I(dp_m_n.gmch_m);
  8963. PIPE_CONF_CHECK_I(dp_m_n.gmch_n);
  8964. PIPE_CONF_CHECK_I(dp_m_n.link_m);
  8965. PIPE_CONF_CHECK_I(dp_m_n.link_n);
  8966. PIPE_CONF_CHECK_I(dp_m_n.tu);
  8967. if (current_config->has_drrs) {
  8968. PIPE_CONF_CHECK_I(dp_m2_n2.gmch_m);
  8969. PIPE_CONF_CHECK_I(dp_m2_n2.gmch_n);
  8970. PIPE_CONF_CHECK_I(dp_m2_n2.link_m);
  8971. PIPE_CONF_CHECK_I(dp_m2_n2.link_n);
  8972. PIPE_CONF_CHECK_I(dp_m2_n2.tu);
  8973. }
  8974. } else {
  8975. PIPE_CONF_CHECK_I_ALT(dp_m_n.gmch_m, dp_m2_n2.gmch_m);
  8976. PIPE_CONF_CHECK_I_ALT(dp_m_n.gmch_n, dp_m2_n2.gmch_n);
  8977. PIPE_CONF_CHECK_I_ALT(dp_m_n.link_m, dp_m2_n2.link_m);
  8978. PIPE_CONF_CHECK_I_ALT(dp_m_n.link_n, dp_m2_n2.link_n);
  8979. PIPE_CONF_CHECK_I_ALT(dp_m_n.tu, dp_m2_n2.tu);
  8980. }
  8981. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hdisplay);
  8982. PIPE_CONF_CHECK_I(adjusted_mode.crtc_htotal);
  8983. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hblank_start);
  8984. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hblank_end);
  8985. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hsync_start);
  8986. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hsync_end);
  8987. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vdisplay);
  8988. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vtotal);
  8989. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vblank_start);
  8990. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vblank_end);
  8991. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vsync_start);
  8992. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vsync_end);
  8993. PIPE_CONF_CHECK_I(pixel_multiplier);
  8994. PIPE_CONF_CHECK_I(has_hdmi_sink);
  8995. if ((INTEL_INFO(dev)->gen < 8 && !IS_HASWELL(dev)) ||
  8996. IS_VALLEYVIEW(dev))
  8997. PIPE_CONF_CHECK_I(limited_color_range);
  8998. PIPE_CONF_CHECK_I(has_audio);
  8999. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  9000. DRM_MODE_FLAG_INTERLACE);
  9001. if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) {
  9002. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  9003. DRM_MODE_FLAG_PHSYNC);
  9004. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  9005. DRM_MODE_FLAG_NHSYNC);
  9006. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  9007. DRM_MODE_FLAG_PVSYNC);
  9008. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  9009. DRM_MODE_FLAG_NVSYNC);
  9010. }
  9011. PIPE_CONF_CHECK_I(pipe_src_w);
  9012. PIPE_CONF_CHECK_I(pipe_src_h);
  9013. /*
  9014. * FIXME: BIOS likes to set up a cloned config with lvds+external
  9015. * screen. Since we don't yet re-compute the pipe config when moving
  9016. * just the lvds port away to another pipe the sw tracking won't match.
  9017. *
  9018. * Proper atomic modesets with recomputed global state will fix this.
  9019. * Until then just don't check gmch state for inherited modes.
  9020. */
  9021. if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_INHERITED_MODE)) {
  9022. PIPE_CONF_CHECK_I(gmch_pfit.control);
  9023. /* pfit ratios are autocomputed by the hw on gen4+ */
  9024. if (INTEL_INFO(dev)->gen < 4)
  9025. PIPE_CONF_CHECK_I(gmch_pfit.pgm_ratios);
  9026. PIPE_CONF_CHECK_I(gmch_pfit.lvds_border_bits);
  9027. }
  9028. PIPE_CONF_CHECK_I(pch_pfit.enabled);
  9029. if (current_config->pch_pfit.enabled) {
  9030. PIPE_CONF_CHECK_I(pch_pfit.pos);
  9031. PIPE_CONF_CHECK_I(pch_pfit.size);
  9032. }
  9033. /* BDW+ don't expose a synchronous way to read the state */
  9034. if (IS_HASWELL(dev))
  9035. PIPE_CONF_CHECK_I(ips_enabled);
  9036. PIPE_CONF_CHECK_I(double_wide);
  9037. PIPE_CONF_CHECK_X(ddi_pll_sel);
  9038. PIPE_CONF_CHECK_I(shared_dpll);
  9039. PIPE_CONF_CHECK_X(dpll_hw_state.dpll);
  9040. PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md);
  9041. PIPE_CONF_CHECK_X(dpll_hw_state.fp0);
  9042. PIPE_CONF_CHECK_X(dpll_hw_state.fp1);
  9043. PIPE_CONF_CHECK_X(dpll_hw_state.wrpll);
  9044. if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5)
  9045. PIPE_CONF_CHECK_I(pipe_bpp);
  9046. PIPE_CONF_CHECK_CLOCK_FUZZY(adjusted_mode.crtc_clock);
  9047. PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock);
  9048. #undef PIPE_CONF_CHECK_X
  9049. #undef PIPE_CONF_CHECK_I
  9050. #undef PIPE_CONF_CHECK_I_ALT
  9051. #undef PIPE_CONF_CHECK_FLAGS
  9052. #undef PIPE_CONF_CHECK_CLOCK_FUZZY
  9053. #undef PIPE_CONF_QUIRK
  9054. return true;
  9055. }
  9056. static void
  9057. check_connector_state(struct drm_device *dev)
  9058. {
  9059. struct intel_connector *connector;
  9060. list_for_each_entry(connector, &dev->mode_config.connector_list,
  9061. base.head) {
  9062. /* This also checks the encoder/connector hw state with the
  9063. * ->get_hw_state callbacks. */
  9064. intel_connector_check_state(connector);
  9065. WARN(&connector->new_encoder->base != connector->base.encoder,
  9066. "connector's staged encoder doesn't match current encoder\n");
  9067. }
  9068. }
  9069. static void
  9070. check_encoder_state(struct drm_device *dev)
  9071. {
  9072. struct intel_encoder *encoder;
  9073. struct intel_connector *connector;
  9074. for_each_intel_encoder(dev, encoder) {
  9075. bool enabled = false;
  9076. bool active = false;
  9077. enum pipe pipe, tracked_pipe;
  9078. DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
  9079. encoder->base.base.id,
  9080. encoder->base.name);
  9081. WARN(&encoder->new_crtc->base != encoder->base.crtc,
  9082. "encoder's stage crtc doesn't match current crtc\n");
  9083. WARN(encoder->connectors_active && !encoder->base.crtc,
  9084. "encoder's active_connectors set, but no crtc\n");
  9085. list_for_each_entry(connector, &dev->mode_config.connector_list,
  9086. base.head) {
  9087. if (connector->base.encoder != &encoder->base)
  9088. continue;
  9089. enabled = true;
  9090. if (connector->base.dpms != DRM_MODE_DPMS_OFF)
  9091. active = true;
  9092. }
  9093. /*
  9094. * for MST connectors if we unplug the connector is gone
  9095. * away but the encoder is still connected to a crtc
  9096. * until a modeset happens in response to the hotplug.
  9097. */
  9098. if (!enabled && encoder->base.encoder_type == DRM_MODE_ENCODER_DPMST)
  9099. continue;
  9100. WARN(!!encoder->base.crtc != enabled,
  9101. "encoder's enabled state mismatch "
  9102. "(expected %i, found %i)\n",
  9103. !!encoder->base.crtc, enabled);
  9104. WARN(active && !encoder->base.crtc,
  9105. "active encoder with no crtc\n");
  9106. WARN(encoder->connectors_active != active,
  9107. "encoder's computed active state doesn't match tracked active state "
  9108. "(expected %i, found %i)\n", active, encoder->connectors_active);
  9109. active = encoder->get_hw_state(encoder, &pipe);
  9110. WARN(active != encoder->connectors_active,
  9111. "encoder's hw state doesn't match sw tracking "
  9112. "(expected %i, found %i)\n",
  9113. encoder->connectors_active, active);
  9114. if (!encoder->base.crtc)
  9115. continue;
  9116. tracked_pipe = to_intel_crtc(encoder->base.crtc)->pipe;
  9117. WARN(active && pipe != tracked_pipe,
  9118. "active encoder's pipe doesn't match"
  9119. "(expected %i, found %i)\n",
  9120. tracked_pipe, pipe);
  9121. }
  9122. }
  9123. static void
  9124. check_crtc_state(struct drm_device *dev)
  9125. {
  9126. struct drm_i915_private *dev_priv = dev->dev_private;
  9127. struct intel_crtc *crtc;
  9128. struct intel_encoder *encoder;
  9129. struct intel_crtc_config pipe_config;
  9130. for_each_intel_crtc(dev, crtc) {
  9131. bool enabled = false;
  9132. bool active = false;
  9133. memset(&pipe_config, 0, sizeof(pipe_config));
  9134. DRM_DEBUG_KMS("[CRTC:%d]\n",
  9135. crtc->base.base.id);
  9136. WARN(crtc->active && !crtc->base.enabled,
  9137. "active crtc, but not enabled in sw tracking\n");
  9138. for_each_intel_encoder(dev, encoder) {
  9139. if (encoder->base.crtc != &crtc->base)
  9140. continue;
  9141. enabled = true;
  9142. if (encoder->connectors_active)
  9143. active = true;
  9144. }
  9145. WARN(active != crtc->active,
  9146. "crtc's computed active state doesn't match tracked active state "
  9147. "(expected %i, found %i)\n", active, crtc->active);
  9148. WARN(enabled != crtc->base.enabled,
  9149. "crtc's computed enabled state doesn't match tracked enabled state "
  9150. "(expected %i, found %i)\n", enabled, crtc->base.enabled);
  9151. active = dev_priv->display.get_pipe_config(crtc,
  9152. &pipe_config);
  9153. /* hw state is inconsistent with the pipe quirk */
  9154. if ((crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) ||
  9155. (crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))
  9156. active = crtc->active;
  9157. for_each_intel_encoder(dev, encoder) {
  9158. enum pipe pipe;
  9159. if (encoder->base.crtc != &crtc->base)
  9160. continue;
  9161. if (encoder->get_hw_state(encoder, &pipe))
  9162. encoder->get_config(encoder, &pipe_config);
  9163. }
  9164. WARN(crtc->active != active,
  9165. "crtc active state doesn't match with hw state "
  9166. "(expected %i, found %i)\n", crtc->active, active);
  9167. if (active &&
  9168. !intel_pipe_config_compare(dev, &crtc->config, &pipe_config)) {
  9169. WARN(1, "pipe state doesn't match!\n");
  9170. intel_dump_pipe_config(crtc, &pipe_config,
  9171. "[hw state]");
  9172. intel_dump_pipe_config(crtc, &crtc->config,
  9173. "[sw state]");
  9174. }
  9175. }
  9176. }
  9177. static void
  9178. check_shared_dpll_state(struct drm_device *dev)
  9179. {
  9180. struct drm_i915_private *dev_priv = dev->dev_private;
  9181. struct intel_crtc *crtc;
  9182. struct intel_dpll_hw_state dpll_hw_state;
  9183. int i;
  9184. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  9185. struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
  9186. int enabled_crtcs = 0, active_crtcs = 0;
  9187. bool active;
  9188. memset(&dpll_hw_state, 0, sizeof(dpll_hw_state));
  9189. DRM_DEBUG_KMS("%s\n", pll->name);
  9190. active = pll->get_hw_state(dev_priv, pll, &dpll_hw_state);
  9191. WARN(pll->active > pll->refcount,
  9192. "more active pll users than references: %i vs %i\n",
  9193. pll->active, pll->refcount);
  9194. WARN(pll->active && !pll->on,
  9195. "pll in active use but not on in sw tracking\n");
  9196. WARN(pll->on && !pll->active,
  9197. "pll in on but not on in use in sw tracking\n");
  9198. WARN(pll->on != active,
  9199. "pll on state mismatch (expected %i, found %i)\n",
  9200. pll->on, active);
  9201. for_each_intel_crtc(dev, crtc) {
  9202. if (crtc->base.enabled && intel_crtc_to_shared_dpll(crtc) == pll)
  9203. enabled_crtcs++;
  9204. if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll)
  9205. active_crtcs++;
  9206. }
  9207. WARN(pll->active != active_crtcs,
  9208. "pll active crtcs mismatch (expected %i, found %i)\n",
  9209. pll->active, active_crtcs);
  9210. WARN(pll->refcount != enabled_crtcs,
  9211. "pll enabled crtcs mismatch (expected %i, found %i)\n",
  9212. pll->refcount, enabled_crtcs);
  9213. WARN(pll->on && memcmp(&pll->hw_state, &dpll_hw_state,
  9214. sizeof(dpll_hw_state)),
  9215. "pll hw state mismatch\n");
  9216. }
  9217. }
  9218. void
  9219. intel_modeset_check_state(struct drm_device *dev)
  9220. {
  9221. check_connector_state(dev);
  9222. check_encoder_state(dev);
  9223. check_crtc_state(dev);
  9224. check_shared_dpll_state(dev);
  9225. }
  9226. void ironlake_check_encoder_dotclock(const struct intel_crtc_config *pipe_config,
  9227. int dotclock)
  9228. {
  9229. /*
  9230. * FDI already provided one idea for the dotclock.
  9231. * Yell if the encoder disagrees.
  9232. */
  9233. WARN(!intel_fuzzy_clock_check(pipe_config->adjusted_mode.crtc_clock, dotclock),
  9234. "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
  9235. pipe_config->adjusted_mode.crtc_clock, dotclock);
  9236. }
  9237. static void update_scanline_offset(struct intel_crtc *crtc)
  9238. {
  9239. struct drm_device *dev = crtc->base.dev;
  9240. /*
  9241. * The scanline counter increments at the leading edge of hsync.
  9242. *
  9243. * On most platforms it starts counting from vtotal-1 on the
  9244. * first active line. That means the scanline counter value is
  9245. * always one less than what we would expect. Ie. just after
  9246. * start of vblank, which also occurs at start of hsync (on the
  9247. * last active line), the scanline counter will read vblank_start-1.
  9248. *
  9249. * On gen2 the scanline counter starts counting from 1 instead
  9250. * of vtotal-1, so we have to subtract one (or rather add vtotal-1
  9251. * to keep the value positive), instead of adding one.
  9252. *
  9253. * On HSW+ the behaviour of the scanline counter depends on the output
  9254. * type. For DP ports it behaves like most other platforms, but on HDMI
  9255. * there's an extra 1 line difference. So we need to add two instead of
  9256. * one to the value.
  9257. */
  9258. if (IS_GEN2(dev)) {
  9259. const struct drm_display_mode *mode = &crtc->config.adjusted_mode;
  9260. int vtotal;
  9261. vtotal = mode->crtc_vtotal;
  9262. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  9263. vtotal /= 2;
  9264. crtc->scanline_offset = vtotal - 1;
  9265. } else if (HAS_DDI(dev) &&
  9266. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_HDMI)) {
  9267. crtc->scanline_offset = 2;
  9268. } else
  9269. crtc->scanline_offset = 1;
  9270. }
  9271. static int __intel_set_mode(struct drm_crtc *crtc,
  9272. struct drm_display_mode *mode,
  9273. int x, int y, struct drm_framebuffer *fb)
  9274. {
  9275. struct drm_device *dev = crtc->dev;
  9276. struct drm_i915_private *dev_priv = dev->dev_private;
  9277. struct drm_display_mode *saved_mode;
  9278. struct intel_crtc_config *pipe_config = NULL;
  9279. struct intel_crtc *intel_crtc;
  9280. unsigned disable_pipes, prepare_pipes, modeset_pipes;
  9281. int ret = 0;
  9282. saved_mode = kmalloc(sizeof(*saved_mode), GFP_KERNEL);
  9283. if (!saved_mode)
  9284. return -ENOMEM;
  9285. intel_modeset_affected_pipes(crtc, &modeset_pipes,
  9286. &prepare_pipes, &disable_pipes);
  9287. *saved_mode = crtc->mode;
  9288. /* Hack: Because we don't (yet) support global modeset on multiple
  9289. * crtcs, we don't keep track of the new mode for more than one crtc.
  9290. * Hence simply check whether any bit is set in modeset_pipes in all the
  9291. * pieces of code that are not yet converted to deal with mutliple crtcs
  9292. * changing their mode at the same time. */
  9293. if (modeset_pipes) {
  9294. pipe_config = intel_modeset_pipe_config(crtc, fb, mode);
  9295. if (IS_ERR(pipe_config)) {
  9296. ret = PTR_ERR(pipe_config);
  9297. pipe_config = NULL;
  9298. goto out;
  9299. }
  9300. intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config,
  9301. "[modeset]");
  9302. to_intel_crtc(crtc)->new_config = pipe_config;
  9303. }
  9304. /*
  9305. * See if the config requires any additional preparation, e.g.
  9306. * to adjust global state with pipes off. We need to do this
  9307. * here so we can get the modeset_pipe updated config for the new
  9308. * mode set on this crtc. For other crtcs we need to use the
  9309. * adjusted_mode bits in the crtc directly.
  9310. */
  9311. if (IS_VALLEYVIEW(dev)) {
  9312. valleyview_modeset_global_pipes(dev, &prepare_pipes);
  9313. /* may have added more to prepare_pipes than we should */
  9314. prepare_pipes &= ~disable_pipes;
  9315. }
  9316. for_each_intel_crtc_masked(dev, disable_pipes, intel_crtc)
  9317. intel_crtc_disable(&intel_crtc->base);
  9318. for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc) {
  9319. if (intel_crtc->base.enabled)
  9320. dev_priv->display.crtc_disable(&intel_crtc->base);
  9321. }
  9322. /* crtc->mode is already used by the ->mode_set callbacks, hence we need
  9323. * to set it here already despite that we pass it down the callchain.
  9324. */
  9325. if (modeset_pipes) {
  9326. crtc->mode = *mode;
  9327. /* mode_set/enable/disable functions rely on a correct pipe
  9328. * config. */
  9329. to_intel_crtc(crtc)->config = *pipe_config;
  9330. to_intel_crtc(crtc)->new_config = &to_intel_crtc(crtc)->config;
  9331. /*
  9332. * Calculate and store various constants which
  9333. * are later needed by vblank and swap-completion
  9334. * timestamping. They are derived from true hwmode.
  9335. */
  9336. drm_calc_timestamping_constants(crtc,
  9337. &pipe_config->adjusted_mode);
  9338. }
  9339. /* Only after disabling all output pipelines that will be changed can we
  9340. * update the the output configuration. */
  9341. intel_modeset_update_state(dev, prepare_pipes);
  9342. if (dev_priv->display.modeset_global_resources)
  9343. dev_priv->display.modeset_global_resources(dev);
  9344. /* Set up the DPLL and any encoders state that needs to adjust or depend
  9345. * on the DPLL.
  9346. */
  9347. for_each_intel_crtc_masked(dev, modeset_pipes, intel_crtc) {
  9348. struct drm_framebuffer *old_fb = crtc->primary->fb;
  9349. struct drm_i915_gem_object *old_obj = intel_fb_obj(old_fb);
  9350. struct drm_i915_gem_object *obj = intel_fb_obj(fb);
  9351. mutex_lock(&dev->struct_mutex);
  9352. ret = intel_pin_and_fence_fb_obj(dev,
  9353. obj,
  9354. NULL);
  9355. if (ret != 0) {
  9356. DRM_ERROR("pin & fence failed\n");
  9357. mutex_unlock(&dev->struct_mutex);
  9358. goto done;
  9359. }
  9360. if (old_fb)
  9361. intel_unpin_fb_obj(old_obj);
  9362. i915_gem_track_fb(old_obj, obj,
  9363. INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe));
  9364. mutex_unlock(&dev->struct_mutex);
  9365. crtc->primary->fb = fb;
  9366. crtc->x = x;
  9367. crtc->y = y;
  9368. ret = dev_priv->display.crtc_mode_set(&intel_crtc->base,
  9369. x, y, fb);
  9370. if (ret)
  9371. goto done;
  9372. }
  9373. /* Now enable the clocks, plane, pipe, and connectors that we set up. */
  9374. for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc) {
  9375. update_scanline_offset(intel_crtc);
  9376. dev_priv->display.crtc_enable(&intel_crtc->base);
  9377. }
  9378. /* FIXME: add subpixel order */
  9379. done:
  9380. if (ret && crtc->enabled)
  9381. crtc->mode = *saved_mode;
  9382. out:
  9383. kfree(pipe_config);
  9384. kfree(saved_mode);
  9385. return ret;
  9386. }
  9387. static int intel_set_mode(struct drm_crtc *crtc,
  9388. struct drm_display_mode *mode,
  9389. int x, int y, struct drm_framebuffer *fb)
  9390. {
  9391. int ret;
  9392. ret = __intel_set_mode(crtc, mode, x, y, fb);
  9393. if (ret == 0)
  9394. intel_modeset_check_state(crtc->dev);
  9395. return ret;
  9396. }
  9397. void intel_crtc_restore_mode(struct drm_crtc *crtc)
  9398. {
  9399. intel_set_mode(crtc, &crtc->mode, crtc->x, crtc->y, crtc->primary->fb);
  9400. }
  9401. #undef for_each_intel_crtc_masked
  9402. static void intel_set_config_free(struct intel_set_config *config)
  9403. {
  9404. if (!config)
  9405. return;
  9406. kfree(config->save_connector_encoders);
  9407. kfree(config->save_encoder_crtcs);
  9408. kfree(config->save_crtc_enabled);
  9409. kfree(config);
  9410. }
  9411. static int intel_set_config_save_state(struct drm_device *dev,
  9412. struct intel_set_config *config)
  9413. {
  9414. struct drm_crtc *crtc;
  9415. struct drm_encoder *encoder;
  9416. struct drm_connector *connector;
  9417. int count;
  9418. config->save_crtc_enabled =
  9419. kcalloc(dev->mode_config.num_crtc,
  9420. sizeof(bool), GFP_KERNEL);
  9421. if (!config->save_crtc_enabled)
  9422. return -ENOMEM;
  9423. config->save_encoder_crtcs =
  9424. kcalloc(dev->mode_config.num_encoder,
  9425. sizeof(struct drm_crtc *), GFP_KERNEL);
  9426. if (!config->save_encoder_crtcs)
  9427. return -ENOMEM;
  9428. config->save_connector_encoders =
  9429. kcalloc(dev->mode_config.num_connector,
  9430. sizeof(struct drm_encoder *), GFP_KERNEL);
  9431. if (!config->save_connector_encoders)
  9432. return -ENOMEM;
  9433. /* Copy data. Note that driver private data is not affected.
  9434. * Should anything bad happen only the expected state is
  9435. * restored, not the drivers personal bookkeeping.
  9436. */
  9437. count = 0;
  9438. for_each_crtc(dev, crtc) {
  9439. config->save_crtc_enabled[count++] = crtc->enabled;
  9440. }
  9441. count = 0;
  9442. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  9443. config->save_encoder_crtcs[count++] = encoder->crtc;
  9444. }
  9445. count = 0;
  9446. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  9447. config->save_connector_encoders[count++] = connector->encoder;
  9448. }
  9449. return 0;
  9450. }
  9451. static void intel_set_config_restore_state(struct drm_device *dev,
  9452. struct intel_set_config *config)
  9453. {
  9454. struct intel_crtc *crtc;
  9455. struct intel_encoder *encoder;
  9456. struct intel_connector *connector;
  9457. int count;
  9458. count = 0;
  9459. for_each_intel_crtc(dev, crtc) {
  9460. crtc->new_enabled = config->save_crtc_enabled[count++];
  9461. if (crtc->new_enabled)
  9462. crtc->new_config = &crtc->config;
  9463. else
  9464. crtc->new_config = NULL;
  9465. }
  9466. count = 0;
  9467. for_each_intel_encoder(dev, encoder) {
  9468. encoder->new_crtc =
  9469. to_intel_crtc(config->save_encoder_crtcs[count++]);
  9470. }
  9471. count = 0;
  9472. list_for_each_entry(connector, &dev->mode_config.connector_list, base.head) {
  9473. connector->new_encoder =
  9474. to_intel_encoder(config->save_connector_encoders[count++]);
  9475. }
  9476. }
  9477. static bool
  9478. is_crtc_connector_off(struct drm_mode_set *set)
  9479. {
  9480. int i;
  9481. if (set->num_connectors == 0)
  9482. return false;
  9483. if (WARN_ON(set->connectors == NULL))
  9484. return false;
  9485. for (i = 0; i < set->num_connectors; i++)
  9486. if (set->connectors[i]->encoder &&
  9487. set->connectors[i]->encoder->crtc == set->crtc &&
  9488. set->connectors[i]->dpms != DRM_MODE_DPMS_ON)
  9489. return true;
  9490. return false;
  9491. }
  9492. static void
  9493. intel_set_config_compute_mode_changes(struct drm_mode_set *set,
  9494. struct intel_set_config *config)
  9495. {
  9496. /* We should be able to check here if the fb has the same properties
  9497. * and then just flip_or_move it */
  9498. if (is_crtc_connector_off(set)) {
  9499. config->mode_changed = true;
  9500. } else if (set->crtc->primary->fb != set->fb) {
  9501. /*
  9502. * If we have no fb, we can only flip as long as the crtc is
  9503. * active, otherwise we need a full mode set. The crtc may
  9504. * be active if we've only disabled the primary plane, or
  9505. * in fastboot situations.
  9506. */
  9507. if (set->crtc->primary->fb == NULL) {
  9508. struct intel_crtc *intel_crtc =
  9509. to_intel_crtc(set->crtc);
  9510. if (intel_crtc->active) {
  9511. DRM_DEBUG_KMS("crtc has no fb, will flip\n");
  9512. config->fb_changed = true;
  9513. } else {
  9514. DRM_DEBUG_KMS("inactive crtc, full mode set\n");
  9515. config->mode_changed = true;
  9516. }
  9517. } else if (set->fb == NULL) {
  9518. config->mode_changed = true;
  9519. } else if (set->fb->pixel_format !=
  9520. set->crtc->primary->fb->pixel_format) {
  9521. config->mode_changed = true;
  9522. } else {
  9523. config->fb_changed = true;
  9524. }
  9525. }
  9526. if (set->fb && (set->x != set->crtc->x || set->y != set->crtc->y))
  9527. config->fb_changed = true;
  9528. if (set->mode && !drm_mode_equal(set->mode, &set->crtc->mode)) {
  9529. DRM_DEBUG_KMS("modes are different, full mode set\n");
  9530. drm_mode_debug_printmodeline(&set->crtc->mode);
  9531. drm_mode_debug_printmodeline(set->mode);
  9532. config->mode_changed = true;
  9533. }
  9534. DRM_DEBUG_KMS("computed changes for [CRTC:%d], mode_changed=%d, fb_changed=%d\n",
  9535. set->crtc->base.id, config->mode_changed, config->fb_changed);
  9536. }
  9537. static int
  9538. intel_modeset_stage_output_state(struct drm_device *dev,
  9539. struct drm_mode_set *set,
  9540. struct intel_set_config *config)
  9541. {
  9542. struct intel_connector *connector;
  9543. struct intel_encoder *encoder;
  9544. struct intel_crtc *crtc;
  9545. int ro;
  9546. /* The upper layers ensure that we either disable a crtc or have a list
  9547. * of connectors. For paranoia, double-check this. */
  9548. WARN_ON(!set->fb && (set->num_connectors != 0));
  9549. WARN_ON(set->fb && (set->num_connectors == 0));
  9550. list_for_each_entry(connector, &dev->mode_config.connector_list,
  9551. base.head) {
  9552. /* Otherwise traverse passed in connector list and get encoders
  9553. * for them. */
  9554. for (ro = 0; ro < set->num_connectors; ro++) {
  9555. if (set->connectors[ro] == &connector->base) {
  9556. connector->new_encoder = intel_find_encoder(connector, to_intel_crtc(set->crtc)->pipe);
  9557. break;
  9558. }
  9559. }
  9560. /* If we disable the crtc, disable all its connectors. Also, if
  9561. * the connector is on the changing crtc but not on the new
  9562. * connector list, disable it. */
  9563. if ((!set->fb || ro == set->num_connectors) &&
  9564. connector->base.encoder &&
  9565. connector->base.encoder->crtc == set->crtc) {
  9566. connector->new_encoder = NULL;
  9567. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n",
  9568. connector->base.base.id,
  9569. connector->base.name);
  9570. }
  9571. if (&connector->new_encoder->base != connector->base.encoder) {
  9572. DRM_DEBUG_KMS("encoder changed, full mode switch\n");
  9573. config->mode_changed = true;
  9574. }
  9575. }
  9576. /* connector->new_encoder is now updated for all connectors. */
  9577. /* Update crtc of enabled connectors. */
  9578. list_for_each_entry(connector, &dev->mode_config.connector_list,
  9579. base.head) {
  9580. struct drm_crtc *new_crtc;
  9581. if (!connector->new_encoder)
  9582. continue;
  9583. new_crtc = connector->new_encoder->base.crtc;
  9584. for (ro = 0; ro < set->num_connectors; ro++) {
  9585. if (set->connectors[ro] == &connector->base)
  9586. new_crtc = set->crtc;
  9587. }
  9588. /* Make sure the new CRTC will work with the encoder */
  9589. if (!drm_encoder_crtc_ok(&connector->new_encoder->base,
  9590. new_crtc)) {
  9591. return -EINVAL;
  9592. }
  9593. connector->new_encoder->new_crtc = to_intel_crtc(new_crtc);
  9594. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n",
  9595. connector->base.base.id,
  9596. connector->base.name,
  9597. new_crtc->base.id);
  9598. }
  9599. /* Check for any encoders that needs to be disabled. */
  9600. for_each_intel_encoder(dev, encoder) {
  9601. int num_connectors = 0;
  9602. list_for_each_entry(connector,
  9603. &dev->mode_config.connector_list,
  9604. base.head) {
  9605. if (connector->new_encoder == encoder) {
  9606. WARN_ON(!connector->new_encoder->new_crtc);
  9607. num_connectors++;
  9608. }
  9609. }
  9610. if (num_connectors == 0)
  9611. encoder->new_crtc = NULL;
  9612. else if (num_connectors > 1)
  9613. return -EINVAL;
  9614. /* Only now check for crtc changes so we don't miss encoders
  9615. * that will be disabled. */
  9616. if (&encoder->new_crtc->base != encoder->base.crtc) {
  9617. DRM_DEBUG_KMS("crtc changed, full mode switch\n");
  9618. config->mode_changed = true;
  9619. }
  9620. }
  9621. /* Now we've also updated encoder->new_crtc for all encoders. */
  9622. list_for_each_entry(connector, &dev->mode_config.connector_list,
  9623. base.head) {
  9624. if (connector->new_encoder)
  9625. if (connector->new_encoder != connector->encoder)
  9626. connector->encoder = connector->new_encoder;
  9627. }
  9628. for_each_intel_crtc(dev, crtc) {
  9629. crtc->new_enabled = false;
  9630. for_each_intel_encoder(dev, encoder) {
  9631. if (encoder->new_crtc == crtc) {
  9632. crtc->new_enabled = true;
  9633. break;
  9634. }
  9635. }
  9636. if (crtc->new_enabled != crtc->base.enabled) {
  9637. DRM_DEBUG_KMS("crtc %sabled, full mode switch\n",
  9638. crtc->new_enabled ? "en" : "dis");
  9639. config->mode_changed = true;
  9640. }
  9641. if (crtc->new_enabled)
  9642. crtc->new_config = &crtc->config;
  9643. else
  9644. crtc->new_config = NULL;
  9645. }
  9646. return 0;
  9647. }
  9648. static void disable_crtc_nofb(struct intel_crtc *crtc)
  9649. {
  9650. struct drm_device *dev = crtc->base.dev;
  9651. struct intel_encoder *encoder;
  9652. struct intel_connector *connector;
  9653. DRM_DEBUG_KMS("Trying to restore without FB -> disabling pipe %c\n",
  9654. pipe_name(crtc->pipe));
  9655. list_for_each_entry(connector, &dev->mode_config.connector_list, base.head) {
  9656. if (connector->new_encoder &&
  9657. connector->new_encoder->new_crtc == crtc)
  9658. connector->new_encoder = NULL;
  9659. }
  9660. for_each_intel_encoder(dev, encoder) {
  9661. if (encoder->new_crtc == crtc)
  9662. encoder->new_crtc = NULL;
  9663. }
  9664. crtc->new_enabled = false;
  9665. crtc->new_config = NULL;
  9666. }
  9667. static int intel_crtc_set_config(struct drm_mode_set *set)
  9668. {
  9669. struct drm_device *dev;
  9670. struct drm_mode_set save_set;
  9671. struct intel_set_config *config;
  9672. int ret;
  9673. BUG_ON(!set);
  9674. BUG_ON(!set->crtc);
  9675. BUG_ON(!set->crtc->helper_private);
  9676. /* Enforce sane interface api - has been abused by the fb helper. */
  9677. BUG_ON(!set->mode && set->fb);
  9678. BUG_ON(set->fb && set->num_connectors == 0);
  9679. if (set->fb) {
  9680. DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n",
  9681. set->crtc->base.id, set->fb->base.id,
  9682. (int)set->num_connectors, set->x, set->y);
  9683. } else {
  9684. DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set->crtc->base.id);
  9685. }
  9686. dev = set->crtc->dev;
  9687. ret = -ENOMEM;
  9688. config = kzalloc(sizeof(*config), GFP_KERNEL);
  9689. if (!config)
  9690. goto out_config;
  9691. ret = intel_set_config_save_state(dev, config);
  9692. if (ret)
  9693. goto out_config;
  9694. save_set.crtc = set->crtc;
  9695. save_set.mode = &set->crtc->mode;
  9696. save_set.x = set->crtc->x;
  9697. save_set.y = set->crtc->y;
  9698. save_set.fb = set->crtc->primary->fb;
  9699. /* Compute whether we need a full modeset, only an fb base update or no
  9700. * change at all. In the future we might also check whether only the
  9701. * mode changed, e.g. for LVDS where we only change the panel fitter in
  9702. * such cases. */
  9703. intel_set_config_compute_mode_changes(set, config);
  9704. ret = intel_modeset_stage_output_state(dev, set, config);
  9705. if (ret)
  9706. goto fail;
  9707. if (config->mode_changed) {
  9708. ret = intel_set_mode(set->crtc, set->mode,
  9709. set->x, set->y, set->fb);
  9710. } else if (config->fb_changed) {
  9711. struct intel_crtc *intel_crtc = to_intel_crtc(set->crtc);
  9712. intel_crtc_wait_for_pending_flips(set->crtc);
  9713. ret = intel_pipe_set_base(set->crtc,
  9714. set->x, set->y, set->fb);
  9715. /*
  9716. * We need to make sure the primary plane is re-enabled if it
  9717. * has previously been turned off.
  9718. */
  9719. if (!intel_crtc->primary_enabled && ret == 0) {
  9720. WARN_ON(!intel_crtc->active);
  9721. intel_enable_primary_hw_plane(set->crtc->primary, set->crtc);
  9722. }
  9723. /*
  9724. * In the fastboot case this may be our only check of the
  9725. * state after boot. It would be better to only do it on
  9726. * the first update, but we don't have a nice way of doing that
  9727. * (and really, set_config isn't used much for high freq page
  9728. * flipping, so increasing its cost here shouldn't be a big
  9729. * deal).
  9730. */
  9731. if (i915.fastboot && ret == 0)
  9732. intel_modeset_check_state(set->crtc->dev);
  9733. }
  9734. if (ret) {
  9735. DRM_DEBUG_KMS("failed to set mode on [CRTC:%d], err = %d\n",
  9736. set->crtc->base.id, ret);
  9737. fail:
  9738. intel_set_config_restore_state(dev, config);
  9739. /*
  9740. * HACK: if the pipe was on, but we didn't have a framebuffer,
  9741. * force the pipe off to avoid oopsing in the modeset code
  9742. * due to fb==NULL. This should only happen during boot since
  9743. * we don't yet reconstruct the FB from the hardware state.
  9744. */
  9745. if (to_intel_crtc(save_set.crtc)->new_enabled && !save_set.fb)
  9746. disable_crtc_nofb(to_intel_crtc(save_set.crtc));
  9747. /* Try to restore the config */
  9748. if (config->mode_changed &&
  9749. intel_set_mode(save_set.crtc, save_set.mode,
  9750. save_set.x, save_set.y, save_set.fb))
  9751. DRM_ERROR("failed to restore config after modeset failure\n");
  9752. }
  9753. out_config:
  9754. intel_set_config_free(config);
  9755. return ret;
  9756. }
  9757. static const struct drm_crtc_funcs intel_crtc_funcs = {
  9758. .gamma_set = intel_crtc_gamma_set,
  9759. .set_config = intel_crtc_set_config,
  9760. .destroy = intel_crtc_destroy,
  9761. .page_flip = intel_crtc_page_flip,
  9762. };
  9763. static bool ibx_pch_dpll_get_hw_state(struct drm_i915_private *dev_priv,
  9764. struct intel_shared_dpll *pll,
  9765. struct intel_dpll_hw_state *hw_state)
  9766. {
  9767. uint32_t val;
  9768. if (!intel_display_power_enabled(dev_priv, POWER_DOMAIN_PLLS))
  9769. return false;
  9770. val = I915_READ(PCH_DPLL(pll->id));
  9771. hw_state->dpll = val;
  9772. hw_state->fp0 = I915_READ(PCH_FP0(pll->id));
  9773. hw_state->fp1 = I915_READ(PCH_FP1(pll->id));
  9774. return val & DPLL_VCO_ENABLE;
  9775. }
  9776. static void ibx_pch_dpll_mode_set(struct drm_i915_private *dev_priv,
  9777. struct intel_shared_dpll *pll)
  9778. {
  9779. I915_WRITE(PCH_FP0(pll->id), pll->hw_state.fp0);
  9780. I915_WRITE(PCH_FP1(pll->id), pll->hw_state.fp1);
  9781. }
  9782. static void ibx_pch_dpll_enable(struct drm_i915_private *dev_priv,
  9783. struct intel_shared_dpll *pll)
  9784. {
  9785. /* PCH refclock must be enabled first */
  9786. ibx_assert_pch_refclk_enabled(dev_priv);
  9787. I915_WRITE(PCH_DPLL(pll->id), pll->hw_state.dpll);
  9788. /* Wait for the clocks to stabilize. */
  9789. POSTING_READ(PCH_DPLL(pll->id));
  9790. udelay(150);
  9791. /* The pixel multiplier can only be updated once the
  9792. * DPLL is enabled and the clocks are stable.
  9793. *
  9794. * So write it again.
  9795. */
  9796. I915_WRITE(PCH_DPLL(pll->id), pll->hw_state.dpll);
  9797. POSTING_READ(PCH_DPLL(pll->id));
  9798. udelay(200);
  9799. }
  9800. static void ibx_pch_dpll_disable(struct drm_i915_private *dev_priv,
  9801. struct intel_shared_dpll *pll)
  9802. {
  9803. struct drm_device *dev = dev_priv->dev;
  9804. struct intel_crtc *crtc;
  9805. /* Make sure no transcoder isn't still depending on us. */
  9806. for_each_intel_crtc(dev, crtc) {
  9807. if (intel_crtc_to_shared_dpll(crtc) == pll)
  9808. assert_pch_transcoder_disabled(dev_priv, crtc->pipe);
  9809. }
  9810. I915_WRITE(PCH_DPLL(pll->id), 0);
  9811. POSTING_READ(PCH_DPLL(pll->id));
  9812. udelay(200);
  9813. }
  9814. static char *ibx_pch_dpll_names[] = {
  9815. "PCH DPLL A",
  9816. "PCH DPLL B",
  9817. };
  9818. static void ibx_pch_dpll_init(struct drm_device *dev)
  9819. {
  9820. struct drm_i915_private *dev_priv = dev->dev_private;
  9821. int i;
  9822. dev_priv->num_shared_dpll = 2;
  9823. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  9824. dev_priv->shared_dplls[i].id = i;
  9825. dev_priv->shared_dplls[i].name = ibx_pch_dpll_names[i];
  9826. dev_priv->shared_dplls[i].mode_set = ibx_pch_dpll_mode_set;
  9827. dev_priv->shared_dplls[i].enable = ibx_pch_dpll_enable;
  9828. dev_priv->shared_dplls[i].disable = ibx_pch_dpll_disable;
  9829. dev_priv->shared_dplls[i].get_hw_state =
  9830. ibx_pch_dpll_get_hw_state;
  9831. }
  9832. }
  9833. static void intel_shared_dpll_init(struct drm_device *dev)
  9834. {
  9835. struct drm_i915_private *dev_priv = dev->dev_private;
  9836. if (HAS_DDI(dev))
  9837. intel_ddi_pll_init(dev);
  9838. else if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
  9839. ibx_pch_dpll_init(dev);
  9840. else
  9841. dev_priv->num_shared_dpll = 0;
  9842. BUG_ON(dev_priv->num_shared_dpll > I915_NUM_PLLS);
  9843. }
  9844. static int
  9845. intel_primary_plane_disable(struct drm_plane *plane)
  9846. {
  9847. struct drm_device *dev = plane->dev;
  9848. struct intel_crtc *intel_crtc;
  9849. if (!plane->fb)
  9850. return 0;
  9851. BUG_ON(!plane->crtc);
  9852. intel_crtc = to_intel_crtc(plane->crtc);
  9853. /*
  9854. * Even though we checked plane->fb above, it's still possible that
  9855. * the primary plane has been implicitly disabled because the crtc
  9856. * coordinates given weren't visible, or because we detected
  9857. * that it was 100% covered by a sprite plane. Or, the CRTC may be
  9858. * off and we've set a fb, but haven't actually turned on the CRTC yet.
  9859. * In either case, we need to unpin the FB and let the fb pointer get
  9860. * updated, but otherwise we don't need to touch the hardware.
  9861. */
  9862. if (!intel_crtc->primary_enabled)
  9863. goto disable_unpin;
  9864. intel_crtc_wait_for_pending_flips(plane->crtc);
  9865. intel_disable_primary_hw_plane(plane, plane->crtc);
  9866. disable_unpin:
  9867. mutex_lock(&dev->struct_mutex);
  9868. i915_gem_track_fb(intel_fb_obj(plane->fb), NULL,
  9869. INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe));
  9870. intel_unpin_fb_obj(intel_fb_obj(plane->fb));
  9871. mutex_unlock(&dev->struct_mutex);
  9872. plane->fb = NULL;
  9873. return 0;
  9874. }
  9875. static int
  9876. intel_primary_plane_setplane(struct drm_plane *plane, struct drm_crtc *crtc,
  9877. struct drm_framebuffer *fb, int crtc_x, int crtc_y,
  9878. unsigned int crtc_w, unsigned int crtc_h,
  9879. uint32_t src_x, uint32_t src_y,
  9880. uint32_t src_w, uint32_t src_h)
  9881. {
  9882. struct drm_device *dev = crtc->dev;
  9883. struct drm_i915_private *dev_priv = dev->dev_private;
  9884. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  9885. struct drm_i915_gem_object *obj = intel_fb_obj(fb);
  9886. struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->fb);
  9887. struct drm_rect dest = {
  9888. /* integer pixels */
  9889. .x1 = crtc_x,
  9890. .y1 = crtc_y,
  9891. .x2 = crtc_x + crtc_w,
  9892. .y2 = crtc_y + crtc_h,
  9893. };
  9894. struct drm_rect src = {
  9895. /* 16.16 fixed point */
  9896. .x1 = src_x,
  9897. .y1 = src_y,
  9898. .x2 = src_x + src_w,
  9899. .y2 = src_y + src_h,
  9900. };
  9901. const struct drm_rect clip = {
  9902. /* integer pixels */
  9903. .x2 = intel_crtc->active ? intel_crtc->config.pipe_src_w : 0,
  9904. .y2 = intel_crtc->active ? intel_crtc->config.pipe_src_h : 0,
  9905. };
  9906. const struct {
  9907. int crtc_x, crtc_y;
  9908. unsigned int crtc_w, crtc_h;
  9909. uint32_t src_x, src_y, src_w, src_h;
  9910. } orig = {
  9911. .crtc_x = crtc_x,
  9912. .crtc_y = crtc_y,
  9913. .crtc_w = crtc_w,
  9914. .crtc_h = crtc_h,
  9915. .src_x = src_x,
  9916. .src_y = src_y,
  9917. .src_w = src_w,
  9918. .src_h = src_h,
  9919. };
  9920. struct intel_plane *intel_plane = to_intel_plane(plane);
  9921. bool visible;
  9922. int ret;
  9923. ret = drm_plane_helper_check_update(plane, crtc, fb,
  9924. &src, &dest, &clip,
  9925. DRM_PLANE_HELPER_NO_SCALING,
  9926. DRM_PLANE_HELPER_NO_SCALING,
  9927. false, true, &visible);
  9928. if (ret)
  9929. return ret;
  9930. /*
  9931. * If the CRTC isn't enabled, we're just pinning the framebuffer,
  9932. * updating the fb pointer, and returning without touching the
  9933. * hardware. This allows us to later do a drmModeSetCrtc with fb=-1 to
  9934. * turn on the display with all planes setup as desired.
  9935. */
  9936. if (!crtc->enabled) {
  9937. mutex_lock(&dev->struct_mutex);
  9938. /*
  9939. * If we already called setplane while the crtc was disabled,
  9940. * we may have an fb pinned; unpin it.
  9941. */
  9942. if (plane->fb)
  9943. intel_unpin_fb_obj(old_obj);
  9944. i915_gem_track_fb(old_obj, obj,
  9945. INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe));
  9946. /* Pin and return without programming hardware */
  9947. ret = intel_pin_and_fence_fb_obj(dev, obj, NULL);
  9948. mutex_unlock(&dev->struct_mutex);
  9949. return ret;
  9950. }
  9951. intel_crtc_wait_for_pending_flips(crtc);
  9952. /*
  9953. * If clipping results in a non-visible primary plane, we'll disable
  9954. * the primary plane. Note that this is a bit different than what
  9955. * happens if userspace explicitly disables the plane by passing fb=0
  9956. * because plane->fb still gets set and pinned.
  9957. */
  9958. if (!visible) {
  9959. mutex_lock(&dev->struct_mutex);
  9960. /*
  9961. * Try to pin the new fb first so that we can bail out if we
  9962. * fail.
  9963. */
  9964. if (plane->fb != fb) {
  9965. ret = intel_pin_and_fence_fb_obj(dev, obj, NULL);
  9966. if (ret) {
  9967. mutex_unlock(&dev->struct_mutex);
  9968. return ret;
  9969. }
  9970. }
  9971. i915_gem_track_fb(old_obj, obj,
  9972. INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe));
  9973. if (intel_crtc->primary_enabled)
  9974. intel_disable_primary_hw_plane(plane, crtc);
  9975. if (plane->fb != fb)
  9976. if (plane->fb)
  9977. intel_unpin_fb_obj(old_obj);
  9978. mutex_unlock(&dev->struct_mutex);
  9979. } else {
  9980. if (intel_crtc && intel_crtc->active &&
  9981. intel_crtc->primary_enabled) {
  9982. /*
  9983. * FBC does not work on some platforms for rotated
  9984. * planes, so disable it when rotation is not 0 and
  9985. * update it when rotation is set back to 0.
  9986. *
  9987. * FIXME: This is redundant with the fbc update done in
  9988. * the primary plane enable function except that that
  9989. * one is done too late. We eventually need to unify
  9990. * this.
  9991. */
  9992. if (INTEL_INFO(dev)->gen <= 4 && !IS_G4X(dev) &&
  9993. dev_priv->fbc.plane == intel_crtc->plane &&
  9994. intel_plane->rotation != BIT(DRM_ROTATE_0)) {
  9995. intel_disable_fbc(dev);
  9996. }
  9997. }
  9998. ret = intel_pipe_set_base(crtc, src.x1, src.y1, fb);
  9999. if (ret)
  10000. return ret;
  10001. if (!intel_crtc->primary_enabled)
  10002. intel_enable_primary_hw_plane(plane, crtc);
  10003. }
  10004. intel_plane->crtc_x = orig.crtc_x;
  10005. intel_plane->crtc_y = orig.crtc_y;
  10006. intel_plane->crtc_w = orig.crtc_w;
  10007. intel_plane->crtc_h = orig.crtc_h;
  10008. intel_plane->src_x = orig.src_x;
  10009. intel_plane->src_y = orig.src_y;
  10010. intel_plane->src_w = orig.src_w;
  10011. intel_plane->src_h = orig.src_h;
  10012. intel_plane->obj = obj;
  10013. return 0;
  10014. }
  10015. /* Common destruction function for both primary and cursor planes */
  10016. static void intel_plane_destroy(struct drm_plane *plane)
  10017. {
  10018. struct intel_plane *intel_plane = to_intel_plane(plane);
  10019. drm_plane_cleanup(plane);
  10020. kfree(intel_plane);
  10021. }
  10022. static const struct drm_plane_funcs intel_primary_plane_funcs = {
  10023. .update_plane = intel_primary_plane_setplane,
  10024. .disable_plane = intel_primary_plane_disable,
  10025. .destroy = intel_plane_destroy,
  10026. .set_property = intel_plane_set_property
  10027. };
  10028. static struct drm_plane *intel_primary_plane_create(struct drm_device *dev,
  10029. int pipe)
  10030. {
  10031. struct intel_plane *primary;
  10032. const uint32_t *intel_primary_formats;
  10033. int num_formats;
  10034. primary = kzalloc(sizeof(*primary), GFP_KERNEL);
  10035. if (primary == NULL)
  10036. return NULL;
  10037. primary->can_scale = false;
  10038. primary->max_downscale = 1;
  10039. primary->pipe = pipe;
  10040. primary->plane = pipe;
  10041. primary->rotation = BIT(DRM_ROTATE_0);
  10042. if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4)
  10043. primary->plane = !pipe;
  10044. if (INTEL_INFO(dev)->gen <= 3) {
  10045. intel_primary_formats = intel_primary_formats_gen2;
  10046. num_formats = ARRAY_SIZE(intel_primary_formats_gen2);
  10047. } else {
  10048. intel_primary_formats = intel_primary_formats_gen4;
  10049. num_formats = ARRAY_SIZE(intel_primary_formats_gen4);
  10050. }
  10051. drm_universal_plane_init(dev, &primary->base, 0,
  10052. &intel_primary_plane_funcs,
  10053. intel_primary_formats, num_formats,
  10054. DRM_PLANE_TYPE_PRIMARY);
  10055. if (INTEL_INFO(dev)->gen >= 4) {
  10056. if (!dev->mode_config.rotation_property)
  10057. dev->mode_config.rotation_property =
  10058. drm_mode_create_rotation_property(dev,
  10059. BIT(DRM_ROTATE_0) |
  10060. BIT(DRM_ROTATE_180));
  10061. if (dev->mode_config.rotation_property)
  10062. drm_object_attach_property(&primary->base.base,
  10063. dev->mode_config.rotation_property,
  10064. primary->rotation);
  10065. }
  10066. return &primary->base;
  10067. }
  10068. static int
  10069. intel_cursor_plane_disable(struct drm_plane *plane)
  10070. {
  10071. if (!plane->fb)
  10072. return 0;
  10073. BUG_ON(!plane->crtc);
  10074. return intel_crtc_cursor_set_obj(plane->crtc, NULL, 0, 0);
  10075. }
  10076. static int
  10077. intel_cursor_plane_update(struct drm_plane *plane, struct drm_crtc *crtc,
  10078. struct drm_framebuffer *fb, int crtc_x, int crtc_y,
  10079. unsigned int crtc_w, unsigned int crtc_h,
  10080. uint32_t src_x, uint32_t src_y,
  10081. uint32_t src_w, uint32_t src_h)
  10082. {
  10083. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  10084. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  10085. struct drm_i915_gem_object *obj = intel_fb->obj;
  10086. struct drm_rect dest = {
  10087. /* integer pixels */
  10088. .x1 = crtc_x,
  10089. .y1 = crtc_y,
  10090. .x2 = crtc_x + crtc_w,
  10091. .y2 = crtc_y + crtc_h,
  10092. };
  10093. struct drm_rect src = {
  10094. /* 16.16 fixed point */
  10095. .x1 = src_x,
  10096. .y1 = src_y,
  10097. .x2 = src_x + src_w,
  10098. .y2 = src_y + src_h,
  10099. };
  10100. const struct drm_rect clip = {
  10101. /* integer pixels */
  10102. .x2 = intel_crtc->active ? intel_crtc->config.pipe_src_w : 0,
  10103. .y2 = intel_crtc->active ? intel_crtc->config.pipe_src_h : 0,
  10104. };
  10105. bool visible;
  10106. int ret;
  10107. ret = drm_plane_helper_check_update(plane, crtc, fb,
  10108. &src, &dest, &clip,
  10109. DRM_PLANE_HELPER_NO_SCALING,
  10110. DRM_PLANE_HELPER_NO_SCALING,
  10111. true, true, &visible);
  10112. if (ret)
  10113. return ret;
  10114. crtc->cursor_x = crtc_x;
  10115. crtc->cursor_y = crtc_y;
  10116. if (fb != crtc->cursor->fb) {
  10117. return intel_crtc_cursor_set_obj(crtc, obj, crtc_w, crtc_h);
  10118. } else {
  10119. intel_crtc_update_cursor(crtc, visible);
  10120. intel_frontbuffer_flip(crtc->dev,
  10121. INTEL_FRONTBUFFER_CURSOR(intel_crtc->pipe));
  10122. return 0;
  10123. }
  10124. }
  10125. static const struct drm_plane_funcs intel_cursor_plane_funcs = {
  10126. .update_plane = intel_cursor_plane_update,
  10127. .disable_plane = intel_cursor_plane_disable,
  10128. .destroy = intel_plane_destroy,
  10129. };
  10130. static struct drm_plane *intel_cursor_plane_create(struct drm_device *dev,
  10131. int pipe)
  10132. {
  10133. struct intel_plane *cursor;
  10134. cursor = kzalloc(sizeof(*cursor), GFP_KERNEL);
  10135. if (cursor == NULL)
  10136. return NULL;
  10137. cursor->can_scale = false;
  10138. cursor->max_downscale = 1;
  10139. cursor->pipe = pipe;
  10140. cursor->plane = pipe;
  10141. drm_universal_plane_init(dev, &cursor->base, 0,
  10142. &intel_cursor_plane_funcs,
  10143. intel_cursor_formats,
  10144. ARRAY_SIZE(intel_cursor_formats),
  10145. DRM_PLANE_TYPE_CURSOR);
  10146. return &cursor->base;
  10147. }
  10148. static void intel_crtc_init(struct drm_device *dev, int pipe)
  10149. {
  10150. struct drm_i915_private *dev_priv = dev->dev_private;
  10151. struct intel_crtc *intel_crtc;
  10152. struct drm_plane *primary = NULL;
  10153. struct drm_plane *cursor = NULL;
  10154. int i, ret;
  10155. intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL);
  10156. if (intel_crtc == NULL)
  10157. return;
  10158. primary = intel_primary_plane_create(dev, pipe);
  10159. if (!primary)
  10160. goto fail;
  10161. cursor = intel_cursor_plane_create(dev, pipe);
  10162. if (!cursor)
  10163. goto fail;
  10164. ret = drm_crtc_init_with_planes(dev, &intel_crtc->base, primary,
  10165. cursor, &intel_crtc_funcs);
  10166. if (ret)
  10167. goto fail;
  10168. drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256);
  10169. for (i = 0; i < 256; i++) {
  10170. intel_crtc->lut_r[i] = i;
  10171. intel_crtc->lut_g[i] = i;
  10172. intel_crtc->lut_b[i] = i;
  10173. }
  10174. /*
  10175. * On gen2/3 only plane A can do fbc, but the panel fitter and lvds port
  10176. * is hooked to pipe B. Hence we want plane A feeding pipe B.
  10177. */
  10178. intel_crtc->pipe = pipe;
  10179. intel_crtc->plane = pipe;
  10180. if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) {
  10181. DRM_DEBUG_KMS("swapping pipes & planes for FBC\n");
  10182. intel_crtc->plane = !pipe;
  10183. }
  10184. intel_crtc->cursor_base = ~0;
  10185. intel_crtc->cursor_cntl = ~0;
  10186. intel_crtc->cursor_size = ~0;
  10187. BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
  10188. dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL);
  10189. dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base;
  10190. dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base;
  10191. drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
  10192. WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe);
  10193. return;
  10194. fail:
  10195. if (primary)
  10196. drm_plane_cleanup(primary);
  10197. if (cursor)
  10198. drm_plane_cleanup(cursor);
  10199. kfree(intel_crtc);
  10200. }
  10201. enum pipe intel_get_pipe_from_connector(struct intel_connector *connector)
  10202. {
  10203. struct drm_encoder *encoder = connector->base.encoder;
  10204. struct drm_device *dev = connector->base.dev;
  10205. WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
  10206. if (!encoder)
  10207. return INVALID_PIPE;
  10208. return to_intel_crtc(encoder->crtc)->pipe;
  10209. }
  10210. int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data,
  10211. struct drm_file *file)
  10212. {
  10213. struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
  10214. struct drm_crtc *drmmode_crtc;
  10215. struct intel_crtc *crtc;
  10216. if (!drm_core_check_feature(dev, DRIVER_MODESET))
  10217. return -ENODEV;
  10218. drmmode_crtc = drm_crtc_find(dev, pipe_from_crtc_id->crtc_id);
  10219. if (!drmmode_crtc) {
  10220. DRM_ERROR("no such CRTC id\n");
  10221. return -ENOENT;
  10222. }
  10223. crtc = to_intel_crtc(drmmode_crtc);
  10224. pipe_from_crtc_id->pipe = crtc->pipe;
  10225. return 0;
  10226. }
  10227. static int intel_encoder_clones(struct intel_encoder *encoder)
  10228. {
  10229. struct drm_device *dev = encoder->base.dev;
  10230. struct intel_encoder *source_encoder;
  10231. int index_mask = 0;
  10232. int entry = 0;
  10233. for_each_intel_encoder(dev, source_encoder) {
  10234. if (encoders_cloneable(encoder, source_encoder))
  10235. index_mask |= (1 << entry);
  10236. entry++;
  10237. }
  10238. return index_mask;
  10239. }
  10240. static bool has_edp_a(struct drm_device *dev)
  10241. {
  10242. struct drm_i915_private *dev_priv = dev->dev_private;
  10243. if (!IS_MOBILE(dev))
  10244. return false;
  10245. if ((I915_READ(DP_A) & DP_DETECTED) == 0)
  10246. return false;
  10247. if (IS_GEN5(dev) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE))
  10248. return false;
  10249. return true;
  10250. }
  10251. const char *intel_output_name(int output)
  10252. {
  10253. static const char *names[] = {
  10254. [INTEL_OUTPUT_UNUSED] = "Unused",
  10255. [INTEL_OUTPUT_ANALOG] = "Analog",
  10256. [INTEL_OUTPUT_DVO] = "DVO",
  10257. [INTEL_OUTPUT_SDVO] = "SDVO",
  10258. [INTEL_OUTPUT_LVDS] = "LVDS",
  10259. [INTEL_OUTPUT_TVOUT] = "TV",
  10260. [INTEL_OUTPUT_HDMI] = "HDMI",
  10261. [INTEL_OUTPUT_DISPLAYPORT] = "DisplayPort",
  10262. [INTEL_OUTPUT_EDP] = "eDP",
  10263. [INTEL_OUTPUT_DSI] = "DSI",
  10264. [INTEL_OUTPUT_UNKNOWN] = "Unknown",
  10265. };
  10266. if (output < 0 || output >= ARRAY_SIZE(names) || !names[output])
  10267. return "Invalid";
  10268. return names[output];
  10269. }
  10270. static bool intel_crt_present(struct drm_device *dev)
  10271. {
  10272. struct drm_i915_private *dev_priv = dev->dev_private;
  10273. if (IS_ULT(dev))
  10274. return false;
  10275. if (IS_CHERRYVIEW(dev))
  10276. return false;
  10277. if (IS_VALLEYVIEW(dev) && !dev_priv->vbt.int_crt_support)
  10278. return false;
  10279. return true;
  10280. }
  10281. static void intel_setup_outputs(struct drm_device *dev)
  10282. {
  10283. struct drm_i915_private *dev_priv = dev->dev_private;
  10284. struct intel_encoder *encoder;
  10285. bool dpd_is_edp = false;
  10286. intel_lvds_init(dev);
  10287. if (intel_crt_present(dev))
  10288. intel_crt_init(dev);
  10289. if (HAS_DDI(dev)) {
  10290. int found;
  10291. /* Haswell uses DDI functions to detect digital outputs */
  10292. found = I915_READ(DDI_BUF_CTL_A) & DDI_INIT_DISPLAY_DETECTED;
  10293. /* DDI A only supports eDP */
  10294. if (found)
  10295. intel_ddi_init(dev, PORT_A);
  10296. /* DDI B, C and D detection is indicated by the SFUSE_STRAP
  10297. * register */
  10298. found = I915_READ(SFUSE_STRAP);
  10299. if (found & SFUSE_STRAP_DDIB_DETECTED)
  10300. intel_ddi_init(dev, PORT_B);
  10301. if (found & SFUSE_STRAP_DDIC_DETECTED)
  10302. intel_ddi_init(dev, PORT_C);
  10303. if (found & SFUSE_STRAP_DDID_DETECTED)
  10304. intel_ddi_init(dev, PORT_D);
  10305. } else if (HAS_PCH_SPLIT(dev)) {
  10306. int found;
  10307. dpd_is_edp = intel_dp_is_edp(dev, PORT_D);
  10308. if (has_edp_a(dev))
  10309. intel_dp_init(dev, DP_A, PORT_A);
  10310. if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) {
  10311. /* PCH SDVOB multiplex with HDMIB */
  10312. found = intel_sdvo_init(dev, PCH_SDVOB, true);
  10313. if (!found)
  10314. intel_hdmi_init(dev, PCH_HDMIB, PORT_B);
  10315. if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
  10316. intel_dp_init(dev, PCH_DP_B, PORT_B);
  10317. }
  10318. if (I915_READ(PCH_HDMIC) & SDVO_DETECTED)
  10319. intel_hdmi_init(dev, PCH_HDMIC, PORT_C);
  10320. if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED)
  10321. intel_hdmi_init(dev, PCH_HDMID, PORT_D);
  10322. if (I915_READ(PCH_DP_C) & DP_DETECTED)
  10323. intel_dp_init(dev, PCH_DP_C, PORT_C);
  10324. if (I915_READ(PCH_DP_D) & DP_DETECTED)
  10325. intel_dp_init(dev, PCH_DP_D, PORT_D);
  10326. } else if (IS_VALLEYVIEW(dev)) {
  10327. if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIB) & SDVO_DETECTED) {
  10328. intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIB,
  10329. PORT_B);
  10330. if (I915_READ(VLV_DISPLAY_BASE + DP_B) & DP_DETECTED)
  10331. intel_dp_init(dev, VLV_DISPLAY_BASE + DP_B, PORT_B);
  10332. }
  10333. if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIC) & SDVO_DETECTED) {
  10334. intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIC,
  10335. PORT_C);
  10336. if (I915_READ(VLV_DISPLAY_BASE + DP_C) & DP_DETECTED)
  10337. intel_dp_init(dev, VLV_DISPLAY_BASE + DP_C, PORT_C);
  10338. }
  10339. if (IS_CHERRYVIEW(dev)) {
  10340. if (I915_READ(VLV_DISPLAY_BASE + CHV_HDMID) & SDVO_DETECTED) {
  10341. intel_hdmi_init(dev, VLV_DISPLAY_BASE + CHV_HDMID,
  10342. PORT_D);
  10343. if (I915_READ(VLV_DISPLAY_BASE + DP_D) & DP_DETECTED)
  10344. intel_dp_init(dev, VLV_DISPLAY_BASE + DP_D, PORT_D);
  10345. }
  10346. }
  10347. intel_dsi_init(dev);
  10348. } else if (SUPPORTS_DIGITAL_OUTPUTS(dev)) {
  10349. bool found = false;
  10350. if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
  10351. DRM_DEBUG_KMS("probing SDVOB\n");
  10352. found = intel_sdvo_init(dev, GEN3_SDVOB, true);
  10353. if (!found && SUPPORTS_INTEGRATED_HDMI(dev)) {
  10354. DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
  10355. intel_hdmi_init(dev, GEN4_HDMIB, PORT_B);
  10356. }
  10357. if (!found && SUPPORTS_INTEGRATED_DP(dev))
  10358. intel_dp_init(dev, DP_B, PORT_B);
  10359. }
  10360. /* Before G4X SDVOC doesn't have its own detect register */
  10361. if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
  10362. DRM_DEBUG_KMS("probing SDVOC\n");
  10363. found = intel_sdvo_init(dev, GEN3_SDVOC, false);
  10364. }
  10365. if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) {
  10366. if (SUPPORTS_INTEGRATED_HDMI(dev)) {
  10367. DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
  10368. intel_hdmi_init(dev, GEN4_HDMIC, PORT_C);
  10369. }
  10370. if (SUPPORTS_INTEGRATED_DP(dev))
  10371. intel_dp_init(dev, DP_C, PORT_C);
  10372. }
  10373. if (SUPPORTS_INTEGRATED_DP(dev) &&
  10374. (I915_READ(DP_D) & DP_DETECTED))
  10375. intel_dp_init(dev, DP_D, PORT_D);
  10376. } else if (IS_GEN2(dev))
  10377. intel_dvo_init(dev);
  10378. if (SUPPORTS_TV(dev))
  10379. intel_tv_init(dev);
  10380. intel_edp_psr_init(dev);
  10381. for_each_intel_encoder(dev, encoder) {
  10382. encoder->base.possible_crtcs = encoder->crtc_mask;
  10383. encoder->base.possible_clones =
  10384. intel_encoder_clones(encoder);
  10385. }
  10386. intel_init_pch_refclk(dev);
  10387. drm_helper_move_panel_connectors_to_head(dev);
  10388. }
  10389. static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
  10390. {
  10391. struct drm_device *dev = fb->dev;
  10392. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  10393. drm_framebuffer_cleanup(fb);
  10394. mutex_lock(&dev->struct_mutex);
  10395. WARN_ON(!intel_fb->obj->framebuffer_references--);
  10396. drm_gem_object_unreference(&intel_fb->obj->base);
  10397. mutex_unlock(&dev->struct_mutex);
  10398. kfree(intel_fb);
  10399. }
  10400. static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
  10401. struct drm_file *file,
  10402. unsigned int *handle)
  10403. {
  10404. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  10405. struct drm_i915_gem_object *obj = intel_fb->obj;
  10406. return drm_gem_handle_create(file, &obj->base, handle);
  10407. }
  10408. static const struct drm_framebuffer_funcs intel_fb_funcs = {
  10409. .destroy = intel_user_framebuffer_destroy,
  10410. .create_handle = intel_user_framebuffer_create_handle,
  10411. };
  10412. static int intel_framebuffer_init(struct drm_device *dev,
  10413. struct intel_framebuffer *intel_fb,
  10414. struct drm_mode_fb_cmd2 *mode_cmd,
  10415. struct drm_i915_gem_object *obj)
  10416. {
  10417. int aligned_height;
  10418. int pitch_limit;
  10419. int ret;
  10420. WARN_ON(!mutex_is_locked(&dev->struct_mutex));
  10421. if (obj->tiling_mode == I915_TILING_Y) {
  10422. DRM_DEBUG("hardware does not support tiling Y\n");
  10423. return -EINVAL;
  10424. }
  10425. if (mode_cmd->pitches[0] & 63) {
  10426. DRM_DEBUG("pitch (%d) must be at least 64 byte aligned\n",
  10427. mode_cmd->pitches[0]);
  10428. return -EINVAL;
  10429. }
  10430. if (INTEL_INFO(dev)->gen >= 5 && !IS_VALLEYVIEW(dev)) {
  10431. pitch_limit = 32*1024;
  10432. } else if (INTEL_INFO(dev)->gen >= 4) {
  10433. if (obj->tiling_mode)
  10434. pitch_limit = 16*1024;
  10435. else
  10436. pitch_limit = 32*1024;
  10437. } else if (INTEL_INFO(dev)->gen >= 3) {
  10438. if (obj->tiling_mode)
  10439. pitch_limit = 8*1024;
  10440. else
  10441. pitch_limit = 16*1024;
  10442. } else
  10443. /* XXX DSPC is limited to 4k tiled */
  10444. pitch_limit = 8*1024;
  10445. if (mode_cmd->pitches[0] > pitch_limit) {
  10446. DRM_DEBUG("%s pitch (%d) must be at less than %d\n",
  10447. obj->tiling_mode ? "tiled" : "linear",
  10448. mode_cmd->pitches[0], pitch_limit);
  10449. return -EINVAL;
  10450. }
  10451. if (obj->tiling_mode != I915_TILING_NONE &&
  10452. mode_cmd->pitches[0] != obj->stride) {
  10453. DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n",
  10454. mode_cmd->pitches[0], obj->stride);
  10455. return -EINVAL;
  10456. }
  10457. /* Reject formats not supported by any plane early. */
  10458. switch (mode_cmd->pixel_format) {
  10459. case DRM_FORMAT_C8:
  10460. case DRM_FORMAT_RGB565:
  10461. case DRM_FORMAT_XRGB8888:
  10462. case DRM_FORMAT_ARGB8888:
  10463. break;
  10464. case DRM_FORMAT_XRGB1555:
  10465. case DRM_FORMAT_ARGB1555:
  10466. if (INTEL_INFO(dev)->gen > 3) {
  10467. DRM_DEBUG("unsupported pixel format: %s\n",
  10468. drm_get_format_name(mode_cmd->pixel_format));
  10469. return -EINVAL;
  10470. }
  10471. break;
  10472. case DRM_FORMAT_XBGR8888:
  10473. case DRM_FORMAT_ABGR8888:
  10474. case DRM_FORMAT_XRGB2101010:
  10475. case DRM_FORMAT_ARGB2101010:
  10476. case DRM_FORMAT_XBGR2101010:
  10477. case DRM_FORMAT_ABGR2101010:
  10478. if (INTEL_INFO(dev)->gen < 4) {
  10479. DRM_DEBUG("unsupported pixel format: %s\n",
  10480. drm_get_format_name(mode_cmd->pixel_format));
  10481. return -EINVAL;
  10482. }
  10483. break;
  10484. case DRM_FORMAT_YUYV:
  10485. case DRM_FORMAT_UYVY:
  10486. case DRM_FORMAT_YVYU:
  10487. case DRM_FORMAT_VYUY:
  10488. if (INTEL_INFO(dev)->gen < 5) {
  10489. DRM_DEBUG("unsupported pixel format: %s\n",
  10490. drm_get_format_name(mode_cmd->pixel_format));
  10491. return -EINVAL;
  10492. }
  10493. break;
  10494. default:
  10495. DRM_DEBUG("unsupported pixel format: %s\n",
  10496. drm_get_format_name(mode_cmd->pixel_format));
  10497. return -EINVAL;
  10498. }
  10499. /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
  10500. if (mode_cmd->offsets[0] != 0)
  10501. return -EINVAL;
  10502. aligned_height = intel_align_height(dev, mode_cmd->height,
  10503. obj->tiling_mode);
  10504. /* FIXME drm helper for size checks (especially planar formats)? */
  10505. if (obj->base.size < aligned_height * mode_cmd->pitches[0])
  10506. return -EINVAL;
  10507. drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd);
  10508. intel_fb->obj = obj;
  10509. intel_fb->obj->framebuffer_references++;
  10510. ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs);
  10511. if (ret) {
  10512. DRM_ERROR("framebuffer init failed %d\n", ret);
  10513. return ret;
  10514. }
  10515. return 0;
  10516. }
  10517. static struct drm_framebuffer *
  10518. intel_user_framebuffer_create(struct drm_device *dev,
  10519. struct drm_file *filp,
  10520. struct drm_mode_fb_cmd2 *mode_cmd)
  10521. {
  10522. struct drm_i915_gem_object *obj;
  10523. obj = to_intel_bo(drm_gem_object_lookup(dev, filp,
  10524. mode_cmd->handles[0]));
  10525. if (&obj->base == NULL)
  10526. return ERR_PTR(-ENOENT);
  10527. return intel_framebuffer_create(dev, mode_cmd, obj);
  10528. }
  10529. #ifndef CONFIG_DRM_I915_FBDEV
  10530. static inline void intel_fbdev_output_poll_changed(struct drm_device *dev)
  10531. {
  10532. }
  10533. #endif
  10534. static const struct drm_mode_config_funcs intel_mode_funcs = {
  10535. .fb_create = intel_user_framebuffer_create,
  10536. .output_poll_changed = intel_fbdev_output_poll_changed,
  10537. };
  10538. /* Set up chip specific display functions */
  10539. static void intel_init_display(struct drm_device *dev)
  10540. {
  10541. struct drm_i915_private *dev_priv = dev->dev_private;
  10542. if (HAS_PCH_SPLIT(dev) || IS_G4X(dev))
  10543. dev_priv->display.find_dpll = g4x_find_best_dpll;
  10544. else if (IS_CHERRYVIEW(dev))
  10545. dev_priv->display.find_dpll = chv_find_best_dpll;
  10546. else if (IS_VALLEYVIEW(dev))
  10547. dev_priv->display.find_dpll = vlv_find_best_dpll;
  10548. else if (IS_PINEVIEW(dev))
  10549. dev_priv->display.find_dpll = pnv_find_best_dpll;
  10550. else
  10551. dev_priv->display.find_dpll = i9xx_find_best_dpll;
  10552. if (HAS_DDI(dev)) {
  10553. dev_priv->display.get_pipe_config = haswell_get_pipe_config;
  10554. dev_priv->display.get_plane_config = ironlake_get_plane_config;
  10555. dev_priv->display.crtc_mode_set = haswell_crtc_mode_set;
  10556. dev_priv->display.crtc_enable = haswell_crtc_enable;
  10557. dev_priv->display.crtc_disable = haswell_crtc_disable;
  10558. dev_priv->display.off = ironlake_crtc_off;
  10559. dev_priv->display.update_primary_plane =
  10560. ironlake_update_primary_plane;
  10561. } else if (HAS_PCH_SPLIT(dev)) {
  10562. dev_priv->display.get_pipe_config = ironlake_get_pipe_config;
  10563. dev_priv->display.get_plane_config = ironlake_get_plane_config;
  10564. dev_priv->display.crtc_mode_set = ironlake_crtc_mode_set;
  10565. dev_priv->display.crtc_enable = ironlake_crtc_enable;
  10566. dev_priv->display.crtc_disable = ironlake_crtc_disable;
  10567. dev_priv->display.off = ironlake_crtc_off;
  10568. dev_priv->display.update_primary_plane =
  10569. ironlake_update_primary_plane;
  10570. } else if (IS_VALLEYVIEW(dev)) {
  10571. dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
  10572. dev_priv->display.get_plane_config = i9xx_get_plane_config;
  10573. dev_priv->display.crtc_mode_set = i9xx_crtc_mode_set;
  10574. dev_priv->display.crtc_enable = valleyview_crtc_enable;
  10575. dev_priv->display.crtc_disable = i9xx_crtc_disable;
  10576. dev_priv->display.off = i9xx_crtc_off;
  10577. dev_priv->display.update_primary_plane =
  10578. i9xx_update_primary_plane;
  10579. } else {
  10580. dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
  10581. dev_priv->display.get_plane_config = i9xx_get_plane_config;
  10582. dev_priv->display.crtc_mode_set = i9xx_crtc_mode_set;
  10583. dev_priv->display.crtc_enable = i9xx_crtc_enable;
  10584. dev_priv->display.crtc_disable = i9xx_crtc_disable;
  10585. dev_priv->display.off = i9xx_crtc_off;
  10586. dev_priv->display.update_primary_plane =
  10587. i9xx_update_primary_plane;
  10588. }
  10589. /* Returns the core display clock speed */
  10590. if (IS_VALLEYVIEW(dev))
  10591. dev_priv->display.get_display_clock_speed =
  10592. valleyview_get_display_clock_speed;
  10593. else if (IS_I945G(dev) || (IS_G33(dev) && !IS_PINEVIEW_M(dev)))
  10594. dev_priv->display.get_display_clock_speed =
  10595. i945_get_display_clock_speed;
  10596. else if (IS_I915G(dev))
  10597. dev_priv->display.get_display_clock_speed =
  10598. i915_get_display_clock_speed;
  10599. else if (IS_I945GM(dev) || IS_845G(dev))
  10600. dev_priv->display.get_display_clock_speed =
  10601. i9xx_misc_get_display_clock_speed;
  10602. else if (IS_PINEVIEW(dev))
  10603. dev_priv->display.get_display_clock_speed =
  10604. pnv_get_display_clock_speed;
  10605. else if (IS_I915GM(dev))
  10606. dev_priv->display.get_display_clock_speed =
  10607. i915gm_get_display_clock_speed;
  10608. else if (IS_I865G(dev))
  10609. dev_priv->display.get_display_clock_speed =
  10610. i865_get_display_clock_speed;
  10611. else if (IS_I85X(dev))
  10612. dev_priv->display.get_display_clock_speed =
  10613. i855_get_display_clock_speed;
  10614. else /* 852, 830 */
  10615. dev_priv->display.get_display_clock_speed =
  10616. i830_get_display_clock_speed;
  10617. if (IS_G4X(dev)) {
  10618. dev_priv->display.write_eld = g4x_write_eld;
  10619. } else if (IS_GEN5(dev)) {
  10620. dev_priv->display.fdi_link_train = ironlake_fdi_link_train;
  10621. dev_priv->display.write_eld = ironlake_write_eld;
  10622. } else if (IS_GEN6(dev)) {
  10623. dev_priv->display.fdi_link_train = gen6_fdi_link_train;
  10624. dev_priv->display.write_eld = ironlake_write_eld;
  10625. dev_priv->display.modeset_global_resources =
  10626. snb_modeset_global_resources;
  10627. } else if (IS_IVYBRIDGE(dev)) {
  10628. /* FIXME: detect B0+ stepping and use auto training */
  10629. dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train;
  10630. dev_priv->display.write_eld = ironlake_write_eld;
  10631. dev_priv->display.modeset_global_resources =
  10632. ivb_modeset_global_resources;
  10633. } else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
  10634. dev_priv->display.fdi_link_train = hsw_fdi_link_train;
  10635. dev_priv->display.write_eld = haswell_write_eld;
  10636. dev_priv->display.modeset_global_resources =
  10637. haswell_modeset_global_resources;
  10638. } else if (IS_VALLEYVIEW(dev)) {
  10639. dev_priv->display.modeset_global_resources =
  10640. valleyview_modeset_global_resources;
  10641. dev_priv->display.write_eld = ironlake_write_eld;
  10642. }
  10643. /* Default just returns -ENODEV to indicate unsupported */
  10644. dev_priv->display.queue_flip = intel_default_queue_flip;
  10645. switch (INTEL_INFO(dev)->gen) {
  10646. case 2:
  10647. dev_priv->display.queue_flip = intel_gen2_queue_flip;
  10648. break;
  10649. case 3:
  10650. dev_priv->display.queue_flip = intel_gen3_queue_flip;
  10651. break;
  10652. case 4:
  10653. case 5:
  10654. dev_priv->display.queue_flip = intel_gen4_queue_flip;
  10655. break;
  10656. case 6:
  10657. dev_priv->display.queue_flip = intel_gen6_queue_flip;
  10658. break;
  10659. case 7:
  10660. case 8: /* FIXME(BDW): Check that the gen8 RCS flip works. */
  10661. dev_priv->display.queue_flip = intel_gen7_queue_flip;
  10662. break;
  10663. }
  10664. intel_panel_init_backlight_funcs(dev);
  10665. mutex_init(&dev_priv->pps_mutex);
  10666. }
  10667. /*
  10668. * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend,
  10669. * resume, or other times. This quirk makes sure that's the case for
  10670. * affected systems.
  10671. */
  10672. static void quirk_pipea_force(struct drm_device *dev)
  10673. {
  10674. struct drm_i915_private *dev_priv = dev->dev_private;
  10675. dev_priv->quirks |= QUIRK_PIPEA_FORCE;
  10676. DRM_INFO("applying pipe a force quirk\n");
  10677. }
  10678. static void quirk_pipeb_force(struct drm_device *dev)
  10679. {
  10680. struct drm_i915_private *dev_priv = dev->dev_private;
  10681. dev_priv->quirks |= QUIRK_PIPEB_FORCE;
  10682. DRM_INFO("applying pipe b force quirk\n");
  10683. }
  10684. /*
  10685. * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason
  10686. */
  10687. static void quirk_ssc_force_disable(struct drm_device *dev)
  10688. {
  10689. struct drm_i915_private *dev_priv = dev->dev_private;
  10690. dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE;
  10691. DRM_INFO("applying lvds SSC disable quirk\n");
  10692. }
  10693. /*
  10694. * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight
  10695. * brightness value
  10696. */
  10697. static void quirk_invert_brightness(struct drm_device *dev)
  10698. {
  10699. struct drm_i915_private *dev_priv = dev->dev_private;
  10700. dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS;
  10701. DRM_INFO("applying inverted panel brightness quirk\n");
  10702. }
  10703. /* Some VBT's incorrectly indicate no backlight is present */
  10704. static void quirk_backlight_present(struct drm_device *dev)
  10705. {
  10706. struct drm_i915_private *dev_priv = dev->dev_private;
  10707. dev_priv->quirks |= QUIRK_BACKLIGHT_PRESENT;
  10708. DRM_INFO("applying backlight present quirk\n");
  10709. }
  10710. struct intel_quirk {
  10711. int device;
  10712. int subsystem_vendor;
  10713. int subsystem_device;
  10714. void (*hook)(struct drm_device *dev);
  10715. };
  10716. /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
  10717. struct intel_dmi_quirk {
  10718. void (*hook)(struct drm_device *dev);
  10719. const struct dmi_system_id (*dmi_id_list)[];
  10720. };
  10721. static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
  10722. {
  10723. DRM_INFO("Backlight polarity reversed on %s\n", id->ident);
  10724. return 1;
  10725. }
  10726. static const struct intel_dmi_quirk intel_dmi_quirks[] = {
  10727. {
  10728. .dmi_id_list = &(const struct dmi_system_id[]) {
  10729. {
  10730. .callback = intel_dmi_reverse_brightness,
  10731. .ident = "NCR Corporation",
  10732. .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
  10733. DMI_MATCH(DMI_PRODUCT_NAME, ""),
  10734. },
  10735. },
  10736. { } /* terminating entry */
  10737. },
  10738. .hook = quirk_invert_brightness,
  10739. },
  10740. };
  10741. static struct intel_quirk intel_quirks[] = {
  10742. /* HP Mini needs pipe A force quirk (LP: #322104) */
  10743. { 0x27ae, 0x103c, 0x361a, quirk_pipea_force },
  10744. /* Toshiba Protege R-205, S-209 needs pipe A force quirk */
  10745. { 0x2592, 0x1179, 0x0001, quirk_pipea_force },
  10746. /* ThinkPad T60 needs pipe A force quirk (bug #16494) */
  10747. { 0x2782, 0x17aa, 0x201a, quirk_pipea_force },
  10748. /* 830 needs to leave pipe A & dpll A up */
  10749. { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force },
  10750. /* 830 needs to leave pipe B & dpll B up */
  10751. { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipeb_force },
  10752. /* Lenovo U160 cannot use SSC on LVDS */
  10753. { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable },
  10754. /* Sony Vaio Y cannot use SSC on LVDS */
  10755. { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable },
  10756. /* Acer Aspire 5734Z must invert backlight brightness */
  10757. { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness },
  10758. /* Acer/eMachines G725 */
  10759. { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness },
  10760. /* Acer/eMachines e725 */
  10761. { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness },
  10762. /* Acer/Packard Bell NCL20 */
  10763. { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness },
  10764. /* Acer Aspire 4736Z */
  10765. { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness },
  10766. /* Acer Aspire 5336 */
  10767. { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness },
  10768. /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */
  10769. { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present },
  10770. /* Acer C720 Chromebook (Core i3 4005U) */
  10771. { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present },
  10772. /* Toshiba CB35 Chromebook (Celeron 2955U) */
  10773. { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present },
  10774. /* HP Chromebook 14 (Celeron 2955U) */
  10775. { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present },
  10776. };
  10777. static void intel_init_quirks(struct drm_device *dev)
  10778. {
  10779. struct pci_dev *d = dev->pdev;
  10780. int i;
  10781. for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) {
  10782. struct intel_quirk *q = &intel_quirks[i];
  10783. if (d->device == q->device &&
  10784. (d->subsystem_vendor == q->subsystem_vendor ||
  10785. q->subsystem_vendor == PCI_ANY_ID) &&
  10786. (d->subsystem_device == q->subsystem_device ||
  10787. q->subsystem_device == PCI_ANY_ID))
  10788. q->hook(dev);
  10789. }
  10790. for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) {
  10791. if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0)
  10792. intel_dmi_quirks[i].hook(dev);
  10793. }
  10794. }
  10795. /* Disable the VGA plane that we never use */
  10796. static void i915_disable_vga(struct drm_device *dev)
  10797. {
  10798. struct drm_i915_private *dev_priv = dev->dev_private;
  10799. u8 sr1;
  10800. u32 vga_reg = i915_vgacntrl_reg(dev);
  10801. /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
  10802. vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO);
  10803. outb(SR01, VGA_SR_INDEX);
  10804. sr1 = inb(VGA_SR_DATA);
  10805. outb(sr1 | 1<<5, VGA_SR_DATA);
  10806. vga_put(dev->pdev, VGA_RSRC_LEGACY_IO);
  10807. udelay(300);
  10808. /*
  10809. * Fujitsu-Siemens Lifebook S6010 (830) has problems resuming
  10810. * from S3 without preserving (some of?) the other bits.
  10811. */
  10812. I915_WRITE(vga_reg, dev_priv->bios_vgacntr | VGA_DISP_DISABLE);
  10813. POSTING_READ(vga_reg);
  10814. }
  10815. void intel_modeset_init_hw(struct drm_device *dev)
  10816. {
  10817. intel_prepare_ddi(dev);
  10818. if (IS_VALLEYVIEW(dev))
  10819. vlv_update_cdclk(dev);
  10820. intel_init_clock_gating(dev);
  10821. intel_enable_gt_powersave(dev);
  10822. }
  10823. void intel_modeset_suspend_hw(struct drm_device *dev)
  10824. {
  10825. intel_suspend_hw(dev);
  10826. }
  10827. void intel_modeset_init(struct drm_device *dev)
  10828. {
  10829. struct drm_i915_private *dev_priv = dev->dev_private;
  10830. int sprite, ret;
  10831. enum pipe pipe;
  10832. struct intel_crtc *crtc;
  10833. drm_mode_config_init(dev);
  10834. dev->mode_config.min_width = 0;
  10835. dev->mode_config.min_height = 0;
  10836. dev->mode_config.preferred_depth = 24;
  10837. dev->mode_config.prefer_shadow = 1;
  10838. dev->mode_config.funcs = &intel_mode_funcs;
  10839. intel_init_quirks(dev);
  10840. intel_init_pm(dev);
  10841. if (INTEL_INFO(dev)->num_pipes == 0)
  10842. return;
  10843. intel_init_display(dev);
  10844. if (IS_GEN2(dev)) {
  10845. dev->mode_config.max_width = 2048;
  10846. dev->mode_config.max_height = 2048;
  10847. } else if (IS_GEN3(dev)) {
  10848. dev->mode_config.max_width = 4096;
  10849. dev->mode_config.max_height = 4096;
  10850. } else {
  10851. dev->mode_config.max_width = 8192;
  10852. dev->mode_config.max_height = 8192;
  10853. }
  10854. if (IS_845G(dev) || IS_I865G(dev)) {
  10855. dev->mode_config.cursor_width = IS_845G(dev) ? 64 : 512;
  10856. dev->mode_config.cursor_height = 1023;
  10857. } else if (IS_GEN2(dev)) {
  10858. dev->mode_config.cursor_width = GEN2_CURSOR_WIDTH;
  10859. dev->mode_config.cursor_height = GEN2_CURSOR_HEIGHT;
  10860. } else {
  10861. dev->mode_config.cursor_width = MAX_CURSOR_WIDTH;
  10862. dev->mode_config.cursor_height = MAX_CURSOR_HEIGHT;
  10863. }
  10864. dev->mode_config.fb_base = dev_priv->gtt.mappable_base;
  10865. DRM_DEBUG_KMS("%d display pipe%s available.\n",
  10866. INTEL_INFO(dev)->num_pipes,
  10867. INTEL_INFO(dev)->num_pipes > 1 ? "s" : "");
  10868. for_each_pipe(dev_priv, pipe) {
  10869. intel_crtc_init(dev, pipe);
  10870. for_each_sprite(pipe, sprite) {
  10871. ret = intel_plane_init(dev, pipe, sprite);
  10872. if (ret)
  10873. DRM_DEBUG_KMS("pipe %c sprite %c init failed: %d\n",
  10874. pipe_name(pipe), sprite_name(pipe, sprite), ret);
  10875. }
  10876. }
  10877. intel_init_dpio(dev);
  10878. intel_shared_dpll_init(dev);
  10879. /* save the BIOS value before clobbering it */
  10880. dev_priv->bios_vgacntr = I915_READ(i915_vgacntrl_reg(dev));
  10881. /* Just disable it once at startup */
  10882. i915_disable_vga(dev);
  10883. intel_setup_outputs(dev);
  10884. /* Just in case the BIOS is doing something questionable. */
  10885. intel_disable_fbc(dev);
  10886. drm_modeset_lock_all(dev);
  10887. intel_modeset_setup_hw_state(dev, false);
  10888. drm_modeset_unlock_all(dev);
  10889. for_each_intel_crtc(dev, crtc) {
  10890. if (!crtc->active)
  10891. continue;
  10892. /*
  10893. * Note that reserving the BIOS fb up front prevents us
  10894. * from stuffing other stolen allocations like the ring
  10895. * on top. This prevents some ugliness at boot time, and
  10896. * can even allow for smooth boot transitions if the BIOS
  10897. * fb is large enough for the active pipe configuration.
  10898. */
  10899. if (dev_priv->display.get_plane_config) {
  10900. dev_priv->display.get_plane_config(crtc,
  10901. &crtc->plane_config);
  10902. /*
  10903. * If the fb is shared between multiple heads, we'll
  10904. * just get the first one.
  10905. */
  10906. intel_find_plane_obj(crtc, &crtc->plane_config);
  10907. }
  10908. }
  10909. }
  10910. static void intel_enable_pipe_a(struct drm_device *dev)
  10911. {
  10912. struct intel_connector *connector;
  10913. struct drm_connector *crt = NULL;
  10914. struct intel_load_detect_pipe load_detect_temp;
  10915. struct drm_modeset_acquire_ctx *ctx = dev->mode_config.acquire_ctx;
  10916. /* We can't just switch on the pipe A, we need to set things up with a
  10917. * proper mode and output configuration. As a gross hack, enable pipe A
  10918. * by enabling the load detect pipe once. */
  10919. list_for_each_entry(connector,
  10920. &dev->mode_config.connector_list,
  10921. base.head) {
  10922. if (connector->encoder->type == INTEL_OUTPUT_ANALOG) {
  10923. crt = &connector->base;
  10924. break;
  10925. }
  10926. }
  10927. if (!crt)
  10928. return;
  10929. if (intel_get_load_detect_pipe(crt, NULL, &load_detect_temp, ctx))
  10930. intel_release_load_detect_pipe(crt, &load_detect_temp);
  10931. }
  10932. static bool
  10933. intel_check_plane_mapping(struct intel_crtc *crtc)
  10934. {
  10935. struct drm_device *dev = crtc->base.dev;
  10936. struct drm_i915_private *dev_priv = dev->dev_private;
  10937. u32 reg, val;
  10938. if (INTEL_INFO(dev)->num_pipes == 1)
  10939. return true;
  10940. reg = DSPCNTR(!crtc->plane);
  10941. val = I915_READ(reg);
  10942. if ((val & DISPLAY_PLANE_ENABLE) &&
  10943. (!!(val & DISPPLANE_SEL_PIPE_MASK) == crtc->pipe))
  10944. return false;
  10945. return true;
  10946. }
  10947. static void intel_sanitize_crtc(struct intel_crtc *crtc)
  10948. {
  10949. struct drm_device *dev = crtc->base.dev;
  10950. struct drm_i915_private *dev_priv = dev->dev_private;
  10951. u32 reg;
  10952. /* Clear any frame start delays used for debugging left by the BIOS */
  10953. reg = PIPECONF(crtc->config.cpu_transcoder);
  10954. I915_WRITE(reg, I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK);
  10955. /* restore vblank interrupts to correct state */
  10956. if (crtc->active) {
  10957. update_scanline_offset(crtc);
  10958. drm_vblank_on(dev, crtc->pipe);
  10959. } else
  10960. drm_vblank_off(dev, crtc->pipe);
  10961. /* We need to sanitize the plane -> pipe mapping first because this will
  10962. * disable the crtc (and hence change the state) if it is wrong. Note
  10963. * that gen4+ has a fixed plane -> pipe mapping. */
  10964. if (INTEL_INFO(dev)->gen < 4 && !intel_check_plane_mapping(crtc)) {
  10965. struct intel_connector *connector;
  10966. bool plane;
  10967. DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n",
  10968. crtc->base.base.id);
  10969. /* Pipe has the wrong plane attached and the plane is active.
  10970. * Temporarily change the plane mapping and disable everything
  10971. * ... */
  10972. plane = crtc->plane;
  10973. crtc->plane = !plane;
  10974. crtc->primary_enabled = true;
  10975. dev_priv->display.crtc_disable(&crtc->base);
  10976. crtc->plane = plane;
  10977. /* ... and break all links. */
  10978. list_for_each_entry(connector, &dev->mode_config.connector_list,
  10979. base.head) {
  10980. if (connector->encoder->base.crtc != &crtc->base)
  10981. continue;
  10982. connector->base.dpms = DRM_MODE_DPMS_OFF;
  10983. connector->base.encoder = NULL;
  10984. }
  10985. /* multiple connectors may have the same encoder:
  10986. * handle them and break crtc link separately */
  10987. list_for_each_entry(connector, &dev->mode_config.connector_list,
  10988. base.head)
  10989. if (connector->encoder->base.crtc == &crtc->base) {
  10990. connector->encoder->base.crtc = NULL;
  10991. connector->encoder->connectors_active = false;
  10992. }
  10993. WARN_ON(crtc->active);
  10994. crtc->base.enabled = false;
  10995. }
  10996. if (dev_priv->quirks & QUIRK_PIPEA_FORCE &&
  10997. crtc->pipe == PIPE_A && !crtc->active) {
  10998. /* BIOS forgot to enable pipe A, this mostly happens after
  10999. * resume. Force-enable the pipe to fix this, the update_dpms
  11000. * call below we restore the pipe to the right state, but leave
  11001. * the required bits on. */
  11002. intel_enable_pipe_a(dev);
  11003. }
  11004. /* Adjust the state of the output pipe according to whether we
  11005. * have active connectors/encoders. */
  11006. intel_crtc_update_dpms(&crtc->base);
  11007. if (crtc->active != crtc->base.enabled) {
  11008. struct intel_encoder *encoder;
  11009. /* This can happen either due to bugs in the get_hw_state
  11010. * functions or because the pipe is force-enabled due to the
  11011. * pipe A quirk. */
  11012. DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n",
  11013. crtc->base.base.id,
  11014. crtc->base.enabled ? "enabled" : "disabled",
  11015. crtc->active ? "enabled" : "disabled");
  11016. crtc->base.enabled = crtc->active;
  11017. /* Because we only establish the connector -> encoder ->
  11018. * crtc links if something is active, this means the
  11019. * crtc is now deactivated. Break the links. connector
  11020. * -> encoder links are only establish when things are
  11021. * actually up, hence no need to break them. */
  11022. WARN_ON(crtc->active);
  11023. for_each_encoder_on_crtc(dev, &crtc->base, encoder) {
  11024. WARN_ON(encoder->connectors_active);
  11025. encoder->base.crtc = NULL;
  11026. }
  11027. }
  11028. if (crtc->active || HAS_GMCH_DISPLAY(dev)) {
  11029. /*
  11030. * We start out with underrun reporting disabled to avoid races.
  11031. * For correct bookkeeping mark this on active crtcs.
  11032. *
  11033. * Also on gmch platforms we dont have any hardware bits to
  11034. * disable the underrun reporting. Which means we need to start
  11035. * out with underrun reporting disabled also on inactive pipes,
  11036. * since otherwise we'll complain about the garbage we read when
  11037. * e.g. coming up after runtime pm.
  11038. *
  11039. * No protection against concurrent access is required - at
  11040. * worst a fifo underrun happens which also sets this to false.
  11041. */
  11042. crtc->cpu_fifo_underrun_disabled = true;
  11043. crtc->pch_fifo_underrun_disabled = true;
  11044. }
  11045. }
  11046. static void intel_sanitize_encoder(struct intel_encoder *encoder)
  11047. {
  11048. struct intel_connector *connector;
  11049. struct drm_device *dev = encoder->base.dev;
  11050. /* We need to check both for a crtc link (meaning that the
  11051. * encoder is active and trying to read from a pipe) and the
  11052. * pipe itself being active. */
  11053. bool has_active_crtc = encoder->base.crtc &&
  11054. to_intel_crtc(encoder->base.crtc)->active;
  11055. if (encoder->connectors_active && !has_active_crtc) {
  11056. DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
  11057. encoder->base.base.id,
  11058. encoder->base.name);
  11059. /* Connector is active, but has no active pipe. This is
  11060. * fallout from our resume register restoring. Disable
  11061. * the encoder manually again. */
  11062. if (encoder->base.crtc) {
  11063. DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
  11064. encoder->base.base.id,
  11065. encoder->base.name);
  11066. encoder->disable(encoder);
  11067. if (encoder->post_disable)
  11068. encoder->post_disable(encoder);
  11069. }
  11070. encoder->base.crtc = NULL;
  11071. encoder->connectors_active = false;
  11072. /* Inconsistent output/port/pipe state happens presumably due to
  11073. * a bug in one of the get_hw_state functions. Or someplace else
  11074. * in our code, like the register restore mess on resume. Clamp
  11075. * things to off as a safer default. */
  11076. list_for_each_entry(connector,
  11077. &dev->mode_config.connector_list,
  11078. base.head) {
  11079. if (connector->encoder != encoder)
  11080. continue;
  11081. connector->base.dpms = DRM_MODE_DPMS_OFF;
  11082. connector->base.encoder = NULL;
  11083. }
  11084. }
  11085. /* Enabled encoders without active connectors will be fixed in
  11086. * the crtc fixup. */
  11087. }
  11088. void i915_redisable_vga_power_on(struct drm_device *dev)
  11089. {
  11090. struct drm_i915_private *dev_priv = dev->dev_private;
  11091. u32 vga_reg = i915_vgacntrl_reg(dev);
  11092. if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) {
  11093. DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
  11094. i915_disable_vga(dev);
  11095. }
  11096. }
  11097. void i915_redisable_vga(struct drm_device *dev)
  11098. {
  11099. struct drm_i915_private *dev_priv = dev->dev_private;
  11100. /* This function can be called both from intel_modeset_setup_hw_state or
  11101. * at a very early point in our resume sequence, where the power well
  11102. * structures are not yet restored. Since this function is at a very
  11103. * paranoid "someone might have enabled VGA while we were not looking"
  11104. * level, just check if the power well is enabled instead of trying to
  11105. * follow the "don't touch the power well if we don't need it" policy
  11106. * the rest of the driver uses. */
  11107. if (!intel_display_power_enabled(dev_priv, POWER_DOMAIN_VGA))
  11108. return;
  11109. i915_redisable_vga_power_on(dev);
  11110. }
  11111. static bool primary_get_hw_state(struct intel_crtc *crtc)
  11112. {
  11113. struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
  11114. if (!crtc->active)
  11115. return false;
  11116. return I915_READ(DSPCNTR(crtc->plane)) & DISPLAY_PLANE_ENABLE;
  11117. }
  11118. static void intel_modeset_readout_hw_state(struct drm_device *dev)
  11119. {
  11120. struct drm_i915_private *dev_priv = dev->dev_private;
  11121. enum pipe pipe;
  11122. struct intel_crtc *crtc;
  11123. struct intel_encoder *encoder;
  11124. struct intel_connector *connector;
  11125. int i;
  11126. for_each_intel_crtc(dev, crtc) {
  11127. memset(&crtc->config, 0, sizeof(crtc->config));
  11128. crtc->config.quirks |= PIPE_CONFIG_QUIRK_INHERITED_MODE;
  11129. crtc->active = dev_priv->display.get_pipe_config(crtc,
  11130. &crtc->config);
  11131. crtc->base.enabled = crtc->active;
  11132. crtc->primary_enabled = primary_get_hw_state(crtc);
  11133. DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n",
  11134. crtc->base.base.id,
  11135. crtc->active ? "enabled" : "disabled");
  11136. }
  11137. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  11138. struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
  11139. pll->on = pll->get_hw_state(dev_priv, pll, &pll->hw_state);
  11140. pll->active = 0;
  11141. for_each_intel_crtc(dev, crtc) {
  11142. if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll)
  11143. pll->active++;
  11144. }
  11145. pll->refcount = pll->active;
  11146. DRM_DEBUG_KMS("%s hw state readout: refcount %i, on %i\n",
  11147. pll->name, pll->refcount, pll->on);
  11148. if (pll->refcount)
  11149. intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS);
  11150. }
  11151. for_each_intel_encoder(dev, encoder) {
  11152. pipe = 0;
  11153. if (encoder->get_hw_state(encoder, &pipe)) {
  11154. crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  11155. encoder->base.crtc = &crtc->base;
  11156. encoder->get_config(encoder, &crtc->config);
  11157. } else {
  11158. encoder->base.crtc = NULL;
  11159. }
  11160. encoder->connectors_active = false;
  11161. DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
  11162. encoder->base.base.id,
  11163. encoder->base.name,
  11164. encoder->base.crtc ? "enabled" : "disabled",
  11165. pipe_name(pipe));
  11166. }
  11167. list_for_each_entry(connector, &dev->mode_config.connector_list,
  11168. base.head) {
  11169. if (connector->get_hw_state(connector)) {
  11170. connector->base.dpms = DRM_MODE_DPMS_ON;
  11171. connector->encoder->connectors_active = true;
  11172. connector->base.encoder = &connector->encoder->base;
  11173. } else {
  11174. connector->base.dpms = DRM_MODE_DPMS_OFF;
  11175. connector->base.encoder = NULL;
  11176. }
  11177. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
  11178. connector->base.base.id,
  11179. connector->base.name,
  11180. connector->base.encoder ? "enabled" : "disabled");
  11181. }
  11182. }
  11183. /* Scan out the current hw modeset state, sanitizes it and maps it into the drm
  11184. * and i915 state tracking structures. */
  11185. void intel_modeset_setup_hw_state(struct drm_device *dev,
  11186. bool force_restore)
  11187. {
  11188. struct drm_i915_private *dev_priv = dev->dev_private;
  11189. enum pipe pipe;
  11190. struct intel_crtc *crtc;
  11191. struct intel_encoder *encoder;
  11192. int i;
  11193. intel_modeset_readout_hw_state(dev);
  11194. /*
  11195. * Now that we have the config, copy it to each CRTC struct
  11196. * Note that this could go away if we move to using crtc_config
  11197. * checking everywhere.
  11198. */
  11199. for_each_intel_crtc(dev, crtc) {
  11200. if (crtc->active && i915.fastboot) {
  11201. intel_mode_from_pipe_config(&crtc->base.mode, &crtc->config);
  11202. DRM_DEBUG_KMS("[CRTC:%d] found active mode: ",
  11203. crtc->base.base.id);
  11204. drm_mode_debug_printmodeline(&crtc->base.mode);
  11205. }
  11206. }
  11207. /* HW state is read out, now we need to sanitize this mess. */
  11208. for_each_intel_encoder(dev, encoder) {
  11209. intel_sanitize_encoder(encoder);
  11210. }
  11211. for_each_pipe(dev_priv, pipe) {
  11212. crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  11213. intel_sanitize_crtc(crtc);
  11214. intel_dump_pipe_config(crtc, &crtc->config, "[setup_hw_state]");
  11215. }
  11216. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  11217. struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
  11218. if (!pll->on || pll->active)
  11219. continue;
  11220. DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll->name);
  11221. pll->disable(dev_priv, pll);
  11222. pll->on = false;
  11223. }
  11224. if (HAS_PCH_SPLIT(dev))
  11225. ilk_wm_get_hw_state(dev);
  11226. if (force_restore) {
  11227. i915_redisable_vga(dev);
  11228. /*
  11229. * We need to use raw interfaces for restoring state to avoid
  11230. * checking (bogus) intermediate states.
  11231. */
  11232. for_each_pipe(dev_priv, pipe) {
  11233. struct drm_crtc *crtc =
  11234. dev_priv->pipe_to_crtc_mapping[pipe];
  11235. __intel_set_mode(crtc, &crtc->mode, crtc->x, crtc->y,
  11236. crtc->primary->fb);
  11237. }
  11238. } else {
  11239. intel_modeset_update_staged_output_state(dev);
  11240. }
  11241. intel_modeset_check_state(dev);
  11242. }
  11243. void intel_modeset_gem_init(struct drm_device *dev)
  11244. {
  11245. struct drm_crtc *c;
  11246. struct drm_i915_gem_object *obj;
  11247. mutex_lock(&dev->struct_mutex);
  11248. intel_init_gt_powersave(dev);
  11249. mutex_unlock(&dev->struct_mutex);
  11250. intel_modeset_init_hw(dev);
  11251. intel_setup_overlay(dev);
  11252. /*
  11253. * Make sure any fbs we allocated at startup are properly
  11254. * pinned & fenced. When we do the allocation it's too early
  11255. * for this.
  11256. */
  11257. mutex_lock(&dev->struct_mutex);
  11258. for_each_crtc(dev, c) {
  11259. obj = intel_fb_obj(c->primary->fb);
  11260. if (obj == NULL)
  11261. continue;
  11262. if (intel_pin_and_fence_fb_obj(dev, obj, NULL)) {
  11263. DRM_ERROR("failed to pin boot fb on pipe %d\n",
  11264. to_intel_crtc(c)->pipe);
  11265. drm_framebuffer_unreference(c->primary->fb);
  11266. c->primary->fb = NULL;
  11267. }
  11268. }
  11269. mutex_unlock(&dev->struct_mutex);
  11270. }
  11271. void intel_connector_unregister(struct intel_connector *intel_connector)
  11272. {
  11273. struct drm_connector *connector = &intel_connector->base;
  11274. intel_panel_destroy_backlight(connector);
  11275. drm_connector_unregister(connector);
  11276. }
  11277. void intel_modeset_cleanup(struct drm_device *dev)
  11278. {
  11279. struct drm_i915_private *dev_priv = dev->dev_private;
  11280. struct drm_connector *connector;
  11281. /*
  11282. * Interrupts and polling as the first thing to avoid creating havoc.
  11283. * Too much stuff here (turning of rps, connectors, ...) would
  11284. * experience fancy races otherwise.
  11285. */
  11286. drm_irq_uninstall(dev);
  11287. intel_hpd_cancel_work(dev_priv);
  11288. dev_priv->pm._irqs_disabled = true;
  11289. /*
  11290. * Due to the hpd irq storm handling the hotplug work can re-arm the
  11291. * poll handlers. Hence disable polling after hpd handling is shut down.
  11292. */
  11293. drm_kms_helper_poll_fini(dev);
  11294. mutex_lock(&dev->struct_mutex);
  11295. intel_unregister_dsm_handler();
  11296. intel_disable_fbc(dev);
  11297. intel_disable_gt_powersave(dev);
  11298. ironlake_teardown_rc6(dev);
  11299. mutex_unlock(&dev->struct_mutex);
  11300. /* flush any delayed tasks or pending work */
  11301. flush_scheduled_work();
  11302. /* destroy the backlight and sysfs files before encoders/connectors */
  11303. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  11304. struct intel_connector *intel_connector;
  11305. intel_connector = to_intel_connector(connector);
  11306. intel_connector->unregister(intel_connector);
  11307. }
  11308. drm_mode_config_cleanup(dev);
  11309. intel_cleanup_overlay(dev);
  11310. mutex_lock(&dev->struct_mutex);
  11311. intel_cleanup_gt_powersave(dev);
  11312. mutex_unlock(&dev->struct_mutex);
  11313. }
  11314. /*
  11315. * Return which encoder is currently attached for connector.
  11316. */
  11317. struct drm_encoder *intel_best_encoder(struct drm_connector *connector)
  11318. {
  11319. return &intel_attached_encoder(connector)->base;
  11320. }
  11321. void intel_connector_attach_encoder(struct intel_connector *connector,
  11322. struct intel_encoder *encoder)
  11323. {
  11324. connector->encoder = encoder;
  11325. drm_mode_connector_attach_encoder(&connector->base,
  11326. &encoder->base);
  11327. }
  11328. /*
  11329. * set vga decode state - true == enable VGA decode
  11330. */
  11331. int intel_modeset_vga_set_state(struct drm_device *dev, bool state)
  11332. {
  11333. struct drm_i915_private *dev_priv = dev->dev_private;
  11334. unsigned reg = INTEL_INFO(dev)->gen >= 6 ? SNB_GMCH_CTRL : INTEL_GMCH_CTRL;
  11335. u16 gmch_ctrl;
  11336. if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) {
  11337. DRM_ERROR("failed to read control word\n");
  11338. return -EIO;
  11339. }
  11340. if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state)
  11341. return 0;
  11342. if (state)
  11343. gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE;
  11344. else
  11345. gmch_ctrl |= INTEL_GMCH_VGA_DISABLE;
  11346. if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) {
  11347. DRM_ERROR("failed to write control word\n");
  11348. return -EIO;
  11349. }
  11350. return 0;
  11351. }
  11352. struct intel_display_error_state {
  11353. u32 power_well_driver;
  11354. int num_transcoders;
  11355. struct intel_cursor_error_state {
  11356. u32 control;
  11357. u32 position;
  11358. u32 base;
  11359. u32 size;
  11360. } cursor[I915_MAX_PIPES];
  11361. struct intel_pipe_error_state {
  11362. bool power_domain_on;
  11363. u32 source;
  11364. u32 stat;
  11365. } pipe[I915_MAX_PIPES];
  11366. struct intel_plane_error_state {
  11367. u32 control;
  11368. u32 stride;
  11369. u32 size;
  11370. u32 pos;
  11371. u32 addr;
  11372. u32 surface;
  11373. u32 tile_offset;
  11374. } plane[I915_MAX_PIPES];
  11375. struct intel_transcoder_error_state {
  11376. bool power_domain_on;
  11377. enum transcoder cpu_transcoder;
  11378. u32 conf;
  11379. u32 htotal;
  11380. u32 hblank;
  11381. u32 hsync;
  11382. u32 vtotal;
  11383. u32 vblank;
  11384. u32 vsync;
  11385. } transcoder[4];
  11386. };
  11387. struct intel_display_error_state *
  11388. intel_display_capture_error_state(struct drm_device *dev)
  11389. {
  11390. struct drm_i915_private *dev_priv = dev->dev_private;
  11391. struct intel_display_error_state *error;
  11392. int transcoders[] = {
  11393. TRANSCODER_A,
  11394. TRANSCODER_B,
  11395. TRANSCODER_C,
  11396. TRANSCODER_EDP,
  11397. };
  11398. int i;
  11399. if (INTEL_INFO(dev)->num_pipes == 0)
  11400. return NULL;
  11401. error = kzalloc(sizeof(*error), GFP_ATOMIC);
  11402. if (error == NULL)
  11403. return NULL;
  11404. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  11405. error->power_well_driver = I915_READ(HSW_PWR_WELL_DRIVER);
  11406. for_each_pipe(dev_priv, i) {
  11407. error->pipe[i].power_domain_on =
  11408. intel_display_power_enabled_unlocked(dev_priv,
  11409. POWER_DOMAIN_PIPE(i));
  11410. if (!error->pipe[i].power_domain_on)
  11411. continue;
  11412. error->cursor[i].control = I915_READ(CURCNTR(i));
  11413. error->cursor[i].position = I915_READ(CURPOS(i));
  11414. error->cursor[i].base = I915_READ(CURBASE(i));
  11415. error->plane[i].control = I915_READ(DSPCNTR(i));
  11416. error->plane[i].stride = I915_READ(DSPSTRIDE(i));
  11417. if (INTEL_INFO(dev)->gen <= 3) {
  11418. error->plane[i].size = I915_READ(DSPSIZE(i));
  11419. error->plane[i].pos = I915_READ(DSPPOS(i));
  11420. }
  11421. if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev))
  11422. error->plane[i].addr = I915_READ(DSPADDR(i));
  11423. if (INTEL_INFO(dev)->gen >= 4) {
  11424. error->plane[i].surface = I915_READ(DSPSURF(i));
  11425. error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i));
  11426. }
  11427. error->pipe[i].source = I915_READ(PIPESRC(i));
  11428. if (HAS_GMCH_DISPLAY(dev))
  11429. error->pipe[i].stat = I915_READ(PIPESTAT(i));
  11430. }
  11431. error->num_transcoders = INTEL_INFO(dev)->num_pipes;
  11432. if (HAS_DDI(dev_priv->dev))
  11433. error->num_transcoders++; /* Account for eDP. */
  11434. for (i = 0; i < error->num_transcoders; i++) {
  11435. enum transcoder cpu_transcoder = transcoders[i];
  11436. error->transcoder[i].power_domain_on =
  11437. intel_display_power_enabled_unlocked(dev_priv,
  11438. POWER_DOMAIN_TRANSCODER(cpu_transcoder));
  11439. if (!error->transcoder[i].power_domain_on)
  11440. continue;
  11441. error->transcoder[i].cpu_transcoder = cpu_transcoder;
  11442. error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder));
  11443. error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder));
  11444. error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder));
  11445. error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder));
  11446. error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder));
  11447. error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder));
  11448. error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder));
  11449. }
  11450. return error;
  11451. }
  11452. #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
  11453. void
  11454. intel_display_print_error_state(struct drm_i915_error_state_buf *m,
  11455. struct drm_device *dev,
  11456. struct intel_display_error_state *error)
  11457. {
  11458. struct drm_i915_private *dev_priv = dev->dev_private;
  11459. int i;
  11460. if (!error)
  11461. return;
  11462. err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev)->num_pipes);
  11463. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  11464. err_printf(m, "PWR_WELL_CTL2: %08x\n",
  11465. error->power_well_driver);
  11466. for_each_pipe(dev_priv, i) {
  11467. err_printf(m, "Pipe [%d]:\n", i);
  11468. err_printf(m, " Power: %s\n",
  11469. error->pipe[i].power_domain_on ? "on" : "off");
  11470. err_printf(m, " SRC: %08x\n", error->pipe[i].source);
  11471. err_printf(m, " STAT: %08x\n", error->pipe[i].stat);
  11472. err_printf(m, "Plane [%d]:\n", i);
  11473. err_printf(m, " CNTR: %08x\n", error->plane[i].control);
  11474. err_printf(m, " STRIDE: %08x\n", error->plane[i].stride);
  11475. if (INTEL_INFO(dev)->gen <= 3) {
  11476. err_printf(m, " SIZE: %08x\n", error->plane[i].size);
  11477. err_printf(m, " POS: %08x\n", error->plane[i].pos);
  11478. }
  11479. if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev))
  11480. err_printf(m, " ADDR: %08x\n", error->plane[i].addr);
  11481. if (INTEL_INFO(dev)->gen >= 4) {
  11482. err_printf(m, " SURF: %08x\n", error->plane[i].surface);
  11483. err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset);
  11484. }
  11485. err_printf(m, "Cursor [%d]:\n", i);
  11486. err_printf(m, " CNTR: %08x\n", error->cursor[i].control);
  11487. err_printf(m, " POS: %08x\n", error->cursor[i].position);
  11488. err_printf(m, " BASE: %08x\n", error->cursor[i].base);
  11489. }
  11490. for (i = 0; i < error->num_transcoders; i++) {
  11491. err_printf(m, "CPU transcoder: %c\n",
  11492. transcoder_name(error->transcoder[i].cpu_transcoder));
  11493. err_printf(m, " Power: %s\n",
  11494. error->transcoder[i].power_domain_on ? "on" : "off");
  11495. err_printf(m, " CONF: %08x\n", error->transcoder[i].conf);
  11496. err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal);
  11497. err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank);
  11498. err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync);
  11499. err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal);
  11500. err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank);
  11501. err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync);
  11502. }
  11503. }
  11504. void intel_modeset_preclose(struct drm_device *dev, struct drm_file *file)
  11505. {
  11506. struct intel_crtc *crtc;
  11507. for_each_intel_crtc(dev, crtc) {
  11508. struct intel_unpin_work *work;
  11509. unsigned long irqflags;
  11510. spin_lock_irqsave(&dev->event_lock, irqflags);
  11511. work = crtc->unpin_work;
  11512. if (work && work->event &&
  11513. work->event->base.file_priv == file) {
  11514. kfree(work->event);
  11515. work->event = NULL;
  11516. }
  11517. spin_unlock_irqrestore(&dev->event_lock, irqflags);
  11518. }
  11519. }