intel_display.c 378 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741
  1. /*
  2. * Copyright © 2006-2007 Intel Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  21. * DEALINGS IN THE SOFTWARE.
  22. *
  23. * Authors:
  24. * Eric Anholt <eric@anholt.net>
  25. */
  26. #include <linux/dmi.h>
  27. #include <linux/module.h>
  28. #include <linux/input.h>
  29. #include <linux/i2c.h>
  30. #include <linux/kernel.h>
  31. #include <linux/slab.h>
  32. #include <linux/vgaarb.h>
  33. #include <drm/drm_edid.h>
  34. #include <drm/drmP.h>
  35. #include "intel_drv.h"
  36. #include <drm/i915_drm.h>
  37. #include "i915_drv.h"
  38. #include "i915_trace.h"
  39. #include <drm/drm_dp_helper.h>
  40. #include <drm/drm_crtc_helper.h>
  41. #include <drm/drm_plane_helper.h>
  42. #include <drm/drm_rect.h>
  43. #include <linux/dma_remapping.h>
  44. /* Primary plane formats supported by all gen */
  45. #define COMMON_PRIMARY_FORMATS \
  46. DRM_FORMAT_C8, \
  47. DRM_FORMAT_RGB565, \
  48. DRM_FORMAT_XRGB8888, \
  49. DRM_FORMAT_ARGB8888
  50. /* Primary plane formats for gen <= 3 */
  51. static const uint32_t intel_primary_formats_gen2[] = {
  52. COMMON_PRIMARY_FORMATS,
  53. DRM_FORMAT_XRGB1555,
  54. DRM_FORMAT_ARGB1555,
  55. };
  56. /* Primary plane formats for gen >= 4 */
  57. static const uint32_t intel_primary_formats_gen4[] = {
  58. COMMON_PRIMARY_FORMATS, \
  59. DRM_FORMAT_XBGR8888,
  60. DRM_FORMAT_ABGR8888,
  61. DRM_FORMAT_XRGB2101010,
  62. DRM_FORMAT_ARGB2101010,
  63. DRM_FORMAT_XBGR2101010,
  64. DRM_FORMAT_ABGR2101010,
  65. };
  66. /* Cursor formats */
  67. static const uint32_t intel_cursor_formats[] = {
  68. DRM_FORMAT_ARGB8888,
  69. };
  70. static void intel_crtc_update_cursor(struct drm_crtc *crtc, bool on);
  71. static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
  72. struct intel_crtc_config *pipe_config);
  73. static void ironlake_pch_clock_get(struct intel_crtc *crtc,
  74. struct intel_crtc_config *pipe_config);
  75. static int intel_set_mode(struct drm_crtc *crtc, struct drm_display_mode *mode,
  76. int x, int y, struct drm_framebuffer *old_fb);
  77. static int intel_framebuffer_init(struct drm_device *dev,
  78. struct intel_framebuffer *ifb,
  79. struct drm_mode_fb_cmd2 *mode_cmd,
  80. struct drm_i915_gem_object *obj);
  81. static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc);
  82. static void intel_set_pipe_timings(struct intel_crtc *intel_crtc);
  83. static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc,
  84. struct intel_link_m_n *m_n,
  85. struct intel_link_m_n *m2_n2);
  86. static void ironlake_set_pipeconf(struct drm_crtc *crtc);
  87. static void haswell_set_pipeconf(struct drm_crtc *crtc);
  88. static void intel_set_pipe_csc(struct drm_crtc *crtc);
  89. static void vlv_prepare_pll(struct intel_crtc *crtc);
  90. static void chv_prepare_pll(struct intel_crtc *crtc);
  91. static struct intel_encoder *intel_find_encoder(struct intel_connector *connector, int pipe)
  92. {
  93. if (!connector->mst_port)
  94. return connector->encoder;
  95. else
  96. return &connector->mst_port->mst_encoders[pipe]->base;
  97. }
  98. typedef struct {
  99. int min, max;
  100. } intel_range_t;
  101. typedef struct {
  102. int dot_limit;
  103. int p2_slow, p2_fast;
  104. } intel_p2_t;
  105. typedef struct intel_limit intel_limit_t;
  106. struct intel_limit {
  107. intel_range_t dot, vco, n, m, m1, m2, p, p1;
  108. intel_p2_t p2;
  109. };
  110. int
  111. intel_pch_rawclk(struct drm_device *dev)
  112. {
  113. struct drm_i915_private *dev_priv = dev->dev_private;
  114. WARN_ON(!HAS_PCH_SPLIT(dev));
  115. return I915_READ(PCH_RAWCLK_FREQ) & RAWCLK_FREQ_MASK;
  116. }
  117. static inline u32 /* units of 100MHz */
  118. intel_fdi_link_freq(struct drm_device *dev)
  119. {
  120. if (IS_GEN5(dev)) {
  121. struct drm_i915_private *dev_priv = dev->dev_private;
  122. return (I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK) + 2;
  123. } else
  124. return 27;
  125. }
  126. static const intel_limit_t intel_limits_i8xx_dac = {
  127. .dot = { .min = 25000, .max = 350000 },
  128. .vco = { .min = 908000, .max = 1512000 },
  129. .n = { .min = 2, .max = 16 },
  130. .m = { .min = 96, .max = 140 },
  131. .m1 = { .min = 18, .max = 26 },
  132. .m2 = { .min = 6, .max = 16 },
  133. .p = { .min = 4, .max = 128 },
  134. .p1 = { .min = 2, .max = 33 },
  135. .p2 = { .dot_limit = 165000,
  136. .p2_slow = 4, .p2_fast = 2 },
  137. };
  138. static const intel_limit_t intel_limits_i8xx_dvo = {
  139. .dot = { .min = 25000, .max = 350000 },
  140. .vco = { .min = 908000, .max = 1512000 },
  141. .n = { .min = 2, .max = 16 },
  142. .m = { .min = 96, .max = 140 },
  143. .m1 = { .min = 18, .max = 26 },
  144. .m2 = { .min = 6, .max = 16 },
  145. .p = { .min = 4, .max = 128 },
  146. .p1 = { .min = 2, .max = 33 },
  147. .p2 = { .dot_limit = 165000,
  148. .p2_slow = 4, .p2_fast = 4 },
  149. };
  150. static const intel_limit_t intel_limits_i8xx_lvds = {
  151. .dot = { .min = 25000, .max = 350000 },
  152. .vco = { .min = 908000, .max = 1512000 },
  153. .n = { .min = 2, .max = 16 },
  154. .m = { .min = 96, .max = 140 },
  155. .m1 = { .min = 18, .max = 26 },
  156. .m2 = { .min = 6, .max = 16 },
  157. .p = { .min = 4, .max = 128 },
  158. .p1 = { .min = 1, .max = 6 },
  159. .p2 = { .dot_limit = 165000,
  160. .p2_slow = 14, .p2_fast = 7 },
  161. };
  162. static const intel_limit_t intel_limits_i9xx_sdvo = {
  163. .dot = { .min = 20000, .max = 400000 },
  164. .vco = { .min = 1400000, .max = 2800000 },
  165. .n = { .min = 1, .max = 6 },
  166. .m = { .min = 70, .max = 120 },
  167. .m1 = { .min = 8, .max = 18 },
  168. .m2 = { .min = 3, .max = 7 },
  169. .p = { .min = 5, .max = 80 },
  170. .p1 = { .min = 1, .max = 8 },
  171. .p2 = { .dot_limit = 200000,
  172. .p2_slow = 10, .p2_fast = 5 },
  173. };
  174. static const intel_limit_t intel_limits_i9xx_lvds = {
  175. .dot = { .min = 20000, .max = 400000 },
  176. .vco = { .min = 1400000, .max = 2800000 },
  177. .n = { .min = 1, .max = 6 },
  178. .m = { .min = 70, .max = 120 },
  179. .m1 = { .min = 8, .max = 18 },
  180. .m2 = { .min = 3, .max = 7 },
  181. .p = { .min = 7, .max = 98 },
  182. .p1 = { .min = 1, .max = 8 },
  183. .p2 = { .dot_limit = 112000,
  184. .p2_slow = 14, .p2_fast = 7 },
  185. };
  186. static const intel_limit_t intel_limits_g4x_sdvo = {
  187. .dot = { .min = 25000, .max = 270000 },
  188. .vco = { .min = 1750000, .max = 3500000},
  189. .n = { .min = 1, .max = 4 },
  190. .m = { .min = 104, .max = 138 },
  191. .m1 = { .min = 17, .max = 23 },
  192. .m2 = { .min = 5, .max = 11 },
  193. .p = { .min = 10, .max = 30 },
  194. .p1 = { .min = 1, .max = 3},
  195. .p2 = { .dot_limit = 270000,
  196. .p2_slow = 10,
  197. .p2_fast = 10
  198. },
  199. };
  200. static const intel_limit_t intel_limits_g4x_hdmi = {
  201. .dot = { .min = 22000, .max = 400000 },
  202. .vco = { .min = 1750000, .max = 3500000},
  203. .n = { .min = 1, .max = 4 },
  204. .m = { .min = 104, .max = 138 },
  205. .m1 = { .min = 16, .max = 23 },
  206. .m2 = { .min = 5, .max = 11 },
  207. .p = { .min = 5, .max = 80 },
  208. .p1 = { .min = 1, .max = 8},
  209. .p2 = { .dot_limit = 165000,
  210. .p2_slow = 10, .p2_fast = 5 },
  211. };
  212. static const intel_limit_t intel_limits_g4x_single_channel_lvds = {
  213. .dot = { .min = 20000, .max = 115000 },
  214. .vco = { .min = 1750000, .max = 3500000 },
  215. .n = { .min = 1, .max = 3 },
  216. .m = { .min = 104, .max = 138 },
  217. .m1 = { .min = 17, .max = 23 },
  218. .m2 = { .min = 5, .max = 11 },
  219. .p = { .min = 28, .max = 112 },
  220. .p1 = { .min = 2, .max = 8 },
  221. .p2 = { .dot_limit = 0,
  222. .p2_slow = 14, .p2_fast = 14
  223. },
  224. };
  225. static const intel_limit_t intel_limits_g4x_dual_channel_lvds = {
  226. .dot = { .min = 80000, .max = 224000 },
  227. .vco = { .min = 1750000, .max = 3500000 },
  228. .n = { .min = 1, .max = 3 },
  229. .m = { .min = 104, .max = 138 },
  230. .m1 = { .min = 17, .max = 23 },
  231. .m2 = { .min = 5, .max = 11 },
  232. .p = { .min = 14, .max = 42 },
  233. .p1 = { .min = 2, .max = 6 },
  234. .p2 = { .dot_limit = 0,
  235. .p2_slow = 7, .p2_fast = 7
  236. },
  237. };
  238. static const intel_limit_t intel_limits_pineview_sdvo = {
  239. .dot = { .min = 20000, .max = 400000},
  240. .vco = { .min = 1700000, .max = 3500000 },
  241. /* Pineview's Ncounter is a ring counter */
  242. .n = { .min = 3, .max = 6 },
  243. .m = { .min = 2, .max = 256 },
  244. /* Pineview only has one combined m divider, which we treat as m2. */
  245. .m1 = { .min = 0, .max = 0 },
  246. .m2 = { .min = 0, .max = 254 },
  247. .p = { .min = 5, .max = 80 },
  248. .p1 = { .min = 1, .max = 8 },
  249. .p2 = { .dot_limit = 200000,
  250. .p2_slow = 10, .p2_fast = 5 },
  251. };
  252. static const intel_limit_t intel_limits_pineview_lvds = {
  253. .dot = { .min = 20000, .max = 400000 },
  254. .vco = { .min = 1700000, .max = 3500000 },
  255. .n = { .min = 3, .max = 6 },
  256. .m = { .min = 2, .max = 256 },
  257. .m1 = { .min = 0, .max = 0 },
  258. .m2 = { .min = 0, .max = 254 },
  259. .p = { .min = 7, .max = 112 },
  260. .p1 = { .min = 1, .max = 8 },
  261. .p2 = { .dot_limit = 112000,
  262. .p2_slow = 14, .p2_fast = 14 },
  263. };
  264. /* Ironlake / Sandybridge
  265. *
  266. * We calculate clock using (register_value + 2) for N/M1/M2, so here
  267. * the range value for them is (actual_value - 2).
  268. */
  269. static const intel_limit_t intel_limits_ironlake_dac = {
  270. .dot = { .min = 25000, .max = 350000 },
  271. .vco = { .min = 1760000, .max = 3510000 },
  272. .n = { .min = 1, .max = 5 },
  273. .m = { .min = 79, .max = 127 },
  274. .m1 = { .min = 12, .max = 22 },
  275. .m2 = { .min = 5, .max = 9 },
  276. .p = { .min = 5, .max = 80 },
  277. .p1 = { .min = 1, .max = 8 },
  278. .p2 = { .dot_limit = 225000,
  279. .p2_slow = 10, .p2_fast = 5 },
  280. };
  281. static const intel_limit_t intel_limits_ironlake_single_lvds = {
  282. .dot = { .min = 25000, .max = 350000 },
  283. .vco = { .min = 1760000, .max = 3510000 },
  284. .n = { .min = 1, .max = 3 },
  285. .m = { .min = 79, .max = 118 },
  286. .m1 = { .min = 12, .max = 22 },
  287. .m2 = { .min = 5, .max = 9 },
  288. .p = { .min = 28, .max = 112 },
  289. .p1 = { .min = 2, .max = 8 },
  290. .p2 = { .dot_limit = 225000,
  291. .p2_slow = 14, .p2_fast = 14 },
  292. };
  293. static const intel_limit_t intel_limits_ironlake_dual_lvds = {
  294. .dot = { .min = 25000, .max = 350000 },
  295. .vco = { .min = 1760000, .max = 3510000 },
  296. .n = { .min = 1, .max = 3 },
  297. .m = { .min = 79, .max = 127 },
  298. .m1 = { .min = 12, .max = 22 },
  299. .m2 = { .min = 5, .max = 9 },
  300. .p = { .min = 14, .max = 56 },
  301. .p1 = { .min = 2, .max = 8 },
  302. .p2 = { .dot_limit = 225000,
  303. .p2_slow = 7, .p2_fast = 7 },
  304. };
  305. /* LVDS 100mhz refclk limits. */
  306. static const intel_limit_t intel_limits_ironlake_single_lvds_100m = {
  307. .dot = { .min = 25000, .max = 350000 },
  308. .vco = { .min = 1760000, .max = 3510000 },
  309. .n = { .min = 1, .max = 2 },
  310. .m = { .min = 79, .max = 126 },
  311. .m1 = { .min = 12, .max = 22 },
  312. .m2 = { .min = 5, .max = 9 },
  313. .p = { .min = 28, .max = 112 },
  314. .p1 = { .min = 2, .max = 8 },
  315. .p2 = { .dot_limit = 225000,
  316. .p2_slow = 14, .p2_fast = 14 },
  317. };
  318. static const intel_limit_t intel_limits_ironlake_dual_lvds_100m = {
  319. .dot = { .min = 25000, .max = 350000 },
  320. .vco = { .min = 1760000, .max = 3510000 },
  321. .n = { .min = 1, .max = 3 },
  322. .m = { .min = 79, .max = 126 },
  323. .m1 = { .min = 12, .max = 22 },
  324. .m2 = { .min = 5, .max = 9 },
  325. .p = { .min = 14, .max = 42 },
  326. .p1 = { .min = 2, .max = 6 },
  327. .p2 = { .dot_limit = 225000,
  328. .p2_slow = 7, .p2_fast = 7 },
  329. };
  330. static const intel_limit_t intel_limits_vlv = {
  331. /*
  332. * These are the data rate limits (measured in fast clocks)
  333. * since those are the strictest limits we have. The fast
  334. * clock and actual rate limits are more relaxed, so checking
  335. * them would make no difference.
  336. */
  337. .dot = { .min = 25000 * 5, .max = 270000 * 5 },
  338. .vco = { .min = 4000000, .max = 6000000 },
  339. .n = { .min = 1, .max = 7 },
  340. .m1 = { .min = 2, .max = 3 },
  341. .m2 = { .min = 11, .max = 156 },
  342. .p1 = { .min = 2, .max = 3 },
  343. .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */
  344. };
  345. static const intel_limit_t intel_limits_chv = {
  346. /*
  347. * These are the data rate limits (measured in fast clocks)
  348. * since those are the strictest limits we have. The fast
  349. * clock and actual rate limits are more relaxed, so checking
  350. * them would make no difference.
  351. */
  352. .dot = { .min = 25000 * 5, .max = 540000 * 5},
  353. .vco = { .min = 4860000, .max = 6700000 },
  354. .n = { .min = 1, .max = 1 },
  355. .m1 = { .min = 2, .max = 2 },
  356. .m2 = { .min = 24 << 22, .max = 175 << 22 },
  357. .p1 = { .min = 2, .max = 4 },
  358. .p2 = { .p2_slow = 1, .p2_fast = 14 },
  359. };
  360. static void vlv_clock(int refclk, intel_clock_t *clock)
  361. {
  362. clock->m = clock->m1 * clock->m2;
  363. clock->p = clock->p1 * clock->p2;
  364. if (WARN_ON(clock->n == 0 || clock->p == 0))
  365. return;
  366. clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
  367. clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
  368. }
  369. /**
  370. * Returns whether any output on the specified pipe is of the specified type
  371. */
  372. static bool intel_pipe_has_type(struct intel_crtc *crtc, int type)
  373. {
  374. struct drm_device *dev = crtc->base.dev;
  375. struct intel_encoder *encoder;
  376. for_each_encoder_on_crtc(dev, &crtc->base, encoder)
  377. if (encoder->type == type)
  378. return true;
  379. return false;
  380. }
  381. static const intel_limit_t *intel_ironlake_limit(struct intel_crtc *crtc,
  382. int refclk)
  383. {
  384. struct drm_device *dev = crtc->base.dev;
  385. const intel_limit_t *limit;
  386. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  387. if (intel_is_dual_link_lvds(dev)) {
  388. if (refclk == 100000)
  389. limit = &intel_limits_ironlake_dual_lvds_100m;
  390. else
  391. limit = &intel_limits_ironlake_dual_lvds;
  392. } else {
  393. if (refclk == 100000)
  394. limit = &intel_limits_ironlake_single_lvds_100m;
  395. else
  396. limit = &intel_limits_ironlake_single_lvds;
  397. }
  398. } else
  399. limit = &intel_limits_ironlake_dac;
  400. return limit;
  401. }
  402. static const intel_limit_t *intel_g4x_limit(struct intel_crtc *crtc)
  403. {
  404. struct drm_device *dev = crtc->base.dev;
  405. const intel_limit_t *limit;
  406. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  407. if (intel_is_dual_link_lvds(dev))
  408. limit = &intel_limits_g4x_dual_channel_lvds;
  409. else
  410. limit = &intel_limits_g4x_single_channel_lvds;
  411. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI) ||
  412. intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG)) {
  413. limit = &intel_limits_g4x_hdmi;
  414. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO)) {
  415. limit = &intel_limits_g4x_sdvo;
  416. } else /* The option is for other outputs */
  417. limit = &intel_limits_i9xx_sdvo;
  418. return limit;
  419. }
  420. static const intel_limit_t *intel_limit(struct intel_crtc *crtc, int refclk)
  421. {
  422. struct drm_device *dev = crtc->base.dev;
  423. const intel_limit_t *limit;
  424. if (HAS_PCH_SPLIT(dev))
  425. limit = intel_ironlake_limit(crtc, refclk);
  426. else if (IS_G4X(dev)) {
  427. limit = intel_g4x_limit(crtc);
  428. } else if (IS_PINEVIEW(dev)) {
  429. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  430. limit = &intel_limits_pineview_lvds;
  431. else
  432. limit = &intel_limits_pineview_sdvo;
  433. } else if (IS_CHERRYVIEW(dev)) {
  434. limit = &intel_limits_chv;
  435. } else if (IS_VALLEYVIEW(dev)) {
  436. limit = &intel_limits_vlv;
  437. } else if (!IS_GEN2(dev)) {
  438. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  439. limit = &intel_limits_i9xx_lvds;
  440. else
  441. limit = &intel_limits_i9xx_sdvo;
  442. } else {
  443. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  444. limit = &intel_limits_i8xx_lvds;
  445. else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO))
  446. limit = &intel_limits_i8xx_dvo;
  447. else
  448. limit = &intel_limits_i8xx_dac;
  449. }
  450. return limit;
  451. }
  452. /* m1 is reserved as 0 in Pineview, n is a ring counter */
  453. static void pineview_clock(int refclk, intel_clock_t *clock)
  454. {
  455. clock->m = clock->m2 + 2;
  456. clock->p = clock->p1 * clock->p2;
  457. if (WARN_ON(clock->n == 0 || clock->p == 0))
  458. return;
  459. clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
  460. clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
  461. }
  462. static uint32_t i9xx_dpll_compute_m(struct dpll *dpll)
  463. {
  464. return 5 * (dpll->m1 + 2) + (dpll->m2 + 2);
  465. }
  466. static void i9xx_clock(int refclk, intel_clock_t *clock)
  467. {
  468. clock->m = i9xx_dpll_compute_m(clock);
  469. clock->p = clock->p1 * clock->p2;
  470. if (WARN_ON(clock->n + 2 == 0 || clock->p == 0))
  471. return;
  472. clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2);
  473. clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
  474. }
  475. static void chv_clock(int refclk, intel_clock_t *clock)
  476. {
  477. clock->m = clock->m1 * clock->m2;
  478. clock->p = clock->p1 * clock->p2;
  479. if (WARN_ON(clock->n == 0 || clock->p == 0))
  480. return;
  481. clock->vco = DIV_ROUND_CLOSEST_ULL((uint64_t)refclk * clock->m,
  482. clock->n << 22);
  483. clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
  484. }
  485. #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
  486. /**
  487. * Returns whether the given set of divisors are valid for a given refclk with
  488. * the given connectors.
  489. */
  490. static bool intel_PLL_is_valid(struct drm_device *dev,
  491. const intel_limit_t *limit,
  492. const intel_clock_t *clock)
  493. {
  494. if (clock->n < limit->n.min || limit->n.max < clock->n)
  495. INTELPllInvalid("n out of range\n");
  496. if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1)
  497. INTELPllInvalid("p1 out of range\n");
  498. if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2)
  499. INTELPllInvalid("m2 out of range\n");
  500. if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1)
  501. INTELPllInvalid("m1 out of range\n");
  502. if (!IS_PINEVIEW(dev) && !IS_VALLEYVIEW(dev))
  503. if (clock->m1 <= clock->m2)
  504. INTELPllInvalid("m1 <= m2\n");
  505. if (!IS_VALLEYVIEW(dev)) {
  506. if (clock->p < limit->p.min || limit->p.max < clock->p)
  507. INTELPllInvalid("p out of range\n");
  508. if (clock->m < limit->m.min || limit->m.max < clock->m)
  509. INTELPllInvalid("m out of range\n");
  510. }
  511. if (clock->vco < limit->vco.min || limit->vco.max < clock->vco)
  512. INTELPllInvalid("vco out of range\n");
  513. /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
  514. * connector, etc., rather than just a single range.
  515. */
  516. if (clock->dot < limit->dot.min || limit->dot.max < clock->dot)
  517. INTELPllInvalid("dot out of range\n");
  518. return true;
  519. }
  520. static bool
  521. i9xx_find_best_dpll(const intel_limit_t *limit, struct intel_crtc *crtc,
  522. int target, int refclk, intel_clock_t *match_clock,
  523. intel_clock_t *best_clock)
  524. {
  525. struct drm_device *dev = crtc->base.dev;
  526. intel_clock_t clock;
  527. int err = target;
  528. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  529. /*
  530. * For LVDS just rely on its current settings for dual-channel.
  531. * We haven't figured out how to reliably set up different
  532. * single/dual channel state, if we even can.
  533. */
  534. if (intel_is_dual_link_lvds(dev))
  535. clock.p2 = limit->p2.p2_fast;
  536. else
  537. clock.p2 = limit->p2.p2_slow;
  538. } else {
  539. if (target < limit->p2.dot_limit)
  540. clock.p2 = limit->p2.p2_slow;
  541. else
  542. clock.p2 = limit->p2.p2_fast;
  543. }
  544. memset(best_clock, 0, sizeof(*best_clock));
  545. for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
  546. clock.m1++) {
  547. for (clock.m2 = limit->m2.min;
  548. clock.m2 <= limit->m2.max; clock.m2++) {
  549. if (clock.m2 >= clock.m1)
  550. break;
  551. for (clock.n = limit->n.min;
  552. clock.n <= limit->n.max; clock.n++) {
  553. for (clock.p1 = limit->p1.min;
  554. clock.p1 <= limit->p1.max; clock.p1++) {
  555. int this_err;
  556. i9xx_clock(refclk, &clock);
  557. if (!intel_PLL_is_valid(dev, limit,
  558. &clock))
  559. continue;
  560. if (match_clock &&
  561. clock.p != match_clock->p)
  562. continue;
  563. this_err = abs(clock.dot - target);
  564. if (this_err < err) {
  565. *best_clock = clock;
  566. err = this_err;
  567. }
  568. }
  569. }
  570. }
  571. }
  572. return (err != target);
  573. }
  574. static bool
  575. pnv_find_best_dpll(const intel_limit_t *limit, struct intel_crtc *crtc,
  576. int target, int refclk, intel_clock_t *match_clock,
  577. intel_clock_t *best_clock)
  578. {
  579. struct drm_device *dev = crtc->base.dev;
  580. intel_clock_t clock;
  581. int err = target;
  582. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  583. /*
  584. * For LVDS just rely on its current settings for dual-channel.
  585. * We haven't figured out how to reliably set up different
  586. * single/dual channel state, if we even can.
  587. */
  588. if (intel_is_dual_link_lvds(dev))
  589. clock.p2 = limit->p2.p2_fast;
  590. else
  591. clock.p2 = limit->p2.p2_slow;
  592. } else {
  593. if (target < limit->p2.dot_limit)
  594. clock.p2 = limit->p2.p2_slow;
  595. else
  596. clock.p2 = limit->p2.p2_fast;
  597. }
  598. memset(best_clock, 0, sizeof(*best_clock));
  599. for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
  600. clock.m1++) {
  601. for (clock.m2 = limit->m2.min;
  602. clock.m2 <= limit->m2.max; clock.m2++) {
  603. for (clock.n = limit->n.min;
  604. clock.n <= limit->n.max; clock.n++) {
  605. for (clock.p1 = limit->p1.min;
  606. clock.p1 <= limit->p1.max; clock.p1++) {
  607. int this_err;
  608. pineview_clock(refclk, &clock);
  609. if (!intel_PLL_is_valid(dev, limit,
  610. &clock))
  611. continue;
  612. if (match_clock &&
  613. clock.p != match_clock->p)
  614. continue;
  615. this_err = abs(clock.dot - target);
  616. if (this_err < err) {
  617. *best_clock = clock;
  618. err = this_err;
  619. }
  620. }
  621. }
  622. }
  623. }
  624. return (err != target);
  625. }
  626. static bool
  627. g4x_find_best_dpll(const intel_limit_t *limit, struct intel_crtc *crtc,
  628. int target, int refclk, intel_clock_t *match_clock,
  629. intel_clock_t *best_clock)
  630. {
  631. struct drm_device *dev = crtc->base.dev;
  632. intel_clock_t clock;
  633. int max_n;
  634. bool found;
  635. /* approximately equals target * 0.00585 */
  636. int err_most = (target >> 8) + (target >> 9);
  637. found = false;
  638. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  639. if (intel_is_dual_link_lvds(dev))
  640. clock.p2 = limit->p2.p2_fast;
  641. else
  642. clock.p2 = limit->p2.p2_slow;
  643. } else {
  644. if (target < limit->p2.dot_limit)
  645. clock.p2 = limit->p2.p2_slow;
  646. else
  647. clock.p2 = limit->p2.p2_fast;
  648. }
  649. memset(best_clock, 0, sizeof(*best_clock));
  650. max_n = limit->n.max;
  651. /* based on hardware requirement, prefer smaller n to precision */
  652. for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
  653. /* based on hardware requirement, prefere larger m1,m2 */
  654. for (clock.m1 = limit->m1.max;
  655. clock.m1 >= limit->m1.min; clock.m1--) {
  656. for (clock.m2 = limit->m2.max;
  657. clock.m2 >= limit->m2.min; clock.m2--) {
  658. for (clock.p1 = limit->p1.max;
  659. clock.p1 >= limit->p1.min; clock.p1--) {
  660. int this_err;
  661. i9xx_clock(refclk, &clock);
  662. if (!intel_PLL_is_valid(dev, limit,
  663. &clock))
  664. continue;
  665. this_err = abs(clock.dot - target);
  666. if (this_err < err_most) {
  667. *best_clock = clock;
  668. err_most = this_err;
  669. max_n = clock.n;
  670. found = true;
  671. }
  672. }
  673. }
  674. }
  675. }
  676. return found;
  677. }
  678. static bool
  679. vlv_find_best_dpll(const intel_limit_t *limit, struct intel_crtc *crtc,
  680. int target, int refclk, intel_clock_t *match_clock,
  681. intel_clock_t *best_clock)
  682. {
  683. struct drm_device *dev = crtc->base.dev;
  684. intel_clock_t clock;
  685. unsigned int bestppm = 1000000;
  686. /* min update 19.2 MHz */
  687. int max_n = min(limit->n.max, refclk / 19200);
  688. bool found = false;
  689. target *= 5; /* fast clock */
  690. memset(best_clock, 0, sizeof(*best_clock));
  691. /* based on hardware requirement, prefer smaller n to precision */
  692. for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
  693. for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
  694. for (clock.p2 = limit->p2.p2_fast; clock.p2 >= limit->p2.p2_slow;
  695. clock.p2 -= clock.p2 > 10 ? 2 : 1) {
  696. clock.p = clock.p1 * clock.p2;
  697. /* based on hardware requirement, prefer bigger m1,m2 values */
  698. for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) {
  699. unsigned int ppm, diff;
  700. clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n,
  701. refclk * clock.m1);
  702. vlv_clock(refclk, &clock);
  703. if (!intel_PLL_is_valid(dev, limit,
  704. &clock))
  705. continue;
  706. diff = abs(clock.dot - target);
  707. ppm = div_u64(1000000ULL * diff, target);
  708. if (ppm < 100 && clock.p > best_clock->p) {
  709. bestppm = 0;
  710. *best_clock = clock;
  711. found = true;
  712. }
  713. if (bestppm >= 10 && ppm < bestppm - 10) {
  714. bestppm = ppm;
  715. *best_clock = clock;
  716. found = true;
  717. }
  718. }
  719. }
  720. }
  721. }
  722. return found;
  723. }
  724. static bool
  725. chv_find_best_dpll(const intel_limit_t *limit, struct intel_crtc *crtc,
  726. int target, int refclk, intel_clock_t *match_clock,
  727. intel_clock_t *best_clock)
  728. {
  729. struct drm_device *dev = crtc->base.dev;
  730. intel_clock_t clock;
  731. uint64_t m2;
  732. int found = false;
  733. memset(best_clock, 0, sizeof(*best_clock));
  734. /*
  735. * Based on hardware doc, the n always set to 1, and m1 always
  736. * set to 2. If requires to support 200Mhz refclk, we need to
  737. * revisit this because n may not 1 anymore.
  738. */
  739. clock.n = 1, clock.m1 = 2;
  740. target *= 5; /* fast clock */
  741. for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
  742. for (clock.p2 = limit->p2.p2_fast;
  743. clock.p2 >= limit->p2.p2_slow;
  744. clock.p2 -= clock.p2 > 10 ? 2 : 1) {
  745. clock.p = clock.p1 * clock.p2;
  746. m2 = DIV_ROUND_CLOSEST_ULL(((uint64_t)target * clock.p *
  747. clock.n) << 22, refclk * clock.m1);
  748. if (m2 > INT_MAX/clock.m1)
  749. continue;
  750. clock.m2 = m2;
  751. chv_clock(refclk, &clock);
  752. if (!intel_PLL_is_valid(dev, limit, &clock))
  753. continue;
  754. /* based on hardware requirement, prefer bigger p
  755. */
  756. if (clock.p > best_clock->p) {
  757. *best_clock = clock;
  758. found = true;
  759. }
  760. }
  761. }
  762. return found;
  763. }
  764. bool intel_crtc_active(struct drm_crtc *crtc)
  765. {
  766. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  767. /* Be paranoid as we can arrive here with only partial
  768. * state retrieved from the hardware during setup.
  769. *
  770. * We can ditch the adjusted_mode.crtc_clock check as soon
  771. * as Haswell has gained clock readout/fastboot support.
  772. *
  773. * We can ditch the crtc->primary->fb check as soon as we can
  774. * properly reconstruct framebuffers.
  775. */
  776. return intel_crtc->active && crtc->primary->fb &&
  777. intel_crtc->config.adjusted_mode.crtc_clock;
  778. }
  779. enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv,
  780. enum pipe pipe)
  781. {
  782. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  783. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  784. return intel_crtc->config.cpu_transcoder;
  785. }
  786. static bool pipe_dsl_stopped(struct drm_device *dev, enum pipe pipe)
  787. {
  788. struct drm_i915_private *dev_priv = dev->dev_private;
  789. u32 reg = PIPEDSL(pipe);
  790. u32 line1, line2;
  791. u32 line_mask;
  792. if (IS_GEN2(dev))
  793. line_mask = DSL_LINEMASK_GEN2;
  794. else
  795. line_mask = DSL_LINEMASK_GEN3;
  796. line1 = I915_READ(reg) & line_mask;
  797. mdelay(5);
  798. line2 = I915_READ(reg) & line_mask;
  799. return line1 == line2;
  800. }
  801. /*
  802. * intel_wait_for_pipe_off - wait for pipe to turn off
  803. * @crtc: crtc whose pipe to wait for
  804. *
  805. * After disabling a pipe, we can't wait for vblank in the usual way,
  806. * spinning on the vblank interrupt status bit, since we won't actually
  807. * see an interrupt when the pipe is disabled.
  808. *
  809. * On Gen4 and above:
  810. * wait for the pipe register state bit to turn off
  811. *
  812. * Otherwise:
  813. * wait for the display line value to settle (it usually
  814. * ends up stopping at the start of the next frame).
  815. *
  816. */
  817. static void intel_wait_for_pipe_off(struct intel_crtc *crtc)
  818. {
  819. struct drm_device *dev = crtc->base.dev;
  820. struct drm_i915_private *dev_priv = dev->dev_private;
  821. enum transcoder cpu_transcoder = crtc->config.cpu_transcoder;
  822. enum pipe pipe = crtc->pipe;
  823. if (INTEL_INFO(dev)->gen >= 4) {
  824. int reg = PIPECONF(cpu_transcoder);
  825. /* Wait for the Pipe State to go off */
  826. if (wait_for((I915_READ(reg) & I965_PIPECONF_ACTIVE) == 0,
  827. 100))
  828. WARN(1, "pipe_off wait timed out\n");
  829. } else {
  830. /* Wait for the display line to settle */
  831. if (wait_for(pipe_dsl_stopped(dev, pipe), 100))
  832. WARN(1, "pipe_off wait timed out\n");
  833. }
  834. }
  835. /*
  836. * ibx_digital_port_connected - is the specified port connected?
  837. * @dev_priv: i915 private structure
  838. * @port: the port to test
  839. *
  840. * Returns true if @port is connected, false otherwise.
  841. */
  842. bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
  843. struct intel_digital_port *port)
  844. {
  845. u32 bit;
  846. if (HAS_PCH_IBX(dev_priv->dev)) {
  847. switch (port->port) {
  848. case PORT_B:
  849. bit = SDE_PORTB_HOTPLUG;
  850. break;
  851. case PORT_C:
  852. bit = SDE_PORTC_HOTPLUG;
  853. break;
  854. case PORT_D:
  855. bit = SDE_PORTD_HOTPLUG;
  856. break;
  857. default:
  858. return true;
  859. }
  860. } else {
  861. switch (port->port) {
  862. case PORT_B:
  863. bit = SDE_PORTB_HOTPLUG_CPT;
  864. break;
  865. case PORT_C:
  866. bit = SDE_PORTC_HOTPLUG_CPT;
  867. break;
  868. case PORT_D:
  869. bit = SDE_PORTD_HOTPLUG_CPT;
  870. break;
  871. default:
  872. return true;
  873. }
  874. }
  875. return I915_READ(SDEISR) & bit;
  876. }
  877. static const char *state_string(bool enabled)
  878. {
  879. return enabled ? "on" : "off";
  880. }
  881. /* Only for pre-ILK configs */
  882. void assert_pll(struct drm_i915_private *dev_priv,
  883. enum pipe pipe, bool state)
  884. {
  885. int reg;
  886. u32 val;
  887. bool cur_state;
  888. reg = DPLL(pipe);
  889. val = I915_READ(reg);
  890. cur_state = !!(val & DPLL_VCO_ENABLE);
  891. WARN(cur_state != state,
  892. "PLL state assertion failure (expected %s, current %s)\n",
  893. state_string(state), state_string(cur_state));
  894. }
  895. /* XXX: the dsi pll is shared between MIPI DSI ports */
  896. static void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state)
  897. {
  898. u32 val;
  899. bool cur_state;
  900. mutex_lock(&dev_priv->dpio_lock);
  901. val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL);
  902. mutex_unlock(&dev_priv->dpio_lock);
  903. cur_state = val & DSI_PLL_VCO_EN;
  904. WARN(cur_state != state,
  905. "DSI PLL state assertion failure (expected %s, current %s)\n",
  906. state_string(state), state_string(cur_state));
  907. }
  908. #define assert_dsi_pll_enabled(d) assert_dsi_pll(d, true)
  909. #define assert_dsi_pll_disabled(d) assert_dsi_pll(d, false)
  910. struct intel_shared_dpll *
  911. intel_crtc_to_shared_dpll(struct intel_crtc *crtc)
  912. {
  913. struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
  914. if (crtc->config.shared_dpll < 0)
  915. return NULL;
  916. return &dev_priv->shared_dplls[crtc->config.shared_dpll];
  917. }
  918. /* For ILK+ */
  919. void assert_shared_dpll(struct drm_i915_private *dev_priv,
  920. struct intel_shared_dpll *pll,
  921. bool state)
  922. {
  923. bool cur_state;
  924. struct intel_dpll_hw_state hw_state;
  925. if (WARN (!pll,
  926. "asserting DPLL %s with no DPLL\n", state_string(state)))
  927. return;
  928. cur_state = pll->get_hw_state(dev_priv, pll, &hw_state);
  929. WARN(cur_state != state,
  930. "%s assertion failure (expected %s, current %s)\n",
  931. pll->name, state_string(state), state_string(cur_state));
  932. }
  933. static void assert_fdi_tx(struct drm_i915_private *dev_priv,
  934. enum pipe pipe, bool state)
  935. {
  936. int reg;
  937. u32 val;
  938. bool cur_state;
  939. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  940. pipe);
  941. if (HAS_DDI(dev_priv->dev)) {
  942. /* DDI does not have a specific FDI_TX register */
  943. reg = TRANS_DDI_FUNC_CTL(cpu_transcoder);
  944. val = I915_READ(reg);
  945. cur_state = !!(val & TRANS_DDI_FUNC_ENABLE);
  946. } else {
  947. reg = FDI_TX_CTL(pipe);
  948. val = I915_READ(reg);
  949. cur_state = !!(val & FDI_TX_ENABLE);
  950. }
  951. WARN(cur_state != state,
  952. "FDI TX state assertion failure (expected %s, current %s)\n",
  953. state_string(state), state_string(cur_state));
  954. }
  955. #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
  956. #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
  957. static void assert_fdi_rx(struct drm_i915_private *dev_priv,
  958. enum pipe pipe, bool state)
  959. {
  960. int reg;
  961. u32 val;
  962. bool cur_state;
  963. reg = FDI_RX_CTL(pipe);
  964. val = I915_READ(reg);
  965. cur_state = !!(val & FDI_RX_ENABLE);
  966. WARN(cur_state != state,
  967. "FDI RX state assertion failure (expected %s, current %s)\n",
  968. state_string(state), state_string(cur_state));
  969. }
  970. #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
  971. #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
  972. static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv,
  973. enum pipe pipe)
  974. {
  975. int reg;
  976. u32 val;
  977. /* ILK FDI PLL is always enabled */
  978. if (INTEL_INFO(dev_priv->dev)->gen == 5)
  979. return;
  980. /* On Haswell, DDI ports are responsible for the FDI PLL setup */
  981. if (HAS_DDI(dev_priv->dev))
  982. return;
  983. reg = FDI_TX_CTL(pipe);
  984. val = I915_READ(reg);
  985. WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n");
  986. }
  987. void assert_fdi_rx_pll(struct drm_i915_private *dev_priv,
  988. enum pipe pipe, bool state)
  989. {
  990. int reg;
  991. u32 val;
  992. bool cur_state;
  993. reg = FDI_RX_CTL(pipe);
  994. val = I915_READ(reg);
  995. cur_state = !!(val & FDI_RX_PLL_ENABLE);
  996. WARN(cur_state != state,
  997. "FDI RX PLL assertion failure (expected %s, current %s)\n",
  998. state_string(state), state_string(cur_state));
  999. }
  1000. void assert_panel_unlocked(struct drm_i915_private *dev_priv,
  1001. enum pipe pipe)
  1002. {
  1003. struct drm_device *dev = dev_priv->dev;
  1004. int pp_reg;
  1005. u32 val;
  1006. enum pipe panel_pipe = PIPE_A;
  1007. bool locked = true;
  1008. if (WARN_ON(HAS_DDI(dev)))
  1009. return;
  1010. if (HAS_PCH_SPLIT(dev)) {
  1011. u32 port_sel;
  1012. pp_reg = PCH_PP_CONTROL;
  1013. port_sel = I915_READ(PCH_PP_ON_DELAYS) & PANEL_PORT_SELECT_MASK;
  1014. if (port_sel == PANEL_PORT_SELECT_LVDS &&
  1015. I915_READ(PCH_LVDS) & LVDS_PIPEB_SELECT)
  1016. panel_pipe = PIPE_B;
  1017. /* XXX: else fix for eDP */
  1018. } else if (IS_VALLEYVIEW(dev)) {
  1019. /* presumably write lock depends on pipe, not port select */
  1020. pp_reg = VLV_PIPE_PP_CONTROL(pipe);
  1021. panel_pipe = pipe;
  1022. } else {
  1023. pp_reg = PP_CONTROL;
  1024. if (I915_READ(LVDS) & LVDS_PIPEB_SELECT)
  1025. panel_pipe = PIPE_B;
  1026. }
  1027. val = I915_READ(pp_reg);
  1028. if (!(val & PANEL_POWER_ON) ||
  1029. ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS))
  1030. locked = false;
  1031. WARN(panel_pipe == pipe && locked,
  1032. "panel assertion failure, pipe %c regs locked\n",
  1033. pipe_name(pipe));
  1034. }
  1035. static void assert_cursor(struct drm_i915_private *dev_priv,
  1036. enum pipe pipe, bool state)
  1037. {
  1038. struct drm_device *dev = dev_priv->dev;
  1039. bool cur_state;
  1040. if (IS_845G(dev) || IS_I865G(dev))
  1041. cur_state = I915_READ(_CURACNTR) & CURSOR_ENABLE;
  1042. else
  1043. cur_state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
  1044. WARN(cur_state != state,
  1045. "cursor on pipe %c assertion failure (expected %s, current %s)\n",
  1046. pipe_name(pipe), state_string(state), state_string(cur_state));
  1047. }
  1048. #define assert_cursor_enabled(d, p) assert_cursor(d, p, true)
  1049. #define assert_cursor_disabled(d, p) assert_cursor(d, p, false)
  1050. void assert_pipe(struct drm_i915_private *dev_priv,
  1051. enum pipe pipe, bool state)
  1052. {
  1053. int reg;
  1054. u32 val;
  1055. bool cur_state;
  1056. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  1057. pipe);
  1058. /* if we need the pipe quirk it must be always on */
  1059. if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) ||
  1060. (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))
  1061. state = true;
  1062. if (!intel_display_power_is_enabled(dev_priv,
  1063. POWER_DOMAIN_TRANSCODER(cpu_transcoder))) {
  1064. cur_state = false;
  1065. } else {
  1066. reg = PIPECONF(cpu_transcoder);
  1067. val = I915_READ(reg);
  1068. cur_state = !!(val & PIPECONF_ENABLE);
  1069. }
  1070. WARN(cur_state != state,
  1071. "pipe %c assertion failure (expected %s, current %s)\n",
  1072. pipe_name(pipe), state_string(state), state_string(cur_state));
  1073. }
  1074. static void assert_plane(struct drm_i915_private *dev_priv,
  1075. enum plane plane, bool state)
  1076. {
  1077. int reg;
  1078. u32 val;
  1079. bool cur_state;
  1080. reg = DSPCNTR(plane);
  1081. val = I915_READ(reg);
  1082. cur_state = !!(val & DISPLAY_PLANE_ENABLE);
  1083. WARN(cur_state != state,
  1084. "plane %c assertion failure (expected %s, current %s)\n",
  1085. plane_name(plane), state_string(state), state_string(cur_state));
  1086. }
  1087. #define assert_plane_enabled(d, p) assert_plane(d, p, true)
  1088. #define assert_plane_disabled(d, p) assert_plane(d, p, false)
  1089. static void assert_planes_disabled(struct drm_i915_private *dev_priv,
  1090. enum pipe pipe)
  1091. {
  1092. struct drm_device *dev = dev_priv->dev;
  1093. int reg, i;
  1094. u32 val;
  1095. int cur_pipe;
  1096. /* Primary planes are fixed to pipes on gen4+ */
  1097. if (INTEL_INFO(dev)->gen >= 4) {
  1098. reg = DSPCNTR(pipe);
  1099. val = I915_READ(reg);
  1100. WARN(val & DISPLAY_PLANE_ENABLE,
  1101. "plane %c assertion failure, should be disabled but not\n",
  1102. plane_name(pipe));
  1103. return;
  1104. }
  1105. /* Need to check both planes against the pipe */
  1106. for_each_pipe(dev_priv, i) {
  1107. reg = DSPCNTR(i);
  1108. val = I915_READ(reg);
  1109. cur_pipe = (val & DISPPLANE_SEL_PIPE_MASK) >>
  1110. DISPPLANE_SEL_PIPE_SHIFT;
  1111. WARN((val & DISPLAY_PLANE_ENABLE) && pipe == cur_pipe,
  1112. "plane %c assertion failure, should be off on pipe %c but is still active\n",
  1113. plane_name(i), pipe_name(pipe));
  1114. }
  1115. }
  1116. static void assert_sprites_disabled(struct drm_i915_private *dev_priv,
  1117. enum pipe pipe)
  1118. {
  1119. struct drm_device *dev = dev_priv->dev;
  1120. int reg, sprite;
  1121. u32 val;
  1122. if (INTEL_INFO(dev)->gen >= 9) {
  1123. for_each_sprite(pipe, sprite) {
  1124. val = I915_READ(PLANE_CTL(pipe, sprite));
  1125. WARN(val & PLANE_CTL_ENABLE,
  1126. "plane %d assertion failure, should be off on pipe %c but is still active\n",
  1127. sprite, pipe_name(pipe));
  1128. }
  1129. } else if (IS_VALLEYVIEW(dev)) {
  1130. for_each_sprite(pipe, sprite) {
  1131. reg = SPCNTR(pipe, sprite);
  1132. val = I915_READ(reg);
  1133. WARN(val & SP_ENABLE,
  1134. "sprite %c assertion failure, should be off on pipe %c but is still active\n",
  1135. sprite_name(pipe, sprite), pipe_name(pipe));
  1136. }
  1137. } else if (INTEL_INFO(dev)->gen >= 7) {
  1138. reg = SPRCTL(pipe);
  1139. val = I915_READ(reg);
  1140. WARN(val & SPRITE_ENABLE,
  1141. "sprite %c assertion failure, should be off on pipe %c but is still active\n",
  1142. plane_name(pipe), pipe_name(pipe));
  1143. } else if (INTEL_INFO(dev)->gen >= 5) {
  1144. reg = DVSCNTR(pipe);
  1145. val = I915_READ(reg);
  1146. WARN(val & DVS_ENABLE,
  1147. "sprite %c assertion failure, should be off on pipe %c but is still active\n",
  1148. plane_name(pipe), pipe_name(pipe));
  1149. }
  1150. }
  1151. static void assert_vblank_disabled(struct drm_crtc *crtc)
  1152. {
  1153. if (WARN_ON(drm_crtc_vblank_get(crtc) == 0))
  1154. drm_crtc_vblank_put(crtc);
  1155. }
  1156. static void ibx_assert_pch_refclk_enabled(struct drm_i915_private *dev_priv)
  1157. {
  1158. u32 val;
  1159. bool enabled;
  1160. WARN_ON(!(HAS_PCH_IBX(dev_priv->dev) || HAS_PCH_CPT(dev_priv->dev)));
  1161. val = I915_READ(PCH_DREF_CONTROL);
  1162. enabled = !!(val & (DREF_SSC_SOURCE_MASK | DREF_NONSPREAD_SOURCE_MASK |
  1163. DREF_SUPERSPREAD_SOURCE_MASK));
  1164. WARN(!enabled, "PCH refclk assertion failure, should be active but is disabled\n");
  1165. }
  1166. static void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv,
  1167. enum pipe pipe)
  1168. {
  1169. int reg;
  1170. u32 val;
  1171. bool enabled;
  1172. reg = PCH_TRANSCONF(pipe);
  1173. val = I915_READ(reg);
  1174. enabled = !!(val & TRANS_ENABLE);
  1175. WARN(enabled,
  1176. "transcoder assertion failed, should be off on pipe %c but is still active\n",
  1177. pipe_name(pipe));
  1178. }
  1179. static bool dp_pipe_enabled(struct drm_i915_private *dev_priv,
  1180. enum pipe pipe, u32 port_sel, u32 val)
  1181. {
  1182. if ((val & DP_PORT_EN) == 0)
  1183. return false;
  1184. if (HAS_PCH_CPT(dev_priv->dev)) {
  1185. u32 trans_dp_ctl_reg = TRANS_DP_CTL(pipe);
  1186. u32 trans_dp_ctl = I915_READ(trans_dp_ctl_reg);
  1187. if ((trans_dp_ctl & TRANS_DP_PORT_SEL_MASK) != port_sel)
  1188. return false;
  1189. } else if (IS_CHERRYVIEW(dev_priv->dev)) {
  1190. if ((val & DP_PIPE_MASK_CHV) != DP_PIPE_SELECT_CHV(pipe))
  1191. return false;
  1192. } else {
  1193. if ((val & DP_PIPE_MASK) != (pipe << 30))
  1194. return false;
  1195. }
  1196. return true;
  1197. }
  1198. static bool hdmi_pipe_enabled(struct drm_i915_private *dev_priv,
  1199. enum pipe pipe, u32 val)
  1200. {
  1201. if ((val & SDVO_ENABLE) == 0)
  1202. return false;
  1203. if (HAS_PCH_CPT(dev_priv->dev)) {
  1204. if ((val & SDVO_PIPE_SEL_MASK_CPT) != SDVO_PIPE_SEL_CPT(pipe))
  1205. return false;
  1206. } else if (IS_CHERRYVIEW(dev_priv->dev)) {
  1207. if ((val & SDVO_PIPE_SEL_MASK_CHV) != SDVO_PIPE_SEL_CHV(pipe))
  1208. return false;
  1209. } else {
  1210. if ((val & SDVO_PIPE_SEL_MASK) != SDVO_PIPE_SEL(pipe))
  1211. return false;
  1212. }
  1213. return true;
  1214. }
  1215. static bool lvds_pipe_enabled(struct drm_i915_private *dev_priv,
  1216. enum pipe pipe, u32 val)
  1217. {
  1218. if ((val & LVDS_PORT_EN) == 0)
  1219. return false;
  1220. if (HAS_PCH_CPT(dev_priv->dev)) {
  1221. if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe))
  1222. return false;
  1223. } else {
  1224. if ((val & LVDS_PIPE_MASK) != LVDS_PIPE(pipe))
  1225. return false;
  1226. }
  1227. return true;
  1228. }
  1229. static bool adpa_pipe_enabled(struct drm_i915_private *dev_priv,
  1230. enum pipe pipe, u32 val)
  1231. {
  1232. if ((val & ADPA_DAC_ENABLE) == 0)
  1233. return false;
  1234. if (HAS_PCH_CPT(dev_priv->dev)) {
  1235. if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe))
  1236. return false;
  1237. } else {
  1238. if ((val & ADPA_PIPE_SELECT_MASK) != ADPA_PIPE_SELECT(pipe))
  1239. return false;
  1240. }
  1241. return true;
  1242. }
  1243. static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv,
  1244. enum pipe pipe, int reg, u32 port_sel)
  1245. {
  1246. u32 val = I915_READ(reg);
  1247. WARN(dp_pipe_enabled(dev_priv, pipe, port_sel, val),
  1248. "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n",
  1249. reg, pipe_name(pipe));
  1250. WARN(HAS_PCH_IBX(dev_priv->dev) && (val & DP_PORT_EN) == 0
  1251. && (val & DP_PIPEB_SELECT),
  1252. "IBX PCH dp port still using transcoder B\n");
  1253. }
  1254. static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv,
  1255. enum pipe pipe, int reg)
  1256. {
  1257. u32 val = I915_READ(reg);
  1258. WARN(hdmi_pipe_enabled(dev_priv, pipe, val),
  1259. "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n",
  1260. reg, pipe_name(pipe));
  1261. WARN(HAS_PCH_IBX(dev_priv->dev) && (val & SDVO_ENABLE) == 0
  1262. && (val & SDVO_PIPE_B_SELECT),
  1263. "IBX PCH hdmi port still using transcoder B\n");
  1264. }
  1265. static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv,
  1266. enum pipe pipe)
  1267. {
  1268. int reg;
  1269. u32 val;
  1270. assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_B, TRANS_DP_PORT_SEL_B);
  1271. assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_C, TRANS_DP_PORT_SEL_C);
  1272. assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_D, TRANS_DP_PORT_SEL_D);
  1273. reg = PCH_ADPA;
  1274. val = I915_READ(reg);
  1275. WARN(adpa_pipe_enabled(dev_priv, pipe, val),
  1276. "PCH VGA enabled on transcoder %c, should be disabled\n",
  1277. pipe_name(pipe));
  1278. reg = PCH_LVDS;
  1279. val = I915_READ(reg);
  1280. WARN(lvds_pipe_enabled(dev_priv, pipe, val),
  1281. "PCH LVDS enabled on transcoder %c, should be disabled\n",
  1282. pipe_name(pipe));
  1283. assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIB);
  1284. assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIC);
  1285. assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMID);
  1286. }
  1287. static void intel_init_dpio(struct drm_device *dev)
  1288. {
  1289. struct drm_i915_private *dev_priv = dev->dev_private;
  1290. if (!IS_VALLEYVIEW(dev))
  1291. return;
  1292. /*
  1293. * IOSF_PORT_DPIO is used for VLV x2 PHY (DP/HDMI B and C),
  1294. * CHV x1 PHY (DP/HDMI D)
  1295. * IOSF_PORT_DPIO_2 is used for CHV x2 PHY (DP/HDMI B and C)
  1296. */
  1297. if (IS_CHERRYVIEW(dev)) {
  1298. DPIO_PHY_IOSF_PORT(DPIO_PHY0) = IOSF_PORT_DPIO_2;
  1299. DPIO_PHY_IOSF_PORT(DPIO_PHY1) = IOSF_PORT_DPIO;
  1300. } else {
  1301. DPIO_PHY_IOSF_PORT(DPIO_PHY0) = IOSF_PORT_DPIO;
  1302. }
  1303. }
  1304. static void vlv_enable_pll(struct intel_crtc *crtc)
  1305. {
  1306. struct drm_device *dev = crtc->base.dev;
  1307. struct drm_i915_private *dev_priv = dev->dev_private;
  1308. int reg = DPLL(crtc->pipe);
  1309. u32 dpll = crtc->config.dpll_hw_state.dpll;
  1310. assert_pipe_disabled(dev_priv, crtc->pipe);
  1311. /* No really, not for ILK+ */
  1312. BUG_ON(!IS_VALLEYVIEW(dev_priv->dev));
  1313. /* PLL is protected by panel, make sure we can write it */
  1314. if (IS_MOBILE(dev_priv->dev))
  1315. assert_panel_unlocked(dev_priv, crtc->pipe);
  1316. I915_WRITE(reg, dpll);
  1317. POSTING_READ(reg);
  1318. udelay(150);
  1319. if (wait_for(((I915_READ(reg) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1))
  1320. DRM_ERROR("DPLL %d failed to lock\n", crtc->pipe);
  1321. I915_WRITE(DPLL_MD(crtc->pipe), crtc->config.dpll_hw_state.dpll_md);
  1322. POSTING_READ(DPLL_MD(crtc->pipe));
  1323. /* We do this three times for luck */
  1324. I915_WRITE(reg, dpll);
  1325. POSTING_READ(reg);
  1326. udelay(150); /* wait for warmup */
  1327. I915_WRITE(reg, dpll);
  1328. POSTING_READ(reg);
  1329. udelay(150); /* wait for warmup */
  1330. I915_WRITE(reg, dpll);
  1331. POSTING_READ(reg);
  1332. udelay(150); /* wait for warmup */
  1333. }
  1334. static void chv_enable_pll(struct intel_crtc *crtc)
  1335. {
  1336. struct drm_device *dev = crtc->base.dev;
  1337. struct drm_i915_private *dev_priv = dev->dev_private;
  1338. int pipe = crtc->pipe;
  1339. enum dpio_channel port = vlv_pipe_to_channel(pipe);
  1340. u32 tmp;
  1341. assert_pipe_disabled(dev_priv, crtc->pipe);
  1342. BUG_ON(!IS_CHERRYVIEW(dev_priv->dev));
  1343. mutex_lock(&dev_priv->dpio_lock);
  1344. /* Enable back the 10bit clock to display controller */
  1345. tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
  1346. tmp |= DPIO_DCLKP_EN;
  1347. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp);
  1348. /*
  1349. * Need to wait > 100ns between dclkp clock enable bit and PLL enable.
  1350. */
  1351. udelay(1);
  1352. /* Enable PLL */
  1353. I915_WRITE(DPLL(pipe), crtc->config.dpll_hw_state.dpll);
  1354. /* Check PLL is locked */
  1355. if (wait_for(((I915_READ(DPLL(pipe)) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1))
  1356. DRM_ERROR("PLL %d failed to lock\n", pipe);
  1357. /* not sure when this should be written */
  1358. I915_WRITE(DPLL_MD(pipe), crtc->config.dpll_hw_state.dpll_md);
  1359. POSTING_READ(DPLL_MD(pipe));
  1360. mutex_unlock(&dev_priv->dpio_lock);
  1361. }
  1362. static int intel_num_dvo_pipes(struct drm_device *dev)
  1363. {
  1364. struct intel_crtc *crtc;
  1365. int count = 0;
  1366. for_each_intel_crtc(dev, crtc)
  1367. count += crtc->active &&
  1368. intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO);
  1369. return count;
  1370. }
  1371. static void i9xx_enable_pll(struct intel_crtc *crtc)
  1372. {
  1373. struct drm_device *dev = crtc->base.dev;
  1374. struct drm_i915_private *dev_priv = dev->dev_private;
  1375. int reg = DPLL(crtc->pipe);
  1376. u32 dpll = crtc->config.dpll_hw_state.dpll;
  1377. assert_pipe_disabled(dev_priv, crtc->pipe);
  1378. /* No really, not for ILK+ */
  1379. BUG_ON(INTEL_INFO(dev)->gen >= 5);
  1380. /* PLL is protected by panel, make sure we can write it */
  1381. if (IS_MOBILE(dev) && !IS_I830(dev))
  1382. assert_panel_unlocked(dev_priv, crtc->pipe);
  1383. /* Enable DVO 2x clock on both PLLs if necessary */
  1384. if (IS_I830(dev) && intel_num_dvo_pipes(dev) > 0) {
  1385. /*
  1386. * It appears to be important that we don't enable this
  1387. * for the current pipe before otherwise configuring the
  1388. * PLL. No idea how this should be handled if multiple
  1389. * DVO outputs are enabled simultaneosly.
  1390. */
  1391. dpll |= DPLL_DVO_2X_MODE;
  1392. I915_WRITE(DPLL(!crtc->pipe),
  1393. I915_READ(DPLL(!crtc->pipe)) | DPLL_DVO_2X_MODE);
  1394. }
  1395. /* Wait for the clocks to stabilize. */
  1396. POSTING_READ(reg);
  1397. udelay(150);
  1398. if (INTEL_INFO(dev)->gen >= 4) {
  1399. I915_WRITE(DPLL_MD(crtc->pipe),
  1400. crtc->config.dpll_hw_state.dpll_md);
  1401. } else {
  1402. /* The pixel multiplier can only be updated once the
  1403. * DPLL is enabled and the clocks are stable.
  1404. *
  1405. * So write it again.
  1406. */
  1407. I915_WRITE(reg, dpll);
  1408. }
  1409. /* We do this three times for luck */
  1410. I915_WRITE(reg, dpll);
  1411. POSTING_READ(reg);
  1412. udelay(150); /* wait for warmup */
  1413. I915_WRITE(reg, dpll);
  1414. POSTING_READ(reg);
  1415. udelay(150); /* wait for warmup */
  1416. I915_WRITE(reg, dpll);
  1417. POSTING_READ(reg);
  1418. udelay(150); /* wait for warmup */
  1419. }
  1420. /**
  1421. * i9xx_disable_pll - disable a PLL
  1422. * @dev_priv: i915 private structure
  1423. * @pipe: pipe PLL to disable
  1424. *
  1425. * Disable the PLL for @pipe, making sure the pipe is off first.
  1426. *
  1427. * Note! This is for pre-ILK only.
  1428. */
  1429. static void i9xx_disable_pll(struct intel_crtc *crtc)
  1430. {
  1431. struct drm_device *dev = crtc->base.dev;
  1432. struct drm_i915_private *dev_priv = dev->dev_private;
  1433. enum pipe pipe = crtc->pipe;
  1434. /* Disable DVO 2x clock on both PLLs if necessary */
  1435. if (IS_I830(dev) &&
  1436. intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO) &&
  1437. intel_num_dvo_pipes(dev) == 1) {
  1438. I915_WRITE(DPLL(PIPE_B),
  1439. I915_READ(DPLL(PIPE_B)) & ~DPLL_DVO_2X_MODE);
  1440. I915_WRITE(DPLL(PIPE_A),
  1441. I915_READ(DPLL(PIPE_A)) & ~DPLL_DVO_2X_MODE);
  1442. }
  1443. /* Don't disable pipe or pipe PLLs if needed */
  1444. if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) ||
  1445. (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))
  1446. return;
  1447. /* Make sure the pipe isn't still relying on us */
  1448. assert_pipe_disabled(dev_priv, pipe);
  1449. I915_WRITE(DPLL(pipe), 0);
  1450. POSTING_READ(DPLL(pipe));
  1451. }
  1452. static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
  1453. {
  1454. u32 val = 0;
  1455. /* Make sure the pipe isn't still relying on us */
  1456. assert_pipe_disabled(dev_priv, pipe);
  1457. /*
  1458. * Leave integrated clock source and reference clock enabled for pipe B.
  1459. * The latter is needed for VGA hotplug / manual detection.
  1460. */
  1461. if (pipe == PIPE_B)
  1462. val = DPLL_INTEGRATED_CRI_CLK_VLV | DPLL_REFA_CLK_ENABLE_VLV;
  1463. I915_WRITE(DPLL(pipe), val);
  1464. POSTING_READ(DPLL(pipe));
  1465. }
  1466. static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
  1467. {
  1468. enum dpio_channel port = vlv_pipe_to_channel(pipe);
  1469. u32 val;
  1470. /* Make sure the pipe isn't still relying on us */
  1471. assert_pipe_disabled(dev_priv, pipe);
  1472. /* Set PLL en = 0 */
  1473. val = DPLL_SSC_REF_CLOCK_CHV | DPLL_REFA_CLK_ENABLE_VLV;
  1474. if (pipe != PIPE_A)
  1475. val |= DPLL_INTEGRATED_CRI_CLK_VLV;
  1476. I915_WRITE(DPLL(pipe), val);
  1477. POSTING_READ(DPLL(pipe));
  1478. mutex_lock(&dev_priv->dpio_lock);
  1479. /* Disable 10bit clock to display controller */
  1480. val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
  1481. val &= ~DPIO_DCLKP_EN;
  1482. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val);
  1483. /* disable left/right clock distribution */
  1484. if (pipe != PIPE_B) {
  1485. val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW5_CH0);
  1486. val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK);
  1487. vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW5_CH0, val);
  1488. } else {
  1489. val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW1_CH1);
  1490. val &= ~(CHV_BUFLEFTENA2_MASK | CHV_BUFRIGHTENA2_MASK);
  1491. vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW1_CH1, val);
  1492. }
  1493. mutex_unlock(&dev_priv->dpio_lock);
  1494. }
  1495. void vlv_wait_port_ready(struct drm_i915_private *dev_priv,
  1496. struct intel_digital_port *dport)
  1497. {
  1498. u32 port_mask;
  1499. int dpll_reg;
  1500. switch (dport->port) {
  1501. case PORT_B:
  1502. port_mask = DPLL_PORTB_READY_MASK;
  1503. dpll_reg = DPLL(0);
  1504. break;
  1505. case PORT_C:
  1506. port_mask = DPLL_PORTC_READY_MASK;
  1507. dpll_reg = DPLL(0);
  1508. break;
  1509. case PORT_D:
  1510. port_mask = DPLL_PORTD_READY_MASK;
  1511. dpll_reg = DPIO_PHY_STATUS;
  1512. break;
  1513. default:
  1514. BUG();
  1515. }
  1516. if (wait_for((I915_READ(dpll_reg) & port_mask) == 0, 1000))
  1517. WARN(1, "timed out waiting for port %c ready: 0x%08x\n",
  1518. port_name(dport->port), I915_READ(dpll_reg));
  1519. }
  1520. static void intel_prepare_shared_dpll(struct intel_crtc *crtc)
  1521. {
  1522. struct drm_device *dev = crtc->base.dev;
  1523. struct drm_i915_private *dev_priv = dev->dev_private;
  1524. struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
  1525. if (WARN_ON(pll == NULL))
  1526. return;
  1527. WARN_ON(!pll->refcount);
  1528. if (pll->active == 0) {
  1529. DRM_DEBUG_DRIVER("setting up %s\n", pll->name);
  1530. WARN_ON(pll->on);
  1531. assert_shared_dpll_disabled(dev_priv, pll);
  1532. pll->mode_set(dev_priv, pll);
  1533. }
  1534. }
  1535. /**
  1536. * intel_enable_shared_dpll - enable PCH PLL
  1537. * @dev_priv: i915 private structure
  1538. * @pipe: pipe PLL to enable
  1539. *
  1540. * The PCH PLL needs to be enabled before the PCH transcoder, since it
  1541. * drives the transcoder clock.
  1542. */
  1543. static void intel_enable_shared_dpll(struct intel_crtc *crtc)
  1544. {
  1545. struct drm_device *dev = crtc->base.dev;
  1546. struct drm_i915_private *dev_priv = dev->dev_private;
  1547. struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
  1548. if (WARN_ON(pll == NULL))
  1549. return;
  1550. if (WARN_ON(pll->refcount == 0))
  1551. return;
  1552. DRM_DEBUG_KMS("enable %s (active %d, on? %d) for crtc %d\n",
  1553. pll->name, pll->active, pll->on,
  1554. crtc->base.base.id);
  1555. if (pll->active++) {
  1556. WARN_ON(!pll->on);
  1557. assert_shared_dpll_enabled(dev_priv, pll);
  1558. return;
  1559. }
  1560. WARN_ON(pll->on);
  1561. intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS);
  1562. DRM_DEBUG_KMS("enabling %s\n", pll->name);
  1563. pll->enable(dev_priv, pll);
  1564. pll->on = true;
  1565. }
  1566. static void intel_disable_shared_dpll(struct intel_crtc *crtc)
  1567. {
  1568. struct drm_device *dev = crtc->base.dev;
  1569. struct drm_i915_private *dev_priv = dev->dev_private;
  1570. struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
  1571. /* PCH only available on ILK+ */
  1572. BUG_ON(INTEL_INFO(dev)->gen < 5);
  1573. if (WARN_ON(pll == NULL))
  1574. return;
  1575. if (WARN_ON(pll->refcount == 0))
  1576. return;
  1577. DRM_DEBUG_KMS("disable %s (active %d, on? %d) for crtc %d\n",
  1578. pll->name, pll->active, pll->on,
  1579. crtc->base.base.id);
  1580. if (WARN_ON(pll->active == 0)) {
  1581. assert_shared_dpll_disabled(dev_priv, pll);
  1582. return;
  1583. }
  1584. assert_shared_dpll_enabled(dev_priv, pll);
  1585. WARN_ON(!pll->on);
  1586. if (--pll->active)
  1587. return;
  1588. DRM_DEBUG_KMS("disabling %s\n", pll->name);
  1589. pll->disable(dev_priv, pll);
  1590. pll->on = false;
  1591. intel_display_power_put(dev_priv, POWER_DOMAIN_PLLS);
  1592. }
  1593. static void ironlake_enable_pch_transcoder(struct drm_i915_private *dev_priv,
  1594. enum pipe pipe)
  1595. {
  1596. struct drm_device *dev = dev_priv->dev;
  1597. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  1598. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1599. uint32_t reg, val, pipeconf_val;
  1600. /* PCH only available on ILK+ */
  1601. BUG_ON(!HAS_PCH_SPLIT(dev));
  1602. /* Make sure PCH DPLL is enabled */
  1603. assert_shared_dpll_enabled(dev_priv,
  1604. intel_crtc_to_shared_dpll(intel_crtc));
  1605. /* FDI must be feeding us bits for PCH ports */
  1606. assert_fdi_tx_enabled(dev_priv, pipe);
  1607. assert_fdi_rx_enabled(dev_priv, pipe);
  1608. if (HAS_PCH_CPT(dev)) {
  1609. /* Workaround: Set the timing override bit before enabling the
  1610. * pch transcoder. */
  1611. reg = TRANS_CHICKEN2(pipe);
  1612. val = I915_READ(reg);
  1613. val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
  1614. I915_WRITE(reg, val);
  1615. }
  1616. reg = PCH_TRANSCONF(pipe);
  1617. val = I915_READ(reg);
  1618. pipeconf_val = I915_READ(PIPECONF(pipe));
  1619. if (HAS_PCH_IBX(dev_priv->dev)) {
  1620. /*
  1621. * make the BPC in transcoder be consistent with
  1622. * that in pipeconf reg.
  1623. */
  1624. val &= ~PIPECONF_BPC_MASK;
  1625. val |= pipeconf_val & PIPECONF_BPC_MASK;
  1626. }
  1627. val &= ~TRANS_INTERLACE_MASK;
  1628. if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK)
  1629. if (HAS_PCH_IBX(dev_priv->dev) &&
  1630. intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO))
  1631. val |= TRANS_LEGACY_INTERLACED_ILK;
  1632. else
  1633. val |= TRANS_INTERLACED;
  1634. else
  1635. val |= TRANS_PROGRESSIVE;
  1636. I915_WRITE(reg, val | TRANS_ENABLE);
  1637. if (wait_for(I915_READ(reg) & TRANS_STATE_ENABLE, 100))
  1638. DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe));
  1639. }
  1640. static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv,
  1641. enum transcoder cpu_transcoder)
  1642. {
  1643. u32 val, pipeconf_val;
  1644. /* PCH only available on ILK+ */
  1645. BUG_ON(!HAS_PCH_SPLIT(dev_priv->dev));
  1646. /* FDI must be feeding us bits for PCH ports */
  1647. assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder);
  1648. assert_fdi_rx_enabled(dev_priv, TRANSCODER_A);
  1649. /* Workaround: set timing override bit. */
  1650. val = I915_READ(_TRANSA_CHICKEN2);
  1651. val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
  1652. I915_WRITE(_TRANSA_CHICKEN2, val);
  1653. val = TRANS_ENABLE;
  1654. pipeconf_val = I915_READ(PIPECONF(cpu_transcoder));
  1655. if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) ==
  1656. PIPECONF_INTERLACED_ILK)
  1657. val |= TRANS_INTERLACED;
  1658. else
  1659. val |= TRANS_PROGRESSIVE;
  1660. I915_WRITE(LPT_TRANSCONF, val);
  1661. if (wait_for(I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE, 100))
  1662. DRM_ERROR("Failed to enable PCH transcoder\n");
  1663. }
  1664. static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv,
  1665. enum pipe pipe)
  1666. {
  1667. struct drm_device *dev = dev_priv->dev;
  1668. uint32_t reg, val;
  1669. /* FDI relies on the transcoder */
  1670. assert_fdi_tx_disabled(dev_priv, pipe);
  1671. assert_fdi_rx_disabled(dev_priv, pipe);
  1672. /* Ports must be off as well */
  1673. assert_pch_ports_disabled(dev_priv, pipe);
  1674. reg = PCH_TRANSCONF(pipe);
  1675. val = I915_READ(reg);
  1676. val &= ~TRANS_ENABLE;
  1677. I915_WRITE(reg, val);
  1678. /* wait for PCH transcoder off, transcoder state */
  1679. if (wait_for((I915_READ(reg) & TRANS_STATE_ENABLE) == 0, 50))
  1680. DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe));
  1681. if (!HAS_PCH_IBX(dev)) {
  1682. /* Workaround: Clear the timing override chicken bit again. */
  1683. reg = TRANS_CHICKEN2(pipe);
  1684. val = I915_READ(reg);
  1685. val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
  1686. I915_WRITE(reg, val);
  1687. }
  1688. }
  1689. static void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv)
  1690. {
  1691. u32 val;
  1692. val = I915_READ(LPT_TRANSCONF);
  1693. val &= ~TRANS_ENABLE;
  1694. I915_WRITE(LPT_TRANSCONF, val);
  1695. /* wait for PCH transcoder off, transcoder state */
  1696. if (wait_for((I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE) == 0, 50))
  1697. DRM_ERROR("Failed to disable PCH transcoder\n");
  1698. /* Workaround: clear timing override bit. */
  1699. val = I915_READ(_TRANSA_CHICKEN2);
  1700. val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
  1701. I915_WRITE(_TRANSA_CHICKEN2, val);
  1702. }
  1703. /**
  1704. * intel_enable_pipe - enable a pipe, asserting requirements
  1705. * @crtc: crtc responsible for the pipe
  1706. *
  1707. * Enable @crtc's pipe, making sure that various hardware specific requirements
  1708. * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc.
  1709. */
  1710. static void intel_enable_pipe(struct intel_crtc *crtc)
  1711. {
  1712. struct drm_device *dev = crtc->base.dev;
  1713. struct drm_i915_private *dev_priv = dev->dev_private;
  1714. enum pipe pipe = crtc->pipe;
  1715. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  1716. pipe);
  1717. enum pipe pch_transcoder;
  1718. int reg;
  1719. u32 val;
  1720. assert_planes_disabled(dev_priv, pipe);
  1721. assert_cursor_disabled(dev_priv, pipe);
  1722. assert_sprites_disabled(dev_priv, pipe);
  1723. if (HAS_PCH_LPT(dev_priv->dev))
  1724. pch_transcoder = TRANSCODER_A;
  1725. else
  1726. pch_transcoder = pipe;
  1727. /*
  1728. * A pipe without a PLL won't actually be able to drive bits from
  1729. * a plane. On ILK+ the pipe PLLs are integrated, so we don't
  1730. * need the check.
  1731. */
  1732. if (!HAS_PCH_SPLIT(dev_priv->dev))
  1733. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DSI))
  1734. assert_dsi_pll_enabled(dev_priv);
  1735. else
  1736. assert_pll_enabled(dev_priv, pipe);
  1737. else {
  1738. if (crtc->config.has_pch_encoder) {
  1739. /* if driving the PCH, we need FDI enabled */
  1740. assert_fdi_rx_pll_enabled(dev_priv, pch_transcoder);
  1741. assert_fdi_tx_pll_enabled(dev_priv,
  1742. (enum pipe) cpu_transcoder);
  1743. }
  1744. /* FIXME: assert CPU port conditions for SNB+ */
  1745. }
  1746. reg = PIPECONF(cpu_transcoder);
  1747. val = I915_READ(reg);
  1748. if (val & PIPECONF_ENABLE) {
  1749. WARN_ON(!((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) ||
  1750. (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)));
  1751. return;
  1752. }
  1753. I915_WRITE(reg, val | PIPECONF_ENABLE);
  1754. POSTING_READ(reg);
  1755. }
  1756. /**
  1757. * intel_disable_pipe - disable a pipe, asserting requirements
  1758. * @crtc: crtc whose pipes is to be disabled
  1759. *
  1760. * Disable the pipe of @crtc, making sure that various hardware
  1761. * specific requirements are met, if applicable, e.g. plane
  1762. * disabled, panel fitter off, etc.
  1763. *
  1764. * Will wait until the pipe has shut down before returning.
  1765. */
  1766. static void intel_disable_pipe(struct intel_crtc *crtc)
  1767. {
  1768. struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
  1769. enum transcoder cpu_transcoder = crtc->config.cpu_transcoder;
  1770. enum pipe pipe = crtc->pipe;
  1771. int reg;
  1772. u32 val;
  1773. /*
  1774. * Make sure planes won't keep trying to pump pixels to us,
  1775. * or we might hang the display.
  1776. */
  1777. assert_planes_disabled(dev_priv, pipe);
  1778. assert_cursor_disabled(dev_priv, pipe);
  1779. assert_sprites_disabled(dev_priv, pipe);
  1780. reg = PIPECONF(cpu_transcoder);
  1781. val = I915_READ(reg);
  1782. if ((val & PIPECONF_ENABLE) == 0)
  1783. return;
  1784. /*
  1785. * Double wide has implications for planes
  1786. * so best keep it disabled when not needed.
  1787. */
  1788. if (crtc->config.double_wide)
  1789. val &= ~PIPECONF_DOUBLE_WIDE;
  1790. /* Don't disable pipe or pipe PLLs if needed */
  1791. if (!(pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) &&
  1792. !(pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))
  1793. val &= ~PIPECONF_ENABLE;
  1794. I915_WRITE(reg, val);
  1795. if ((val & PIPECONF_ENABLE) == 0)
  1796. intel_wait_for_pipe_off(crtc);
  1797. }
  1798. /*
  1799. * Plane regs are double buffered, going from enabled->disabled needs a
  1800. * trigger in order to latch. The display address reg provides this.
  1801. */
  1802. void intel_flush_primary_plane(struct drm_i915_private *dev_priv,
  1803. enum plane plane)
  1804. {
  1805. struct drm_device *dev = dev_priv->dev;
  1806. u32 reg = INTEL_INFO(dev)->gen >= 4 ? DSPSURF(plane) : DSPADDR(plane);
  1807. I915_WRITE(reg, I915_READ(reg));
  1808. POSTING_READ(reg);
  1809. }
  1810. /**
  1811. * intel_enable_primary_hw_plane - enable the primary plane on a given pipe
  1812. * @plane: plane to be enabled
  1813. * @crtc: crtc for the plane
  1814. *
  1815. * Enable @plane on @crtc, making sure that the pipe is running first.
  1816. */
  1817. static void intel_enable_primary_hw_plane(struct drm_plane *plane,
  1818. struct drm_crtc *crtc)
  1819. {
  1820. struct drm_device *dev = plane->dev;
  1821. struct drm_i915_private *dev_priv = dev->dev_private;
  1822. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1823. /* If the pipe isn't enabled, we can't pump pixels and may hang */
  1824. assert_pipe_enabled(dev_priv, intel_crtc->pipe);
  1825. if (intel_crtc->primary_enabled)
  1826. return;
  1827. intel_crtc->primary_enabled = true;
  1828. dev_priv->display.update_primary_plane(crtc, plane->fb,
  1829. crtc->x, crtc->y);
  1830. /*
  1831. * BDW signals flip done immediately if the plane
  1832. * is disabled, even if the plane enable is already
  1833. * armed to occur at the next vblank :(
  1834. */
  1835. if (IS_BROADWELL(dev))
  1836. intel_wait_for_vblank(dev, intel_crtc->pipe);
  1837. }
  1838. /**
  1839. * intel_disable_primary_hw_plane - disable the primary hardware plane
  1840. * @plane: plane to be disabled
  1841. * @crtc: crtc for the plane
  1842. *
  1843. * Disable @plane on @crtc, making sure that the pipe is running first.
  1844. */
  1845. static void intel_disable_primary_hw_plane(struct drm_plane *plane,
  1846. struct drm_crtc *crtc)
  1847. {
  1848. struct drm_device *dev = plane->dev;
  1849. struct drm_i915_private *dev_priv = dev->dev_private;
  1850. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1851. assert_pipe_enabled(dev_priv, intel_crtc->pipe);
  1852. if (!intel_crtc->primary_enabled)
  1853. return;
  1854. intel_crtc->primary_enabled = false;
  1855. dev_priv->display.update_primary_plane(crtc, plane->fb,
  1856. crtc->x, crtc->y);
  1857. }
  1858. static bool need_vtd_wa(struct drm_device *dev)
  1859. {
  1860. #ifdef CONFIG_INTEL_IOMMU
  1861. if (INTEL_INFO(dev)->gen >= 6 && intel_iommu_gfx_mapped)
  1862. return true;
  1863. #endif
  1864. return false;
  1865. }
  1866. static int intel_align_height(struct drm_device *dev, int height, bool tiled)
  1867. {
  1868. int tile_height;
  1869. tile_height = tiled ? (IS_GEN2(dev) ? 16 : 8) : 1;
  1870. return ALIGN(height, tile_height);
  1871. }
  1872. int
  1873. intel_pin_and_fence_fb_obj(struct drm_device *dev,
  1874. struct drm_i915_gem_object *obj,
  1875. struct intel_engine_cs *pipelined)
  1876. {
  1877. struct drm_i915_private *dev_priv = dev->dev_private;
  1878. u32 alignment;
  1879. int ret;
  1880. WARN_ON(!mutex_is_locked(&dev->struct_mutex));
  1881. switch (obj->tiling_mode) {
  1882. case I915_TILING_NONE:
  1883. if (INTEL_INFO(dev)->gen >= 9)
  1884. alignment = 256 * 1024;
  1885. else if (IS_BROADWATER(dev) || IS_CRESTLINE(dev))
  1886. alignment = 128 * 1024;
  1887. else if (INTEL_INFO(dev)->gen >= 4)
  1888. alignment = 4 * 1024;
  1889. else
  1890. alignment = 64 * 1024;
  1891. break;
  1892. case I915_TILING_X:
  1893. if (INTEL_INFO(dev)->gen >= 9)
  1894. alignment = 256 * 1024;
  1895. else {
  1896. /* pin() will align the object as required by fence */
  1897. alignment = 0;
  1898. }
  1899. break;
  1900. case I915_TILING_Y:
  1901. WARN(1, "Y tiled bo slipped through, driver bug!\n");
  1902. return -EINVAL;
  1903. default:
  1904. BUG();
  1905. }
  1906. /* Note that the w/a also requires 64 PTE of padding following the
  1907. * bo. We currently fill all unused PTE with the shadow page and so
  1908. * we should always have valid PTE following the scanout preventing
  1909. * the VT-d warning.
  1910. */
  1911. if (need_vtd_wa(dev) && alignment < 256 * 1024)
  1912. alignment = 256 * 1024;
  1913. /*
  1914. * Global gtt pte registers are special registers which actually forward
  1915. * writes to a chunk of system memory. Which means that there is no risk
  1916. * that the register values disappear as soon as we call
  1917. * intel_runtime_pm_put(), so it is correct to wrap only the
  1918. * pin/unpin/fence and not more.
  1919. */
  1920. intel_runtime_pm_get(dev_priv);
  1921. dev_priv->mm.interruptible = false;
  1922. ret = i915_gem_object_pin_to_display_plane(obj, alignment, pipelined);
  1923. if (ret)
  1924. goto err_interruptible;
  1925. /* Install a fence for tiled scan-out. Pre-i965 always needs a
  1926. * fence, whereas 965+ only requires a fence if using
  1927. * framebuffer compression. For simplicity, we always install
  1928. * a fence as the cost is not that onerous.
  1929. */
  1930. ret = i915_gem_object_get_fence(obj);
  1931. if (ret)
  1932. goto err_unpin;
  1933. i915_gem_object_pin_fence(obj);
  1934. dev_priv->mm.interruptible = true;
  1935. intel_runtime_pm_put(dev_priv);
  1936. return 0;
  1937. err_unpin:
  1938. i915_gem_object_unpin_from_display_plane(obj);
  1939. err_interruptible:
  1940. dev_priv->mm.interruptible = true;
  1941. intel_runtime_pm_put(dev_priv);
  1942. return ret;
  1943. }
  1944. void intel_unpin_fb_obj(struct drm_i915_gem_object *obj)
  1945. {
  1946. WARN_ON(!mutex_is_locked(&obj->base.dev->struct_mutex));
  1947. i915_gem_object_unpin_fence(obj);
  1948. i915_gem_object_unpin_from_display_plane(obj);
  1949. }
  1950. /* Computes the linear offset to the base tile and adjusts x, y. bytes per pixel
  1951. * is assumed to be a power-of-two. */
  1952. unsigned long intel_gen4_compute_page_offset(int *x, int *y,
  1953. unsigned int tiling_mode,
  1954. unsigned int cpp,
  1955. unsigned int pitch)
  1956. {
  1957. if (tiling_mode != I915_TILING_NONE) {
  1958. unsigned int tile_rows, tiles;
  1959. tile_rows = *y / 8;
  1960. *y %= 8;
  1961. tiles = *x / (512/cpp);
  1962. *x %= 512/cpp;
  1963. return tile_rows * pitch * 8 + tiles * 4096;
  1964. } else {
  1965. unsigned int offset;
  1966. offset = *y * pitch + *x * cpp;
  1967. *y = 0;
  1968. *x = (offset & 4095) / cpp;
  1969. return offset & -4096;
  1970. }
  1971. }
  1972. int intel_format_to_fourcc(int format)
  1973. {
  1974. switch (format) {
  1975. case DISPPLANE_8BPP:
  1976. return DRM_FORMAT_C8;
  1977. case DISPPLANE_BGRX555:
  1978. return DRM_FORMAT_XRGB1555;
  1979. case DISPPLANE_BGRX565:
  1980. return DRM_FORMAT_RGB565;
  1981. default:
  1982. case DISPPLANE_BGRX888:
  1983. return DRM_FORMAT_XRGB8888;
  1984. case DISPPLANE_RGBX888:
  1985. return DRM_FORMAT_XBGR8888;
  1986. case DISPPLANE_BGRX101010:
  1987. return DRM_FORMAT_XRGB2101010;
  1988. case DISPPLANE_RGBX101010:
  1989. return DRM_FORMAT_XBGR2101010;
  1990. }
  1991. }
  1992. static bool intel_alloc_plane_obj(struct intel_crtc *crtc,
  1993. struct intel_plane_config *plane_config)
  1994. {
  1995. struct drm_device *dev = crtc->base.dev;
  1996. struct drm_i915_gem_object *obj = NULL;
  1997. struct drm_mode_fb_cmd2 mode_cmd = { 0 };
  1998. u32 base = plane_config->base;
  1999. if (plane_config->size == 0)
  2000. return false;
  2001. obj = i915_gem_object_create_stolen_for_preallocated(dev, base, base,
  2002. plane_config->size);
  2003. if (!obj)
  2004. return false;
  2005. if (plane_config->tiled) {
  2006. obj->tiling_mode = I915_TILING_X;
  2007. obj->stride = crtc->base.primary->fb->pitches[0];
  2008. }
  2009. mode_cmd.pixel_format = crtc->base.primary->fb->pixel_format;
  2010. mode_cmd.width = crtc->base.primary->fb->width;
  2011. mode_cmd.height = crtc->base.primary->fb->height;
  2012. mode_cmd.pitches[0] = crtc->base.primary->fb->pitches[0];
  2013. mutex_lock(&dev->struct_mutex);
  2014. if (intel_framebuffer_init(dev, to_intel_framebuffer(crtc->base.primary->fb),
  2015. &mode_cmd, obj)) {
  2016. DRM_DEBUG_KMS("intel fb init failed\n");
  2017. goto out_unref_obj;
  2018. }
  2019. obj->frontbuffer_bits = INTEL_FRONTBUFFER_PRIMARY(crtc->pipe);
  2020. mutex_unlock(&dev->struct_mutex);
  2021. DRM_DEBUG_KMS("plane fb obj %p\n", obj);
  2022. return true;
  2023. out_unref_obj:
  2024. drm_gem_object_unreference(&obj->base);
  2025. mutex_unlock(&dev->struct_mutex);
  2026. return false;
  2027. }
  2028. static void intel_find_plane_obj(struct intel_crtc *intel_crtc,
  2029. struct intel_plane_config *plane_config)
  2030. {
  2031. struct drm_device *dev = intel_crtc->base.dev;
  2032. struct drm_i915_private *dev_priv = dev->dev_private;
  2033. struct drm_crtc *c;
  2034. struct intel_crtc *i;
  2035. struct drm_i915_gem_object *obj;
  2036. if (!intel_crtc->base.primary->fb)
  2037. return;
  2038. if (intel_alloc_plane_obj(intel_crtc, plane_config))
  2039. return;
  2040. kfree(intel_crtc->base.primary->fb);
  2041. intel_crtc->base.primary->fb = NULL;
  2042. /*
  2043. * Failed to alloc the obj, check to see if we should share
  2044. * an fb with another CRTC instead
  2045. */
  2046. for_each_crtc(dev, c) {
  2047. i = to_intel_crtc(c);
  2048. if (c == &intel_crtc->base)
  2049. continue;
  2050. if (!i->active)
  2051. continue;
  2052. obj = intel_fb_obj(c->primary->fb);
  2053. if (obj == NULL)
  2054. continue;
  2055. if (i915_gem_obj_ggtt_offset(obj) == plane_config->base) {
  2056. if (obj->tiling_mode != I915_TILING_NONE)
  2057. dev_priv->preserve_bios_swizzle = true;
  2058. drm_framebuffer_reference(c->primary->fb);
  2059. intel_crtc->base.primary->fb = c->primary->fb;
  2060. obj->frontbuffer_bits |= INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe);
  2061. break;
  2062. }
  2063. }
  2064. }
  2065. static void i9xx_update_primary_plane(struct drm_crtc *crtc,
  2066. struct drm_framebuffer *fb,
  2067. int x, int y)
  2068. {
  2069. struct drm_device *dev = crtc->dev;
  2070. struct drm_i915_private *dev_priv = dev->dev_private;
  2071. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2072. struct drm_i915_gem_object *obj;
  2073. int plane = intel_crtc->plane;
  2074. unsigned long linear_offset;
  2075. u32 dspcntr;
  2076. u32 reg = DSPCNTR(plane);
  2077. int pixel_size;
  2078. if (!intel_crtc->primary_enabled) {
  2079. I915_WRITE(reg, 0);
  2080. if (INTEL_INFO(dev)->gen >= 4)
  2081. I915_WRITE(DSPSURF(plane), 0);
  2082. else
  2083. I915_WRITE(DSPADDR(plane), 0);
  2084. POSTING_READ(reg);
  2085. return;
  2086. }
  2087. obj = intel_fb_obj(fb);
  2088. if (WARN_ON(obj == NULL))
  2089. return;
  2090. pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
  2091. dspcntr = DISPPLANE_GAMMA_ENABLE;
  2092. dspcntr |= DISPLAY_PLANE_ENABLE;
  2093. if (INTEL_INFO(dev)->gen < 4) {
  2094. if (intel_crtc->pipe == PIPE_B)
  2095. dspcntr |= DISPPLANE_SEL_PIPE_B;
  2096. /* pipesrc and dspsize control the size that is scaled from,
  2097. * which should always be the user's requested size.
  2098. */
  2099. I915_WRITE(DSPSIZE(plane),
  2100. ((intel_crtc->config.pipe_src_h - 1) << 16) |
  2101. (intel_crtc->config.pipe_src_w - 1));
  2102. I915_WRITE(DSPPOS(plane), 0);
  2103. }
  2104. switch (fb->pixel_format) {
  2105. case DRM_FORMAT_C8:
  2106. dspcntr |= DISPPLANE_8BPP;
  2107. break;
  2108. case DRM_FORMAT_XRGB1555:
  2109. case DRM_FORMAT_ARGB1555:
  2110. dspcntr |= DISPPLANE_BGRX555;
  2111. break;
  2112. case DRM_FORMAT_RGB565:
  2113. dspcntr |= DISPPLANE_BGRX565;
  2114. break;
  2115. case DRM_FORMAT_XRGB8888:
  2116. case DRM_FORMAT_ARGB8888:
  2117. dspcntr |= DISPPLANE_BGRX888;
  2118. break;
  2119. case DRM_FORMAT_XBGR8888:
  2120. case DRM_FORMAT_ABGR8888:
  2121. dspcntr |= DISPPLANE_RGBX888;
  2122. break;
  2123. case DRM_FORMAT_XRGB2101010:
  2124. case DRM_FORMAT_ARGB2101010:
  2125. dspcntr |= DISPPLANE_BGRX101010;
  2126. break;
  2127. case DRM_FORMAT_XBGR2101010:
  2128. case DRM_FORMAT_ABGR2101010:
  2129. dspcntr |= DISPPLANE_RGBX101010;
  2130. break;
  2131. default:
  2132. BUG();
  2133. }
  2134. if (INTEL_INFO(dev)->gen >= 4 &&
  2135. obj->tiling_mode != I915_TILING_NONE)
  2136. dspcntr |= DISPPLANE_TILED;
  2137. if (IS_G4X(dev))
  2138. dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
  2139. linear_offset = y * fb->pitches[0] + x * pixel_size;
  2140. if (INTEL_INFO(dev)->gen >= 4) {
  2141. intel_crtc->dspaddr_offset =
  2142. intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
  2143. pixel_size,
  2144. fb->pitches[0]);
  2145. linear_offset -= intel_crtc->dspaddr_offset;
  2146. } else {
  2147. intel_crtc->dspaddr_offset = linear_offset;
  2148. }
  2149. if (to_intel_plane(crtc->primary)->rotation == BIT(DRM_ROTATE_180)) {
  2150. dspcntr |= DISPPLANE_ROTATE_180;
  2151. x += (intel_crtc->config.pipe_src_w - 1);
  2152. y += (intel_crtc->config.pipe_src_h - 1);
  2153. /* Finding the last pixel of the last line of the display
  2154. data and adding to linear_offset*/
  2155. linear_offset +=
  2156. (intel_crtc->config.pipe_src_h - 1) * fb->pitches[0] +
  2157. (intel_crtc->config.pipe_src_w - 1) * pixel_size;
  2158. }
  2159. I915_WRITE(reg, dspcntr);
  2160. DRM_DEBUG_KMS("Writing base %08lX %08lX %d %d %d\n",
  2161. i915_gem_obj_ggtt_offset(obj), linear_offset, x, y,
  2162. fb->pitches[0]);
  2163. I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]);
  2164. if (INTEL_INFO(dev)->gen >= 4) {
  2165. I915_WRITE(DSPSURF(plane),
  2166. i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset);
  2167. I915_WRITE(DSPTILEOFF(plane), (y << 16) | x);
  2168. I915_WRITE(DSPLINOFF(plane), linear_offset);
  2169. } else
  2170. I915_WRITE(DSPADDR(plane), i915_gem_obj_ggtt_offset(obj) + linear_offset);
  2171. POSTING_READ(reg);
  2172. }
  2173. static void ironlake_update_primary_plane(struct drm_crtc *crtc,
  2174. struct drm_framebuffer *fb,
  2175. int x, int y)
  2176. {
  2177. struct drm_device *dev = crtc->dev;
  2178. struct drm_i915_private *dev_priv = dev->dev_private;
  2179. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2180. struct drm_i915_gem_object *obj;
  2181. int plane = intel_crtc->plane;
  2182. unsigned long linear_offset;
  2183. u32 dspcntr;
  2184. u32 reg = DSPCNTR(plane);
  2185. int pixel_size;
  2186. if (!intel_crtc->primary_enabled) {
  2187. I915_WRITE(reg, 0);
  2188. I915_WRITE(DSPSURF(plane), 0);
  2189. POSTING_READ(reg);
  2190. return;
  2191. }
  2192. obj = intel_fb_obj(fb);
  2193. if (WARN_ON(obj == NULL))
  2194. return;
  2195. pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
  2196. dspcntr = DISPPLANE_GAMMA_ENABLE;
  2197. dspcntr |= DISPLAY_PLANE_ENABLE;
  2198. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  2199. dspcntr |= DISPPLANE_PIPE_CSC_ENABLE;
  2200. switch (fb->pixel_format) {
  2201. case DRM_FORMAT_C8:
  2202. dspcntr |= DISPPLANE_8BPP;
  2203. break;
  2204. case DRM_FORMAT_RGB565:
  2205. dspcntr |= DISPPLANE_BGRX565;
  2206. break;
  2207. case DRM_FORMAT_XRGB8888:
  2208. case DRM_FORMAT_ARGB8888:
  2209. dspcntr |= DISPPLANE_BGRX888;
  2210. break;
  2211. case DRM_FORMAT_XBGR8888:
  2212. case DRM_FORMAT_ABGR8888:
  2213. dspcntr |= DISPPLANE_RGBX888;
  2214. break;
  2215. case DRM_FORMAT_XRGB2101010:
  2216. case DRM_FORMAT_ARGB2101010:
  2217. dspcntr |= DISPPLANE_BGRX101010;
  2218. break;
  2219. case DRM_FORMAT_XBGR2101010:
  2220. case DRM_FORMAT_ABGR2101010:
  2221. dspcntr |= DISPPLANE_RGBX101010;
  2222. break;
  2223. default:
  2224. BUG();
  2225. }
  2226. if (obj->tiling_mode != I915_TILING_NONE)
  2227. dspcntr |= DISPPLANE_TILED;
  2228. if (!IS_HASWELL(dev) && !IS_BROADWELL(dev))
  2229. dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
  2230. linear_offset = y * fb->pitches[0] + x * pixel_size;
  2231. intel_crtc->dspaddr_offset =
  2232. intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
  2233. pixel_size,
  2234. fb->pitches[0]);
  2235. linear_offset -= intel_crtc->dspaddr_offset;
  2236. if (to_intel_plane(crtc->primary)->rotation == BIT(DRM_ROTATE_180)) {
  2237. dspcntr |= DISPPLANE_ROTATE_180;
  2238. if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) {
  2239. x += (intel_crtc->config.pipe_src_w - 1);
  2240. y += (intel_crtc->config.pipe_src_h - 1);
  2241. /* Finding the last pixel of the last line of the display
  2242. data and adding to linear_offset*/
  2243. linear_offset +=
  2244. (intel_crtc->config.pipe_src_h - 1) * fb->pitches[0] +
  2245. (intel_crtc->config.pipe_src_w - 1) * pixel_size;
  2246. }
  2247. }
  2248. I915_WRITE(reg, dspcntr);
  2249. DRM_DEBUG_KMS("Writing base %08lX %08lX %d %d %d\n",
  2250. i915_gem_obj_ggtt_offset(obj), linear_offset, x, y,
  2251. fb->pitches[0]);
  2252. I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]);
  2253. I915_WRITE(DSPSURF(plane),
  2254. i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset);
  2255. if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
  2256. I915_WRITE(DSPOFFSET(plane), (y << 16) | x);
  2257. } else {
  2258. I915_WRITE(DSPTILEOFF(plane), (y << 16) | x);
  2259. I915_WRITE(DSPLINOFF(plane), linear_offset);
  2260. }
  2261. POSTING_READ(reg);
  2262. }
  2263. static void skylake_update_primary_plane(struct drm_crtc *crtc,
  2264. struct drm_framebuffer *fb,
  2265. int x, int y)
  2266. {
  2267. struct drm_device *dev = crtc->dev;
  2268. struct drm_i915_private *dev_priv = dev->dev_private;
  2269. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2270. struct intel_framebuffer *intel_fb;
  2271. struct drm_i915_gem_object *obj;
  2272. int pipe = intel_crtc->pipe;
  2273. u32 plane_ctl, stride;
  2274. if (!intel_crtc->primary_enabled) {
  2275. I915_WRITE(PLANE_CTL(pipe, 0), 0);
  2276. I915_WRITE(PLANE_SURF(pipe, 0), 0);
  2277. POSTING_READ(PLANE_CTL(pipe, 0));
  2278. return;
  2279. }
  2280. plane_ctl = PLANE_CTL_ENABLE |
  2281. PLANE_CTL_PIPE_GAMMA_ENABLE |
  2282. PLANE_CTL_PIPE_CSC_ENABLE;
  2283. switch (fb->pixel_format) {
  2284. case DRM_FORMAT_RGB565:
  2285. plane_ctl |= PLANE_CTL_FORMAT_RGB_565;
  2286. break;
  2287. case DRM_FORMAT_XRGB8888:
  2288. plane_ctl |= PLANE_CTL_FORMAT_XRGB_8888;
  2289. break;
  2290. case DRM_FORMAT_XBGR8888:
  2291. plane_ctl |= PLANE_CTL_ORDER_RGBX;
  2292. plane_ctl |= PLANE_CTL_FORMAT_XRGB_8888;
  2293. break;
  2294. case DRM_FORMAT_XRGB2101010:
  2295. plane_ctl |= PLANE_CTL_FORMAT_XRGB_2101010;
  2296. break;
  2297. case DRM_FORMAT_XBGR2101010:
  2298. plane_ctl |= PLANE_CTL_ORDER_RGBX;
  2299. plane_ctl |= PLANE_CTL_FORMAT_XRGB_2101010;
  2300. break;
  2301. default:
  2302. BUG();
  2303. }
  2304. intel_fb = to_intel_framebuffer(fb);
  2305. obj = intel_fb->obj;
  2306. /*
  2307. * The stride is either expressed as a multiple of 64 bytes chunks for
  2308. * linear buffers or in number of tiles for tiled buffers.
  2309. */
  2310. switch (obj->tiling_mode) {
  2311. case I915_TILING_NONE:
  2312. stride = fb->pitches[0] >> 6;
  2313. break;
  2314. case I915_TILING_X:
  2315. plane_ctl |= PLANE_CTL_TILED_X;
  2316. stride = fb->pitches[0] >> 9;
  2317. break;
  2318. default:
  2319. BUG();
  2320. }
  2321. plane_ctl |= PLANE_CTL_PLANE_GAMMA_DISABLE;
  2322. if (to_intel_plane(crtc->primary)->rotation == BIT(DRM_ROTATE_180))
  2323. plane_ctl |= PLANE_CTL_ROTATE_180;
  2324. I915_WRITE(PLANE_CTL(pipe, 0), plane_ctl);
  2325. DRM_DEBUG_KMS("Writing base %08lX %d,%d,%d,%d pitch=%d\n",
  2326. i915_gem_obj_ggtt_offset(obj),
  2327. x, y, fb->width, fb->height,
  2328. fb->pitches[0]);
  2329. I915_WRITE(PLANE_POS(pipe, 0), 0);
  2330. I915_WRITE(PLANE_OFFSET(pipe, 0), (y << 16) | x);
  2331. I915_WRITE(PLANE_SIZE(pipe, 0),
  2332. (intel_crtc->config.pipe_src_h - 1) << 16 |
  2333. (intel_crtc->config.pipe_src_w - 1));
  2334. I915_WRITE(PLANE_STRIDE(pipe, 0), stride);
  2335. I915_WRITE(PLANE_SURF(pipe, 0), i915_gem_obj_ggtt_offset(obj));
  2336. POSTING_READ(PLANE_SURF(pipe, 0));
  2337. }
  2338. /* Assume fb object is pinned & idle & fenced and just update base pointers */
  2339. static int
  2340. intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb,
  2341. int x, int y, enum mode_set_atomic state)
  2342. {
  2343. struct drm_device *dev = crtc->dev;
  2344. struct drm_i915_private *dev_priv = dev->dev_private;
  2345. if (dev_priv->display.disable_fbc)
  2346. dev_priv->display.disable_fbc(dev);
  2347. dev_priv->display.update_primary_plane(crtc, fb, x, y);
  2348. return 0;
  2349. }
  2350. void intel_display_handle_reset(struct drm_device *dev)
  2351. {
  2352. struct drm_i915_private *dev_priv = dev->dev_private;
  2353. struct drm_crtc *crtc;
  2354. /*
  2355. * Flips in the rings have been nuked by the reset,
  2356. * so complete all pending flips so that user space
  2357. * will get its events and not get stuck.
  2358. *
  2359. * Also update the base address of all primary
  2360. * planes to the the last fb to make sure we're
  2361. * showing the correct fb after a reset.
  2362. *
  2363. * Need to make two loops over the crtcs so that we
  2364. * don't try to grab a crtc mutex before the
  2365. * pending_flip_queue really got woken up.
  2366. */
  2367. for_each_crtc(dev, crtc) {
  2368. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2369. enum plane plane = intel_crtc->plane;
  2370. intel_prepare_page_flip(dev, plane);
  2371. intel_finish_page_flip_plane(dev, plane);
  2372. }
  2373. for_each_crtc(dev, crtc) {
  2374. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2375. drm_modeset_lock(&crtc->mutex, NULL);
  2376. /*
  2377. * FIXME: Once we have proper support for primary planes (and
  2378. * disabling them without disabling the entire crtc) allow again
  2379. * a NULL crtc->primary->fb.
  2380. */
  2381. if (intel_crtc->active && crtc->primary->fb)
  2382. dev_priv->display.update_primary_plane(crtc,
  2383. crtc->primary->fb,
  2384. crtc->x,
  2385. crtc->y);
  2386. drm_modeset_unlock(&crtc->mutex);
  2387. }
  2388. }
  2389. static int
  2390. intel_finish_fb(struct drm_framebuffer *old_fb)
  2391. {
  2392. struct drm_i915_gem_object *obj = intel_fb_obj(old_fb);
  2393. struct drm_i915_private *dev_priv = obj->base.dev->dev_private;
  2394. bool was_interruptible = dev_priv->mm.interruptible;
  2395. int ret;
  2396. /* Big Hammer, we also need to ensure that any pending
  2397. * MI_WAIT_FOR_EVENT inside a user batch buffer on the
  2398. * current scanout is retired before unpinning the old
  2399. * framebuffer.
  2400. *
  2401. * This should only fail upon a hung GPU, in which case we
  2402. * can safely continue.
  2403. */
  2404. dev_priv->mm.interruptible = false;
  2405. ret = i915_gem_object_finish_gpu(obj);
  2406. dev_priv->mm.interruptible = was_interruptible;
  2407. return ret;
  2408. }
  2409. static bool intel_crtc_has_pending_flip(struct drm_crtc *crtc)
  2410. {
  2411. struct drm_device *dev = crtc->dev;
  2412. struct drm_i915_private *dev_priv = dev->dev_private;
  2413. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2414. bool pending;
  2415. if (i915_reset_in_progress(&dev_priv->gpu_error) ||
  2416. intel_crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter))
  2417. return false;
  2418. spin_lock_irq(&dev->event_lock);
  2419. pending = to_intel_crtc(crtc)->unpin_work != NULL;
  2420. spin_unlock_irq(&dev->event_lock);
  2421. return pending;
  2422. }
  2423. static void intel_update_pipe_size(struct intel_crtc *crtc)
  2424. {
  2425. struct drm_device *dev = crtc->base.dev;
  2426. struct drm_i915_private *dev_priv = dev->dev_private;
  2427. const struct drm_display_mode *adjusted_mode;
  2428. if (!i915.fastboot)
  2429. return;
  2430. /*
  2431. * Update pipe size and adjust fitter if needed: the reason for this is
  2432. * that in compute_mode_changes we check the native mode (not the pfit
  2433. * mode) to see if we can flip rather than do a full mode set. In the
  2434. * fastboot case, we'll flip, but if we don't update the pipesrc and
  2435. * pfit state, we'll end up with a big fb scanned out into the wrong
  2436. * sized surface.
  2437. *
  2438. * To fix this properly, we need to hoist the checks up into
  2439. * compute_mode_changes (or above), check the actual pfit state and
  2440. * whether the platform allows pfit disable with pipe active, and only
  2441. * then update the pipesrc and pfit state, even on the flip path.
  2442. */
  2443. adjusted_mode = &crtc->config.adjusted_mode;
  2444. I915_WRITE(PIPESRC(crtc->pipe),
  2445. ((adjusted_mode->crtc_hdisplay - 1) << 16) |
  2446. (adjusted_mode->crtc_vdisplay - 1));
  2447. if (!crtc->config.pch_pfit.enabled &&
  2448. (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) ||
  2449. intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) {
  2450. I915_WRITE(PF_CTL(crtc->pipe), 0);
  2451. I915_WRITE(PF_WIN_POS(crtc->pipe), 0);
  2452. I915_WRITE(PF_WIN_SZ(crtc->pipe), 0);
  2453. }
  2454. crtc->config.pipe_src_w = adjusted_mode->crtc_hdisplay;
  2455. crtc->config.pipe_src_h = adjusted_mode->crtc_vdisplay;
  2456. }
  2457. static int
  2458. intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
  2459. struct drm_framebuffer *fb)
  2460. {
  2461. struct drm_device *dev = crtc->dev;
  2462. struct drm_i915_private *dev_priv = dev->dev_private;
  2463. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2464. enum pipe pipe = intel_crtc->pipe;
  2465. struct drm_framebuffer *old_fb = crtc->primary->fb;
  2466. struct drm_i915_gem_object *obj = intel_fb_obj(fb);
  2467. struct drm_i915_gem_object *old_obj = intel_fb_obj(old_fb);
  2468. int ret;
  2469. if (intel_crtc_has_pending_flip(crtc)) {
  2470. DRM_ERROR("pipe is still busy with an old pageflip\n");
  2471. return -EBUSY;
  2472. }
  2473. /* no fb bound */
  2474. if (!fb) {
  2475. DRM_ERROR("No FB bound\n");
  2476. return 0;
  2477. }
  2478. if (intel_crtc->plane > INTEL_INFO(dev)->num_pipes) {
  2479. DRM_ERROR("no plane for crtc: plane %c, num_pipes %d\n",
  2480. plane_name(intel_crtc->plane),
  2481. INTEL_INFO(dev)->num_pipes);
  2482. return -EINVAL;
  2483. }
  2484. mutex_lock(&dev->struct_mutex);
  2485. ret = intel_pin_and_fence_fb_obj(dev, obj, NULL);
  2486. if (ret == 0)
  2487. i915_gem_track_fb(old_obj, obj,
  2488. INTEL_FRONTBUFFER_PRIMARY(pipe));
  2489. mutex_unlock(&dev->struct_mutex);
  2490. if (ret != 0) {
  2491. DRM_ERROR("pin & fence failed\n");
  2492. return ret;
  2493. }
  2494. intel_update_pipe_size(intel_crtc);
  2495. dev_priv->display.update_primary_plane(crtc, fb, x, y);
  2496. if (intel_crtc->active)
  2497. intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_PRIMARY(pipe));
  2498. crtc->primary->fb = fb;
  2499. crtc->x = x;
  2500. crtc->y = y;
  2501. if (old_fb) {
  2502. if (intel_crtc->active && old_fb != fb)
  2503. intel_wait_for_vblank(dev, intel_crtc->pipe);
  2504. mutex_lock(&dev->struct_mutex);
  2505. intel_unpin_fb_obj(old_obj);
  2506. mutex_unlock(&dev->struct_mutex);
  2507. }
  2508. mutex_lock(&dev->struct_mutex);
  2509. intel_update_fbc(dev);
  2510. mutex_unlock(&dev->struct_mutex);
  2511. return 0;
  2512. }
  2513. static void intel_fdi_normal_train(struct drm_crtc *crtc)
  2514. {
  2515. struct drm_device *dev = crtc->dev;
  2516. struct drm_i915_private *dev_priv = dev->dev_private;
  2517. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2518. int pipe = intel_crtc->pipe;
  2519. u32 reg, temp;
  2520. /* enable normal train */
  2521. reg = FDI_TX_CTL(pipe);
  2522. temp = I915_READ(reg);
  2523. if (IS_IVYBRIDGE(dev)) {
  2524. temp &= ~FDI_LINK_TRAIN_NONE_IVB;
  2525. temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE;
  2526. } else {
  2527. temp &= ~FDI_LINK_TRAIN_NONE;
  2528. temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
  2529. }
  2530. I915_WRITE(reg, temp);
  2531. reg = FDI_RX_CTL(pipe);
  2532. temp = I915_READ(reg);
  2533. if (HAS_PCH_CPT(dev)) {
  2534. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2535. temp |= FDI_LINK_TRAIN_NORMAL_CPT;
  2536. } else {
  2537. temp &= ~FDI_LINK_TRAIN_NONE;
  2538. temp |= FDI_LINK_TRAIN_NONE;
  2539. }
  2540. I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
  2541. /* wait one idle pattern time */
  2542. POSTING_READ(reg);
  2543. udelay(1000);
  2544. /* IVB wants error correction enabled */
  2545. if (IS_IVYBRIDGE(dev))
  2546. I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE |
  2547. FDI_FE_ERRC_ENABLE);
  2548. }
  2549. static bool pipe_has_enabled_pch(struct intel_crtc *crtc)
  2550. {
  2551. return crtc->base.enabled && crtc->active &&
  2552. crtc->config.has_pch_encoder;
  2553. }
  2554. static void ivb_modeset_global_resources(struct drm_device *dev)
  2555. {
  2556. struct drm_i915_private *dev_priv = dev->dev_private;
  2557. struct intel_crtc *pipe_B_crtc =
  2558. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_B]);
  2559. struct intel_crtc *pipe_C_crtc =
  2560. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_C]);
  2561. uint32_t temp;
  2562. /*
  2563. * When everything is off disable fdi C so that we could enable fdi B
  2564. * with all lanes. Note that we don't care about enabled pipes without
  2565. * an enabled pch encoder.
  2566. */
  2567. if (!pipe_has_enabled_pch(pipe_B_crtc) &&
  2568. !pipe_has_enabled_pch(pipe_C_crtc)) {
  2569. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
  2570. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
  2571. temp = I915_READ(SOUTH_CHICKEN1);
  2572. temp &= ~FDI_BC_BIFURCATION_SELECT;
  2573. DRM_DEBUG_KMS("disabling fdi C rx\n");
  2574. I915_WRITE(SOUTH_CHICKEN1, temp);
  2575. }
  2576. }
  2577. /* The FDI link training functions for ILK/Ibexpeak. */
  2578. static void ironlake_fdi_link_train(struct drm_crtc *crtc)
  2579. {
  2580. struct drm_device *dev = crtc->dev;
  2581. struct drm_i915_private *dev_priv = dev->dev_private;
  2582. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2583. int pipe = intel_crtc->pipe;
  2584. u32 reg, temp, tries;
  2585. /* FDI needs bits from pipe first */
  2586. assert_pipe_enabled(dev_priv, pipe);
  2587. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  2588. for train result */
  2589. reg = FDI_RX_IMR(pipe);
  2590. temp = I915_READ(reg);
  2591. temp &= ~FDI_RX_SYMBOL_LOCK;
  2592. temp &= ~FDI_RX_BIT_LOCK;
  2593. I915_WRITE(reg, temp);
  2594. I915_READ(reg);
  2595. udelay(150);
  2596. /* enable CPU FDI TX and PCH FDI RX */
  2597. reg = FDI_TX_CTL(pipe);
  2598. temp = I915_READ(reg);
  2599. temp &= ~FDI_DP_PORT_WIDTH_MASK;
  2600. temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes);
  2601. temp &= ~FDI_LINK_TRAIN_NONE;
  2602. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2603. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  2604. reg = FDI_RX_CTL(pipe);
  2605. temp = I915_READ(reg);
  2606. temp &= ~FDI_LINK_TRAIN_NONE;
  2607. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2608. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  2609. POSTING_READ(reg);
  2610. udelay(150);
  2611. /* Ironlake workaround, enable clock pointer after FDI enable*/
  2612. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
  2613. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR |
  2614. FDI_RX_PHASE_SYNC_POINTER_EN);
  2615. reg = FDI_RX_IIR(pipe);
  2616. for (tries = 0; tries < 5; tries++) {
  2617. temp = I915_READ(reg);
  2618. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2619. if ((temp & FDI_RX_BIT_LOCK)) {
  2620. DRM_DEBUG_KMS("FDI train 1 done.\n");
  2621. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  2622. break;
  2623. }
  2624. }
  2625. if (tries == 5)
  2626. DRM_ERROR("FDI train 1 fail!\n");
  2627. /* Train 2 */
  2628. reg = FDI_TX_CTL(pipe);
  2629. temp = I915_READ(reg);
  2630. temp &= ~FDI_LINK_TRAIN_NONE;
  2631. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2632. I915_WRITE(reg, temp);
  2633. reg = FDI_RX_CTL(pipe);
  2634. temp = I915_READ(reg);
  2635. temp &= ~FDI_LINK_TRAIN_NONE;
  2636. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2637. I915_WRITE(reg, temp);
  2638. POSTING_READ(reg);
  2639. udelay(150);
  2640. reg = FDI_RX_IIR(pipe);
  2641. for (tries = 0; tries < 5; tries++) {
  2642. temp = I915_READ(reg);
  2643. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2644. if (temp & FDI_RX_SYMBOL_LOCK) {
  2645. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  2646. DRM_DEBUG_KMS("FDI train 2 done.\n");
  2647. break;
  2648. }
  2649. }
  2650. if (tries == 5)
  2651. DRM_ERROR("FDI train 2 fail!\n");
  2652. DRM_DEBUG_KMS("FDI train done\n");
  2653. }
  2654. static const int snb_b_fdi_train_param[] = {
  2655. FDI_LINK_TRAIN_400MV_0DB_SNB_B,
  2656. FDI_LINK_TRAIN_400MV_6DB_SNB_B,
  2657. FDI_LINK_TRAIN_600MV_3_5DB_SNB_B,
  2658. FDI_LINK_TRAIN_800MV_0DB_SNB_B,
  2659. };
  2660. /* The FDI link training functions for SNB/Cougarpoint. */
  2661. static void gen6_fdi_link_train(struct drm_crtc *crtc)
  2662. {
  2663. struct drm_device *dev = crtc->dev;
  2664. struct drm_i915_private *dev_priv = dev->dev_private;
  2665. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2666. int pipe = intel_crtc->pipe;
  2667. u32 reg, temp, i, retry;
  2668. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  2669. for train result */
  2670. reg = FDI_RX_IMR(pipe);
  2671. temp = I915_READ(reg);
  2672. temp &= ~FDI_RX_SYMBOL_LOCK;
  2673. temp &= ~FDI_RX_BIT_LOCK;
  2674. I915_WRITE(reg, temp);
  2675. POSTING_READ(reg);
  2676. udelay(150);
  2677. /* enable CPU FDI TX and PCH FDI RX */
  2678. reg = FDI_TX_CTL(pipe);
  2679. temp = I915_READ(reg);
  2680. temp &= ~FDI_DP_PORT_WIDTH_MASK;
  2681. temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes);
  2682. temp &= ~FDI_LINK_TRAIN_NONE;
  2683. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2684. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2685. /* SNB-B */
  2686. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  2687. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  2688. I915_WRITE(FDI_RX_MISC(pipe),
  2689. FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
  2690. reg = FDI_RX_CTL(pipe);
  2691. temp = I915_READ(reg);
  2692. if (HAS_PCH_CPT(dev)) {
  2693. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2694. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2695. } else {
  2696. temp &= ~FDI_LINK_TRAIN_NONE;
  2697. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2698. }
  2699. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  2700. POSTING_READ(reg);
  2701. udelay(150);
  2702. for (i = 0; i < 4; i++) {
  2703. reg = FDI_TX_CTL(pipe);
  2704. temp = I915_READ(reg);
  2705. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2706. temp |= snb_b_fdi_train_param[i];
  2707. I915_WRITE(reg, temp);
  2708. POSTING_READ(reg);
  2709. udelay(500);
  2710. for (retry = 0; retry < 5; retry++) {
  2711. reg = FDI_RX_IIR(pipe);
  2712. temp = I915_READ(reg);
  2713. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2714. if (temp & FDI_RX_BIT_LOCK) {
  2715. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  2716. DRM_DEBUG_KMS("FDI train 1 done.\n");
  2717. break;
  2718. }
  2719. udelay(50);
  2720. }
  2721. if (retry < 5)
  2722. break;
  2723. }
  2724. if (i == 4)
  2725. DRM_ERROR("FDI train 1 fail!\n");
  2726. /* Train 2 */
  2727. reg = FDI_TX_CTL(pipe);
  2728. temp = I915_READ(reg);
  2729. temp &= ~FDI_LINK_TRAIN_NONE;
  2730. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2731. if (IS_GEN6(dev)) {
  2732. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2733. /* SNB-B */
  2734. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  2735. }
  2736. I915_WRITE(reg, temp);
  2737. reg = FDI_RX_CTL(pipe);
  2738. temp = I915_READ(reg);
  2739. if (HAS_PCH_CPT(dev)) {
  2740. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2741. temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
  2742. } else {
  2743. temp &= ~FDI_LINK_TRAIN_NONE;
  2744. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2745. }
  2746. I915_WRITE(reg, temp);
  2747. POSTING_READ(reg);
  2748. udelay(150);
  2749. for (i = 0; i < 4; i++) {
  2750. reg = FDI_TX_CTL(pipe);
  2751. temp = I915_READ(reg);
  2752. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2753. temp |= snb_b_fdi_train_param[i];
  2754. I915_WRITE(reg, temp);
  2755. POSTING_READ(reg);
  2756. udelay(500);
  2757. for (retry = 0; retry < 5; retry++) {
  2758. reg = FDI_RX_IIR(pipe);
  2759. temp = I915_READ(reg);
  2760. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2761. if (temp & FDI_RX_SYMBOL_LOCK) {
  2762. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  2763. DRM_DEBUG_KMS("FDI train 2 done.\n");
  2764. break;
  2765. }
  2766. udelay(50);
  2767. }
  2768. if (retry < 5)
  2769. break;
  2770. }
  2771. if (i == 4)
  2772. DRM_ERROR("FDI train 2 fail!\n");
  2773. DRM_DEBUG_KMS("FDI train done.\n");
  2774. }
  2775. /* Manual link training for Ivy Bridge A0 parts */
  2776. static void ivb_manual_fdi_link_train(struct drm_crtc *crtc)
  2777. {
  2778. struct drm_device *dev = crtc->dev;
  2779. struct drm_i915_private *dev_priv = dev->dev_private;
  2780. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2781. int pipe = intel_crtc->pipe;
  2782. u32 reg, temp, i, j;
  2783. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  2784. for train result */
  2785. reg = FDI_RX_IMR(pipe);
  2786. temp = I915_READ(reg);
  2787. temp &= ~FDI_RX_SYMBOL_LOCK;
  2788. temp &= ~FDI_RX_BIT_LOCK;
  2789. I915_WRITE(reg, temp);
  2790. POSTING_READ(reg);
  2791. udelay(150);
  2792. DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
  2793. I915_READ(FDI_RX_IIR(pipe)));
  2794. /* Try each vswing and preemphasis setting twice before moving on */
  2795. for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) {
  2796. /* disable first in case we need to retry */
  2797. reg = FDI_TX_CTL(pipe);
  2798. temp = I915_READ(reg);
  2799. temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB);
  2800. temp &= ~FDI_TX_ENABLE;
  2801. I915_WRITE(reg, temp);
  2802. reg = FDI_RX_CTL(pipe);
  2803. temp = I915_READ(reg);
  2804. temp &= ~FDI_LINK_TRAIN_AUTO;
  2805. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2806. temp &= ~FDI_RX_ENABLE;
  2807. I915_WRITE(reg, temp);
  2808. /* enable CPU FDI TX and PCH FDI RX */
  2809. reg = FDI_TX_CTL(pipe);
  2810. temp = I915_READ(reg);
  2811. temp &= ~FDI_DP_PORT_WIDTH_MASK;
  2812. temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes);
  2813. temp |= FDI_LINK_TRAIN_PATTERN_1_IVB;
  2814. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2815. temp |= snb_b_fdi_train_param[j/2];
  2816. temp |= FDI_COMPOSITE_SYNC;
  2817. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  2818. I915_WRITE(FDI_RX_MISC(pipe),
  2819. FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
  2820. reg = FDI_RX_CTL(pipe);
  2821. temp = I915_READ(reg);
  2822. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2823. temp |= FDI_COMPOSITE_SYNC;
  2824. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  2825. POSTING_READ(reg);
  2826. udelay(1); /* should be 0.5us */
  2827. for (i = 0; i < 4; i++) {
  2828. reg = FDI_RX_IIR(pipe);
  2829. temp = I915_READ(reg);
  2830. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2831. if (temp & FDI_RX_BIT_LOCK ||
  2832. (I915_READ(reg) & FDI_RX_BIT_LOCK)) {
  2833. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  2834. DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
  2835. i);
  2836. break;
  2837. }
  2838. udelay(1); /* should be 0.5us */
  2839. }
  2840. if (i == 4) {
  2841. DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2);
  2842. continue;
  2843. }
  2844. /* Train 2 */
  2845. reg = FDI_TX_CTL(pipe);
  2846. temp = I915_READ(reg);
  2847. temp &= ~FDI_LINK_TRAIN_NONE_IVB;
  2848. temp |= FDI_LINK_TRAIN_PATTERN_2_IVB;
  2849. I915_WRITE(reg, temp);
  2850. reg = FDI_RX_CTL(pipe);
  2851. temp = I915_READ(reg);
  2852. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2853. temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
  2854. I915_WRITE(reg, temp);
  2855. POSTING_READ(reg);
  2856. udelay(2); /* should be 1.5us */
  2857. for (i = 0; i < 4; i++) {
  2858. reg = FDI_RX_IIR(pipe);
  2859. temp = I915_READ(reg);
  2860. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2861. if (temp & FDI_RX_SYMBOL_LOCK ||
  2862. (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) {
  2863. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  2864. DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
  2865. i);
  2866. goto train_done;
  2867. }
  2868. udelay(2); /* should be 1.5us */
  2869. }
  2870. if (i == 4)
  2871. DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j / 2);
  2872. }
  2873. train_done:
  2874. DRM_DEBUG_KMS("FDI train done.\n");
  2875. }
  2876. static void ironlake_fdi_pll_enable(struct intel_crtc *intel_crtc)
  2877. {
  2878. struct drm_device *dev = intel_crtc->base.dev;
  2879. struct drm_i915_private *dev_priv = dev->dev_private;
  2880. int pipe = intel_crtc->pipe;
  2881. u32 reg, temp;
  2882. /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
  2883. reg = FDI_RX_CTL(pipe);
  2884. temp = I915_READ(reg);
  2885. temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16));
  2886. temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes);
  2887. temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
  2888. I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE);
  2889. POSTING_READ(reg);
  2890. udelay(200);
  2891. /* Switch from Rawclk to PCDclk */
  2892. temp = I915_READ(reg);
  2893. I915_WRITE(reg, temp | FDI_PCDCLK);
  2894. POSTING_READ(reg);
  2895. udelay(200);
  2896. /* Enable CPU FDI TX PLL, always on for Ironlake */
  2897. reg = FDI_TX_CTL(pipe);
  2898. temp = I915_READ(reg);
  2899. if ((temp & FDI_TX_PLL_ENABLE) == 0) {
  2900. I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE);
  2901. POSTING_READ(reg);
  2902. udelay(100);
  2903. }
  2904. }
  2905. static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc)
  2906. {
  2907. struct drm_device *dev = intel_crtc->base.dev;
  2908. struct drm_i915_private *dev_priv = dev->dev_private;
  2909. int pipe = intel_crtc->pipe;
  2910. u32 reg, temp;
  2911. /* Switch from PCDclk to Rawclk */
  2912. reg = FDI_RX_CTL(pipe);
  2913. temp = I915_READ(reg);
  2914. I915_WRITE(reg, temp & ~FDI_PCDCLK);
  2915. /* Disable CPU FDI TX PLL */
  2916. reg = FDI_TX_CTL(pipe);
  2917. temp = I915_READ(reg);
  2918. I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE);
  2919. POSTING_READ(reg);
  2920. udelay(100);
  2921. reg = FDI_RX_CTL(pipe);
  2922. temp = I915_READ(reg);
  2923. I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE);
  2924. /* Wait for the clocks to turn off. */
  2925. POSTING_READ(reg);
  2926. udelay(100);
  2927. }
  2928. static void ironlake_fdi_disable(struct drm_crtc *crtc)
  2929. {
  2930. struct drm_device *dev = crtc->dev;
  2931. struct drm_i915_private *dev_priv = dev->dev_private;
  2932. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2933. int pipe = intel_crtc->pipe;
  2934. u32 reg, temp;
  2935. /* disable CPU FDI tx and PCH FDI rx */
  2936. reg = FDI_TX_CTL(pipe);
  2937. temp = I915_READ(reg);
  2938. I915_WRITE(reg, temp & ~FDI_TX_ENABLE);
  2939. POSTING_READ(reg);
  2940. reg = FDI_RX_CTL(pipe);
  2941. temp = I915_READ(reg);
  2942. temp &= ~(0x7 << 16);
  2943. temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
  2944. I915_WRITE(reg, temp & ~FDI_RX_ENABLE);
  2945. POSTING_READ(reg);
  2946. udelay(100);
  2947. /* Ironlake workaround, disable clock pointer after downing FDI */
  2948. if (HAS_PCH_IBX(dev))
  2949. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
  2950. /* still set train pattern 1 */
  2951. reg = FDI_TX_CTL(pipe);
  2952. temp = I915_READ(reg);
  2953. temp &= ~FDI_LINK_TRAIN_NONE;
  2954. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2955. I915_WRITE(reg, temp);
  2956. reg = FDI_RX_CTL(pipe);
  2957. temp = I915_READ(reg);
  2958. if (HAS_PCH_CPT(dev)) {
  2959. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2960. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2961. } else {
  2962. temp &= ~FDI_LINK_TRAIN_NONE;
  2963. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2964. }
  2965. /* BPC in FDI rx is consistent with that in PIPECONF */
  2966. temp &= ~(0x07 << 16);
  2967. temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
  2968. I915_WRITE(reg, temp);
  2969. POSTING_READ(reg);
  2970. udelay(100);
  2971. }
  2972. bool intel_has_pending_fb_unpin(struct drm_device *dev)
  2973. {
  2974. struct intel_crtc *crtc;
  2975. /* Note that we don't need to be called with mode_config.lock here
  2976. * as our list of CRTC objects is static for the lifetime of the
  2977. * device and so cannot disappear as we iterate. Similarly, we can
  2978. * happily treat the predicates as racy, atomic checks as userspace
  2979. * cannot claim and pin a new fb without at least acquring the
  2980. * struct_mutex and so serialising with us.
  2981. */
  2982. for_each_intel_crtc(dev, crtc) {
  2983. if (atomic_read(&crtc->unpin_work_count) == 0)
  2984. continue;
  2985. if (crtc->unpin_work)
  2986. intel_wait_for_vblank(dev, crtc->pipe);
  2987. return true;
  2988. }
  2989. return false;
  2990. }
  2991. static void page_flip_completed(struct intel_crtc *intel_crtc)
  2992. {
  2993. struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
  2994. struct intel_unpin_work *work = intel_crtc->unpin_work;
  2995. /* ensure that the unpin work is consistent wrt ->pending. */
  2996. smp_rmb();
  2997. intel_crtc->unpin_work = NULL;
  2998. if (work->event)
  2999. drm_send_vblank_event(intel_crtc->base.dev,
  3000. intel_crtc->pipe,
  3001. work->event);
  3002. drm_crtc_vblank_put(&intel_crtc->base);
  3003. wake_up_all(&dev_priv->pending_flip_queue);
  3004. queue_work(dev_priv->wq, &work->work);
  3005. trace_i915_flip_complete(intel_crtc->plane,
  3006. work->pending_flip_obj);
  3007. }
  3008. void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
  3009. {
  3010. struct drm_device *dev = crtc->dev;
  3011. struct drm_i915_private *dev_priv = dev->dev_private;
  3012. WARN_ON(waitqueue_active(&dev_priv->pending_flip_queue));
  3013. if (WARN_ON(wait_event_timeout(dev_priv->pending_flip_queue,
  3014. !intel_crtc_has_pending_flip(crtc),
  3015. 60*HZ) == 0)) {
  3016. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3017. spin_lock_irq(&dev->event_lock);
  3018. if (intel_crtc->unpin_work) {
  3019. WARN_ONCE(1, "Removing stuck page flip\n");
  3020. page_flip_completed(intel_crtc);
  3021. }
  3022. spin_unlock_irq(&dev->event_lock);
  3023. }
  3024. if (crtc->primary->fb) {
  3025. mutex_lock(&dev->struct_mutex);
  3026. intel_finish_fb(crtc->primary->fb);
  3027. mutex_unlock(&dev->struct_mutex);
  3028. }
  3029. }
  3030. /* Program iCLKIP clock to the desired frequency */
  3031. static void lpt_program_iclkip(struct drm_crtc *crtc)
  3032. {
  3033. struct drm_device *dev = crtc->dev;
  3034. struct drm_i915_private *dev_priv = dev->dev_private;
  3035. int clock = to_intel_crtc(crtc)->config.adjusted_mode.crtc_clock;
  3036. u32 divsel, phaseinc, auxdiv, phasedir = 0;
  3037. u32 temp;
  3038. mutex_lock(&dev_priv->dpio_lock);
  3039. /* It is necessary to ungate the pixclk gate prior to programming
  3040. * the divisors, and gate it back when it is done.
  3041. */
  3042. I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE);
  3043. /* Disable SSCCTL */
  3044. intel_sbi_write(dev_priv, SBI_SSCCTL6,
  3045. intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK) |
  3046. SBI_SSCCTL_DISABLE,
  3047. SBI_ICLK);
  3048. /* 20MHz is a corner case which is out of range for the 7-bit divisor */
  3049. if (clock == 20000) {
  3050. auxdiv = 1;
  3051. divsel = 0x41;
  3052. phaseinc = 0x20;
  3053. } else {
  3054. /* The iCLK virtual clock root frequency is in MHz,
  3055. * but the adjusted_mode->crtc_clock in in KHz. To get the
  3056. * divisors, it is necessary to divide one by another, so we
  3057. * convert the virtual clock precision to KHz here for higher
  3058. * precision.
  3059. */
  3060. u32 iclk_virtual_root_freq = 172800 * 1000;
  3061. u32 iclk_pi_range = 64;
  3062. u32 desired_divisor, msb_divisor_value, pi_value;
  3063. desired_divisor = (iclk_virtual_root_freq / clock);
  3064. msb_divisor_value = desired_divisor / iclk_pi_range;
  3065. pi_value = desired_divisor % iclk_pi_range;
  3066. auxdiv = 0;
  3067. divsel = msb_divisor_value - 2;
  3068. phaseinc = pi_value;
  3069. }
  3070. /* This should not happen with any sane values */
  3071. WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) &
  3072. ~SBI_SSCDIVINTPHASE_DIVSEL_MASK);
  3073. WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) &
  3074. ~SBI_SSCDIVINTPHASE_INCVAL_MASK);
  3075. DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
  3076. clock,
  3077. auxdiv,
  3078. divsel,
  3079. phasedir,
  3080. phaseinc);
  3081. /* Program SSCDIVINTPHASE6 */
  3082. temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
  3083. temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK;
  3084. temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel);
  3085. temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK;
  3086. temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc);
  3087. temp |= SBI_SSCDIVINTPHASE_DIR(phasedir);
  3088. temp |= SBI_SSCDIVINTPHASE_PROPAGATE;
  3089. intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK);
  3090. /* Program SSCAUXDIV */
  3091. temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
  3092. temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
  3093. temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv);
  3094. intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK);
  3095. /* Enable modulator and associated divider */
  3096. temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
  3097. temp &= ~SBI_SSCCTL_DISABLE;
  3098. intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
  3099. /* Wait for initialization time */
  3100. udelay(24);
  3101. I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE);
  3102. mutex_unlock(&dev_priv->dpio_lock);
  3103. }
  3104. static void ironlake_pch_transcoder_set_timings(struct intel_crtc *crtc,
  3105. enum pipe pch_transcoder)
  3106. {
  3107. struct drm_device *dev = crtc->base.dev;
  3108. struct drm_i915_private *dev_priv = dev->dev_private;
  3109. enum transcoder cpu_transcoder = crtc->config.cpu_transcoder;
  3110. I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder),
  3111. I915_READ(HTOTAL(cpu_transcoder)));
  3112. I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder),
  3113. I915_READ(HBLANK(cpu_transcoder)));
  3114. I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder),
  3115. I915_READ(HSYNC(cpu_transcoder)));
  3116. I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder),
  3117. I915_READ(VTOTAL(cpu_transcoder)));
  3118. I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder),
  3119. I915_READ(VBLANK(cpu_transcoder)));
  3120. I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder),
  3121. I915_READ(VSYNC(cpu_transcoder)));
  3122. I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder),
  3123. I915_READ(VSYNCSHIFT(cpu_transcoder)));
  3124. }
  3125. static void cpt_enable_fdi_bc_bifurcation(struct drm_device *dev)
  3126. {
  3127. struct drm_i915_private *dev_priv = dev->dev_private;
  3128. uint32_t temp;
  3129. temp = I915_READ(SOUTH_CHICKEN1);
  3130. if (temp & FDI_BC_BIFURCATION_SELECT)
  3131. return;
  3132. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
  3133. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
  3134. temp |= FDI_BC_BIFURCATION_SELECT;
  3135. DRM_DEBUG_KMS("enabling fdi C rx\n");
  3136. I915_WRITE(SOUTH_CHICKEN1, temp);
  3137. POSTING_READ(SOUTH_CHICKEN1);
  3138. }
  3139. static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc *intel_crtc)
  3140. {
  3141. struct drm_device *dev = intel_crtc->base.dev;
  3142. struct drm_i915_private *dev_priv = dev->dev_private;
  3143. switch (intel_crtc->pipe) {
  3144. case PIPE_A:
  3145. break;
  3146. case PIPE_B:
  3147. if (intel_crtc->config.fdi_lanes > 2)
  3148. WARN_ON(I915_READ(SOUTH_CHICKEN1) & FDI_BC_BIFURCATION_SELECT);
  3149. else
  3150. cpt_enable_fdi_bc_bifurcation(dev);
  3151. break;
  3152. case PIPE_C:
  3153. cpt_enable_fdi_bc_bifurcation(dev);
  3154. break;
  3155. default:
  3156. BUG();
  3157. }
  3158. }
  3159. /*
  3160. * Enable PCH resources required for PCH ports:
  3161. * - PCH PLLs
  3162. * - FDI training & RX/TX
  3163. * - update transcoder timings
  3164. * - DP transcoding bits
  3165. * - transcoder
  3166. */
  3167. static void ironlake_pch_enable(struct drm_crtc *crtc)
  3168. {
  3169. struct drm_device *dev = crtc->dev;
  3170. struct drm_i915_private *dev_priv = dev->dev_private;
  3171. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3172. int pipe = intel_crtc->pipe;
  3173. u32 reg, temp;
  3174. assert_pch_transcoder_disabled(dev_priv, pipe);
  3175. if (IS_IVYBRIDGE(dev))
  3176. ivybridge_update_fdi_bc_bifurcation(intel_crtc);
  3177. /* Write the TU size bits before fdi link training, so that error
  3178. * detection works. */
  3179. I915_WRITE(FDI_RX_TUSIZE1(pipe),
  3180. I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
  3181. /* For PCH output, training FDI link */
  3182. dev_priv->display.fdi_link_train(crtc);
  3183. /* We need to program the right clock selection before writing the pixel
  3184. * mutliplier into the DPLL. */
  3185. if (HAS_PCH_CPT(dev)) {
  3186. u32 sel;
  3187. temp = I915_READ(PCH_DPLL_SEL);
  3188. temp |= TRANS_DPLL_ENABLE(pipe);
  3189. sel = TRANS_DPLLB_SEL(pipe);
  3190. if (intel_crtc->config.shared_dpll == DPLL_ID_PCH_PLL_B)
  3191. temp |= sel;
  3192. else
  3193. temp &= ~sel;
  3194. I915_WRITE(PCH_DPLL_SEL, temp);
  3195. }
  3196. /* XXX: pch pll's can be enabled any time before we enable the PCH
  3197. * transcoder, and we actually should do this to not upset any PCH
  3198. * transcoder that already use the clock when we share it.
  3199. *
  3200. * Note that enable_shared_dpll tries to do the right thing, but
  3201. * get_shared_dpll unconditionally resets the pll - we need that to have
  3202. * the right LVDS enable sequence. */
  3203. intel_enable_shared_dpll(intel_crtc);
  3204. /* set transcoder timing, panel must allow it */
  3205. assert_panel_unlocked(dev_priv, pipe);
  3206. ironlake_pch_transcoder_set_timings(intel_crtc, pipe);
  3207. intel_fdi_normal_train(crtc);
  3208. /* For PCH DP, enable TRANS_DP_CTL */
  3209. if (HAS_PCH_CPT(dev) &&
  3210. (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DISPLAYPORT) ||
  3211. intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_EDP))) {
  3212. u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5;
  3213. reg = TRANS_DP_CTL(pipe);
  3214. temp = I915_READ(reg);
  3215. temp &= ~(TRANS_DP_PORT_SEL_MASK |
  3216. TRANS_DP_SYNC_MASK |
  3217. TRANS_DP_BPC_MASK);
  3218. temp |= (TRANS_DP_OUTPUT_ENABLE |
  3219. TRANS_DP_ENH_FRAMING);
  3220. temp |= bpc << 9; /* same format but at 11:9 */
  3221. if (crtc->mode.flags & DRM_MODE_FLAG_PHSYNC)
  3222. temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
  3223. if (crtc->mode.flags & DRM_MODE_FLAG_PVSYNC)
  3224. temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
  3225. switch (intel_trans_dp_port_sel(crtc)) {
  3226. case PCH_DP_B:
  3227. temp |= TRANS_DP_PORT_SEL_B;
  3228. break;
  3229. case PCH_DP_C:
  3230. temp |= TRANS_DP_PORT_SEL_C;
  3231. break;
  3232. case PCH_DP_D:
  3233. temp |= TRANS_DP_PORT_SEL_D;
  3234. break;
  3235. default:
  3236. BUG();
  3237. }
  3238. I915_WRITE(reg, temp);
  3239. }
  3240. ironlake_enable_pch_transcoder(dev_priv, pipe);
  3241. }
  3242. static void lpt_pch_enable(struct drm_crtc *crtc)
  3243. {
  3244. struct drm_device *dev = crtc->dev;
  3245. struct drm_i915_private *dev_priv = dev->dev_private;
  3246. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3247. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  3248. assert_pch_transcoder_disabled(dev_priv, TRANSCODER_A);
  3249. lpt_program_iclkip(crtc);
  3250. /* Set transcoder timing. */
  3251. ironlake_pch_transcoder_set_timings(intel_crtc, PIPE_A);
  3252. lpt_enable_pch_transcoder(dev_priv, cpu_transcoder);
  3253. }
  3254. void intel_put_shared_dpll(struct intel_crtc *crtc)
  3255. {
  3256. struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
  3257. if (pll == NULL)
  3258. return;
  3259. if (pll->refcount == 0) {
  3260. WARN(1, "bad %s refcount\n", pll->name);
  3261. return;
  3262. }
  3263. if (--pll->refcount == 0) {
  3264. WARN_ON(pll->on);
  3265. WARN_ON(pll->active);
  3266. }
  3267. crtc->config.shared_dpll = DPLL_ID_PRIVATE;
  3268. }
  3269. struct intel_shared_dpll *intel_get_shared_dpll(struct intel_crtc *crtc)
  3270. {
  3271. struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
  3272. struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
  3273. enum intel_dpll_id i;
  3274. if (pll) {
  3275. DRM_DEBUG_KMS("CRTC:%d dropping existing %s\n",
  3276. crtc->base.base.id, pll->name);
  3277. intel_put_shared_dpll(crtc);
  3278. }
  3279. if (HAS_PCH_IBX(dev_priv->dev)) {
  3280. /* Ironlake PCH has a fixed PLL->PCH pipe mapping. */
  3281. i = (enum intel_dpll_id) crtc->pipe;
  3282. pll = &dev_priv->shared_dplls[i];
  3283. DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n",
  3284. crtc->base.base.id, pll->name);
  3285. WARN_ON(pll->refcount);
  3286. goto found;
  3287. }
  3288. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  3289. pll = &dev_priv->shared_dplls[i];
  3290. /* Only want to check enabled timings first */
  3291. if (pll->refcount == 0)
  3292. continue;
  3293. if (memcmp(&crtc->config.dpll_hw_state, &pll->hw_state,
  3294. sizeof(pll->hw_state)) == 0) {
  3295. DRM_DEBUG_KMS("CRTC:%d sharing existing %s (refcount %d, ative %d)\n",
  3296. crtc->base.base.id,
  3297. pll->name, pll->refcount, pll->active);
  3298. goto found;
  3299. }
  3300. }
  3301. /* Ok no matching timings, maybe there's a free one? */
  3302. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  3303. pll = &dev_priv->shared_dplls[i];
  3304. if (pll->refcount == 0) {
  3305. DRM_DEBUG_KMS("CRTC:%d allocated %s\n",
  3306. crtc->base.base.id, pll->name);
  3307. goto found;
  3308. }
  3309. }
  3310. return NULL;
  3311. found:
  3312. if (pll->refcount == 0)
  3313. pll->hw_state = crtc->config.dpll_hw_state;
  3314. crtc->config.shared_dpll = i;
  3315. DRM_DEBUG_DRIVER("using %s for pipe %c\n", pll->name,
  3316. pipe_name(crtc->pipe));
  3317. pll->refcount++;
  3318. return pll;
  3319. }
  3320. static void cpt_verify_modeset(struct drm_device *dev, int pipe)
  3321. {
  3322. struct drm_i915_private *dev_priv = dev->dev_private;
  3323. int dslreg = PIPEDSL(pipe);
  3324. u32 temp;
  3325. temp = I915_READ(dslreg);
  3326. udelay(500);
  3327. if (wait_for(I915_READ(dslreg) != temp, 5)) {
  3328. if (wait_for(I915_READ(dslreg) != temp, 5))
  3329. DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe));
  3330. }
  3331. }
  3332. static void ironlake_pfit_enable(struct intel_crtc *crtc)
  3333. {
  3334. struct drm_device *dev = crtc->base.dev;
  3335. struct drm_i915_private *dev_priv = dev->dev_private;
  3336. int pipe = crtc->pipe;
  3337. if (crtc->config.pch_pfit.enabled) {
  3338. /* Force use of hard-coded filter coefficients
  3339. * as some pre-programmed values are broken,
  3340. * e.g. x201.
  3341. */
  3342. if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev))
  3343. I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 |
  3344. PF_PIPE_SEL_IVB(pipe));
  3345. else
  3346. I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3);
  3347. I915_WRITE(PF_WIN_POS(pipe), crtc->config.pch_pfit.pos);
  3348. I915_WRITE(PF_WIN_SZ(pipe), crtc->config.pch_pfit.size);
  3349. }
  3350. }
  3351. static void intel_enable_planes(struct drm_crtc *crtc)
  3352. {
  3353. struct drm_device *dev = crtc->dev;
  3354. enum pipe pipe = to_intel_crtc(crtc)->pipe;
  3355. struct drm_plane *plane;
  3356. struct intel_plane *intel_plane;
  3357. drm_for_each_legacy_plane(plane, &dev->mode_config.plane_list) {
  3358. intel_plane = to_intel_plane(plane);
  3359. if (intel_plane->pipe == pipe)
  3360. intel_plane_restore(&intel_plane->base);
  3361. }
  3362. }
  3363. static void intel_disable_planes(struct drm_crtc *crtc)
  3364. {
  3365. struct drm_device *dev = crtc->dev;
  3366. enum pipe pipe = to_intel_crtc(crtc)->pipe;
  3367. struct drm_plane *plane;
  3368. struct intel_plane *intel_plane;
  3369. drm_for_each_legacy_plane(plane, &dev->mode_config.plane_list) {
  3370. intel_plane = to_intel_plane(plane);
  3371. if (intel_plane->pipe == pipe)
  3372. intel_plane_disable(&intel_plane->base);
  3373. }
  3374. }
  3375. void hsw_enable_ips(struct intel_crtc *crtc)
  3376. {
  3377. struct drm_device *dev = crtc->base.dev;
  3378. struct drm_i915_private *dev_priv = dev->dev_private;
  3379. if (!crtc->config.ips_enabled)
  3380. return;
  3381. /* We can only enable IPS after we enable a plane and wait for a vblank */
  3382. intel_wait_for_vblank(dev, crtc->pipe);
  3383. assert_plane_enabled(dev_priv, crtc->plane);
  3384. if (IS_BROADWELL(dev)) {
  3385. mutex_lock(&dev_priv->rps.hw_lock);
  3386. WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0xc0000000));
  3387. mutex_unlock(&dev_priv->rps.hw_lock);
  3388. /* Quoting Art Runyan: "its not safe to expect any particular
  3389. * value in IPS_CTL bit 31 after enabling IPS through the
  3390. * mailbox." Moreover, the mailbox may return a bogus state,
  3391. * so we need to just enable it and continue on.
  3392. */
  3393. } else {
  3394. I915_WRITE(IPS_CTL, IPS_ENABLE);
  3395. /* The bit only becomes 1 in the next vblank, so this wait here
  3396. * is essentially intel_wait_for_vblank. If we don't have this
  3397. * and don't wait for vblanks until the end of crtc_enable, then
  3398. * the HW state readout code will complain that the expected
  3399. * IPS_CTL value is not the one we read. */
  3400. if (wait_for(I915_READ_NOTRACE(IPS_CTL) & IPS_ENABLE, 50))
  3401. DRM_ERROR("Timed out waiting for IPS enable\n");
  3402. }
  3403. }
  3404. void hsw_disable_ips(struct intel_crtc *crtc)
  3405. {
  3406. struct drm_device *dev = crtc->base.dev;
  3407. struct drm_i915_private *dev_priv = dev->dev_private;
  3408. if (!crtc->config.ips_enabled)
  3409. return;
  3410. assert_plane_enabled(dev_priv, crtc->plane);
  3411. if (IS_BROADWELL(dev)) {
  3412. mutex_lock(&dev_priv->rps.hw_lock);
  3413. WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0));
  3414. mutex_unlock(&dev_priv->rps.hw_lock);
  3415. /* wait for pcode to finish disabling IPS, which may take up to 42ms */
  3416. if (wait_for((I915_READ(IPS_CTL) & IPS_ENABLE) == 0, 42))
  3417. DRM_ERROR("Timed out waiting for IPS disable\n");
  3418. } else {
  3419. I915_WRITE(IPS_CTL, 0);
  3420. POSTING_READ(IPS_CTL);
  3421. }
  3422. /* We need to wait for a vblank before we can disable the plane. */
  3423. intel_wait_for_vblank(dev, crtc->pipe);
  3424. }
  3425. /** Loads the palette/gamma unit for the CRTC with the prepared values */
  3426. static void intel_crtc_load_lut(struct drm_crtc *crtc)
  3427. {
  3428. struct drm_device *dev = crtc->dev;
  3429. struct drm_i915_private *dev_priv = dev->dev_private;
  3430. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3431. enum pipe pipe = intel_crtc->pipe;
  3432. int palreg = PALETTE(pipe);
  3433. int i;
  3434. bool reenable_ips = false;
  3435. /* The clocks have to be on to load the palette. */
  3436. if (!crtc->enabled || !intel_crtc->active)
  3437. return;
  3438. if (!HAS_PCH_SPLIT(dev_priv->dev)) {
  3439. if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI))
  3440. assert_dsi_pll_enabled(dev_priv);
  3441. else
  3442. assert_pll_enabled(dev_priv, pipe);
  3443. }
  3444. /* use legacy palette for Ironlake */
  3445. if (!HAS_GMCH_DISPLAY(dev))
  3446. palreg = LGC_PALETTE(pipe);
  3447. /* Workaround : Do not read or write the pipe palette/gamma data while
  3448. * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
  3449. */
  3450. if (IS_HASWELL(dev) && intel_crtc->config.ips_enabled &&
  3451. ((I915_READ(GAMMA_MODE(pipe)) & GAMMA_MODE_MODE_MASK) ==
  3452. GAMMA_MODE_MODE_SPLIT)) {
  3453. hsw_disable_ips(intel_crtc);
  3454. reenable_ips = true;
  3455. }
  3456. for (i = 0; i < 256; i++) {
  3457. I915_WRITE(palreg + 4 * i,
  3458. (intel_crtc->lut_r[i] << 16) |
  3459. (intel_crtc->lut_g[i] << 8) |
  3460. intel_crtc->lut_b[i]);
  3461. }
  3462. if (reenable_ips)
  3463. hsw_enable_ips(intel_crtc);
  3464. }
  3465. static void intel_crtc_dpms_overlay(struct intel_crtc *intel_crtc, bool enable)
  3466. {
  3467. if (!enable && intel_crtc->overlay) {
  3468. struct drm_device *dev = intel_crtc->base.dev;
  3469. struct drm_i915_private *dev_priv = dev->dev_private;
  3470. mutex_lock(&dev->struct_mutex);
  3471. dev_priv->mm.interruptible = false;
  3472. (void) intel_overlay_switch_off(intel_crtc->overlay);
  3473. dev_priv->mm.interruptible = true;
  3474. mutex_unlock(&dev->struct_mutex);
  3475. }
  3476. /* Let userspace switch the overlay on again. In most cases userspace
  3477. * has to recompute where to put it anyway.
  3478. */
  3479. }
  3480. static void intel_crtc_enable_planes(struct drm_crtc *crtc)
  3481. {
  3482. struct drm_device *dev = crtc->dev;
  3483. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3484. int pipe = intel_crtc->pipe;
  3485. intel_enable_primary_hw_plane(crtc->primary, crtc);
  3486. intel_enable_planes(crtc);
  3487. intel_crtc_update_cursor(crtc, true);
  3488. intel_crtc_dpms_overlay(intel_crtc, true);
  3489. hsw_enable_ips(intel_crtc);
  3490. mutex_lock(&dev->struct_mutex);
  3491. intel_update_fbc(dev);
  3492. mutex_unlock(&dev->struct_mutex);
  3493. /*
  3494. * FIXME: Once we grow proper nuclear flip support out of this we need
  3495. * to compute the mask of flip planes precisely. For the time being
  3496. * consider this a flip from a NULL plane.
  3497. */
  3498. intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_ALL_MASK(pipe));
  3499. }
  3500. static void intel_crtc_disable_planes(struct drm_crtc *crtc)
  3501. {
  3502. struct drm_device *dev = crtc->dev;
  3503. struct drm_i915_private *dev_priv = dev->dev_private;
  3504. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3505. int pipe = intel_crtc->pipe;
  3506. int plane = intel_crtc->plane;
  3507. intel_crtc_wait_for_pending_flips(crtc);
  3508. if (dev_priv->fbc.plane == plane)
  3509. intel_disable_fbc(dev);
  3510. hsw_disable_ips(intel_crtc);
  3511. intel_crtc_dpms_overlay(intel_crtc, false);
  3512. intel_crtc_update_cursor(crtc, false);
  3513. intel_disable_planes(crtc);
  3514. intel_disable_primary_hw_plane(crtc->primary, crtc);
  3515. /*
  3516. * FIXME: Once we grow proper nuclear flip support out of this we need
  3517. * to compute the mask of flip planes precisely. For the time being
  3518. * consider this a flip to a NULL plane.
  3519. */
  3520. intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_ALL_MASK(pipe));
  3521. }
  3522. static void ironlake_crtc_enable(struct drm_crtc *crtc)
  3523. {
  3524. struct drm_device *dev = crtc->dev;
  3525. struct drm_i915_private *dev_priv = dev->dev_private;
  3526. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3527. struct intel_encoder *encoder;
  3528. int pipe = intel_crtc->pipe;
  3529. WARN_ON(!crtc->enabled);
  3530. if (intel_crtc->active)
  3531. return;
  3532. if (intel_crtc->config.has_pch_encoder)
  3533. intel_prepare_shared_dpll(intel_crtc);
  3534. if (intel_crtc->config.has_dp_encoder)
  3535. intel_dp_set_m_n(intel_crtc);
  3536. intel_set_pipe_timings(intel_crtc);
  3537. if (intel_crtc->config.has_pch_encoder) {
  3538. intel_cpu_transcoder_set_m_n(intel_crtc,
  3539. &intel_crtc->config.fdi_m_n, NULL);
  3540. }
  3541. ironlake_set_pipeconf(crtc);
  3542. intel_crtc->active = true;
  3543. intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
  3544. intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
  3545. for_each_encoder_on_crtc(dev, crtc, encoder)
  3546. if (encoder->pre_enable)
  3547. encoder->pre_enable(encoder);
  3548. if (intel_crtc->config.has_pch_encoder) {
  3549. /* Note: FDI PLL enabling _must_ be done before we enable the
  3550. * cpu pipes, hence this is separate from all the other fdi/pch
  3551. * enabling. */
  3552. ironlake_fdi_pll_enable(intel_crtc);
  3553. } else {
  3554. assert_fdi_tx_disabled(dev_priv, pipe);
  3555. assert_fdi_rx_disabled(dev_priv, pipe);
  3556. }
  3557. ironlake_pfit_enable(intel_crtc);
  3558. /*
  3559. * On ILK+ LUT must be loaded before the pipe is running but with
  3560. * clocks enabled
  3561. */
  3562. intel_crtc_load_lut(crtc);
  3563. intel_update_watermarks(crtc);
  3564. intel_enable_pipe(intel_crtc);
  3565. if (intel_crtc->config.has_pch_encoder)
  3566. ironlake_pch_enable(crtc);
  3567. for_each_encoder_on_crtc(dev, crtc, encoder)
  3568. encoder->enable(encoder);
  3569. if (HAS_PCH_CPT(dev))
  3570. cpt_verify_modeset(dev, intel_crtc->pipe);
  3571. assert_vblank_disabled(crtc);
  3572. drm_crtc_vblank_on(crtc);
  3573. intel_crtc_enable_planes(crtc);
  3574. }
  3575. /* IPS only exists on ULT machines and is tied to pipe A. */
  3576. static bool hsw_crtc_supports_ips(struct intel_crtc *crtc)
  3577. {
  3578. return HAS_IPS(crtc->base.dev) && crtc->pipe == PIPE_A;
  3579. }
  3580. /*
  3581. * This implements the workaround described in the "notes" section of the mode
  3582. * set sequence documentation. When going from no pipes or single pipe to
  3583. * multiple pipes, and planes are enabled after the pipe, we need to wait at
  3584. * least 2 vblanks on the first pipe before enabling planes on the second pipe.
  3585. */
  3586. static void haswell_mode_set_planes_workaround(struct intel_crtc *crtc)
  3587. {
  3588. struct drm_device *dev = crtc->base.dev;
  3589. struct intel_crtc *crtc_it, *other_active_crtc = NULL;
  3590. /* We want to get the other_active_crtc only if there's only 1 other
  3591. * active crtc. */
  3592. for_each_intel_crtc(dev, crtc_it) {
  3593. if (!crtc_it->active || crtc_it == crtc)
  3594. continue;
  3595. if (other_active_crtc)
  3596. return;
  3597. other_active_crtc = crtc_it;
  3598. }
  3599. if (!other_active_crtc)
  3600. return;
  3601. intel_wait_for_vblank(dev, other_active_crtc->pipe);
  3602. intel_wait_for_vblank(dev, other_active_crtc->pipe);
  3603. }
  3604. static void haswell_crtc_enable(struct drm_crtc *crtc)
  3605. {
  3606. struct drm_device *dev = crtc->dev;
  3607. struct drm_i915_private *dev_priv = dev->dev_private;
  3608. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3609. struct intel_encoder *encoder;
  3610. int pipe = intel_crtc->pipe;
  3611. WARN_ON(!crtc->enabled);
  3612. if (intel_crtc->active)
  3613. return;
  3614. if (intel_crtc_to_shared_dpll(intel_crtc))
  3615. intel_enable_shared_dpll(intel_crtc);
  3616. if (intel_crtc->config.has_dp_encoder)
  3617. intel_dp_set_m_n(intel_crtc);
  3618. intel_set_pipe_timings(intel_crtc);
  3619. if (intel_crtc->config.cpu_transcoder != TRANSCODER_EDP) {
  3620. I915_WRITE(PIPE_MULT(intel_crtc->config.cpu_transcoder),
  3621. intel_crtc->config.pixel_multiplier - 1);
  3622. }
  3623. if (intel_crtc->config.has_pch_encoder) {
  3624. intel_cpu_transcoder_set_m_n(intel_crtc,
  3625. &intel_crtc->config.fdi_m_n, NULL);
  3626. }
  3627. haswell_set_pipeconf(crtc);
  3628. intel_set_pipe_csc(crtc);
  3629. intel_crtc->active = true;
  3630. intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
  3631. for_each_encoder_on_crtc(dev, crtc, encoder)
  3632. if (encoder->pre_enable)
  3633. encoder->pre_enable(encoder);
  3634. if (intel_crtc->config.has_pch_encoder) {
  3635. intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A,
  3636. true);
  3637. dev_priv->display.fdi_link_train(crtc);
  3638. }
  3639. intel_ddi_enable_pipe_clock(intel_crtc);
  3640. ironlake_pfit_enable(intel_crtc);
  3641. /*
  3642. * On ILK+ LUT must be loaded before the pipe is running but with
  3643. * clocks enabled
  3644. */
  3645. intel_crtc_load_lut(crtc);
  3646. intel_ddi_set_pipe_settings(crtc);
  3647. intel_ddi_enable_transcoder_func(crtc);
  3648. intel_update_watermarks(crtc);
  3649. intel_enable_pipe(intel_crtc);
  3650. if (intel_crtc->config.has_pch_encoder)
  3651. lpt_pch_enable(crtc);
  3652. if (intel_crtc->config.dp_encoder_is_mst)
  3653. intel_ddi_set_vc_payload_alloc(crtc, true);
  3654. for_each_encoder_on_crtc(dev, crtc, encoder) {
  3655. encoder->enable(encoder);
  3656. intel_opregion_notify_encoder(encoder, true);
  3657. }
  3658. assert_vblank_disabled(crtc);
  3659. drm_crtc_vblank_on(crtc);
  3660. /* If we change the relative order between pipe/planes enabling, we need
  3661. * to change the workaround. */
  3662. haswell_mode_set_planes_workaround(intel_crtc);
  3663. intel_crtc_enable_planes(crtc);
  3664. }
  3665. static void ironlake_pfit_disable(struct intel_crtc *crtc)
  3666. {
  3667. struct drm_device *dev = crtc->base.dev;
  3668. struct drm_i915_private *dev_priv = dev->dev_private;
  3669. int pipe = crtc->pipe;
  3670. /* To avoid upsetting the power well on haswell only disable the pfit if
  3671. * it's in use. The hw state code will make sure we get this right. */
  3672. if (crtc->config.pch_pfit.enabled) {
  3673. I915_WRITE(PF_CTL(pipe), 0);
  3674. I915_WRITE(PF_WIN_POS(pipe), 0);
  3675. I915_WRITE(PF_WIN_SZ(pipe), 0);
  3676. }
  3677. }
  3678. static void ironlake_crtc_disable(struct drm_crtc *crtc)
  3679. {
  3680. struct drm_device *dev = crtc->dev;
  3681. struct drm_i915_private *dev_priv = dev->dev_private;
  3682. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3683. struct intel_encoder *encoder;
  3684. int pipe = intel_crtc->pipe;
  3685. u32 reg, temp;
  3686. if (!intel_crtc->active)
  3687. return;
  3688. intel_crtc_disable_planes(crtc);
  3689. drm_crtc_vblank_off(crtc);
  3690. assert_vblank_disabled(crtc);
  3691. for_each_encoder_on_crtc(dev, crtc, encoder)
  3692. encoder->disable(encoder);
  3693. if (intel_crtc->config.has_pch_encoder)
  3694. intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
  3695. intel_disable_pipe(intel_crtc);
  3696. ironlake_pfit_disable(intel_crtc);
  3697. for_each_encoder_on_crtc(dev, crtc, encoder)
  3698. if (encoder->post_disable)
  3699. encoder->post_disable(encoder);
  3700. if (intel_crtc->config.has_pch_encoder) {
  3701. ironlake_fdi_disable(crtc);
  3702. ironlake_disable_pch_transcoder(dev_priv, pipe);
  3703. intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
  3704. if (HAS_PCH_CPT(dev)) {
  3705. /* disable TRANS_DP_CTL */
  3706. reg = TRANS_DP_CTL(pipe);
  3707. temp = I915_READ(reg);
  3708. temp &= ~(TRANS_DP_OUTPUT_ENABLE |
  3709. TRANS_DP_PORT_SEL_MASK);
  3710. temp |= TRANS_DP_PORT_SEL_NONE;
  3711. I915_WRITE(reg, temp);
  3712. /* disable DPLL_SEL */
  3713. temp = I915_READ(PCH_DPLL_SEL);
  3714. temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe));
  3715. I915_WRITE(PCH_DPLL_SEL, temp);
  3716. }
  3717. /* disable PCH DPLL */
  3718. intel_disable_shared_dpll(intel_crtc);
  3719. ironlake_fdi_pll_disable(intel_crtc);
  3720. }
  3721. intel_crtc->active = false;
  3722. intel_update_watermarks(crtc);
  3723. mutex_lock(&dev->struct_mutex);
  3724. intel_update_fbc(dev);
  3725. mutex_unlock(&dev->struct_mutex);
  3726. }
  3727. static void haswell_crtc_disable(struct drm_crtc *crtc)
  3728. {
  3729. struct drm_device *dev = crtc->dev;
  3730. struct drm_i915_private *dev_priv = dev->dev_private;
  3731. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3732. struct intel_encoder *encoder;
  3733. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  3734. if (!intel_crtc->active)
  3735. return;
  3736. intel_crtc_disable_planes(crtc);
  3737. drm_crtc_vblank_off(crtc);
  3738. assert_vblank_disabled(crtc);
  3739. for_each_encoder_on_crtc(dev, crtc, encoder) {
  3740. intel_opregion_notify_encoder(encoder, false);
  3741. encoder->disable(encoder);
  3742. }
  3743. if (intel_crtc->config.has_pch_encoder)
  3744. intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A,
  3745. false);
  3746. intel_disable_pipe(intel_crtc);
  3747. if (intel_crtc->config.dp_encoder_is_mst)
  3748. intel_ddi_set_vc_payload_alloc(crtc, false);
  3749. intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder);
  3750. ironlake_pfit_disable(intel_crtc);
  3751. intel_ddi_disable_pipe_clock(intel_crtc);
  3752. if (intel_crtc->config.has_pch_encoder) {
  3753. lpt_disable_pch_transcoder(dev_priv);
  3754. intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A,
  3755. true);
  3756. intel_ddi_fdi_disable(crtc);
  3757. }
  3758. for_each_encoder_on_crtc(dev, crtc, encoder)
  3759. if (encoder->post_disable)
  3760. encoder->post_disable(encoder);
  3761. intel_crtc->active = false;
  3762. intel_update_watermarks(crtc);
  3763. mutex_lock(&dev->struct_mutex);
  3764. intel_update_fbc(dev);
  3765. mutex_unlock(&dev->struct_mutex);
  3766. if (intel_crtc_to_shared_dpll(intel_crtc))
  3767. intel_disable_shared_dpll(intel_crtc);
  3768. }
  3769. static void ironlake_crtc_off(struct drm_crtc *crtc)
  3770. {
  3771. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3772. intel_put_shared_dpll(intel_crtc);
  3773. }
  3774. static void i9xx_pfit_enable(struct intel_crtc *crtc)
  3775. {
  3776. struct drm_device *dev = crtc->base.dev;
  3777. struct drm_i915_private *dev_priv = dev->dev_private;
  3778. struct intel_crtc_config *pipe_config = &crtc->config;
  3779. if (!crtc->config.gmch_pfit.control)
  3780. return;
  3781. /*
  3782. * The panel fitter should only be adjusted whilst the pipe is disabled,
  3783. * according to register description and PRM.
  3784. */
  3785. WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE);
  3786. assert_pipe_disabled(dev_priv, crtc->pipe);
  3787. I915_WRITE(PFIT_PGM_RATIOS, pipe_config->gmch_pfit.pgm_ratios);
  3788. I915_WRITE(PFIT_CONTROL, pipe_config->gmch_pfit.control);
  3789. /* Border color in case we don't scale up to the full screen. Black by
  3790. * default, change to something else for debugging. */
  3791. I915_WRITE(BCLRPAT(crtc->pipe), 0);
  3792. }
  3793. static enum intel_display_power_domain port_to_power_domain(enum port port)
  3794. {
  3795. switch (port) {
  3796. case PORT_A:
  3797. return POWER_DOMAIN_PORT_DDI_A_4_LANES;
  3798. case PORT_B:
  3799. return POWER_DOMAIN_PORT_DDI_B_4_LANES;
  3800. case PORT_C:
  3801. return POWER_DOMAIN_PORT_DDI_C_4_LANES;
  3802. case PORT_D:
  3803. return POWER_DOMAIN_PORT_DDI_D_4_LANES;
  3804. default:
  3805. WARN_ON_ONCE(1);
  3806. return POWER_DOMAIN_PORT_OTHER;
  3807. }
  3808. }
  3809. #define for_each_power_domain(domain, mask) \
  3810. for ((domain) = 0; (domain) < POWER_DOMAIN_NUM; (domain)++) \
  3811. if ((1 << (domain)) & (mask))
  3812. enum intel_display_power_domain
  3813. intel_display_port_power_domain(struct intel_encoder *intel_encoder)
  3814. {
  3815. struct drm_device *dev = intel_encoder->base.dev;
  3816. struct intel_digital_port *intel_dig_port;
  3817. switch (intel_encoder->type) {
  3818. case INTEL_OUTPUT_UNKNOWN:
  3819. /* Only DDI platforms should ever use this output type */
  3820. WARN_ON_ONCE(!HAS_DDI(dev));
  3821. case INTEL_OUTPUT_DISPLAYPORT:
  3822. case INTEL_OUTPUT_HDMI:
  3823. case INTEL_OUTPUT_EDP:
  3824. intel_dig_port = enc_to_dig_port(&intel_encoder->base);
  3825. return port_to_power_domain(intel_dig_port->port);
  3826. case INTEL_OUTPUT_DP_MST:
  3827. intel_dig_port = enc_to_mst(&intel_encoder->base)->primary;
  3828. return port_to_power_domain(intel_dig_port->port);
  3829. case INTEL_OUTPUT_ANALOG:
  3830. return POWER_DOMAIN_PORT_CRT;
  3831. case INTEL_OUTPUT_DSI:
  3832. return POWER_DOMAIN_PORT_DSI;
  3833. default:
  3834. return POWER_DOMAIN_PORT_OTHER;
  3835. }
  3836. }
  3837. static unsigned long get_crtc_power_domains(struct drm_crtc *crtc)
  3838. {
  3839. struct drm_device *dev = crtc->dev;
  3840. struct intel_encoder *intel_encoder;
  3841. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3842. enum pipe pipe = intel_crtc->pipe;
  3843. unsigned long mask;
  3844. enum transcoder transcoder;
  3845. transcoder = intel_pipe_to_cpu_transcoder(dev->dev_private, pipe);
  3846. mask = BIT(POWER_DOMAIN_PIPE(pipe));
  3847. mask |= BIT(POWER_DOMAIN_TRANSCODER(transcoder));
  3848. if (intel_crtc->config.pch_pfit.enabled ||
  3849. intel_crtc->config.pch_pfit.force_thru)
  3850. mask |= BIT(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe));
  3851. for_each_encoder_on_crtc(dev, crtc, intel_encoder)
  3852. mask |= BIT(intel_display_port_power_domain(intel_encoder));
  3853. return mask;
  3854. }
  3855. static void modeset_update_crtc_power_domains(struct drm_device *dev)
  3856. {
  3857. struct drm_i915_private *dev_priv = dev->dev_private;
  3858. unsigned long pipe_domains[I915_MAX_PIPES] = { 0, };
  3859. struct intel_crtc *crtc;
  3860. /*
  3861. * First get all needed power domains, then put all unneeded, to avoid
  3862. * any unnecessary toggling of the power wells.
  3863. */
  3864. for_each_intel_crtc(dev, crtc) {
  3865. enum intel_display_power_domain domain;
  3866. if (!crtc->base.enabled)
  3867. continue;
  3868. pipe_domains[crtc->pipe] = get_crtc_power_domains(&crtc->base);
  3869. for_each_power_domain(domain, pipe_domains[crtc->pipe])
  3870. intel_display_power_get(dev_priv, domain);
  3871. }
  3872. for_each_intel_crtc(dev, crtc) {
  3873. enum intel_display_power_domain domain;
  3874. for_each_power_domain(domain, crtc->enabled_power_domains)
  3875. intel_display_power_put(dev_priv, domain);
  3876. crtc->enabled_power_domains = pipe_domains[crtc->pipe];
  3877. }
  3878. intel_display_set_init_power(dev_priv, false);
  3879. }
  3880. /* returns HPLL frequency in kHz */
  3881. static int valleyview_get_vco(struct drm_i915_private *dev_priv)
  3882. {
  3883. int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 };
  3884. /* Obtain SKU information */
  3885. mutex_lock(&dev_priv->dpio_lock);
  3886. hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) &
  3887. CCK_FUSE_HPLL_FREQ_MASK;
  3888. mutex_unlock(&dev_priv->dpio_lock);
  3889. return vco_freq[hpll_freq] * 1000;
  3890. }
  3891. static void vlv_update_cdclk(struct drm_device *dev)
  3892. {
  3893. struct drm_i915_private *dev_priv = dev->dev_private;
  3894. dev_priv->vlv_cdclk_freq = dev_priv->display.get_display_clock_speed(dev);
  3895. DRM_DEBUG_DRIVER("Current CD clock rate: %d kHz\n",
  3896. dev_priv->vlv_cdclk_freq);
  3897. /*
  3898. * Program the gmbus_freq based on the cdclk frequency.
  3899. * BSpec erroneously claims we should aim for 4MHz, but
  3900. * in fact 1MHz is the correct frequency.
  3901. */
  3902. I915_WRITE(GMBUSFREQ_VLV, dev_priv->vlv_cdclk_freq);
  3903. }
  3904. /* Adjust CDclk dividers to allow high res or save power if possible */
  3905. static void valleyview_set_cdclk(struct drm_device *dev, int cdclk)
  3906. {
  3907. struct drm_i915_private *dev_priv = dev->dev_private;
  3908. u32 val, cmd;
  3909. WARN_ON(dev_priv->display.get_display_clock_speed(dev) != dev_priv->vlv_cdclk_freq);
  3910. if (cdclk >= 320000) /* jump to highest voltage for 400MHz too */
  3911. cmd = 2;
  3912. else if (cdclk == 266667)
  3913. cmd = 1;
  3914. else
  3915. cmd = 0;
  3916. mutex_lock(&dev_priv->rps.hw_lock);
  3917. val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
  3918. val &= ~DSPFREQGUAR_MASK;
  3919. val |= (cmd << DSPFREQGUAR_SHIFT);
  3920. vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val);
  3921. if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) &
  3922. DSPFREQSTAT_MASK) == (cmd << DSPFREQSTAT_SHIFT),
  3923. 50)) {
  3924. DRM_ERROR("timed out waiting for CDclk change\n");
  3925. }
  3926. mutex_unlock(&dev_priv->rps.hw_lock);
  3927. if (cdclk == 400000) {
  3928. u32 divider, vco;
  3929. vco = valleyview_get_vco(dev_priv);
  3930. divider = DIV_ROUND_CLOSEST(vco << 1, cdclk) - 1;
  3931. mutex_lock(&dev_priv->dpio_lock);
  3932. /* adjust cdclk divider */
  3933. val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL);
  3934. val &= ~DISPLAY_FREQUENCY_VALUES;
  3935. val |= divider;
  3936. vlv_cck_write(dev_priv, CCK_DISPLAY_CLOCK_CONTROL, val);
  3937. if (wait_for((vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL) &
  3938. DISPLAY_FREQUENCY_STATUS) == (divider << DISPLAY_FREQUENCY_STATUS_SHIFT),
  3939. 50))
  3940. DRM_ERROR("timed out waiting for CDclk change\n");
  3941. mutex_unlock(&dev_priv->dpio_lock);
  3942. }
  3943. mutex_lock(&dev_priv->dpio_lock);
  3944. /* adjust self-refresh exit latency value */
  3945. val = vlv_bunit_read(dev_priv, BUNIT_REG_BISOC);
  3946. val &= ~0x7f;
  3947. /*
  3948. * For high bandwidth configs, we set a higher latency in the bunit
  3949. * so that the core display fetch happens in time to avoid underruns.
  3950. */
  3951. if (cdclk == 400000)
  3952. val |= 4500 / 250; /* 4.5 usec */
  3953. else
  3954. val |= 3000 / 250; /* 3.0 usec */
  3955. vlv_bunit_write(dev_priv, BUNIT_REG_BISOC, val);
  3956. mutex_unlock(&dev_priv->dpio_lock);
  3957. vlv_update_cdclk(dev);
  3958. }
  3959. static void cherryview_set_cdclk(struct drm_device *dev, int cdclk)
  3960. {
  3961. struct drm_i915_private *dev_priv = dev->dev_private;
  3962. u32 val, cmd;
  3963. WARN_ON(dev_priv->display.get_display_clock_speed(dev) != dev_priv->vlv_cdclk_freq);
  3964. switch (cdclk) {
  3965. case 400000:
  3966. cmd = 3;
  3967. break;
  3968. case 333333:
  3969. case 320000:
  3970. cmd = 2;
  3971. break;
  3972. case 266667:
  3973. cmd = 1;
  3974. break;
  3975. case 200000:
  3976. cmd = 0;
  3977. break;
  3978. default:
  3979. WARN_ON(1);
  3980. return;
  3981. }
  3982. mutex_lock(&dev_priv->rps.hw_lock);
  3983. val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
  3984. val &= ~DSPFREQGUAR_MASK_CHV;
  3985. val |= (cmd << DSPFREQGUAR_SHIFT_CHV);
  3986. vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val);
  3987. if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) &
  3988. DSPFREQSTAT_MASK_CHV) == (cmd << DSPFREQSTAT_SHIFT_CHV),
  3989. 50)) {
  3990. DRM_ERROR("timed out waiting for CDclk change\n");
  3991. }
  3992. mutex_unlock(&dev_priv->rps.hw_lock);
  3993. vlv_update_cdclk(dev);
  3994. }
  3995. static int valleyview_calc_cdclk(struct drm_i915_private *dev_priv,
  3996. int max_pixclk)
  3997. {
  3998. int vco = valleyview_get_vco(dev_priv);
  3999. int freq_320 = (vco << 1) % 320000 != 0 ? 333333 : 320000;
  4000. /* FIXME: Punit isn't quite ready yet */
  4001. if (IS_CHERRYVIEW(dev_priv->dev))
  4002. return 400000;
  4003. /*
  4004. * Really only a few cases to deal with, as only 4 CDclks are supported:
  4005. * 200MHz
  4006. * 267MHz
  4007. * 320/333MHz (depends on HPLL freq)
  4008. * 400MHz
  4009. * So we check to see whether we're above 90% of the lower bin and
  4010. * adjust if needed.
  4011. *
  4012. * We seem to get an unstable or solid color picture at 200MHz.
  4013. * Not sure what's wrong. For now use 200MHz only when all pipes
  4014. * are off.
  4015. */
  4016. if (max_pixclk > freq_320*9/10)
  4017. return 400000;
  4018. else if (max_pixclk > 266667*9/10)
  4019. return freq_320;
  4020. else if (max_pixclk > 0)
  4021. return 266667;
  4022. else
  4023. return 200000;
  4024. }
  4025. /* compute the max pixel clock for new configuration */
  4026. static int intel_mode_max_pixclk(struct drm_i915_private *dev_priv)
  4027. {
  4028. struct drm_device *dev = dev_priv->dev;
  4029. struct intel_crtc *intel_crtc;
  4030. int max_pixclk = 0;
  4031. for_each_intel_crtc(dev, intel_crtc) {
  4032. if (intel_crtc->new_enabled)
  4033. max_pixclk = max(max_pixclk,
  4034. intel_crtc->new_config->adjusted_mode.crtc_clock);
  4035. }
  4036. return max_pixclk;
  4037. }
  4038. static void valleyview_modeset_global_pipes(struct drm_device *dev,
  4039. unsigned *prepare_pipes)
  4040. {
  4041. struct drm_i915_private *dev_priv = dev->dev_private;
  4042. struct intel_crtc *intel_crtc;
  4043. int max_pixclk = intel_mode_max_pixclk(dev_priv);
  4044. if (valleyview_calc_cdclk(dev_priv, max_pixclk) ==
  4045. dev_priv->vlv_cdclk_freq)
  4046. return;
  4047. /* disable/enable all currently active pipes while we change cdclk */
  4048. for_each_intel_crtc(dev, intel_crtc)
  4049. if (intel_crtc->base.enabled)
  4050. *prepare_pipes |= (1 << intel_crtc->pipe);
  4051. }
  4052. static void valleyview_modeset_global_resources(struct drm_device *dev)
  4053. {
  4054. struct drm_i915_private *dev_priv = dev->dev_private;
  4055. int max_pixclk = intel_mode_max_pixclk(dev_priv);
  4056. int req_cdclk = valleyview_calc_cdclk(dev_priv, max_pixclk);
  4057. if (req_cdclk != dev_priv->vlv_cdclk_freq) {
  4058. if (IS_CHERRYVIEW(dev))
  4059. cherryview_set_cdclk(dev, req_cdclk);
  4060. else
  4061. valleyview_set_cdclk(dev, req_cdclk);
  4062. }
  4063. modeset_update_crtc_power_domains(dev);
  4064. }
  4065. static void valleyview_crtc_enable(struct drm_crtc *crtc)
  4066. {
  4067. struct drm_device *dev = crtc->dev;
  4068. struct drm_i915_private *dev_priv = to_i915(dev);
  4069. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4070. struct intel_encoder *encoder;
  4071. int pipe = intel_crtc->pipe;
  4072. bool is_dsi;
  4073. WARN_ON(!crtc->enabled);
  4074. if (intel_crtc->active)
  4075. return;
  4076. is_dsi = intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI);
  4077. if (!is_dsi) {
  4078. if (IS_CHERRYVIEW(dev))
  4079. chv_prepare_pll(intel_crtc);
  4080. else
  4081. vlv_prepare_pll(intel_crtc);
  4082. }
  4083. if (intel_crtc->config.has_dp_encoder)
  4084. intel_dp_set_m_n(intel_crtc);
  4085. intel_set_pipe_timings(intel_crtc);
  4086. i9xx_set_pipeconf(intel_crtc);
  4087. intel_crtc->active = true;
  4088. intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
  4089. for_each_encoder_on_crtc(dev, crtc, encoder)
  4090. if (encoder->pre_pll_enable)
  4091. encoder->pre_pll_enable(encoder);
  4092. if (!is_dsi) {
  4093. if (IS_CHERRYVIEW(dev))
  4094. chv_enable_pll(intel_crtc);
  4095. else
  4096. vlv_enable_pll(intel_crtc);
  4097. }
  4098. for_each_encoder_on_crtc(dev, crtc, encoder)
  4099. if (encoder->pre_enable)
  4100. encoder->pre_enable(encoder);
  4101. i9xx_pfit_enable(intel_crtc);
  4102. intel_crtc_load_lut(crtc);
  4103. intel_update_watermarks(crtc);
  4104. intel_enable_pipe(intel_crtc);
  4105. for_each_encoder_on_crtc(dev, crtc, encoder)
  4106. encoder->enable(encoder);
  4107. assert_vblank_disabled(crtc);
  4108. drm_crtc_vblank_on(crtc);
  4109. intel_crtc_enable_planes(crtc);
  4110. /* Underruns don't raise interrupts, so check manually. */
  4111. i9xx_check_fifo_underruns(dev_priv);
  4112. }
  4113. static void i9xx_set_pll_dividers(struct intel_crtc *crtc)
  4114. {
  4115. struct drm_device *dev = crtc->base.dev;
  4116. struct drm_i915_private *dev_priv = dev->dev_private;
  4117. I915_WRITE(FP0(crtc->pipe), crtc->config.dpll_hw_state.fp0);
  4118. I915_WRITE(FP1(crtc->pipe), crtc->config.dpll_hw_state.fp1);
  4119. }
  4120. static void i9xx_crtc_enable(struct drm_crtc *crtc)
  4121. {
  4122. struct drm_device *dev = crtc->dev;
  4123. struct drm_i915_private *dev_priv = to_i915(dev);
  4124. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4125. struct intel_encoder *encoder;
  4126. int pipe = intel_crtc->pipe;
  4127. WARN_ON(!crtc->enabled);
  4128. if (intel_crtc->active)
  4129. return;
  4130. i9xx_set_pll_dividers(intel_crtc);
  4131. if (intel_crtc->config.has_dp_encoder)
  4132. intel_dp_set_m_n(intel_crtc);
  4133. intel_set_pipe_timings(intel_crtc);
  4134. i9xx_set_pipeconf(intel_crtc);
  4135. intel_crtc->active = true;
  4136. if (!IS_GEN2(dev))
  4137. intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
  4138. for_each_encoder_on_crtc(dev, crtc, encoder)
  4139. if (encoder->pre_enable)
  4140. encoder->pre_enable(encoder);
  4141. i9xx_enable_pll(intel_crtc);
  4142. i9xx_pfit_enable(intel_crtc);
  4143. intel_crtc_load_lut(crtc);
  4144. intel_update_watermarks(crtc);
  4145. intel_enable_pipe(intel_crtc);
  4146. for_each_encoder_on_crtc(dev, crtc, encoder)
  4147. encoder->enable(encoder);
  4148. assert_vblank_disabled(crtc);
  4149. drm_crtc_vblank_on(crtc);
  4150. intel_crtc_enable_planes(crtc);
  4151. /*
  4152. * Gen2 reports pipe underruns whenever all planes are disabled.
  4153. * So don't enable underrun reporting before at least some planes
  4154. * are enabled.
  4155. * FIXME: Need to fix the logic to work when we turn off all planes
  4156. * but leave the pipe running.
  4157. */
  4158. if (IS_GEN2(dev))
  4159. intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
  4160. /* Underruns don't raise interrupts, so check manually. */
  4161. i9xx_check_fifo_underruns(dev_priv);
  4162. }
  4163. static void i9xx_pfit_disable(struct intel_crtc *crtc)
  4164. {
  4165. struct drm_device *dev = crtc->base.dev;
  4166. struct drm_i915_private *dev_priv = dev->dev_private;
  4167. if (!crtc->config.gmch_pfit.control)
  4168. return;
  4169. assert_pipe_disabled(dev_priv, crtc->pipe);
  4170. DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n",
  4171. I915_READ(PFIT_CONTROL));
  4172. I915_WRITE(PFIT_CONTROL, 0);
  4173. }
  4174. static void i9xx_crtc_disable(struct drm_crtc *crtc)
  4175. {
  4176. struct drm_device *dev = crtc->dev;
  4177. struct drm_i915_private *dev_priv = dev->dev_private;
  4178. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4179. struct intel_encoder *encoder;
  4180. int pipe = intel_crtc->pipe;
  4181. if (!intel_crtc->active)
  4182. return;
  4183. /*
  4184. * Gen2 reports pipe underruns whenever all planes are disabled.
  4185. * So diasble underrun reporting before all the planes get disabled.
  4186. * FIXME: Need to fix the logic to work when we turn off all planes
  4187. * but leave the pipe running.
  4188. */
  4189. if (IS_GEN2(dev))
  4190. intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
  4191. /*
  4192. * Vblank time updates from the shadow to live plane control register
  4193. * are blocked if the memory self-refresh mode is active at that
  4194. * moment. So to make sure the plane gets truly disabled, disable
  4195. * first the self-refresh mode. The self-refresh enable bit in turn
  4196. * will be checked/applied by the HW only at the next frame start
  4197. * event which is after the vblank start event, so we need to have a
  4198. * wait-for-vblank between disabling the plane and the pipe.
  4199. */
  4200. intel_set_memory_cxsr(dev_priv, false);
  4201. intel_crtc_disable_planes(crtc);
  4202. /*
  4203. * On gen2 planes are double buffered but the pipe isn't, so we must
  4204. * wait for planes to fully turn off before disabling the pipe.
  4205. * We also need to wait on all gmch platforms because of the
  4206. * self-refresh mode constraint explained above.
  4207. */
  4208. intel_wait_for_vblank(dev, pipe);
  4209. drm_crtc_vblank_off(crtc);
  4210. assert_vblank_disabled(crtc);
  4211. for_each_encoder_on_crtc(dev, crtc, encoder)
  4212. encoder->disable(encoder);
  4213. intel_disable_pipe(intel_crtc);
  4214. i9xx_pfit_disable(intel_crtc);
  4215. for_each_encoder_on_crtc(dev, crtc, encoder)
  4216. if (encoder->post_disable)
  4217. encoder->post_disable(encoder);
  4218. if (!intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI)) {
  4219. if (IS_CHERRYVIEW(dev))
  4220. chv_disable_pll(dev_priv, pipe);
  4221. else if (IS_VALLEYVIEW(dev))
  4222. vlv_disable_pll(dev_priv, pipe);
  4223. else
  4224. i9xx_disable_pll(intel_crtc);
  4225. }
  4226. if (!IS_GEN2(dev))
  4227. intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
  4228. intel_crtc->active = false;
  4229. intel_update_watermarks(crtc);
  4230. mutex_lock(&dev->struct_mutex);
  4231. intel_update_fbc(dev);
  4232. mutex_unlock(&dev->struct_mutex);
  4233. }
  4234. static void i9xx_crtc_off(struct drm_crtc *crtc)
  4235. {
  4236. }
  4237. static void intel_crtc_update_sarea(struct drm_crtc *crtc,
  4238. bool enabled)
  4239. {
  4240. struct drm_device *dev = crtc->dev;
  4241. struct drm_i915_master_private *master_priv;
  4242. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4243. int pipe = intel_crtc->pipe;
  4244. if (!dev->primary->master)
  4245. return;
  4246. master_priv = dev->primary->master->driver_priv;
  4247. if (!master_priv->sarea_priv)
  4248. return;
  4249. switch (pipe) {
  4250. case 0:
  4251. master_priv->sarea_priv->pipeA_w = enabled ? crtc->mode.hdisplay : 0;
  4252. master_priv->sarea_priv->pipeA_h = enabled ? crtc->mode.vdisplay : 0;
  4253. break;
  4254. case 1:
  4255. master_priv->sarea_priv->pipeB_w = enabled ? crtc->mode.hdisplay : 0;
  4256. master_priv->sarea_priv->pipeB_h = enabled ? crtc->mode.vdisplay : 0;
  4257. break;
  4258. default:
  4259. DRM_ERROR("Can't update pipe %c in SAREA\n", pipe_name(pipe));
  4260. break;
  4261. }
  4262. }
  4263. /* Master function to enable/disable CRTC and corresponding power wells */
  4264. void intel_crtc_control(struct drm_crtc *crtc, bool enable)
  4265. {
  4266. struct drm_device *dev = crtc->dev;
  4267. struct drm_i915_private *dev_priv = dev->dev_private;
  4268. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4269. enum intel_display_power_domain domain;
  4270. unsigned long domains;
  4271. if (enable) {
  4272. if (!intel_crtc->active) {
  4273. domains = get_crtc_power_domains(crtc);
  4274. for_each_power_domain(domain, domains)
  4275. intel_display_power_get(dev_priv, domain);
  4276. intel_crtc->enabled_power_domains = domains;
  4277. dev_priv->display.crtc_enable(crtc);
  4278. }
  4279. } else {
  4280. if (intel_crtc->active) {
  4281. dev_priv->display.crtc_disable(crtc);
  4282. domains = intel_crtc->enabled_power_domains;
  4283. for_each_power_domain(domain, domains)
  4284. intel_display_power_put(dev_priv, domain);
  4285. intel_crtc->enabled_power_domains = 0;
  4286. }
  4287. }
  4288. }
  4289. /**
  4290. * Sets the power management mode of the pipe and plane.
  4291. */
  4292. void intel_crtc_update_dpms(struct drm_crtc *crtc)
  4293. {
  4294. struct drm_device *dev = crtc->dev;
  4295. struct intel_encoder *intel_encoder;
  4296. bool enable = false;
  4297. for_each_encoder_on_crtc(dev, crtc, intel_encoder)
  4298. enable |= intel_encoder->connectors_active;
  4299. intel_crtc_control(crtc, enable);
  4300. intel_crtc_update_sarea(crtc, enable);
  4301. }
  4302. static void intel_crtc_disable(struct drm_crtc *crtc)
  4303. {
  4304. struct drm_device *dev = crtc->dev;
  4305. struct drm_connector *connector;
  4306. struct drm_i915_private *dev_priv = dev->dev_private;
  4307. struct drm_i915_gem_object *old_obj = intel_fb_obj(crtc->primary->fb);
  4308. enum pipe pipe = to_intel_crtc(crtc)->pipe;
  4309. /* crtc should still be enabled when we disable it. */
  4310. WARN_ON(!crtc->enabled);
  4311. dev_priv->display.crtc_disable(crtc);
  4312. intel_crtc_update_sarea(crtc, false);
  4313. dev_priv->display.off(crtc);
  4314. if (crtc->primary->fb) {
  4315. mutex_lock(&dev->struct_mutex);
  4316. intel_unpin_fb_obj(old_obj);
  4317. i915_gem_track_fb(old_obj, NULL,
  4318. INTEL_FRONTBUFFER_PRIMARY(pipe));
  4319. mutex_unlock(&dev->struct_mutex);
  4320. crtc->primary->fb = NULL;
  4321. }
  4322. /* Update computed state. */
  4323. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  4324. if (!connector->encoder || !connector->encoder->crtc)
  4325. continue;
  4326. if (connector->encoder->crtc != crtc)
  4327. continue;
  4328. connector->dpms = DRM_MODE_DPMS_OFF;
  4329. to_intel_encoder(connector->encoder)->connectors_active = false;
  4330. }
  4331. }
  4332. void intel_encoder_destroy(struct drm_encoder *encoder)
  4333. {
  4334. struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
  4335. drm_encoder_cleanup(encoder);
  4336. kfree(intel_encoder);
  4337. }
  4338. /* Simple dpms helper for encoders with just one connector, no cloning and only
  4339. * one kind of off state. It clamps all !ON modes to fully OFF and changes the
  4340. * state of the entire output pipe. */
  4341. static void intel_encoder_dpms(struct intel_encoder *encoder, int mode)
  4342. {
  4343. if (mode == DRM_MODE_DPMS_ON) {
  4344. encoder->connectors_active = true;
  4345. intel_crtc_update_dpms(encoder->base.crtc);
  4346. } else {
  4347. encoder->connectors_active = false;
  4348. intel_crtc_update_dpms(encoder->base.crtc);
  4349. }
  4350. }
  4351. /* Cross check the actual hw state with our own modeset state tracking (and it's
  4352. * internal consistency). */
  4353. static void intel_connector_check_state(struct intel_connector *connector)
  4354. {
  4355. if (connector->get_hw_state(connector)) {
  4356. struct intel_encoder *encoder = connector->encoder;
  4357. struct drm_crtc *crtc;
  4358. bool encoder_enabled;
  4359. enum pipe pipe;
  4360. DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
  4361. connector->base.base.id,
  4362. connector->base.name);
  4363. /* there is no real hw state for MST connectors */
  4364. if (connector->mst_port)
  4365. return;
  4366. WARN(connector->base.dpms == DRM_MODE_DPMS_OFF,
  4367. "wrong connector dpms state\n");
  4368. WARN(connector->base.encoder != &encoder->base,
  4369. "active connector not linked to encoder\n");
  4370. if (encoder) {
  4371. WARN(!encoder->connectors_active,
  4372. "encoder->connectors_active not set\n");
  4373. encoder_enabled = encoder->get_hw_state(encoder, &pipe);
  4374. WARN(!encoder_enabled, "encoder not enabled\n");
  4375. if (WARN_ON(!encoder->base.crtc))
  4376. return;
  4377. crtc = encoder->base.crtc;
  4378. WARN(!crtc->enabled, "crtc not enabled\n");
  4379. WARN(!to_intel_crtc(crtc)->active, "crtc not active\n");
  4380. WARN(pipe != to_intel_crtc(crtc)->pipe,
  4381. "encoder active on the wrong pipe\n");
  4382. }
  4383. }
  4384. }
  4385. /* Even simpler default implementation, if there's really no special case to
  4386. * consider. */
  4387. void intel_connector_dpms(struct drm_connector *connector, int mode)
  4388. {
  4389. /* All the simple cases only support two dpms states. */
  4390. if (mode != DRM_MODE_DPMS_ON)
  4391. mode = DRM_MODE_DPMS_OFF;
  4392. if (mode == connector->dpms)
  4393. return;
  4394. connector->dpms = mode;
  4395. /* Only need to change hw state when actually enabled */
  4396. if (connector->encoder)
  4397. intel_encoder_dpms(to_intel_encoder(connector->encoder), mode);
  4398. intel_modeset_check_state(connector->dev);
  4399. }
  4400. /* Simple connector->get_hw_state implementation for encoders that support only
  4401. * one connector and no cloning and hence the encoder state determines the state
  4402. * of the connector. */
  4403. bool intel_connector_get_hw_state(struct intel_connector *connector)
  4404. {
  4405. enum pipe pipe = 0;
  4406. struct intel_encoder *encoder = connector->encoder;
  4407. return encoder->get_hw_state(encoder, &pipe);
  4408. }
  4409. static bool ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe,
  4410. struct intel_crtc_config *pipe_config)
  4411. {
  4412. struct drm_i915_private *dev_priv = dev->dev_private;
  4413. struct intel_crtc *pipe_B_crtc =
  4414. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_B]);
  4415. DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
  4416. pipe_name(pipe), pipe_config->fdi_lanes);
  4417. if (pipe_config->fdi_lanes > 4) {
  4418. DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
  4419. pipe_name(pipe), pipe_config->fdi_lanes);
  4420. return false;
  4421. }
  4422. if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
  4423. if (pipe_config->fdi_lanes > 2) {
  4424. DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
  4425. pipe_config->fdi_lanes);
  4426. return false;
  4427. } else {
  4428. return true;
  4429. }
  4430. }
  4431. if (INTEL_INFO(dev)->num_pipes == 2)
  4432. return true;
  4433. /* Ivybridge 3 pipe is really complicated */
  4434. switch (pipe) {
  4435. case PIPE_A:
  4436. return true;
  4437. case PIPE_B:
  4438. if (dev_priv->pipe_to_crtc_mapping[PIPE_C]->enabled &&
  4439. pipe_config->fdi_lanes > 2) {
  4440. DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
  4441. pipe_name(pipe), pipe_config->fdi_lanes);
  4442. return false;
  4443. }
  4444. return true;
  4445. case PIPE_C:
  4446. if (!pipe_has_enabled_pch(pipe_B_crtc) ||
  4447. pipe_B_crtc->config.fdi_lanes <= 2) {
  4448. if (pipe_config->fdi_lanes > 2) {
  4449. DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
  4450. pipe_name(pipe), pipe_config->fdi_lanes);
  4451. return false;
  4452. }
  4453. } else {
  4454. DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
  4455. return false;
  4456. }
  4457. return true;
  4458. default:
  4459. BUG();
  4460. }
  4461. }
  4462. #define RETRY 1
  4463. static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc,
  4464. struct intel_crtc_config *pipe_config)
  4465. {
  4466. struct drm_device *dev = intel_crtc->base.dev;
  4467. struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
  4468. int lane, link_bw, fdi_dotclock;
  4469. bool setup_ok, needs_recompute = false;
  4470. retry:
  4471. /* FDI is a binary signal running at ~2.7GHz, encoding
  4472. * each output octet as 10 bits. The actual frequency
  4473. * is stored as a divider into a 100MHz clock, and the
  4474. * mode pixel clock is stored in units of 1KHz.
  4475. * Hence the bw of each lane in terms of the mode signal
  4476. * is:
  4477. */
  4478. link_bw = intel_fdi_link_freq(dev) * MHz(100)/KHz(1)/10;
  4479. fdi_dotclock = adjusted_mode->crtc_clock;
  4480. lane = ironlake_get_lanes_required(fdi_dotclock, link_bw,
  4481. pipe_config->pipe_bpp);
  4482. pipe_config->fdi_lanes = lane;
  4483. intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock,
  4484. link_bw, &pipe_config->fdi_m_n);
  4485. setup_ok = ironlake_check_fdi_lanes(intel_crtc->base.dev,
  4486. intel_crtc->pipe, pipe_config);
  4487. if (!setup_ok && pipe_config->pipe_bpp > 6*3) {
  4488. pipe_config->pipe_bpp -= 2*3;
  4489. DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
  4490. pipe_config->pipe_bpp);
  4491. needs_recompute = true;
  4492. pipe_config->bw_constrained = true;
  4493. goto retry;
  4494. }
  4495. if (needs_recompute)
  4496. return RETRY;
  4497. return setup_ok ? 0 : -EINVAL;
  4498. }
  4499. static void hsw_compute_ips_config(struct intel_crtc *crtc,
  4500. struct intel_crtc_config *pipe_config)
  4501. {
  4502. pipe_config->ips_enabled = i915.enable_ips &&
  4503. hsw_crtc_supports_ips(crtc) &&
  4504. pipe_config->pipe_bpp <= 24;
  4505. }
  4506. static int intel_crtc_compute_config(struct intel_crtc *crtc,
  4507. struct intel_crtc_config *pipe_config)
  4508. {
  4509. struct drm_device *dev = crtc->base.dev;
  4510. struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
  4511. /* FIXME should check pixel clock limits on all platforms */
  4512. if (INTEL_INFO(dev)->gen < 4) {
  4513. struct drm_i915_private *dev_priv = dev->dev_private;
  4514. int clock_limit =
  4515. dev_priv->display.get_display_clock_speed(dev);
  4516. /*
  4517. * Enable pixel doubling when the dot clock
  4518. * is > 90% of the (display) core speed.
  4519. *
  4520. * GDG double wide on either pipe,
  4521. * otherwise pipe A only.
  4522. */
  4523. if ((crtc->pipe == PIPE_A || IS_I915G(dev)) &&
  4524. adjusted_mode->crtc_clock > clock_limit * 9 / 10) {
  4525. clock_limit *= 2;
  4526. pipe_config->double_wide = true;
  4527. }
  4528. if (adjusted_mode->crtc_clock > clock_limit * 9 / 10)
  4529. return -EINVAL;
  4530. }
  4531. /*
  4532. * Pipe horizontal size must be even in:
  4533. * - DVO ganged mode
  4534. * - LVDS dual channel mode
  4535. * - Double wide pipe
  4536. */
  4537. if ((intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
  4538. intel_is_dual_link_lvds(dev)) || pipe_config->double_wide)
  4539. pipe_config->pipe_src_w &= ~1;
  4540. /* Cantiga+ cannot handle modes with a hsync front porch of 0.
  4541. * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
  4542. */
  4543. if ((INTEL_INFO(dev)->gen > 4 || IS_G4X(dev)) &&
  4544. adjusted_mode->hsync_start == adjusted_mode->hdisplay)
  4545. return -EINVAL;
  4546. if ((IS_G4X(dev) || IS_VALLEYVIEW(dev)) && pipe_config->pipe_bpp > 10*3) {
  4547. pipe_config->pipe_bpp = 10*3; /* 12bpc is gen5+ */
  4548. } else if (INTEL_INFO(dev)->gen <= 4 && pipe_config->pipe_bpp > 8*3) {
  4549. /* only a 8bpc pipe, with 6bpc dither through the panel fitter
  4550. * for lvds. */
  4551. pipe_config->pipe_bpp = 8*3;
  4552. }
  4553. if (HAS_IPS(dev))
  4554. hsw_compute_ips_config(crtc, pipe_config);
  4555. /*
  4556. * XXX: PCH/WRPLL clock sharing is done in ->mode_set, so make sure the
  4557. * old clock survives for now.
  4558. */
  4559. if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev) || HAS_DDI(dev))
  4560. pipe_config->shared_dpll = crtc->config.shared_dpll;
  4561. if (pipe_config->has_pch_encoder)
  4562. return ironlake_fdi_compute_config(crtc, pipe_config);
  4563. return 0;
  4564. }
  4565. static int valleyview_get_display_clock_speed(struct drm_device *dev)
  4566. {
  4567. struct drm_i915_private *dev_priv = dev->dev_private;
  4568. int vco = valleyview_get_vco(dev_priv);
  4569. u32 val;
  4570. int divider;
  4571. /* FIXME: Punit isn't quite ready yet */
  4572. if (IS_CHERRYVIEW(dev))
  4573. return 400000;
  4574. mutex_lock(&dev_priv->dpio_lock);
  4575. val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL);
  4576. mutex_unlock(&dev_priv->dpio_lock);
  4577. divider = val & DISPLAY_FREQUENCY_VALUES;
  4578. WARN((val & DISPLAY_FREQUENCY_STATUS) !=
  4579. (divider << DISPLAY_FREQUENCY_STATUS_SHIFT),
  4580. "cdclk change in progress\n");
  4581. return DIV_ROUND_CLOSEST(vco << 1, divider + 1);
  4582. }
  4583. static int i945_get_display_clock_speed(struct drm_device *dev)
  4584. {
  4585. return 400000;
  4586. }
  4587. static int i915_get_display_clock_speed(struct drm_device *dev)
  4588. {
  4589. return 333000;
  4590. }
  4591. static int i9xx_misc_get_display_clock_speed(struct drm_device *dev)
  4592. {
  4593. return 200000;
  4594. }
  4595. static int pnv_get_display_clock_speed(struct drm_device *dev)
  4596. {
  4597. u16 gcfgc = 0;
  4598. pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
  4599. switch (gcfgc & GC_DISPLAY_CLOCK_MASK) {
  4600. case GC_DISPLAY_CLOCK_267_MHZ_PNV:
  4601. return 267000;
  4602. case GC_DISPLAY_CLOCK_333_MHZ_PNV:
  4603. return 333000;
  4604. case GC_DISPLAY_CLOCK_444_MHZ_PNV:
  4605. return 444000;
  4606. case GC_DISPLAY_CLOCK_200_MHZ_PNV:
  4607. return 200000;
  4608. default:
  4609. DRM_ERROR("Unknown pnv display core clock 0x%04x\n", gcfgc);
  4610. case GC_DISPLAY_CLOCK_133_MHZ_PNV:
  4611. return 133000;
  4612. case GC_DISPLAY_CLOCK_167_MHZ_PNV:
  4613. return 167000;
  4614. }
  4615. }
  4616. static int i915gm_get_display_clock_speed(struct drm_device *dev)
  4617. {
  4618. u16 gcfgc = 0;
  4619. pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
  4620. if (gcfgc & GC_LOW_FREQUENCY_ENABLE)
  4621. return 133000;
  4622. else {
  4623. switch (gcfgc & GC_DISPLAY_CLOCK_MASK) {
  4624. case GC_DISPLAY_CLOCK_333_MHZ:
  4625. return 333000;
  4626. default:
  4627. case GC_DISPLAY_CLOCK_190_200_MHZ:
  4628. return 190000;
  4629. }
  4630. }
  4631. }
  4632. static int i865_get_display_clock_speed(struct drm_device *dev)
  4633. {
  4634. return 266000;
  4635. }
  4636. static int i855_get_display_clock_speed(struct drm_device *dev)
  4637. {
  4638. u16 hpllcc = 0;
  4639. /* Assume that the hardware is in the high speed state. This
  4640. * should be the default.
  4641. */
  4642. switch (hpllcc & GC_CLOCK_CONTROL_MASK) {
  4643. case GC_CLOCK_133_200:
  4644. case GC_CLOCK_100_200:
  4645. return 200000;
  4646. case GC_CLOCK_166_250:
  4647. return 250000;
  4648. case GC_CLOCK_100_133:
  4649. return 133000;
  4650. }
  4651. /* Shouldn't happen */
  4652. return 0;
  4653. }
  4654. static int i830_get_display_clock_speed(struct drm_device *dev)
  4655. {
  4656. return 133000;
  4657. }
  4658. static void
  4659. intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den)
  4660. {
  4661. while (*num > DATA_LINK_M_N_MASK ||
  4662. *den > DATA_LINK_M_N_MASK) {
  4663. *num >>= 1;
  4664. *den >>= 1;
  4665. }
  4666. }
  4667. static void compute_m_n(unsigned int m, unsigned int n,
  4668. uint32_t *ret_m, uint32_t *ret_n)
  4669. {
  4670. *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
  4671. *ret_m = div_u64((uint64_t) m * *ret_n, n);
  4672. intel_reduce_m_n_ratio(ret_m, ret_n);
  4673. }
  4674. void
  4675. intel_link_compute_m_n(int bits_per_pixel, int nlanes,
  4676. int pixel_clock, int link_clock,
  4677. struct intel_link_m_n *m_n)
  4678. {
  4679. m_n->tu = 64;
  4680. compute_m_n(bits_per_pixel * pixel_clock,
  4681. link_clock * nlanes * 8,
  4682. &m_n->gmch_m, &m_n->gmch_n);
  4683. compute_m_n(pixel_clock, link_clock,
  4684. &m_n->link_m, &m_n->link_n);
  4685. }
  4686. static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
  4687. {
  4688. if (i915.panel_use_ssc >= 0)
  4689. return i915.panel_use_ssc != 0;
  4690. return dev_priv->vbt.lvds_use_ssc
  4691. && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE);
  4692. }
  4693. static int i9xx_get_refclk(struct intel_crtc *crtc, int num_connectors)
  4694. {
  4695. struct drm_device *dev = crtc->base.dev;
  4696. struct drm_i915_private *dev_priv = dev->dev_private;
  4697. int refclk;
  4698. if (IS_VALLEYVIEW(dev)) {
  4699. refclk = 100000;
  4700. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
  4701. intel_panel_use_ssc(dev_priv) && num_connectors < 2) {
  4702. refclk = dev_priv->vbt.lvds_ssc_freq;
  4703. DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
  4704. } else if (!IS_GEN2(dev)) {
  4705. refclk = 96000;
  4706. } else {
  4707. refclk = 48000;
  4708. }
  4709. return refclk;
  4710. }
  4711. static uint32_t pnv_dpll_compute_fp(struct dpll *dpll)
  4712. {
  4713. return (1 << dpll->n) << 16 | dpll->m2;
  4714. }
  4715. static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll)
  4716. {
  4717. return dpll->n << 16 | dpll->m1 << 8 | dpll->m2;
  4718. }
  4719. static void i9xx_update_pll_dividers(struct intel_crtc *crtc,
  4720. intel_clock_t *reduced_clock)
  4721. {
  4722. struct drm_device *dev = crtc->base.dev;
  4723. u32 fp, fp2 = 0;
  4724. if (IS_PINEVIEW(dev)) {
  4725. fp = pnv_dpll_compute_fp(&crtc->config.dpll);
  4726. if (reduced_clock)
  4727. fp2 = pnv_dpll_compute_fp(reduced_clock);
  4728. } else {
  4729. fp = i9xx_dpll_compute_fp(&crtc->config.dpll);
  4730. if (reduced_clock)
  4731. fp2 = i9xx_dpll_compute_fp(reduced_clock);
  4732. }
  4733. crtc->config.dpll_hw_state.fp0 = fp;
  4734. crtc->lowfreq_avail = false;
  4735. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
  4736. reduced_clock && i915.powersave) {
  4737. crtc->config.dpll_hw_state.fp1 = fp2;
  4738. crtc->lowfreq_avail = true;
  4739. } else {
  4740. crtc->config.dpll_hw_state.fp1 = fp;
  4741. }
  4742. }
  4743. static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe
  4744. pipe)
  4745. {
  4746. u32 reg_val;
  4747. /*
  4748. * PLLB opamp always calibrates to max value of 0x3f, force enable it
  4749. * and set it to a reasonable value instead.
  4750. */
  4751. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
  4752. reg_val &= 0xffffff00;
  4753. reg_val |= 0x00000030;
  4754. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
  4755. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
  4756. reg_val &= 0x8cffffff;
  4757. reg_val = 0x8c000000;
  4758. vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
  4759. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
  4760. reg_val &= 0xffffff00;
  4761. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
  4762. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
  4763. reg_val &= 0x00ffffff;
  4764. reg_val |= 0xb0000000;
  4765. vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
  4766. }
  4767. static void intel_pch_transcoder_set_m_n(struct intel_crtc *crtc,
  4768. struct intel_link_m_n *m_n)
  4769. {
  4770. struct drm_device *dev = crtc->base.dev;
  4771. struct drm_i915_private *dev_priv = dev->dev_private;
  4772. int pipe = crtc->pipe;
  4773. I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
  4774. I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n);
  4775. I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m);
  4776. I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n);
  4777. }
  4778. static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc,
  4779. struct intel_link_m_n *m_n,
  4780. struct intel_link_m_n *m2_n2)
  4781. {
  4782. struct drm_device *dev = crtc->base.dev;
  4783. struct drm_i915_private *dev_priv = dev->dev_private;
  4784. int pipe = crtc->pipe;
  4785. enum transcoder transcoder = crtc->config.cpu_transcoder;
  4786. if (INTEL_INFO(dev)->gen >= 5) {
  4787. I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m);
  4788. I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n);
  4789. I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m);
  4790. I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n);
  4791. /* M2_N2 registers to be set only for gen < 8 (M2_N2 available
  4792. * for gen < 8) and if DRRS is supported (to make sure the
  4793. * registers are not unnecessarily accessed).
  4794. */
  4795. if (m2_n2 && INTEL_INFO(dev)->gen < 8 &&
  4796. crtc->config.has_drrs) {
  4797. I915_WRITE(PIPE_DATA_M2(transcoder),
  4798. TU_SIZE(m2_n2->tu) | m2_n2->gmch_m);
  4799. I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n);
  4800. I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m);
  4801. I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n);
  4802. }
  4803. } else {
  4804. I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
  4805. I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n);
  4806. I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m);
  4807. I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n);
  4808. }
  4809. }
  4810. void intel_dp_set_m_n(struct intel_crtc *crtc)
  4811. {
  4812. if (crtc->config.has_pch_encoder)
  4813. intel_pch_transcoder_set_m_n(crtc, &crtc->config.dp_m_n);
  4814. else
  4815. intel_cpu_transcoder_set_m_n(crtc, &crtc->config.dp_m_n,
  4816. &crtc->config.dp_m2_n2);
  4817. }
  4818. static void vlv_update_pll(struct intel_crtc *crtc)
  4819. {
  4820. u32 dpll, dpll_md;
  4821. /*
  4822. * Enable DPIO clock input. We should never disable the reference
  4823. * clock for pipe B, since VGA hotplug / manual detection depends
  4824. * on it.
  4825. */
  4826. dpll = DPLL_EXT_BUFFER_ENABLE_VLV | DPLL_REFA_CLK_ENABLE_VLV |
  4827. DPLL_VGA_MODE_DIS | DPLL_INTEGRATED_CLOCK_VLV;
  4828. /* We should never disable this, set it here for state tracking */
  4829. if (crtc->pipe == PIPE_B)
  4830. dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
  4831. dpll |= DPLL_VCO_ENABLE;
  4832. crtc->config.dpll_hw_state.dpll = dpll;
  4833. dpll_md = (crtc->config.pixel_multiplier - 1)
  4834. << DPLL_MD_UDI_MULTIPLIER_SHIFT;
  4835. crtc->config.dpll_hw_state.dpll_md = dpll_md;
  4836. }
  4837. static void vlv_prepare_pll(struct intel_crtc *crtc)
  4838. {
  4839. struct drm_device *dev = crtc->base.dev;
  4840. struct drm_i915_private *dev_priv = dev->dev_private;
  4841. int pipe = crtc->pipe;
  4842. u32 mdiv;
  4843. u32 bestn, bestm1, bestm2, bestp1, bestp2;
  4844. u32 coreclk, reg_val;
  4845. mutex_lock(&dev_priv->dpio_lock);
  4846. bestn = crtc->config.dpll.n;
  4847. bestm1 = crtc->config.dpll.m1;
  4848. bestm2 = crtc->config.dpll.m2;
  4849. bestp1 = crtc->config.dpll.p1;
  4850. bestp2 = crtc->config.dpll.p2;
  4851. /* See eDP HDMI DPIO driver vbios notes doc */
  4852. /* PLL B needs special handling */
  4853. if (pipe == PIPE_B)
  4854. vlv_pllb_recal_opamp(dev_priv, pipe);
  4855. /* Set up Tx target for periodic Rcomp update */
  4856. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f);
  4857. /* Disable target IRef on PLL */
  4858. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe));
  4859. reg_val &= 0x00ffffff;
  4860. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val);
  4861. /* Disable fast lock */
  4862. vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610);
  4863. /* Set idtafcrecal before PLL is enabled */
  4864. mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK));
  4865. mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT));
  4866. mdiv |= ((bestn << DPIO_N_SHIFT));
  4867. mdiv |= (1 << DPIO_K_SHIFT);
  4868. /*
  4869. * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
  4870. * but we don't support that).
  4871. * Note: don't use the DAC post divider as it seems unstable.
  4872. */
  4873. mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT);
  4874. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
  4875. mdiv |= DPIO_ENABLE_CALIBRATION;
  4876. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
  4877. /* Set HBR and RBR LPF coefficients */
  4878. if (crtc->config.port_clock == 162000 ||
  4879. intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG) ||
  4880. intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI))
  4881. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
  4882. 0x009f0003);
  4883. else
  4884. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
  4885. 0x00d0000f);
  4886. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP) ||
  4887. intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) {
  4888. /* Use SSC source */
  4889. if (pipe == PIPE_A)
  4890. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
  4891. 0x0df40000);
  4892. else
  4893. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
  4894. 0x0df70000);
  4895. } else { /* HDMI or VGA */
  4896. /* Use bend source */
  4897. if (pipe == PIPE_A)
  4898. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
  4899. 0x0df70000);
  4900. else
  4901. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
  4902. 0x0df40000);
  4903. }
  4904. coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe));
  4905. coreclk = (coreclk & 0x0000ff00) | 0x01c00000;
  4906. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) ||
  4907. intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))
  4908. coreclk |= 0x01000000;
  4909. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk);
  4910. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000);
  4911. mutex_unlock(&dev_priv->dpio_lock);
  4912. }
  4913. static void chv_update_pll(struct intel_crtc *crtc)
  4914. {
  4915. crtc->config.dpll_hw_state.dpll = DPLL_SSC_REF_CLOCK_CHV |
  4916. DPLL_REFA_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS |
  4917. DPLL_VCO_ENABLE;
  4918. if (crtc->pipe != PIPE_A)
  4919. crtc->config.dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
  4920. crtc->config.dpll_hw_state.dpll_md =
  4921. (crtc->config.pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
  4922. }
  4923. static void chv_prepare_pll(struct intel_crtc *crtc)
  4924. {
  4925. struct drm_device *dev = crtc->base.dev;
  4926. struct drm_i915_private *dev_priv = dev->dev_private;
  4927. int pipe = crtc->pipe;
  4928. int dpll_reg = DPLL(crtc->pipe);
  4929. enum dpio_channel port = vlv_pipe_to_channel(pipe);
  4930. u32 loopfilter, intcoeff;
  4931. u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac;
  4932. int refclk;
  4933. bestn = crtc->config.dpll.n;
  4934. bestm2_frac = crtc->config.dpll.m2 & 0x3fffff;
  4935. bestm1 = crtc->config.dpll.m1;
  4936. bestm2 = crtc->config.dpll.m2 >> 22;
  4937. bestp1 = crtc->config.dpll.p1;
  4938. bestp2 = crtc->config.dpll.p2;
  4939. /*
  4940. * Enable Refclk and SSC
  4941. */
  4942. I915_WRITE(dpll_reg,
  4943. crtc->config.dpll_hw_state.dpll & ~DPLL_VCO_ENABLE);
  4944. mutex_lock(&dev_priv->dpio_lock);
  4945. /* p1 and p2 divider */
  4946. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port),
  4947. 5 << DPIO_CHV_S1_DIV_SHIFT |
  4948. bestp1 << DPIO_CHV_P1_DIV_SHIFT |
  4949. bestp2 << DPIO_CHV_P2_DIV_SHIFT |
  4950. 1 << DPIO_CHV_K_DIV_SHIFT);
  4951. /* Feedback post-divider - m2 */
  4952. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2);
  4953. /* Feedback refclk divider - n and m1 */
  4954. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port),
  4955. DPIO_CHV_M1_DIV_BY_2 |
  4956. 1 << DPIO_CHV_N_DIV_SHIFT);
  4957. /* M2 fraction division */
  4958. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac);
  4959. /* M2 fraction division enable */
  4960. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port),
  4961. DPIO_CHV_FRAC_DIV_EN |
  4962. (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT));
  4963. /* Loop filter */
  4964. refclk = i9xx_get_refclk(crtc, 0);
  4965. loopfilter = 5 << DPIO_CHV_PROP_COEFF_SHIFT |
  4966. 2 << DPIO_CHV_GAIN_CTRL_SHIFT;
  4967. if (refclk == 100000)
  4968. intcoeff = 11;
  4969. else if (refclk == 38400)
  4970. intcoeff = 10;
  4971. else
  4972. intcoeff = 9;
  4973. loopfilter |= intcoeff << DPIO_CHV_INT_COEFF_SHIFT;
  4974. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter);
  4975. /* AFC Recal */
  4976. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port),
  4977. vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) |
  4978. DPIO_AFC_RECAL);
  4979. mutex_unlock(&dev_priv->dpio_lock);
  4980. }
  4981. static void i9xx_update_pll(struct intel_crtc *crtc,
  4982. intel_clock_t *reduced_clock,
  4983. int num_connectors)
  4984. {
  4985. struct drm_device *dev = crtc->base.dev;
  4986. struct drm_i915_private *dev_priv = dev->dev_private;
  4987. u32 dpll;
  4988. bool is_sdvo;
  4989. struct dpll *clock = &crtc->config.dpll;
  4990. i9xx_update_pll_dividers(crtc, reduced_clock);
  4991. is_sdvo = intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO) ||
  4992. intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI);
  4993. dpll = DPLL_VGA_MODE_DIS;
  4994. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  4995. dpll |= DPLLB_MODE_LVDS;
  4996. else
  4997. dpll |= DPLLB_MODE_DAC_SERIAL;
  4998. if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) {
  4999. dpll |= (crtc->config.pixel_multiplier - 1)
  5000. << SDVO_MULTIPLIER_SHIFT_HIRES;
  5001. }
  5002. if (is_sdvo)
  5003. dpll |= DPLL_SDVO_HIGH_SPEED;
  5004. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT))
  5005. dpll |= DPLL_SDVO_HIGH_SPEED;
  5006. /* compute bitmask from p1 value */
  5007. if (IS_PINEVIEW(dev))
  5008. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
  5009. else {
  5010. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  5011. if (IS_G4X(dev) && reduced_clock)
  5012. dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
  5013. }
  5014. switch (clock->p2) {
  5015. case 5:
  5016. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
  5017. break;
  5018. case 7:
  5019. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
  5020. break;
  5021. case 10:
  5022. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
  5023. break;
  5024. case 14:
  5025. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
  5026. break;
  5027. }
  5028. if (INTEL_INFO(dev)->gen >= 4)
  5029. dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
  5030. if (crtc->config.sdvo_tv_clock)
  5031. dpll |= PLL_REF_INPUT_TVCLKINBC;
  5032. else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
  5033. intel_panel_use_ssc(dev_priv) && num_connectors < 2)
  5034. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  5035. else
  5036. dpll |= PLL_REF_INPUT_DREFCLK;
  5037. dpll |= DPLL_VCO_ENABLE;
  5038. crtc->config.dpll_hw_state.dpll = dpll;
  5039. if (INTEL_INFO(dev)->gen >= 4) {
  5040. u32 dpll_md = (crtc->config.pixel_multiplier - 1)
  5041. << DPLL_MD_UDI_MULTIPLIER_SHIFT;
  5042. crtc->config.dpll_hw_state.dpll_md = dpll_md;
  5043. }
  5044. }
  5045. static void i8xx_update_pll(struct intel_crtc *crtc,
  5046. intel_clock_t *reduced_clock,
  5047. int num_connectors)
  5048. {
  5049. struct drm_device *dev = crtc->base.dev;
  5050. struct drm_i915_private *dev_priv = dev->dev_private;
  5051. u32 dpll;
  5052. struct dpll *clock = &crtc->config.dpll;
  5053. i9xx_update_pll_dividers(crtc, reduced_clock);
  5054. dpll = DPLL_VGA_MODE_DIS;
  5055. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  5056. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  5057. } else {
  5058. if (clock->p1 == 2)
  5059. dpll |= PLL_P1_DIVIDE_BY_TWO;
  5060. else
  5061. dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  5062. if (clock->p2 == 4)
  5063. dpll |= PLL_P2_DIVIDE_BY_4;
  5064. }
  5065. if (!IS_I830(dev) && intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO))
  5066. dpll |= DPLL_DVO_2X_MODE;
  5067. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
  5068. intel_panel_use_ssc(dev_priv) && num_connectors < 2)
  5069. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  5070. else
  5071. dpll |= PLL_REF_INPUT_DREFCLK;
  5072. dpll |= DPLL_VCO_ENABLE;
  5073. crtc->config.dpll_hw_state.dpll = dpll;
  5074. }
  5075. static void intel_set_pipe_timings(struct intel_crtc *intel_crtc)
  5076. {
  5077. struct drm_device *dev = intel_crtc->base.dev;
  5078. struct drm_i915_private *dev_priv = dev->dev_private;
  5079. enum pipe pipe = intel_crtc->pipe;
  5080. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  5081. struct drm_display_mode *adjusted_mode =
  5082. &intel_crtc->config.adjusted_mode;
  5083. uint32_t crtc_vtotal, crtc_vblank_end;
  5084. int vsyncshift = 0;
  5085. /* We need to be careful not to changed the adjusted mode, for otherwise
  5086. * the hw state checker will get angry at the mismatch. */
  5087. crtc_vtotal = adjusted_mode->crtc_vtotal;
  5088. crtc_vblank_end = adjusted_mode->crtc_vblank_end;
  5089. if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
  5090. /* the chip adds 2 halflines automatically */
  5091. crtc_vtotal -= 1;
  5092. crtc_vblank_end -= 1;
  5093. if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO))
  5094. vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2;
  5095. else
  5096. vsyncshift = adjusted_mode->crtc_hsync_start -
  5097. adjusted_mode->crtc_htotal / 2;
  5098. if (vsyncshift < 0)
  5099. vsyncshift += adjusted_mode->crtc_htotal;
  5100. }
  5101. if (INTEL_INFO(dev)->gen > 3)
  5102. I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift);
  5103. I915_WRITE(HTOTAL(cpu_transcoder),
  5104. (adjusted_mode->crtc_hdisplay - 1) |
  5105. ((adjusted_mode->crtc_htotal - 1) << 16));
  5106. I915_WRITE(HBLANK(cpu_transcoder),
  5107. (adjusted_mode->crtc_hblank_start - 1) |
  5108. ((adjusted_mode->crtc_hblank_end - 1) << 16));
  5109. I915_WRITE(HSYNC(cpu_transcoder),
  5110. (adjusted_mode->crtc_hsync_start - 1) |
  5111. ((adjusted_mode->crtc_hsync_end - 1) << 16));
  5112. I915_WRITE(VTOTAL(cpu_transcoder),
  5113. (adjusted_mode->crtc_vdisplay - 1) |
  5114. ((crtc_vtotal - 1) << 16));
  5115. I915_WRITE(VBLANK(cpu_transcoder),
  5116. (adjusted_mode->crtc_vblank_start - 1) |
  5117. ((crtc_vblank_end - 1) << 16));
  5118. I915_WRITE(VSYNC(cpu_transcoder),
  5119. (adjusted_mode->crtc_vsync_start - 1) |
  5120. ((adjusted_mode->crtc_vsync_end - 1) << 16));
  5121. /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
  5122. * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
  5123. * documented on the DDI_FUNC_CTL register description, EDP Input Select
  5124. * bits. */
  5125. if (IS_HASWELL(dev) && cpu_transcoder == TRANSCODER_EDP &&
  5126. (pipe == PIPE_B || pipe == PIPE_C))
  5127. I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder)));
  5128. /* pipesrc controls the size that is scaled from, which should
  5129. * always be the user's requested size.
  5130. */
  5131. I915_WRITE(PIPESRC(pipe),
  5132. ((intel_crtc->config.pipe_src_w - 1) << 16) |
  5133. (intel_crtc->config.pipe_src_h - 1));
  5134. }
  5135. static void intel_get_pipe_timings(struct intel_crtc *crtc,
  5136. struct intel_crtc_config *pipe_config)
  5137. {
  5138. struct drm_device *dev = crtc->base.dev;
  5139. struct drm_i915_private *dev_priv = dev->dev_private;
  5140. enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
  5141. uint32_t tmp;
  5142. tmp = I915_READ(HTOTAL(cpu_transcoder));
  5143. pipe_config->adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1;
  5144. pipe_config->adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1;
  5145. tmp = I915_READ(HBLANK(cpu_transcoder));
  5146. pipe_config->adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1;
  5147. pipe_config->adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1;
  5148. tmp = I915_READ(HSYNC(cpu_transcoder));
  5149. pipe_config->adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1;
  5150. pipe_config->adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1;
  5151. tmp = I915_READ(VTOTAL(cpu_transcoder));
  5152. pipe_config->adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1;
  5153. pipe_config->adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1;
  5154. tmp = I915_READ(VBLANK(cpu_transcoder));
  5155. pipe_config->adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1;
  5156. pipe_config->adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1;
  5157. tmp = I915_READ(VSYNC(cpu_transcoder));
  5158. pipe_config->adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1;
  5159. pipe_config->adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1;
  5160. if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) {
  5161. pipe_config->adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE;
  5162. pipe_config->adjusted_mode.crtc_vtotal += 1;
  5163. pipe_config->adjusted_mode.crtc_vblank_end += 1;
  5164. }
  5165. tmp = I915_READ(PIPESRC(crtc->pipe));
  5166. pipe_config->pipe_src_h = (tmp & 0xffff) + 1;
  5167. pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1;
  5168. pipe_config->requested_mode.vdisplay = pipe_config->pipe_src_h;
  5169. pipe_config->requested_mode.hdisplay = pipe_config->pipe_src_w;
  5170. }
  5171. void intel_mode_from_pipe_config(struct drm_display_mode *mode,
  5172. struct intel_crtc_config *pipe_config)
  5173. {
  5174. mode->hdisplay = pipe_config->adjusted_mode.crtc_hdisplay;
  5175. mode->htotal = pipe_config->adjusted_mode.crtc_htotal;
  5176. mode->hsync_start = pipe_config->adjusted_mode.crtc_hsync_start;
  5177. mode->hsync_end = pipe_config->adjusted_mode.crtc_hsync_end;
  5178. mode->vdisplay = pipe_config->adjusted_mode.crtc_vdisplay;
  5179. mode->vtotal = pipe_config->adjusted_mode.crtc_vtotal;
  5180. mode->vsync_start = pipe_config->adjusted_mode.crtc_vsync_start;
  5181. mode->vsync_end = pipe_config->adjusted_mode.crtc_vsync_end;
  5182. mode->flags = pipe_config->adjusted_mode.flags;
  5183. mode->clock = pipe_config->adjusted_mode.crtc_clock;
  5184. mode->flags |= pipe_config->adjusted_mode.flags;
  5185. }
  5186. static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc)
  5187. {
  5188. struct drm_device *dev = intel_crtc->base.dev;
  5189. struct drm_i915_private *dev_priv = dev->dev_private;
  5190. uint32_t pipeconf;
  5191. pipeconf = 0;
  5192. if ((intel_crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) ||
  5193. (intel_crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))
  5194. pipeconf |= I915_READ(PIPECONF(intel_crtc->pipe)) & PIPECONF_ENABLE;
  5195. if (intel_crtc->config.double_wide)
  5196. pipeconf |= PIPECONF_DOUBLE_WIDE;
  5197. /* only g4x and later have fancy bpc/dither controls */
  5198. if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) {
  5199. /* Bspec claims that we can't use dithering for 30bpp pipes. */
  5200. if (intel_crtc->config.dither && intel_crtc->config.pipe_bpp != 30)
  5201. pipeconf |= PIPECONF_DITHER_EN |
  5202. PIPECONF_DITHER_TYPE_SP;
  5203. switch (intel_crtc->config.pipe_bpp) {
  5204. case 18:
  5205. pipeconf |= PIPECONF_6BPC;
  5206. break;
  5207. case 24:
  5208. pipeconf |= PIPECONF_8BPC;
  5209. break;
  5210. case 30:
  5211. pipeconf |= PIPECONF_10BPC;
  5212. break;
  5213. default:
  5214. /* Case prevented by intel_choose_pipe_bpp_dither. */
  5215. BUG();
  5216. }
  5217. }
  5218. if (HAS_PIPE_CXSR(dev)) {
  5219. if (intel_crtc->lowfreq_avail) {
  5220. DRM_DEBUG_KMS("enabling CxSR downclocking\n");
  5221. pipeconf |= PIPECONF_CXSR_DOWNCLOCK;
  5222. } else {
  5223. DRM_DEBUG_KMS("disabling CxSR downclocking\n");
  5224. }
  5225. }
  5226. if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
  5227. if (INTEL_INFO(dev)->gen < 4 ||
  5228. intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO))
  5229. pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
  5230. else
  5231. pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT;
  5232. } else
  5233. pipeconf |= PIPECONF_PROGRESSIVE;
  5234. if (IS_VALLEYVIEW(dev) && intel_crtc->config.limited_color_range)
  5235. pipeconf |= PIPECONF_COLOR_RANGE_SELECT;
  5236. I915_WRITE(PIPECONF(intel_crtc->pipe), pipeconf);
  5237. POSTING_READ(PIPECONF(intel_crtc->pipe));
  5238. }
  5239. static int i9xx_crtc_mode_set(struct intel_crtc *crtc,
  5240. int x, int y,
  5241. struct drm_framebuffer *fb)
  5242. {
  5243. struct drm_device *dev = crtc->base.dev;
  5244. struct drm_i915_private *dev_priv = dev->dev_private;
  5245. int refclk, num_connectors = 0;
  5246. intel_clock_t clock, reduced_clock;
  5247. bool ok, has_reduced_clock = false;
  5248. bool is_lvds = false, is_dsi = false;
  5249. struct intel_encoder *encoder;
  5250. const intel_limit_t *limit;
  5251. for_each_encoder_on_crtc(dev, &crtc->base, encoder) {
  5252. switch (encoder->type) {
  5253. case INTEL_OUTPUT_LVDS:
  5254. is_lvds = true;
  5255. break;
  5256. case INTEL_OUTPUT_DSI:
  5257. is_dsi = true;
  5258. break;
  5259. }
  5260. num_connectors++;
  5261. }
  5262. if (is_dsi)
  5263. return 0;
  5264. if (!crtc->config.clock_set) {
  5265. refclk = i9xx_get_refclk(crtc, num_connectors);
  5266. /*
  5267. * Returns a set of divisors for the desired target clock with
  5268. * the given refclk, or FALSE. The returned values represent
  5269. * the clock equation: reflck * (5 * (m1 + 2) + (m2 + 2)) / (n +
  5270. * 2) / p1 / p2.
  5271. */
  5272. limit = intel_limit(crtc, refclk);
  5273. ok = dev_priv->display.find_dpll(limit, crtc,
  5274. crtc->config.port_clock,
  5275. refclk, NULL, &clock);
  5276. if (!ok) {
  5277. DRM_ERROR("Couldn't find PLL settings for mode!\n");
  5278. return -EINVAL;
  5279. }
  5280. if (is_lvds && dev_priv->lvds_downclock_avail) {
  5281. /*
  5282. * Ensure we match the reduced clock's P to the target
  5283. * clock. If the clocks don't match, we can't switch
  5284. * the display clock by using the FP0/FP1. In such case
  5285. * we will disable the LVDS downclock feature.
  5286. */
  5287. has_reduced_clock =
  5288. dev_priv->display.find_dpll(limit, crtc,
  5289. dev_priv->lvds_downclock,
  5290. refclk, &clock,
  5291. &reduced_clock);
  5292. }
  5293. /* Compat-code for transition, will disappear. */
  5294. crtc->config.dpll.n = clock.n;
  5295. crtc->config.dpll.m1 = clock.m1;
  5296. crtc->config.dpll.m2 = clock.m2;
  5297. crtc->config.dpll.p1 = clock.p1;
  5298. crtc->config.dpll.p2 = clock.p2;
  5299. }
  5300. if (IS_GEN2(dev)) {
  5301. i8xx_update_pll(crtc,
  5302. has_reduced_clock ? &reduced_clock : NULL,
  5303. num_connectors);
  5304. } else if (IS_CHERRYVIEW(dev)) {
  5305. chv_update_pll(crtc);
  5306. } else if (IS_VALLEYVIEW(dev)) {
  5307. vlv_update_pll(crtc);
  5308. } else {
  5309. i9xx_update_pll(crtc,
  5310. has_reduced_clock ? &reduced_clock : NULL,
  5311. num_connectors);
  5312. }
  5313. return 0;
  5314. }
  5315. static void i9xx_get_pfit_config(struct intel_crtc *crtc,
  5316. struct intel_crtc_config *pipe_config)
  5317. {
  5318. struct drm_device *dev = crtc->base.dev;
  5319. struct drm_i915_private *dev_priv = dev->dev_private;
  5320. uint32_t tmp;
  5321. if (INTEL_INFO(dev)->gen <= 3 && (IS_I830(dev) || !IS_MOBILE(dev)))
  5322. return;
  5323. tmp = I915_READ(PFIT_CONTROL);
  5324. if (!(tmp & PFIT_ENABLE))
  5325. return;
  5326. /* Check whether the pfit is attached to our pipe. */
  5327. if (INTEL_INFO(dev)->gen < 4) {
  5328. if (crtc->pipe != PIPE_B)
  5329. return;
  5330. } else {
  5331. if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT))
  5332. return;
  5333. }
  5334. pipe_config->gmch_pfit.control = tmp;
  5335. pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS);
  5336. if (INTEL_INFO(dev)->gen < 5)
  5337. pipe_config->gmch_pfit.lvds_border_bits =
  5338. I915_READ(LVDS) & LVDS_BORDER_ENABLE;
  5339. }
  5340. static void vlv_crtc_clock_get(struct intel_crtc *crtc,
  5341. struct intel_crtc_config *pipe_config)
  5342. {
  5343. struct drm_device *dev = crtc->base.dev;
  5344. struct drm_i915_private *dev_priv = dev->dev_private;
  5345. int pipe = pipe_config->cpu_transcoder;
  5346. intel_clock_t clock;
  5347. u32 mdiv;
  5348. int refclk = 100000;
  5349. /* In case of MIPI DPLL will not even be used */
  5350. if (!(pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE))
  5351. return;
  5352. mutex_lock(&dev_priv->dpio_lock);
  5353. mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe));
  5354. mutex_unlock(&dev_priv->dpio_lock);
  5355. clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7;
  5356. clock.m2 = mdiv & DPIO_M2DIV_MASK;
  5357. clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf;
  5358. clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7;
  5359. clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f;
  5360. vlv_clock(refclk, &clock);
  5361. /* clock.dot is the fast clock */
  5362. pipe_config->port_clock = clock.dot / 5;
  5363. }
  5364. static void i9xx_get_plane_config(struct intel_crtc *crtc,
  5365. struct intel_plane_config *plane_config)
  5366. {
  5367. struct drm_device *dev = crtc->base.dev;
  5368. struct drm_i915_private *dev_priv = dev->dev_private;
  5369. u32 val, base, offset;
  5370. int pipe = crtc->pipe, plane = crtc->plane;
  5371. int fourcc, pixel_format;
  5372. int aligned_height;
  5373. crtc->base.primary->fb = kzalloc(sizeof(struct intel_framebuffer), GFP_KERNEL);
  5374. if (!crtc->base.primary->fb) {
  5375. DRM_DEBUG_KMS("failed to alloc fb\n");
  5376. return;
  5377. }
  5378. val = I915_READ(DSPCNTR(plane));
  5379. if (INTEL_INFO(dev)->gen >= 4)
  5380. if (val & DISPPLANE_TILED)
  5381. plane_config->tiled = true;
  5382. pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
  5383. fourcc = intel_format_to_fourcc(pixel_format);
  5384. crtc->base.primary->fb->pixel_format = fourcc;
  5385. crtc->base.primary->fb->bits_per_pixel =
  5386. drm_format_plane_cpp(fourcc, 0) * 8;
  5387. if (INTEL_INFO(dev)->gen >= 4) {
  5388. if (plane_config->tiled)
  5389. offset = I915_READ(DSPTILEOFF(plane));
  5390. else
  5391. offset = I915_READ(DSPLINOFF(plane));
  5392. base = I915_READ(DSPSURF(plane)) & 0xfffff000;
  5393. } else {
  5394. base = I915_READ(DSPADDR(plane));
  5395. }
  5396. plane_config->base = base;
  5397. val = I915_READ(PIPESRC(pipe));
  5398. crtc->base.primary->fb->width = ((val >> 16) & 0xfff) + 1;
  5399. crtc->base.primary->fb->height = ((val >> 0) & 0xfff) + 1;
  5400. val = I915_READ(DSPSTRIDE(pipe));
  5401. crtc->base.primary->fb->pitches[0] = val & 0xffffffc0;
  5402. aligned_height = intel_align_height(dev, crtc->base.primary->fb->height,
  5403. plane_config->tiled);
  5404. plane_config->size = PAGE_ALIGN(crtc->base.primary->fb->pitches[0] *
  5405. aligned_height);
  5406. DRM_DEBUG_KMS("pipe/plane %d/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
  5407. pipe, plane, crtc->base.primary->fb->width,
  5408. crtc->base.primary->fb->height,
  5409. crtc->base.primary->fb->bits_per_pixel, base,
  5410. crtc->base.primary->fb->pitches[0],
  5411. plane_config->size);
  5412. }
  5413. static void chv_crtc_clock_get(struct intel_crtc *crtc,
  5414. struct intel_crtc_config *pipe_config)
  5415. {
  5416. struct drm_device *dev = crtc->base.dev;
  5417. struct drm_i915_private *dev_priv = dev->dev_private;
  5418. int pipe = pipe_config->cpu_transcoder;
  5419. enum dpio_channel port = vlv_pipe_to_channel(pipe);
  5420. intel_clock_t clock;
  5421. u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2;
  5422. int refclk = 100000;
  5423. mutex_lock(&dev_priv->dpio_lock);
  5424. cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port));
  5425. pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port));
  5426. pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port));
  5427. pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port));
  5428. mutex_unlock(&dev_priv->dpio_lock);
  5429. clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0;
  5430. clock.m2 = ((pll_dw0 & 0xff) << 22) | (pll_dw2 & 0x3fffff);
  5431. clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf;
  5432. clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7;
  5433. clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f;
  5434. chv_clock(refclk, &clock);
  5435. /* clock.dot is the fast clock */
  5436. pipe_config->port_clock = clock.dot / 5;
  5437. }
  5438. static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
  5439. struct intel_crtc_config *pipe_config)
  5440. {
  5441. struct drm_device *dev = crtc->base.dev;
  5442. struct drm_i915_private *dev_priv = dev->dev_private;
  5443. uint32_t tmp;
  5444. if (!intel_display_power_is_enabled(dev_priv,
  5445. POWER_DOMAIN_PIPE(crtc->pipe)))
  5446. return false;
  5447. pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
  5448. pipe_config->shared_dpll = DPLL_ID_PRIVATE;
  5449. tmp = I915_READ(PIPECONF(crtc->pipe));
  5450. if (!(tmp & PIPECONF_ENABLE))
  5451. return false;
  5452. if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) {
  5453. switch (tmp & PIPECONF_BPC_MASK) {
  5454. case PIPECONF_6BPC:
  5455. pipe_config->pipe_bpp = 18;
  5456. break;
  5457. case PIPECONF_8BPC:
  5458. pipe_config->pipe_bpp = 24;
  5459. break;
  5460. case PIPECONF_10BPC:
  5461. pipe_config->pipe_bpp = 30;
  5462. break;
  5463. default:
  5464. break;
  5465. }
  5466. }
  5467. if (IS_VALLEYVIEW(dev) && (tmp & PIPECONF_COLOR_RANGE_SELECT))
  5468. pipe_config->limited_color_range = true;
  5469. if (INTEL_INFO(dev)->gen < 4)
  5470. pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE;
  5471. intel_get_pipe_timings(crtc, pipe_config);
  5472. i9xx_get_pfit_config(crtc, pipe_config);
  5473. if (INTEL_INFO(dev)->gen >= 4) {
  5474. tmp = I915_READ(DPLL_MD(crtc->pipe));
  5475. pipe_config->pixel_multiplier =
  5476. ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK)
  5477. >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1;
  5478. pipe_config->dpll_hw_state.dpll_md = tmp;
  5479. } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) {
  5480. tmp = I915_READ(DPLL(crtc->pipe));
  5481. pipe_config->pixel_multiplier =
  5482. ((tmp & SDVO_MULTIPLIER_MASK)
  5483. >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1;
  5484. } else {
  5485. /* Note that on i915G/GM the pixel multiplier is in the sdvo
  5486. * port and will be fixed up in the encoder->get_config
  5487. * function. */
  5488. pipe_config->pixel_multiplier = 1;
  5489. }
  5490. pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe));
  5491. if (!IS_VALLEYVIEW(dev)) {
  5492. /*
  5493. * DPLL_DVO_2X_MODE must be enabled for both DPLLs
  5494. * on 830. Filter it out here so that we don't
  5495. * report errors due to that.
  5496. */
  5497. if (IS_I830(dev))
  5498. pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE;
  5499. pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe));
  5500. pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe));
  5501. } else {
  5502. /* Mask out read-only status bits. */
  5503. pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV |
  5504. DPLL_PORTC_READY_MASK |
  5505. DPLL_PORTB_READY_MASK);
  5506. }
  5507. if (IS_CHERRYVIEW(dev))
  5508. chv_crtc_clock_get(crtc, pipe_config);
  5509. else if (IS_VALLEYVIEW(dev))
  5510. vlv_crtc_clock_get(crtc, pipe_config);
  5511. else
  5512. i9xx_crtc_clock_get(crtc, pipe_config);
  5513. return true;
  5514. }
  5515. static void ironlake_init_pch_refclk(struct drm_device *dev)
  5516. {
  5517. struct drm_i915_private *dev_priv = dev->dev_private;
  5518. struct intel_encoder *encoder;
  5519. u32 val, final;
  5520. bool has_lvds = false;
  5521. bool has_cpu_edp = false;
  5522. bool has_panel = false;
  5523. bool has_ck505 = false;
  5524. bool can_ssc = false;
  5525. /* We need to take the global config into account */
  5526. for_each_intel_encoder(dev, encoder) {
  5527. switch (encoder->type) {
  5528. case INTEL_OUTPUT_LVDS:
  5529. has_panel = true;
  5530. has_lvds = true;
  5531. break;
  5532. case INTEL_OUTPUT_EDP:
  5533. has_panel = true;
  5534. if (enc_to_dig_port(&encoder->base)->port == PORT_A)
  5535. has_cpu_edp = true;
  5536. break;
  5537. }
  5538. }
  5539. if (HAS_PCH_IBX(dev)) {
  5540. has_ck505 = dev_priv->vbt.display_clock_mode;
  5541. can_ssc = has_ck505;
  5542. } else {
  5543. has_ck505 = false;
  5544. can_ssc = true;
  5545. }
  5546. DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d\n",
  5547. has_panel, has_lvds, has_ck505);
  5548. /* Ironlake: try to setup display ref clock before DPLL
  5549. * enabling. This is only under driver's control after
  5550. * PCH B stepping, previous chipset stepping should be
  5551. * ignoring this setting.
  5552. */
  5553. val = I915_READ(PCH_DREF_CONTROL);
  5554. /* As we must carefully and slowly disable/enable each source in turn,
  5555. * compute the final state we want first and check if we need to
  5556. * make any changes at all.
  5557. */
  5558. final = val;
  5559. final &= ~DREF_NONSPREAD_SOURCE_MASK;
  5560. if (has_ck505)
  5561. final |= DREF_NONSPREAD_CK505_ENABLE;
  5562. else
  5563. final |= DREF_NONSPREAD_SOURCE_ENABLE;
  5564. final &= ~DREF_SSC_SOURCE_MASK;
  5565. final &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
  5566. final &= ~DREF_SSC1_ENABLE;
  5567. if (has_panel) {
  5568. final |= DREF_SSC_SOURCE_ENABLE;
  5569. if (intel_panel_use_ssc(dev_priv) && can_ssc)
  5570. final |= DREF_SSC1_ENABLE;
  5571. if (has_cpu_edp) {
  5572. if (intel_panel_use_ssc(dev_priv) && can_ssc)
  5573. final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
  5574. else
  5575. final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
  5576. } else
  5577. final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  5578. } else {
  5579. final |= DREF_SSC_SOURCE_DISABLE;
  5580. final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  5581. }
  5582. if (final == val)
  5583. return;
  5584. /* Always enable nonspread source */
  5585. val &= ~DREF_NONSPREAD_SOURCE_MASK;
  5586. if (has_ck505)
  5587. val |= DREF_NONSPREAD_CK505_ENABLE;
  5588. else
  5589. val |= DREF_NONSPREAD_SOURCE_ENABLE;
  5590. if (has_panel) {
  5591. val &= ~DREF_SSC_SOURCE_MASK;
  5592. val |= DREF_SSC_SOURCE_ENABLE;
  5593. /* SSC must be turned on before enabling the CPU output */
  5594. if (intel_panel_use_ssc(dev_priv) && can_ssc) {
  5595. DRM_DEBUG_KMS("Using SSC on panel\n");
  5596. val |= DREF_SSC1_ENABLE;
  5597. } else
  5598. val &= ~DREF_SSC1_ENABLE;
  5599. /* Get SSC going before enabling the outputs */
  5600. I915_WRITE(PCH_DREF_CONTROL, val);
  5601. POSTING_READ(PCH_DREF_CONTROL);
  5602. udelay(200);
  5603. val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
  5604. /* Enable CPU source on CPU attached eDP */
  5605. if (has_cpu_edp) {
  5606. if (intel_panel_use_ssc(dev_priv) && can_ssc) {
  5607. DRM_DEBUG_KMS("Using SSC on eDP\n");
  5608. val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
  5609. } else
  5610. val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
  5611. } else
  5612. val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  5613. I915_WRITE(PCH_DREF_CONTROL, val);
  5614. POSTING_READ(PCH_DREF_CONTROL);
  5615. udelay(200);
  5616. } else {
  5617. DRM_DEBUG_KMS("Disabling SSC entirely\n");
  5618. val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
  5619. /* Turn off CPU output */
  5620. val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  5621. I915_WRITE(PCH_DREF_CONTROL, val);
  5622. POSTING_READ(PCH_DREF_CONTROL);
  5623. udelay(200);
  5624. /* Turn off the SSC source */
  5625. val &= ~DREF_SSC_SOURCE_MASK;
  5626. val |= DREF_SSC_SOURCE_DISABLE;
  5627. /* Turn off SSC1 */
  5628. val &= ~DREF_SSC1_ENABLE;
  5629. I915_WRITE(PCH_DREF_CONTROL, val);
  5630. POSTING_READ(PCH_DREF_CONTROL);
  5631. udelay(200);
  5632. }
  5633. BUG_ON(val != final);
  5634. }
  5635. static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv)
  5636. {
  5637. uint32_t tmp;
  5638. tmp = I915_READ(SOUTH_CHICKEN2);
  5639. tmp |= FDI_MPHY_IOSFSB_RESET_CTL;
  5640. I915_WRITE(SOUTH_CHICKEN2, tmp);
  5641. if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2) &
  5642. FDI_MPHY_IOSFSB_RESET_STATUS, 100))
  5643. DRM_ERROR("FDI mPHY reset assert timeout\n");
  5644. tmp = I915_READ(SOUTH_CHICKEN2);
  5645. tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL;
  5646. I915_WRITE(SOUTH_CHICKEN2, tmp);
  5647. if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2) &
  5648. FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100))
  5649. DRM_ERROR("FDI mPHY reset de-assert timeout\n");
  5650. }
  5651. /* WaMPhyProgramming:hsw */
  5652. static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv)
  5653. {
  5654. uint32_t tmp;
  5655. tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY);
  5656. tmp &= ~(0xFF << 24);
  5657. tmp |= (0x12 << 24);
  5658. intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY);
  5659. tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY);
  5660. tmp |= (1 << 11);
  5661. intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY);
  5662. tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY);
  5663. tmp |= (1 << 11);
  5664. intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY);
  5665. tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY);
  5666. tmp |= (1 << 24) | (1 << 21) | (1 << 18);
  5667. intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY);
  5668. tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY);
  5669. tmp |= (1 << 24) | (1 << 21) | (1 << 18);
  5670. intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY);
  5671. tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY);
  5672. tmp &= ~(7 << 13);
  5673. tmp |= (5 << 13);
  5674. intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY);
  5675. tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY);
  5676. tmp &= ~(7 << 13);
  5677. tmp |= (5 << 13);
  5678. intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY);
  5679. tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY);
  5680. tmp &= ~0xFF;
  5681. tmp |= 0x1C;
  5682. intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY);
  5683. tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY);
  5684. tmp &= ~0xFF;
  5685. tmp |= 0x1C;
  5686. intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY);
  5687. tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY);
  5688. tmp &= ~(0xFF << 16);
  5689. tmp |= (0x1C << 16);
  5690. intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY);
  5691. tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY);
  5692. tmp &= ~(0xFF << 16);
  5693. tmp |= (0x1C << 16);
  5694. intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY);
  5695. tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY);
  5696. tmp |= (1 << 27);
  5697. intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY);
  5698. tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY);
  5699. tmp |= (1 << 27);
  5700. intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY);
  5701. tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY);
  5702. tmp &= ~(0xF << 28);
  5703. tmp |= (4 << 28);
  5704. intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY);
  5705. tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY);
  5706. tmp &= ~(0xF << 28);
  5707. tmp |= (4 << 28);
  5708. intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY);
  5709. }
  5710. /* Implements 3 different sequences from BSpec chapter "Display iCLK
  5711. * Programming" based on the parameters passed:
  5712. * - Sequence to enable CLKOUT_DP
  5713. * - Sequence to enable CLKOUT_DP without spread
  5714. * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
  5715. */
  5716. static void lpt_enable_clkout_dp(struct drm_device *dev, bool with_spread,
  5717. bool with_fdi)
  5718. {
  5719. struct drm_i915_private *dev_priv = dev->dev_private;
  5720. uint32_t reg, tmp;
  5721. if (WARN(with_fdi && !with_spread, "FDI requires downspread\n"))
  5722. with_spread = true;
  5723. if (WARN(dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE &&
  5724. with_fdi, "LP PCH doesn't have FDI\n"))
  5725. with_fdi = false;
  5726. mutex_lock(&dev_priv->dpio_lock);
  5727. tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
  5728. tmp &= ~SBI_SSCCTL_DISABLE;
  5729. tmp |= SBI_SSCCTL_PATHALT;
  5730. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  5731. udelay(24);
  5732. if (with_spread) {
  5733. tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
  5734. tmp &= ~SBI_SSCCTL_PATHALT;
  5735. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  5736. if (with_fdi) {
  5737. lpt_reset_fdi_mphy(dev_priv);
  5738. lpt_program_fdi_mphy(dev_priv);
  5739. }
  5740. }
  5741. reg = (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) ?
  5742. SBI_GEN0 : SBI_DBUFF0;
  5743. tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
  5744. tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE;
  5745. intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
  5746. mutex_unlock(&dev_priv->dpio_lock);
  5747. }
  5748. /* Sequence to disable CLKOUT_DP */
  5749. static void lpt_disable_clkout_dp(struct drm_device *dev)
  5750. {
  5751. struct drm_i915_private *dev_priv = dev->dev_private;
  5752. uint32_t reg, tmp;
  5753. mutex_lock(&dev_priv->dpio_lock);
  5754. reg = (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) ?
  5755. SBI_GEN0 : SBI_DBUFF0;
  5756. tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
  5757. tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE;
  5758. intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
  5759. tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
  5760. if (!(tmp & SBI_SSCCTL_DISABLE)) {
  5761. if (!(tmp & SBI_SSCCTL_PATHALT)) {
  5762. tmp |= SBI_SSCCTL_PATHALT;
  5763. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  5764. udelay(32);
  5765. }
  5766. tmp |= SBI_SSCCTL_DISABLE;
  5767. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  5768. }
  5769. mutex_unlock(&dev_priv->dpio_lock);
  5770. }
  5771. static void lpt_init_pch_refclk(struct drm_device *dev)
  5772. {
  5773. struct intel_encoder *encoder;
  5774. bool has_vga = false;
  5775. for_each_intel_encoder(dev, encoder) {
  5776. switch (encoder->type) {
  5777. case INTEL_OUTPUT_ANALOG:
  5778. has_vga = true;
  5779. break;
  5780. }
  5781. }
  5782. if (has_vga)
  5783. lpt_enable_clkout_dp(dev, true, true);
  5784. else
  5785. lpt_disable_clkout_dp(dev);
  5786. }
  5787. /*
  5788. * Initialize reference clocks when the driver loads
  5789. */
  5790. void intel_init_pch_refclk(struct drm_device *dev)
  5791. {
  5792. if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
  5793. ironlake_init_pch_refclk(dev);
  5794. else if (HAS_PCH_LPT(dev))
  5795. lpt_init_pch_refclk(dev);
  5796. }
  5797. static int ironlake_get_refclk(struct drm_crtc *crtc)
  5798. {
  5799. struct drm_device *dev = crtc->dev;
  5800. struct drm_i915_private *dev_priv = dev->dev_private;
  5801. struct intel_encoder *encoder;
  5802. int num_connectors = 0;
  5803. bool is_lvds = false;
  5804. for_each_encoder_on_crtc(dev, crtc, encoder) {
  5805. switch (encoder->type) {
  5806. case INTEL_OUTPUT_LVDS:
  5807. is_lvds = true;
  5808. break;
  5809. }
  5810. num_connectors++;
  5811. }
  5812. if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) {
  5813. DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
  5814. dev_priv->vbt.lvds_ssc_freq);
  5815. return dev_priv->vbt.lvds_ssc_freq;
  5816. }
  5817. return 120000;
  5818. }
  5819. static void ironlake_set_pipeconf(struct drm_crtc *crtc)
  5820. {
  5821. struct drm_i915_private *dev_priv = crtc->dev->dev_private;
  5822. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5823. int pipe = intel_crtc->pipe;
  5824. uint32_t val;
  5825. val = 0;
  5826. switch (intel_crtc->config.pipe_bpp) {
  5827. case 18:
  5828. val |= PIPECONF_6BPC;
  5829. break;
  5830. case 24:
  5831. val |= PIPECONF_8BPC;
  5832. break;
  5833. case 30:
  5834. val |= PIPECONF_10BPC;
  5835. break;
  5836. case 36:
  5837. val |= PIPECONF_12BPC;
  5838. break;
  5839. default:
  5840. /* Case prevented by intel_choose_pipe_bpp_dither. */
  5841. BUG();
  5842. }
  5843. if (intel_crtc->config.dither)
  5844. val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
  5845. if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
  5846. val |= PIPECONF_INTERLACED_ILK;
  5847. else
  5848. val |= PIPECONF_PROGRESSIVE;
  5849. if (intel_crtc->config.limited_color_range)
  5850. val |= PIPECONF_COLOR_RANGE_SELECT;
  5851. I915_WRITE(PIPECONF(pipe), val);
  5852. POSTING_READ(PIPECONF(pipe));
  5853. }
  5854. /*
  5855. * Set up the pipe CSC unit.
  5856. *
  5857. * Currently only full range RGB to limited range RGB conversion
  5858. * is supported, but eventually this should handle various
  5859. * RGB<->YCbCr scenarios as well.
  5860. */
  5861. static void intel_set_pipe_csc(struct drm_crtc *crtc)
  5862. {
  5863. struct drm_device *dev = crtc->dev;
  5864. struct drm_i915_private *dev_priv = dev->dev_private;
  5865. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5866. int pipe = intel_crtc->pipe;
  5867. uint16_t coeff = 0x7800; /* 1.0 */
  5868. /*
  5869. * TODO: Check what kind of values actually come out of the pipe
  5870. * with these coeff/postoff values and adjust to get the best
  5871. * accuracy. Perhaps we even need to take the bpc value into
  5872. * consideration.
  5873. */
  5874. if (intel_crtc->config.limited_color_range)
  5875. coeff = ((235 - 16) * (1 << 12) / 255) & 0xff8; /* 0.xxx... */
  5876. /*
  5877. * GY/GU and RY/RU should be the other way around according
  5878. * to BSpec, but reality doesn't agree. Just set them up in
  5879. * a way that results in the correct picture.
  5880. */
  5881. I915_WRITE(PIPE_CSC_COEFF_RY_GY(pipe), coeff << 16);
  5882. I915_WRITE(PIPE_CSC_COEFF_BY(pipe), 0);
  5883. I915_WRITE(PIPE_CSC_COEFF_RU_GU(pipe), coeff);
  5884. I915_WRITE(PIPE_CSC_COEFF_BU(pipe), 0);
  5885. I915_WRITE(PIPE_CSC_COEFF_RV_GV(pipe), 0);
  5886. I915_WRITE(PIPE_CSC_COEFF_BV(pipe), coeff << 16);
  5887. I915_WRITE(PIPE_CSC_PREOFF_HI(pipe), 0);
  5888. I915_WRITE(PIPE_CSC_PREOFF_ME(pipe), 0);
  5889. I915_WRITE(PIPE_CSC_PREOFF_LO(pipe), 0);
  5890. if (INTEL_INFO(dev)->gen > 6) {
  5891. uint16_t postoff = 0;
  5892. if (intel_crtc->config.limited_color_range)
  5893. postoff = (16 * (1 << 12) / 255) & 0x1fff;
  5894. I915_WRITE(PIPE_CSC_POSTOFF_HI(pipe), postoff);
  5895. I915_WRITE(PIPE_CSC_POSTOFF_ME(pipe), postoff);
  5896. I915_WRITE(PIPE_CSC_POSTOFF_LO(pipe), postoff);
  5897. I915_WRITE(PIPE_CSC_MODE(pipe), 0);
  5898. } else {
  5899. uint32_t mode = CSC_MODE_YUV_TO_RGB;
  5900. if (intel_crtc->config.limited_color_range)
  5901. mode |= CSC_BLACK_SCREEN_OFFSET;
  5902. I915_WRITE(PIPE_CSC_MODE(pipe), mode);
  5903. }
  5904. }
  5905. static void haswell_set_pipeconf(struct drm_crtc *crtc)
  5906. {
  5907. struct drm_device *dev = crtc->dev;
  5908. struct drm_i915_private *dev_priv = dev->dev_private;
  5909. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5910. enum pipe pipe = intel_crtc->pipe;
  5911. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  5912. uint32_t val;
  5913. val = 0;
  5914. if (IS_HASWELL(dev) && intel_crtc->config.dither)
  5915. val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
  5916. if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
  5917. val |= PIPECONF_INTERLACED_ILK;
  5918. else
  5919. val |= PIPECONF_PROGRESSIVE;
  5920. I915_WRITE(PIPECONF(cpu_transcoder), val);
  5921. POSTING_READ(PIPECONF(cpu_transcoder));
  5922. I915_WRITE(GAMMA_MODE(intel_crtc->pipe), GAMMA_MODE_MODE_8BIT);
  5923. POSTING_READ(GAMMA_MODE(intel_crtc->pipe));
  5924. if (IS_BROADWELL(dev) || INTEL_INFO(dev)->gen >= 9) {
  5925. val = 0;
  5926. switch (intel_crtc->config.pipe_bpp) {
  5927. case 18:
  5928. val |= PIPEMISC_DITHER_6_BPC;
  5929. break;
  5930. case 24:
  5931. val |= PIPEMISC_DITHER_8_BPC;
  5932. break;
  5933. case 30:
  5934. val |= PIPEMISC_DITHER_10_BPC;
  5935. break;
  5936. case 36:
  5937. val |= PIPEMISC_DITHER_12_BPC;
  5938. break;
  5939. default:
  5940. /* Case prevented by pipe_config_set_bpp. */
  5941. BUG();
  5942. }
  5943. if (intel_crtc->config.dither)
  5944. val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP;
  5945. I915_WRITE(PIPEMISC(pipe), val);
  5946. }
  5947. }
  5948. static bool ironlake_compute_clocks(struct drm_crtc *crtc,
  5949. intel_clock_t *clock,
  5950. bool *has_reduced_clock,
  5951. intel_clock_t *reduced_clock)
  5952. {
  5953. struct drm_device *dev = crtc->dev;
  5954. struct drm_i915_private *dev_priv = dev->dev_private;
  5955. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5956. int refclk;
  5957. const intel_limit_t *limit;
  5958. bool ret, is_lvds = false;
  5959. is_lvds = intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_LVDS);
  5960. refclk = ironlake_get_refclk(crtc);
  5961. /*
  5962. * Returns a set of divisors for the desired target clock with the given
  5963. * refclk, or FALSE. The returned values represent the clock equation:
  5964. * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
  5965. */
  5966. limit = intel_limit(intel_crtc, refclk);
  5967. ret = dev_priv->display.find_dpll(limit, intel_crtc,
  5968. intel_crtc->config.port_clock,
  5969. refclk, NULL, clock);
  5970. if (!ret)
  5971. return false;
  5972. if (is_lvds && dev_priv->lvds_downclock_avail) {
  5973. /*
  5974. * Ensure we match the reduced clock's P to the target clock.
  5975. * If the clocks don't match, we can't switch the display clock
  5976. * by using the FP0/FP1. In such case we will disable the LVDS
  5977. * downclock feature.
  5978. */
  5979. *has_reduced_clock =
  5980. dev_priv->display.find_dpll(limit, intel_crtc,
  5981. dev_priv->lvds_downclock,
  5982. refclk, clock,
  5983. reduced_clock);
  5984. }
  5985. return true;
  5986. }
  5987. int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp)
  5988. {
  5989. /*
  5990. * Account for spread spectrum to avoid
  5991. * oversubscribing the link. Max center spread
  5992. * is 2.5%; use 5% for safety's sake.
  5993. */
  5994. u32 bps = target_clock * bpp * 21 / 20;
  5995. return DIV_ROUND_UP(bps, link_bw * 8);
  5996. }
  5997. static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor)
  5998. {
  5999. return i9xx_dpll_compute_m(dpll) < factor * dpll->n;
  6000. }
  6001. static uint32_t ironlake_compute_dpll(struct intel_crtc *intel_crtc,
  6002. u32 *fp,
  6003. intel_clock_t *reduced_clock, u32 *fp2)
  6004. {
  6005. struct drm_crtc *crtc = &intel_crtc->base;
  6006. struct drm_device *dev = crtc->dev;
  6007. struct drm_i915_private *dev_priv = dev->dev_private;
  6008. struct intel_encoder *intel_encoder;
  6009. uint32_t dpll;
  6010. int factor, num_connectors = 0;
  6011. bool is_lvds = false, is_sdvo = false;
  6012. for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
  6013. switch (intel_encoder->type) {
  6014. case INTEL_OUTPUT_LVDS:
  6015. is_lvds = true;
  6016. break;
  6017. case INTEL_OUTPUT_SDVO:
  6018. case INTEL_OUTPUT_HDMI:
  6019. is_sdvo = true;
  6020. break;
  6021. }
  6022. num_connectors++;
  6023. }
  6024. /* Enable autotuning of the PLL clock (if permissible) */
  6025. factor = 21;
  6026. if (is_lvds) {
  6027. if ((intel_panel_use_ssc(dev_priv) &&
  6028. dev_priv->vbt.lvds_ssc_freq == 100000) ||
  6029. (HAS_PCH_IBX(dev) && intel_is_dual_link_lvds(dev)))
  6030. factor = 25;
  6031. } else if (intel_crtc->config.sdvo_tv_clock)
  6032. factor = 20;
  6033. if (ironlake_needs_fb_cb_tune(&intel_crtc->config.dpll, factor))
  6034. *fp |= FP_CB_TUNE;
  6035. if (fp2 && (reduced_clock->m < factor * reduced_clock->n))
  6036. *fp2 |= FP_CB_TUNE;
  6037. dpll = 0;
  6038. if (is_lvds)
  6039. dpll |= DPLLB_MODE_LVDS;
  6040. else
  6041. dpll |= DPLLB_MODE_DAC_SERIAL;
  6042. dpll |= (intel_crtc->config.pixel_multiplier - 1)
  6043. << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
  6044. if (is_sdvo)
  6045. dpll |= DPLL_SDVO_HIGH_SPEED;
  6046. if (intel_crtc->config.has_dp_encoder)
  6047. dpll |= DPLL_SDVO_HIGH_SPEED;
  6048. /* compute bitmask from p1 value */
  6049. dpll |= (1 << (intel_crtc->config.dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  6050. /* also FPA1 */
  6051. dpll |= (1 << (intel_crtc->config.dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
  6052. switch (intel_crtc->config.dpll.p2) {
  6053. case 5:
  6054. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
  6055. break;
  6056. case 7:
  6057. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
  6058. break;
  6059. case 10:
  6060. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
  6061. break;
  6062. case 14:
  6063. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
  6064. break;
  6065. }
  6066. if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2)
  6067. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  6068. else
  6069. dpll |= PLL_REF_INPUT_DREFCLK;
  6070. return dpll | DPLL_VCO_ENABLE;
  6071. }
  6072. static int ironlake_crtc_mode_set(struct intel_crtc *crtc,
  6073. int x, int y,
  6074. struct drm_framebuffer *fb)
  6075. {
  6076. struct drm_device *dev = crtc->base.dev;
  6077. intel_clock_t clock, reduced_clock;
  6078. u32 dpll = 0, fp = 0, fp2 = 0;
  6079. bool ok, has_reduced_clock = false;
  6080. bool is_lvds = false;
  6081. struct intel_shared_dpll *pll;
  6082. is_lvds = intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS);
  6083. WARN(!(HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)),
  6084. "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev));
  6085. ok = ironlake_compute_clocks(&crtc->base, &clock,
  6086. &has_reduced_clock, &reduced_clock);
  6087. if (!ok && !crtc->config.clock_set) {
  6088. DRM_ERROR("Couldn't find PLL settings for mode!\n");
  6089. return -EINVAL;
  6090. }
  6091. /* Compat-code for transition, will disappear. */
  6092. if (!crtc->config.clock_set) {
  6093. crtc->config.dpll.n = clock.n;
  6094. crtc->config.dpll.m1 = clock.m1;
  6095. crtc->config.dpll.m2 = clock.m2;
  6096. crtc->config.dpll.p1 = clock.p1;
  6097. crtc->config.dpll.p2 = clock.p2;
  6098. }
  6099. /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
  6100. if (crtc->config.has_pch_encoder) {
  6101. fp = i9xx_dpll_compute_fp(&crtc->config.dpll);
  6102. if (has_reduced_clock)
  6103. fp2 = i9xx_dpll_compute_fp(&reduced_clock);
  6104. dpll = ironlake_compute_dpll(crtc,
  6105. &fp, &reduced_clock,
  6106. has_reduced_clock ? &fp2 : NULL);
  6107. crtc->config.dpll_hw_state.dpll = dpll;
  6108. crtc->config.dpll_hw_state.fp0 = fp;
  6109. if (has_reduced_clock)
  6110. crtc->config.dpll_hw_state.fp1 = fp2;
  6111. else
  6112. crtc->config.dpll_hw_state.fp1 = fp;
  6113. pll = intel_get_shared_dpll(crtc);
  6114. if (pll == NULL) {
  6115. DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
  6116. pipe_name(crtc->pipe));
  6117. return -EINVAL;
  6118. }
  6119. } else
  6120. intel_put_shared_dpll(crtc);
  6121. if (is_lvds && has_reduced_clock && i915.powersave)
  6122. crtc->lowfreq_avail = true;
  6123. else
  6124. crtc->lowfreq_avail = false;
  6125. return 0;
  6126. }
  6127. static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc,
  6128. struct intel_link_m_n *m_n)
  6129. {
  6130. struct drm_device *dev = crtc->base.dev;
  6131. struct drm_i915_private *dev_priv = dev->dev_private;
  6132. enum pipe pipe = crtc->pipe;
  6133. m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe));
  6134. m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe));
  6135. m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe))
  6136. & ~TU_SIZE_MASK;
  6137. m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe));
  6138. m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe))
  6139. & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
  6140. }
  6141. static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc,
  6142. enum transcoder transcoder,
  6143. struct intel_link_m_n *m_n,
  6144. struct intel_link_m_n *m2_n2)
  6145. {
  6146. struct drm_device *dev = crtc->base.dev;
  6147. struct drm_i915_private *dev_priv = dev->dev_private;
  6148. enum pipe pipe = crtc->pipe;
  6149. if (INTEL_INFO(dev)->gen >= 5) {
  6150. m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder));
  6151. m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder));
  6152. m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder))
  6153. & ~TU_SIZE_MASK;
  6154. m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder));
  6155. m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder))
  6156. & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
  6157. /* Read M2_N2 registers only for gen < 8 (M2_N2 available for
  6158. * gen < 8) and if DRRS is supported (to make sure the
  6159. * registers are not unnecessarily read).
  6160. */
  6161. if (m2_n2 && INTEL_INFO(dev)->gen < 8 &&
  6162. crtc->config.has_drrs) {
  6163. m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder));
  6164. m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder));
  6165. m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder))
  6166. & ~TU_SIZE_MASK;
  6167. m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder));
  6168. m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder))
  6169. & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
  6170. }
  6171. } else {
  6172. m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe));
  6173. m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe));
  6174. m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe))
  6175. & ~TU_SIZE_MASK;
  6176. m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe));
  6177. m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe))
  6178. & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
  6179. }
  6180. }
  6181. void intel_dp_get_m_n(struct intel_crtc *crtc,
  6182. struct intel_crtc_config *pipe_config)
  6183. {
  6184. if (crtc->config.has_pch_encoder)
  6185. intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n);
  6186. else
  6187. intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
  6188. &pipe_config->dp_m_n,
  6189. &pipe_config->dp_m2_n2);
  6190. }
  6191. static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc,
  6192. struct intel_crtc_config *pipe_config)
  6193. {
  6194. intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
  6195. &pipe_config->fdi_m_n, NULL);
  6196. }
  6197. static void ironlake_get_pfit_config(struct intel_crtc *crtc,
  6198. struct intel_crtc_config *pipe_config)
  6199. {
  6200. struct drm_device *dev = crtc->base.dev;
  6201. struct drm_i915_private *dev_priv = dev->dev_private;
  6202. uint32_t tmp;
  6203. tmp = I915_READ(PF_CTL(crtc->pipe));
  6204. if (tmp & PF_ENABLE) {
  6205. pipe_config->pch_pfit.enabled = true;
  6206. pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe));
  6207. pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe));
  6208. /* We currently do not free assignements of panel fitters on
  6209. * ivb/hsw (since we don't use the higher upscaling modes which
  6210. * differentiates them) so just WARN about this case for now. */
  6211. if (IS_GEN7(dev)) {
  6212. WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) !=
  6213. PF_PIPE_SEL_IVB(crtc->pipe));
  6214. }
  6215. }
  6216. }
  6217. static void ironlake_get_plane_config(struct intel_crtc *crtc,
  6218. struct intel_plane_config *plane_config)
  6219. {
  6220. struct drm_device *dev = crtc->base.dev;
  6221. struct drm_i915_private *dev_priv = dev->dev_private;
  6222. u32 val, base, offset;
  6223. int pipe = crtc->pipe, plane = crtc->plane;
  6224. int fourcc, pixel_format;
  6225. int aligned_height;
  6226. crtc->base.primary->fb = kzalloc(sizeof(struct intel_framebuffer), GFP_KERNEL);
  6227. if (!crtc->base.primary->fb) {
  6228. DRM_DEBUG_KMS("failed to alloc fb\n");
  6229. return;
  6230. }
  6231. val = I915_READ(DSPCNTR(plane));
  6232. if (INTEL_INFO(dev)->gen >= 4)
  6233. if (val & DISPPLANE_TILED)
  6234. plane_config->tiled = true;
  6235. pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
  6236. fourcc = intel_format_to_fourcc(pixel_format);
  6237. crtc->base.primary->fb->pixel_format = fourcc;
  6238. crtc->base.primary->fb->bits_per_pixel =
  6239. drm_format_plane_cpp(fourcc, 0) * 8;
  6240. base = I915_READ(DSPSURF(plane)) & 0xfffff000;
  6241. if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
  6242. offset = I915_READ(DSPOFFSET(plane));
  6243. } else {
  6244. if (plane_config->tiled)
  6245. offset = I915_READ(DSPTILEOFF(plane));
  6246. else
  6247. offset = I915_READ(DSPLINOFF(plane));
  6248. }
  6249. plane_config->base = base;
  6250. val = I915_READ(PIPESRC(pipe));
  6251. crtc->base.primary->fb->width = ((val >> 16) & 0xfff) + 1;
  6252. crtc->base.primary->fb->height = ((val >> 0) & 0xfff) + 1;
  6253. val = I915_READ(DSPSTRIDE(pipe));
  6254. crtc->base.primary->fb->pitches[0] = val & 0xffffffc0;
  6255. aligned_height = intel_align_height(dev, crtc->base.primary->fb->height,
  6256. plane_config->tiled);
  6257. plane_config->size = PAGE_ALIGN(crtc->base.primary->fb->pitches[0] *
  6258. aligned_height);
  6259. DRM_DEBUG_KMS("pipe/plane %d/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
  6260. pipe, plane, crtc->base.primary->fb->width,
  6261. crtc->base.primary->fb->height,
  6262. crtc->base.primary->fb->bits_per_pixel, base,
  6263. crtc->base.primary->fb->pitches[0],
  6264. plane_config->size);
  6265. }
  6266. static bool ironlake_get_pipe_config(struct intel_crtc *crtc,
  6267. struct intel_crtc_config *pipe_config)
  6268. {
  6269. struct drm_device *dev = crtc->base.dev;
  6270. struct drm_i915_private *dev_priv = dev->dev_private;
  6271. uint32_t tmp;
  6272. if (!intel_display_power_is_enabled(dev_priv,
  6273. POWER_DOMAIN_PIPE(crtc->pipe)))
  6274. return false;
  6275. pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
  6276. pipe_config->shared_dpll = DPLL_ID_PRIVATE;
  6277. tmp = I915_READ(PIPECONF(crtc->pipe));
  6278. if (!(tmp & PIPECONF_ENABLE))
  6279. return false;
  6280. switch (tmp & PIPECONF_BPC_MASK) {
  6281. case PIPECONF_6BPC:
  6282. pipe_config->pipe_bpp = 18;
  6283. break;
  6284. case PIPECONF_8BPC:
  6285. pipe_config->pipe_bpp = 24;
  6286. break;
  6287. case PIPECONF_10BPC:
  6288. pipe_config->pipe_bpp = 30;
  6289. break;
  6290. case PIPECONF_12BPC:
  6291. pipe_config->pipe_bpp = 36;
  6292. break;
  6293. default:
  6294. break;
  6295. }
  6296. if (tmp & PIPECONF_COLOR_RANGE_SELECT)
  6297. pipe_config->limited_color_range = true;
  6298. if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) {
  6299. struct intel_shared_dpll *pll;
  6300. pipe_config->has_pch_encoder = true;
  6301. tmp = I915_READ(FDI_RX_CTL(crtc->pipe));
  6302. pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
  6303. FDI_DP_PORT_WIDTH_SHIFT) + 1;
  6304. ironlake_get_fdi_m_n_config(crtc, pipe_config);
  6305. if (HAS_PCH_IBX(dev_priv->dev)) {
  6306. pipe_config->shared_dpll =
  6307. (enum intel_dpll_id) crtc->pipe;
  6308. } else {
  6309. tmp = I915_READ(PCH_DPLL_SEL);
  6310. if (tmp & TRANS_DPLLB_SEL(crtc->pipe))
  6311. pipe_config->shared_dpll = DPLL_ID_PCH_PLL_B;
  6312. else
  6313. pipe_config->shared_dpll = DPLL_ID_PCH_PLL_A;
  6314. }
  6315. pll = &dev_priv->shared_dplls[pipe_config->shared_dpll];
  6316. WARN_ON(!pll->get_hw_state(dev_priv, pll,
  6317. &pipe_config->dpll_hw_state));
  6318. tmp = pipe_config->dpll_hw_state.dpll;
  6319. pipe_config->pixel_multiplier =
  6320. ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK)
  6321. >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1;
  6322. ironlake_pch_clock_get(crtc, pipe_config);
  6323. } else {
  6324. pipe_config->pixel_multiplier = 1;
  6325. }
  6326. intel_get_pipe_timings(crtc, pipe_config);
  6327. ironlake_get_pfit_config(crtc, pipe_config);
  6328. return true;
  6329. }
  6330. static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv)
  6331. {
  6332. struct drm_device *dev = dev_priv->dev;
  6333. struct intel_crtc *crtc;
  6334. for_each_intel_crtc(dev, crtc)
  6335. WARN(crtc->active, "CRTC for pipe %c enabled\n",
  6336. pipe_name(crtc->pipe));
  6337. WARN(I915_READ(HSW_PWR_WELL_DRIVER), "Power well on\n");
  6338. WARN(I915_READ(SPLL_CTL) & SPLL_PLL_ENABLE, "SPLL enabled\n");
  6339. WARN(I915_READ(WRPLL_CTL1) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n");
  6340. WARN(I915_READ(WRPLL_CTL2) & WRPLL_PLL_ENABLE, "WRPLL2 enabled\n");
  6341. WARN(I915_READ(PCH_PP_STATUS) & PP_ON, "Panel power on\n");
  6342. WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE,
  6343. "CPU PWM1 enabled\n");
  6344. if (IS_HASWELL(dev))
  6345. WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE,
  6346. "CPU PWM2 enabled\n");
  6347. WARN(I915_READ(BLC_PWM_PCH_CTL1) & BLM_PCH_PWM_ENABLE,
  6348. "PCH PWM1 enabled\n");
  6349. WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
  6350. "Utility pin enabled\n");
  6351. WARN(I915_READ(PCH_GTC_CTL) & PCH_GTC_ENABLE, "PCH GTC enabled\n");
  6352. /*
  6353. * In theory we can still leave IRQs enabled, as long as only the HPD
  6354. * interrupts remain enabled. We used to check for that, but since it's
  6355. * gen-specific and since we only disable LCPLL after we fully disable
  6356. * the interrupts, the check below should be enough.
  6357. */
  6358. WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n");
  6359. }
  6360. static uint32_t hsw_read_dcomp(struct drm_i915_private *dev_priv)
  6361. {
  6362. struct drm_device *dev = dev_priv->dev;
  6363. if (IS_HASWELL(dev))
  6364. return I915_READ(D_COMP_HSW);
  6365. else
  6366. return I915_READ(D_COMP_BDW);
  6367. }
  6368. static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val)
  6369. {
  6370. struct drm_device *dev = dev_priv->dev;
  6371. if (IS_HASWELL(dev)) {
  6372. mutex_lock(&dev_priv->rps.hw_lock);
  6373. if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP,
  6374. val))
  6375. DRM_ERROR("Failed to write to D_COMP\n");
  6376. mutex_unlock(&dev_priv->rps.hw_lock);
  6377. } else {
  6378. I915_WRITE(D_COMP_BDW, val);
  6379. POSTING_READ(D_COMP_BDW);
  6380. }
  6381. }
  6382. /*
  6383. * This function implements pieces of two sequences from BSpec:
  6384. * - Sequence for display software to disable LCPLL
  6385. * - Sequence for display software to allow package C8+
  6386. * The steps implemented here are just the steps that actually touch the LCPLL
  6387. * register. Callers should take care of disabling all the display engine
  6388. * functions, doing the mode unset, fixing interrupts, etc.
  6389. */
  6390. static void hsw_disable_lcpll(struct drm_i915_private *dev_priv,
  6391. bool switch_to_fclk, bool allow_power_down)
  6392. {
  6393. uint32_t val;
  6394. assert_can_disable_lcpll(dev_priv);
  6395. val = I915_READ(LCPLL_CTL);
  6396. if (switch_to_fclk) {
  6397. val |= LCPLL_CD_SOURCE_FCLK;
  6398. I915_WRITE(LCPLL_CTL, val);
  6399. if (wait_for_atomic_us(I915_READ(LCPLL_CTL) &
  6400. LCPLL_CD_SOURCE_FCLK_DONE, 1))
  6401. DRM_ERROR("Switching to FCLK failed\n");
  6402. val = I915_READ(LCPLL_CTL);
  6403. }
  6404. val |= LCPLL_PLL_DISABLE;
  6405. I915_WRITE(LCPLL_CTL, val);
  6406. POSTING_READ(LCPLL_CTL);
  6407. if (wait_for((I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK) == 0, 1))
  6408. DRM_ERROR("LCPLL still locked\n");
  6409. val = hsw_read_dcomp(dev_priv);
  6410. val |= D_COMP_COMP_DISABLE;
  6411. hsw_write_dcomp(dev_priv, val);
  6412. ndelay(100);
  6413. if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0,
  6414. 1))
  6415. DRM_ERROR("D_COMP RCOMP still in progress\n");
  6416. if (allow_power_down) {
  6417. val = I915_READ(LCPLL_CTL);
  6418. val |= LCPLL_POWER_DOWN_ALLOW;
  6419. I915_WRITE(LCPLL_CTL, val);
  6420. POSTING_READ(LCPLL_CTL);
  6421. }
  6422. }
  6423. /*
  6424. * Fully restores LCPLL, disallowing power down and switching back to LCPLL
  6425. * source.
  6426. */
  6427. static void hsw_restore_lcpll(struct drm_i915_private *dev_priv)
  6428. {
  6429. uint32_t val;
  6430. val = I915_READ(LCPLL_CTL);
  6431. if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK |
  6432. LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK)
  6433. return;
  6434. /*
  6435. * Make sure we're not on PC8 state before disabling PC8, otherwise
  6436. * we'll hang the machine. To prevent PC8 state, just enable force_wake.
  6437. *
  6438. * The other problem is that hsw_restore_lcpll() is called as part of
  6439. * the runtime PM resume sequence, so we can't just call
  6440. * gen6_gt_force_wake_get() because that function calls
  6441. * intel_runtime_pm_get(), and we can't change the runtime PM refcount
  6442. * while we are on the resume sequence. So to solve this problem we have
  6443. * to call special forcewake code that doesn't touch runtime PM and
  6444. * doesn't enable the forcewake delayed work.
  6445. */
  6446. spin_lock_irq(&dev_priv->uncore.lock);
  6447. if (dev_priv->uncore.forcewake_count++ == 0)
  6448. dev_priv->uncore.funcs.force_wake_get(dev_priv, FORCEWAKE_ALL);
  6449. spin_unlock_irq(&dev_priv->uncore.lock);
  6450. if (val & LCPLL_POWER_DOWN_ALLOW) {
  6451. val &= ~LCPLL_POWER_DOWN_ALLOW;
  6452. I915_WRITE(LCPLL_CTL, val);
  6453. POSTING_READ(LCPLL_CTL);
  6454. }
  6455. val = hsw_read_dcomp(dev_priv);
  6456. val |= D_COMP_COMP_FORCE;
  6457. val &= ~D_COMP_COMP_DISABLE;
  6458. hsw_write_dcomp(dev_priv, val);
  6459. val = I915_READ(LCPLL_CTL);
  6460. val &= ~LCPLL_PLL_DISABLE;
  6461. I915_WRITE(LCPLL_CTL, val);
  6462. if (wait_for(I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK, 5))
  6463. DRM_ERROR("LCPLL not locked yet\n");
  6464. if (val & LCPLL_CD_SOURCE_FCLK) {
  6465. val = I915_READ(LCPLL_CTL);
  6466. val &= ~LCPLL_CD_SOURCE_FCLK;
  6467. I915_WRITE(LCPLL_CTL, val);
  6468. if (wait_for_atomic_us((I915_READ(LCPLL_CTL) &
  6469. LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1))
  6470. DRM_ERROR("Switching back to LCPLL failed\n");
  6471. }
  6472. /* See the big comment above. */
  6473. spin_lock_irq(&dev_priv->uncore.lock);
  6474. if (--dev_priv->uncore.forcewake_count == 0)
  6475. dev_priv->uncore.funcs.force_wake_put(dev_priv, FORCEWAKE_ALL);
  6476. spin_unlock_irq(&dev_priv->uncore.lock);
  6477. }
  6478. /*
  6479. * Package states C8 and deeper are really deep PC states that can only be
  6480. * reached when all the devices on the system allow it, so even if the graphics
  6481. * device allows PC8+, it doesn't mean the system will actually get to these
  6482. * states. Our driver only allows PC8+ when going into runtime PM.
  6483. *
  6484. * The requirements for PC8+ are that all the outputs are disabled, the power
  6485. * well is disabled and most interrupts are disabled, and these are also
  6486. * requirements for runtime PM. When these conditions are met, we manually do
  6487. * the other conditions: disable the interrupts, clocks and switch LCPLL refclk
  6488. * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard
  6489. * hang the machine.
  6490. *
  6491. * When we really reach PC8 or deeper states (not just when we allow it) we lose
  6492. * the state of some registers, so when we come back from PC8+ we need to
  6493. * restore this state. We don't get into PC8+ if we're not in RC6, so we don't
  6494. * need to take care of the registers kept by RC6. Notice that this happens even
  6495. * if we don't put the device in PCI D3 state (which is what currently happens
  6496. * because of the runtime PM support).
  6497. *
  6498. * For more, read "Display Sequences for Package C8" on the hardware
  6499. * documentation.
  6500. */
  6501. void hsw_enable_pc8(struct drm_i915_private *dev_priv)
  6502. {
  6503. struct drm_device *dev = dev_priv->dev;
  6504. uint32_t val;
  6505. DRM_DEBUG_KMS("Enabling package C8+\n");
  6506. if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) {
  6507. val = I915_READ(SOUTH_DSPCLK_GATE_D);
  6508. val &= ~PCH_LP_PARTITION_LEVEL_DISABLE;
  6509. I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
  6510. }
  6511. lpt_disable_clkout_dp(dev);
  6512. hsw_disable_lcpll(dev_priv, true, true);
  6513. }
  6514. void hsw_disable_pc8(struct drm_i915_private *dev_priv)
  6515. {
  6516. struct drm_device *dev = dev_priv->dev;
  6517. uint32_t val;
  6518. DRM_DEBUG_KMS("Disabling package C8+\n");
  6519. hsw_restore_lcpll(dev_priv);
  6520. lpt_init_pch_refclk(dev);
  6521. if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) {
  6522. val = I915_READ(SOUTH_DSPCLK_GATE_D);
  6523. val |= PCH_LP_PARTITION_LEVEL_DISABLE;
  6524. I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
  6525. }
  6526. intel_prepare_ddi(dev);
  6527. }
  6528. static void snb_modeset_global_resources(struct drm_device *dev)
  6529. {
  6530. modeset_update_crtc_power_domains(dev);
  6531. }
  6532. static void haswell_modeset_global_resources(struct drm_device *dev)
  6533. {
  6534. modeset_update_crtc_power_domains(dev);
  6535. }
  6536. static int haswell_crtc_mode_set(struct intel_crtc *crtc,
  6537. int x, int y,
  6538. struct drm_framebuffer *fb)
  6539. {
  6540. if (!intel_ddi_pll_select(crtc))
  6541. return -EINVAL;
  6542. crtc->lowfreq_avail = false;
  6543. return 0;
  6544. }
  6545. static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv,
  6546. enum port port,
  6547. struct intel_crtc_config *pipe_config)
  6548. {
  6549. pipe_config->ddi_pll_sel = I915_READ(PORT_CLK_SEL(port));
  6550. switch (pipe_config->ddi_pll_sel) {
  6551. case PORT_CLK_SEL_WRPLL1:
  6552. pipe_config->shared_dpll = DPLL_ID_WRPLL1;
  6553. break;
  6554. case PORT_CLK_SEL_WRPLL2:
  6555. pipe_config->shared_dpll = DPLL_ID_WRPLL2;
  6556. break;
  6557. }
  6558. }
  6559. static void haswell_get_ddi_port_state(struct intel_crtc *crtc,
  6560. struct intel_crtc_config *pipe_config)
  6561. {
  6562. struct drm_device *dev = crtc->base.dev;
  6563. struct drm_i915_private *dev_priv = dev->dev_private;
  6564. struct intel_shared_dpll *pll;
  6565. enum port port;
  6566. uint32_t tmp;
  6567. tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder));
  6568. port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT;
  6569. haswell_get_ddi_pll(dev_priv, port, pipe_config);
  6570. if (pipe_config->shared_dpll >= 0) {
  6571. pll = &dev_priv->shared_dplls[pipe_config->shared_dpll];
  6572. WARN_ON(!pll->get_hw_state(dev_priv, pll,
  6573. &pipe_config->dpll_hw_state));
  6574. }
  6575. /*
  6576. * Haswell has only FDI/PCH transcoder A. It is which is connected to
  6577. * DDI E. So just check whether this pipe is wired to DDI E and whether
  6578. * the PCH transcoder is on.
  6579. */
  6580. if (INTEL_INFO(dev)->gen < 9 &&
  6581. (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) {
  6582. pipe_config->has_pch_encoder = true;
  6583. tmp = I915_READ(FDI_RX_CTL(PIPE_A));
  6584. pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
  6585. FDI_DP_PORT_WIDTH_SHIFT) + 1;
  6586. ironlake_get_fdi_m_n_config(crtc, pipe_config);
  6587. }
  6588. }
  6589. static bool haswell_get_pipe_config(struct intel_crtc *crtc,
  6590. struct intel_crtc_config *pipe_config)
  6591. {
  6592. struct drm_device *dev = crtc->base.dev;
  6593. struct drm_i915_private *dev_priv = dev->dev_private;
  6594. enum intel_display_power_domain pfit_domain;
  6595. uint32_t tmp;
  6596. if (!intel_display_power_is_enabled(dev_priv,
  6597. POWER_DOMAIN_PIPE(crtc->pipe)))
  6598. return false;
  6599. pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
  6600. pipe_config->shared_dpll = DPLL_ID_PRIVATE;
  6601. tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
  6602. if (tmp & TRANS_DDI_FUNC_ENABLE) {
  6603. enum pipe trans_edp_pipe;
  6604. switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
  6605. default:
  6606. WARN(1, "unknown pipe linked to edp transcoder\n");
  6607. case TRANS_DDI_EDP_INPUT_A_ONOFF:
  6608. case TRANS_DDI_EDP_INPUT_A_ON:
  6609. trans_edp_pipe = PIPE_A;
  6610. break;
  6611. case TRANS_DDI_EDP_INPUT_B_ONOFF:
  6612. trans_edp_pipe = PIPE_B;
  6613. break;
  6614. case TRANS_DDI_EDP_INPUT_C_ONOFF:
  6615. trans_edp_pipe = PIPE_C;
  6616. break;
  6617. }
  6618. if (trans_edp_pipe == crtc->pipe)
  6619. pipe_config->cpu_transcoder = TRANSCODER_EDP;
  6620. }
  6621. if (!intel_display_power_is_enabled(dev_priv,
  6622. POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder)))
  6623. return false;
  6624. tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder));
  6625. if (!(tmp & PIPECONF_ENABLE))
  6626. return false;
  6627. haswell_get_ddi_port_state(crtc, pipe_config);
  6628. intel_get_pipe_timings(crtc, pipe_config);
  6629. pfit_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe);
  6630. if (intel_display_power_is_enabled(dev_priv, pfit_domain))
  6631. ironlake_get_pfit_config(crtc, pipe_config);
  6632. if (IS_HASWELL(dev))
  6633. pipe_config->ips_enabled = hsw_crtc_supports_ips(crtc) &&
  6634. (I915_READ(IPS_CTL) & IPS_ENABLE);
  6635. if (pipe_config->cpu_transcoder != TRANSCODER_EDP) {
  6636. pipe_config->pixel_multiplier =
  6637. I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1;
  6638. } else {
  6639. pipe_config->pixel_multiplier = 1;
  6640. }
  6641. return true;
  6642. }
  6643. static struct {
  6644. int clock;
  6645. u32 config;
  6646. } hdmi_audio_clock[] = {
  6647. { DIV_ROUND_UP(25200 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_25175 },
  6648. { 25200, AUD_CONFIG_PIXEL_CLOCK_HDMI_25200 }, /* default per bspec */
  6649. { 27000, AUD_CONFIG_PIXEL_CLOCK_HDMI_27000 },
  6650. { 27000 * 1001 / 1000, AUD_CONFIG_PIXEL_CLOCK_HDMI_27027 },
  6651. { 54000, AUD_CONFIG_PIXEL_CLOCK_HDMI_54000 },
  6652. { 54000 * 1001 / 1000, AUD_CONFIG_PIXEL_CLOCK_HDMI_54054 },
  6653. { DIV_ROUND_UP(74250 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_74176 },
  6654. { 74250, AUD_CONFIG_PIXEL_CLOCK_HDMI_74250 },
  6655. { DIV_ROUND_UP(148500 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_148352 },
  6656. { 148500, AUD_CONFIG_PIXEL_CLOCK_HDMI_148500 },
  6657. };
  6658. /* get AUD_CONFIG_PIXEL_CLOCK_HDMI_* value for mode */
  6659. static u32 audio_config_hdmi_pixel_clock(struct drm_display_mode *mode)
  6660. {
  6661. int i;
  6662. for (i = 0; i < ARRAY_SIZE(hdmi_audio_clock); i++) {
  6663. if (mode->clock == hdmi_audio_clock[i].clock)
  6664. break;
  6665. }
  6666. if (i == ARRAY_SIZE(hdmi_audio_clock)) {
  6667. DRM_DEBUG_KMS("HDMI audio pixel clock setting for %d not found, falling back to defaults\n", mode->clock);
  6668. i = 1;
  6669. }
  6670. DRM_DEBUG_KMS("Configuring HDMI audio for pixel clock %d (0x%08x)\n",
  6671. hdmi_audio_clock[i].clock,
  6672. hdmi_audio_clock[i].config);
  6673. return hdmi_audio_clock[i].config;
  6674. }
  6675. static bool intel_eld_uptodate(struct drm_connector *connector,
  6676. int reg_eldv, uint32_t bits_eldv,
  6677. int reg_elda, uint32_t bits_elda,
  6678. int reg_edid)
  6679. {
  6680. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  6681. uint8_t *eld = connector->eld;
  6682. uint32_t i;
  6683. i = I915_READ(reg_eldv);
  6684. i &= bits_eldv;
  6685. if (!eld[0])
  6686. return !i;
  6687. if (!i)
  6688. return false;
  6689. i = I915_READ(reg_elda);
  6690. i &= ~bits_elda;
  6691. I915_WRITE(reg_elda, i);
  6692. for (i = 0; i < eld[2]; i++)
  6693. if (I915_READ(reg_edid) != *((uint32_t *)eld + i))
  6694. return false;
  6695. return true;
  6696. }
  6697. static void g4x_write_eld(struct drm_connector *connector,
  6698. struct drm_crtc *crtc,
  6699. struct drm_display_mode *mode)
  6700. {
  6701. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  6702. uint8_t *eld = connector->eld;
  6703. uint32_t eldv;
  6704. uint32_t len;
  6705. uint32_t i;
  6706. i = I915_READ(G4X_AUD_VID_DID);
  6707. if (i == INTEL_AUDIO_DEVBLC || i == INTEL_AUDIO_DEVCL)
  6708. eldv = G4X_ELDV_DEVCL_DEVBLC;
  6709. else
  6710. eldv = G4X_ELDV_DEVCTG;
  6711. if (intel_eld_uptodate(connector,
  6712. G4X_AUD_CNTL_ST, eldv,
  6713. G4X_AUD_CNTL_ST, G4X_ELD_ADDR,
  6714. G4X_HDMIW_HDMIEDID))
  6715. return;
  6716. i = I915_READ(G4X_AUD_CNTL_ST);
  6717. i &= ~(eldv | G4X_ELD_ADDR);
  6718. len = (i >> 9) & 0x1f; /* ELD buffer size */
  6719. I915_WRITE(G4X_AUD_CNTL_ST, i);
  6720. if (!eld[0])
  6721. return;
  6722. len = min_t(uint8_t, eld[2], len);
  6723. DRM_DEBUG_DRIVER("ELD size %d\n", len);
  6724. for (i = 0; i < len; i++)
  6725. I915_WRITE(G4X_HDMIW_HDMIEDID, *((uint32_t *)eld + i));
  6726. i = I915_READ(G4X_AUD_CNTL_ST);
  6727. i |= eldv;
  6728. I915_WRITE(G4X_AUD_CNTL_ST, i);
  6729. }
  6730. static void haswell_write_eld(struct drm_connector *connector,
  6731. struct drm_crtc *crtc,
  6732. struct drm_display_mode *mode)
  6733. {
  6734. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  6735. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6736. uint8_t *eld = connector->eld;
  6737. uint32_t eldv;
  6738. uint32_t i;
  6739. int len;
  6740. int pipe = to_intel_crtc(crtc)->pipe;
  6741. int tmp;
  6742. int hdmiw_hdmiedid = HSW_AUD_EDID_DATA(pipe);
  6743. int aud_cntl_st = HSW_AUD_DIP_ELD_CTRL(pipe);
  6744. int aud_config = HSW_AUD_CFG(pipe);
  6745. int aud_cntrl_st2 = HSW_AUD_PIN_ELD_CP_VLD;
  6746. /* Audio output enable */
  6747. DRM_DEBUG_DRIVER("HDMI audio: enable codec\n");
  6748. tmp = I915_READ(aud_cntrl_st2);
  6749. tmp |= (AUDIO_OUTPUT_ENABLE_A << (pipe * 4));
  6750. I915_WRITE(aud_cntrl_st2, tmp);
  6751. POSTING_READ(aud_cntrl_st2);
  6752. assert_pipe_disabled(dev_priv, to_intel_crtc(crtc)->pipe);
  6753. /* Set ELD valid state */
  6754. tmp = I915_READ(aud_cntrl_st2);
  6755. DRM_DEBUG_DRIVER("HDMI audio: pin eld vld status=0x%08x\n", tmp);
  6756. tmp |= (AUDIO_ELD_VALID_A << (pipe * 4));
  6757. I915_WRITE(aud_cntrl_st2, tmp);
  6758. tmp = I915_READ(aud_cntrl_st2);
  6759. DRM_DEBUG_DRIVER("HDMI audio: eld vld status=0x%08x\n", tmp);
  6760. /* Enable HDMI mode */
  6761. tmp = I915_READ(aud_config);
  6762. DRM_DEBUG_DRIVER("HDMI audio: audio conf: 0x%08x\n", tmp);
  6763. /* clear N_programing_enable and N_value_index */
  6764. tmp &= ~(AUD_CONFIG_N_VALUE_INDEX | AUD_CONFIG_N_PROG_ENABLE);
  6765. I915_WRITE(aud_config, tmp);
  6766. DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe));
  6767. eldv = AUDIO_ELD_VALID_A << (pipe * 4);
  6768. if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DISPLAYPORT)) {
  6769. DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
  6770. eld[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
  6771. I915_WRITE(aud_config, AUD_CONFIG_N_VALUE_INDEX); /* 0x1 = DP */
  6772. } else {
  6773. I915_WRITE(aud_config, audio_config_hdmi_pixel_clock(mode));
  6774. }
  6775. if (intel_eld_uptodate(connector,
  6776. aud_cntrl_st2, eldv,
  6777. aud_cntl_st, IBX_ELD_ADDRESS,
  6778. hdmiw_hdmiedid))
  6779. return;
  6780. i = I915_READ(aud_cntrl_st2);
  6781. i &= ~eldv;
  6782. I915_WRITE(aud_cntrl_st2, i);
  6783. if (!eld[0])
  6784. return;
  6785. i = I915_READ(aud_cntl_st);
  6786. i &= ~IBX_ELD_ADDRESS;
  6787. I915_WRITE(aud_cntl_st, i);
  6788. i = (i >> 29) & DIP_PORT_SEL_MASK; /* DIP_Port_Select, 0x1 = PortB */
  6789. DRM_DEBUG_DRIVER("port num:%d\n", i);
  6790. len = min_t(uint8_t, eld[2], 21); /* 84 bytes of hw ELD buffer */
  6791. DRM_DEBUG_DRIVER("ELD size %d\n", len);
  6792. for (i = 0; i < len; i++)
  6793. I915_WRITE(hdmiw_hdmiedid, *((uint32_t *)eld + i));
  6794. i = I915_READ(aud_cntrl_st2);
  6795. i |= eldv;
  6796. I915_WRITE(aud_cntrl_st2, i);
  6797. }
  6798. static void ironlake_write_eld(struct drm_connector *connector,
  6799. struct drm_crtc *crtc,
  6800. struct drm_display_mode *mode)
  6801. {
  6802. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  6803. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6804. uint8_t *eld = connector->eld;
  6805. uint32_t eldv;
  6806. uint32_t i;
  6807. int len;
  6808. int hdmiw_hdmiedid;
  6809. int aud_config;
  6810. int aud_cntl_st;
  6811. int aud_cntrl_st2;
  6812. int pipe = to_intel_crtc(crtc)->pipe;
  6813. if (HAS_PCH_IBX(connector->dev)) {
  6814. hdmiw_hdmiedid = IBX_HDMIW_HDMIEDID(pipe);
  6815. aud_config = IBX_AUD_CFG(pipe);
  6816. aud_cntl_st = IBX_AUD_CNTL_ST(pipe);
  6817. aud_cntrl_st2 = IBX_AUD_CNTL_ST2;
  6818. } else if (IS_VALLEYVIEW(connector->dev)) {
  6819. hdmiw_hdmiedid = VLV_HDMIW_HDMIEDID(pipe);
  6820. aud_config = VLV_AUD_CFG(pipe);
  6821. aud_cntl_st = VLV_AUD_CNTL_ST(pipe);
  6822. aud_cntrl_st2 = VLV_AUD_CNTL_ST2;
  6823. } else {
  6824. hdmiw_hdmiedid = CPT_HDMIW_HDMIEDID(pipe);
  6825. aud_config = CPT_AUD_CFG(pipe);
  6826. aud_cntl_st = CPT_AUD_CNTL_ST(pipe);
  6827. aud_cntrl_st2 = CPT_AUD_CNTRL_ST2;
  6828. }
  6829. DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe));
  6830. if (IS_VALLEYVIEW(connector->dev)) {
  6831. struct intel_encoder *intel_encoder;
  6832. struct intel_digital_port *intel_dig_port;
  6833. intel_encoder = intel_attached_encoder(connector);
  6834. intel_dig_port = enc_to_dig_port(&intel_encoder->base);
  6835. i = intel_dig_port->port;
  6836. } else {
  6837. i = I915_READ(aud_cntl_st);
  6838. i = (i >> 29) & DIP_PORT_SEL_MASK;
  6839. /* DIP_Port_Select, 0x1 = PortB */
  6840. }
  6841. if (!i) {
  6842. DRM_DEBUG_DRIVER("Audio directed to unknown port\n");
  6843. /* operate blindly on all ports */
  6844. eldv = IBX_ELD_VALIDB;
  6845. eldv |= IBX_ELD_VALIDB << 4;
  6846. eldv |= IBX_ELD_VALIDB << 8;
  6847. } else {
  6848. DRM_DEBUG_DRIVER("ELD on port %c\n", port_name(i));
  6849. eldv = IBX_ELD_VALIDB << ((i - 1) * 4);
  6850. }
  6851. if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DISPLAYPORT)) {
  6852. DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
  6853. eld[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
  6854. I915_WRITE(aud_config, AUD_CONFIG_N_VALUE_INDEX); /* 0x1 = DP */
  6855. } else {
  6856. I915_WRITE(aud_config, audio_config_hdmi_pixel_clock(mode));
  6857. }
  6858. if (intel_eld_uptodate(connector,
  6859. aud_cntrl_st2, eldv,
  6860. aud_cntl_st, IBX_ELD_ADDRESS,
  6861. hdmiw_hdmiedid))
  6862. return;
  6863. i = I915_READ(aud_cntrl_st2);
  6864. i &= ~eldv;
  6865. I915_WRITE(aud_cntrl_st2, i);
  6866. if (!eld[0])
  6867. return;
  6868. i = I915_READ(aud_cntl_st);
  6869. i &= ~IBX_ELD_ADDRESS;
  6870. I915_WRITE(aud_cntl_st, i);
  6871. len = min_t(uint8_t, eld[2], 21); /* 84 bytes of hw ELD buffer */
  6872. DRM_DEBUG_DRIVER("ELD size %d\n", len);
  6873. for (i = 0; i < len; i++)
  6874. I915_WRITE(hdmiw_hdmiedid, *((uint32_t *)eld + i));
  6875. i = I915_READ(aud_cntrl_st2);
  6876. i |= eldv;
  6877. I915_WRITE(aud_cntrl_st2, i);
  6878. }
  6879. void intel_write_eld(struct drm_encoder *encoder,
  6880. struct drm_display_mode *mode)
  6881. {
  6882. struct drm_crtc *crtc = encoder->crtc;
  6883. struct drm_connector *connector;
  6884. struct drm_device *dev = encoder->dev;
  6885. struct drm_i915_private *dev_priv = dev->dev_private;
  6886. connector = drm_select_eld(encoder, mode);
  6887. if (!connector)
  6888. return;
  6889. DRM_DEBUG_DRIVER("ELD on [CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
  6890. connector->base.id,
  6891. connector->name,
  6892. connector->encoder->base.id,
  6893. connector->encoder->name);
  6894. connector->eld[6] = drm_av_sync_delay(connector, mode) / 2;
  6895. if (dev_priv->display.write_eld)
  6896. dev_priv->display.write_eld(connector, crtc, mode);
  6897. }
  6898. static void i845_update_cursor(struct drm_crtc *crtc, u32 base)
  6899. {
  6900. struct drm_device *dev = crtc->dev;
  6901. struct drm_i915_private *dev_priv = dev->dev_private;
  6902. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6903. uint32_t cntl = 0, size = 0;
  6904. if (base) {
  6905. unsigned int width = intel_crtc->cursor_width;
  6906. unsigned int height = intel_crtc->cursor_height;
  6907. unsigned int stride = roundup_pow_of_two(width) * 4;
  6908. switch (stride) {
  6909. default:
  6910. WARN_ONCE(1, "Invalid cursor width/stride, width=%u, stride=%u\n",
  6911. width, stride);
  6912. stride = 256;
  6913. /* fallthrough */
  6914. case 256:
  6915. case 512:
  6916. case 1024:
  6917. case 2048:
  6918. break;
  6919. }
  6920. cntl |= CURSOR_ENABLE |
  6921. CURSOR_GAMMA_ENABLE |
  6922. CURSOR_FORMAT_ARGB |
  6923. CURSOR_STRIDE(stride);
  6924. size = (height << 12) | width;
  6925. }
  6926. if (intel_crtc->cursor_cntl != 0 &&
  6927. (intel_crtc->cursor_base != base ||
  6928. intel_crtc->cursor_size != size ||
  6929. intel_crtc->cursor_cntl != cntl)) {
  6930. /* On these chipsets we can only modify the base/size/stride
  6931. * whilst the cursor is disabled.
  6932. */
  6933. I915_WRITE(_CURACNTR, 0);
  6934. POSTING_READ(_CURACNTR);
  6935. intel_crtc->cursor_cntl = 0;
  6936. }
  6937. if (intel_crtc->cursor_base != base) {
  6938. I915_WRITE(_CURABASE, base);
  6939. intel_crtc->cursor_base = base;
  6940. }
  6941. if (intel_crtc->cursor_size != size) {
  6942. I915_WRITE(CURSIZE, size);
  6943. intel_crtc->cursor_size = size;
  6944. }
  6945. if (intel_crtc->cursor_cntl != cntl) {
  6946. I915_WRITE(_CURACNTR, cntl);
  6947. POSTING_READ(_CURACNTR);
  6948. intel_crtc->cursor_cntl = cntl;
  6949. }
  6950. }
  6951. static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base)
  6952. {
  6953. struct drm_device *dev = crtc->dev;
  6954. struct drm_i915_private *dev_priv = dev->dev_private;
  6955. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6956. int pipe = intel_crtc->pipe;
  6957. uint32_t cntl;
  6958. cntl = 0;
  6959. if (base) {
  6960. cntl = MCURSOR_GAMMA_ENABLE;
  6961. switch (intel_crtc->cursor_width) {
  6962. case 64:
  6963. cntl |= CURSOR_MODE_64_ARGB_AX;
  6964. break;
  6965. case 128:
  6966. cntl |= CURSOR_MODE_128_ARGB_AX;
  6967. break;
  6968. case 256:
  6969. cntl |= CURSOR_MODE_256_ARGB_AX;
  6970. break;
  6971. default:
  6972. WARN_ON(1);
  6973. return;
  6974. }
  6975. cntl |= pipe << 28; /* Connect to correct pipe */
  6976. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  6977. cntl |= CURSOR_PIPE_CSC_ENABLE;
  6978. }
  6979. if (to_intel_plane(crtc->cursor)->rotation == BIT(DRM_ROTATE_180))
  6980. cntl |= CURSOR_ROTATE_180;
  6981. if (intel_crtc->cursor_cntl != cntl) {
  6982. I915_WRITE(CURCNTR(pipe), cntl);
  6983. POSTING_READ(CURCNTR(pipe));
  6984. intel_crtc->cursor_cntl = cntl;
  6985. }
  6986. /* and commit changes on next vblank */
  6987. I915_WRITE(CURBASE(pipe), base);
  6988. POSTING_READ(CURBASE(pipe));
  6989. intel_crtc->cursor_base = base;
  6990. }
  6991. /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */
  6992. static void intel_crtc_update_cursor(struct drm_crtc *crtc,
  6993. bool on)
  6994. {
  6995. struct drm_device *dev = crtc->dev;
  6996. struct drm_i915_private *dev_priv = dev->dev_private;
  6997. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6998. int pipe = intel_crtc->pipe;
  6999. int x = crtc->cursor_x;
  7000. int y = crtc->cursor_y;
  7001. u32 base = 0, pos = 0;
  7002. if (on)
  7003. base = intel_crtc->cursor_addr;
  7004. if (x >= intel_crtc->config.pipe_src_w)
  7005. base = 0;
  7006. if (y >= intel_crtc->config.pipe_src_h)
  7007. base = 0;
  7008. if (x < 0) {
  7009. if (x + intel_crtc->cursor_width <= 0)
  7010. base = 0;
  7011. pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
  7012. x = -x;
  7013. }
  7014. pos |= x << CURSOR_X_SHIFT;
  7015. if (y < 0) {
  7016. if (y + intel_crtc->cursor_height <= 0)
  7017. base = 0;
  7018. pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
  7019. y = -y;
  7020. }
  7021. pos |= y << CURSOR_Y_SHIFT;
  7022. if (base == 0 && intel_crtc->cursor_base == 0)
  7023. return;
  7024. I915_WRITE(CURPOS(pipe), pos);
  7025. /* ILK+ do this automagically */
  7026. if (HAS_GMCH_DISPLAY(dev) &&
  7027. to_intel_plane(crtc->cursor)->rotation == BIT(DRM_ROTATE_180)) {
  7028. base += (intel_crtc->cursor_height *
  7029. intel_crtc->cursor_width - 1) * 4;
  7030. }
  7031. if (IS_845G(dev) || IS_I865G(dev))
  7032. i845_update_cursor(crtc, base);
  7033. else
  7034. i9xx_update_cursor(crtc, base);
  7035. }
  7036. static bool cursor_size_ok(struct drm_device *dev,
  7037. uint32_t width, uint32_t height)
  7038. {
  7039. if (width == 0 || height == 0)
  7040. return false;
  7041. /*
  7042. * 845g/865g are special in that they are only limited by
  7043. * the width of their cursors, the height is arbitrary up to
  7044. * the precision of the register. Everything else requires
  7045. * square cursors, limited to a few power-of-two sizes.
  7046. */
  7047. if (IS_845G(dev) || IS_I865G(dev)) {
  7048. if ((width & 63) != 0)
  7049. return false;
  7050. if (width > (IS_845G(dev) ? 64 : 512))
  7051. return false;
  7052. if (height > 1023)
  7053. return false;
  7054. } else {
  7055. switch (width | height) {
  7056. case 256:
  7057. case 128:
  7058. if (IS_GEN2(dev))
  7059. return false;
  7060. case 64:
  7061. break;
  7062. default:
  7063. return false;
  7064. }
  7065. }
  7066. return true;
  7067. }
  7068. static int intel_crtc_cursor_set_obj(struct drm_crtc *crtc,
  7069. struct drm_i915_gem_object *obj,
  7070. uint32_t width, uint32_t height)
  7071. {
  7072. struct drm_device *dev = crtc->dev;
  7073. struct drm_i915_private *dev_priv = dev->dev_private;
  7074. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7075. enum pipe pipe = intel_crtc->pipe;
  7076. unsigned old_width;
  7077. uint32_t addr;
  7078. int ret;
  7079. /* if we want to turn off the cursor ignore width and height */
  7080. if (!obj) {
  7081. DRM_DEBUG_KMS("cursor off\n");
  7082. addr = 0;
  7083. mutex_lock(&dev->struct_mutex);
  7084. goto finish;
  7085. }
  7086. /* we only need to pin inside GTT if cursor is non-phy */
  7087. mutex_lock(&dev->struct_mutex);
  7088. if (!INTEL_INFO(dev)->cursor_needs_physical) {
  7089. unsigned alignment;
  7090. /*
  7091. * Global gtt pte registers are special registers which actually
  7092. * forward writes to a chunk of system memory. Which means that
  7093. * there is no risk that the register values disappear as soon
  7094. * as we call intel_runtime_pm_put(), so it is correct to wrap
  7095. * only the pin/unpin/fence and not more.
  7096. */
  7097. intel_runtime_pm_get(dev_priv);
  7098. /* Note that the w/a also requires 2 PTE of padding following
  7099. * the bo. We currently fill all unused PTE with the shadow
  7100. * page and so we should always have valid PTE following the
  7101. * cursor preventing the VT-d warning.
  7102. */
  7103. alignment = 0;
  7104. if (need_vtd_wa(dev))
  7105. alignment = 64*1024;
  7106. ret = i915_gem_object_pin_to_display_plane(obj, alignment, NULL);
  7107. if (ret) {
  7108. DRM_DEBUG_KMS("failed to move cursor bo into the GTT\n");
  7109. intel_runtime_pm_put(dev_priv);
  7110. goto fail_locked;
  7111. }
  7112. ret = i915_gem_object_put_fence(obj);
  7113. if (ret) {
  7114. DRM_DEBUG_KMS("failed to release fence for cursor");
  7115. intel_runtime_pm_put(dev_priv);
  7116. goto fail_unpin;
  7117. }
  7118. addr = i915_gem_obj_ggtt_offset(obj);
  7119. intel_runtime_pm_put(dev_priv);
  7120. } else {
  7121. int align = IS_I830(dev) ? 16 * 1024 : 256;
  7122. ret = i915_gem_object_attach_phys(obj, align);
  7123. if (ret) {
  7124. DRM_DEBUG_KMS("failed to attach phys object\n");
  7125. goto fail_locked;
  7126. }
  7127. addr = obj->phys_handle->busaddr;
  7128. }
  7129. finish:
  7130. if (intel_crtc->cursor_bo) {
  7131. if (!INTEL_INFO(dev)->cursor_needs_physical)
  7132. i915_gem_object_unpin_from_display_plane(intel_crtc->cursor_bo);
  7133. }
  7134. i915_gem_track_fb(intel_crtc->cursor_bo, obj,
  7135. INTEL_FRONTBUFFER_CURSOR(pipe));
  7136. mutex_unlock(&dev->struct_mutex);
  7137. old_width = intel_crtc->cursor_width;
  7138. intel_crtc->cursor_addr = addr;
  7139. intel_crtc->cursor_bo = obj;
  7140. intel_crtc->cursor_width = width;
  7141. intel_crtc->cursor_height = height;
  7142. if (intel_crtc->active) {
  7143. if (old_width != width)
  7144. intel_update_watermarks(crtc);
  7145. intel_crtc_update_cursor(crtc, intel_crtc->cursor_bo != NULL);
  7146. }
  7147. intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_CURSOR(pipe));
  7148. return 0;
  7149. fail_unpin:
  7150. i915_gem_object_unpin_from_display_plane(obj);
  7151. fail_locked:
  7152. mutex_unlock(&dev->struct_mutex);
  7153. return ret;
  7154. }
  7155. static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
  7156. u16 *blue, uint32_t start, uint32_t size)
  7157. {
  7158. int end = (start + size > 256) ? 256 : start + size, i;
  7159. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7160. for (i = start; i < end; i++) {
  7161. intel_crtc->lut_r[i] = red[i] >> 8;
  7162. intel_crtc->lut_g[i] = green[i] >> 8;
  7163. intel_crtc->lut_b[i] = blue[i] >> 8;
  7164. }
  7165. intel_crtc_load_lut(crtc);
  7166. }
  7167. /* VESA 640x480x72Hz mode to set on the pipe */
  7168. static struct drm_display_mode load_detect_mode = {
  7169. DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
  7170. 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  7171. };
  7172. struct drm_framebuffer *
  7173. __intel_framebuffer_create(struct drm_device *dev,
  7174. struct drm_mode_fb_cmd2 *mode_cmd,
  7175. struct drm_i915_gem_object *obj)
  7176. {
  7177. struct intel_framebuffer *intel_fb;
  7178. int ret;
  7179. intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
  7180. if (!intel_fb) {
  7181. drm_gem_object_unreference_unlocked(&obj->base);
  7182. return ERR_PTR(-ENOMEM);
  7183. }
  7184. ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj);
  7185. if (ret)
  7186. goto err;
  7187. return &intel_fb->base;
  7188. err:
  7189. drm_gem_object_unreference_unlocked(&obj->base);
  7190. kfree(intel_fb);
  7191. return ERR_PTR(ret);
  7192. }
  7193. static struct drm_framebuffer *
  7194. intel_framebuffer_create(struct drm_device *dev,
  7195. struct drm_mode_fb_cmd2 *mode_cmd,
  7196. struct drm_i915_gem_object *obj)
  7197. {
  7198. struct drm_framebuffer *fb;
  7199. int ret;
  7200. ret = i915_mutex_lock_interruptible(dev);
  7201. if (ret)
  7202. return ERR_PTR(ret);
  7203. fb = __intel_framebuffer_create(dev, mode_cmd, obj);
  7204. mutex_unlock(&dev->struct_mutex);
  7205. return fb;
  7206. }
  7207. static u32
  7208. intel_framebuffer_pitch_for_width(int width, int bpp)
  7209. {
  7210. u32 pitch = DIV_ROUND_UP(width * bpp, 8);
  7211. return ALIGN(pitch, 64);
  7212. }
  7213. static u32
  7214. intel_framebuffer_size_for_mode(struct drm_display_mode *mode, int bpp)
  7215. {
  7216. u32 pitch = intel_framebuffer_pitch_for_width(mode->hdisplay, bpp);
  7217. return PAGE_ALIGN(pitch * mode->vdisplay);
  7218. }
  7219. static struct drm_framebuffer *
  7220. intel_framebuffer_create_for_mode(struct drm_device *dev,
  7221. struct drm_display_mode *mode,
  7222. int depth, int bpp)
  7223. {
  7224. struct drm_i915_gem_object *obj;
  7225. struct drm_mode_fb_cmd2 mode_cmd = { 0 };
  7226. obj = i915_gem_alloc_object(dev,
  7227. intel_framebuffer_size_for_mode(mode, bpp));
  7228. if (obj == NULL)
  7229. return ERR_PTR(-ENOMEM);
  7230. mode_cmd.width = mode->hdisplay;
  7231. mode_cmd.height = mode->vdisplay;
  7232. mode_cmd.pitches[0] = intel_framebuffer_pitch_for_width(mode_cmd.width,
  7233. bpp);
  7234. mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth);
  7235. return intel_framebuffer_create(dev, &mode_cmd, obj);
  7236. }
  7237. static struct drm_framebuffer *
  7238. mode_fits_in_fbdev(struct drm_device *dev,
  7239. struct drm_display_mode *mode)
  7240. {
  7241. #ifdef CONFIG_DRM_I915_FBDEV
  7242. struct drm_i915_private *dev_priv = dev->dev_private;
  7243. struct drm_i915_gem_object *obj;
  7244. struct drm_framebuffer *fb;
  7245. if (!dev_priv->fbdev)
  7246. return NULL;
  7247. if (!dev_priv->fbdev->fb)
  7248. return NULL;
  7249. obj = dev_priv->fbdev->fb->obj;
  7250. BUG_ON(!obj);
  7251. fb = &dev_priv->fbdev->fb->base;
  7252. if (fb->pitches[0] < intel_framebuffer_pitch_for_width(mode->hdisplay,
  7253. fb->bits_per_pixel))
  7254. return NULL;
  7255. if (obj->base.size < mode->vdisplay * fb->pitches[0])
  7256. return NULL;
  7257. return fb;
  7258. #else
  7259. return NULL;
  7260. #endif
  7261. }
  7262. bool intel_get_load_detect_pipe(struct drm_connector *connector,
  7263. struct drm_display_mode *mode,
  7264. struct intel_load_detect_pipe *old,
  7265. struct drm_modeset_acquire_ctx *ctx)
  7266. {
  7267. struct intel_crtc *intel_crtc;
  7268. struct intel_encoder *intel_encoder =
  7269. intel_attached_encoder(connector);
  7270. struct drm_crtc *possible_crtc;
  7271. struct drm_encoder *encoder = &intel_encoder->base;
  7272. struct drm_crtc *crtc = NULL;
  7273. struct drm_device *dev = encoder->dev;
  7274. struct drm_framebuffer *fb;
  7275. struct drm_mode_config *config = &dev->mode_config;
  7276. int ret, i = -1;
  7277. DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
  7278. connector->base.id, connector->name,
  7279. encoder->base.id, encoder->name);
  7280. retry:
  7281. ret = drm_modeset_lock(&config->connection_mutex, ctx);
  7282. if (ret)
  7283. goto fail_unlock;
  7284. /*
  7285. * Algorithm gets a little messy:
  7286. *
  7287. * - if the connector already has an assigned crtc, use it (but make
  7288. * sure it's on first)
  7289. *
  7290. * - try to find the first unused crtc that can drive this connector,
  7291. * and use that if we find one
  7292. */
  7293. /* See if we already have a CRTC for this connector */
  7294. if (encoder->crtc) {
  7295. crtc = encoder->crtc;
  7296. ret = drm_modeset_lock(&crtc->mutex, ctx);
  7297. if (ret)
  7298. goto fail_unlock;
  7299. old->dpms_mode = connector->dpms;
  7300. old->load_detect_temp = false;
  7301. /* Make sure the crtc and connector are running */
  7302. if (connector->dpms != DRM_MODE_DPMS_ON)
  7303. connector->funcs->dpms(connector, DRM_MODE_DPMS_ON);
  7304. return true;
  7305. }
  7306. /* Find an unused one (if possible) */
  7307. for_each_crtc(dev, possible_crtc) {
  7308. i++;
  7309. if (!(encoder->possible_crtcs & (1 << i)))
  7310. continue;
  7311. if (possible_crtc->enabled)
  7312. continue;
  7313. /* This can occur when applying the pipe A quirk on resume. */
  7314. if (to_intel_crtc(possible_crtc)->new_enabled)
  7315. continue;
  7316. crtc = possible_crtc;
  7317. break;
  7318. }
  7319. /*
  7320. * If we didn't find an unused CRTC, don't use any.
  7321. */
  7322. if (!crtc) {
  7323. DRM_DEBUG_KMS("no pipe available for load-detect\n");
  7324. goto fail_unlock;
  7325. }
  7326. ret = drm_modeset_lock(&crtc->mutex, ctx);
  7327. if (ret)
  7328. goto fail_unlock;
  7329. intel_encoder->new_crtc = to_intel_crtc(crtc);
  7330. to_intel_connector(connector)->new_encoder = intel_encoder;
  7331. intel_crtc = to_intel_crtc(crtc);
  7332. intel_crtc->new_enabled = true;
  7333. intel_crtc->new_config = &intel_crtc->config;
  7334. old->dpms_mode = connector->dpms;
  7335. old->load_detect_temp = true;
  7336. old->release_fb = NULL;
  7337. if (!mode)
  7338. mode = &load_detect_mode;
  7339. /* We need a framebuffer large enough to accommodate all accesses
  7340. * that the plane may generate whilst we perform load detection.
  7341. * We can not rely on the fbcon either being present (we get called
  7342. * during its initialisation to detect all boot displays, or it may
  7343. * not even exist) or that it is large enough to satisfy the
  7344. * requested mode.
  7345. */
  7346. fb = mode_fits_in_fbdev(dev, mode);
  7347. if (fb == NULL) {
  7348. DRM_DEBUG_KMS("creating tmp fb for load-detection\n");
  7349. fb = intel_framebuffer_create_for_mode(dev, mode, 24, 32);
  7350. old->release_fb = fb;
  7351. } else
  7352. DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n");
  7353. if (IS_ERR(fb)) {
  7354. DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n");
  7355. goto fail;
  7356. }
  7357. if (intel_set_mode(crtc, mode, 0, 0, fb)) {
  7358. DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
  7359. if (old->release_fb)
  7360. old->release_fb->funcs->destroy(old->release_fb);
  7361. goto fail;
  7362. }
  7363. /* let the connector get through one full cycle before testing */
  7364. intel_wait_for_vblank(dev, intel_crtc->pipe);
  7365. return true;
  7366. fail:
  7367. intel_crtc->new_enabled = crtc->enabled;
  7368. if (intel_crtc->new_enabled)
  7369. intel_crtc->new_config = &intel_crtc->config;
  7370. else
  7371. intel_crtc->new_config = NULL;
  7372. fail_unlock:
  7373. if (ret == -EDEADLK) {
  7374. drm_modeset_backoff(ctx);
  7375. goto retry;
  7376. }
  7377. return false;
  7378. }
  7379. void intel_release_load_detect_pipe(struct drm_connector *connector,
  7380. struct intel_load_detect_pipe *old)
  7381. {
  7382. struct intel_encoder *intel_encoder =
  7383. intel_attached_encoder(connector);
  7384. struct drm_encoder *encoder = &intel_encoder->base;
  7385. struct drm_crtc *crtc = encoder->crtc;
  7386. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7387. DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
  7388. connector->base.id, connector->name,
  7389. encoder->base.id, encoder->name);
  7390. if (old->load_detect_temp) {
  7391. to_intel_connector(connector)->new_encoder = NULL;
  7392. intel_encoder->new_crtc = NULL;
  7393. intel_crtc->new_enabled = false;
  7394. intel_crtc->new_config = NULL;
  7395. intel_set_mode(crtc, NULL, 0, 0, NULL);
  7396. if (old->release_fb) {
  7397. drm_framebuffer_unregister_private(old->release_fb);
  7398. drm_framebuffer_unreference(old->release_fb);
  7399. }
  7400. return;
  7401. }
  7402. /* Switch crtc and encoder back off if necessary */
  7403. if (old->dpms_mode != DRM_MODE_DPMS_ON)
  7404. connector->funcs->dpms(connector, old->dpms_mode);
  7405. }
  7406. static int i9xx_pll_refclk(struct drm_device *dev,
  7407. const struct intel_crtc_config *pipe_config)
  7408. {
  7409. struct drm_i915_private *dev_priv = dev->dev_private;
  7410. u32 dpll = pipe_config->dpll_hw_state.dpll;
  7411. if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN)
  7412. return dev_priv->vbt.lvds_ssc_freq;
  7413. else if (HAS_PCH_SPLIT(dev))
  7414. return 120000;
  7415. else if (!IS_GEN2(dev))
  7416. return 96000;
  7417. else
  7418. return 48000;
  7419. }
  7420. /* Returns the clock of the currently programmed mode of the given pipe. */
  7421. static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
  7422. struct intel_crtc_config *pipe_config)
  7423. {
  7424. struct drm_device *dev = crtc->base.dev;
  7425. struct drm_i915_private *dev_priv = dev->dev_private;
  7426. int pipe = pipe_config->cpu_transcoder;
  7427. u32 dpll = pipe_config->dpll_hw_state.dpll;
  7428. u32 fp;
  7429. intel_clock_t clock;
  7430. int refclk = i9xx_pll_refclk(dev, pipe_config);
  7431. if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
  7432. fp = pipe_config->dpll_hw_state.fp0;
  7433. else
  7434. fp = pipe_config->dpll_hw_state.fp1;
  7435. clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
  7436. if (IS_PINEVIEW(dev)) {
  7437. clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
  7438. clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
  7439. } else {
  7440. clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
  7441. clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
  7442. }
  7443. if (!IS_GEN2(dev)) {
  7444. if (IS_PINEVIEW(dev))
  7445. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
  7446. DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
  7447. else
  7448. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
  7449. DPLL_FPA01_P1_POST_DIV_SHIFT);
  7450. switch (dpll & DPLL_MODE_MASK) {
  7451. case DPLLB_MODE_DAC_SERIAL:
  7452. clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
  7453. 5 : 10;
  7454. break;
  7455. case DPLLB_MODE_LVDS:
  7456. clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
  7457. 7 : 14;
  7458. break;
  7459. default:
  7460. DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
  7461. "mode\n", (int)(dpll & DPLL_MODE_MASK));
  7462. return;
  7463. }
  7464. if (IS_PINEVIEW(dev))
  7465. pineview_clock(refclk, &clock);
  7466. else
  7467. i9xx_clock(refclk, &clock);
  7468. } else {
  7469. u32 lvds = IS_I830(dev) ? 0 : I915_READ(LVDS);
  7470. bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN);
  7471. if (is_lvds) {
  7472. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
  7473. DPLL_FPA01_P1_POST_DIV_SHIFT);
  7474. if (lvds & LVDS_CLKB_POWER_UP)
  7475. clock.p2 = 7;
  7476. else
  7477. clock.p2 = 14;
  7478. } else {
  7479. if (dpll & PLL_P1_DIVIDE_BY_TWO)
  7480. clock.p1 = 2;
  7481. else {
  7482. clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
  7483. DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
  7484. }
  7485. if (dpll & PLL_P2_DIVIDE_BY_4)
  7486. clock.p2 = 4;
  7487. else
  7488. clock.p2 = 2;
  7489. }
  7490. i9xx_clock(refclk, &clock);
  7491. }
  7492. /*
  7493. * This value includes pixel_multiplier. We will use
  7494. * port_clock to compute adjusted_mode.crtc_clock in the
  7495. * encoder's get_config() function.
  7496. */
  7497. pipe_config->port_clock = clock.dot;
  7498. }
  7499. int intel_dotclock_calculate(int link_freq,
  7500. const struct intel_link_m_n *m_n)
  7501. {
  7502. /*
  7503. * The calculation for the data clock is:
  7504. * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
  7505. * But we want to avoid losing precison if possible, so:
  7506. * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
  7507. *
  7508. * and the link clock is simpler:
  7509. * link_clock = (m * link_clock) / n
  7510. */
  7511. if (!m_n->link_n)
  7512. return 0;
  7513. return div_u64((u64)m_n->link_m * link_freq, m_n->link_n);
  7514. }
  7515. static void ironlake_pch_clock_get(struct intel_crtc *crtc,
  7516. struct intel_crtc_config *pipe_config)
  7517. {
  7518. struct drm_device *dev = crtc->base.dev;
  7519. /* read out port_clock from the DPLL */
  7520. i9xx_crtc_clock_get(crtc, pipe_config);
  7521. /*
  7522. * This value does not include pixel_multiplier.
  7523. * We will check that port_clock and adjusted_mode.crtc_clock
  7524. * agree once we know their relationship in the encoder's
  7525. * get_config() function.
  7526. */
  7527. pipe_config->adjusted_mode.crtc_clock =
  7528. intel_dotclock_calculate(intel_fdi_link_freq(dev) * 10000,
  7529. &pipe_config->fdi_m_n);
  7530. }
  7531. /** Returns the currently programmed mode of the given pipe. */
  7532. struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev,
  7533. struct drm_crtc *crtc)
  7534. {
  7535. struct drm_i915_private *dev_priv = dev->dev_private;
  7536. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7537. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  7538. struct drm_display_mode *mode;
  7539. struct intel_crtc_config pipe_config;
  7540. int htot = I915_READ(HTOTAL(cpu_transcoder));
  7541. int hsync = I915_READ(HSYNC(cpu_transcoder));
  7542. int vtot = I915_READ(VTOTAL(cpu_transcoder));
  7543. int vsync = I915_READ(VSYNC(cpu_transcoder));
  7544. enum pipe pipe = intel_crtc->pipe;
  7545. mode = kzalloc(sizeof(*mode), GFP_KERNEL);
  7546. if (!mode)
  7547. return NULL;
  7548. /*
  7549. * Construct a pipe_config sufficient for getting the clock info
  7550. * back out of crtc_clock_get.
  7551. *
  7552. * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need
  7553. * to use a real value here instead.
  7554. */
  7555. pipe_config.cpu_transcoder = (enum transcoder) pipe;
  7556. pipe_config.pixel_multiplier = 1;
  7557. pipe_config.dpll_hw_state.dpll = I915_READ(DPLL(pipe));
  7558. pipe_config.dpll_hw_state.fp0 = I915_READ(FP0(pipe));
  7559. pipe_config.dpll_hw_state.fp1 = I915_READ(FP1(pipe));
  7560. i9xx_crtc_clock_get(intel_crtc, &pipe_config);
  7561. mode->clock = pipe_config.port_clock / pipe_config.pixel_multiplier;
  7562. mode->hdisplay = (htot & 0xffff) + 1;
  7563. mode->htotal = ((htot & 0xffff0000) >> 16) + 1;
  7564. mode->hsync_start = (hsync & 0xffff) + 1;
  7565. mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1;
  7566. mode->vdisplay = (vtot & 0xffff) + 1;
  7567. mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1;
  7568. mode->vsync_start = (vsync & 0xffff) + 1;
  7569. mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1;
  7570. drm_mode_set_name(mode);
  7571. return mode;
  7572. }
  7573. static void intel_decrease_pllclock(struct drm_crtc *crtc)
  7574. {
  7575. struct drm_device *dev = crtc->dev;
  7576. struct drm_i915_private *dev_priv = dev->dev_private;
  7577. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7578. if (!HAS_GMCH_DISPLAY(dev))
  7579. return;
  7580. if (!dev_priv->lvds_downclock_avail)
  7581. return;
  7582. /*
  7583. * Since this is called by a timer, we should never get here in
  7584. * the manual case.
  7585. */
  7586. if (!HAS_PIPE_CXSR(dev) && intel_crtc->lowfreq_avail) {
  7587. int pipe = intel_crtc->pipe;
  7588. int dpll_reg = DPLL(pipe);
  7589. int dpll;
  7590. DRM_DEBUG_DRIVER("downclocking LVDS\n");
  7591. assert_panel_unlocked(dev_priv, pipe);
  7592. dpll = I915_READ(dpll_reg);
  7593. dpll |= DISPLAY_RATE_SELECT_FPA1;
  7594. I915_WRITE(dpll_reg, dpll);
  7595. intel_wait_for_vblank(dev, pipe);
  7596. dpll = I915_READ(dpll_reg);
  7597. if (!(dpll & DISPLAY_RATE_SELECT_FPA1))
  7598. DRM_DEBUG_DRIVER("failed to downclock LVDS!\n");
  7599. }
  7600. }
  7601. void intel_mark_busy(struct drm_device *dev)
  7602. {
  7603. struct drm_i915_private *dev_priv = dev->dev_private;
  7604. if (dev_priv->mm.busy)
  7605. return;
  7606. intel_runtime_pm_get(dev_priv);
  7607. i915_update_gfx_val(dev_priv);
  7608. dev_priv->mm.busy = true;
  7609. }
  7610. void intel_mark_idle(struct drm_device *dev)
  7611. {
  7612. struct drm_i915_private *dev_priv = dev->dev_private;
  7613. struct drm_crtc *crtc;
  7614. if (!dev_priv->mm.busy)
  7615. return;
  7616. dev_priv->mm.busy = false;
  7617. if (!i915.powersave)
  7618. goto out;
  7619. for_each_crtc(dev, crtc) {
  7620. if (!crtc->primary->fb)
  7621. continue;
  7622. intel_decrease_pllclock(crtc);
  7623. }
  7624. if (INTEL_INFO(dev)->gen >= 6)
  7625. gen6_rps_idle(dev->dev_private);
  7626. out:
  7627. intel_runtime_pm_put(dev_priv);
  7628. }
  7629. static void intel_crtc_destroy(struct drm_crtc *crtc)
  7630. {
  7631. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7632. struct drm_device *dev = crtc->dev;
  7633. struct intel_unpin_work *work;
  7634. spin_lock_irq(&dev->event_lock);
  7635. work = intel_crtc->unpin_work;
  7636. intel_crtc->unpin_work = NULL;
  7637. spin_unlock_irq(&dev->event_lock);
  7638. if (work) {
  7639. cancel_work_sync(&work->work);
  7640. kfree(work);
  7641. }
  7642. drm_crtc_cleanup(crtc);
  7643. kfree(intel_crtc);
  7644. }
  7645. static void intel_unpin_work_fn(struct work_struct *__work)
  7646. {
  7647. struct intel_unpin_work *work =
  7648. container_of(__work, struct intel_unpin_work, work);
  7649. struct drm_device *dev = work->crtc->dev;
  7650. enum pipe pipe = to_intel_crtc(work->crtc)->pipe;
  7651. mutex_lock(&dev->struct_mutex);
  7652. intel_unpin_fb_obj(work->old_fb_obj);
  7653. drm_gem_object_unreference(&work->pending_flip_obj->base);
  7654. drm_gem_object_unreference(&work->old_fb_obj->base);
  7655. intel_update_fbc(dev);
  7656. mutex_unlock(&dev->struct_mutex);
  7657. intel_frontbuffer_flip_complete(dev, INTEL_FRONTBUFFER_PRIMARY(pipe));
  7658. BUG_ON(atomic_read(&to_intel_crtc(work->crtc)->unpin_work_count) == 0);
  7659. atomic_dec(&to_intel_crtc(work->crtc)->unpin_work_count);
  7660. kfree(work);
  7661. }
  7662. static void do_intel_finish_page_flip(struct drm_device *dev,
  7663. struct drm_crtc *crtc)
  7664. {
  7665. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7666. struct intel_unpin_work *work;
  7667. unsigned long flags;
  7668. /* Ignore early vblank irqs */
  7669. if (intel_crtc == NULL)
  7670. return;
  7671. /*
  7672. * This is called both by irq handlers and the reset code (to complete
  7673. * lost pageflips) so needs the full irqsave spinlocks.
  7674. */
  7675. spin_lock_irqsave(&dev->event_lock, flags);
  7676. work = intel_crtc->unpin_work;
  7677. /* Ensure we don't miss a work->pending update ... */
  7678. smp_rmb();
  7679. if (work == NULL || atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) {
  7680. spin_unlock_irqrestore(&dev->event_lock, flags);
  7681. return;
  7682. }
  7683. page_flip_completed(intel_crtc);
  7684. spin_unlock_irqrestore(&dev->event_lock, flags);
  7685. }
  7686. void intel_finish_page_flip(struct drm_device *dev, int pipe)
  7687. {
  7688. struct drm_i915_private *dev_priv = dev->dev_private;
  7689. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  7690. do_intel_finish_page_flip(dev, crtc);
  7691. }
  7692. void intel_finish_page_flip_plane(struct drm_device *dev, int plane)
  7693. {
  7694. struct drm_i915_private *dev_priv = dev->dev_private;
  7695. struct drm_crtc *crtc = dev_priv->plane_to_crtc_mapping[plane];
  7696. do_intel_finish_page_flip(dev, crtc);
  7697. }
  7698. /* Is 'a' after or equal to 'b'? */
  7699. static bool g4x_flip_count_after_eq(u32 a, u32 b)
  7700. {
  7701. return !((a - b) & 0x80000000);
  7702. }
  7703. static bool page_flip_finished(struct intel_crtc *crtc)
  7704. {
  7705. struct drm_device *dev = crtc->base.dev;
  7706. struct drm_i915_private *dev_priv = dev->dev_private;
  7707. /*
  7708. * The relevant registers doen't exist on pre-ctg.
  7709. * As the flip done interrupt doesn't trigger for mmio
  7710. * flips on gmch platforms, a flip count check isn't
  7711. * really needed there. But since ctg has the registers,
  7712. * include it in the check anyway.
  7713. */
  7714. if (INTEL_INFO(dev)->gen < 5 && !IS_G4X(dev))
  7715. return true;
  7716. /*
  7717. * A DSPSURFLIVE check isn't enough in case the mmio and CS flips
  7718. * used the same base address. In that case the mmio flip might
  7719. * have completed, but the CS hasn't even executed the flip yet.
  7720. *
  7721. * A flip count check isn't enough as the CS might have updated
  7722. * the base address just after start of vblank, but before we
  7723. * managed to process the interrupt. This means we'd complete the
  7724. * CS flip too soon.
  7725. *
  7726. * Combining both checks should get us a good enough result. It may
  7727. * still happen that the CS flip has been executed, but has not
  7728. * yet actually completed. But in case the base address is the same
  7729. * anyway, we don't really care.
  7730. */
  7731. return (I915_READ(DSPSURFLIVE(crtc->plane)) & ~0xfff) ==
  7732. crtc->unpin_work->gtt_offset &&
  7733. g4x_flip_count_after_eq(I915_READ(PIPE_FLIPCOUNT_GM45(crtc->pipe)),
  7734. crtc->unpin_work->flip_count);
  7735. }
  7736. void intel_prepare_page_flip(struct drm_device *dev, int plane)
  7737. {
  7738. struct drm_i915_private *dev_priv = dev->dev_private;
  7739. struct intel_crtc *intel_crtc =
  7740. to_intel_crtc(dev_priv->plane_to_crtc_mapping[plane]);
  7741. unsigned long flags;
  7742. /*
  7743. * This is called both by irq handlers and the reset code (to complete
  7744. * lost pageflips) so needs the full irqsave spinlocks.
  7745. *
  7746. * NB: An MMIO update of the plane base pointer will also
  7747. * generate a page-flip completion irq, i.e. every modeset
  7748. * is also accompanied by a spurious intel_prepare_page_flip().
  7749. */
  7750. spin_lock_irqsave(&dev->event_lock, flags);
  7751. if (intel_crtc->unpin_work && page_flip_finished(intel_crtc))
  7752. atomic_inc_not_zero(&intel_crtc->unpin_work->pending);
  7753. spin_unlock_irqrestore(&dev->event_lock, flags);
  7754. }
  7755. static inline void intel_mark_page_flip_active(struct intel_crtc *intel_crtc)
  7756. {
  7757. /* Ensure that the work item is consistent when activating it ... */
  7758. smp_wmb();
  7759. atomic_set(&intel_crtc->unpin_work->pending, INTEL_FLIP_PENDING);
  7760. /* and that it is marked active as soon as the irq could fire. */
  7761. smp_wmb();
  7762. }
  7763. static int intel_gen2_queue_flip(struct drm_device *dev,
  7764. struct drm_crtc *crtc,
  7765. struct drm_framebuffer *fb,
  7766. struct drm_i915_gem_object *obj,
  7767. struct intel_engine_cs *ring,
  7768. uint32_t flags)
  7769. {
  7770. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7771. u32 flip_mask;
  7772. int ret;
  7773. ret = intel_ring_begin(ring, 6);
  7774. if (ret)
  7775. return ret;
  7776. /* Can't queue multiple flips, so wait for the previous
  7777. * one to finish before executing the next.
  7778. */
  7779. if (intel_crtc->plane)
  7780. flip_mask = MI_WAIT_FOR_PLANE_B_FLIP;
  7781. else
  7782. flip_mask = MI_WAIT_FOR_PLANE_A_FLIP;
  7783. intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask);
  7784. intel_ring_emit(ring, MI_NOOP);
  7785. intel_ring_emit(ring, MI_DISPLAY_FLIP |
  7786. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  7787. intel_ring_emit(ring, fb->pitches[0]);
  7788. intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset);
  7789. intel_ring_emit(ring, 0); /* aux display base address, unused */
  7790. intel_mark_page_flip_active(intel_crtc);
  7791. __intel_ring_advance(ring);
  7792. return 0;
  7793. }
  7794. static int intel_gen3_queue_flip(struct drm_device *dev,
  7795. struct drm_crtc *crtc,
  7796. struct drm_framebuffer *fb,
  7797. struct drm_i915_gem_object *obj,
  7798. struct intel_engine_cs *ring,
  7799. uint32_t flags)
  7800. {
  7801. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7802. u32 flip_mask;
  7803. int ret;
  7804. ret = intel_ring_begin(ring, 6);
  7805. if (ret)
  7806. return ret;
  7807. if (intel_crtc->plane)
  7808. flip_mask = MI_WAIT_FOR_PLANE_B_FLIP;
  7809. else
  7810. flip_mask = MI_WAIT_FOR_PLANE_A_FLIP;
  7811. intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask);
  7812. intel_ring_emit(ring, MI_NOOP);
  7813. intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 |
  7814. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  7815. intel_ring_emit(ring, fb->pitches[0]);
  7816. intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset);
  7817. intel_ring_emit(ring, MI_NOOP);
  7818. intel_mark_page_flip_active(intel_crtc);
  7819. __intel_ring_advance(ring);
  7820. return 0;
  7821. }
  7822. static int intel_gen4_queue_flip(struct drm_device *dev,
  7823. struct drm_crtc *crtc,
  7824. struct drm_framebuffer *fb,
  7825. struct drm_i915_gem_object *obj,
  7826. struct intel_engine_cs *ring,
  7827. uint32_t flags)
  7828. {
  7829. struct drm_i915_private *dev_priv = dev->dev_private;
  7830. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7831. uint32_t pf, pipesrc;
  7832. int ret;
  7833. ret = intel_ring_begin(ring, 4);
  7834. if (ret)
  7835. return ret;
  7836. /* i965+ uses the linear or tiled offsets from the
  7837. * Display Registers (which do not change across a page-flip)
  7838. * so we need only reprogram the base address.
  7839. */
  7840. intel_ring_emit(ring, MI_DISPLAY_FLIP |
  7841. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  7842. intel_ring_emit(ring, fb->pitches[0]);
  7843. intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset |
  7844. obj->tiling_mode);
  7845. /* XXX Enabling the panel-fitter across page-flip is so far
  7846. * untested on non-native modes, so ignore it for now.
  7847. * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE;
  7848. */
  7849. pf = 0;
  7850. pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
  7851. intel_ring_emit(ring, pf | pipesrc);
  7852. intel_mark_page_flip_active(intel_crtc);
  7853. __intel_ring_advance(ring);
  7854. return 0;
  7855. }
  7856. static int intel_gen6_queue_flip(struct drm_device *dev,
  7857. struct drm_crtc *crtc,
  7858. struct drm_framebuffer *fb,
  7859. struct drm_i915_gem_object *obj,
  7860. struct intel_engine_cs *ring,
  7861. uint32_t flags)
  7862. {
  7863. struct drm_i915_private *dev_priv = dev->dev_private;
  7864. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7865. uint32_t pf, pipesrc;
  7866. int ret;
  7867. ret = intel_ring_begin(ring, 4);
  7868. if (ret)
  7869. return ret;
  7870. intel_ring_emit(ring, MI_DISPLAY_FLIP |
  7871. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  7872. intel_ring_emit(ring, fb->pitches[0] | obj->tiling_mode);
  7873. intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset);
  7874. /* Contrary to the suggestions in the documentation,
  7875. * "Enable Panel Fitter" does not seem to be required when page
  7876. * flipping with a non-native mode, and worse causes a normal
  7877. * modeset to fail.
  7878. * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE;
  7879. */
  7880. pf = 0;
  7881. pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
  7882. intel_ring_emit(ring, pf | pipesrc);
  7883. intel_mark_page_flip_active(intel_crtc);
  7884. __intel_ring_advance(ring);
  7885. return 0;
  7886. }
  7887. static int intel_gen7_queue_flip(struct drm_device *dev,
  7888. struct drm_crtc *crtc,
  7889. struct drm_framebuffer *fb,
  7890. struct drm_i915_gem_object *obj,
  7891. struct intel_engine_cs *ring,
  7892. uint32_t flags)
  7893. {
  7894. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7895. uint32_t plane_bit = 0;
  7896. int len, ret;
  7897. switch (intel_crtc->plane) {
  7898. case PLANE_A:
  7899. plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_A;
  7900. break;
  7901. case PLANE_B:
  7902. plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_B;
  7903. break;
  7904. case PLANE_C:
  7905. plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_C;
  7906. break;
  7907. default:
  7908. WARN_ONCE(1, "unknown plane in flip command\n");
  7909. return -ENODEV;
  7910. }
  7911. len = 4;
  7912. if (ring->id == RCS) {
  7913. len += 6;
  7914. /*
  7915. * On Gen 8, SRM is now taking an extra dword to accommodate
  7916. * 48bits addresses, and we need a NOOP for the batch size to
  7917. * stay even.
  7918. */
  7919. if (IS_GEN8(dev))
  7920. len += 2;
  7921. }
  7922. /*
  7923. * BSpec MI_DISPLAY_FLIP for IVB:
  7924. * "The full packet must be contained within the same cache line."
  7925. *
  7926. * Currently the LRI+SRM+MI_DISPLAY_FLIP all fit within the same
  7927. * cacheline, if we ever start emitting more commands before
  7928. * the MI_DISPLAY_FLIP we may need to first emit everything else,
  7929. * then do the cacheline alignment, and finally emit the
  7930. * MI_DISPLAY_FLIP.
  7931. */
  7932. ret = intel_ring_cacheline_align(ring);
  7933. if (ret)
  7934. return ret;
  7935. ret = intel_ring_begin(ring, len);
  7936. if (ret)
  7937. return ret;
  7938. /* Unmask the flip-done completion message. Note that the bspec says that
  7939. * we should do this for both the BCS and RCS, and that we must not unmask
  7940. * more than one flip event at any time (or ensure that one flip message
  7941. * can be sent by waiting for flip-done prior to queueing new flips).
  7942. * Experimentation says that BCS works despite DERRMR masking all
  7943. * flip-done completion events and that unmasking all planes at once
  7944. * for the RCS also doesn't appear to drop events. Setting the DERRMR
  7945. * to zero does lead to lockups within MI_DISPLAY_FLIP.
  7946. */
  7947. if (ring->id == RCS) {
  7948. intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1));
  7949. intel_ring_emit(ring, DERRMR);
  7950. intel_ring_emit(ring, ~(DERRMR_PIPEA_PRI_FLIP_DONE |
  7951. DERRMR_PIPEB_PRI_FLIP_DONE |
  7952. DERRMR_PIPEC_PRI_FLIP_DONE));
  7953. if (IS_GEN8(dev))
  7954. intel_ring_emit(ring, MI_STORE_REGISTER_MEM_GEN8(1) |
  7955. MI_SRM_LRM_GLOBAL_GTT);
  7956. else
  7957. intel_ring_emit(ring, MI_STORE_REGISTER_MEM(1) |
  7958. MI_SRM_LRM_GLOBAL_GTT);
  7959. intel_ring_emit(ring, DERRMR);
  7960. intel_ring_emit(ring, ring->scratch.gtt_offset + 256);
  7961. if (IS_GEN8(dev)) {
  7962. intel_ring_emit(ring, 0);
  7963. intel_ring_emit(ring, MI_NOOP);
  7964. }
  7965. }
  7966. intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | plane_bit);
  7967. intel_ring_emit(ring, (fb->pitches[0] | obj->tiling_mode));
  7968. intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset);
  7969. intel_ring_emit(ring, (MI_NOOP));
  7970. intel_mark_page_flip_active(intel_crtc);
  7971. __intel_ring_advance(ring);
  7972. return 0;
  7973. }
  7974. static bool use_mmio_flip(struct intel_engine_cs *ring,
  7975. struct drm_i915_gem_object *obj)
  7976. {
  7977. /*
  7978. * This is not being used for older platforms, because
  7979. * non-availability of flip done interrupt forces us to use
  7980. * CS flips. Older platforms derive flip done using some clever
  7981. * tricks involving the flip_pending status bits and vblank irqs.
  7982. * So using MMIO flips there would disrupt this mechanism.
  7983. */
  7984. if (ring == NULL)
  7985. return true;
  7986. if (INTEL_INFO(ring->dev)->gen < 5)
  7987. return false;
  7988. if (i915.use_mmio_flip < 0)
  7989. return false;
  7990. else if (i915.use_mmio_flip > 0)
  7991. return true;
  7992. else if (i915.enable_execlists)
  7993. return true;
  7994. else
  7995. return ring != obj->ring;
  7996. }
  7997. static void intel_do_mmio_flip(struct intel_crtc *intel_crtc)
  7998. {
  7999. struct drm_device *dev = intel_crtc->base.dev;
  8000. struct drm_i915_private *dev_priv = dev->dev_private;
  8001. struct intel_framebuffer *intel_fb =
  8002. to_intel_framebuffer(intel_crtc->base.primary->fb);
  8003. struct drm_i915_gem_object *obj = intel_fb->obj;
  8004. u32 dspcntr;
  8005. u32 reg;
  8006. intel_mark_page_flip_active(intel_crtc);
  8007. reg = DSPCNTR(intel_crtc->plane);
  8008. dspcntr = I915_READ(reg);
  8009. if (INTEL_INFO(dev)->gen >= 4) {
  8010. if (obj->tiling_mode != I915_TILING_NONE)
  8011. dspcntr |= DISPPLANE_TILED;
  8012. else
  8013. dspcntr &= ~DISPPLANE_TILED;
  8014. }
  8015. I915_WRITE(reg, dspcntr);
  8016. I915_WRITE(DSPSURF(intel_crtc->plane),
  8017. intel_crtc->unpin_work->gtt_offset);
  8018. POSTING_READ(DSPSURF(intel_crtc->plane));
  8019. }
  8020. static int intel_postpone_flip(struct drm_i915_gem_object *obj)
  8021. {
  8022. struct intel_engine_cs *ring;
  8023. int ret;
  8024. lockdep_assert_held(&obj->base.dev->struct_mutex);
  8025. if (!obj->last_write_seqno)
  8026. return 0;
  8027. ring = obj->ring;
  8028. if (i915_seqno_passed(ring->get_seqno(ring, true),
  8029. obj->last_write_seqno))
  8030. return 0;
  8031. ret = i915_gem_check_olr(ring, obj->last_write_seqno);
  8032. if (ret)
  8033. return ret;
  8034. if (WARN_ON(!ring->irq_get(ring)))
  8035. return 0;
  8036. return 1;
  8037. }
  8038. void intel_notify_mmio_flip(struct intel_engine_cs *ring)
  8039. {
  8040. struct drm_i915_private *dev_priv = to_i915(ring->dev);
  8041. struct intel_crtc *intel_crtc;
  8042. unsigned long irq_flags;
  8043. u32 seqno;
  8044. seqno = ring->get_seqno(ring, false);
  8045. spin_lock_irqsave(&dev_priv->mmio_flip_lock, irq_flags);
  8046. for_each_intel_crtc(ring->dev, intel_crtc) {
  8047. struct intel_mmio_flip *mmio_flip;
  8048. mmio_flip = &intel_crtc->mmio_flip;
  8049. if (mmio_flip->seqno == 0)
  8050. continue;
  8051. if (ring->id != mmio_flip->ring_id)
  8052. continue;
  8053. if (i915_seqno_passed(seqno, mmio_flip->seqno)) {
  8054. intel_do_mmio_flip(intel_crtc);
  8055. mmio_flip->seqno = 0;
  8056. ring->irq_put(ring);
  8057. }
  8058. }
  8059. spin_unlock_irqrestore(&dev_priv->mmio_flip_lock, irq_flags);
  8060. }
  8061. static int intel_queue_mmio_flip(struct drm_device *dev,
  8062. struct drm_crtc *crtc,
  8063. struct drm_framebuffer *fb,
  8064. struct drm_i915_gem_object *obj,
  8065. struct intel_engine_cs *ring,
  8066. uint32_t flags)
  8067. {
  8068. struct drm_i915_private *dev_priv = dev->dev_private;
  8069. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  8070. int ret;
  8071. if (WARN_ON(intel_crtc->mmio_flip.seqno))
  8072. return -EBUSY;
  8073. ret = intel_postpone_flip(obj);
  8074. if (ret < 0)
  8075. return ret;
  8076. if (ret == 0) {
  8077. intel_do_mmio_flip(intel_crtc);
  8078. return 0;
  8079. }
  8080. spin_lock_irq(&dev_priv->mmio_flip_lock);
  8081. intel_crtc->mmio_flip.seqno = obj->last_write_seqno;
  8082. intel_crtc->mmio_flip.ring_id = obj->ring->id;
  8083. spin_unlock_irq(&dev_priv->mmio_flip_lock);
  8084. /*
  8085. * Double check to catch cases where irq fired before
  8086. * mmio flip data was ready
  8087. */
  8088. intel_notify_mmio_flip(obj->ring);
  8089. return 0;
  8090. }
  8091. static int intel_default_queue_flip(struct drm_device *dev,
  8092. struct drm_crtc *crtc,
  8093. struct drm_framebuffer *fb,
  8094. struct drm_i915_gem_object *obj,
  8095. struct intel_engine_cs *ring,
  8096. uint32_t flags)
  8097. {
  8098. return -ENODEV;
  8099. }
  8100. static bool __intel_pageflip_stall_check(struct drm_device *dev,
  8101. struct drm_crtc *crtc)
  8102. {
  8103. struct drm_i915_private *dev_priv = dev->dev_private;
  8104. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  8105. struct intel_unpin_work *work = intel_crtc->unpin_work;
  8106. u32 addr;
  8107. if (atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE)
  8108. return true;
  8109. if (!work->enable_stall_check)
  8110. return false;
  8111. if (work->flip_ready_vblank == 0) {
  8112. if (work->flip_queued_ring &&
  8113. !i915_seqno_passed(work->flip_queued_ring->get_seqno(work->flip_queued_ring, true),
  8114. work->flip_queued_seqno))
  8115. return false;
  8116. work->flip_ready_vblank = drm_vblank_count(dev, intel_crtc->pipe);
  8117. }
  8118. if (drm_vblank_count(dev, intel_crtc->pipe) - work->flip_ready_vblank < 3)
  8119. return false;
  8120. /* Potential stall - if we see that the flip has happened,
  8121. * assume a missed interrupt. */
  8122. if (INTEL_INFO(dev)->gen >= 4)
  8123. addr = I915_HI_DISPBASE(I915_READ(DSPSURF(intel_crtc->plane)));
  8124. else
  8125. addr = I915_READ(DSPADDR(intel_crtc->plane));
  8126. /* There is a potential issue here with a false positive after a flip
  8127. * to the same address. We could address this by checking for a
  8128. * non-incrementing frame counter.
  8129. */
  8130. return addr == work->gtt_offset;
  8131. }
  8132. void intel_check_page_flip(struct drm_device *dev, int pipe)
  8133. {
  8134. struct drm_i915_private *dev_priv = dev->dev_private;
  8135. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  8136. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  8137. WARN_ON(!in_irq());
  8138. if (crtc == NULL)
  8139. return;
  8140. spin_lock(&dev->event_lock);
  8141. if (intel_crtc->unpin_work && __intel_pageflip_stall_check(dev, crtc)) {
  8142. WARN_ONCE(1, "Kicking stuck page flip: queued at %d, now %d\n",
  8143. intel_crtc->unpin_work->flip_queued_vblank, drm_vblank_count(dev, pipe));
  8144. page_flip_completed(intel_crtc);
  8145. }
  8146. spin_unlock(&dev->event_lock);
  8147. }
  8148. static int intel_crtc_page_flip(struct drm_crtc *crtc,
  8149. struct drm_framebuffer *fb,
  8150. struct drm_pending_vblank_event *event,
  8151. uint32_t page_flip_flags)
  8152. {
  8153. struct drm_device *dev = crtc->dev;
  8154. struct drm_i915_private *dev_priv = dev->dev_private;
  8155. struct drm_framebuffer *old_fb = crtc->primary->fb;
  8156. struct drm_i915_gem_object *obj = intel_fb_obj(fb);
  8157. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  8158. enum pipe pipe = intel_crtc->pipe;
  8159. struct intel_unpin_work *work;
  8160. struct intel_engine_cs *ring;
  8161. int ret;
  8162. /*
  8163. * drm_mode_page_flip_ioctl() should already catch this, but double
  8164. * check to be safe. In the future we may enable pageflipping from
  8165. * a disabled primary plane.
  8166. */
  8167. if (WARN_ON(intel_fb_obj(old_fb) == NULL))
  8168. return -EBUSY;
  8169. /* Can't change pixel format via MI display flips. */
  8170. if (fb->pixel_format != crtc->primary->fb->pixel_format)
  8171. return -EINVAL;
  8172. /*
  8173. * TILEOFF/LINOFF registers can't be changed via MI display flips.
  8174. * Note that pitch changes could also affect these register.
  8175. */
  8176. if (INTEL_INFO(dev)->gen > 3 &&
  8177. (fb->offsets[0] != crtc->primary->fb->offsets[0] ||
  8178. fb->pitches[0] != crtc->primary->fb->pitches[0]))
  8179. return -EINVAL;
  8180. if (i915_terminally_wedged(&dev_priv->gpu_error))
  8181. goto out_hang;
  8182. work = kzalloc(sizeof(*work), GFP_KERNEL);
  8183. if (work == NULL)
  8184. return -ENOMEM;
  8185. work->event = event;
  8186. work->crtc = crtc;
  8187. work->old_fb_obj = intel_fb_obj(old_fb);
  8188. INIT_WORK(&work->work, intel_unpin_work_fn);
  8189. ret = drm_crtc_vblank_get(crtc);
  8190. if (ret)
  8191. goto free_work;
  8192. /* We borrow the event spin lock for protecting unpin_work */
  8193. spin_lock_irq(&dev->event_lock);
  8194. if (intel_crtc->unpin_work) {
  8195. /* Before declaring the flip queue wedged, check if
  8196. * the hardware completed the operation behind our backs.
  8197. */
  8198. if (__intel_pageflip_stall_check(dev, crtc)) {
  8199. DRM_DEBUG_DRIVER("flip queue: previous flip completed, continuing\n");
  8200. page_flip_completed(intel_crtc);
  8201. } else {
  8202. DRM_DEBUG_DRIVER("flip queue: crtc already busy\n");
  8203. spin_unlock_irq(&dev->event_lock);
  8204. drm_crtc_vblank_put(crtc);
  8205. kfree(work);
  8206. return -EBUSY;
  8207. }
  8208. }
  8209. intel_crtc->unpin_work = work;
  8210. spin_unlock_irq(&dev->event_lock);
  8211. if (atomic_read(&intel_crtc->unpin_work_count) >= 2)
  8212. flush_workqueue(dev_priv->wq);
  8213. ret = i915_mutex_lock_interruptible(dev);
  8214. if (ret)
  8215. goto cleanup;
  8216. /* Reference the objects for the scheduled work. */
  8217. drm_gem_object_reference(&work->old_fb_obj->base);
  8218. drm_gem_object_reference(&obj->base);
  8219. crtc->primary->fb = fb;
  8220. work->pending_flip_obj = obj;
  8221. atomic_inc(&intel_crtc->unpin_work_count);
  8222. intel_crtc->reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter);
  8223. if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev))
  8224. work->flip_count = I915_READ(PIPE_FLIPCOUNT_GM45(pipe)) + 1;
  8225. if (IS_VALLEYVIEW(dev)) {
  8226. ring = &dev_priv->ring[BCS];
  8227. if (obj->tiling_mode != work->old_fb_obj->tiling_mode)
  8228. /* vlv: DISPLAY_FLIP fails to change tiling */
  8229. ring = NULL;
  8230. } else if (IS_IVYBRIDGE(dev)) {
  8231. ring = &dev_priv->ring[BCS];
  8232. } else if (INTEL_INFO(dev)->gen >= 7) {
  8233. ring = obj->ring;
  8234. if (ring == NULL || ring->id != RCS)
  8235. ring = &dev_priv->ring[BCS];
  8236. } else {
  8237. ring = &dev_priv->ring[RCS];
  8238. }
  8239. ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
  8240. if (ret)
  8241. goto cleanup_pending;
  8242. work->gtt_offset =
  8243. i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset;
  8244. if (use_mmio_flip(ring, obj)) {
  8245. ret = intel_queue_mmio_flip(dev, crtc, fb, obj, ring,
  8246. page_flip_flags);
  8247. if (ret)
  8248. goto cleanup_unpin;
  8249. work->flip_queued_seqno = obj->last_write_seqno;
  8250. work->flip_queued_ring = obj->ring;
  8251. } else {
  8252. ret = dev_priv->display.queue_flip(dev, crtc, fb, obj, ring,
  8253. page_flip_flags);
  8254. if (ret)
  8255. goto cleanup_unpin;
  8256. work->flip_queued_seqno = intel_ring_get_seqno(ring);
  8257. work->flip_queued_ring = ring;
  8258. }
  8259. work->flip_queued_vblank = drm_vblank_count(dev, intel_crtc->pipe);
  8260. work->enable_stall_check = true;
  8261. i915_gem_track_fb(work->old_fb_obj, obj,
  8262. INTEL_FRONTBUFFER_PRIMARY(pipe));
  8263. intel_disable_fbc(dev);
  8264. intel_frontbuffer_flip_prepare(dev, INTEL_FRONTBUFFER_PRIMARY(pipe));
  8265. mutex_unlock(&dev->struct_mutex);
  8266. trace_i915_flip_request(intel_crtc->plane, obj);
  8267. return 0;
  8268. cleanup_unpin:
  8269. intel_unpin_fb_obj(obj);
  8270. cleanup_pending:
  8271. atomic_dec(&intel_crtc->unpin_work_count);
  8272. crtc->primary->fb = old_fb;
  8273. drm_gem_object_unreference(&work->old_fb_obj->base);
  8274. drm_gem_object_unreference(&obj->base);
  8275. mutex_unlock(&dev->struct_mutex);
  8276. cleanup:
  8277. spin_lock_irq(&dev->event_lock);
  8278. intel_crtc->unpin_work = NULL;
  8279. spin_unlock_irq(&dev->event_lock);
  8280. drm_crtc_vblank_put(crtc);
  8281. free_work:
  8282. kfree(work);
  8283. if (ret == -EIO) {
  8284. out_hang:
  8285. intel_crtc_wait_for_pending_flips(crtc);
  8286. ret = intel_pipe_set_base(crtc, crtc->x, crtc->y, fb);
  8287. if (ret == 0 && event) {
  8288. spin_lock_irq(&dev->event_lock);
  8289. drm_send_vblank_event(dev, pipe, event);
  8290. spin_unlock_irq(&dev->event_lock);
  8291. }
  8292. }
  8293. return ret;
  8294. }
  8295. static struct drm_crtc_helper_funcs intel_helper_funcs = {
  8296. .mode_set_base_atomic = intel_pipe_set_base_atomic,
  8297. .load_lut = intel_crtc_load_lut,
  8298. };
  8299. /**
  8300. * intel_modeset_update_staged_output_state
  8301. *
  8302. * Updates the staged output configuration state, e.g. after we've read out the
  8303. * current hw state.
  8304. */
  8305. static void intel_modeset_update_staged_output_state(struct drm_device *dev)
  8306. {
  8307. struct intel_crtc *crtc;
  8308. struct intel_encoder *encoder;
  8309. struct intel_connector *connector;
  8310. list_for_each_entry(connector, &dev->mode_config.connector_list,
  8311. base.head) {
  8312. connector->new_encoder =
  8313. to_intel_encoder(connector->base.encoder);
  8314. }
  8315. for_each_intel_encoder(dev, encoder) {
  8316. encoder->new_crtc =
  8317. to_intel_crtc(encoder->base.crtc);
  8318. }
  8319. for_each_intel_crtc(dev, crtc) {
  8320. crtc->new_enabled = crtc->base.enabled;
  8321. if (crtc->new_enabled)
  8322. crtc->new_config = &crtc->config;
  8323. else
  8324. crtc->new_config = NULL;
  8325. }
  8326. }
  8327. /**
  8328. * intel_modeset_commit_output_state
  8329. *
  8330. * This function copies the stage display pipe configuration to the real one.
  8331. */
  8332. static void intel_modeset_commit_output_state(struct drm_device *dev)
  8333. {
  8334. struct intel_crtc *crtc;
  8335. struct intel_encoder *encoder;
  8336. struct intel_connector *connector;
  8337. list_for_each_entry(connector, &dev->mode_config.connector_list,
  8338. base.head) {
  8339. connector->base.encoder = &connector->new_encoder->base;
  8340. }
  8341. for_each_intel_encoder(dev, encoder) {
  8342. encoder->base.crtc = &encoder->new_crtc->base;
  8343. }
  8344. for_each_intel_crtc(dev, crtc) {
  8345. crtc->base.enabled = crtc->new_enabled;
  8346. }
  8347. }
  8348. static void
  8349. connected_sink_compute_bpp(struct intel_connector *connector,
  8350. struct intel_crtc_config *pipe_config)
  8351. {
  8352. int bpp = pipe_config->pipe_bpp;
  8353. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n",
  8354. connector->base.base.id,
  8355. connector->base.name);
  8356. /* Don't use an invalid EDID bpc value */
  8357. if (connector->base.display_info.bpc &&
  8358. connector->base.display_info.bpc * 3 < bpp) {
  8359. DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n",
  8360. bpp, connector->base.display_info.bpc*3);
  8361. pipe_config->pipe_bpp = connector->base.display_info.bpc*3;
  8362. }
  8363. /* Clamp bpp to 8 on screens without EDID 1.4 */
  8364. if (connector->base.display_info.bpc == 0 && bpp > 24) {
  8365. DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n",
  8366. bpp);
  8367. pipe_config->pipe_bpp = 24;
  8368. }
  8369. }
  8370. static int
  8371. compute_baseline_pipe_bpp(struct intel_crtc *crtc,
  8372. struct drm_framebuffer *fb,
  8373. struct intel_crtc_config *pipe_config)
  8374. {
  8375. struct drm_device *dev = crtc->base.dev;
  8376. struct intel_connector *connector;
  8377. int bpp;
  8378. switch (fb->pixel_format) {
  8379. case DRM_FORMAT_C8:
  8380. bpp = 8*3; /* since we go through a colormap */
  8381. break;
  8382. case DRM_FORMAT_XRGB1555:
  8383. case DRM_FORMAT_ARGB1555:
  8384. /* checked in intel_framebuffer_init already */
  8385. if (WARN_ON(INTEL_INFO(dev)->gen > 3))
  8386. return -EINVAL;
  8387. case DRM_FORMAT_RGB565:
  8388. bpp = 6*3; /* min is 18bpp */
  8389. break;
  8390. case DRM_FORMAT_XBGR8888:
  8391. case DRM_FORMAT_ABGR8888:
  8392. /* checked in intel_framebuffer_init already */
  8393. if (WARN_ON(INTEL_INFO(dev)->gen < 4))
  8394. return -EINVAL;
  8395. case DRM_FORMAT_XRGB8888:
  8396. case DRM_FORMAT_ARGB8888:
  8397. bpp = 8*3;
  8398. break;
  8399. case DRM_FORMAT_XRGB2101010:
  8400. case DRM_FORMAT_ARGB2101010:
  8401. case DRM_FORMAT_XBGR2101010:
  8402. case DRM_FORMAT_ABGR2101010:
  8403. /* checked in intel_framebuffer_init already */
  8404. if (WARN_ON(INTEL_INFO(dev)->gen < 4))
  8405. return -EINVAL;
  8406. bpp = 10*3;
  8407. break;
  8408. /* TODO: gen4+ supports 16 bpc floating point, too. */
  8409. default:
  8410. DRM_DEBUG_KMS("unsupported depth\n");
  8411. return -EINVAL;
  8412. }
  8413. pipe_config->pipe_bpp = bpp;
  8414. /* Clamp display bpp to EDID value */
  8415. list_for_each_entry(connector, &dev->mode_config.connector_list,
  8416. base.head) {
  8417. if (!connector->new_encoder ||
  8418. connector->new_encoder->new_crtc != crtc)
  8419. continue;
  8420. connected_sink_compute_bpp(connector, pipe_config);
  8421. }
  8422. return bpp;
  8423. }
  8424. static void intel_dump_crtc_timings(const struct drm_display_mode *mode)
  8425. {
  8426. DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
  8427. "type: 0x%x flags: 0x%x\n",
  8428. mode->crtc_clock,
  8429. mode->crtc_hdisplay, mode->crtc_hsync_start,
  8430. mode->crtc_hsync_end, mode->crtc_htotal,
  8431. mode->crtc_vdisplay, mode->crtc_vsync_start,
  8432. mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags);
  8433. }
  8434. static void intel_dump_pipe_config(struct intel_crtc *crtc,
  8435. struct intel_crtc_config *pipe_config,
  8436. const char *context)
  8437. {
  8438. DRM_DEBUG_KMS("[CRTC:%d]%s config for pipe %c\n", crtc->base.base.id,
  8439. context, pipe_name(crtc->pipe));
  8440. DRM_DEBUG_KMS("cpu_transcoder: %c\n", transcoder_name(pipe_config->cpu_transcoder));
  8441. DRM_DEBUG_KMS("pipe bpp: %i, dithering: %i\n",
  8442. pipe_config->pipe_bpp, pipe_config->dither);
  8443. DRM_DEBUG_KMS("fdi/pch: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
  8444. pipe_config->has_pch_encoder,
  8445. pipe_config->fdi_lanes,
  8446. pipe_config->fdi_m_n.gmch_m, pipe_config->fdi_m_n.gmch_n,
  8447. pipe_config->fdi_m_n.link_m, pipe_config->fdi_m_n.link_n,
  8448. pipe_config->fdi_m_n.tu);
  8449. DRM_DEBUG_KMS("dp: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
  8450. pipe_config->has_dp_encoder,
  8451. pipe_config->dp_m_n.gmch_m, pipe_config->dp_m_n.gmch_n,
  8452. pipe_config->dp_m_n.link_m, pipe_config->dp_m_n.link_n,
  8453. pipe_config->dp_m_n.tu);
  8454. DRM_DEBUG_KMS("dp: %i, gmch_m2: %u, gmch_n2: %u, link_m2: %u, link_n2: %u, tu2: %u\n",
  8455. pipe_config->has_dp_encoder,
  8456. pipe_config->dp_m2_n2.gmch_m,
  8457. pipe_config->dp_m2_n2.gmch_n,
  8458. pipe_config->dp_m2_n2.link_m,
  8459. pipe_config->dp_m2_n2.link_n,
  8460. pipe_config->dp_m2_n2.tu);
  8461. DRM_DEBUG_KMS("requested mode:\n");
  8462. drm_mode_debug_printmodeline(&pipe_config->requested_mode);
  8463. DRM_DEBUG_KMS("adjusted mode:\n");
  8464. drm_mode_debug_printmodeline(&pipe_config->adjusted_mode);
  8465. intel_dump_crtc_timings(&pipe_config->adjusted_mode);
  8466. DRM_DEBUG_KMS("port clock: %d\n", pipe_config->port_clock);
  8467. DRM_DEBUG_KMS("pipe src size: %dx%d\n",
  8468. pipe_config->pipe_src_w, pipe_config->pipe_src_h);
  8469. DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
  8470. pipe_config->gmch_pfit.control,
  8471. pipe_config->gmch_pfit.pgm_ratios,
  8472. pipe_config->gmch_pfit.lvds_border_bits);
  8473. DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n",
  8474. pipe_config->pch_pfit.pos,
  8475. pipe_config->pch_pfit.size,
  8476. pipe_config->pch_pfit.enabled ? "enabled" : "disabled");
  8477. DRM_DEBUG_KMS("ips: %i\n", pipe_config->ips_enabled);
  8478. DRM_DEBUG_KMS("double wide: %i\n", pipe_config->double_wide);
  8479. }
  8480. static bool encoders_cloneable(const struct intel_encoder *a,
  8481. const struct intel_encoder *b)
  8482. {
  8483. /* masks could be asymmetric, so check both ways */
  8484. return a == b || (a->cloneable & (1 << b->type) &&
  8485. b->cloneable & (1 << a->type));
  8486. }
  8487. static bool check_single_encoder_cloning(struct intel_crtc *crtc,
  8488. struct intel_encoder *encoder)
  8489. {
  8490. struct drm_device *dev = crtc->base.dev;
  8491. struct intel_encoder *source_encoder;
  8492. for_each_intel_encoder(dev, source_encoder) {
  8493. if (source_encoder->new_crtc != crtc)
  8494. continue;
  8495. if (!encoders_cloneable(encoder, source_encoder))
  8496. return false;
  8497. }
  8498. return true;
  8499. }
  8500. static bool check_encoder_cloning(struct intel_crtc *crtc)
  8501. {
  8502. struct drm_device *dev = crtc->base.dev;
  8503. struct intel_encoder *encoder;
  8504. for_each_intel_encoder(dev, encoder) {
  8505. if (encoder->new_crtc != crtc)
  8506. continue;
  8507. if (!check_single_encoder_cloning(crtc, encoder))
  8508. return false;
  8509. }
  8510. return true;
  8511. }
  8512. static struct intel_crtc_config *
  8513. intel_modeset_pipe_config(struct drm_crtc *crtc,
  8514. struct drm_framebuffer *fb,
  8515. struct drm_display_mode *mode)
  8516. {
  8517. struct drm_device *dev = crtc->dev;
  8518. struct intel_encoder *encoder;
  8519. struct intel_crtc_config *pipe_config;
  8520. int plane_bpp, ret = -EINVAL;
  8521. bool retry = true;
  8522. if (!check_encoder_cloning(to_intel_crtc(crtc))) {
  8523. DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
  8524. return ERR_PTR(-EINVAL);
  8525. }
  8526. pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL);
  8527. if (!pipe_config)
  8528. return ERR_PTR(-ENOMEM);
  8529. drm_mode_copy(&pipe_config->adjusted_mode, mode);
  8530. drm_mode_copy(&pipe_config->requested_mode, mode);
  8531. pipe_config->cpu_transcoder =
  8532. (enum transcoder) to_intel_crtc(crtc)->pipe;
  8533. pipe_config->shared_dpll = DPLL_ID_PRIVATE;
  8534. /*
  8535. * Sanitize sync polarity flags based on requested ones. If neither
  8536. * positive or negative polarity is requested, treat this as meaning
  8537. * negative polarity.
  8538. */
  8539. if (!(pipe_config->adjusted_mode.flags &
  8540. (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC)))
  8541. pipe_config->adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC;
  8542. if (!(pipe_config->adjusted_mode.flags &
  8543. (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC)))
  8544. pipe_config->adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC;
  8545. /* Compute a starting value for pipe_config->pipe_bpp taking the source
  8546. * plane pixel format and any sink constraints into account. Returns the
  8547. * source plane bpp so that dithering can be selected on mismatches
  8548. * after encoders and crtc also have had their say. */
  8549. plane_bpp = compute_baseline_pipe_bpp(to_intel_crtc(crtc),
  8550. fb, pipe_config);
  8551. if (plane_bpp < 0)
  8552. goto fail;
  8553. /*
  8554. * Determine the real pipe dimensions. Note that stereo modes can
  8555. * increase the actual pipe size due to the frame doubling and
  8556. * insertion of additional space for blanks between the frame. This
  8557. * is stored in the crtc timings. We use the requested mode to do this
  8558. * computation to clearly distinguish it from the adjusted mode, which
  8559. * can be changed by the connectors in the below retry loop.
  8560. */
  8561. drm_mode_set_crtcinfo(&pipe_config->requested_mode, CRTC_STEREO_DOUBLE);
  8562. pipe_config->pipe_src_w = pipe_config->requested_mode.crtc_hdisplay;
  8563. pipe_config->pipe_src_h = pipe_config->requested_mode.crtc_vdisplay;
  8564. encoder_retry:
  8565. /* Ensure the port clock defaults are reset when retrying. */
  8566. pipe_config->port_clock = 0;
  8567. pipe_config->pixel_multiplier = 1;
  8568. /* Fill in default crtc timings, allow encoders to overwrite them. */
  8569. drm_mode_set_crtcinfo(&pipe_config->adjusted_mode, CRTC_STEREO_DOUBLE);
  8570. /* Pass our mode to the connectors and the CRTC to give them a chance to
  8571. * adjust it according to limitations or connector properties, and also
  8572. * a chance to reject the mode entirely.
  8573. */
  8574. for_each_intel_encoder(dev, encoder) {
  8575. if (&encoder->new_crtc->base != crtc)
  8576. continue;
  8577. if (!(encoder->compute_config(encoder, pipe_config))) {
  8578. DRM_DEBUG_KMS("Encoder config failure\n");
  8579. goto fail;
  8580. }
  8581. }
  8582. /* Set default port clock if not overwritten by the encoder. Needs to be
  8583. * done afterwards in case the encoder adjusts the mode. */
  8584. if (!pipe_config->port_clock)
  8585. pipe_config->port_clock = pipe_config->adjusted_mode.crtc_clock
  8586. * pipe_config->pixel_multiplier;
  8587. ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config);
  8588. if (ret < 0) {
  8589. DRM_DEBUG_KMS("CRTC fixup failed\n");
  8590. goto fail;
  8591. }
  8592. if (ret == RETRY) {
  8593. if (WARN(!retry, "loop in pipe configuration computation\n")) {
  8594. ret = -EINVAL;
  8595. goto fail;
  8596. }
  8597. DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
  8598. retry = false;
  8599. goto encoder_retry;
  8600. }
  8601. pipe_config->dither = pipe_config->pipe_bpp != plane_bpp;
  8602. DRM_DEBUG_KMS("plane bpp: %i, pipe bpp: %i, dithering: %i\n",
  8603. plane_bpp, pipe_config->pipe_bpp, pipe_config->dither);
  8604. return pipe_config;
  8605. fail:
  8606. kfree(pipe_config);
  8607. return ERR_PTR(ret);
  8608. }
  8609. /* Computes which crtcs are affected and sets the relevant bits in the mask. For
  8610. * simplicity we use the crtc's pipe number (because it's easier to obtain). */
  8611. static void
  8612. intel_modeset_affected_pipes(struct drm_crtc *crtc, unsigned *modeset_pipes,
  8613. unsigned *prepare_pipes, unsigned *disable_pipes)
  8614. {
  8615. struct intel_crtc *intel_crtc;
  8616. struct drm_device *dev = crtc->dev;
  8617. struct intel_encoder *encoder;
  8618. struct intel_connector *connector;
  8619. struct drm_crtc *tmp_crtc;
  8620. *disable_pipes = *modeset_pipes = *prepare_pipes = 0;
  8621. /* Check which crtcs have changed outputs connected to them, these need
  8622. * to be part of the prepare_pipes mask. We don't (yet) support global
  8623. * modeset across multiple crtcs, so modeset_pipes will only have one
  8624. * bit set at most. */
  8625. list_for_each_entry(connector, &dev->mode_config.connector_list,
  8626. base.head) {
  8627. if (connector->base.encoder == &connector->new_encoder->base)
  8628. continue;
  8629. if (connector->base.encoder) {
  8630. tmp_crtc = connector->base.encoder->crtc;
  8631. *prepare_pipes |= 1 << to_intel_crtc(tmp_crtc)->pipe;
  8632. }
  8633. if (connector->new_encoder)
  8634. *prepare_pipes |=
  8635. 1 << connector->new_encoder->new_crtc->pipe;
  8636. }
  8637. for_each_intel_encoder(dev, encoder) {
  8638. if (encoder->base.crtc == &encoder->new_crtc->base)
  8639. continue;
  8640. if (encoder->base.crtc) {
  8641. tmp_crtc = encoder->base.crtc;
  8642. *prepare_pipes |= 1 << to_intel_crtc(tmp_crtc)->pipe;
  8643. }
  8644. if (encoder->new_crtc)
  8645. *prepare_pipes |= 1 << encoder->new_crtc->pipe;
  8646. }
  8647. /* Check for pipes that will be enabled/disabled ... */
  8648. for_each_intel_crtc(dev, intel_crtc) {
  8649. if (intel_crtc->base.enabled == intel_crtc->new_enabled)
  8650. continue;
  8651. if (!intel_crtc->new_enabled)
  8652. *disable_pipes |= 1 << intel_crtc->pipe;
  8653. else
  8654. *prepare_pipes |= 1 << intel_crtc->pipe;
  8655. }
  8656. /* set_mode is also used to update properties on life display pipes. */
  8657. intel_crtc = to_intel_crtc(crtc);
  8658. if (intel_crtc->new_enabled)
  8659. *prepare_pipes |= 1 << intel_crtc->pipe;
  8660. /*
  8661. * For simplicity do a full modeset on any pipe where the output routing
  8662. * changed. We could be more clever, but that would require us to be
  8663. * more careful with calling the relevant encoder->mode_set functions.
  8664. */
  8665. if (*prepare_pipes)
  8666. *modeset_pipes = *prepare_pipes;
  8667. /* ... and mask these out. */
  8668. *modeset_pipes &= ~(*disable_pipes);
  8669. *prepare_pipes &= ~(*disable_pipes);
  8670. /*
  8671. * HACK: We don't (yet) fully support global modesets. intel_set_config
  8672. * obies this rule, but the modeset restore mode of
  8673. * intel_modeset_setup_hw_state does not.
  8674. */
  8675. *modeset_pipes &= 1 << intel_crtc->pipe;
  8676. *prepare_pipes &= 1 << intel_crtc->pipe;
  8677. DRM_DEBUG_KMS("set mode pipe masks: modeset: %x, prepare: %x, disable: %x\n",
  8678. *modeset_pipes, *prepare_pipes, *disable_pipes);
  8679. }
  8680. static bool intel_crtc_in_use(struct drm_crtc *crtc)
  8681. {
  8682. struct drm_encoder *encoder;
  8683. struct drm_device *dev = crtc->dev;
  8684. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head)
  8685. if (encoder->crtc == crtc)
  8686. return true;
  8687. return false;
  8688. }
  8689. static void
  8690. intel_modeset_update_state(struct drm_device *dev, unsigned prepare_pipes)
  8691. {
  8692. struct intel_encoder *intel_encoder;
  8693. struct intel_crtc *intel_crtc;
  8694. struct drm_connector *connector;
  8695. for_each_intel_encoder(dev, intel_encoder) {
  8696. if (!intel_encoder->base.crtc)
  8697. continue;
  8698. intel_crtc = to_intel_crtc(intel_encoder->base.crtc);
  8699. if (prepare_pipes & (1 << intel_crtc->pipe))
  8700. intel_encoder->connectors_active = false;
  8701. }
  8702. intel_modeset_commit_output_state(dev);
  8703. /* Double check state. */
  8704. for_each_intel_crtc(dev, intel_crtc) {
  8705. WARN_ON(intel_crtc->base.enabled != intel_crtc_in_use(&intel_crtc->base));
  8706. WARN_ON(intel_crtc->new_config &&
  8707. intel_crtc->new_config != &intel_crtc->config);
  8708. WARN_ON(intel_crtc->base.enabled != !!intel_crtc->new_config);
  8709. }
  8710. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  8711. if (!connector->encoder || !connector->encoder->crtc)
  8712. continue;
  8713. intel_crtc = to_intel_crtc(connector->encoder->crtc);
  8714. if (prepare_pipes & (1 << intel_crtc->pipe)) {
  8715. struct drm_property *dpms_property =
  8716. dev->mode_config.dpms_property;
  8717. connector->dpms = DRM_MODE_DPMS_ON;
  8718. drm_object_property_set_value(&connector->base,
  8719. dpms_property,
  8720. DRM_MODE_DPMS_ON);
  8721. intel_encoder = to_intel_encoder(connector->encoder);
  8722. intel_encoder->connectors_active = true;
  8723. }
  8724. }
  8725. }
  8726. static bool intel_fuzzy_clock_check(int clock1, int clock2)
  8727. {
  8728. int diff;
  8729. if (clock1 == clock2)
  8730. return true;
  8731. if (!clock1 || !clock2)
  8732. return false;
  8733. diff = abs(clock1 - clock2);
  8734. if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105)
  8735. return true;
  8736. return false;
  8737. }
  8738. #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \
  8739. list_for_each_entry((intel_crtc), \
  8740. &(dev)->mode_config.crtc_list, \
  8741. base.head) \
  8742. if (mask & (1 <<(intel_crtc)->pipe))
  8743. static bool
  8744. intel_pipe_config_compare(struct drm_device *dev,
  8745. struct intel_crtc_config *current_config,
  8746. struct intel_crtc_config *pipe_config)
  8747. {
  8748. #define PIPE_CONF_CHECK_X(name) \
  8749. if (current_config->name != pipe_config->name) { \
  8750. DRM_ERROR("mismatch in " #name " " \
  8751. "(expected 0x%08x, found 0x%08x)\n", \
  8752. current_config->name, \
  8753. pipe_config->name); \
  8754. return false; \
  8755. }
  8756. #define PIPE_CONF_CHECK_I(name) \
  8757. if (current_config->name != pipe_config->name) { \
  8758. DRM_ERROR("mismatch in " #name " " \
  8759. "(expected %i, found %i)\n", \
  8760. current_config->name, \
  8761. pipe_config->name); \
  8762. return false; \
  8763. }
  8764. /* This is required for BDW+ where there is only one set of registers for
  8765. * switching between high and low RR.
  8766. * This macro can be used whenever a comparison has to be made between one
  8767. * hw state and multiple sw state variables.
  8768. */
  8769. #define PIPE_CONF_CHECK_I_ALT(name, alt_name) \
  8770. if ((current_config->name != pipe_config->name) && \
  8771. (current_config->alt_name != pipe_config->name)) { \
  8772. DRM_ERROR("mismatch in " #name " " \
  8773. "(expected %i or %i, found %i)\n", \
  8774. current_config->name, \
  8775. current_config->alt_name, \
  8776. pipe_config->name); \
  8777. return false; \
  8778. }
  8779. #define PIPE_CONF_CHECK_FLAGS(name, mask) \
  8780. if ((current_config->name ^ pipe_config->name) & (mask)) { \
  8781. DRM_ERROR("mismatch in " #name "(" #mask ") " \
  8782. "(expected %i, found %i)\n", \
  8783. current_config->name & (mask), \
  8784. pipe_config->name & (mask)); \
  8785. return false; \
  8786. }
  8787. #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \
  8788. if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
  8789. DRM_ERROR("mismatch in " #name " " \
  8790. "(expected %i, found %i)\n", \
  8791. current_config->name, \
  8792. pipe_config->name); \
  8793. return false; \
  8794. }
  8795. #define PIPE_CONF_QUIRK(quirk) \
  8796. ((current_config->quirks | pipe_config->quirks) & (quirk))
  8797. PIPE_CONF_CHECK_I(cpu_transcoder);
  8798. PIPE_CONF_CHECK_I(has_pch_encoder);
  8799. PIPE_CONF_CHECK_I(fdi_lanes);
  8800. PIPE_CONF_CHECK_I(fdi_m_n.gmch_m);
  8801. PIPE_CONF_CHECK_I(fdi_m_n.gmch_n);
  8802. PIPE_CONF_CHECK_I(fdi_m_n.link_m);
  8803. PIPE_CONF_CHECK_I(fdi_m_n.link_n);
  8804. PIPE_CONF_CHECK_I(fdi_m_n.tu);
  8805. PIPE_CONF_CHECK_I(has_dp_encoder);
  8806. if (INTEL_INFO(dev)->gen < 8) {
  8807. PIPE_CONF_CHECK_I(dp_m_n.gmch_m);
  8808. PIPE_CONF_CHECK_I(dp_m_n.gmch_n);
  8809. PIPE_CONF_CHECK_I(dp_m_n.link_m);
  8810. PIPE_CONF_CHECK_I(dp_m_n.link_n);
  8811. PIPE_CONF_CHECK_I(dp_m_n.tu);
  8812. if (current_config->has_drrs) {
  8813. PIPE_CONF_CHECK_I(dp_m2_n2.gmch_m);
  8814. PIPE_CONF_CHECK_I(dp_m2_n2.gmch_n);
  8815. PIPE_CONF_CHECK_I(dp_m2_n2.link_m);
  8816. PIPE_CONF_CHECK_I(dp_m2_n2.link_n);
  8817. PIPE_CONF_CHECK_I(dp_m2_n2.tu);
  8818. }
  8819. } else {
  8820. PIPE_CONF_CHECK_I_ALT(dp_m_n.gmch_m, dp_m2_n2.gmch_m);
  8821. PIPE_CONF_CHECK_I_ALT(dp_m_n.gmch_n, dp_m2_n2.gmch_n);
  8822. PIPE_CONF_CHECK_I_ALT(dp_m_n.link_m, dp_m2_n2.link_m);
  8823. PIPE_CONF_CHECK_I_ALT(dp_m_n.link_n, dp_m2_n2.link_n);
  8824. PIPE_CONF_CHECK_I_ALT(dp_m_n.tu, dp_m2_n2.tu);
  8825. }
  8826. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hdisplay);
  8827. PIPE_CONF_CHECK_I(adjusted_mode.crtc_htotal);
  8828. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hblank_start);
  8829. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hblank_end);
  8830. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hsync_start);
  8831. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hsync_end);
  8832. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vdisplay);
  8833. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vtotal);
  8834. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vblank_start);
  8835. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vblank_end);
  8836. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vsync_start);
  8837. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vsync_end);
  8838. PIPE_CONF_CHECK_I(pixel_multiplier);
  8839. PIPE_CONF_CHECK_I(has_hdmi_sink);
  8840. if ((INTEL_INFO(dev)->gen < 8 && !IS_HASWELL(dev)) ||
  8841. IS_VALLEYVIEW(dev))
  8842. PIPE_CONF_CHECK_I(limited_color_range);
  8843. PIPE_CONF_CHECK_I(has_audio);
  8844. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  8845. DRM_MODE_FLAG_INTERLACE);
  8846. if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) {
  8847. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  8848. DRM_MODE_FLAG_PHSYNC);
  8849. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  8850. DRM_MODE_FLAG_NHSYNC);
  8851. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  8852. DRM_MODE_FLAG_PVSYNC);
  8853. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  8854. DRM_MODE_FLAG_NVSYNC);
  8855. }
  8856. PIPE_CONF_CHECK_I(pipe_src_w);
  8857. PIPE_CONF_CHECK_I(pipe_src_h);
  8858. /*
  8859. * FIXME: BIOS likes to set up a cloned config with lvds+external
  8860. * screen. Since we don't yet re-compute the pipe config when moving
  8861. * just the lvds port away to another pipe the sw tracking won't match.
  8862. *
  8863. * Proper atomic modesets with recomputed global state will fix this.
  8864. * Until then just don't check gmch state for inherited modes.
  8865. */
  8866. if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_INHERITED_MODE)) {
  8867. PIPE_CONF_CHECK_I(gmch_pfit.control);
  8868. /* pfit ratios are autocomputed by the hw on gen4+ */
  8869. if (INTEL_INFO(dev)->gen < 4)
  8870. PIPE_CONF_CHECK_I(gmch_pfit.pgm_ratios);
  8871. PIPE_CONF_CHECK_I(gmch_pfit.lvds_border_bits);
  8872. }
  8873. PIPE_CONF_CHECK_I(pch_pfit.enabled);
  8874. if (current_config->pch_pfit.enabled) {
  8875. PIPE_CONF_CHECK_I(pch_pfit.pos);
  8876. PIPE_CONF_CHECK_I(pch_pfit.size);
  8877. }
  8878. /* BDW+ don't expose a synchronous way to read the state */
  8879. if (IS_HASWELL(dev))
  8880. PIPE_CONF_CHECK_I(ips_enabled);
  8881. PIPE_CONF_CHECK_I(double_wide);
  8882. PIPE_CONF_CHECK_X(ddi_pll_sel);
  8883. PIPE_CONF_CHECK_I(shared_dpll);
  8884. PIPE_CONF_CHECK_X(dpll_hw_state.dpll);
  8885. PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md);
  8886. PIPE_CONF_CHECK_X(dpll_hw_state.fp0);
  8887. PIPE_CONF_CHECK_X(dpll_hw_state.fp1);
  8888. PIPE_CONF_CHECK_X(dpll_hw_state.wrpll);
  8889. if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5)
  8890. PIPE_CONF_CHECK_I(pipe_bpp);
  8891. PIPE_CONF_CHECK_CLOCK_FUZZY(adjusted_mode.crtc_clock);
  8892. PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock);
  8893. #undef PIPE_CONF_CHECK_X
  8894. #undef PIPE_CONF_CHECK_I
  8895. #undef PIPE_CONF_CHECK_I_ALT
  8896. #undef PIPE_CONF_CHECK_FLAGS
  8897. #undef PIPE_CONF_CHECK_CLOCK_FUZZY
  8898. #undef PIPE_CONF_QUIRK
  8899. return true;
  8900. }
  8901. static void
  8902. check_connector_state(struct drm_device *dev)
  8903. {
  8904. struct intel_connector *connector;
  8905. list_for_each_entry(connector, &dev->mode_config.connector_list,
  8906. base.head) {
  8907. /* This also checks the encoder/connector hw state with the
  8908. * ->get_hw_state callbacks. */
  8909. intel_connector_check_state(connector);
  8910. WARN(&connector->new_encoder->base != connector->base.encoder,
  8911. "connector's staged encoder doesn't match current encoder\n");
  8912. }
  8913. }
  8914. static void
  8915. check_encoder_state(struct drm_device *dev)
  8916. {
  8917. struct intel_encoder *encoder;
  8918. struct intel_connector *connector;
  8919. for_each_intel_encoder(dev, encoder) {
  8920. bool enabled = false;
  8921. bool active = false;
  8922. enum pipe pipe, tracked_pipe;
  8923. DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
  8924. encoder->base.base.id,
  8925. encoder->base.name);
  8926. WARN(&encoder->new_crtc->base != encoder->base.crtc,
  8927. "encoder's stage crtc doesn't match current crtc\n");
  8928. WARN(encoder->connectors_active && !encoder->base.crtc,
  8929. "encoder's active_connectors set, but no crtc\n");
  8930. list_for_each_entry(connector, &dev->mode_config.connector_list,
  8931. base.head) {
  8932. if (connector->base.encoder != &encoder->base)
  8933. continue;
  8934. enabled = true;
  8935. if (connector->base.dpms != DRM_MODE_DPMS_OFF)
  8936. active = true;
  8937. }
  8938. /*
  8939. * for MST connectors if we unplug the connector is gone
  8940. * away but the encoder is still connected to a crtc
  8941. * until a modeset happens in response to the hotplug.
  8942. */
  8943. if (!enabled && encoder->base.encoder_type == DRM_MODE_ENCODER_DPMST)
  8944. continue;
  8945. WARN(!!encoder->base.crtc != enabled,
  8946. "encoder's enabled state mismatch "
  8947. "(expected %i, found %i)\n",
  8948. !!encoder->base.crtc, enabled);
  8949. WARN(active && !encoder->base.crtc,
  8950. "active encoder with no crtc\n");
  8951. WARN(encoder->connectors_active != active,
  8952. "encoder's computed active state doesn't match tracked active state "
  8953. "(expected %i, found %i)\n", active, encoder->connectors_active);
  8954. active = encoder->get_hw_state(encoder, &pipe);
  8955. WARN(active != encoder->connectors_active,
  8956. "encoder's hw state doesn't match sw tracking "
  8957. "(expected %i, found %i)\n",
  8958. encoder->connectors_active, active);
  8959. if (!encoder->base.crtc)
  8960. continue;
  8961. tracked_pipe = to_intel_crtc(encoder->base.crtc)->pipe;
  8962. WARN(active && pipe != tracked_pipe,
  8963. "active encoder's pipe doesn't match"
  8964. "(expected %i, found %i)\n",
  8965. tracked_pipe, pipe);
  8966. }
  8967. }
  8968. static void
  8969. check_crtc_state(struct drm_device *dev)
  8970. {
  8971. struct drm_i915_private *dev_priv = dev->dev_private;
  8972. struct intel_crtc *crtc;
  8973. struct intel_encoder *encoder;
  8974. struct intel_crtc_config pipe_config;
  8975. for_each_intel_crtc(dev, crtc) {
  8976. bool enabled = false;
  8977. bool active = false;
  8978. memset(&pipe_config, 0, sizeof(pipe_config));
  8979. DRM_DEBUG_KMS("[CRTC:%d]\n",
  8980. crtc->base.base.id);
  8981. WARN(crtc->active && !crtc->base.enabled,
  8982. "active crtc, but not enabled in sw tracking\n");
  8983. for_each_intel_encoder(dev, encoder) {
  8984. if (encoder->base.crtc != &crtc->base)
  8985. continue;
  8986. enabled = true;
  8987. if (encoder->connectors_active)
  8988. active = true;
  8989. }
  8990. WARN(active != crtc->active,
  8991. "crtc's computed active state doesn't match tracked active state "
  8992. "(expected %i, found %i)\n", active, crtc->active);
  8993. WARN(enabled != crtc->base.enabled,
  8994. "crtc's computed enabled state doesn't match tracked enabled state "
  8995. "(expected %i, found %i)\n", enabled, crtc->base.enabled);
  8996. active = dev_priv->display.get_pipe_config(crtc,
  8997. &pipe_config);
  8998. /* hw state is inconsistent with the pipe quirk */
  8999. if ((crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) ||
  9000. (crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))
  9001. active = crtc->active;
  9002. for_each_intel_encoder(dev, encoder) {
  9003. enum pipe pipe;
  9004. if (encoder->base.crtc != &crtc->base)
  9005. continue;
  9006. if (encoder->get_hw_state(encoder, &pipe))
  9007. encoder->get_config(encoder, &pipe_config);
  9008. }
  9009. WARN(crtc->active != active,
  9010. "crtc active state doesn't match with hw state "
  9011. "(expected %i, found %i)\n", crtc->active, active);
  9012. if (active &&
  9013. !intel_pipe_config_compare(dev, &crtc->config, &pipe_config)) {
  9014. WARN(1, "pipe state doesn't match!\n");
  9015. intel_dump_pipe_config(crtc, &pipe_config,
  9016. "[hw state]");
  9017. intel_dump_pipe_config(crtc, &crtc->config,
  9018. "[sw state]");
  9019. }
  9020. }
  9021. }
  9022. static void
  9023. check_shared_dpll_state(struct drm_device *dev)
  9024. {
  9025. struct drm_i915_private *dev_priv = dev->dev_private;
  9026. struct intel_crtc *crtc;
  9027. struct intel_dpll_hw_state dpll_hw_state;
  9028. int i;
  9029. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  9030. struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
  9031. int enabled_crtcs = 0, active_crtcs = 0;
  9032. bool active;
  9033. memset(&dpll_hw_state, 0, sizeof(dpll_hw_state));
  9034. DRM_DEBUG_KMS("%s\n", pll->name);
  9035. active = pll->get_hw_state(dev_priv, pll, &dpll_hw_state);
  9036. WARN(pll->active > pll->refcount,
  9037. "more active pll users than references: %i vs %i\n",
  9038. pll->active, pll->refcount);
  9039. WARN(pll->active && !pll->on,
  9040. "pll in active use but not on in sw tracking\n");
  9041. WARN(pll->on && !pll->active,
  9042. "pll in on but not on in use in sw tracking\n");
  9043. WARN(pll->on != active,
  9044. "pll on state mismatch (expected %i, found %i)\n",
  9045. pll->on, active);
  9046. for_each_intel_crtc(dev, crtc) {
  9047. if (crtc->base.enabled && intel_crtc_to_shared_dpll(crtc) == pll)
  9048. enabled_crtcs++;
  9049. if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll)
  9050. active_crtcs++;
  9051. }
  9052. WARN(pll->active != active_crtcs,
  9053. "pll active crtcs mismatch (expected %i, found %i)\n",
  9054. pll->active, active_crtcs);
  9055. WARN(pll->refcount != enabled_crtcs,
  9056. "pll enabled crtcs mismatch (expected %i, found %i)\n",
  9057. pll->refcount, enabled_crtcs);
  9058. WARN(pll->on && memcmp(&pll->hw_state, &dpll_hw_state,
  9059. sizeof(dpll_hw_state)),
  9060. "pll hw state mismatch\n");
  9061. }
  9062. }
  9063. void
  9064. intel_modeset_check_state(struct drm_device *dev)
  9065. {
  9066. check_connector_state(dev);
  9067. check_encoder_state(dev);
  9068. check_crtc_state(dev);
  9069. check_shared_dpll_state(dev);
  9070. }
  9071. void ironlake_check_encoder_dotclock(const struct intel_crtc_config *pipe_config,
  9072. int dotclock)
  9073. {
  9074. /*
  9075. * FDI already provided one idea for the dotclock.
  9076. * Yell if the encoder disagrees.
  9077. */
  9078. WARN(!intel_fuzzy_clock_check(pipe_config->adjusted_mode.crtc_clock, dotclock),
  9079. "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
  9080. pipe_config->adjusted_mode.crtc_clock, dotclock);
  9081. }
  9082. static void update_scanline_offset(struct intel_crtc *crtc)
  9083. {
  9084. struct drm_device *dev = crtc->base.dev;
  9085. /*
  9086. * The scanline counter increments at the leading edge of hsync.
  9087. *
  9088. * On most platforms it starts counting from vtotal-1 on the
  9089. * first active line. That means the scanline counter value is
  9090. * always one less than what we would expect. Ie. just after
  9091. * start of vblank, which also occurs at start of hsync (on the
  9092. * last active line), the scanline counter will read vblank_start-1.
  9093. *
  9094. * On gen2 the scanline counter starts counting from 1 instead
  9095. * of vtotal-1, so we have to subtract one (or rather add vtotal-1
  9096. * to keep the value positive), instead of adding one.
  9097. *
  9098. * On HSW+ the behaviour of the scanline counter depends on the output
  9099. * type. For DP ports it behaves like most other platforms, but on HDMI
  9100. * there's an extra 1 line difference. So we need to add two instead of
  9101. * one to the value.
  9102. */
  9103. if (IS_GEN2(dev)) {
  9104. const struct drm_display_mode *mode = &crtc->config.adjusted_mode;
  9105. int vtotal;
  9106. vtotal = mode->crtc_vtotal;
  9107. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  9108. vtotal /= 2;
  9109. crtc->scanline_offset = vtotal - 1;
  9110. } else if (HAS_DDI(dev) &&
  9111. intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) {
  9112. crtc->scanline_offset = 2;
  9113. } else
  9114. crtc->scanline_offset = 1;
  9115. }
  9116. static int __intel_set_mode(struct drm_crtc *crtc,
  9117. struct drm_display_mode *mode,
  9118. int x, int y, struct drm_framebuffer *fb)
  9119. {
  9120. struct drm_device *dev = crtc->dev;
  9121. struct drm_i915_private *dev_priv = dev->dev_private;
  9122. struct drm_display_mode *saved_mode;
  9123. struct intel_crtc_config *pipe_config = NULL;
  9124. struct intel_crtc *intel_crtc;
  9125. unsigned disable_pipes, prepare_pipes, modeset_pipes;
  9126. int ret = 0;
  9127. saved_mode = kmalloc(sizeof(*saved_mode), GFP_KERNEL);
  9128. if (!saved_mode)
  9129. return -ENOMEM;
  9130. intel_modeset_affected_pipes(crtc, &modeset_pipes,
  9131. &prepare_pipes, &disable_pipes);
  9132. *saved_mode = crtc->mode;
  9133. /* Hack: Because we don't (yet) support global modeset on multiple
  9134. * crtcs, we don't keep track of the new mode for more than one crtc.
  9135. * Hence simply check whether any bit is set in modeset_pipes in all the
  9136. * pieces of code that are not yet converted to deal with mutliple crtcs
  9137. * changing their mode at the same time. */
  9138. if (modeset_pipes) {
  9139. pipe_config = intel_modeset_pipe_config(crtc, fb, mode);
  9140. if (IS_ERR(pipe_config)) {
  9141. ret = PTR_ERR(pipe_config);
  9142. pipe_config = NULL;
  9143. goto out;
  9144. }
  9145. intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config,
  9146. "[modeset]");
  9147. to_intel_crtc(crtc)->new_config = pipe_config;
  9148. }
  9149. /*
  9150. * See if the config requires any additional preparation, e.g.
  9151. * to adjust global state with pipes off. We need to do this
  9152. * here so we can get the modeset_pipe updated config for the new
  9153. * mode set on this crtc. For other crtcs we need to use the
  9154. * adjusted_mode bits in the crtc directly.
  9155. */
  9156. if (IS_VALLEYVIEW(dev)) {
  9157. valleyview_modeset_global_pipes(dev, &prepare_pipes);
  9158. /* may have added more to prepare_pipes than we should */
  9159. prepare_pipes &= ~disable_pipes;
  9160. }
  9161. for_each_intel_crtc_masked(dev, disable_pipes, intel_crtc)
  9162. intel_crtc_disable(&intel_crtc->base);
  9163. for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc) {
  9164. if (intel_crtc->base.enabled)
  9165. dev_priv->display.crtc_disable(&intel_crtc->base);
  9166. }
  9167. /* crtc->mode is already used by the ->mode_set callbacks, hence we need
  9168. * to set it here already despite that we pass it down the callchain.
  9169. */
  9170. if (modeset_pipes) {
  9171. crtc->mode = *mode;
  9172. /* mode_set/enable/disable functions rely on a correct pipe
  9173. * config. */
  9174. to_intel_crtc(crtc)->config = *pipe_config;
  9175. to_intel_crtc(crtc)->new_config = &to_intel_crtc(crtc)->config;
  9176. /*
  9177. * Calculate and store various constants which
  9178. * are later needed by vblank and swap-completion
  9179. * timestamping. They are derived from true hwmode.
  9180. */
  9181. drm_calc_timestamping_constants(crtc,
  9182. &pipe_config->adjusted_mode);
  9183. }
  9184. /* Only after disabling all output pipelines that will be changed can we
  9185. * update the the output configuration. */
  9186. intel_modeset_update_state(dev, prepare_pipes);
  9187. if (dev_priv->display.modeset_global_resources)
  9188. dev_priv->display.modeset_global_resources(dev);
  9189. /* Set up the DPLL and any encoders state that needs to adjust or depend
  9190. * on the DPLL.
  9191. */
  9192. for_each_intel_crtc_masked(dev, modeset_pipes, intel_crtc) {
  9193. struct drm_framebuffer *old_fb = crtc->primary->fb;
  9194. struct drm_i915_gem_object *old_obj = intel_fb_obj(old_fb);
  9195. struct drm_i915_gem_object *obj = intel_fb_obj(fb);
  9196. mutex_lock(&dev->struct_mutex);
  9197. ret = intel_pin_and_fence_fb_obj(dev,
  9198. obj,
  9199. NULL);
  9200. if (ret != 0) {
  9201. DRM_ERROR("pin & fence failed\n");
  9202. mutex_unlock(&dev->struct_mutex);
  9203. goto done;
  9204. }
  9205. if (old_fb)
  9206. intel_unpin_fb_obj(old_obj);
  9207. i915_gem_track_fb(old_obj, obj,
  9208. INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe));
  9209. mutex_unlock(&dev->struct_mutex);
  9210. crtc->primary->fb = fb;
  9211. crtc->x = x;
  9212. crtc->y = y;
  9213. ret = dev_priv->display.crtc_mode_set(intel_crtc, x, y, fb);
  9214. if (ret)
  9215. goto done;
  9216. }
  9217. /* Now enable the clocks, plane, pipe, and connectors that we set up. */
  9218. for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc) {
  9219. update_scanline_offset(intel_crtc);
  9220. dev_priv->display.crtc_enable(&intel_crtc->base);
  9221. }
  9222. /* FIXME: add subpixel order */
  9223. done:
  9224. if (ret && crtc->enabled)
  9225. crtc->mode = *saved_mode;
  9226. out:
  9227. kfree(pipe_config);
  9228. kfree(saved_mode);
  9229. return ret;
  9230. }
  9231. static int intel_set_mode(struct drm_crtc *crtc,
  9232. struct drm_display_mode *mode,
  9233. int x, int y, struct drm_framebuffer *fb)
  9234. {
  9235. int ret;
  9236. ret = __intel_set_mode(crtc, mode, x, y, fb);
  9237. if (ret == 0)
  9238. intel_modeset_check_state(crtc->dev);
  9239. return ret;
  9240. }
  9241. void intel_crtc_restore_mode(struct drm_crtc *crtc)
  9242. {
  9243. intel_set_mode(crtc, &crtc->mode, crtc->x, crtc->y, crtc->primary->fb);
  9244. }
  9245. #undef for_each_intel_crtc_masked
  9246. static void intel_set_config_free(struct intel_set_config *config)
  9247. {
  9248. if (!config)
  9249. return;
  9250. kfree(config->save_connector_encoders);
  9251. kfree(config->save_encoder_crtcs);
  9252. kfree(config->save_crtc_enabled);
  9253. kfree(config);
  9254. }
  9255. static int intel_set_config_save_state(struct drm_device *dev,
  9256. struct intel_set_config *config)
  9257. {
  9258. struct drm_crtc *crtc;
  9259. struct drm_encoder *encoder;
  9260. struct drm_connector *connector;
  9261. int count;
  9262. config->save_crtc_enabled =
  9263. kcalloc(dev->mode_config.num_crtc,
  9264. sizeof(bool), GFP_KERNEL);
  9265. if (!config->save_crtc_enabled)
  9266. return -ENOMEM;
  9267. config->save_encoder_crtcs =
  9268. kcalloc(dev->mode_config.num_encoder,
  9269. sizeof(struct drm_crtc *), GFP_KERNEL);
  9270. if (!config->save_encoder_crtcs)
  9271. return -ENOMEM;
  9272. config->save_connector_encoders =
  9273. kcalloc(dev->mode_config.num_connector,
  9274. sizeof(struct drm_encoder *), GFP_KERNEL);
  9275. if (!config->save_connector_encoders)
  9276. return -ENOMEM;
  9277. /* Copy data. Note that driver private data is not affected.
  9278. * Should anything bad happen only the expected state is
  9279. * restored, not the drivers personal bookkeeping.
  9280. */
  9281. count = 0;
  9282. for_each_crtc(dev, crtc) {
  9283. config->save_crtc_enabled[count++] = crtc->enabled;
  9284. }
  9285. count = 0;
  9286. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  9287. config->save_encoder_crtcs[count++] = encoder->crtc;
  9288. }
  9289. count = 0;
  9290. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  9291. config->save_connector_encoders[count++] = connector->encoder;
  9292. }
  9293. return 0;
  9294. }
  9295. static void intel_set_config_restore_state(struct drm_device *dev,
  9296. struct intel_set_config *config)
  9297. {
  9298. struct intel_crtc *crtc;
  9299. struct intel_encoder *encoder;
  9300. struct intel_connector *connector;
  9301. int count;
  9302. count = 0;
  9303. for_each_intel_crtc(dev, crtc) {
  9304. crtc->new_enabled = config->save_crtc_enabled[count++];
  9305. if (crtc->new_enabled)
  9306. crtc->new_config = &crtc->config;
  9307. else
  9308. crtc->new_config = NULL;
  9309. }
  9310. count = 0;
  9311. for_each_intel_encoder(dev, encoder) {
  9312. encoder->new_crtc =
  9313. to_intel_crtc(config->save_encoder_crtcs[count++]);
  9314. }
  9315. count = 0;
  9316. list_for_each_entry(connector, &dev->mode_config.connector_list, base.head) {
  9317. connector->new_encoder =
  9318. to_intel_encoder(config->save_connector_encoders[count++]);
  9319. }
  9320. }
  9321. static bool
  9322. is_crtc_connector_off(struct drm_mode_set *set)
  9323. {
  9324. int i;
  9325. if (set->num_connectors == 0)
  9326. return false;
  9327. if (WARN_ON(set->connectors == NULL))
  9328. return false;
  9329. for (i = 0; i < set->num_connectors; i++)
  9330. if (set->connectors[i]->encoder &&
  9331. set->connectors[i]->encoder->crtc == set->crtc &&
  9332. set->connectors[i]->dpms != DRM_MODE_DPMS_ON)
  9333. return true;
  9334. return false;
  9335. }
  9336. static void
  9337. intel_set_config_compute_mode_changes(struct drm_mode_set *set,
  9338. struct intel_set_config *config)
  9339. {
  9340. /* We should be able to check here if the fb has the same properties
  9341. * and then just flip_or_move it */
  9342. if (is_crtc_connector_off(set)) {
  9343. config->mode_changed = true;
  9344. } else if (set->crtc->primary->fb != set->fb) {
  9345. /*
  9346. * If we have no fb, we can only flip as long as the crtc is
  9347. * active, otherwise we need a full mode set. The crtc may
  9348. * be active if we've only disabled the primary plane, or
  9349. * in fastboot situations.
  9350. */
  9351. if (set->crtc->primary->fb == NULL) {
  9352. struct intel_crtc *intel_crtc =
  9353. to_intel_crtc(set->crtc);
  9354. if (intel_crtc->active) {
  9355. DRM_DEBUG_KMS("crtc has no fb, will flip\n");
  9356. config->fb_changed = true;
  9357. } else {
  9358. DRM_DEBUG_KMS("inactive crtc, full mode set\n");
  9359. config->mode_changed = true;
  9360. }
  9361. } else if (set->fb == NULL) {
  9362. config->mode_changed = true;
  9363. } else if (set->fb->pixel_format !=
  9364. set->crtc->primary->fb->pixel_format) {
  9365. config->mode_changed = true;
  9366. } else {
  9367. config->fb_changed = true;
  9368. }
  9369. }
  9370. if (set->fb && (set->x != set->crtc->x || set->y != set->crtc->y))
  9371. config->fb_changed = true;
  9372. if (set->mode && !drm_mode_equal(set->mode, &set->crtc->mode)) {
  9373. DRM_DEBUG_KMS("modes are different, full mode set\n");
  9374. drm_mode_debug_printmodeline(&set->crtc->mode);
  9375. drm_mode_debug_printmodeline(set->mode);
  9376. config->mode_changed = true;
  9377. }
  9378. DRM_DEBUG_KMS("computed changes for [CRTC:%d], mode_changed=%d, fb_changed=%d\n",
  9379. set->crtc->base.id, config->mode_changed, config->fb_changed);
  9380. }
  9381. static int
  9382. intel_modeset_stage_output_state(struct drm_device *dev,
  9383. struct drm_mode_set *set,
  9384. struct intel_set_config *config)
  9385. {
  9386. struct intel_connector *connector;
  9387. struct intel_encoder *encoder;
  9388. struct intel_crtc *crtc;
  9389. int ro;
  9390. /* The upper layers ensure that we either disable a crtc or have a list
  9391. * of connectors. For paranoia, double-check this. */
  9392. WARN_ON(!set->fb && (set->num_connectors != 0));
  9393. WARN_ON(set->fb && (set->num_connectors == 0));
  9394. list_for_each_entry(connector, &dev->mode_config.connector_list,
  9395. base.head) {
  9396. /* Otherwise traverse passed in connector list and get encoders
  9397. * for them. */
  9398. for (ro = 0; ro < set->num_connectors; ro++) {
  9399. if (set->connectors[ro] == &connector->base) {
  9400. connector->new_encoder = intel_find_encoder(connector, to_intel_crtc(set->crtc)->pipe);
  9401. break;
  9402. }
  9403. }
  9404. /* If we disable the crtc, disable all its connectors. Also, if
  9405. * the connector is on the changing crtc but not on the new
  9406. * connector list, disable it. */
  9407. if ((!set->fb || ro == set->num_connectors) &&
  9408. connector->base.encoder &&
  9409. connector->base.encoder->crtc == set->crtc) {
  9410. connector->new_encoder = NULL;
  9411. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n",
  9412. connector->base.base.id,
  9413. connector->base.name);
  9414. }
  9415. if (&connector->new_encoder->base != connector->base.encoder) {
  9416. DRM_DEBUG_KMS("encoder changed, full mode switch\n");
  9417. config->mode_changed = true;
  9418. }
  9419. }
  9420. /* connector->new_encoder is now updated for all connectors. */
  9421. /* Update crtc of enabled connectors. */
  9422. list_for_each_entry(connector, &dev->mode_config.connector_list,
  9423. base.head) {
  9424. struct drm_crtc *new_crtc;
  9425. if (!connector->new_encoder)
  9426. continue;
  9427. new_crtc = connector->new_encoder->base.crtc;
  9428. for (ro = 0; ro < set->num_connectors; ro++) {
  9429. if (set->connectors[ro] == &connector->base)
  9430. new_crtc = set->crtc;
  9431. }
  9432. /* Make sure the new CRTC will work with the encoder */
  9433. if (!drm_encoder_crtc_ok(&connector->new_encoder->base,
  9434. new_crtc)) {
  9435. return -EINVAL;
  9436. }
  9437. connector->new_encoder->new_crtc = to_intel_crtc(new_crtc);
  9438. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n",
  9439. connector->base.base.id,
  9440. connector->base.name,
  9441. new_crtc->base.id);
  9442. }
  9443. /* Check for any encoders that needs to be disabled. */
  9444. for_each_intel_encoder(dev, encoder) {
  9445. int num_connectors = 0;
  9446. list_for_each_entry(connector,
  9447. &dev->mode_config.connector_list,
  9448. base.head) {
  9449. if (connector->new_encoder == encoder) {
  9450. WARN_ON(!connector->new_encoder->new_crtc);
  9451. num_connectors++;
  9452. }
  9453. }
  9454. if (num_connectors == 0)
  9455. encoder->new_crtc = NULL;
  9456. else if (num_connectors > 1)
  9457. return -EINVAL;
  9458. /* Only now check for crtc changes so we don't miss encoders
  9459. * that will be disabled. */
  9460. if (&encoder->new_crtc->base != encoder->base.crtc) {
  9461. DRM_DEBUG_KMS("crtc changed, full mode switch\n");
  9462. config->mode_changed = true;
  9463. }
  9464. }
  9465. /* Now we've also updated encoder->new_crtc for all encoders. */
  9466. list_for_each_entry(connector, &dev->mode_config.connector_list,
  9467. base.head) {
  9468. if (connector->new_encoder)
  9469. if (connector->new_encoder != connector->encoder)
  9470. connector->encoder = connector->new_encoder;
  9471. }
  9472. for_each_intel_crtc(dev, crtc) {
  9473. crtc->new_enabled = false;
  9474. for_each_intel_encoder(dev, encoder) {
  9475. if (encoder->new_crtc == crtc) {
  9476. crtc->new_enabled = true;
  9477. break;
  9478. }
  9479. }
  9480. if (crtc->new_enabled != crtc->base.enabled) {
  9481. DRM_DEBUG_KMS("crtc %sabled, full mode switch\n",
  9482. crtc->new_enabled ? "en" : "dis");
  9483. config->mode_changed = true;
  9484. }
  9485. if (crtc->new_enabled)
  9486. crtc->new_config = &crtc->config;
  9487. else
  9488. crtc->new_config = NULL;
  9489. }
  9490. return 0;
  9491. }
  9492. static void disable_crtc_nofb(struct intel_crtc *crtc)
  9493. {
  9494. struct drm_device *dev = crtc->base.dev;
  9495. struct intel_encoder *encoder;
  9496. struct intel_connector *connector;
  9497. DRM_DEBUG_KMS("Trying to restore without FB -> disabling pipe %c\n",
  9498. pipe_name(crtc->pipe));
  9499. list_for_each_entry(connector, &dev->mode_config.connector_list, base.head) {
  9500. if (connector->new_encoder &&
  9501. connector->new_encoder->new_crtc == crtc)
  9502. connector->new_encoder = NULL;
  9503. }
  9504. for_each_intel_encoder(dev, encoder) {
  9505. if (encoder->new_crtc == crtc)
  9506. encoder->new_crtc = NULL;
  9507. }
  9508. crtc->new_enabled = false;
  9509. crtc->new_config = NULL;
  9510. }
  9511. static int intel_crtc_set_config(struct drm_mode_set *set)
  9512. {
  9513. struct drm_device *dev;
  9514. struct drm_mode_set save_set;
  9515. struct intel_set_config *config;
  9516. int ret;
  9517. BUG_ON(!set);
  9518. BUG_ON(!set->crtc);
  9519. BUG_ON(!set->crtc->helper_private);
  9520. /* Enforce sane interface api - has been abused by the fb helper. */
  9521. BUG_ON(!set->mode && set->fb);
  9522. BUG_ON(set->fb && set->num_connectors == 0);
  9523. if (set->fb) {
  9524. DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n",
  9525. set->crtc->base.id, set->fb->base.id,
  9526. (int)set->num_connectors, set->x, set->y);
  9527. } else {
  9528. DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set->crtc->base.id);
  9529. }
  9530. dev = set->crtc->dev;
  9531. ret = -ENOMEM;
  9532. config = kzalloc(sizeof(*config), GFP_KERNEL);
  9533. if (!config)
  9534. goto out_config;
  9535. ret = intel_set_config_save_state(dev, config);
  9536. if (ret)
  9537. goto out_config;
  9538. save_set.crtc = set->crtc;
  9539. save_set.mode = &set->crtc->mode;
  9540. save_set.x = set->crtc->x;
  9541. save_set.y = set->crtc->y;
  9542. save_set.fb = set->crtc->primary->fb;
  9543. /* Compute whether we need a full modeset, only an fb base update or no
  9544. * change at all. In the future we might also check whether only the
  9545. * mode changed, e.g. for LVDS where we only change the panel fitter in
  9546. * such cases. */
  9547. intel_set_config_compute_mode_changes(set, config);
  9548. ret = intel_modeset_stage_output_state(dev, set, config);
  9549. if (ret)
  9550. goto fail;
  9551. if (config->mode_changed) {
  9552. ret = intel_set_mode(set->crtc, set->mode,
  9553. set->x, set->y, set->fb);
  9554. } else if (config->fb_changed) {
  9555. struct intel_crtc *intel_crtc = to_intel_crtc(set->crtc);
  9556. intel_crtc_wait_for_pending_flips(set->crtc);
  9557. ret = intel_pipe_set_base(set->crtc,
  9558. set->x, set->y, set->fb);
  9559. /*
  9560. * We need to make sure the primary plane is re-enabled if it
  9561. * has previously been turned off.
  9562. */
  9563. if (!intel_crtc->primary_enabled && ret == 0) {
  9564. WARN_ON(!intel_crtc->active);
  9565. intel_enable_primary_hw_plane(set->crtc->primary, set->crtc);
  9566. }
  9567. /*
  9568. * In the fastboot case this may be our only check of the
  9569. * state after boot. It would be better to only do it on
  9570. * the first update, but we don't have a nice way of doing that
  9571. * (and really, set_config isn't used much for high freq page
  9572. * flipping, so increasing its cost here shouldn't be a big
  9573. * deal).
  9574. */
  9575. if (i915.fastboot && ret == 0)
  9576. intel_modeset_check_state(set->crtc->dev);
  9577. }
  9578. if (ret) {
  9579. DRM_DEBUG_KMS("failed to set mode on [CRTC:%d], err = %d\n",
  9580. set->crtc->base.id, ret);
  9581. fail:
  9582. intel_set_config_restore_state(dev, config);
  9583. /*
  9584. * HACK: if the pipe was on, but we didn't have a framebuffer,
  9585. * force the pipe off to avoid oopsing in the modeset code
  9586. * due to fb==NULL. This should only happen during boot since
  9587. * we don't yet reconstruct the FB from the hardware state.
  9588. */
  9589. if (to_intel_crtc(save_set.crtc)->new_enabled && !save_set.fb)
  9590. disable_crtc_nofb(to_intel_crtc(save_set.crtc));
  9591. /* Try to restore the config */
  9592. if (config->mode_changed &&
  9593. intel_set_mode(save_set.crtc, save_set.mode,
  9594. save_set.x, save_set.y, save_set.fb))
  9595. DRM_ERROR("failed to restore config after modeset failure\n");
  9596. }
  9597. out_config:
  9598. intel_set_config_free(config);
  9599. return ret;
  9600. }
  9601. static const struct drm_crtc_funcs intel_crtc_funcs = {
  9602. .gamma_set = intel_crtc_gamma_set,
  9603. .set_config = intel_crtc_set_config,
  9604. .destroy = intel_crtc_destroy,
  9605. .page_flip = intel_crtc_page_flip,
  9606. };
  9607. static bool ibx_pch_dpll_get_hw_state(struct drm_i915_private *dev_priv,
  9608. struct intel_shared_dpll *pll,
  9609. struct intel_dpll_hw_state *hw_state)
  9610. {
  9611. uint32_t val;
  9612. if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_PLLS))
  9613. return false;
  9614. val = I915_READ(PCH_DPLL(pll->id));
  9615. hw_state->dpll = val;
  9616. hw_state->fp0 = I915_READ(PCH_FP0(pll->id));
  9617. hw_state->fp1 = I915_READ(PCH_FP1(pll->id));
  9618. return val & DPLL_VCO_ENABLE;
  9619. }
  9620. static void ibx_pch_dpll_mode_set(struct drm_i915_private *dev_priv,
  9621. struct intel_shared_dpll *pll)
  9622. {
  9623. I915_WRITE(PCH_FP0(pll->id), pll->hw_state.fp0);
  9624. I915_WRITE(PCH_FP1(pll->id), pll->hw_state.fp1);
  9625. }
  9626. static void ibx_pch_dpll_enable(struct drm_i915_private *dev_priv,
  9627. struct intel_shared_dpll *pll)
  9628. {
  9629. /* PCH refclock must be enabled first */
  9630. ibx_assert_pch_refclk_enabled(dev_priv);
  9631. I915_WRITE(PCH_DPLL(pll->id), pll->hw_state.dpll);
  9632. /* Wait for the clocks to stabilize. */
  9633. POSTING_READ(PCH_DPLL(pll->id));
  9634. udelay(150);
  9635. /* The pixel multiplier can only be updated once the
  9636. * DPLL is enabled and the clocks are stable.
  9637. *
  9638. * So write it again.
  9639. */
  9640. I915_WRITE(PCH_DPLL(pll->id), pll->hw_state.dpll);
  9641. POSTING_READ(PCH_DPLL(pll->id));
  9642. udelay(200);
  9643. }
  9644. static void ibx_pch_dpll_disable(struct drm_i915_private *dev_priv,
  9645. struct intel_shared_dpll *pll)
  9646. {
  9647. struct drm_device *dev = dev_priv->dev;
  9648. struct intel_crtc *crtc;
  9649. /* Make sure no transcoder isn't still depending on us. */
  9650. for_each_intel_crtc(dev, crtc) {
  9651. if (intel_crtc_to_shared_dpll(crtc) == pll)
  9652. assert_pch_transcoder_disabled(dev_priv, crtc->pipe);
  9653. }
  9654. I915_WRITE(PCH_DPLL(pll->id), 0);
  9655. POSTING_READ(PCH_DPLL(pll->id));
  9656. udelay(200);
  9657. }
  9658. static char *ibx_pch_dpll_names[] = {
  9659. "PCH DPLL A",
  9660. "PCH DPLL B",
  9661. };
  9662. static void ibx_pch_dpll_init(struct drm_device *dev)
  9663. {
  9664. struct drm_i915_private *dev_priv = dev->dev_private;
  9665. int i;
  9666. dev_priv->num_shared_dpll = 2;
  9667. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  9668. dev_priv->shared_dplls[i].id = i;
  9669. dev_priv->shared_dplls[i].name = ibx_pch_dpll_names[i];
  9670. dev_priv->shared_dplls[i].mode_set = ibx_pch_dpll_mode_set;
  9671. dev_priv->shared_dplls[i].enable = ibx_pch_dpll_enable;
  9672. dev_priv->shared_dplls[i].disable = ibx_pch_dpll_disable;
  9673. dev_priv->shared_dplls[i].get_hw_state =
  9674. ibx_pch_dpll_get_hw_state;
  9675. }
  9676. }
  9677. static void intel_shared_dpll_init(struct drm_device *dev)
  9678. {
  9679. struct drm_i915_private *dev_priv = dev->dev_private;
  9680. if (HAS_DDI(dev))
  9681. intel_ddi_pll_init(dev);
  9682. else if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
  9683. ibx_pch_dpll_init(dev);
  9684. else
  9685. dev_priv->num_shared_dpll = 0;
  9686. BUG_ON(dev_priv->num_shared_dpll > I915_NUM_PLLS);
  9687. }
  9688. static int
  9689. intel_primary_plane_disable(struct drm_plane *plane)
  9690. {
  9691. struct drm_device *dev = plane->dev;
  9692. struct intel_crtc *intel_crtc;
  9693. if (!plane->fb)
  9694. return 0;
  9695. BUG_ON(!plane->crtc);
  9696. intel_crtc = to_intel_crtc(plane->crtc);
  9697. /*
  9698. * Even though we checked plane->fb above, it's still possible that
  9699. * the primary plane has been implicitly disabled because the crtc
  9700. * coordinates given weren't visible, or because we detected
  9701. * that it was 100% covered by a sprite plane. Or, the CRTC may be
  9702. * off and we've set a fb, but haven't actually turned on the CRTC yet.
  9703. * In either case, we need to unpin the FB and let the fb pointer get
  9704. * updated, but otherwise we don't need to touch the hardware.
  9705. */
  9706. if (!intel_crtc->primary_enabled)
  9707. goto disable_unpin;
  9708. intel_crtc_wait_for_pending_flips(plane->crtc);
  9709. intel_disable_primary_hw_plane(plane, plane->crtc);
  9710. disable_unpin:
  9711. mutex_lock(&dev->struct_mutex);
  9712. i915_gem_track_fb(intel_fb_obj(plane->fb), NULL,
  9713. INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe));
  9714. intel_unpin_fb_obj(intel_fb_obj(plane->fb));
  9715. mutex_unlock(&dev->struct_mutex);
  9716. plane->fb = NULL;
  9717. return 0;
  9718. }
  9719. static int
  9720. intel_check_primary_plane(struct drm_plane *plane,
  9721. struct intel_plane_state *state)
  9722. {
  9723. struct drm_crtc *crtc = state->crtc;
  9724. struct drm_framebuffer *fb = state->fb;
  9725. struct drm_rect *dest = &state->dst;
  9726. struct drm_rect *src = &state->src;
  9727. const struct drm_rect *clip = &state->clip;
  9728. int ret;
  9729. ret = drm_plane_helper_check_update(plane, crtc, fb,
  9730. src, dest, clip,
  9731. DRM_PLANE_HELPER_NO_SCALING,
  9732. DRM_PLANE_HELPER_NO_SCALING,
  9733. false, true, &state->visible);
  9734. if (ret)
  9735. return ret;
  9736. /* no fb bound */
  9737. if (state->visible && !fb) {
  9738. DRM_ERROR("No FB bound\n");
  9739. return -EINVAL;
  9740. }
  9741. return 0;
  9742. }
  9743. static int
  9744. intel_commit_primary_plane(struct drm_plane *plane,
  9745. struct intel_plane_state *state)
  9746. {
  9747. struct drm_crtc *crtc = state->crtc;
  9748. struct drm_framebuffer *fb = state->fb;
  9749. struct drm_device *dev = crtc->dev;
  9750. struct drm_i915_private *dev_priv = dev->dev_private;
  9751. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  9752. enum pipe pipe = intel_crtc->pipe;
  9753. struct drm_framebuffer *old_fb = plane->fb;
  9754. struct drm_i915_gem_object *obj = intel_fb_obj(fb);
  9755. struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->fb);
  9756. struct intel_plane *intel_plane = to_intel_plane(plane);
  9757. struct drm_rect *src = &state->src;
  9758. int ret;
  9759. intel_crtc_wait_for_pending_flips(crtc);
  9760. if (intel_crtc_has_pending_flip(crtc)) {
  9761. DRM_ERROR("pipe is still busy with an old pageflip\n");
  9762. return -EBUSY;
  9763. }
  9764. if (plane->fb != fb) {
  9765. mutex_lock(&dev->struct_mutex);
  9766. ret = intel_pin_and_fence_fb_obj(dev, obj, NULL);
  9767. if (ret == 0)
  9768. i915_gem_track_fb(old_obj, obj,
  9769. INTEL_FRONTBUFFER_PRIMARY(pipe));
  9770. mutex_unlock(&dev->struct_mutex);
  9771. if (ret != 0) {
  9772. DRM_DEBUG_KMS("pin & fence failed\n");
  9773. return ret;
  9774. }
  9775. }
  9776. crtc->primary->fb = fb;
  9777. crtc->x = src->x1;
  9778. crtc->y = src->y1;
  9779. intel_plane->crtc_x = state->orig_dst.x1;
  9780. intel_plane->crtc_y = state->orig_dst.y1;
  9781. intel_plane->crtc_w = drm_rect_width(&state->orig_dst);
  9782. intel_plane->crtc_h = drm_rect_height(&state->orig_dst);
  9783. intel_plane->src_x = state->orig_src.x1;
  9784. intel_plane->src_y = state->orig_src.y1;
  9785. intel_plane->src_w = drm_rect_width(&state->orig_src);
  9786. intel_plane->src_h = drm_rect_height(&state->orig_src);
  9787. intel_plane->obj = obj;
  9788. if (intel_crtc->active) {
  9789. /*
  9790. * FBC does not work on some platforms for rotated
  9791. * planes, so disable it when rotation is not 0 and
  9792. * update it when rotation is set back to 0.
  9793. *
  9794. * FIXME: This is redundant with the fbc update done in
  9795. * the primary plane enable function except that that
  9796. * one is done too late. We eventually need to unify
  9797. * this.
  9798. */
  9799. if (intel_crtc->primary_enabled &&
  9800. INTEL_INFO(dev)->gen <= 4 && !IS_G4X(dev) &&
  9801. dev_priv->fbc.plane == intel_crtc->plane &&
  9802. intel_plane->rotation != BIT(DRM_ROTATE_0)) {
  9803. intel_disable_fbc(dev);
  9804. }
  9805. if (state->visible) {
  9806. bool was_enabled = intel_crtc->primary_enabled;
  9807. /* FIXME: kill this fastboot hack */
  9808. intel_update_pipe_size(intel_crtc);
  9809. intel_crtc->primary_enabled = true;
  9810. dev_priv->display.update_primary_plane(crtc, plane->fb,
  9811. crtc->x, crtc->y);
  9812. /*
  9813. * BDW signals flip done immediately if the plane
  9814. * is disabled, even if the plane enable is already
  9815. * armed to occur at the next vblank :(
  9816. */
  9817. if (IS_BROADWELL(dev) && !was_enabled)
  9818. intel_wait_for_vblank(dev, intel_crtc->pipe);
  9819. } else {
  9820. /*
  9821. * If clipping results in a non-visible primary plane,
  9822. * we'll disable the primary plane. Note that this is
  9823. * a bit different than what happens if userspace
  9824. * explicitly disables the plane by passing fb=0
  9825. * because plane->fb still gets set and pinned.
  9826. */
  9827. intel_disable_primary_hw_plane(plane, crtc);
  9828. }
  9829. intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_PRIMARY(pipe));
  9830. mutex_lock(&dev->struct_mutex);
  9831. intel_update_fbc(dev);
  9832. mutex_unlock(&dev->struct_mutex);
  9833. }
  9834. if (old_fb && old_fb != fb) {
  9835. if (intel_crtc->active)
  9836. intel_wait_for_vblank(dev, intel_crtc->pipe);
  9837. mutex_lock(&dev->struct_mutex);
  9838. intel_unpin_fb_obj(old_obj);
  9839. mutex_unlock(&dev->struct_mutex);
  9840. }
  9841. return 0;
  9842. }
  9843. static int
  9844. intel_primary_plane_setplane(struct drm_plane *plane, struct drm_crtc *crtc,
  9845. struct drm_framebuffer *fb, int crtc_x, int crtc_y,
  9846. unsigned int crtc_w, unsigned int crtc_h,
  9847. uint32_t src_x, uint32_t src_y,
  9848. uint32_t src_w, uint32_t src_h)
  9849. {
  9850. struct intel_plane_state state;
  9851. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  9852. int ret;
  9853. state.crtc = crtc;
  9854. state.fb = fb;
  9855. /* sample coordinates in 16.16 fixed point */
  9856. state.src.x1 = src_x;
  9857. state.src.x2 = src_x + src_w;
  9858. state.src.y1 = src_y;
  9859. state.src.y2 = src_y + src_h;
  9860. /* integer pixels */
  9861. state.dst.x1 = crtc_x;
  9862. state.dst.x2 = crtc_x + crtc_w;
  9863. state.dst.y1 = crtc_y;
  9864. state.dst.y2 = crtc_y + crtc_h;
  9865. state.clip.x1 = 0;
  9866. state.clip.y1 = 0;
  9867. state.clip.x2 = intel_crtc->active ? intel_crtc->config.pipe_src_w : 0;
  9868. state.clip.y2 = intel_crtc->active ? intel_crtc->config.pipe_src_h : 0;
  9869. state.orig_src = state.src;
  9870. state.orig_dst = state.dst;
  9871. ret = intel_check_primary_plane(plane, &state);
  9872. if (ret)
  9873. return ret;
  9874. intel_commit_primary_plane(plane, &state);
  9875. return 0;
  9876. }
  9877. /* Common destruction function for both primary and cursor planes */
  9878. static void intel_plane_destroy(struct drm_plane *plane)
  9879. {
  9880. struct intel_plane *intel_plane = to_intel_plane(plane);
  9881. drm_plane_cleanup(plane);
  9882. kfree(intel_plane);
  9883. }
  9884. static const struct drm_plane_funcs intel_primary_plane_funcs = {
  9885. .update_plane = intel_primary_plane_setplane,
  9886. .disable_plane = intel_primary_plane_disable,
  9887. .destroy = intel_plane_destroy,
  9888. .set_property = intel_plane_set_property
  9889. };
  9890. static struct drm_plane *intel_primary_plane_create(struct drm_device *dev,
  9891. int pipe)
  9892. {
  9893. struct intel_plane *primary;
  9894. const uint32_t *intel_primary_formats;
  9895. int num_formats;
  9896. primary = kzalloc(sizeof(*primary), GFP_KERNEL);
  9897. if (primary == NULL)
  9898. return NULL;
  9899. primary->can_scale = false;
  9900. primary->max_downscale = 1;
  9901. primary->pipe = pipe;
  9902. primary->plane = pipe;
  9903. primary->rotation = BIT(DRM_ROTATE_0);
  9904. if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4)
  9905. primary->plane = !pipe;
  9906. if (INTEL_INFO(dev)->gen <= 3) {
  9907. intel_primary_formats = intel_primary_formats_gen2;
  9908. num_formats = ARRAY_SIZE(intel_primary_formats_gen2);
  9909. } else {
  9910. intel_primary_formats = intel_primary_formats_gen4;
  9911. num_formats = ARRAY_SIZE(intel_primary_formats_gen4);
  9912. }
  9913. drm_universal_plane_init(dev, &primary->base, 0,
  9914. &intel_primary_plane_funcs,
  9915. intel_primary_formats, num_formats,
  9916. DRM_PLANE_TYPE_PRIMARY);
  9917. if (INTEL_INFO(dev)->gen >= 4) {
  9918. if (!dev->mode_config.rotation_property)
  9919. dev->mode_config.rotation_property =
  9920. drm_mode_create_rotation_property(dev,
  9921. BIT(DRM_ROTATE_0) |
  9922. BIT(DRM_ROTATE_180));
  9923. if (dev->mode_config.rotation_property)
  9924. drm_object_attach_property(&primary->base.base,
  9925. dev->mode_config.rotation_property,
  9926. primary->rotation);
  9927. }
  9928. return &primary->base;
  9929. }
  9930. static int
  9931. intel_cursor_plane_disable(struct drm_plane *plane)
  9932. {
  9933. if (!plane->fb)
  9934. return 0;
  9935. BUG_ON(!plane->crtc);
  9936. return intel_crtc_cursor_set_obj(plane->crtc, NULL, 0, 0);
  9937. }
  9938. static int
  9939. intel_check_cursor_plane(struct drm_plane *plane,
  9940. struct intel_plane_state *state)
  9941. {
  9942. struct drm_crtc *crtc = state->crtc;
  9943. struct drm_device *dev = crtc->dev;
  9944. struct drm_framebuffer *fb = state->fb;
  9945. struct drm_rect *dest = &state->dst;
  9946. struct drm_rect *src = &state->src;
  9947. const struct drm_rect *clip = &state->clip;
  9948. struct drm_i915_gem_object *obj = intel_fb_obj(fb);
  9949. int crtc_w, crtc_h;
  9950. unsigned stride;
  9951. int ret;
  9952. ret = drm_plane_helper_check_update(plane, crtc, fb,
  9953. src, dest, clip,
  9954. DRM_PLANE_HELPER_NO_SCALING,
  9955. DRM_PLANE_HELPER_NO_SCALING,
  9956. true, true, &state->visible);
  9957. if (ret)
  9958. return ret;
  9959. /* if we want to turn off the cursor ignore width and height */
  9960. if (!obj)
  9961. return 0;
  9962. /* Check for which cursor types we support */
  9963. crtc_w = drm_rect_width(&state->orig_dst);
  9964. crtc_h = drm_rect_height(&state->orig_dst);
  9965. if (!cursor_size_ok(dev, crtc_w, crtc_h)) {
  9966. DRM_DEBUG("Cursor dimension not supported\n");
  9967. return -EINVAL;
  9968. }
  9969. stride = roundup_pow_of_two(crtc_w) * 4;
  9970. if (obj->base.size < stride * crtc_h) {
  9971. DRM_DEBUG_KMS("buffer is too small\n");
  9972. return -ENOMEM;
  9973. }
  9974. if (fb == crtc->cursor->fb)
  9975. return 0;
  9976. /* we only need to pin inside GTT if cursor is non-phy */
  9977. mutex_lock(&dev->struct_mutex);
  9978. if (!INTEL_INFO(dev)->cursor_needs_physical && obj->tiling_mode) {
  9979. DRM_DEBUG_KMS("cursor cannot be tiled\n");
  9980. ret = -EINVAL;
  9981. }
  9982. mutex_unlock(&dev->struct_mutex);
  9983. return ret;
  9984. }
  9985. static int
  9986. intel_commit_cursor_plane(struct drm_plane *plane,
  9987. struct intel_plane_state *state)
  9988. {
  9989. struct drm_crtc *crtc = state->crtc;
  9990. struct drm_framebuffer *fb = state->fb;
  9991. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  9992. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  9993. struct drm_i915_gem_object *obj = intel_fb->obj;
  9994. int crtc_w, crtc_h;
  9995. crtc->cursor_x = state->orig_dst.x1;
  9996. crtc->cursor_y = state->orig_dst.y1;
  9997. if (fb != crtc->cursor->fb) {
  9998. crtc_w = drm_rect_width(&state->orig_dst);
  9999. crtc_h = drm_rect_height(&state->orig_dst);
  10000. return intel_crtc_cursor_set_obj(crtc, obj, crtc_w, crtc_h);
  10001. } else {
  10002. intel_crtc_update_cursor(crtc, state->visible);
  10003. intel_frontbuffer_flip(crtc->dev,
  10004. INTEL_FRONTBUFFER_CURSOR(intel_crtc->pipe));
  10005. return 0;
  10006. }
  10007. }
  10008. static int
  10009. intel_cursor_plane_update(struct drm_plane *plane, struct drm_crtc *crtc,
  10010. struct drm_framebuffer *fb, int crtc_x, int crtc_y,
  10011. unsigned int crtc_w, unsigned int crtc_h,
  10012. uint32_t src_x, uint32_t src_y,
  10013. uint32_t src_w, uint32_t src_h)
  10014. {
  10015. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  10016. struct intel_plane_state state;
  10017. int ret;
  10018. state.crtc = crtc;
  10019. state.fb = fb;
  10020. /* sample coordinates in 16.16 fixed point */
  10021. state.src.x1 = src_x;
  10022. state.src.x2 = src_x + src_w;
  10023. state.src.y1 = src_y;
  10024. state.src.y2 = src_y + src_h;
  10025. /* integer pixels */
  10026. state.dst.x1 = crtc_x;
  10027. state.dst.x2 = crtc_x + crtc_w;
  10028. state.dst.y1 = crtc_y;
  10029. state.dst.y2 = crtc_y + crtc_h;
  10030. state.clip.x1 = 0;
  10031. state.clip.y1 = 0;
  10032. state.clip.x2 = intel_crtc->active ? intel_crtc->config.pipe_src_w : 0;
  10033. state.clip.y2 = intel_crtc->active ? intel_crtc->config.pipe_src_h : 0;
  10034. state.orig_src = state.src;
  10035. state.orig_dst = state.dst;
  10036. ret = intel_check_cursor_plane(plane, &state);
  10037. if (ret)
  10038. return ret;
  10039. return intel_commit_cursor_plane(plane, &state);
  10040. }
  10041. static const struct drm_plane_funcs intel_cursor_plane_funcs = {
  10042. .update_plane = intel_cursor_plane_update,
  10043. .disable_plane = intel_cursor_plane_disable,
  10044. .destroy = intel_plane_destroy,
  10045. .set_property = intel_plane_set_property,
  10046. };
  10047. static struct drm_plane *intel_cursor_plane_create(struct drm_device *dev,
  10048. int pipe)
  10049. {
  10050. struct intel_plane *cursor;
  10051. cursor = kzalloc(sizeof(*cursor), GFP_KERNEL);
  10052. if (cursor == NULL)
  10053. return NULL;
  10054. cursor->can_scale = false;
  10055. cursor->max_downscale = 1;
  10056. cursor->pipe = pipe;
  10057. cursor->plane = pipe;
  10058. cursor->rotation = BIT(DRM_ROTATE_0);
  10059. drm_universal_plane_init(dev, &cursor->base, 0,
  10060. &intel_cursor_plane_funcs,
  10061. intel_cursor_formats,
  10062. ARRAY_SIZE(intel_cursor_formats),
  10063. DRM_PLANE_TYPE_CURSOR);
  10064. if (INTEL_INFO(dev)->gen >= 4) {
  10065. if (!dev->mode_config.rotation_property)
  10066. dev->mode_config.rotation_property =
  10067. drm_mode_create_rotation_property(dev,
  10068. BIT(DRM_ROTATE_0) |
  10069. BIT(DRM_ROTATE_180));
  10070. if (dev->mode_config.rotation_property)
  10071. drm_object_attach_property(&cursor->base.base,
  10072. dev->mode_config.rotation_property,
  10073. cursor->rotation);
  10074. }
  10075. return &cursor->base;
  10076. }
  10077. static void intel_crtc_init(struct drm_device *dev, int pipe)
  10078. {
  10079. struct drm_i915_private *dev_priv = dev->dev_private;
  10080. struct intel_crtc *intel_crtc;
  10081. struct drm_plane *primary = NULL;
  10082. struct drm_plane *cursor = NULL;
  10083. int i, ret;
  10084. intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL);
  10085. if (intel_crtc == NULL)
  10086. return;
  10087. primary = intel_primary_plane_create(dev, pipe);
  10088. if (!primary)
  10089. goto fail;
  10090. cursor = intel_cursor_plane_create(dev, pipe);
  10091. if (!cursor)
  10092. goto fail;
  10093. ret = drm_crtc_init_with_planes(dev, &intel_crtc->base, primary,
  10094. cursor, &intel_crtc_funcs);
  10095. if (ret)
  10096. goto fail;
  10097. drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256);
  10098. for (i = 0; i < 256; i++) {
  10099. intel_crtc->lut_r[i] = i;
  10100. intel_crtc->lut_g[i] = i;
  10101. intel_crtc->lut_b[i] = i;
  10102. }
  10103. /*
  10104. * On gen2/3 only plane A can do fbc, but the panel fitter and lvds port
  10105. * is hooked to pipe B. Hence we want plane A feeding pipe B.
  10106. */
  10107. intel_crtc->pipe = pipe;
  10108. intel_crtc->plane = pipe;
  10109. if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) {
  10110. DRM_DEBUG_KMS("swapping pipes & planes for FBC\n");
  10111. intel_crtc->plane = !pipe;
  10112. }
  10113. intel_crtc->cursor_base = ~0;
  10114. intel_crtc->cursor_cntl = ~0;
  10115. intel_crtc->cursor_size = ~0;
  10116. BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
  10117. dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL);
  10118. dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base;
  10119. dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base;
  10120. drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
  10121. WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe);
  10122. return;
  10123. fail:
  10124. if (primary)
  10125. drm_plane_cleanup(primary);
  10126. if (cursor)
  10127. drm_plane_cleanup(cursor);
  10128. kfree(intel_crtc);
  10129. }
  10130. enum pipe intel_get_pipe_from_connector(struct intel_connector *connector)
  10131. {
  10132. struct drm_encoder *encoder = connector->base.encoder;
  10133. struct drm_device *dev = connector->base.dev;
  10134. WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
  10135. if (!encoder)
  10136. return INVALID_PIPE;
  10137. return to_intel_crtc(encoder->crtc)->pipe;
  10138. }
  10139. int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data,
  10140. struct drm_file *file)
  10141. {
  10142. struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
  10143. struct drm_crtc *drmmode_crtc;
  10144. struct intel_crtc *crtc;
  10145. if (!drm_core_check_feature(dev, DRIVER_MODESET))
  10146. return -ENODEV;
  10147. drmmode_crtc = drm_crtc_find(dev, pipe_from_crtc_id->crtc_id);
  10148. if (!drmmode_crtc) {
  10149. DRM_ERROR("no such CRTC id\n");
  10150. return -ENOENT;
  10151. }
  10152. crtc = to_intel_crtc(drmmode_crtc);
  10153. pipe_from_crtc_id->pipe = crtc->pipe;
  10154. return 0;
  10155. }
  10156. static int intel_encoder_clones(struct intel_encoder *encoder)
  10157. {
  10158. struct drm_device *dev = encoder->base.dev;
  10159. struct intel_encoder *source_encoder;
  10160. int index_mask = 0;
  10161. int entry = 0;
  10162. for_each_intel_encoder(dev, source_encoder) {
  10163. if (encoders_cloneable(encoder, source_encoder))
  10164. index_mask |= (1 << entry);
  10165. entry++;
  10166. }
  10167. return index_mask;
  10168. }
  10169. static bool has_edp_a(struct drm_device *dev)
  10170. {
  10171. struct drm_i915_private *dev_priv = dev->dev_private;
  10172. if (!IS_MOBILE(dev))
  10173. return false;
  10174. if ((I915_READ(DP_A) & DP_DETECTED) == 0)
  10175. return false;
  10176. if (IS_GEN5(dev) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE))
  10177. return false;
  10178. return true;
  10179. }
  10180. const char *intel_output_name(int output)
  10181. {
  10182. static const char *names[] = {
  10183. [INTEL_OUTPUT_UNUSED] = "Unused",
  10184. [INTEL_OUTPUT_ANALOG] = "Analog",
  10185. [INTEL_OUTPUT_DVO] = "DVO",
  10186. [INTEL_OUTPUT_SDVO] = "SDVO",
  10187. [INTEL_OUTPUT_LVDS] = "LVDS",
  10188. [INTEL_OUTPUT_TVOUT] = "TV",
  10189. [INTEL_OUTPUT_HDMI] = "HDMI",
  10190. [INTEL_OUTPUT_DISPLAYPORT] = "DisplayPort",
  10191. [INTEL_OUTPUT_EDP] = "eDP",
  10192. [INTEL_OUTPUT_DSI] = "DSI",
  10193. [INTEL_OUTPUT_UNKNOWN] = "Unknown",
  10194. };
  10195. if (output < 0 || output >= ARRAY_SIZE(names) || !names[output])
  10196. return "Invalid";
  10197. return names[output];
  10198. }
  10199. static bool intel_crt_present(struct drm_device *dev)
  10200. {
  10201. struct drm_i915_private *dev_priv = dev->dev_private;
  10202. if (INTEL_INFO(dev)->gen >= 9)
  10203. return false;
  10204. if (IS_HSW_ULT(dev) || IS_BDW_ULT(dev))
  10205. return false;
  10206. if (IS_CHERRYVIEW(dev))
  10207. return false;
  10208. if (IS_VALLEYVIEW(dev) && !dev_priv->vbt.int_crt_support)
  10209. return false;
  10210. return true;
  10211. }
  10212. static void intel_setup_outputs(struct drm_device *dev)
  10213. {
  10214. struct drm_i915_private *dev_priv = dev->dev_private;
  10215. struct intel_encoder *encoder;
  10216. bool dpd_is_edp = false;
  10217. intel_lvds_init(dev);
  10218. if (intel_crt_present(dev))
  10219. intel_crt_init(dev);
  10220. if (HAS_DDI(dev)) {
  10221. int found;
  10222. /* Haswell uses DDI functions to detect digital outputs */
  10223. found = I915_READ(DDI_BUF_CTL_A) & DDI_INIT_DISPLAY_DETECTED;
  10224. /* DDI A only supports eDP */
  10225. if (found)
  10226. intel_ddi_init(dev, PORT_A);
  10227. /* DDI B, C and D detection is indicated by the SFUSE_STRAP
  10228. * register */
  10229. found = I915_READ(SFUSE_STRAP);
  10230. if (found & SFUSE_STRAP_DDIB_DETECTED)
  10231. intel_ddi_init(dev, PORT_B);
  10232. if (found & SFUSE_STRAP_DDIC_DETECTED)
  10233. intel_ddi_init(dev, PORT_C);
  10234. if (found & SFUSE_STRAP_DDID_DETECTED)
  10235. intel_ddi_init(dev, PORT_D);
  10236. } else if (HAS_PCH_SPLIT(dev)) {
  10237. int found;
  10238. dpd_is_edp = intel_dp_is_edp(dev, PORT_D);
  10239. if (has_edp_a(dev))
  10240. intel_dp_init(dev, DP_A, PORT_A);
  10241. if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) {
  10242. /* PCH SDVOB multiplex with HDMIB */
  10243. found = intel_sdvo_init(dev, PCH_SDVOB, true);
  10244. if (!found)
  10245. intel_hdmi_init(dev, PCH_HDMIB, PORT_B);
  10246. if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
  10247. intel_dp_init(dev, PCH_DP_B, PORT_B);
  10248. }
  10249. if (I915_READ(PCH_HDMIC) & SDVO_DETECTED)
  10250. intel_hdmi_init(dev, PCH_HDMIC, PORT_C);
  10251. if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED)
  10252. intel_hdmi_init(dev, PCH_HDMID, PORT_D);
  10253. if (I915_READ(PCH_DP_C) & DP_DETECTED)
  10254. intel_dp_init(dev, PCH_DP_C, PORT_C);
  10255. if (I915_READ(PCH_DP_D) & DP_DETECTED)
  10256. intel_dp_init(dev, PCH_DP_D, PORT_D);
  10257. } else if (IS_VALLEYVIEW(dev)) {
  10258. /*
  10259. * The DP_DETECTED bit is the latched state of the DDC
  10260. * SDA pin at boot. However since eDP doesn't require DDC
  10261. * (no way to plug in a DP->HDMI dongle) the DDC pins for
  10262. * eDP ports may have been muxed to an alternate function.
  10263. * Thus we can't rely on the DP_DETECTED bit alone to detect
  10264. * eDP ports. Consult the VBT as well as DP_DETECTED to
  10265. * detect eDP ports.
  10266. */
  10267. if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIB) & SDVO_DETECTED)
  10268. intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIB,
  10269. PORT_B);
  10270. if (I915_READ(VLV_DISPLAY_BASE + DP_B) & DP_DETECTED ||
  10271. intel_dp_is_edp(dev, PORT_B))
  10272. intel_dp_init(dev, VLV_DISPLAY_BASE + DP_B, PORT_B);
  10273. if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIC) & SDVO_DETECTED)
  10274. intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIC,
  10275. PORT_C);
  10276. if (I915_READ(VLV_DISPLAY_BASE + DP_C) & DP_DETECTED ||
  10277. intel_dp_is_edp(dev, PORT_C))
  10278. intel_dp_init(dev, VLV_DISPLAY_BASE + DP_C, PORT_C);
  10279. if (IS_CHERRYVIEW(dev)) {
  10280. if (I915_READ(VLV_DISPLAY_BASE + CHV_HDMID) & SDVO_DETECTED)
  10281. intel_hdmi_init(dev, VLV_DISPLAY_BASE + CHV_HDMID,
  10282. PORT_D);
  10283. /* eDP not supported on port D, so don't check VBT */
  10284. if (I915_READ(VLV_DISPLAY_BASE + DP_D) & DP_DETECTED)
  10285. intel_dp_init(dev, VLV_DISPLAY_BASE + DP_D, PORT_D);
  10286. }
  10287. intel_dsi_init(dev);
  10288. } else if (SUPPORTS_DIGITAL_OUTPUTS(dev)) {
  10289. bool found = false;
  10290. if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
  10291. DRM_DEBUG_KMS("probing SDVOB\n");
  10292. found = intel_sdvo_init(dev, GEN3_SDVOB, true);
  10293. if (!found && SUPPORTS_INTEGRATED_HDMI(dev)) {
  10294. DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
  10295. intel_hdmi_init(dev, GEN4_HDMIB, PORT_B);
  10296. }
  10297. if (!found && SUPPORTS_INTEGRATED_DP(dev))
  10298. intel_dp_init(dev, DP_B, PORT_B);
  10299. }
  10300. /* Before G4X SDVOC doesn't have its own detect register */
  10301. if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
  10302. DRM_DEBUG_KMS("probing SDVOC\n");
  10303. found = intel_sdvo_init(dev, GEN3_SDVOC, false);
  10304. }
  10305. if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) {
  10306. if (SUPPORTS_INTEGRATED_HDMI(dev)) {
  10307. DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
  10308. intel_hdmi_init(dev, GEN4_HDMIC, PORT_C);
  10309. }
  10310. if (SUPPORTS_INTEGRATED_DP(dev))
  10311. intel_dp_init(dev, DP_C, PORT_C);
  10312. }
  10313. if (SUPPORTS_INTEGRATED_DP(dev) &&
  10314. (I915_READ(DP_D) & DP_DETECTED))
  10315. intel_dp_init(dev, DP_D, PORT_D);
  10316. } else if (IS_GEN2(dev))
  10317. intel_dvo_init(dev);
  10318. if (SUPPORTS_TV(dev))
  10319. intel_tv_init(dev);
  10320. intel_edp_psr_init(dev);
  10321. for_each_intel_encoder(dev, encoder) {
  10322. encoder->base.possible_crtcs = encoder->crtc_mask;
  10323. encoder->base.possible_clones =
  10324. intel_encoder_clones(encoder);
  10325. }
  10326. intel_init_pch_refclk(dev);
  10327. drm_helper_move_panel_connectors_to_head(dev);
  10328. }
  10329. static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
  10330. {
  10331. struct drm_device *dev = fb->dev;
  10332. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  10333. drm_framebuffer_cleanup(fb);
  10334. mutex_lock(&dev->struct_mutex);
  10335. WARN_ON(!intel_fb->obj->framebuffer_references--);
  10336. drm_gem_object_unreference(&intel_fb->obj->base);
  10337. mutex_unlock(&dev->struct_mutex);
  10338. kfree(intel_fb);
  10339. }
  10340. static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
  10341. struct drm_file *file,
  10342. unsigned int *handle)
  10343. {
  10344. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  10345. struct drm_i915_gem_object *obj = intel_fb->obj;
  10346. return drm_gem_handle_create(file, &obj->base, handle);
  10347. }
  10348. static const struct drm_framebuffer_funcs intel_fb_funcs = {
  10349. .destroy = intel_user_framebuffer_destroy,
  10350. .create_handle = intel_user_framebuffer_create_handle,
  10351. };
  10352. static int intel_framebuffer_init(struct drm_device *dev,
  10353. struct intel_framebuffer *intel_fb,
  10354. struct drm_mode_fb_cmd2 *mode_cmd,
  10355. struct drm_i915_gem_object *obj)
  10356. {
  10357. int aligned_height;
  10358. int pitch_limit;
  10359. int ret;
  10360. WARN_ON(!mutex_is_locked(&dev->struct_mutex));
  10361. if (obj->tiling_mode == I915_TILING_Y) {
  10362. DRM_DEBUG("hardware does not support tiling Y\n");
  10363. return -EINVAL;
  10364. }
  10365. if (mode_cmd->pitches[0] & 63) {
  10366. DRM_DEBUG("pitch (%d) must be at least 64 byte aligned\n",
  10367. mode_cmd->pitches[0]);
  10368. return -EINVAL;
  10369. }
  10370. if (INTEL_INFO(dev)->gen >= 5 && !IS_VALLEYVIEW(dev)) {
  10371. pitch_limit = 32*1024;
  10372. } else if (INTEL_INFO(dev)->gen >= 4) {
  10373. if (obj->tiling_mode)
  10374. pitch_limit = 16*1024;
  10375. else
  10376. pitch_limit = 32*1024;
  10377. } else if (INTEL_INFO(dev)->gen >= 3) {
  10378. if (obj->tiling_mode)
  10379. pitch_limit = 8*1024;
  10380. else
  10381. pitch_limit = 16*1024;
  10382. } else
  10383. /* XXX DSPC is limited to 4k tiled */
  10384. pitch_limit = 8*1024;
  10385. if (mode_cmd->pitches[0] > pitch_limit) {
  10386. DRM_DEBUG("%s pitch (%d) must be at less than %d\n",
  10387. obj->tiling_mode ? "tiled" : "linear",
  10388. mode_cmd->pitches[0], pitch_limit);
  10389. return -EINVAL;
  10390. }
  10391. if (obj->tiling_mode != I915_TILING_NONE &&
  10392. mode_cmd->pitches[0] != obj->stride) {
  10393. DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n",
  10394. mode_cmd->pitches[0], obj->stride);
  10395. return -EINVAL;
  10396. }
  10397. /* Reject formats not supported by any plane early. */
  10398. switch (mode_cmd->pixel_format) {
  10399. case DRM_FORMAT_C8:
  10400. case DRM_FORMAT_RGB565:
  10401. case DRM_FORMAT_XRGB8888:
  10402. case DRM_FORMAT_ARGB8888:
  10403. break;
  10404. case DRM_FORMAT_XRGB1555:
  10405. case DRM_FORMAT_ARGB1555:
  10406. if (INTEL_INFO(dev)->gen > 3) {
  10407. DRM_DEBUG("unsupported pixel format: %s\n",
  10408. drm_get_format_name(mode_cmd->pixel_format));
  10409. return -EINVAL;
  10410. }
  10411. break;
  10412. case DRM_FORMAT_XBGR8888:
  10413. case DRM_FORMAT_ABGR8888:
  10414. case DRM_FORMAT_XRGB2101010:
  10415. case DRM_FORMAT_ARGB2101010:
  10416. case DRM_FORMAT_XBGR2101010:
  10417. case DRM_FORMAT_ABGR2101010:
  10418. if (INTEL_INFO(dev)->gen < 4) {
  10419. DRM_DEBUG("unsupported pixel format: %s\n",
  10420. drm_get_format_name(mode_cmd->pixel_format));
  10421. return -EINVAL;
  10422. }
  10423. break;
  10424. case DRM_FORMAT_YUYV:
  10425. case DRM_FORMAT_UYVY:
  10426. case DRM_FORMAT_YVYU:
  10427. case DRM_FORMAT_VYUY:
  10428. if (INTEL_INFO(dev)->gen < 5) {
  10429. DRM_DEBUG("unsupported pixel format: %s\n",
  10430. drm_get_format_name(mode_cmd->pixel_format));
  10431. return -EINVAL;
  10432. }
  10433. break;
  10434. default:
  10435. DRM_DEBUG("unsupported pixel format: %s\n",
  10436. drm_get_format_name(mode_cmd->pixel_format));
  10437. return -EINVAL;
  10438. }
  10439. /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
  10440. if (mode_cmd->offsets[0] != 0)
  10441. return -EINVAL;
  10442. aligned_height = intel_align_height(dev, mode_cmd->height,
  10443. obj->tiling_mode);
  10444. /* FIXME drm helper for size checks (especially planar formats)? */
  10445. if (obj->base.size < aligned_height * mode_cmd->pitches[0])
  10446. return -EINVAL;
  10447. drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd);
  10448. intel_fb->obj = obj;
  10449. intel_fb->obj->framebuffer_references++;
  10450. ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs);
  10451. if (ret) {
  10452. DRM_ERROR("framebuffer init failed %d\n", ret);
  10453. return ret;
  10454. }
  10455. return 0;
  10456. }
  10457. static struct drm_framebuffer *
  10458. intel_user_framebuffer_create(struct drm_device *dev,
  10459. struct drm_file *filp,
  10460. struct drm_mode_fb_cmd2 *mode_cmd)
  10461. {
  10462. struct drm_i915_gem_object *obj;
  10463. obj = to_intel_bo(drm_gem_object_lookup(dev, filp,
  10464. mode_cmd->handles[0]));
  10465. if (&obj->base == NULL)
  10466. return ERR_PTR(-ENOENT);
  10467. return intel_framebuffer_create(dev, mode_cmd, obj);
  10468. }
  10469. #ifndef CONFIG_DRM_I915_FBDEV
  10470. static inline void intel_fbdev_output_poll_changed(struct drm_device *dev)
  10471. {
  10472. }
  10473. #endif
  10474. static const struct drm_mode_config_funcs intel_mode_funcs = {
  10475. .fb_create = intel_user_framebuffer_create,
  10476. .output_poll_changed = intel_fbdev_output_poll_changed,
  10477. };
  10478. /* Set up chip specific display functions */
  10479. static void intel_init_display(struct drm_device *dev)
  10480. {
  10481. struct drm_i915_private *dev_priv = dev->dev_private;
  10482. if (HAS_PCH_SPLIT(dev) || IS_G4X(dev))
  10483. dev_priv->display.find_dpll = g4x_find_best_dpll;
  10484. else if (IS_CHERRYVIEW(dev))
  10485. dev_priv->display.find_dpll = chv_find_best_dpll;
  10486. else if (IS_VALLEYVIEW(dev))
  10487. dev_priv->display.find_dpll = vlv_find_best_dpll;
  10488. else if (IS_PINEVIEW(dev))
  10489. dev_priv->display.find_dpll = pnv_find_best_dpll;
  10490. else
  10491. dev_priv->display.find_dpll = i9xx_find_best_dpll;
  10492. if (HAS_DDI(dev)) {
  10493. dev_priv->display.get_pipe_config = haswell_get_pipe_config;
  10494. dev_priv->display.get_plane_config = ironlake_get_plane_config;
  10495. dev_priv->display.crtc_mode_set = haswell_crtc_mode_set;
  10496. dev_priv->display.crtc_enable = haswell_crtc_enable;
  10497. dev_priv->display.crtc_disable = haswell_crtc_disable;
  10498. dev_priv->display.off = ironlake_crtc_off;
  10499. if (INTEL_INFO(dev)->gen >= 9)
  10500. dev_priv->display.update_primary_plane =
  10501. skylake_update_primary_plane;
  10502. else
  10503. dev_priv->display.update_primary_plane =
  10504. ironlake_update_primary_plane;
  10505. } else if (HAS_PCH_SPLIT(dev)) {
  10506. dev_priv->display.get_pipe_config = ironlake_get_pipe_config;
  10507. dev_priv->display.get_plane_config = ironlake_get_plane_config;
  10508. dev_priv->display.crtc_mode_set = ironlake_crtc_mode_set;
  10509. dev_priv->display.crtc_enable = ironlake_crtc_enable;
  10510. dev_priv->display.crtc_disable = ironlake_crtc_disable;
  10511. dev_priv->display.off = ironlake_crtc_off;
  10512. dev_priv->display.update_primary_plane =
  10513. ironlake_update_primary_plane;
  10514. } else if (IS_VALLEYVIEW(dev)) {
  10515. dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
  10516. dev_priv->display.get_plane_config = i9xx_get_plane_config;
  10517. dev_priv->display.crtc_mode_set = i9xx_crtc_mode_set;
  10518. dev_priv->display.crtc_enable = valleyview_crtc_enable;
  10519. dev_priv->display.crtc_disable = i9xx_crtc_disable;
  10520. dev_priv->display.off = i9xx_crtc_off;
  10521. dev_priv->display.update_primary_plane =
  10522. i9xx_update_primary_plane;
  10523. } else {
  10524. dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
  10525. dev_priv->display.get_plane_config = i9xx_get_plane_config;
  10526. dev_priv->display.crtc_mode_set = i9xx_crtc_mode_set;
  10527. dev_priv->display.crtc_enable = i9xx_crtc_enable;
  10528. dev_priv->display.crtc_disable = i9xx_crtc_disable;
  10529. dev_priv->display.off = i9xx_crtc_off;
  10530. dev_priv->display.update_primary_plane =
  10531. i9xx_update_primary_plane;
  10532. }
  10533. /* Returns the core display clock speed */
  10534. if (IS_VALLEYVIEW(dev))
  10535. dev_priv->display.get_display_clock_speed =
  10536. valleyview_get_display_clock_speed;
  10537. else if (IS_I945G(dev) || (IS_G33(dev) && !IS_PINEVIEW_M(dev)))
  10538. dev_priv->display.get_display_clock_speed =
  10539. i945_get_display_clock_speed;
  10540. else if (IS_I915G(dev))
  10541. dev_priv->display.get_display_clock_speed =
  10542. i915_get_display_clock_speed;
  10543. else if (IS_I945GM(dev) || IS_845G(dev))
  10544. dev_priv->display.get_display_clock_speed =
  10545. i9xx_misc_get_display_clock_speed;
  10546. else if (IS_PINEVIEW(dev))
  10547. dev_priv->display.get_display_clock_speed =
  10548. pnv_get_display_clock_speed;
  10549. else if (IS_I915GM(dev))
  10550. dev_priv->display.get_display_clock_speed =
  10551. i915gm_get_display_clock_speed;
  10552. else if (IS_I865G(dev))
  10553. dev_priv->display.get_display_clock_speed =
  10554. i865_get_display_clock_speed;
  10555. else if (IS_I85X(dev))
  10556. dev_priv->display.get_display_clock_speed =
  10557. i855_get_display_clock_speed;
  10558. else /* 852, 830 */
  10559. dev_priv->display.get_display_clock_speed =
  10560. i830_get_display_clock_speed;
  10561. if (IS_G4X(dev)) {
  10562. dev_priv->display.write_eld = g4x_write_eld;
  10563. } else if (IS_GEN5(dev)) {
  10564. dev_priv->display.fdi_link_train = ironlake_fdi_link_train;
  10565. dev_priv->display.write_eld = ironlake_write_eld;
  10566. } else if (IS_GEN6(dev)) {
  10567. dev_priv->display.fdi_link_train = gen6_fdi_link_train;
  10568. dev_priv->display.write_eld = ironlake_write_eld;
  10569. dev_priv->display.modeset_global_resources =
  10570. snb_modeset_global_resources;
  10571. } else if (IS_IVYBRIDGE(dev)) {
  10572. /* FIXME: detect B0+ stepping and use auto training */
  10573. dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train;
  10574. dev_priv->display.write_eld = ironlake_write_eld;
  10575. dev_priv->display.modeset_global_resources =
  10576. ivb_modeset_global_resources;
  10577. } else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
  10578. dev_priv->display.fdi_link_train = hsw_fdi_link_train;
  10579. dev_priv->display.write_eld = haswell_write_eld;
  10580. dev_priv->display.modeset_global_resources =
  10581. haswell_modeset_global_resources;
  10582. } else if (IS_VALLEYVIEW(dev)) {
  10583. dev_priv->display.modeset_global_resources =
  10584. valleyview_modeset_global_resources;
  10585. dev_priv->display.write_eld = ironlake_write_eld;
  10586. } else if (INTEL_INFO(dev)->gen >= 9) {
  10587. dev_priv->display.write_eld = haswell_write_eld;
  10588. dev_priv->display.modeset_global_resources =
  10589. haswell_modeset_global_resources;
  10590. }
  10591. /* Default just returns -ENODEV to indicate unsupported */
  10592. dev_priv->display.queue_flip = intel_default_queue_flip;
  10593. switch (INTEL_INFO(dev)->gen) {
  10594. case 2:
  10595. dev_priv->display.queue_flip = intel_gen2_queue_flip;
  10596. break;
  10597. case 3:
  10598. dev_priv->display.queue_flip = intel_gen3_queue_flip;
  10599. break;
  10600. case 4:
  10601. case 5:
  10602. dev_priv->display.queue_flip = intel_gen4_queue_flip;
  10603. break;
  10604. case 6:
  10605. dev_priv->display.queue_flip = intel_gen6_queue_flip;
  10606. break;
  10607. case 7:
  10608. case 8: /* FIXME(BDW): Check that the gen8 RCS flip works. */
  10609. dev_priv->display.queue_flip = intel_gen7_queue_flip;
  10610. break;
  10611. }
  10612. intel_panel_init_backlight_funcs(dev);
  10613. mutex_init(&dev_priv->pps_mutex);
  10614. }
  10615. /*
  10616. * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend,
  10617. * resume, or other times. This quirk makes sure that's the case for
  10618. * affected systems.
  10619. */
  10620. static void quirk_pipea_force(struct drm_device *dev)
  10621. {
  10622. struct drm_i915_private *dev_priv = dev->dev_private;
  10623. dev_priv->quirks |= QUIRK_PIPEA_FORCE;
  10624. DRM_INFO("applying pipe a force quirk\n");
  10625. }
  10626. static void quirk_pipeb_force(struct drm_device *dev)
  10627. {
  10628. struct drm_i915_private *dev_priv = dev->dev_private;
  10629. dev_priv->quirks |= QUIRK_PIPEB_FORCE;
  10630. DRM_INFO("applying pipe b force quirk\n");
  10631. }
  10632. /*
  10633. * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason
  10634. */
  10635. static void quirk_ssc_force_disable(struct drm_device *dev)
  10636. {
  10637. struct drm_i915_private *dev_priv = dev->dev_private;
  10638. dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE;
  10639. DRM_INFO("applying lvds SSC disable quirk\n");
  10640. }
  10641. /*
  10642. * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight
  10643. * brightness value
  10644. */
  10645. static void quirk_invert_brightness(struct drm_device *dev)
  10646. {
  10647. struct drm_i915_private *dev_priv = dev->dev_private;
  10648. dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS;
  10649. DRM_INFO("applying inverted panel brightness quirk\n");
  10650. }
  10651. /* Some VBT's incorrectly indicate no backlight is present */
  10652. static void quirk_backlight_present(struct drm_device *dev)
  10653. {
  10654. struct drm_i915_private *dev_priv = dev->dev_private;
  10655. dev_priv->quirks |= QUIRK_BACKLIGHT_PRESENT;
  10656. DRM_INFO("applying backlight present quirk\n");
  10657. }
  10658. struct intel_quirk {
  10659. int device;
  10660. int subsystem_vendor;
  10661. int subsystem_device;
  10662. void (*hook)(struct drm_device *dev);
  10663. };
  10664. /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
  10665. struct intel_dmi_quirk {
  10666. void (*hook)(struct drm_device *dev);
  10667. const struct dmi_system_id (*dmi_id_list)[];
  10668. };
  10669. static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
  10670. {
  10671. DRM_INFO("Backlight polarity reversed on %s\n", id->ident);
  10672. return 1;
  10673. }
  10674. static const struct intel_dmi_quirk intel_dmi_quirks[] = {
  10675. {
  10676. .dmi_id_list = &(const struct dmi_system_id[]) {
  10677. {
  10678. .callback = intel_dmi_reverse_brightness,
  10679. .ident = "NCR Corporation",
  10680. .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
  10681. DMI_MATCH(DMI_PRODUCT_NAME, ""),
  10682. },
  10683. },
  10684. { } /* terminating entry */
  10685. },
  10686. .hook = quirk_invert_brightness,
  10687. },
  10688. };
  10689. static struct intel_quirk intel_quirks[] = {
  10690. /* HP Mini needs pipe A force quirk (LP: #322104) */
  10691. { 0x27ae, 0x103c, 0x361a, quirk_pipea_force },
  10692. /* Toshiba Protege R-205, S-209 needs pipe A force quirk */
  10693. { 0x2592, 0x1179, 0x0001, quirk_pipea_force },
  10694. /* ThinkPad T60 needs pipe A force quirk (bug #16494) */
  10695. { 0x2782, 0x17aa, 0x201a, quirk_pipea_force },
  10696. /* 830 needs to leave pipe A & dpll A up */
  10697. { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force },
  10698. /* 830 needs to leave pipe B & dpll B up */
  10699. { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipeb_force },
  10700. /* Lenovo U160 cannot use SSC on LVDS */
  10701. { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable },
  10702. /* Sony Vaio Y cannot use SSC on LVDS */
  10703. { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable },
  10704. /* Acer Aspire 5734Z must invert backlight brightness */
  10705. { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness },
  10706. /* Acer/eMachines G725 */
  10707. { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness },
  10708. /* Acer/eMachines e725 */
  10709. { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness },
  10710. /* Acer/Packard Bell NCL20 */
  10711. { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness },
  10712. /* Acer Aspire 4736Z */
  10713. { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness },
  10714. /* Acer Aspire 5336 */
  10715. { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness },
  10716. /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */
  10717. { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present },
  10718. /* Acer C720 Chromebook (Core i3 4005U) */
  10719. { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present },
  10720. /* Toshiba CB35 Chromebook (Celeron 2955U) */
  10721. { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present },
  10722. /* HP Chromebook 14 (Celeron 2955U) */
  10723. { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present },
  10724. };
  10725. static void intel_init_quirks(struct drm_device *dev)
  10726. {
  10727. struct pci_dev *d = dev->pdev;
  10728. int i;
  10729. for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) {
  10730. struct intel_quirk *q = &intel_quirks[i];
  10731. if (d->device == q->device &&
  10732. (d->subsystem_vendor == q->subsystem_vendor ||
  10733. q->subsystem_vendor == PCI_ANY_ID) &&
  10734. (d->subsystem_device == q->subsystem_device ||
  10735. q->subsystem_device == PCI_ANY_ID))
  10736. q->hook(dev);
  10737. }
  10738. for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) {
  10739. if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0)
  10740. intel_dmi_quirks[i].hook(dev);
  10741. }
  10742. }
  10743. /* Disable the VGA plane that we never use */
  10744. static void i915_disable_vga(struct drm_device *dev)
  10745. {
  10746. struct drm_i915_private *dev_priv = dev->dev_private;
  10747. u8 sr1;
  10748. u32 vga_reg = i915_vgacntrl_reg(dev);
  10749. /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
  10750. vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO);
  10751. outb(SR01, VGA_SR_INDEX);
  10752. sr1 = inb(VGA_SR_DATA);
  10753. outb(sr1 | 1<<5, VGA_SR_DATA);
  10754. vga_put(dev->pdev, VGA_RSRC_LEGACY_IO);
  10755. udelay(300);
  10756. /*
  10757. * Fujitsu-Siemens Lifebook S6010 (830) has problems resuming
  10758. * from S3 without preserving (some of?) the other bits.
  10759. */
  10760. I915_WRITE(vga_reg, dev_priv->bios_vgacntr | VGA_DISP_DISABLE);
  10761. POSTING_READ(vga_reg);
  10762. }
  10763. void intel_modeset_init_hw(struct drm_device *dev)
  10764. {
  10765. intel_prepare_ddi(dev);
  10766. if (IS_VALLEYVIEW(dev))
  10767. vlv_update_cdclk(dev);
  10768. intel_init_clock_gating(dev);
  10769. intel_enable_gt_powersave(dev);
  10770. }
  10771. void intel_modeset_init(struct drm_device *dev)
  10772. {
  10773. struct drm_i915_private *dev_priv = dev->dev_private;
  10774. int sprite, ret;
  10775. enum pipe pipe;
  10776. struct intel_crtc *crtc;
  10777. drm_mode_config_init(dev);
  10778. dev->mode_config.min_width = 0;
  10779. dev->mode_config.min_height = 0;
  10780. dev->mode_config.preferred_depth = 24;
  10781. dev->mode_config.prefer_shadow = 1;
  10782. dev->mode_config.funcs = &intel_mode_funcs;
  10783. intel_init_quirks(dev);
  10784. intel_init_pm(dev);
  10785. if (INTEL_INFO(dev)->num_pipes == 0)
  10786. return;
  10787. intel_init_display(dev);
  10788. if (IS_GEN2(dev)) {
  10789. dev->mode_config.max_width = 2048;
  10790. dev->mode_config.max_height = 2048;
  10791. } else if (IS_GEN3(dev)) {
  10792. dev->mode_config.max_width = 4096;
  10793. dev->mode_config.max_height = 4096;
  10794. } else {
  10795. dev->mode_config.max_width = 8192;
  10796. dev->mode_config.max_height = 8192;
  10797. }
  10798. if (IS_845G(dev) || IS_I865G(dev)) {
  10799. dev->mode_config.cursor_width = IS_845G(dev) ? 64 : 512;
  10800. dev->mode_config.cursor_height = 1023;
  10801. } else if (IS_GEN2(dev)) {
  10802. dev->mode_config.cursor_width = GEN2_CURSOR_WIDTH;
  10803. dev->mode_config.cursor_height = GEN2_CURSOR_HEIGHT;
  10804. } else {
  10805. dev->mode_config.cursor_width = MAX_CURSOR_WIDTH;
  10806. dev->mode_config.cursor_height = MAX_CURSOR_HEIGHT;
  10807. }
  10808. dev->mode_config.fb_base = dev_priv->gtt.mappable_base;
  10809. DRM_DEBUG_KMS("%d display pipe%s available.\n",
  10810. INTEL_INFO(dev)->num_pipes,
  10811. INTEL_INFO(dev)->num_pipes > 1 ? "s" : "");
  10812. for_each_pipe(dev_priv, pipe) {
  10813. intel_crtc_init(dev, pipe);
  10814. for_each_sprite(pipe, sprite) {
  10815. ret = intel_plane_init(dev, pipe, sprite);
  10816. if (ret)
  10817. DRM_DEBUG_KMS("pipe %c sprite %c init failed: %d\n",
  10818. pipe_name(pipe), sprite_name(pipe, sprite), ret);
  10819. }
  10820. }
  10821. intel_init_dpio(dev);
  10822. intel_shared_dpll_init(dev);
  10823. /* save the BIOS value before clobbering it */
  10824. dev_priv->bios_vgacntr = I915_READ(i915_vgacntrl_reg(dev));
  10825. /* Just disable it once at startup */
  10826. i915_disable_vga(dev);
  10827. intel_setup_outputs(dev);
  10828. /* Just in case the BIOS is doing something questionable. */
  10829. intel_disable_fbc(dev);
  10830. drm_modeset_lock_all(dev);
  10831. intel_modeset_setup_hw_state(dev, false);
  10832. drm_modeset_unlock_all(dev);
  10833. for_each_intel_crtc(dev, crtc) {
  10834. if (!crtc->active)
  10835. continue;
  10836. /*
  10837. * Note that reserving the BIOS fb up front prevents us
  10838. * from stuffing other stolen allocations like the ring
  10839. * on top. This prevents some ugliness at boot time, and
  10840. * can even allow for smooth boot transitions if the BIOS
  10841. * fb is large enough for the active pipe configuration.
  10842. */
  10843. if (dev_priv->display.get_plane_config) {
  10844. dev_priv->display.get_plane_config(crtc,
  10845. &crtc->plane_config);
  10846. /*
  10847. * If the fb is shared between multiple heads, we'll
  10848. * just get the first one.
  10849. */
  10850. intel_find_plane_obj(crtc, &crtc->plane_config);
  10851. }
  10852. }
  10853. }
  10854. static void intel_enable_pipe_a(struct drm_device *dev)
  10855. {
  10856. struct intel_connector *connector;
  10857. struct drm_connector *crt = NULL;
  10858. struct intel_load_detect_pipe load_detect_temp;
  10859. struct drm_modeset_acquire_ctx *ctx = dev->mode_config.acquire_ctx;
  10860. /* We can't just switch on the pipe A, we need to set things up with a
  10861. * proper mode and output configuration. As a gross hack, enable pipe A
  10862. * by enabling the load detect pipe once. */
  10863. list_for_each_entry(connector,
  10864. &dev->mode_config.connector_list,
  10865. base.head) {
  10866. if (connector->encoder->type == INTEL_OUTPUT_ANALOG) {
  10867. crt = &connector->base;
  10868. break;
  10869. }
  10870. }
  10871. if (!crt)
  10872. return;
  10873. if (intel_get_load_detect_pipe(crt, NULL, &load_detect_temp, ctx))
  10874. intel_release_load_detect_pipe(crt, &load_detect_temp);
  10875. }
  10876. static bool
  10877. intel_check_plane_mapping(struct intel_crtc *crtc)
  10878. {
  10879. struct drm_device *dev = crtc->base.dev;
  10880. struct drm_i915_private *dev_priv = dev->dev_private;
  10881. u32 reg, val;
  10882. if (INTEL_INFO(dev)->num_pipes == 1)
  10883. return true;
  10884. reg = DSPCNTR(!crtc->plane);
  10885. val = I915_READ(reg);
  10886. if ((val & DISPLAY_PLANE_ENABLE) &&
  10887. (!!(val & DISPPLANE_SEL_PIPE_MASK) == crtc->pipe))
  10888. return false;
  10889. return true;
  10890. }
  10891. static void intel_sanitize_crtc(struct intel_crtc *crtc)
  10892. {
  10893. struct drm_device *dev = crtc->base.dev;
  10894. struct drm_i915_private *dev_priv = dev->dev_private;
  10895. u32 reg;
  10896. /* Clear any frame start delays used for debugging left by the BIOS */
  10897. reg = PIPECONF(crtc->config.cpu_transcoder);
  10898. I915_WRITE(reg, I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK);
  10899. /* restore vblank interrupts to correct state */
  10900. if (crtc->active) {
  10901. update_scanline_offset(crtc);
  10902. drm_vblank_on(dev, crtc->pipe);
  10903. } else
  10904. drm_vblank_off(dev, crtc->pipe);
  10905. /* We need to sanitize the plane -> pipe mapping first because this will
  10906. * disable the crtc (and hence change the state) if it is wrong. Note
  10907. * that gen4+ has a fixed plane -> pipe mapping. */
  10908. if (INTEL_INFO(dev)->gen < 4 && !intel_check_plane_mapping(crtc)) {
  10909. struct intel_connector *connector;
  10910. bool plane;
  10911. DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n",
  10912. crtc->base.base.id);
  10913. /* Pipe has the wrong plane attached and the plane is active.
  10914. * Temporarily change the plane mapping and disable everything
  10915. * ... */
  10916. plane = crtc->plane;
  10917. crtc->plane = !plane;
  10918. crtc->primary_enabled = true;
  10919. dev_priv->display.crtc_disable(&crtc->base);
  10920. crtc->plane = plane;
  10921. /* ... and break all links. */
  10922. list_for_each_entry(connector, &dev->mode_config.connector_list,
  10923. base.head) {
  10924. if (connector->encoder->base.crtc != &crtc->base)
  10925. continue;
  10926. connector->base.dpms = DRM_MODE_DPMS_OFF;
  10927. connector->base.encoder = NULL;
  10928. }
  10929. /* multiple connectors may have the same encoder:
  10930. * handle them and break crtc link separately */
  10931. list_for_each_entry(connector, &dev->mode_config.connector_list,
  10932. base.head)
  10933. if (connector->encoder->base.crtc == &crtc->base) {
  10934. connector->encoder->base.crtc = NULL;
  10935. connector->encoder->connectors_active = false;
  10936. }
  10937. WARN_ON(crtc->active);
  10938. crtc->base.enabled = false;
  10939. }
  10940. if (dev_priv->quirks & QUIRK_PIPEA_FORCE &&
  10941. crtc->pipe == PIPE_A && !crtc->active) {
  10942. /* BIOS forgot to enable pipe A, this mostly happens after
  10943. * resume. Force-enable the pipe to fix this, the update_dpms
  10944. * call below we restore the pipe to the right state, but leave
  10945. * the required bits on. */
  10946. intel_enable_pipe_a(dev);
  10947. }
  10948. /* Adjust the state of the output pipe according to whether we
  10949. * have active connectors/encoders. */
  10950. intel_crtc_update_dpms(&crtc->base);
  10951. if (crtc->active != crtc->base.enabled) {
  10952. struct intel_encoder *encoder;
  10953. /* This can happen either due to bugs in the get_hw_state
  10954. * functions or because the pipe is force-enabled due to the
  10955. * pipe A quirk. */
  10956. DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n",
  10957. crtc->base.base.id,
  10958. crtc->base.enabled ? "enabled" : "disabled",
  10959. crtc->active ? "enabled" : "disabled");
  10960. crtc->base.enabled = crtc->active;
  10961. /* Because we only establish the connector -> encoder ->
  10962. * crtc links if something is active, this means the
  10963. * crtc is now deactivated. Break the links. connector
  10964. * -> encoder links are only establish when things are
  10965. * actually up, hence no need to break them. */
  10966. WARN_ON(crtc->active);
  10967. for_each_encoder_on_crtc(dev, &crtc->base, encoder) {
  10968. WARN_ON(encoder->connectors_active);
  10969. encoder->base.crtc = NULL;
  10970. }
  10971. }
  10972. if (crtc->active || HAS_GMCH_DISPLAY(dev)) {
  10973. /*
  10974. * We start out with underrun reporting disabled to avoid races.
  10975. * For correct bookkeeping mark this on active crtcs.
  10976. *
  10977. * Also on gmch platforms we dont have any hardware bits to
  10978. * disable the underrun reporting. Which means we need to start
  10979. * out with underrun reporting disabled also on inactive pipes,
  10980. * since otherwise we'll complain about the garbage we read when
  10981. * e.g. coming up after runtime pm.
  10982. *
  10983. * No protection against concurrent access is required - at
  10984. * worst a fifo underrun happens which also sets this to false.
  10985. */
  10986. crtc->cpu_fifo_underrun_disabled = true;
  10987. crtc->pch_fifo_underrun_disabled = true;
  10988. }
  10989. }
  10990. static void intel_sanitize_encoder(struct intel_encoder *encoder)
  10991. {
  10992. struct intel_connector *connector;
  10993. struct drm_device *dev = encoder->base.dev;
  10994. /* We need to check both for a crtc link (meaning that the
  10995. * encoder is active and trying to read from a pipe) and the
  10996. * pipe itself being active. */
  10997. bool has_active_crtc = encoder->base.crtc &&
  10998. to_intel_crtc(encoder->base.crtc)->active;
  10999. if (encoder->connectors_active && !has_active_crtc) {
  11000. DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
  11001. encoder->base.base.id,
  11002. encoder->base.name);
  11003. /* Connector is active, but has no active pipe. This is
  11004. * fallout from our resume register restoring. Disable
  11005. * the encoder manually again. */
  11006. if (encoder->base.crtc) {
  11007. DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
  11008. encoder->base.base.id,
  11009. encoder->base.name);
  11010. encoder->disable(encoder);
  11011. if (encoder->post_disable)
  11012. encoder->post_disable(encoder);
  11013. }
  11014. encoder->base.crtc = NULL;
  11015. encoder->connectors_active = false;
  11016. /* Inconsistent output/port/pipe state happens presumably due to
  11017. * a bug in one of the get_hw_state functions. Or someplace else
  11018. * in our code, like the register restore mess on resume. Clamp
  11019. * things to off as a safer default. */
  11020. list_for_each_entry(connector,
  11021. &dev->mode_config.connector_list,
  11022. base.head) {
  11023. if (connector->encoder != encoder)
  11024. continue;
  11025. connector->base.dpms = DRM_MODE_DPMS_OFF;
  11026. connector->base.encoder = NULL;
  11027. }
  11028. }
  11029. /* Enabled encoders without active connectors will be fixed in
  11030. * the crtc fixup. */
  11031. }
  11032. void i915_redisable_vga_power_on(struct drm_device *dev)
  11033. {
  11034. struct drm_i915_private *dev_priv = dev->dev_private;
  11035. u32 vga_reg = i915_vgacntrl_reg(dev);
  11036. if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) {
  11037. DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
  11038. i915_disable_vga(dev);
  11039. }
  11040. }
  11041. void i915_redisable_vga(struct drm_device *dev)
  11042. {
  11043. struct drm_i915_private *dev_priv = dev->dev_private;
  11044. /* This function can be called both from intel_modeset_setup_hw_state or
  11045. * at a very early point in our resume sequence, where the power well
  11046. * structures are not yet restored. Since this function is at a very
  11047. * paranoid "someone might have enabled VGA while we were not looking"
  11048. * level, just check if the power well is enabled instead of trying to
  11049. * follow the "don't touch the power well if we don't need it" policy
  11050. * the rest of the driver uses. */
  11051. if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_VGA))
  11052. return;
  11053. i915_redisable_vga_power_on(dev);
  11054. }
  11055. static bool primary_get_hw_state(struct intel_crtc *crtc)
  11056. {
  11057. struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
  11058. if (!crtc->active)
  11059. return false;
  11060. return I915_READ(DSPCNTR(crtc->plane)) & DISPLAY_PLANE_ENABLE;
  11061. }
  11062. static void intel_modeset_readout_hw_state(struct drm_device *dev)
  11063. {
  11064. struct drm_i915_private *dev_priv = dev->dev_private;
  11065. enum pipe pipe;
  11066. struct intel_crtc *crtc;
  11067. struct intel_encoder *encoder;
  11068. struct intel_connector *connector;
  11069. int i;
  11070. for_each_intel_crtc(dev, crtc) {
  11071. memset(&crtc->config, 0, sizeof(crtc->config));
  11072. crtc->config.quirks |= PIPE_CONFIG_QUIRK_INHERITED_MODE;
  11073. crtc->active = dev_priv->display.get_pipe_config(crtc,
  11074. &crtc->config);
  11075. crtc->base.enabled = crtc->active;
  11076. crtc->primary_enabled = primary_get_hw_state(crtc);
  11077. DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n",
  11078. crtc->base.base.id,
  11079. crtc->active ? "enabled" : "disabled");
  11080. }
  11081. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  11082. struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
  11083. pll->on = pll->get_hw_state(dev_priv, pll, &pll->hw_state);
  11084. pll->active = 0;
  11085. for_each_intel_crtc(dev, crtc) {
  11086. if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll)
  11087. pll->active++;
  11088. }
  11089. pll->refcount = pll->active;
  11090. DRM_DEBUG_KMS("%s hw state readout: refcount %i, on %i\n",
  11091. pll->name, pll->refcount, pll->on);
  11092. if (pll->refcount)
  11093. intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS);
  11094. }
  11095. for_each_intel_encoder(dev, encoder) {
  11096. pipe = 0;
  11097. if (encoder->get_hw_state(encoder, &pipe)) {
  11098. crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  11099. encoder->base.crtc = &crtc->base;
  11100. encoder->get_config(encoder, &crtc->config);
  11101. } else {
  11102. encoder->base.crtc = NULL;
  11103. }
  11104. encoder->connectors_active = false;
  11105. DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
  11106. encoder->base.base.id,
  11107. encoder->base.name,
  11108. encoder->base.crtc ? "enabled" : "disabled",
  11109. pipe_name(pipe));
  11110. }
  11111. list_for_each_entry(connector, &dev->mode_config.connector_list,
  11112. base.head) {
  11113. if (connector->get_hw_state(connector)) {
  11114. connector->base.dpms = DRM_MODE_DPMS_ON;
  11115. connector->encoder->connectors_active = true;
  11116. connector->base.encoder = &connector->encoder->base;
  11117. } else {
  11118. connector->base.dpms = DRM_MODE_DPMS_OFF;
  11119. connector->base.encoder = NULL;
  11120. }
  11121. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
  11122. connector->base.base.id,
  11123. connector->base.name,
  11124. connector->base.encoder ? "enabled" : "disabled");
  11125. }
  11126. }
  11127. /* Scan out the current hw modeset state, sanitizes it and maps it into the drm
  11128. * and i915 state tracking structures. */
  11129. void intel_modeset_setup_hw_state(struct drm_device *dev,
  11130. bool force_restore)
  11131. {
  11132. struct drm_i915_private *dev_priv = dev->dev_private;
  11133. enum pipe pipe;
  11134. struct intel_crtc *crtc;
  11135. struct intel_encoder *encoder;
  11136. int i;
  11137. intel_modeset_readout_hw_state(dev);
  11138. /*
  11139. * Now that we have the config, copy it to each CRTC struct
  11140. * Note that this could go away if we move to using crtc_config
  11141. * checking everywhere.
  11142. */
  11143. for_each_intel_crtc(dev, crtc) {
  11144. if (crtc->active && i915.fastboot) {
  11145. intel_mode_from_pipe_config(&crtc->base.mode, &crtc->config);
  11146. DRM_DEBUG_KMS("[CRTC:%d] found active mode: ",
  11147. crtc->base.base.id);
  11148. drm_mode_debug_printmodeline(&crtc->base.mode);
  11149. }
  11150. }
  11151. /* HW state is read out, now we need to sanitize this mess. */
  11152. for_each_intel_encoder(dev, encoder) {
  11153. intel_sanitize_encoder(encoder);
  11154. }
  11155. for_each_pipe(dev_priv, pipe) {
  11156. crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  11157. intel_sanitize_crtc(crtc);
  11158. intel_dump_pipe_config(crtc, &crtc->config, "[setup_hw_state]");
  11159. }
  11160. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  11161. struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
  11162. if (!pll->on || pll->active)
  11163. continue;
  11164. DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll->name);
  11165. pll->disable(dev_priv, pll);
  11166. pll->on = false;
  11167. }
  11168. if (HAS_PCH_SPLIT(dev))
  11169. ilk_wm_get_hw_state(dev);
  11170. if (force_restore) {
  11171. i915_redisable_vga(dev);
  11172. /*
  11173. * We need to use raw interfaces for restoring state to avoid
  11174. * checking (bogus) intermediate states.
  11175. */
  11176. for_each_pipe(dev_priv, pipe) {
  11177. struct drm_crtc *crtc =
  11178. dev_priv->pipe_to_crtc_mapping[pipe];
  11179. __intel_set_mode(crtc, &crtc->mode, crtc->x, crtc->y,
  11180. crtc->primary->fb);
  11181. }
  11182. } else {
  11183. intel_modeset_update_staged_output_state(dev);
  11184. }
  11185. intel_modeset_check_state(dev);
  11186. }
  11187. void intel_modeset_gem_init(struct drm_device *dev)
  11188. {
  11189. struct drm_crtc *c;
  11190. struct drm_i915_gem_object *obj;
  11191. mutex_lock(&dev->struct_mutex);
  11192. intel_init_gt_powersave(dev);
  11193. mutex_unlock(&dev->struct_mutex);
  11194. intel_modeset_init_hw(dev);
  11195. intel_setup_overlay(dev);
  11196. /*
  11197. * Make sure any fbs we allocated at startup are properly
  11198. * pinned & fenced. When we do the allocation it's too early
  11199. * for this.
  11200. */
  11201. mutex_lock(&dev->struct_mutex);
  11202. for_each_crtc(dev, c) {
  11203. obj = intel_fb_obj(c->primary->fb);
  11204. if (obj == NULL)
  11205. continue;
  11206. if (intel_pin_and_fence_fb_obj(dev, obj, NULL)) {
  11207. DRM_ERROR("failed to pin boot fb on pipe %d\n",
  11208. to_intel_crtc(c)->pipe);
  11209. drm_framebuffer_unreference(c->primary->fb);
  11210. c->primary->fb = NULL;
  11211. }
  11212. }
  11213. mutex_unlock(&dev->struct_mutex);
  11214. }
  11215. void intel_connector_unregister(struct intel_connector *intel_connector)
  11216. {
  11217. struct drm_connector *connector = &intel_connector->base;
  11218. intel_panel_destroy_backlight(connector);
  11219. drm_connector_unregister(connector);
  11220. }
  11221. void intel_modeset_cleanup(struct drm_device *dev)
  11222. {
  11223. struct drm_i915_private *dev_priv = dev->dev_private;
  11224. struct drm_connector *connector;
  11225. /*
  11226. * Interrupts and polling as the first thing to avoid creating havoc.
  11227. * Too much stuff here (turning of rps, connectors, ...) would
  11228. * experience fancy races otherwise.
  11229. */
  11230. intel_irq_uninstall(dev_priv);
  11231. /*
  11232. * Due to the hpd irq storm handling the hotplug work can re-arm the
  11233. * poll handlers. Hence disable polling after hpd handling is shut down.
  11234. */
  11235. drm_kms_helper_poll_fini(dev);
  11236. mutex_lock(&dev->struct_mutex);
  11237. intel_unregister_dsm_handler();
  11238. intel_disable_fbc(dev);
  11239. intel_disable_gt_powersave(dev);
  11240. ironlake_teardown_rc6(dev);
  11241. mutex_unlock(&dev->struct_mutex);
  11242. /* flush any delayed tasks or pending work */
  11243. flush_scheduled_work();
  11244. /* destroy the backlight and sysfs files before encoders/connectors */
  11245. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  11246. struct intel_connector *intel_connector;
  11247. intel_connector = to_intel_connector(connector);
  11248. intel_connector->unregister(intel_connector);
  11249. }
  11250. drm_mode_config_cleanup(dev);
  11251. intel_cleanup_overlay(dev);
  11252. mutex_lock(&dev->struct_mutex);
  11253. intel_cleanup_gt_powersave(dev);
  11254. mutex_unlock(&dev->struct_mutex);
  11255. }
  11256. /*
  11257. * Return which encoder is currently attached for connector.
  11258. */
  11259. struct drm_encoder *intel_best_encoder(struct drm_connector *connector)
  11260. {
  11261. return &intel_attached_encoder(connector)->base;
  11262. }
  11263. void intel_connector_attach_encoder(struct intel_connector *connector,
  11264. struct intel_encoder *encoder)
  11265. {
  11266. connector->encoder = encoder;
  11267. drm_mode_connector_attach_encoder(&connector->base,
  11268. &encoder->base);
  11269. }
  11270. /*
  11271. * set vga decode state - true == enable VGA decode
  11272. */
  11273. int intel_modeset_vga_set_state(struct drm_device *dev, bool state)
  11274. {
  11275. struct drm_i915_private *dev_priv = dev->dev_private;
  11276. unsigned reg = INTEL_INFO(dev)->gen >= 6 ? SNB_GMCH_CTRL : INTEL_GMCH_CTRL;
  11277. u16 gmch_ctrl;
  11278. if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) {
  11279. DRM_ERROR("failed to read control word\n");
  11280. return -EIO;
  11281. }
  11282. if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state)
  11283. return 0;
  11284. if (state)
  11285. gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE;
  11286. else
  11287. gmch_ctrl |= INTEL_GMCH_VGA_DISABLE;
  11288. if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) {
  11289. DRM_ERROR("failed to write control word\n");
  11290. return -EIO;
  11291. }
  11292. return 0;
  11293. }
  11294. struct intel_display_error_state {
  11295. u32 power_well_driver;
  11296. int num_transcoders;
  11297. struct intel_cursor_error_state {
  11298. u32 control;
  11299. u32 position;
  11300. u32 base;
  11301. u32 size;
  11302. } cursor[I915_MAX_PIPES];
  11303. struct intel_pipe_error_state {
  11304. bool power_domain_on;
  11305. u32 source;
  11306. u32 stat;
  11307. } pipe[I915_MAX_PIPES];
  11308. struct intel_plane_error_state {
  11309. u32 control;
  11310. u32 stride;
  11311. u32 size;
  11312. u32 pos;
  11313. u32 addr;
  11314. u32 surface;
  11315. u32 tile_offset;
  11316. } plane[I915_MAX_PIPES];
  11317. struct intel_transcoder_error_state {
  11318. bool power_domain_on;
  11319. enum transcoder cpu_transcoder;
  11320. u32 conf;
  11321. u32 htotal;
  11322. u32 hblank;
  11323. u32 hsync;
  11324. u32 vtotal;
  11325. u32 vblank;
  11326. u32 vsync;
  11327. } transcoder[4];
  11328. };
  11329. struct intel_display_error_state *
  11330. intel_display_capture_error_state(struct drm_device *dev)
  11331. {
  11332. struct drm_i915_private *dev_priv = dev->dev_private;
  11333. struct intel_display_error_state *error;
  11334. int transcoders[] = {
  11335. TRANSCODER_A,
  11336. TRANSCODER_B,
  11337. TRANSCODER_C,
  11338. TRANSCODER_EDP,
  11339. };
  11340. int i;
  11341. if (INTEL_INFO(dev)->num_pipes == 0)
  11342. return NULL;
  11343. error = kzalloc(sizeof(*error), GFP_ATOMIC);
  11344. if (error == NULL)
  11345. return NULL;
  11346. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  11347. error->power_well_driver = I915_READ(HSW_PWR_WELL_DRIVER);
  11348. for_each_pipe(dev_priv, i) {
  11349. error->pipe[i].power_domain_on =
  11350. __intel_display_power_is_enabled(dev_priv,
  11351. POWER_DOMAIN_PIPE(i));
  11352. if (!error->pipe[i].power_domain_on)
  11353. continue;
  11354. error->cursor[i].control = I915_READ(CURCNTR(i));
  11355. error->cursor[i].position = I915_READ(CURPOS(i));
  11356. error->cursor[i].base = I915_READ(CURBASE(i));
  11357. error->plane[i].control = I915_READ(DSPCNTR(i));
  11358. error->plane[i].stride = I915_READ(DSPSTRIDE(i));
  11359. if (INTEL_INFO(dev)->gen <= 3) {
  11360. error->plane[i].size = I915_READ(DSPSIZE(i));
  11361. error->plane[i].pos = I915_READ(DSPPOS(i));
  11362. }
  11363. if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev))
  11364. error->plane[i].addr = I915_READ(DSPADDR(i));
  11365. if (INTEL_INFO(dev)->gen >= 4) {
  11366. error->plane[i].surface = I915_READ(DSPSURF(i));
  11367. error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i));
  11368. }
  11369. error->pipe[i].source = I915_READ(PIPESRC(i));
  11370. if (HAS_GMCH_DISPLAY(dev))
  11371. error->pipe[i].stat = I915_READ(PIPESTAT(i));
  11372. }
  11373. error->num_transcoders = INTEL_INFO(dev)->num_pipes;
  11374. if (HAS_DDI(dev_priv->dev))
  11375. error->num_transcoders++; /* Account for eDP. */
  11376. for (i = 0; i < error->num_transcoders; i++) {
  11377. enum transcoder cpu_transcoder = transcoders[i];
  11378. error->transcoder[i].power_domain_on =
  11379. __intel_display_power_is_enabled(dev_priv,
  11380. POWER_DOMAIN_TRANSCODER(cpu_transcoder));
  11381. if (!error->transcoder[i].power_domain_on)
  11382. continue;
  11383. error->transcoder[i].cpu_transcoder = cpu_transcoder;
  11384. error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder));
  11385. error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder));
  11386. error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder));
  11387. error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder));
  11388. error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder));
  11389. error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder));
  11390. error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder));
  11391. }
  11392. return error;
  11393. }
  11394. #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
  11395. void
  11396. intel_display_print_error_state(struct drm_i915_error_state_buf *m,
  11397. struct drm_device *dev,
  11398. struct intel_display_error_state *error)
  11399. {
  11400. struct drm_i915_private *dev_priv = dev->dev_private;
  11401. int i;
  11402. if (!error)
  11403. return;
  11404. err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev)->num_pipes);
  11405. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  11406. err_printf(m, "PWR_WELL_CTL2: %08x\n",
  11407. error->power_well_driver);
  11408. for_each_pipe(dev_priv, i) {
  11409. err_printf(m, "Pipe [%d]:\n", i);
  11410. err_printf(m, " Power: %s\n",
  11411. error->pipe[i].power_domain_on ? "on" : "off");
  11412. err_printf(m, " SRC: %08x\n", error->pipe[i].source);
  11413. err_printf(m, " STAT: %08x\n", error->pipe[i].stat);
  11414. err_printf(m, "Plane [%d]:\n", i);
  11415. err_printf(m, " CNTR: %08x\n", error->plane[i].control);
  11416. err_printf(m, " STRIDE: %08x\n", error->plane[i].stride);
  11417. if (INTEL_INFO(dev)->gen <= 3) {
  11418. err_printf(m, " SIZE: %08x\n", error->plane[i].size);
  11419. err_printf(m, " POS: %08x\n", error->plane[i].pos);
  11420. }
  11421. if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev))
  11422. err_printf(m, " ADDR: %08x\n", error->plane[i].addr);
  11423. if (INTEL_INFO(dev)->gen >= 4) {
  11424. err_printf(m, " SURF: %08x\n", error->plane[i].surface);
  11425. err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset);
  11426. }
  11427. err_printf(m, "Cursor [%d]:\n", i);
  11428. err_printf(m, " CNTR: %08x\n", error->cursor[i].control);
  11429. err_printf(m, " POS: %08x\n", error->cursor[i].position);
  11430. err_printf(m, " BASE: %08x\n", error->cursor[i].base);
  11431. }
  11432. for (i = 0; i < error->num_transcoders; i++) {
  11433. err_printf(m, "CPU transcoder: %c\n",
  11434. transcoder_name(error->transcoder[i].cpu_transcoder));
  11435. err_printf(m, " Power: %s\n",
  11436. error->transcoder[i].power_domain_on ? "on" : "off");
  11437. err_printf(m, " CONF: %08x\n", error->transcoder[i].conf);
  11438. err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal);
  11439. err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank);
  11440. err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync);
  11441. err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal);
  11442. err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank);
  11443. err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync);
  11444. }
  11445. }
  11446. void intel_modeset_preclose(struct drm_device *dev, struct drm_file *file)
  11447. {
  11448. struct intel_crtc *crtc;
  11449. for_each_intel_crtc(dev, crtc) {
  11450. struct intel_unpin_work *work;
  11451. spin_lock_irq(&dev->event_lock);
  11452. work = crtc->unpin_work;
  11453. if (work && work->event &&
  11454. work->event->base.file_priv == file) {
  11455. kfree(work->event);
  11456. work->event = NULL;
  11457. }
  11458. spin_unlock_irq(&dev->event_lock);
  11459. }
  11460. }