intel_display.c 364 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240
  1. /*
  2. * Copyright © 2006-2007 Intel Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  21. * DEALINGS IN THE SOFTWARE.
  22. *
  23. * Authors:
  24. * Eric Anholt <eric@anholt.net>
  25. */
  26. #include <linux/dmi.h>
  27. #include <linux/module.h>
  28. #include <linux/input.h>
  29. #include <linux/i2c.h>
  30. #include <linux/kernel.h>
  31. #include <linux/slab.h>
  32. #include <linux/vgaarb.h>
  33. #include <drm/drm_edid.h>
  34. #include <drm/drmP.h>
  35. #include "intel_drv.h"
  36. #include <drm/i915_drm.h>
  37. #include "i915_drv.h"
  38. #include "i915_trace.h"
  39. #include <drm/drm_dp_helper.h>
  40. #include <drm/drm_crtc_helper.h>
  41. #include <drm/drm_plane_helper.h>
  42. #include <drm/drm_rect.h>
  43. #include <linux/dma_remapping.h>
  44. /* Primary plane formats supported by all gen */
  45. #define COMMON_PRIMARY_FORMATS \
  46. DRM_FORMAT_C8, \
  47. DRM_FORMAT_RGB565, \
  48. DRM_FORMAT_XRGB8888, \
  49. DRM_FORMAT_ARGB8888
  50. /* Primary plane formats for gen <= 3 */
  51. static const uint32_t intel_primary_formats_gen2[] = {
  52. COMMON_PRIMARY_FORMATS,
  53. DRM_FORMAT_XRGB1555,
  54. DRM_FORMAT_ARGB1555,
  55. };
  56. /* Primary plane formats for gen >= 4 */
  57. static const uint32_t intel_primary_formats_gen4[] = {
  58. COMMON_PRIMARY_FORMATS, \
  59. DRM_FORMAT_XBGR8888,
  60. DRM_FORMAT_ABGR8888,
  61. DRM_FORMAT_XRGB2101010,
  62. DRM_FORMAT_ARGB2101010,
  63. DRM_FORMAT_XBGR2101010,
  64. DRM_FORMAT_ABGR2101010,
  65. };
  66. /* Cursor formats */
  67. static const uint32_t intel_cursor_formats[] = {
  68. DRM_FORMAT_ARGB8888,
  69. };
  70. #define DIV_ROUND_CLOSEST_ULL(ll, d) \
  71. ({ unsigned long long _tmp = (ll)+(d)/2; do_div(_tmp, d); _tmp; })
  72. static void intel_increase_pllclock(struct drm_device *dev,
  73. enum pipe pipe);
  74. static void intel_crtc_update_cursor(struct drm_crtc *crtc, bool on);
  75. static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
  76. struct intel_crtc_config *pipe_config);
  77. static void ironlake_pch_clock_get(struct intel_crtc *crtc,
  78. struct intel_crtc_config *pipe_config);
  79. static int intel_set_mode(struct drm_crtc *crtc, struct drm_display_mode *mode,
  80. int x, int y, struct drm_framebuffer *old_fb);
  81. static int intel_framebuffer_init(struct drm_device *dev,
  82. struct intel_framebuffer *ifb,
  83. struct drm_mode_fb_cmd2 *mode_cmd,
  84. struct drm_i915_gem_object *obj);
  85. static void intel_dp_set_m_n(struct intel_crtc *crtc);
  86. static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc);
  87. static void intel_set_pipe_timings(struct intel_crtc *intel_crtc);
  88. static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc,
  89. struct intel_link_m_n *m_n);
  90. static void ironlake_set_pipeconf(struct drm_crtc *crtc);
  91. static void haswell_set_pipeconf(struct drm_crtc *crtc);
  92. static void intel_set_pipe_csc(struct drm_crtc *crtc);
  93. static void vlv_prepare_pll(struct intel_crtc *crtc);
  94. typedef struct {
  95. int min, max;
  96. } intel_range_t;
  97. typedef struct {
  98. int dot_limit;
  99. int p2_slow, p2_fast;
  100. } intel_p2_t;
  101. typedef struct intel_limit intel_limit_t;
  102. struct intel_limit {
  103. intel_range_t dot, vco, n, m, m1, m2, p, p1;
  104. intel_p2_t p2;
  105. };
  106. int
  107. intel_pch_rawclk(struct drm_device *dev)
  108. {
  109. struct drm_i915_private *dev_priv = dev->dev_private;
  110. WARN_ON(!HAS_PCH_SPLIT(dev));
  111. return I915_READ(PCH_RAWCLK_FREQ) & RAWCLK_FREQ_MASK;
  112. }
  113. static inline u32 /* units of 100MHz */
  114. intel_fdi_link_freq(struct drm_device *dev)
  115. {
  116. if (IS_GEN5(dev)) {
  117. struct drm_i915_private *dev_priv = dev->dev_private;
  118. return (I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK) + 2;
  119. } else
  120. return 27;
  121. }
  122. static const intel_limit_t intel_limits_i8xx_dac = {
  123. .dot = { .min = 25000, .max = 350000 },
  124. .vco = { .min = 908000, .max = 1512000 },
  125. .n = { .min = 2, .max = 16 },
  126. .m = { .min = 96, .max = 140 },
  127. .m1 = { .min = 18, .max = 26 },
  128. .m2 = { .min = 6, .max = 16 },
  129. .p = { .min = 4, .max = 128 },
  130. .p1 = { .min = 2, .max = 33 },
  131. .p2 = { .dot_limit = 165000,
  132. .p2_slow = 4, .p2_fast = 2 },
  133. };
  134. static const intel_limit_t intel_limits_i8xx_dvo = {
  135. .dot = { .min = 25000, .max = 350000 },
  136. .vco = { .min = 908000, .max = 1512000 },
  137. .n = { .min = 2, .max = 16 },
  138. .m = { .min = 96, .max = 140 },
  139. .m1 = { .min = 18, .max = 26 },
  140. .m2 = { .min = 6, .max = 16 },
  141. .p = { .min = 4, .max = 128 },
  142. .p1 = { .min = 2, .max = 33 },
  143. .p2 = { .dot_limit = 165000,
  144. .p2_slow = 4, .p2_fast = 4 },
  145. };
  146. static const intel_limit_t intel_limits_i8xx_lvds = {
  147. .dot = { .min = 25000, .max = 350000 },
  148. .vco = { .min = 908000, .max = 1512000 },
  149. .n = { .min = 2, .max = 16 },
  150. .m = { .min = 96, .max = 140 },
  151. .m1 = { .min = 18, .max = 26 },
  152. .m2 = { .min = 6, .max = 16 },
  153. .p = { .min = 4, .max = 128 },
  154. .p1 = { .min = 1, .max = 6 },
  155. .p2 = { .dot_limit = 165000,
  156. .p2_slow = 14, .p2_fast = 7 },
  157. };
  158. static const intel_limit_t intel_limits_i9xx_sdvo = {
  159. .dot = { .min = 20000, .max = 400000 },
  160. .vco = { .min = 1400000, .max = 2800000 },
  161. .n = { .min = 1, .max = 6 },
  162. .m = { .min = 70, .max = 120 },
  163. .m1 = { .min = 8, .max = 18 },
  164. .m2 = { .min = 3, .max = 7 },
  165. .p = { .min = 5, .max = 80 },
  166. .p1 = { .min = 1, .max = 8 },
  167. .p2 = { .dot_limit = 200000,
  168. .p2_slow = 10, .p2_fast = 5 },
  169. };
  170. static const intel_limit_t intel_limits_i9xx_lvds = {
  171. .dot = { .min = 20000, .max = 400000 },
  172. .vco = { .min = 1400000, .max = 2800000 },
  173. .n = { .min = 1, .max = 6 },
  174. .m = { .min = 70, .max = 120 },
  175. .m1 = { .min = 8, .max = 18 },
  176. .m2 = { .min = 3, .max = 7 },
  177. .p = { .min = 7, .max = 98 },
  178. .p1 = { .min = 1, .max = 8 },
  179. .p2 = { .dot_limit = 112000,
  180. .p2_slow = 14, .p2_fast = 7 },
  181. };
  182. static const intel_limit_t intel_limits_g4x_sdvo = {
  183. .dot = { .min = 25000, .max = 270000 },
  184. .vco = { .min = 1750000, .max = 3500000},
  185. .n = { .min = 1, .max = 4 },
  186. .m = { .min = 104, .max = 138 },
  187. .m1 = { .min = 17, .max = 23 },
  188. .m2 = { .min = 5, .max = 11 },
  189. .p = { .min = 10, .max = 30 },
  190. .p1 = { .min = 1, .max = 3},
  191. .p2 = { .dot_limit = 270000,
  192. .p2_slow = 10,
  193. .p2_fast = 10
  194. },
  195. };
  196. static const intel_limit_t intel_limits_g4x_hdmi = {
  197. .dot = { .min = 22000, .max = 400000 },
  198. .vco = { .min = 1750000, .max = 3500000},
  199. .n = { .min = 1, .max = 4 },
  200. .m = { .min = 104, .max = 138 },
  201. .m1 = { .min = 16, .max = 23 },
  202. .m2 = { .min = 5, .max = 11 },
  203. .p = { .min = 5, .max = 80 },
  204. .p1 = { .min = 1, .max = 8},
  205. .p2 = { .dot_limit = 165000,
  206. .p2_slow = 10, .p2_fast = 5 },
  207. };
  208. static const intel_limit_t intel_limits_g4x_single_channel_lvds = {
  209. .dot = { .min = 20000, .max = 115000 },
  210. .vco = { .min = 1750000, .max = 3500000 },
  211. .n = { .min = 1, .max = 3 },
  212. .m = { .min = 104, .max = 138 },
  213. .m1 = { .min = 17, .max = 23 },
  214. .m2 = { .min = 5, .max = 11 },
  215. .p = { .min = 28, .max = 112 },
  216. .p1 = { .min = 2, .max = 8 },
  217. .p2 = { .dot_limit = 0,
  218. .p2_slow = 14, .p2_fast = 14
  219. },
  220. };
  221. static const intel_limit_t intel_limits_g4x_dual_channel_lvds = {
  222. .dot = { .min = 80000, .max = 224000 },
  223. .vco = { .min = 1750000, .max = 3500000 },
  224. .n = { .min = 1, .max = 3 },
  225. .m = { .min = 104, .max = 138 },
  226. .m1 = { .min = 17, .max = 23 },
  227. .m2 = { .min = 5, .max = 11 },
  228. .p = { .min = 14, .max = 42 },
  229. .p1 = { .min = 2, .max = 6 },
  230. .p2 = { .dot_limit = 0,
  231. .p2_slow = 7, .p2_fast = 7
  232. },
  233. };
  234. static const intel_limit_t intel_limits_pineview_sdvo = {
  235. .dot = { .min = 20000, .max = 400000},
  236. .vco = { .min = 1700000, .max = 3500000 },
  237. /* Pineview's Ncounter is a ring counter */
  238. .n = { .min = 3, .max = 6 },
  239. .m = { .min = 2, .max = 256 },
  240. /* Pineview only has one combined m divider, which we treat as m2. */
  241. .m1 = { .min = 0, .max = 0 },
  242. .m2 = { .min = 0, .max = 254 },
  243. .p = { .min = 5, .max = 80 },
  244. .p1 = { .min = 1, .max = 8 },
  245. .p2 = { .dot_limit = 200000,
  246. .p2_slow = 10, .p2_fast = 5 },
  247. };
  248. static const intel_limit_t intel_limits_pineview_lvds = {
  249. .dot = { .min = 20000, .max = 400000 },
  250. .vco = { .min = 1700000, .max = 3500000 },
  251. .n = { .min = 3, .max = 6 },
  252. .m = { .min = 2, .max = 256 },
  253. .m1 = { .min = 0, .max = 0 },
  254. .m2 = { .min = 0, .max = 254 },
  255. .p = { .min = 7, .max = 112 },
  256. .p1 = { .min = 1, .max = 8 },
  257. .p2 = { .dot_limit = 112000,
  258. .p2_slow = 14, .p2_fast = 14 },
  259. };
  260. /* Ironlake / Sandybridge
  261. *
  262. * We calculate clock using (register_value + 2) for N/M1/M2, so here
  263. * the range value for them is (actual_value - 2).
  264. */
  265. static const intel_limit_t intel_limits_ironlake_dac = {
  266. .dot = { .min = 25000, .max = 350000 },
  267. .vco = { .min = 1760000, .max = 3510000 },
  268. .n = { .min = 1, .max = 5 },
  269. .m = { .min = 79, .max = 127 },
  270. .m1 = { .min = 12, .max = 22 },
  271. .m2 = { .min = 5, .max = 9 },
  272. .p = { .min = 5, .max = 80 },
  273. .p1 = { .min = 1, .max = 8 },
  274. .p2 = { .dot_limit = 225000,
  275. .p2_slow = 10, .p2_fast = 5 },
  276. };
  277. static const intel_limit_t intel_limits_ironlake_single_lvds = {
  278. .dot = { .min = 25000, .max = 350000 },
  279. .vco = { .min = 1760000, .max = 3510000 },
  280. .n = { .min = 1, .max = 3 },
  281. .m = { .min = 79, .max = 118 },
  282. .m1 = { .min = 12, .max = 22 },
  283. .m2 = { .min = 5, .max = 9 },
  284. .p = { .min = 28, .max = 112 },
  285. .p1 = { .min = 2, .max = 8 },
  286. .p2 = { .dot_limit = 225000,
  287. .p2_slow = 14, .p2_fast = 14 },
  288. };
  289. static const intel_limit_t intel_limits_ironlake_dual_lvds = {
  290. .dot = { .min = 25000, .max = 350000 },
  291. .vco = { .min = 1760000, .max = 3510000 },
  292. .n = { .min = 1, .max = 3 },
  293. .m = { .min = 79, .max = 127 },
  294. .m1 = { .min = 12, .max = 22 },
  295. .m2 = { .min = 5, .max = 9 },
  296. .p = { .min = 14, .max = 56 },
  297. .p1 = { .min = 2, .max = 8 },
  298. .p2 = { .dot_limit = 225000,
  299. .p2_slow = 7, .p2_fast = 7 },
  300. };
  301. /* LVDS 100mhz refclk limits. */
  302. static const intel_limit_t intel_limits_ironlake_single_lvds_100m = {
  303. .dot = { .min = 25000, .max = 350000 },
  304. .vco = { .min = 1760000, .max = 3510000 },
  305. .n = { .min = 1, .max = 2 },
  306. .m = { .min = 79, .max = 126 },
  307. .m1 = { .min = 12, .max = 22 },
  308. .m2 = { .min = 5, .max = 9 },
  309. .p = { .min = 28, .max = 112 },
  310. .p1 = { .min = 2, .max = 8 },
  311. .p2 = { .dot_limit = 225000,
  312. .p2_slow = 14, .p2_fast = 14 },
  313. };
  314. static const intel_limit_t intel_limits_ironlake_dual_lvds_100m = {
  315. .dot = { .min = 25000, .max = 350000 },
  316. .vco = { .min = 1760000, .max = 3510000 },
  317. .n = { .min = 1, .max = 3 },
  318. .m = { .min = 79, .max = 126 },
  319. .m1 = { .min = 12, .max = 22 },
  320. .m2 = { .min = 5, .max = 9 },
  321. .p = { .min = 14, .max = 42 },
  322. .p1 = { .min = 2, .max = 6 },
  323. .p2 = { .dot_limit = 225000,
  324. .p2_slow = 7, .p2_fast = 7 },
  325. };
  326. static const intel_limit_t intel_limits_vlv = {
  327. /*
  328. * These are the data rate limits (measured in fast clocks)
  329. * since those are the strictest limits we have. The fast
  330. * clock and actual rate limits are more relaxed, so checking
  331. * them would make no difference.
  332. */
  333. .dot = { .min = 25000 * 5, .max = 270000 * 5 },
  334. .vco = { .min = 4000000, .max = 6000000 },
  335. .n = { .min = 1, .max = 7 },
  336. .m1 = { .min = 2, .max = 3 },
  337. .m2 = { .min = 11, .max = 156 },
  338. .p1 = { .min = 2, .max = 3 },
  339. .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */
  340. };
  341. static const intel_limit_t intel_limits_chv = {
  342. /*
  343. * These are the data rate limits (measured in fast clocks)
  344. * since those are the strictest limits we have. The fast
  345. * clock and actual rate limits are more relaxed, so checking
  346. * them would make no difference.
  347. */
  348. .dot = { .min = 25000 * 5, .max = 540000 * 5},
  349. .vco = { .min = 4860000, .max = 6700000 },
  350. .n = { .min = 1, .max = 1 },
  351. .m1 = { .min = 2, .max = 2 },
  352. .m2 = { .min = 24 << 22, .max = 175 << 22 },
  353. .p1 = { .min = 2, .max = 4 },
  354. .p2 = { .p2_slow = 1, .p2_fast = 14 },
  355. };
  356. static void vlv_clock(int refclk, intel_clock_t *clock)
  357. {
  358. clock->m = clock->m1 * clock->m2;
  359. clock->p = clock->p1 * clock->p2;
  360. if (WARN_ON(clock->n == 0 || clock->p == 0))
  361. return;
  362. clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
  363. clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
  364. }
  365. /**
  366. * Returns whether any output on the specified pipe is of the specified type
  367. */
  368. static bool intel_pipe_has_type(struct drm_crtc *crtc, int type)
  369. {
  370. struct drm_device *dev = crtc->dev;
  371. struct intel_encoder *encoder;
  372. for_each_encoder_on_crtc(dev, crtc, encoder)
  373. if (encoder->type == type)
  374. return true;
  375. return false;
  376. }
  377. static const intel_limit_t *intel_ironlake_limit(struct drm_crtc *crtc,
  378. int refclk)
  379. {
  380. struct drm_device *dev = crtc->dev;
  381. const intel_limit_t *limit;
  382. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  383. if (intel_is_dual_link_lvds(dev)) {
  384. if (refclk == 100000)
  385. limit = &intel_limits_ironlake_dual_lvds_100m;
  386. else
  387. limit = &intel_limits_ironlake_dual_lvds;
  388. } else {
  389. if (refclk == 100000)
  390. limit = &intel_limits_ironlake_single_lvds_100m;
  391. else
  392. limit = &intel_limits_ironlake_single_lvds;
  393. }
  394. } else
  395. limit = &intel_limits_ironlake_dac;
  396. return limit;
  397. }
  398. static const intel_limit_t *intel_g4x_limit(struct drm_crtc *crtc)
  399. {
  400. struct drm_device *dev = crtc->dev;
  401. const intel_limit_t *limit;
  402. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  403. if (intel_is_dual_link_lvds(dev))
  404. limit = &intel_limits_g4x_dual_channel_lvds;
  405. else
  406. limit = &intel_limits_g4x_single_channel_lvds;
  407. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI) ||
  408. intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG)) {
  409. limit = &intel_limits_g4x_hdmi;
  410. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO)) {
  411. limit = &intel_limits_g4x_sdvo;
  412. } else /* The option is for other outputs */
  413. limit = &intel_limits_i9xx_sdvo;
  414. return limit;
  415. }
  416. static const intel_limit_t *intel_limit(struct drm_crtc *crtc, int refclk)
  417. {
  418. struct drm_device *dev = crtc->dev;
  419. const intel_limit_t *limit;
  420. if (HAS_PCH_SPLIT(dev))
  421. limit = intel_ironlake_limit(crtc, refclk);
  422. else if (IS_G4X(dev)) {
  423. limit = intel_g4x_limit(crtc);
  424. } else if (IS_PINEVIEW(dev)) {
  425. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  426. limit = &intel_limits_pineview_lvds;
  427. else
  428. limit = &intel_limits_pineview_sdvo;
  429. } else if (IS_CHERRYVIEW(dev)) {
  430. limit = &intel_limits_chv;
  431. } else if (IS_VALLEYVIEW(dev)) {
  432. limit = &intel_limits_vlv;
  433. } else if (!IS_GEN2(dev)) {
  434. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  435. limit = &intel_limits_i9xx_lvds;
  436. else
  437. limit = &intel_limits_i9xx_sdvo;
  438. } else {
  439. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  440. limit = &intel_limits_i8xx_lvds;
  441. else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO))
  442. limit = &intel_limits_i8xx_dvo;
  443. else
  444. limit = &intel_limits_i8xx_dac;
  445. }
  446. return limit;
  447. }
  448. /* m1 is reserved as 0 in Pineview, n is a ring counter */
  449. static void pineview_clock(int refclk, intel_clock_t *clock)
  450. {
  451. clock->m = clock->m2 + 2;
  452. clock->p = clock->p1 * clock->p2;
  453. if (WARN_ON(clock->n == 0 || clock->p == 0))
  454. return;
  455. clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
  456. clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
  457. }
  458. static uint32_t i9xx_dpll_compute_m(struct dpll *dpll)
  459. {
  460. return 5 * (dpll->m1 + 2) + (dpll->m2 + 2);
  461. }
  462. static void i9xx_clock(int refclk, intel_clock_t *clock)
  463. {
  464. clock->m = i9xx_dpll_compute_m(clock);
  465. clock->p = clock->p1 * clock->p2;
  466. if (WARN_ON(clock->n + 2 == 0 || clock->p == 0))
  467. return;
  468. clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2);
  469. clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
  470. }
  471. static void chv_clock(int refclk, intel_clock_t *clock)
  472. {
  473. clock->m = clock->m1 * clock->m2;
  474. clock->p = clock->p1 * clock->p2;
  475. if (WARN_ON(clock->n == 0 || clock->p == 0))
  476. return;
  477. clock->vco = DIV_ROUND_CLOSEST_ULL((uint64_t)refclk * clock->m,
  478. clock->n << 22);
  479. clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
  480. }
  481. #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
  482. /**
  483. * Returns whether the given set of divisors are valid for a given refclk with
  484. * the given connectors.
  485. */
  486. static bool intel_PLL_is_valid(struct drm_device *dev,
  487. const intel_limit_t *limit,
  488. const intel_clock_t *clock)
  489. {
  490. if (clock->n < limit->n.min || limit->n.max < clock->n)
  491. INTELPllInvalid("n out of range\n");
  492. if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1)
  493. INTELPllInvalid("p1 out of range\n");
  494. if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2)
  495. INTELPllInvalid("m2 out of range\n");
  496. if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1)
  497. INTELPllInvalid("m1 out of range\n");
  498. if (!IS_PINEVIEW(dev) && !IS_VALLEYVIEW(dev))
  499. if (clock->m1 <= clock->m2)
  500. INTELPllInvalid("m1 <= m2\n");
  501. if (!IS_VALLEYVIEW(dev)) {
  502. if (clock->p < limit->p.min || limit->p.max < clock->p)
  503. INTELPllInvalid("p out of range\n");
  504. if (clock->m < limit->m.min || limit->m.max < clock->m)
  505. INTELPllInvalid("m out of range\n");
  506. }
  507. if (clock->vco < limit->vco.min || limit->vco.max < clock->vco)
  508. INTELPllInvalid("vco out of range\n");
  509. /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
  510. * connector, etc., rather than just a single range.
  511. */
  512. if (clock->dot < limit->dot.min || limit->dot.max < clock->dot)
  513. INTELPllInvalid("dot out of range\n");
  514. return true;
  515. }
  516. static bool
  517. i9xx_find_best_dpll(const intel_limit_t *limit, struct drm_crtc *crtc,
  518. int target, int refclk, intel_clock_t *match_clock,
  519. intel_clock_t *best_clock)
  520. {
  521. struct drm_device *dev = crtc->dev;
  522. intel_clock_t clock;
  523. int err = target;
  524. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  525. /*
  526. * For LVDS just rely on its current settings for dual-channel.
  527. * We haven't figured out how to reliably set up different
  528. * single/dual channel state, if we even can.
  529. */
  530. if (intel_is_dual_link_lvds(dev))
  531. clock.p2 = limit->p2.p2_fast;
  532. else
  533. clock.p2 = limit->p2.p2_slow;
  534. } else {
  535. if (target < limit->p2.dot_limit)
  536. clock.p2 = limit->p2.p2_slow;
  537. else
  538. clock.p2 = limit->p2.p2_fast;
  539. }
  540. memset(best_clock, 0, sizeof(*best_clock));
  541. for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
  542. clock.m1++) {
  543. for (clock.m2 = limit->m2.min;
  544. clock.m2 <= limit->m2.max; clock.m2++) {
  545. if (clock.m2 >= clock.m1)
  546. break;
  547. for (clock.n = limit->n.min;
  548. clock.n <= limit->n.max; clock.n++) {
  549. for (clock.p1 = limit->p1.min;
  550. clock.p1 <= limit->p1.max; clock.p1++) {
  551. int this_err;
  552. i9xx_clock(refclk, &clock);
  553. if (!intel_PLL_is_valid(dev, limit,
  554. &clock))
  555. continue;
  556. if (match_clock &&
  557. clock.p != match_clock->p)
  558. continue;
  559. this_err = abs(clock.dot - target);
  560. if (this_err < err) {
  561. *best_clock = clock;
  562. err = this_err;
  563. }
  564. }
  565. }
  566. }
  567. }
  568. return (err != target);
  569. }
  570. static bool
  571. pnv_find_best_dpll(const intel_limit_t *limit, struct drm_crtc *crtc,
  572. int target, int refclk, intel_clock_t *match_clock,
  573. intel_clock_t *best_clock)
  574. {
  575. struct drm_device *dev = crtc->dev;
  576. intel_clock_t clock;
  577. int err = target;
  578. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  579. /*
  580. * For LVDS just rely on its current settings for dual-channel.
  581. * We haven't figured out how to reliably set up different
  582. * single/dual channel state, if we even can.
  583. */
  584. if (intel_is_dual_link_lvds(dev))
  585. clock.p2 = limit->p2.p2_fast;
  586. else
  587. clock.p2 = limit->p2.p2_slow;
  588. } else {
  589. if (target < limit->p2.dot_limit)
  590. clock.p2 = limit->p2.p2_slow;
  591. else
  592. clock.p2 = limit->p2.p2_fast;
  593. }
  594. memset(best_clock, 0, sizeof(*best_clock));
  595. for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
  596. clock.m1++) {
  597. for (clock.m2 = limit->m2.min;
  598. clock.m2 <= limit->m2.max; clock.m2++) {
  599. for (clock.n = limit->n.min;
  600. clock.n <= limit->n.max; clock.n++) {
  601. for (clock.p1 = limit->p1.min;
  602. clock.p1 <= limit->p1.max; clock.p1++) {
  603. int this_err;
  604. pineview_clock(refclk, &clock);
  605. if (!intel_PLL_is_valid(dev, limit,
  606. &clock))
  607. continue;
  608. if (match_clock &&
  609. clock.p != match_clock->p)
  610. continue;
  611. this_err = abs(clock.dot - target);
  612. if (this_err < err) {
  613. *best_clock = clock;
  614. err = this_err;
  615. }
  616. }
  617. }
  618. }
  619. }
  620. return (err != target);
  621. }
  622. static bool
  623. g4x_find_best_dpll(const intel_limit_t *limit, struct drm_crtc *crtc,
  624. int target, int refclk, intel_clock_t *match_clock,
  625. intel_clock_t *best_clock)
  626. {
  627. struct drm_device *dev = crtc->dev;
  628. intel_clock_t clock;
  629. int max_n;
  630. bool found;
  631. /* approximately equals target * 0.00585 */
  632. int err_most = (target >> 8) + (target >> 9);
  633. found = false;
  634. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  635. if (intel_is_dual_link_lvds(dev))
  636. clock.p2 = limit->p2.p2_fast;
  637. else
  638. clock.p2 = limit->p2.p2_slow;
  639. } else {
  640. if (target < limit->p2.dot_limit)
  641. clock.p2 = limit->p2.p2_slow;
  642. else
  643. clock.p2 = limit->p2.p2_fast;
  644. }
  645. memset(best_clock, 0, sizeof(*best_clock));
  646. max_n = limit->n.max;
  647. /* based on hardware requirement, prefer smaller n to precision */
  648. for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
  649. /* based on hardware requirement, prefere larger m1,m2 */
  650. for (clock.m1 = limit->m1.max;
  651. clock.m1 >= limit->m1.min; clock.m1--) {
  652. for (clock.m2 = limit->m2.max;
  653. clock.m2 >= limit->m2.min; clock.m2--) {
  654. for (clock.p1 = limit->p1.max;
  655. clock.p1 >= limit->p1.min; clock.p1--) {
  656. int this_err;
  657. i9xx_clock(refclk, &clock);
  658. if (!intel_PLL_is_valid(dev, limit,
  659. &clock))
  660. continue;
  661. this_err = abs(clock.dot - target);
  662. if (this_err < err_most) {
  663. *best_clock = clock;
  664. err_most = this_err;
  665. max_n = clock.n;
  666. found = true;
  667. }
  668. }
  669. }
  670. }
  671. }
  672. return found;
  673. }
  674. static bool
  675. vlv_find_best_dpll(const intel_limit_t *limit, struct drm_crtc *crtc,
  676. int target, int refclk, intel_clock_t *match_clock,
  677. intel_clock_t *best_clock)
  678. {
  679. struct drm_device *dev = crtc->dev;
  680. intel_clock_t clock;
  681. unsigned int bestppm = 1000000;
  682. /* min update 19.2 MHz */
  683. int max_n = min(limit->n.max, refclk / 19200);
  684. bool found = false;
  685. target *= 5; /* fast clock */
  686. memset(best_clock, 0, sizeof(*best_clock));
  687. /* based on hardware requirement, prefer smaller n to precision */
  688. for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
  689. for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
  690. for (clock.p2 = limit->p2.p2_fast; clock.p2 >= limit->p2.p2_slow;
  691. clock.p2 -= clock.p2 > 10 ? 2 : 1) {
  692. clock.p = clock.p1 * clock.p2;
  693. /* based on hardware requirement, prefer bigger m1,m2 values */
  694. for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) {
  695. unsigned int ppm, diff;
  696. clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n,
  697. refclk * clock.m1);
  698. vlv_clock(refclk, &clock);
  699. if (!intel_PLL_is_valid(dev, limit,
  700. &clock))
  701. continue;
  702. diff = abs(clock.dot - target);
  703. ppm = div_u64(1000000ULL * diff, target);
  704. if (ppm < 100 && clock.p > best_clock->p) {
  705. bestppm = 0;
  706. *best_clock = clock;
  707. found = true;
  708. }
  709. if (bestppm >= 10 && ppm < bestppm - 10) {
  710. bestppm = ppm;
  711. *best_clock = clock;
  712. found = true;
  713. }
  714. }
  715. }
  716. }
  717. }
  718. return found;
  719. }
  720. static bool
  721. chv_find_best_dpll(const intel_limit_t *limit, struct drm_crtc *crtc,
  722. int target, int refclk, intel_clock_t *match_clock,
  723. intel_clock_t *best_clock)
  724. {
  725. struct drm_device *dev = crtc->dev;
  726. intel_clock_t clock;
  727. uint64_t m2;
  728. int found = false;
  729. memset(best_clock, 0, sizeof(*best_clock));
  730. /*
  731. * Based on hardware doc, the n always set to 1, and m1 always
  732. * set to 2. If requires to support 200Mhz refclk, we need to
  733. * revisit this because n may not 1 anymore.
  734. */
  735. clock.n = 1, clock.m1 = 2;
  736. target *= 5; /* fast clock */
  737. for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
  738. for (clock.p2 = limit->p2.p2_fast;
  739. clock.p2 >= limit->p2.p2_slow;
  740. clock.p2 -= clock.p2 > 10 ? 2 : 1) {
  741. clock.p = clock.p1 * clock.p2;
  742. m2 = DIV_ROUND_CLOSEST_ULL(((uint64_t)target * clock.p *
  743. clock.n) << 22, refclk * clock.m1);
  744. if (m2 > INT_MAX/clock.m1)
  745. continue;
  746. clock.m2 = m2;
  747. chv_clock(refclk, &clock);
  748. if (!intel_PLL_is_valid(dev, limit, &clock))
  749. continue;
  750. /* based on hardware requirement, prefer bigger p
  751. */
  752. if (clock.p > best_clock->p) {
  753. *best_clock = clock;
  754. found = true;
  755. }
  756. }
  757. }
  758. return found;
  759. }
  760. bool intel_crtc_active(struct drm_crtc *crtc)
  761. {
  762. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  763. /* Be paranoid as we can arrive here with only partial
  764. * state retrieved from the hardware during setup.
  765. *
  766. * We can ditch the adjusted_mode.crtc_clock check as soon
  767. * as Haswell has gained clock readout/fastboot support.
  768. *
  769. * We can ditch the crtc->primary->fb check as soon as we can
  770. * properly reconstruct framebuffers.
  771. */
  772. return intel_crtc->active && crtc->primary->fb &&
  773. intel_crtc->config.adjusted_mode.crtc_clock;
  774. }
  775. enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv,
  776. enum pipe pipe)
  777. {
  778. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  779. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  780. return intel_crtc->config.cpu_transcoder;
  781. }
  782. static void g4x_wait_for_vblank(struct drm_device *dev, int pipe)
  783. {
  784. struct drm_i915_private *dev_priv = dev->dev_private;
  785. u32 frame, frame_reg = PIPE_FRMCOUNT_GM45(pipe);
  786. frame = I915_READ(frame_reg);
  787. if (wait_for(I915_READ_NOTRACE(frame_reg) != frame, 50))
  788. WARN(1, "vblank wait timed out\n");
  789. }
  790. /**
  791. * intel_wait_for_vblank - wait for vblank on a given pipe
  792. * @dev: drm device
  793. * @pipe: pipe to wait for
  794. *
  795. * Wait for vblank to occur on a given pipe. Needed for various bits of
  796. * mode setting code.
  797. */
  798. void intel_wait_for_vblank(struct drm_device *dev, int pipe)
  799. {
  800. struct drm_i915_private *dev_priv = dev->dev_private;
  801. int pipestat_reg = PIPESTAT(pipe);
  802. if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
  803. g4x_wait_for_vblank(dev, pipe);
  804. return;
  805. }
  806. /* Clear existing vblank status. Note this will clear any other
  807. * sticky status fields as well.
  808. *
  809. * This races with i915_driver_irq_handler() with the result
  810. * that either function could miss a vblank event. Here it is not
  811. * fatal, as we will either wait upon the next vblank interrupt or
  812. * timeout. Generally speaking intel_wait_for_vblank() is only
  813. * called during modeset at which time the GPU should be idle and
  814. * should *not* be performing page flips and thus not waiting on
  815. * vblanks...
  816. * Currently, the result of us stealing a vblank from the irq
  817. * handler is that a single frame will be skipped during swapbuffers.
  818. */
  819. I915_WRITE(pipestat_reg,
  820. I915_READ(pipestat_reg) | PIPE_VBLANK_INTERRUPT_STATUS);
  821. /* Wait for vblank interrupt bit to set */
  822. if (wait_for(I915_READ(pipestat_reg) &
  823. PIPE_VBLANK_INTERRUPT_STATUS,
  824. 50))
  825. DRM_DEBUG_KMS("vblank wait timed out\n");
  826. }
  827. static bool pipe_dsl_stopped(struct drm_device *dev, enum pipe pipe)
  828. {
  829. struct drm_i915_private *dev_priv = dev->dev_private;
  830. u32 reg = PIPEDSL(pipe);
  831. u32 line1, line2;
  832. u32 line_mask;
  833. if (IS_GEN2(dev))
  834. line_mask = DSL_LINEMASK_GEN2;
  835. else
  836. line_mask = DSL_LINEMASK_GEN3;
  837. line1 = I915_READ(reg) & line_mask;
  838. mdelay(5);
  839. line2 = I915_READ(reg) & line_mask;
  840. return line1 == line2;
  841. }
  842. /*
  843. * intel_wait_for_pipe_off - wait for pipe to turn off
  844. * @dev: drm device
  845. * @pipe: pipe to wait for
  846. *
  847. * After disabling a pipe, we can't wait for vblank in the usual way,
  848. * spinning on the vblank interrupt status bit, since we won't actually
  849. * see an interrupt when the pipe is disabled.
  850. *
  851. * On Gen4 and above:
  852. * wait for the pipe register state bit to turn off
  853. *
  854. * Otherwise:
  855. * wait for the display line value to settle (it usually
  856. * ends up stopping at the start of the next frame).
  857. *
  858. */
  859. void intel_wait_for_pipe_off(struct drm_device *dev, int pipe)
  860. {
  861. struct drm_i915_private *dev_priv = dev->dev_private;
  862. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  863. pipe);
  864. if (INTEL_INFO(dev)->gen >= 4) {
  865. int reg = PIPECONF(cpu_transcoder);
  866. /* Wait for the Pipe State to go off */
  867. if (wait_for((I915_READ(reg) & I965_PIPECONF_ACTIVE) == 0,
  868. 100))
  869. WARN(1, "pipe_off wait timed out\n");
  870. } else {
  871. /* Wait for the display line to settle */
  872. if (wait_for(pipe_dsl_stopped(dev, pipe), 100))
  873. WARN(1, "pipe_off wait timed out\n");
  874. }
  875. }
  876. /*
  877. * ibx_digital_port_connected - is the specified port connected?
  878. * @dev_priv: i915 private structure
  879. * @port: the port to test
  880. *
  881. * Returns true if @port is connected, false otherwise.
  882. */
  883. bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
  884. struct intel_digital_port *port)
  885. {
  886. u32 bit;
  887. if (HAS_PCH_IBX(dev_priv->dev)) {
  888. switch (port->port) {
  889. case PORT_B:
  890. bit = SDE_PORTB_HOTPLUG;
  891. break;
  892. case PORT_C:
  893. bit = SDE_PORTC_HOTPLUG;
  894. break;
  895. case PORT_D:
  896. bit = SDE_PORTD_HOTPLUG;
  897. break;
  898. default:
  899. return true;
  900. }
  901. } else {
  902. switch (port->port) {
  903. case PORT_B:
  904. bit = SDE_PORTB_HOTPLUG_CPT;
  905. break;
  906. case PORT_C:
  907. bit = SDE_PORTC_HOTPLUG_CPT;
  908. break;
  909. case PORT_D:
  910. bit = SDE_PORTD_HOTPLUG_CPT;
  911. break;
  912. default:
  913. return true;
  914. }
  915. }
  916. return I915_READ(SDEISR) & bit;
  917. }
  918. static const char *state_string(bool enabled)
  919. {
  920. return enabled ? "on" : "off";
  921. }
  922. /* Only for pre-ILK configs */
  923. void assert_pll(struct drm_i915_private *dev_priv,
  924. enum pipe pipe, bool state)
  925. {
  926. int reg;
  927. u32 val;
  928. bool cur_state;
  929. reg = DPLL(pipe);
  930. val = I915_READ(reg);
  931. cur_state = !!(val & DPLL_VCO_ENABLE);
  932. WARN(cur_state != state,
  933. "PLL state assertion failure (expected %s, current %s)\n",
  934. state_string(state), state_string(cur_state));
  935. }
  936. /* XXX: the dsi pll is shared between MIPI DSI ports */
  937. static void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state)
  938. {
  939. u32 val;
  940. bool cur_state;
  941. mutex_lock(&dev_priv->dpio_lock);
  942. val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL);
  943. mutex_unlock(&dev_priv->dpio_lock);
  944. cur_state = val & DSI_PLL_VCO_EN;
  945. WARN(cur_state != state,
  946. "DSI PLL state assertion failure (expected %s, current %s)\n",
  947. state_string(state), state_string(cur_state));
  948. }
  949. #define assert_dsi_pll_enabled(d) assert_dsi_pll(d, true)
  950. #define assert_dsi_pll_disabled(d) assert_dsi_pll(d, false)
  951. struct intel_shared_dpll *
  952. intel_crtc_to_shared_dpll(struct intel_crtc *crtc)
  953. {
  954. struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
  955. if (crtc->config.shared_dpll < 0)
  956. return NULL;
  957. return &dev_priv->shared_dplls[crtc->config.shared_dpll];
  958. }
  959. /* For ILK+ */
  960. void assert_shared_dpll(struct drm_i915_private *dev_priv,
  961. struct intel_shared_dpll *pll,
  962. bool state)
  963. {
  964. bool cur_state;
  965. struct intel_dpll_hw_state hw_state;
  966. if (HAS_PCH_LPT(dev_priv->dev)) {
  967. DRM_DEBUG_DRIVER("LPT detected: skipping PCH PLL test\n");
  968. return;
  969. }
  970. if (WARN (!pll,
  971. "asserting DPLL %s with no DPLL\n", state_string(state)))
  972. return;
  973. cur_state = pll->get_hw_state(dev_priv, pll, &hw_state);
  974. WARN(cur_state != state,
  975. "%s assertion failure (expected %s, current %s)\n",
  976. pll->name, state_string(state), state_string(cur_state));
  977. }
  978. static void assert_fdi_tx(struct drm_i915_private *dev_priv,
  979. enum pipe pipe, bool state)
  980. {
  981. int reg;
  982. u32 val;
  983. bool cur_state;
  984. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  985. pipe);
  986. if (HAS_DDI(dev_priv->dev)) {
  987. /* DDI does not have a specific FDI_TX register */
  988. reg = TRANS_DDI_FUNC_CTL(cpu_transcoder);
  989. val = I915_READ(reg);
  990. cur_state = !!(val & TRANS_DDI_FUNC_ENABLE);
  991. } else {
  992. reg = FDI_TX_CTL(pipe);
  993. val = I915_READ(reg);
  994. cur_state = !!(val & FDI_TX_ENABLE);
  995. }
  996. WARN(cur_state != state,
  997. "FDI TX state assertion failure (expected %s, current %s)\n",
  998. state_string(state), state_string(cur_state));
  999. }
  1000. #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
  1001. #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
  1002. static void assert_fdi_rx(struct drm_i915_private *dev_priv,
  1003. enum pipe pipe, bool state)
  1004. {
  1005. int reg;
  1006. u32 val;
  1007. bool cur_state;
  1008. reg = FDI_RX_CTL(pipe);
  1009. val = I915_READ(reg);
  1010. cur_state = !!(val & FDI_RX_ENABLE);
  1011. WARN(cur_state != state,
  1012. "FDI RX state assertion failure (expected %s, current %s)\n",
  1013. state_string(state), state_string(cur_state));
  1014. }
  1015. #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
  1016. #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
  1017. static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv,
  1018. enum pipe pipe)
  1019. {
  1020. int reg;
  1021. u32 val;
  1022. /* ILK FDI PLL is always enabled */
  1023. if (INTEL_INFO(dev_priv->dev)->gen == 5)
  1024. return;
  1025. /* On Haswell, DDI ports are responsible for the FDI PLL setup */
  1026. if (HAS_DDI(dev_priv->dev))
  1027. return;
  1028. reg = FDI_TX_CTL(pipe);
  1029. val = I915_READ(reg);
  1030. WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n");
  1031. }
  1032. void assert_fdi_rx_pll(struct drm_i915_private *dev_priv,
  1033. enum pipe pipe, bool state)
  1034. {
  1035. int reg;
  1036. u32 val;
  1037. bool cur_state;
  1038. reg = FDI_RX_CTL(pipe);
  1039. val = I915_READ(reg);
  1040. cur_state = !!(val & FDI_RX_PLL_ENABLE);
  1041. WARN(cur_state != state,
  1042. "FDI RX PLL assertion failure (expected %s, current %s)\n",
  1043. state_string(state), state_string(cur_state));
  1044. }
  1045. static void assert_panel_unlocked(struct drm_i915_private *dev_priv,
  1046. enum pipe pipe)
  1047. {
  1048. int pp_reg, lvds_reg;
  1049. u32 val;
  1050. enum pipe panel_pipe = PIPE_A;
  1051. bool locked = true;
  1052. if (HAS_PCH_SPLIT(dev_priv->dev)) {
  1053. pp_reg = PCH_PP_CONTROL;
  1054. lvds_reg = PCH_LVDS;
  1055. } else {
  1056. pp_reg = PP_CONTROL;
  1057. lvds_reg = LVDS;
  1058. }
  1059. val = I915_READ(pp_reg);
  1060. if (!(val & PANEL_POWER_ON) ||
  1061. ((val & PANEL_UNLOCK_REGS) == PANEL_UNLOCK_REGS))
  1062. locked = false;
  1063. if (I915_READ(lvds_reg) & LVDS_PIPEB_SELECT)
  1064. panel_pipe = PIPE_B;
  1065. WARN(panel_pipe == pipe && locked,
  1066. "panel assertion failure, pipe %c regs locked\n",
  1067. pipe_name(pipe));
  1068. }
  1069. static void assert_cursor(struct drm_i915_private *dev_priv,
  1070. enum pipe pipe, bool state)
  1071. {
  1072. struct drm_device *dev = dev_priv->dev;
  1073. bool cur_state;
  1074. if (IS_845G(dev) || IS_I865G(dev))
  1075. cur_state = I915_READ(_CURACNTR) & CURSOR_ENABLE;
  1076. else
  1077. cur_state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
  1078. WARN(cur_state != state,
  1079. "cursor on pipe %c assertion failure (expected %s, current %s)\n",
  1080. pipe_name(pipe), state_string(state), state_string(cur_state));
  1081. }
  1082. #define assert_cursor_enabled(d, p) assert_cursor(d, p, true)
  1083. #define assert_cursor_disabled(d, p) assert_cursor(d, p, false)
  1084. void assert_pipe(struct drm_i915_private *dev_priv,
  1085. enum pipe pipe, bool state)
  1086. {
  1087. int reg;
  1088. u32 val;
  1089. bool cur_state;
  1090. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  1091. pipe);
  1092. /* if we need the pipe A quirk it must be always on */
  1093. if (pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE)
  1094. state = true;
  1095. if (!intel_display_power_enabled(dev_priv,
  1096. POWER_DOMAIN_TRANSCODER(cpu_transcoder))) {
  1097. cur_state = false;
  1098. } else {
  1099. reg = PIPECONF(cpu_transcoder);
  1100. val = I915_READ(reg);
  1101. cur_state = !!(val & PIPECONF_ENABLE);
  1102. }
  1103. WARN(cur_state != state,
  1104. "pipe %c assertion failure (expected %s, current %s)\n",
  1105. pipe_name(pipe), state_string(state), state_string(cur_state));
  1106. }
  1107. static void assert_plane(struct drm_i915_private *dev_priv,
  1108. enum plane plane, bool state)
  1109. {
  1110. int reg;
  1111. u32 val;
  1112. bool cur_state;
  1113. reg = DSPCNTR(plane);
  1114. val = I915_READ(reg);
  1115. cur_state = !!(val & DISPLAY_PLANE_ENABLE);
  1116. WARN(cur_state != state,
  1117. "plane %c assertion failure (expected %s, current %s)\n",
  1118. plane_name(plane), state_string(state), state_string(cur_state));
  1119. }
  1120. #define assert_plane_enabled(d, p) assert_plane(d, p, true)
  1121. #define assert_plane_disabled(d, p) assert_plane(d, p, false)
  1122. static void assert_planes_disabled(struct drm_i915_private *dev_priv,
  1123. enum pipe pipe)
  1124. {
  1125. struct drm_device *dev = dev_priv->dev;
  1126. int reg, i;
  1127. u32 val;
  1128. int cur_pipe;
  1129. /* Primary planes are fixed to pipes on gen4+ */
  1130. if (INTEL_INFO(dev)->gen >= 4) {
  1131. reg = DSPCNTR(pipe);
  1132. val = I915_READ(reg);
  1133. WARN(val & DISPLAY_PLANE_ENABLE,
  1134. "plane %c assertion failure, should be disabled but not\n",
  1135. plane_name(pipe));
  1136. return;
  1137. }
  1138. /* Need to check both planes against the pipe */
  1139. for_each_pipe(i) {
  1140. reg = DSPCNTR(i);
  1141. val = I915_READ(reg);
  1142. cur_pipe = (val & DISPPLANE_SEL_PIPE_MASK) >>
  1143. DISPPLANE_SEL_PIPE_SHIFT;
  1144. WARN((val & DISPLAY_PLANE_ENABLE) && pipe == cur_pipe,
  1145. "plane %c assertion failure, should be off on pipe %c but is still active\n",
  1146. plane_name(i), pipe_name(pipe));
  1147. }
  1148. }
  1149. static void assert_sprites_disabled(struct drm_i915_private *dev_priv,
  1150. enum pipe pipe)
  1151. {
  1152. struct drm_device *dev = dev_priv->dev;
  1153. int reg, sprite;
  1154. u32 val;
  1155. if (IS_VALLEYVIEW(dev)) {
  1156. for_each_sprite(pipe, sprite) {
  1157. reg = SPCNTR(pipe, sprite);
  1158. val = I915_READ(reg);
  1159. WARN(val & SP_ENABLE,
  1160. "sprite %c assertion failure, should be off on pipe %c but is still active\n",
  1161. sprite_name(pipe, sprite), pipe_name(pipe));
  1162. }
  1163. } else if (INTEL_INFO(dev)->gen >= 7) {
  1164. reg = SPRCTL(pipe);
  1165. val = I915_READ(reg);
  1166. WARN(val & SPRITE_ENABLE,
  1167. "sprite %c assertion failure, should be off on pipe %c but is still active\n",
  1168. plane_name(pipe), pipe_name(pipe));
  1169. } else if (INTEL_INFO(dev)->gen >= 5) {
  1170. reg = DVSCNTR(pipe);
  1171. val = I915_READ(reg);
  1172. WARN(val & DVS_ENABLE,
  1173. "sprite %c assertion failure, should be off on pipe %c but is still active\n",
  1174. plane_name(pipe), pipe_name(pipe));
  1175. }
  1176. }
  1177. static void ibx_assert_pch_refclk_enabled(struct drm_i915_private *dev_priv)
  1178. {
  1179. u32 val;
  1180. bool enabled;
  1181. WARN_ON(!(HAS_PCH_IBX(dev_priv->dev) || HAS_PCH_CPT(dev_priv->dev)));
  1182. val = I915_READ(PCH_DREF_CONTROL);
  1183. enabled = !!(val & (DREF_SSC_SOURCE_MASK | DREF_NONSPREAD_SOURCE_MASK |
  1184. DREF_SUPERSPREAD_SOURCE_MASK));
  1185. WARN(!enabled, "PCH refclk assertion failure, should be active but is disabled\n");
  1186. }
  1187. static void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv,
  1188. enum pipe pipe)
  1189. {
  1190. int reg;
  1191. u32 val;
  1192. bool enabled;
  1193. reg = PCH_TRANSCONF(pipe);
  1194. val = I915_READ(reg);
  1195. enabled = !!(val & TRANS_ENABLE);
  1196. WARN(enabled,
  1197. "transcoder assertion failed, should be off on pipe %c but is still active\n",
  1198. pipe_name(pipe));
  1199. }
  1200. static bool dp_pipe_enabled(struct drm_i915_private *dev_priv,
  1201. enum pipe pipe, u32 port_sel, u32 val)
  1202. {
  1203. if ((val & DP_PORT_EN) == 0)
  1204. return false;
  1205. if (HAS_PCH_CPT(dev_priv->dev)) {
  1206. u32 trans_dp_ctl_reg = TRANS_DP_CTL(pipe);
  1207. u32 trans_dp_ctl = I915_READ(trans_dp_ctl_reg);
  1208. if ((trans_dp_ctl & TRANS_DP_PORT_SEL_MASK) != port_sel)
  1209. return false;
  1210. } else if (IS_CHERRYVIEW(dev_priv->dev)) {
  1211. if ((val & DP_PIPE_MASK_CHV) != DP_PIPE_SELECT_CHV(pipe))
  1212. return false;
  1213. } else {
  1214. if ((val & DP_PIPE_MASK) != (pipe << 30))
  1215. return false;
  1216. }
  1217. return true;
  1218. }
  1219. static bool hdmi_pipe_enabled(struct drm_i915_private *dev_priv,
  1220. enum pipe pipe, u32 val)
  1221. {
  1222. if ((val & SDVO_ENABLE) == 0)
  1223. return false;
  1224. if (HAS_PCH_CPT(dev_priv->dev)) {
  1225. if ((val & SDVO_PIPE_SEL_MASK_CPT) != SDVO_PIPE_SEL_CPT(pipe))
  1226. return false;
  1227. } else if (IS_CHERRYVIEW(dev_priv->dev)) {
  1228. if ((val & SDVO_PIPE_SEL_MASK_CHV) != SDVO_PIPE_SEL_CHV(pipe))
  1229. return false;
  1230. } else {
  1231. if ((val & SDVO_PIPE_SEL_MASK) != SDVO_PIPE_SEL(pipe))
  1232. return false;
  1233. }
  1234. return true;
  1235. }
  1236. static bool lvds_pipe_enabled(struct drm_i915_private *dev_priv,
  1237. enum pipe pipe, u32 val)
  1238. {
  1239. if ((val & LVDS_PORT_EN) == 0)
  1240. return false;
  1241. if (HAS_PCH_CPT(dev_priv->dev)) {
  1242. if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe))
  1243. return false;
  1244. } else {
  1245. if ((val & LVDS_PIPE_MASK) != LVDS_PIPE(pipe))
  1246. return false;
  1247. }
  1248. return true;
  1249. }
  1250. static bool adpa_pipe_enabled(struct drm_i915_private *dev_priv,
  1251. enum pipe pipe, u32 val)
  1252. {
  1253. if ((val & ADPA_DAC_ENABLE) == 0)
  1254. return false;
  1255. if (HAS_PCH_CPT(dev_priv->dev)) {
  1256. if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe))
  1257. return false;
  1258. } else {
  1259. if ((val & ADPA_PIPE_SELECT_MASK) != ADPA_PIPE_SELECT(pipe))
  1260. return false;
  1261. }
  1262. return true;
  1263. }
  1264. static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv,
  1265. enum pipe pipe, int reg, u32 port_sel)
  1266. {
  1267. u32 val = I915_READ(reg);
  1268. WARN(dp_pipe_enabled(dev_priv, pipe, port_sel, val),
  1269. "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n",
  1270. reg, pipe_name(pipe));
  1271. WARN(HAS_PCH_IBX(dev_priv->dev) && (val & DP_PORT_EN) == 0
  1272. && (val & DP_PIPEB_SELECT),
  1273. "IBX PCH dp port still using transcoder B\n");
  1274. }
  1275. static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv,
  1276. enum pipe pipe, int reg)
  1277. {
  1278. u32 val = I915_READ(reg);
  1279. WARN(hdmi_pipe_enabled(dev_priv, pipe, val),
  1280. "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n",
  1281. reg, pipe_name(pipe));
  1282. WARN(HAS_PCH_IBX(dev_priv->dev) && (val & SDVO_ENABLE) == 0
  1283. && (val & SDVO_PIPE_B_SELECT),
  1284. "IBX PCH hdmi port still using transcoder B\n");
  1285. }
  1286. static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv,
  1287. enum pipe pipe)
  1288. {
  1289. int reg;
  1290. u32 val;
  1291. assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_B, TRANS_DP_PORT_SEL_B);
  1292. assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_C, TRANS_DP_PORT_SEL_C);
  1293. assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_D, TRANS_DP_PORT_SEL_D);
  1294. reg = PCH_ADPA;
  1295. val = I915_READ(reg);
  1296. WARN(adpa_pipe_enabled(dev_priv, pipe, val),
  1297. "PCH VGA enabled on transcoder %c, should be disabled\n",
  1298. pipe_name(pipe));
  1299. reg = PCH_LVDS;
  1300. val = I915_READ(reg);
  1301. WARN(lvds_pipe_enabled(dev_priv, pipe, val),
  1302. "PCH LVDS enabled on transcoder %c, should be disabled\n",
  1303. pipe_name(pipe));
  1304. assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIB);
  1305. assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIC);
  1306. assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMID);
  1307. }
  1308. static void intel_init_dpio(struct drm_device *dev)
  1309. {
  1310. struct drm_i915_private *dev_priv = dev->dev_private;
  1311. if (!IS_VALLEYVIEW(dev))
  1312. return;
  1313. /*
  1314. * IOSF_PORT_DPIO is used for VLV x2 PHY (DP/HDMI B and C),
  1315. * CHV x1 PHY (DP/HDMI D)
  1316. * IOSF_PORT_DPIO_2 is used for CHV x2 PHY (DP/HDMI B and C)
  1317. */
  1318. if (IS_CHERRYVIEW(dev)) {
  1319. DPIO_PHY_IOSF_PORT(DPIO_PHY0) = IOSF_PORT_DPIO_2;
  1320. DPIO_PHY_IOSF_PORT(DPIO_PHY1) = IOSF_PORT_DPIO;
  1321. } else {
  1322. DPIO_PHY_IOSF_PORT(DPIO_PHY0) = IOSF_PORT_DPIO;
  1323. }
  1324. }
  1325. static void intel_reset_dpio(struct drm_device *dev)
  1326. {
  1327. struct drm_i915_private *dev_priv = dev->dev_private;
  1328. if (!IS_VALLEYVIEW(dev))
  1329. return;
  1330. if (IS_CHERRYVIEW(dev)) {
  1331. enum dpio_phy phy;
  1332. u32 val;
  1333. for (phy = DPIO_PHY0; phy < I915_NUM_PHYS_VLV; phy++) {
  1334. /* Poll for phypwrgood signal */
  1335. if (wait_for(I915_READ(DISPLAY_PHY_STATUS) &
  1336. PHY_POWERGOOD(phy), 1))
  1337. DRM_ERROR("Display PHY %d is not power up\n", phy);
  1338. /*
  1339. * Deassert common lane reset for PHY.
  1340. *
  1341. * This should only be done on init and resume from S3
  1342. * with both PLLs disabled, or we risk losing DPIO and
  1343. * PLL synchronization.
  1344. */
  1345. val = I915_READ(DISPLAY_PHY_CONTROL);
  1346. I915_WRITE(DISPLAY_PHY_CONTROL,
  1347. PHY_COM_LANE_RESET_DEASSERT(phy, val));
  1348. }
  1349. } else {
  1350. /*
  1351. * If DPIO has already been reset, e.g. by BIOS, just skip all
  1352. * this.
  1353. */
  1354. if (I915_READ(DPIO_CTL) & DPIO_CMNRST)
  1355. return;
  1356. /*
  1357. * From VLV2A0_DP_eDP_HDMI_DPIO_driver_vbios_notes_11.docx:
  1358. * Need to assert and de-assert PHY SB reset by gating the
  1359. * common lane power, then un-gating it.
  1360. * Simply ungating isn't enough to reset the PHY enough to get
  1361. * ports and lanes running.
  1362. */
  1363. __vlv_set_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC,
  1364. false);
  1365. __vlv_set_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC,
  1366. true);
  1367. }
  1368. }
  1369. static void vlv_enable_pll(struct intel_crtc *crtc)
  1370. {
  1371. struct drm_device *dev = crtc->base.dev;
  1372. struct drm_i915_private *dev_priv = dev->dev_private;
  1373. int reg = DPLL(crtc->pipe);
  1374. u32 dpll = crtc->config.dpll_hw_state.dpll;
  1375. assert_pipe_disabled(dev_priv, crtc->pipe);
  1376. /* No really, not for ILK+ */
  1377. BUG_ON(!IS_VALLEYVIEW(dev_priv->dev));
  1378. /* PLL is protected by panel, make sure we can write it */
  1379. if (IS_MOBILE(dev_priv->dev) && !IS_I830(dev_priv->dev))
  1380. assert_panel_unlocked(dev_priv, crtc->pipe);
  1381. I915_WRITE(reg, dpll);
  1382. POSTING_READ(reg);
  1383. udelay(150);
  1384. if (wait_for(((I915_READ(reg) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1))
  1385. DRM_ERROR("DPLL %d failed to lock\n", crtc->pipe);
  1386. I915_WRITE(DPLL_MD(crtc->pipe), crtc->config.dpll_hw_state.dpll_md);
  1387. POSTING_READ(DPLL_MD(crtc->pipe));
  1388. /* We do this three times for luck */
  1389. I915_WRITE(reg, dpll);
  1390. POSTING_READ(reg);
  1391. udelay(150); /* wait for warmup */
  1392. I915_WRITE(reg, dpll);
  1393. POSTING_READ(reg);
  1394. udelay(150); /* wait for warmup */
  1395. I915_WRITE(reg, dpll);
  1396. POSTING_READ(reg);
  1397. udelay(150); /* wait for warmup */
  1398. }
  1399. static void chv_enable_pll(struct intel_crtc *crtc)
  1400. {
  1401. struct drm_device *dev = crtc->base.dev;
  1402. struct drm_i915_private *dev_priv = dev->dev_private;
  1403. int pipe = crtc->pipe;
  1404. enum dpio_channel port = vlv_pipe_to_channel(pipe);
  1405. u32 tmp;
  1406. assert_pipe_disabled(dev_priv, crtc->pipe);
  1407. BUG_ON(!IS_CHERRYVIEW(dev_priv->dev));
  1408. mutex_lock(&dev_priv->dpio_lock);
  1409. /* Enable back the 10bit clock to display controller */
  1410. tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
  1411. tmp |= DPIO_DCLKP_EN;
  1412. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp);
  1413. /*
  1414. * Need to wait > 100ns between dclkp clock enable bit and PLL enable.
  1415. */
  1416. udelay(1);
  1417. /* Enable PLL */
  1418. I915_WRITE(DPLL(pipe), crtc->config.dpll_hw_state.dpll);
  1419. /* Check PLL is locked */
  1420. if (wait_for(((I915_READ(DPLL(pipe)) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1))
  1421. DRM_ERROR("PLL %d failed to lock\n", pipe);
  1422. /* not sure when this should be written */
  1423. I915_WRITE(DPLL_MD(pipe), crtc->config.dpll_hw_state.dpll_md);
  1424. POSTING_READ(DPLL_MD(pipe));
  1425. mutex_unlock(&dev_priv->dpio_lock);
  1426. }
  1427. static void i9xx_enable_pll(struct intel_crtc *crtc)
  1428. {
  1429. struct drm_device *dev = crtc->base.dev;
  1430. struct drm_i915_private *dev_priv = dev->dev_private;
  1431. int reg = DPLL(crtc->pipe);
  1432. u32 dpll = crtc->config.dpll_hw_state.dpll;
  1433. assert_pipe_disabled(dev_priv, crtc->pipe);
  1434. /* No really, not for ILK+ */
  1435. BUG_ON(INTEL_INFO(dev)->gen >= 5);
  1436. /* PLL is protected by panel, make sure we can write it */
  1437. if (IS_MOBILE(dev) && !IS_I830(dev))
  1438. assert_panel_unlocked(dev_priv, crtc->pipe);
  1439. I915_WRITE(reg, dpll);
  1440. /* Wait for the clocks to stabilize. */
  1441. POSTING_READ(reg);
  1442. udelay(150);
  1443. if (INTEL_INFO(dev)->gen >= 4) {
  1444. I915_WRITE(DPLL_MD(crtc->pipe),
  1445. crtc->config.dpll_hw_state.dpll_md);
  1446. } else {
  1447. /* The pixel multiplier can only be updated once the
  1448. * DPLL is enabled and the clocks are stable.
  1449. *
  1450. * So write it again.
  1451. */
  1452. I915_WRITE(reg, dpll);
  1453. }
  1454. /* We do this three times for luck */
  1455. I915_WRITE(reg, dpll);
  1456. POSTING_READ(reg);
  1457. udelay(150); /* wait for warmup */
  1458. I915_WRITE(reg, dpll);
  1459. POSTING_READ(reg);
  1460. udelay(150); /* wait for warmup */
  1461. I915_WRITE(reg, dpll);
  1462. POSTING_READ(reg);
  1463. udelay(150); /* wait for warmup */
  1464. }
  1465. /**
  1466. * i9xx_disable_pll - disable a PLL
  1467. * @dev_priv: i915 private structure
  1468. * @pipe: pipe PLL to disable
  1469. *
  1470. * Disable the PLL for @pipe, making sure the pipe is off first.
  1471. *
  1472. * Note! This is for pre-ILK only.
  1473. */
  1474. static void i9xx_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
  1475. {
  1476. /* Don't disable pipe A or pipe A PLLs if needed */
  1477. if (pipe == PIPE_A && (dev_priv->quirks & QUIRK_PIPEA_FORCE))
  1478. return;
  1479. /* Make sure the pipe isn't still relying on us */
  1480. assert_pipe_disabled(dev_priv, pipe);
  1481. I915_WRITE(DPLL(pipe), 0);
  1482. POSTING_READ(DPLL(pipe));
  1483. }
  1484. static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
  1485. {
  1486. u32 val = 0;
  1487. /* Make sure the pipe isn't still relying on us */
  1488. assert_pipe_disabled(dev_priv, pipe);
  1489. /*
  1490. * Leave integrated clock source and reference clock enabled for pipe B.
  1491. * The latter is needed for VGA hotplug / manual detection.
  1492. */
  1493. if (pipe == PIPE_B)
  1494. val = DPLL_INTEGRATED_CRI_CLK_VLV | DPLL_REFA_CLK_ENABLE_VLV;
  1495. I915_WRITE(DPLL(pipe), val);
  1496. POSTING_READ(DPLL(pipe));
  1497. }
  1498. static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
  1499. {
  1500. enum dpio_channel port = vlv_pipe_to_channel(pipe);
  1501. u32 val;
  1502. /* Make sure the pipe isn't still relying on us */
  1503. assert_pipe_disabled(dev_priv, pipe);
  1504. /* Set PLL en = 0 */
  1505. val = DPLL_SSC_REF_CLOCK_CHV;
  1506. if (pipe != PIPE_A)
  1507. val |= DPLL_INTEGRATED_CRI_CLK_VLV;
  1508. I915_WRITE(DPLL(pipe), val);
  1509. POSTING_READ(DPLL(pipe));
  1510. mutex_lock(&dev_priv->dpio_lock);
  1511. /* Disable 10bit clock to display controller */
  1512. val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
  1513. val &= ~DPIO_DCLKP_EN;
  1514. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val);
  1515. /* disable left/right clock distribution */
  1516. if (pipe != PIPE_B) {
  1517. val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW5_CH0);
  1518. val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK);
  1519. vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW5_CH0, val);
  1520. } else {
  1521. val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW1_CH1);
  1522. val &= ~(CHV_BUFLEFTENA2_MASK | CHV_BUFRIGHTENA2_MASK);
  1523. vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW1_CH1, val);
  1524. }
  1525. mutex_unlock(&dev_priv->dpio_lock);
  1526. }
  1527. void vlv_wait_port_ready(struct drm_i915_private *dev_priv,
  1528. struct intel_digital_port *dport)
  1529. {
  1530. u32 port_mask;
  1531. int dpll_reg;
  1532. switch (dport->port) {
  1533. case PORT_B:
  1534. port_mask = DPLL_PORTB_READY_MASK;
  1535. dpll_reg = DPLL(0);
  1536. break;
  1537. case PORT_C:
  1538. port_mask = DPLL_PORTC_READY_MASK;
  1539. dpll_reg = DPLL(0);
  1540. break;
  1541. case PORT_D:
  1542. port_mask = DPLL_PORTD_READY_MASK;
  1543. dpll_reg = DPIO_PHY_STATUS;
  1544. break;
  1545. default:
  1546. BUG();
  1547. }
  1548. if (wait_for((I915_READ(dpll_reg) & port_mask) == 0, 1000))
  1549. WARN(1, "timed out waiting for port %c ready: 0x%08x\n",
  1550. port_name(dport->port), I915_READ(dpll_reg));
  1551. }
  1552. static void intel_prepare_shared_dpll(struct intel_crtc *crtc)
  1553. {
  1554. struct drm_device *dev = crtc->base.dev;
  1555. struct drm_i915_private *dev_priv = dev->dev_private;
  1556. struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
  1557. if (WARN_ON(pll == NULL))
  1558. return;
  1559. WARN_ON(!pll->refcount);
  1560. if (pll->active == 0) {
  1561. DRM_DEBUG_DRIVER("setting up %s\n", pll->name);
  1562. WARN_ON(pll->on);
  1563. assert_shared_dpll_disabled(dev_priv, pll);
  1564. pll->mode_set(dev_priv, pll);
  1565. }
  1566. }
  1567. /**
  1568. * intel_enable_shared_dpll - enable PCH PLL
  1569. * @dev_priv: i915 private structure
  1570. * @pipe: pipe PLL to enable
  1571. *
  1572. * The PCH PLL needs to be enabled before the PCH transcoder, since it
  1573. * drives the transcoder clock.
  1574. */
  1575. static void intel_enable_shared_dpll(struct intel_crtc *crtc)
  1576. {
  1577. struct drm_device *dev = crtc->base.dev;
  1578. struct drm_i915_private *dev_priv = dev->dev_private;
  1579. struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
  1580. if (WARN_ON(pll == NULL))
  1581. return;
  1582. if (WARN_ON(pll->refcount == 0))
  1583. return;
  1584. DRM_DEBUG_KMS("enable %s (active %d, on? %d)for crtc %d\n",
  1585. pll->name, pll->active, pll->on,
  1586. crtc->base.base.id);
  1587. if (pll->active++) {
  1588. WARN_ON(!pll->on);
  1589. assert_shared_dpll_enabled(dev_priv, pll);
  1590. return;
  1591. }
  1592. WARN_ON(pll->on);
  1593. DRM_DEBUG_KMS("enabling %s\n", pll->name);
  1594. pll->enable(dev_priv, pll);
  1595. pll->on = true;
  1596. }
  1597. static void intel_disable_shared_dpll(struct intel_crtc *crtc)
  1598. {
  1599. struct drm_device *dev = crtc->base.dev;
  1600. struct drm_i915_private *dev_priv = dev->dev_private;
  1601. struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
  1602. /* PCH only available on ILK+ */
  1603. BUG_ON(INTEL_INFO(dev)->gen < 5);
  1604. if (WARN_ON(pll == NULL))
  1605. return;
  1606. if (WARN_ON(pll->refcount == 0))
  1607. return;
  1608. DRM_DEBUG_KMS("disable %s (active %d, on? %d) for crtc %d\n",
  1609. pll->name, pll->active, pll->on,
  1610. crtc->base.base.id);
  1611. if (WARN_ON(pll->active == 0)) {
  1612. assert_shared_dpll_disabled(dev_priv, pll);
  1613. return;
  1614. }
  1615. assert_shared_dpll_enabled(dev_priv, pll);
  1616. WARN_ON(!pll->on);
  1617. if (--pll->active)
  1618. return;
  1619. DRM_DEBUG_KMS("disabling %s\n", pll->name);
  1620. pll->disable(dev_priv, pll);
  1621. pll->on = false;
  1622. }
  1623. static void ironlake_enable_pch_transcoder(struct drm_i915_private *dev_priv,
  1624. enum pipe pipe)
  1625. {
  1626. struct drm_device *dev = dev_priv->dev;
  1627. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  1628. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1629. uint32_t reg, val, pipeconf_val;
  1630. /* PCH only available on ILK+ */
  1631. BUG_ON(INTEL_INFO(dev)->gen < 5);
  1632. /* Make sure PCH DPLL is enabled */
  1633. assert_shared_dpll_enabled(dev_priv,
  1634. intel_crtc_to_shared_dpll(intel_crtc));
  1635. /* FDI must be feeding us bits for PCH ports */
  1636. assert_fdi_tx_enabled(dev_priv, pipe);
  1637. assert_fdi_rx_enabled(dev_priv, pipe);
  1638. if (HAS_PCH_CPT(dev)) {
  1639. /* Workaround: Set the timing override bit before enabling the
  1640. * pch transcoder. */
  1641. reg = TRANS_CHICKEN2(pipe);
  1642. val = I915_READ(reg);
  1643. val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
  1644. I915_WRITE(reg, val);
  1645. }
  1646. reg = PCH_TRANSCONF(pipe);
  1647. val = I915_READ(reg);
  1648. pipeconf_val = I915_READ(PIPECONF(pipe));
  1649. if (HAS_PCH_IBX(dev_priv->dev)) {
  1650. /*
  1651. * make the BPC in transcoder be consistent with
  1652. * that in pipeconf reg.
  1653. */
  1654. val &= ~PIPECONF_BPC_MASK;
  1655. val |= pipeconf_val & PIPECONF_BPC_MASK;
  1656. }
  1657. val &= ~TRANS_INTERLACE_MASK;
  1658. if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK)
  1659. if (HAS_PCH_IBX(dev_priv->dev) &&
  1660. intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO))
  1661. val |= TRANS_LEGACY_INTERLACED_ILK;
  1662. else
  1663. val |= TRANS_INTERLACED;
  1664. else
  1665. val |= TRANS_PROGRESSIVE;
  1666. I915_WRITE(reg, val | TRANS_ENABLE);
  1667. if (wait_for(I915_READ(reg) & TRANS_STATE_ENABLE, 100))
  1668. DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe));
  1669. }
  1670. static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv,
  1671. enum transcoder cpu_transcoder)
  1672. {
  1673. u32 val, pipeconf_val;
  1674. /* PCH only available on ILK+ */
  1675. BUG_ON(INTEL_INFO(dev_priv->dev)->gen < 5);
  1676. /* FDI must be feeding us bits for PCH ports */
  1677. assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder);
  1678. assert_fdi_rx_enabled(dev_priv, TRANSCODER_A);
  1679. /* Workaround: set timing override bit. */
  1680. val = I915_READ(_TRANSA_CHICKEN2);
  1681. val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
  1682. I915_WRITE(_TRANSA_CHICKEN2, val);
  1683. val = TRANS_ENABLE;
  1684. pipeconf_val = I915_READ(PIPECONF(cpu_transcoder));
  1685. if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) ==
  1686. PIPECONF_INTERLACED_ILK)
  1687. val |= TRANS_INTERLACED;
  1688. else
  1689. val |= TRANS_PROGRESSIVE;
  1690. I915_WRITE(LPT_TRANSCONF, val);
  1691. if (wait_for(I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE, 100))
  1692. DRM_ERROR("Failed to enable PCH transcoder\n");
  1693. }
  1694. static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv,
  1695. enum pipe pipe)
  1696. {
  1697. struct drm_device *dev = dev_priv->dev;
  1698. uint32_t reg, val;
  1699. /* FDI relies on the transcoder */
  1700. assert_fdi_tx_disabled(dev_priv, pipe);
  1701. assert_fdi_rx_disabled(dev_priv, pipe);
  1702. /* Ports must be off as well */
  1703. assert_pch_ports_disabled(dev_priv, pipe);
  1704. reg = PCH_TRANSCONF(pipe);
  1705. val = I915_READ(reg);
  1706. val &= ~TRANS_ENABLE;
  1707. I915_WRITE(reg, val);
  1708. /* wait for PCH transcoder off, transcoder state */
  1709. if (wait_for((I915_READ(reg) & TRANS_STATE_ENABLE) == 0, 50))
  1710. DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe));
  1711. if (!HAS_PCH_IBX(dev)) {
  1712. /* Workaround: Clear the timing override chicken bit again. */
  1713. reg = TRANS_CHICKEN2(pipe);
  1714. val = I915_READ(reg);
  1715. val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
  1716. I915_WRITE(reg, val);
  1717. }
  1718. }
  1719. static void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv)
  1720. {
  1721. u32 val;
  1722. val = I915_READ(LPT_TRANSCONF);
  1723. val &= ~TRANS_ENABLE;
  1724. I915_WRITE(LPT_TRANSCONF, val);
  1725. /* wait for PCH transcoder off, transcoder state */
  1726. if (wait_for((I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE) == 0, 50))
  1727. DRM_ERROR("Failed to disable PCH transcoder\n");
  1728. /* Workaround: clear timing override bit. */
  1729. val = I915_READ(_TRANSA_CHICKEN2);
  1730. val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
  1731. I915_WRITE(_TRANSA_CHICKEN2, val);
  1732. }
  1733. /**
  1734. * intel_enable_pipe - enable a pipe, asserting requirements
  1735. * @crtc: crtc responsible for the pipe
  1736. *
  1737. * Enable @crtc's pipe, making sure that various hardware specific requirements
  1738. * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc.
  1739. */
  1740. static void intel_enable_pipe(struct intel_crtc *crtc)
  1741. {
  1742. struct drm_device *dev = crtc->base.dev;
  1743. struct drm_i915_private *dev_priv = dev->dev_private;
  1744. enum pipe pipe = crtc->pipe;
  1745. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  1746. pipe);
  1747. enum pipe pch_transcoder;
  1748. int reg;
  1749. u32 val;
  1750. assert_planes_disabled(dev_priv, pipe);
  1751. assert_cursor_disabled(dev_priv, pipe);
  1752. assert_sprites_disabled(dev_priv, pipe);
  1753. if (HAS_PCH_LPT(dev_priv->dev))
  1754. pch_transcoder = TRANSCODER_A;
  1755. else
  1756. pch_transcoder = pipe;
  1757. /*
  1758. * A pipe without a PLL won't actually be able to drive bits from
  1759. * a plane. On ILK+ the pipe PLLs are integrated, so we don't
  1760. * need the check.
  1761. */
  1762. if (!HAS_PCH_SPLIT(dev_priv->dev))
  1763. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DSI))
  1764. assert_dsi_pll_enabled(dev_priv);
  1765. else
  1766. assert_pll_enabled(dev_priv, pipe);
  1767. else {
  1768. if (crtc->config.has_pch_encoder) {
  1769. /* if driving the PCH, we need FDI enabled */
  1770. assert_fdi_rx_pll_enabled(dev_priv, pch_transcoder);
  1771. assert_fdi_tx_pll_enabled(dev_priv,
  1772. (enum pipe) cpu_transcoder);
  1773. }
  1774. /* FIXME: assert CPU port conditions for SNB+ */
  1775. }
  1776. reg = PIPECONF(cpu_transcoder);
  1777. val = I915_READ(reg);
  1778. if (val & PIPECONF_ENABLE) {
  1779. WARN_ON(!(pipe == PIPE_A &&
  1780. dev_priv->quirks & QUIRK_PIPEA_FORCE));
  1781. return;
  1782. }
  1783. I915_WRITE(reg, val | PIPECONF_ENABLE);
  1784. POSTING_READ(reg);
  1785. }
  1786. /**
  1787. * intel_disable_pipe - disable a pipe, asserting requirements
  1788. * @dev_priv: i915 private structure
  1789. * @pipe: pipe to disable
  1790. *
  1791. * Disable @pipe, making sure that various hardware specific requirements
  1792. * are met, if applicable, e.g. plane disabled, panel fitter off, etc.
  1793. *
  1794. * @pipe should be %PIPE_A or %PIPE_B.
  1795. *
  1796. * Will wait until the pipe has shut down before returning.
  1797. */
  1798. static void intel_disable_pipe(struct drm_i915_private *dev_priv,
  1799. enum pipe pipe)
  1800. {
  1801. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  1802. pipe);
  1803. int reg;
  1804. u32 val;
  1805. /*
  1806. * Make sure planes won't keep trying to pump pixels to us,
  1807. * or we might hang the display.
  1808. */
  1809. assert_planes_disabled(dev_priv, pipe);
  1810. assert_cursor_disabled(dev_priv, pipe);
  1811. assert_sprites_disabled(dev_priv, pipe);
  1812. /* Don't disable pipe A or pipe A PLLs if needed */
  1813. if (pipe == PIPE_A && (dev_priv->quirks & QUIRK_PIPEA_FORCE))
  1814. return;
  1815. reg = PIPECONF(cpu_transcoder);
  1816. val = I915_READ(reg);
  1817. if ((val & PIPECONF_ENABLE) == 0)
  1818. return;
  1819. I915_WRITE(reg, val & ~PIPECONF_ENABLE);
  1820. intel_wait_for_pipe_off(dev_priv->dev, pipe);
  1821. }
  1822. /*
  1823. * Plane regs are double buffered, going from enabled->disabled needs a
  1824. * trigger in order to latch. The display address reg provides this.
  1825. */
  1826. void intel_flush_primary_plane(struct drm_i915_private *dev_priv,
  1827. enum plane plane)
  1828. {
  1829. struct drm_device *dev = dev_priv->dev;
  1830. u32 reg = INTEL_INFO(dev)->gen >= 4 ? DSPSURF(plane) : DSPADDR(plane);
  1831. I915_WRITE(reg, I915_READ(reg));
  1832. POSTING_READ(reg);
  1833. }
  1834. /**
  1835. * intel_enable_primary_hw_plane - enable the primary plane on a given pipe
  1836. * @dev_priv: i915 private structure
  1837. * @plane: plane to enable
  1838. * @pipe: pipe being fed
  1839. *
  1840. * Enable @plane on @pipe, making sure that @pipe is running first.
  1841. */
  1842. static void intel_enable_primary_hw_plane(struct drm_i915_private *dev_priv,
  1843. enum plane plane, enum pipe pipe)
  1844. {
  1845. struct intel_crtc *intel_crtc =
  1846. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  1847. int reg;
  1848. u32 val;
  1849. /* If the pipe isn't enabled, we can't pump pixels and may hang */
  1850. assert_pipe_enabled(dev_priv, pipe);
  1851. if (intel_crtc->primary_enabled)
  1852. return;
  1853. intel_crtc->primary_enabled = true;
  1854. reg = DSPCNTR(plane);
  1855. val = I915_READ(reg);
  1856. WARN_ON(val & DISPLAY_PLANE_ENABLE);
  1857. I915_WRITE(reg, val | DISPLAY_PLANE_ENABLE);
  1858. intel_flush_primary_plane(dev_priv, plane);
  1859. }
  1860. /**
  1861. * intel_disable_primary_hw_plane - disable the primary hardware plane
  1862. * @dev_priv: i915 private structure
  1863. * @plane: plane to disable
  1864. * @pipe: pipe consuming the data
  1865. *
  1866. * Disable @plane; should be an independent operation.
  1867. */
  1868. static void intel_disable_primary_hw_plane(struct drm_i915_private *dev_priv,
  1869. enum plane plane, enum pipe pipe)
  1870. {
  1871. struct intel_crtc *intel_crtc =
  1872. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  1873. int reg;
  1874. u32 val;
  1875. if (!intel_crtc->primary_enabled)
  1876. return;
  1877. intel_crtc->primary_enabled = false;
  1878. reg = DSPCNTR(plane);
  1879. val = I915_READ(reg);
  1880. WARN_ON((val & DISPLAY_PLANE_ENABLE) == 0);
  1881. I915_WRITE(reg, val & ~DISPLAY_PLANE_ENABLE);
  1882. intel_flush_primary_plane(dev_priv, plane);
  1883. }
  1884. static bool need_vtd_wa(struct drm_device *dev)
  1885. {
  1886. #ifdef CONFIG_INTEL_IOMMU
  1887. if (INTEL_INFO(dev)->gen >= 6 && intel_iommu_gfx_mapped)
  1888. return true;
  1889. #endif
  1890. return false;
  1891. }
  1892. static int intel_align_height(struct drm_device *dev, int height, bool tiled)
  1893. {
  1894. int tile_height;
  1895. tile_height = tiled ? (IS_GEN2(dev) ? 16 : 8) : 1;
  1896. return ALIGN(height, tile_height);
  1897. }
  1898. int
  1899. intel_pin_and_fence_fb_obj(struct drm_device *dev,
  1900. struct drm_i915_gem_object *obj,
  1901. struct intel_engine_cs *pipelined)
  1902. {
  1903. struct drm_i915_private *dev_priv = dev->dev_private;
  1904. u32 alignment;
  1905. int ret;
  1906. switch (obj->tiling_mode) {
  1907. case I915_TILING_NONE:
  1908. if (IS_BROADWATER(dev) || IS_CRESTLINE(dev))
  1909. alignment = 128 * 1024;
  1910. else if (INTEL_INFO(dev)->gen >= 4)
  1911. alignment = 4 * 1024;
  1912. else
  1913. alignment = 64 * 1024;
  1914. break;
  1915. case I915_TILING_X:
  1916. /* pin() will align the object as required by fence */
  1917. alignment = 0;
  1918. break;
  1919. case I915_TILING_Y:
  1920. WARN(1, "Y tiled bo slipped through, driver bug!\n");
  1921. return -EINVAL;
  1922. default:
  1923. BUG();
  1924. }
  1925. /* Note that the w/a also requires 64 PTE of padding following the
  1926. * bo. We currently fill all unused PTE with the shadow page and so
  1927. * we should always have valid PTE following the scanout preventing
  1928. * the VT-d warning.
  1929. */
  1930. if (need_vtd_wa(dev) && alignment < 256 * 1024)
  1931. alignment = 256 * 1024;
  1932. dev_priv->mm.interruptible = false;
  1933. ret = i915_gem_object_pin_to_display_plane(obj, alignment, pipelined);
  1934. if (ret)
  1935. goto err_interruptible;
  1936. /* Install a fence for tiled scan-out. Pre-i965 always needs a
  1937. * fence, whereas 965+ only requires a fence if using
  1938. * framebuffer compression. For simplicity, we always install
  1939. * a fence as the cost is not that onerous.
  1940. */
  1941. ret = i915_gem_object_get_fence(obj);
  1942. if (ret)
  1943. goto err_unpin;
  1944. i915_gem_object_pin_fence(obj);
  1945. dev_priv->mm.interruptible = true;
  1946. return 0;
  1947. err_unpin:
  1948. i915_gem_object_unpin_from_display_plane(obj);
  1949. err_interruptible:
  1950. dev_priv->mm.interruptible = true;
  1951. return ret;
  1952. }
  1953. void intel_unpin_fb_obj(struct drm_i915_gem_object *obj)
  1954. {
  1955. i915_gem_object_unpin_fence(obj);
  1956. i915_gem_object_unpin_from_display_plane(obj);
  1957. }
  1958. /* Computes the linear offset to the base tile and adjusts x, y. bytes per pixel
  1959. * is assumed to be a power-of-two. */
  1960. unsigned long intel_gen4_compute_page_offset(int *x, int *y,
  1961. unsigned int tiling_mode,
  1962. unsigned int cpp,
  1963. unsigned int pitch)
  1964. {
  1965. if (tiling_mode != I915_TILING_NONE) {
  1966. unsigned int tile_rows, tiles;
  1967. tile_rows = *y / 8;
  1968. *y %= 8;
  1969. tiles = *x / (512/cpp);
  1970. *x %= 512/cpp;
  1971. return tile_rows * pitch * 8 + tiles * 4096;
  1972. } else {
  1973. unsigned int offset;
  1974. offset = *y * pitch + *x * cpp;
  1975. *y = 0;
  1976. *x = (offset & 4095) / cpp;
  1977. return offset & -4096;
  1978. }
  1979. }
  1980. int intel_format_to_fourcc(int format)
  1981. {
  1982. switch (format) {
  1983. case DISPPLANE_8BPP:
  1984. return DRM_FORMAT_C8;
  1985. case DISPPLANE_BGRX555:
  1986. return DRM_FORMAT_XRGB1555;
  1987. case DISPPLANE_BGRX565:
  1988. return DRM_FORMAT_RGB565;
  1989. default:
  1990. case DISPPLANE_BGRX888:
  1991. return DRM_FORMAT_XRGB8888;
  1992. case DISPPLANE_RGBX888:
  1993. return DRM_FORMAT_XBGR8888;
  1994. case DISPPLANE_BGRX101010:
  1995. return DRM_FORMAT_XRGB2101010;
  1996. case DISPPLANE_RGBX101010:
  1997. return DRM_FORMAT_XBGR2101010;
  1998. }
  1999. }
  2000. static bool intel_alloc_plane_obj(struct intel_crtc *crtc,
  2001. struct intel_plane_config *plane_config)
  2002. {
  2003. struct drm_device *dev = crtc->base.dev;
  2004. struct drm_i915_gem_object *obj = NULL;
  2005. struct drm_mode_fb_cmd2 mode_cmd = { 0 };
  2006. u32 base = plane_config->base;
  2007. if (plane_config->size == 0)
  2008. return false;
  2009. obj = i915_gem_object_create_stolen_for_preallocated(dev, base, base,
  2010. plane_config->size);
  2011. if (!obj)
  2012. return false;
  2013. if (plane_config->tiled) {
  2014. obj->tiling_mode = I915_TILING_X;
  2015. obj->stride = crtc->base.primary->fb->pitches[0];
  2016. }
  2017. mode_cmd.pixel_format = crtc->base.primary->fb->pixel_format;
  2018. mode_cmd.width = crtc->base.primary->fb->width;
  2019. mode_cmd.height = crtc->base.primary->fb->height;
  2020. mode_cmd.pitches[0] = crtc->base.primary->fb->pitches[0];
  2021. mutex_lock(&dev->struct_mutex);
  2022. if (intel_framebuffer_init(dev, to_intel_framebuffer(crtc->base.primary->fb),
  2023. &mode_cmd, obj)) {
  2024. DRM_DEBUG_KMS("intel fb init failed\n");
  2025. goto out_unref_obj;
  2026. }
  2027. obj->frontbuffer_bits = INTEL_FRONTBUFFER_PRIMARY(crtc->pipe);
  2028. mutex_unlock(&dev->struct_mutex);
  2029. DRM_DEBUG_KMS("plane fb obj %p\n", obj);
  2030. return true;
  2031. out_unref_obj:
  2032. drm_gem_object_unreference(&obj->base);
  2033. mutex_unlock(&dev->struct_mutex);
  2034. return false;
  2035. }
  2036. static void intel_find_plane_obj(struct intel_crtc *intel_crtc,
  2037. struct intel_plane_config *plane_config)
  2038. {
  2039. struct drm_device *dev = intel_crtc->base.dev;
  2040. struct drm_crtc *c;
  2041. struct intel_crtc *i;
  2042. struct intel_framebuffer *fb;
  2043. if (!intel_crtc->base.primary->fb)
  2044. return;
  2045. if (intel_alloc_plane_obj(intel_crtc, plane_config))
  2046. return;
  2047. kfree(intel_crtc->base.primary->fb);
  2048. intel_crtc->base.primary->fb = NULL;
  2049. /*
  2050. * Failed to alloc the obj, check to see if we should share
  2051. * an fb with another CRTC instead
  2052. */
  2053. for_each_crtc(dev, c) {
  2054. i = to_intel_crtc(c);
  2055. if (c == &intel_crtc->base)
  2056. continue;
  2057. if (!i->active || !c->primary->fb)
  2058. continue;
  2059. fb = to_intel_framebuffer(c->primary->fb);
  2060. if (i915_gem_obj_ggtt_offset(fb->obj) == plane_config->base) {
  2061. drm_framebuffer_reference(c->primary->fb);
  2062. intel_crtc->base.primary->fb = c->primary->fb;
  2063. fb->obj->frontbuffer_bits |= INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe);
  2064. break;
  2065. }
  2066. }
  2067. }
  2068. static void i9xx_update_primary_plane(struct drm_crtc *crtc,
  2069. struct drm_framebuffer *fb,
  2070. int x, int y)
  2071. {
  2072. struct drm_device *dev = crtc->dev;
  2073. struct drm_i915_private *dev_priv = dev->dev_private;
  2074. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2075. struct intel_framebuffer *intel_fb;
  2076. struct drm_i915_gem_object *obj;
  2077. int plane = intel_crtc->plane;
  2078. unsigned long linear_offset;
  2079. u32 dspcntr;
  2080. u32 reg;
  2081. intel_fb = to_intel_framebuffer(fb);
  2082. obj = intel_fb->obj;
  2083. reg = DSPCNTR(plane);
  2084. dspcntr = I915_READ(reg);
  2085. /* Mask out pixel format bits in case we change it */
  2086. dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;
  2087. switch (fb->pixel_format) {
  2088. case DRM_FORMAT_C8:
  2089. dspcntr |= DISPPLANE_8BPP;
  2090. break;
  2091. case DRM_FORMAT_XRGB1555:
  2092. case DRM_FORMAT_ARGB1555:
  2093. dspcntr |= DISPPLANE_BGRX555;
  2094. break;
  2095. case DRM_FORMAT_RGB565:
  2096. dspcntr |= DISPPLANE_BGRX565;
  2097. break;
  2098. case DRM_FORMAT_XRGB8888:
  2099. case DRM_FORMAT_ARGB8888:
  2100. dspcntr |= DISPPLANE_BGRX888;
  2101. break;
  2102. case DRM_FORMAT_XBGR8888:
  2103. case DRM_FORMAT_ABGR8888:
  2104. dspcntr |= DISPPLANE_RGBX888;
  2105. break;
  2106. case DRM_FORMAT_XRGB2101010:
  2107. case DRM_FORMAT_ARGB2101010:
  2108. dspcntr |= DISPPLANE_BGRX101010;
  2109. break;
  2110. case DRM_FORMAT_XBGR2101010:
  2111. case DRM_FORMAT_ABGR2101010:
  2112. dspcntr |= DISPPLANE_RGBX101010;
  2113. break;
  2114. default:
  2115. BUG();
  2116. }
  2117. if (INTEL_INFO(dev)->gen >= 4) {
  2118. if (obj->tiling_mode != I915_TILING_NONE)
  2119. dspcntr |= DISPPLANE_TILED;
  2120. else
  2121. dspcntr &= ~DISPPLANE_TILED;
  2122. }
  2123. if (IS_G4X(dev))
  2124. dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
  2125. I915_WRITE(reg, dspcntr);
  2126. linear_offset = y * fb->pitches[0] + x * (fb->bits_per_pixel / 8);
  2127. if (INTEL_INFO(dev)->gen >= 4) {
  2128. intel_crtc->dspaddr_offset =
  2129. intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
  2130. fb->bits_per_pixel / 8,
  2131. fb->pitches[0]);
  2132. linear_offset -= intel_crtc->dspaddr_offset;
  2133. } else {
  2134. intel_crtc->dspaddr_offset = linear_offset;
  2135. }
  2136. DRM_DEBUG_KMS("Writing base %08lX %08lX %d %d %d\n",
  2137. i915_gem_obj_ggtt_offset(obj), linear_offset, x, y,
  2138. fb->pitches[0]);
  2139. I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]);
  2140. if (INTEL_INFO(dev)->gen >= 4) {
  2141. I915_WRITE(DSPSURF(plane),
  2142. i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset);
  2143. I915_WRITE(DSPTILEOFF(plane), (y << 16) | x);
  2144. I915_WRITE(DSPLINOFF(plane), linear_offset);
  2145. } else
  2146. I915_WRITE(DSPADDR(plane), i915_gem_obj_ggtt_offset(obj) + linear_offset);
  2147. POSTING_READ(reg);
  2148. }
  2149. static void ironlake_update_primary_plane(struct drm_crtc *crtc,
  2150. struct drm_framebuffer *fb,
  2151. int x, int y)
  2152. {
  2153. struct drm_device *dev = crtc->dev;
  2154. struct drm_i915_private *dev_priv = dev->dev_private;
  2155. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2156. struct intel_framebuffer *intel_fb;
  2157. struct drm_i915_gem_object *obj;
  2158. int plane = intel_crtc->plane;
  2159. unsigned long linear_offset;
  2160. u32 dspcntr;
  2161. u32 reg;
  2162. intel_fb = to_intel_framebuffer(fb);
  2163. obj = intel_fb->obj;
  2164. reg = DSPCNTR(plane);
  2165. dspcntr = I915_READ(reg);
  2166. /* Mask out pixel format bits in case we change it */
  2167. dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;
  2168. switch (fb->pixel_format) {
  2169. case DRM_FORMAT_C8:
  2170. dspcntr |= DISPPLANE_8BPP;
  2171. break;
  2172. case DRM_FORMAT_RGB565:
  2173. dspcntr |= DISPPLANE_BGRX565;
  2174. break;
  2175. case DRM_FORMAT_XRGB8888:
  2176. case DRM_FORMAT_ARGB8888:
  2177. dspcntr |= DISPPLANE_BGRX888;
  2178. break;
  2179. case DRM_FORMAT_XBGR8888:
  2180. case DRM_FORMAT_ABGR8888:
  2181. dspcntr |= DISPPLANE_RGBX888;
  2182. break;
  2183. case DRM_FORMAT_XRGB2101010:
  2184. case DRM_FORMAT_ARGB2101010:
  2185. dspcntr |= DISPPLANE_BGRX101010;
  2186. break;
  2187. case DRM_FORMAT_XBGR2101010:
  2188. case DRM_FORMAT_ABGR2101010:
  2189. dspcntr |= DISPPLANE_RGBX101010;
  2190. break;
  2191. default:
  2192. BUG();
  2193. }
  2194. if (obj->tiling_mode != I915_TILING_NONE)
  2195. dspcntr |= DISPPLANE_TILED;
  2196. else
  2197. dspcntr &= ~DISPPLANE_TILED;
  2198. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  2199. dspcntr &= ~DISPPLANE_TRICKLE_FEED_DISABLE;
  2200. else
  2201. dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
  2202. I915_WRITE(reg, dspcntr);
  2203. linear_offset = y * fb->pitches[0] + x * (fb->bits_per_pixel / 8);
  2204. intel_crtc->dspaddr_offset =
  2205. intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
  2206. fb->bits_per_pixel / 8,
  2207. fb->pitches[0]);
  2208. linear_offset -= intel_crtc->dspaddr_offset;
  2209. DRM_DEBUG_KMS("Writing base %08lX %08lX %d %d %d\n",
  2210. i915_gem_obj_ggtt_offset(obj), linear_offset, x, y,
  2211. fb->pitches[0]);
  2212. I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]);
  2213. I915_WRITE(DSPSURF(plane),
  2214. i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset);
  2215. if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
  2216. I915_WRITE(DSPOFFSET(plane), (y << 16) | x);
  2217. } else {
  2218. I915_WRITE(DSPTILEOFF(plane), (y << 16) | x);
  2219. I915_WRITE(DSPLINOFF(plane), linear_offset);
  2220. }
  2221. POSTING_READ(reg);
  2222. }
  2223. /* Assume fb object is pinned & idle & fenced and just update base pointers */
  2224. static int
  2225. intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb,
  2226. int x, int y, enum mode_set_atomic state)
  2227. {
  2228. struct drm_device *dev = crtc->dev;
  2229. struct drm_i915_private *dev_priv = dev->dev_private;
  2230. if (dev_priv->display.disable_fbc)
  2231. dev_priv->display.disable_fbc(dev);
  2232. intel_increase_pllclock(dev, to_intel_crtc(crtc)->pipe);
  2233. dev_priv->display.update_primary_plane(crtc, fb, x, y);
  2234. return 0;
  2235. }
  2236. void intel_display_handle_reset(struct drm_device *dev)
  2237. {
  2238. struct drm_i915_private *dev_priv = dev->dev_private;
  2239. struct drm_crtc *crtc;
  2240. /*
  2241. * Flips in the rings have been nuked by the reset,
  2242. * so complete all pending flips so that user space
  2243. * will get its events and not get stuck.
  2244. *
  2245. * Also update the base address of all primary
  2246. * planes to the the last fb to make sure we're
  2247. * showing the correct fb after a reset.
  2248. *
  2249. * Need to make two loops over the crtcs so that we
  2250. * don't try to grab a crtc mutex before the
  2251. * pending_flip_queue really got woken up.
  2252. */
  2253. for_each_crtc(dev, crtc) {
  2254. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2255. enum plane plane = intel_crtc->plane;
  2256. intel_prepare_page_flip(dev, plane);
  2257. intel_finish_page_flip_plane(dev, plane);
  2258. }
  2259. for_each_crtc(dev, crtc) {
  2260. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2261. drm_modeset_lock(&crtc->mutex, NULL);
  2262. /*
  2263. * FIXME: Once we have proper support for primary planes (and
  2264. * disabling them without disabling the entire crtc) allow again
  2265. * a NULL crtc->primary->fb.
  2266. */
  2267. if (intel_crtc->active && crtc->primary->fb)
  2268. dev_priv->display.update_primary_plane(crtc,
  2269. crtc->primary->fb,
  2270. crtc->x,
  2271. crtc->y);
  2272. drm_modeset_unlock(&crtc->mutex);
  2273. }
  2274. }
  2275. static int
  2276. intel_finish_fb(struct drm_framebuffer *old_fb)
  2277. {
  2278. struct drm_i915_gem_object *obj = to_intel_framebuffer(old_fb)->obj;
  2279. struct drm_i915_private *dev_priv = obj->base.dev->dev_private;
  2280. bool was_interruptible = dev_priv->mm.interruptible;
  2281. int ret;
  2282. /* Big Hammer, we also need to ensure that any pending
  2283. * MI_WAIT_FOR_EVENT inside a user batch buffer on the
  2284. * current scanout is retired before unpinning the old
  2285. * framebuffer.
  2286. *
  2287. * This should only fail upon a hung GPU, in which case we
  2288. * can safely continue.
  2289. */
  2290. dev_priv->mm.interruptible = false;
  2291. ret = i915_gem_object_finish_gpu(obj);
  2292. dev_priv->mm.interruptible = was_interruptible;
  2293. return ret;
  2294. }
  2295. static bool intel_crtc_has_pending_flip(struct drm_crtc *crtc)
  2296. {
  2297. struct drm_device *dev = crtc->dev;
  2298. struct drm_i915_private *dev_priv = dev->dev_private;
  2299. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2300. unsigned long flags;
  2301. bool pending;
  2302. if (i915_reset_in_progress(&dev_priv->gpu_error) ||
  2303. intel_crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter))
  2304. return false;
  2305. spin_lock_irqsave(&dev->event_lock, flags);
  2306. pending = to_intel_crtc(crtc)->unpin_work != NULL;
  2307. spin_unlock_irqrestore(&dev->event_lock, flags);
  2308. return pending;
  2309. }
  2310. static int
  2311. intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
  2312. struct drm_framebuffer *fb)
  2313. {
  2314. struct drm_device *dev = crtc->dev;
  2315. struct drm_i915_private *dev_priv = dev->dev_private;
  2316. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2317. enum pipe pipe = intel_crtc->pipe;
  2318. struct drm_framebuffer *old_fb;
  2319. struct drm_i915_gem_object *obj = to_intel_framebuffer(fb)->obj;
  2320. struct drm_i915_gem_object *old_obj;
  2321. int ret;
  2322. if (intel_crtc_has_pending_flip(crtc)) {
  2323. DRM_ERROR("pipe is still busy with an old pageflip\n");
  2324. return -EBUSY;
  2325. }
  2326. /* no fb bound */
  2327. if (!fb) {
  2328. DRM_ERROR("No FB bound\n");
  2329. return 0;
  2330. }
  2331. if (intel_crtc->plane > INTEL_INFO(dev)->num_pipes) {
  2332. DRM_ERROR("no plane for crtc: plane %c, num_pipes %d\n",
  2333. plane_name(intel_crtc->plane),
  2334. INTEL_INFO(dev)->num_pipes);
  2335. return -EINVAL;
  2336. }
  2337. old_fb = crtc->primary->fb;
  2338. old_obj = old_fb ? to_intel_framebuffer(old_fb)->obj : NULL;
  2339. mutex_lock(&dev->struct_mutex);
  2340. ret = intel_pin_and_fence_fb_obj(dev, obj, NULL);
  2341. if (ret == 0)
  2342. i915_gem_track_fb(old_obj, obj,
  2343. INTEL_FRONTBUFFER_PRIMARY(pipe));
  2344. mutex_unlock(&dev->struct_mutex);
  2345. if (ret != 0) {
  2346. DRM_ERROR("pin & fence failed\n");
  2347. return ret;
  2348. }
  2349. /*
  2350. * Update pipe size and adjust fitter if needed: the reason for this is
  2351. * that in compute_mode_changes we check the native mode (not the pfit
  2352. * mode) to see if we can flip rather than do a full mode set. In the
  2353. * fastboot case, we'll flip, but if we don't update the pipesrc and
  2354. * pfit state, we'll end up with a big fb scanned out into the wrong
  2355. * sized surface.
  2356. *
  2357. * To fix this properly, we need to hoist the checks up into
  2358. * compute_mode_changes (or above), check the actual pfit state and
  2359. * whether the platform allows pfit disable with pipe active, and only
  2360. * then update the pipesrc and pfit state, even on the flip path.
  2361. */
  2362. if (i915.fastboot) {
  2363. const struct drm_display_mode *adjusted_mode =
  2364. &intel_crtc->config.adjusted_mode;
  2365. I915_WRITE(PIPESRC(intel_crtc->pipe),
  2366. ((adjusted_mode->crtc_hdisplay - 1) << 16) |
  2367. (adjusted_mode->crtc_vdisplay - 1));
  2368. if (!intel_crtc->config.pch_pfit.enabled &&
  2369. (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) ||
  2370. intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) {
  2371. I915_WRITE(PF_CTL(intel_crtc->pipe), 0);
  2372. I915_WRITE(PF_WIN_POS(intel_crtc->pipe), 0);
  2373. I915_WRITE(PF_WIN_SZ(intel_crtc->pipe), 0);
  2374. }
  2375. intel_crtc->config.pipe_src_w = adjusted_mode->crtc_hdisplay;
  2376. intel_crtc->config.pipe_src_h = adjusted_mode->crtc_vdisplay;
  2377. }
  2378. dev_priv->display.update_primary_plane(crtc, fb, x, y);
  2379. if (intel_crtc->active)
  2380. intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_PRIMARY(pipe));
  2381. crtc->primary->fb = fb;
  2382. crtc->x = x;
  2383. crtc->y = y;
  2384. if (old_fb) {
  2385. if (intel_crtc->active && old_fb != fb)
  2386. intel_wait_for_vblank(dev, intel_crtc->pipe);
  2387. mutex_lock(&dev->struct_mutex);
  2388. intel_unpin_fb_obj(to_intel_framebuffer(old_fb)->obj);
  2389. mutex_unlock(&dev->struct_mutex);
  2390. }
  2391. mutex_lock(&dev->struct_mutex);
  2392. intel_update_fbc(dev);
  2393. mutex_unlock(&dev->struct_mutex);
  2394. return 0;
  2395. }
  2396. static void intel_fdi_normal_train(struct drm_crtc *crtc)
  2397. {
  2398. struct drm_device *dev = crtc->dev;
  2399. struct drm_i915_private *dev_priv = dev->dev_private;
  2400. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2401. int pipe = intel_crtc->pipe;
  2402. u32 reg, temp;
  2403. /* enable normal train */
  2404. reg = FDI_TX_CTL(pipe);
  2405. temp = I915_READ(reg);
  2406. if (IS_IVYBRIDGE(dev)) {
  2407. temp &= ~FDI_LINK_TRAIN_NONE_IVB;
  2408. temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE;
  2409. } else {
  2410. temp &= ~FDI_LINK_TRAIN_NONE;
  2411. temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
  2412. }
  2413. I915_WRITE(reg, temp);
  2414. reg = FDI_RX_CTL(pipe);
  2415. temp = I915_READ(reg);
  2416. if (HAS_PCH_CPT(dev)) {
  2417. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2418. temp |= FDI_LINK_TRAIN_NORMAL_CPT;
  2419. } else {
  2420. temp &= ~FDI_LINK_TRAIN_NONE;
  2421. temp |= FDI_LINK_TRAIN_NONE;
  2422. }
  2423. I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
  2424. /* wait one idle pattern time */
  2425. POSTING_READ(reg);
  2426. udelay(1000);
  2427. /* IVB wants error correction enabled */
  2428. if (IS_IVYBRIDGE(dev))
  2429. I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE |
  2430. FDI_FE_ERRC_ENABLE);
  2431. }
  2432. static bool pipe_has_enabled_pch(struct intel_crtc *crtc)
  2433. {
  2434. return crtc->base.enabled && crtc->active &&
  2435. crtc->config.has_pch_encoder;
  2436. }
  2437. static void ivb_modeset_global_resources(struct drm_device *dev)
  2438. {
  2439. struct drm_i915_private *dev_priv = dev->dev_private;
  2440. struct intel_crtc *pipe_B_crtc =
  2441. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_B]);
  2442. struct intel_crtc *pipe_C_crtc =
  2443. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_C]);
  2444. uint32_t temp;
  2445. /*
  2446. * When everything is off disable fdi C so that we could enable fdi B
  2447. * with all lanes. Note that we don't care about enabled pipes without
  2448. * an enabled pch encoder.
  2449. */
  2450. if (!pipe_has_enabled_pch(pipe_B_crtc) &&
  2451. !pipe_has_enabled_pch(pipe_C_crtc)) {
  2452. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
  2453. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
  2454. temp = I915_READ(SOUTH_CHICKEN1);
  2455. temp &= ~FDI_BC_BIFURCATION_SELECT;
  2456. DRM_DEBUG_KMS("disabling fdi C rx\n");
  2457. I915_WRITE(SOUTH_CHICKEN1, temp);
  2458. }
  2459. }
  2460. /* The FDI link training functions for ILK/Ibexpeak. */
  2461. static void ironlake_fdi_link_train(struct drm_crtc *crtc)
  2462. {
  2463. struct drm_device *dev = crtc->dev;
  2464. struct drm_i915_private *dev_priv = dev->dev_private;
  2465. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2466. int pipe = intel_crtc->pipe;
  2467. u32 reg, temp, tries;
  2468. /* FDI needs bits from pipe first */
  2469. assert_pipe_enabled(dev_priv, pipe);
  2470. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  2471. for train result */
  2472. reg = FDI_RX_IMR(pipe);
  2473. temp = I915_READ(reg);
  2474. temp &= ~FDI_RX_SYMBOL_LOCK;
  2475. temp &= ~FDI_RX_BIT_LOCK;
  2476. I915_WRITE(reg, temp);
  2477. I915_READ(reg);
  2478. udelay(150);
  2479. /* enable CPU FDI TX and PCH FDI RX */
  2480. reg = FDI_TX_CTL(pipe);
  2481. temp = I915_READ(reg);
  2482. temp &= ~FDI_DP_PORT_WIDTH_MASK;
  2483. temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes);
  2484. temp &= ~FDI_LINK_TRAIN_NONE;
  2485. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2486. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  2487. reg = FDI_RX_CTL(pipe);
  2488. temp = I915_READ(reg);
  2489. temp &= ~FDI_LINK_TRAIN_NONE;
  2490. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2491. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  2492. POSTING_READ(reg);
  2493. udelay(150);
  2494. /* Ironlake workaround, enable clock pointer after FDI enable*/
  2495. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
  2496. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR |
  2497. FDI_RX_PHASE_SYNC_POINTER_EN);
  2498. reg = FDI_RX_IIR(pipe);
  2499. for (tries = 0; tries < 5; tries++) {
  2500. temp = I915_READ(reg);
  2501. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2502. if ((temp & FDI_RX_BIT_LOCK)) {
  2503. DRM_DEBUG_KMS("FDI train 1 done.\n");
  2504. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  2505. break;
  2506. }
  2507. }
  2508. if (tries == 5)
  2509. DRM_ERROR("FDI train 1 fail!\n");
  2510. /* Train 2 */
  2511. reg = FDI_TX_CTL(pipe);
  2512. temp = I915_READ(reg);
  2513. temp &= ~FDI_LINK_TRAIN_NONE;
  2514. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2515. I915_WRITE(reg, temp);
  2516. reg = FDI_RX_CTL(pipe);
  2517. temp = I915_READ(reg);
  2518. temp &= ~FDI_LINK_TRAIN_NONE;
  2519. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2520. I915_WRITE(reg, temp);
  2521. POSTING_READ(reg);
  2522. udelay(150);
  2523. reg = FDI_RX_IIR(pipe);
  2524. for (tries = 0; tries < 5; tries++) {
  2525. temp = I915_READ(reg);
  2526. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2527. if (temp & FDI_RX_SYMBOL_LOCK) {
  2528. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  2529. DRM_DEBUG_KMS("FDI train 2 done.\n");
  2530. break;
  2531. }
  2532. }
  2533. if (tries == 5)
  2534. DRM_ERROR("FDI train 2 fail!\n");
  2535. DRM_DEBUG_KMS("FDI train done\n");
  2536. }
  2537. static const int snb_b_fdi_train_param[] = {
  2538. FDI_LINK_TRAIN_400MV_0DB_SNB_B,
  2539. FDI_LINK_TRAIN_400MV_6DB_SNB_B,
  2540. FDI_LINK_TRAIN_600MV_3_5DB_SNB_B,
  2541. FDI_LINK_TRAIN_800MV_0DB_SNB_B,
  2542. };
  2543. /* The FDI link training functions for SNB/Cougarpoint. */
  2544. static void gen6_fdi_link_train(struct drm_crtc *crtc)
  2545. {
  2546. struct drm_device *dev = crtc->dev;
  2547. struct drm_i915_private *dev_priv = dev->dev_private;
  2548. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2549. int pipe = intel_crtc->pipe;
  2550. u32 reg, temp, i, retry;
  2551. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  2552. for train result */
  2553. reg = FDI_RX_IMR(pipe);
  2554. temp = I915_READ(reg);
  2555. temp &= ~FDI_RX_SYMBOL_LOCK;
  2556. temp &= ~FDI_RX_BIT_LOCK;
  2557. I915_WRITE(reg, temp);
  2558. POSTING_READ(reg);
  2559. udelay(150);
  2560. /* enable CPU FDI TX and PCH FDI RX */
  2561. reg = FDI_TX_CTL(pipe);
  2562. temp = I915_READ(reg);
  2563. temp &= ~FDI_DP_PORT_WIDTH_MASK;
  2564. temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes);
  2565. temp &= ~FDI_LINK_TRAIN_NONE;
  2566. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2567. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2568. /* SNB-B */
  2569. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  2570. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  2571. I915_WRITE(FDI_RX_MISC(pipe),
  2572. FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
  2573. reg = FDI_RX_CTL(pipe);
  2574. temp = I915_READ(reg);
  2575. if (HAS_PCH_CPT(dev)) {
  2576. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2577. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2578. } else {
  2579. temp &= ~FDI_LINK_TRAIN_NONE;
  2580. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2581. }
  2582. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  2583. POSTING_READ(reg);
  2584. udelay(150);
  2585. for (i = 0; i < 4; i++) {
  2586. reg = FDI_TX_CTL(pipe);
  2587. temp = I915_READ(reg);
  2588. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2589. temp |= snb_b_fdi_train_param[i];
  2590. I915_WRITE(reg, temp);
  2591. POSTING_READ(reg);
  2592. udelay(500);
  2593. for (retry = 0; retry < 5; retry++) {
  2594. reg = FDI_RX_IIR(pipe);
  2595. temp = I915_READ(reg);
  2596. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2597. if (temp & FDI_RX_BIT_LOCK) {
  2598. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  2599. DRM_DEBUG_KMS("FDI train 1 done.\n");
  2600. break;
  2601. }
  2602. udelay(50);
  2603. }
  2604. if (retry < 5)
  2605. break;
  2606. }
  2607. if (i == 4)
  2608. DRM_ERROR("FDI train 1 fail!\n");
  2609. /* Train 2 */
  2610. reg = FDI_TX_CTL(pipe);
  2611. temp = I915_READ(reg);
  2612. temp &= ~FDI_LINK_TRAIN_NONE;
  2613. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2614. if (IS_GEN6(dev)) {
  2615. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2616. /* SNB-B */
  2617. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  2618. }
  2619. I915_WRITE(reg, temp);
  2620. reg = FDI_RX_CTL(pipe);
  2621. temp = I915_READ(reg);
  2622. if (HAS_PCH_CPT(dev)) {
  2623. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2624. temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
  2625. } else {
  2626. temp &= ~FDI_LINK_TRAIN_NONE;
  2627. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2628. }
  2629. I915_WRITE(reg, temp);
  2630. POSTING_READ(reg);
  2631. udelay(150);
  2632. for (i = 0; i < 4; i++) {
  2633. reg = FDI_TX_CTL(pipe);
  2634. temp = I915_READ(reg);
  2635. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2636. temp |= snb_b_fdi_train_param[i];
  2637. I915_WRITE(reg, temp);
  2638. POSTING_READ(reg);
  2639. udelay(500);
  2640. for (retry = 0; retry < 5; retry++) {
  2641. reg = FDI_RX_IIR(pipe);
  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. udelay(50);
  2650. }
  2651. if (retry < 5)
  2652. break;
  2653. }
  2654. if (i == 4)
  2655. DRM_ERROR("FDI train 2 fail!\n");
  2656. DRM_DEBUG_KMS("FDI train done.\n");
  2657. }
  2658. /* Manual link training for Ivy Bridge A0 parts */
  2659. static void ivb_manual_fdi_link_train(struct drm_crtc *crtc)
  2660. {
  2661. struct drm_device *dev = crtc->dev;
  2662. struct drm_i915_private *dev_priv = dev->dev_private;
  2663. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2664. int pipe = intel_crtc->pipe;
  2665. u32 reg, temp, i, j;
  2666. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  2667. for train result */
  2668. reg = FDI_RX_IMR(pipe);
  2669. temp = I915_READ(reg);
  2670. temp &= ~FDI_RX_SYMBOL_LOCK;
  2671. temp &= ~FDI_RX_BIT_LOCK;
  2672. I915_WRITE(reg, temp);
  2673. POSTING_READ(reg);
  2674. udelay(150);
  2675. DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
  2676. I915_READ(FDI_RX_IIR(pipe)));
  2677. /* Try each vswing and preemphasis setting twice before moving on */
  2678. for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) {
  2679. /* disable first in case we need to retry */
  2680. reg = FDI_TX_CTL(pipe);
  2681. temp = I915_READ(reg);
  2682. temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB);
  2683. temp &= ~FDI_TX_ENABLE;
  2684. I915_WRITE(reg, temp);
  2685. reg = FDI_RX_CTL(pipe);
  2686. temp = I915_READ(reg);
  2687. temp &= ~FDI_LINK_TRAIN_AUTO;
  2688. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2689. temp &= ~FDI_RX_ENABLE;
  2690. I915_WRITE(reg, temp);
  2691. /* enable CPU FDI TX and PCH FDI RX */
  2692. reg = FDI_TX_CTL(pipe);
  2693. temp = I915_READ(reg);
  2694. temp &= ~FDI_DP_PORT_WIDTH_MASK;
  2695. temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes);
  2696. temp |= FDI_LINK_TRAIN_PATTERN_1_IVB;
  2697. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2698. temp |= snb_b_fdi_train_param[j/2];
  2699. temp |= FDI_COMPOSITE_SYNC;
  2700. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  2701. I915_WRITE(FDI_RX_MISC(pipe),
  2702. FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
  2703. reg = FDI_RX_CTL(pipe);
  2704. temp = I915_READ(reg);
  2705. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2706. temp |= FDI_COMPOSITE_SYNC;
  2707. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  2708. POSTING_READ(reg);
  2709. udelay(1); /* should be 0.5us */
  2710. for (i = 0; i < 4; i++) {
  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_READ(reg) & FDI_RX_BIT_LOCK)) {
  2716. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  2717. DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
  2718. i);
  2719. break;
  2720. }
  2721. udelay(1); /* should be 0.5us */
  2722. }
  2723. if (i == 4) {
  2724. DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2);
  2725. continue;
  2726. }
  2727. /* Train 2 */
  2728. reg = FDI_TX_CTL(pipe);
  2729. temp = I915_READ(reg);
  2730. temp &= ~FDI_LINK_TRAIN_NONE_IVB;
  2731. temp |= FDI_LINK_TRAIN_PATTERN_2_IVB;
  2732. I915_WRITE(reg, temp);
  2733. reg = FDI_RX_CTL(pipe);
  2734. temp = I915_READ(reg);
  2735. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2736. temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
  2737. I915_WRITE(reg, temp);
  2738. POSTING_READ(reg);
  2739. udelay(2); /* should be 1.5us */
  2740. for (i = 0; i < 4; i++) {
  2741. reg = FDI_RX_IIR(pipe);
  2742. temp = I915_READ(reg);
  2743. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2744. if (temp & FDI_RX_SYMBOL_LOCK ||
  2745. (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) {
  2746. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  2747. DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
  2748. i);
  2749. goto train_done;
  2750. }
  2751. udelay(2); /* should be 1.5us */
  2752. }
  2753. if (i == 4)
  2754. DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j / 2);
  2755. }
  2756. train_done:
  2757. DRM_DEBUG_KMS("FDI train done.\n");
  2758. }
  2759. static void ironlake_fdi_pll_enable(struct intel_crtc *intel_crtc)
  2760. {
  2761. struct drm_device *dev = intel_crtc->base.dev;
  2762. struct drm_i915_private *dev_priv = dev->dev_private;
  2763. int pipe = intel_crtc->pipe;
  2764. u32 reg, temp;
  2765. /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
  2766. reg = FDI_RX_CTL(pipe);
  2767. temp = I915_READ(reg);
  2768. temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16));
  2769. temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes);
  2770. temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
  2771. I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE);
  2772. POSTING_READ(reg);
  2773. udelay(200);
  2774. /* Switch from Rawclk to PCDclk */
  2775. temp = I915_READ(reg);
  2776. I915_WRITE(reg, temp | FDI_PCDCLK);
  2777. POSTING_READ(reg);
  2778. udelay(200);
  2779. /* Enable CPU FDI TX PLL, always on for Ironlake */
  2780. reg = FDI_TX_CTL(pipe);
  2781. temp = I915_READ(reg);
  2782. if ((temp & FDI_TX_PLL_ENABLE) == 0) {
  2783. I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE);
  2784. POSTING_READ(reg);
  2785. udelay(100);
  2786. }
  2787. }
  2788. static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc)
  2789. {
  2790. struct drm_device *dev = intel_crtc->base.dev;
  2791. struct drm_i915_private *dev_priv = dev->dev_private;
  2792. int pipe = intel_crtc->pipe;
  2793. u32 reg, temp;
  2794. /* Switch from PCDclk to Rawclk */
  2795. reg = FDI_RX_CTL(pipe);
  2796. temp = I915_READ(reg);
  2797. I915_WRITE(reg, temp & ~FDI_PCDCLK);
  2798. /* Disable CPU FDI TX PLL */
  2799. reg = FDI_TX_CTL(pipe);
  2800. temp = I915_READ(reg);
  2801. I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE);
  2802. POSTING_READ(reg);
  2803. udelay(100);
  2804. reg = FDI_RX_CTL(pipe);
  2805. temp = I915_READ(reg);
  2806. I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE);
  2807. /* Wait for the clocks to turn off. */
  2808. POSTING_READ(reg);
  2809. udelay(100);
  2810. }
  2811. static void ironlake_fdi_disable(struct drm_crtc *crtc)
  2812. {
  2813. struct drm_device *dev = crtc->dev;
  2814. struct drm_i915_private *dev_priv = dev->dev_private;
  2815. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2816. int pipe = intel_crtc->pipe;
  2817. u32 reg, temp;
  2818. /* disable CPU FDI tx and PCH FDI rx */
  2819. reg = FDI_TX_CTL(pipe);
  2820. temp = I915_READ(reg);
  2821. I915_WRITE(reg, temp & ~FDI_TX_ENABLE);
  2822. POSTING_READ(reg);
  2823. reg = FDI_RX_CTL(pipe);
  2824. temp = I915_READ(reg);
  2825. temp &= ~(0x7 << 16);
  2826. temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
  2827. I915_WRITE(reg, temp & ~FDI_RX_ENABLE);
  2828. POSTING_READ(reg);
  2829. udelay(100);
  2830. /* Ironlake workaround, disable clock pointer after downing FDI */
  2831. if (HAS_PCH_IBX(dev))
  2832. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
  2833. /* still set train pattern 1 */
  2834. reg = FDI_TX_CTL(pipe);
  2835. temp = I915_READ(reg);
  2836. temp &= ~FDI_LINK_TRAIN_NONE;
  2837. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2838. I915_WRITE(reg, temp);
  2839. reg = FDI_RX_CTL(pipe);
  2840. temp = I915_READ(reg);
  2841. if (HAS_PCH_CPT(dev)) {
  2842. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2843. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2844. } else {
  2845. temp &= ~FDI_LINK_TRAIN_NONE;
  2846. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2847. }
  2848. /* BPC in FDI rx is consistent with that in PIPECONF */
  2849. temp &= ~(0x07 << 16);
  2850. temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
  2851. I915_WRITE(reg, temp);
  2852. POSTING_READ(reg);
  2853. udelay(100);
  2854. }
  2855. bool intel_has_pending_fb_unpin(struct drm_device *dev)
  2856. {
  2857. struct intel_crtc *crtc;
  2858. /* Note that we don't need to be called with mode_config.lock here
  2859. * as our list of CRTC objects is static for the lifetime of the
  2860. * device and so cannot disappear as we iterate. Similarly, we can
  2861. * happily treat the predicates as racy, atomic checks as userspace
  2862. * cannot claim and pin a new fb without at least acquring the
  2863. * struct_mutex and so serialising with us.
  2864. */
  2865. for_each_intel_crtc(dev, crtc) {
  2866. if (atomic_read(&crtc->unpin_work_count) == 0)
  2867. continue;
  2868. if (crtc->unpin_work)
  2869. intel_wait_for_vblank(dev, crtc->pipe);
  2870. return true;
  2871. }
  2872. return false;
  2873. }
  2874. void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
  2875. {
  2876. struct drm_device *dev = crtc->dev;
  2877. struct drm_i915_private *dev_priv = dev->dev_private;
  2878. if (crtc->primary->fb == NULL)
  2879. return;
  2880. WARN_ON(waitqueue_active(&dev_priv->pending_flip_queue));
  2881. WARN_ON(wait_event_timeout(dev_priv->pending_flip_queue,
  2882. !intel_crtc_has_pending_flip(crtc),
  2883. 60*HZ) == 0);
  2884. mutex_lock(&dev->struct_mutex);
  2885. intel_finish_fb(crtc->primary->fb);
  2886. mutex_unlock(&dev->struct_mutex);
  2887. }
  2888. /* Program iCLKIP clock to the desired frequency */
  2889. static void lpt_program_iclkip(struct drm_crtc *crtc)
  2890. {
  2891. struct drm_device *dev = crtc->dev;
  2892. struct drm_i915_private *dev_priv = dev->dev_private;
  2893. int clock = to_intel_crtc(crtc)->config.adjusted_mode.crtc_clock;
  2894. u32 divsel, phaseinc, auxdiv, phasedir = 0;
  2895. u32 temp;
  2896. mutex_lock(&dev_priv->dpio_lock);
  2897. /* It is necessary to ungate the pixclk gate prior to programming
  2898. * the divisors, and gate it back when it is done.
  2899. */
  2900. I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE);
  2901. /* Disable SSCCTL */
  2902. intel_sbi_write(dev_priv, SBI_SSCCTL6,
  2903. intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK) |
  2904. SBI_SSCCTL_DISABLE,
  2905. SBI_ICLK);
  2906. /* 20MHz is a corner case which is out of range for the 7-bit divisor */
  2907. if (clock == 20000) {
  2908. auxdiv = 1;
  2909. divsel = 0x41;
  2910. phaseinc = 0x20;
  2911. } else {
  2912. /* The iCLK virtual clock root frequency is in MHz,
  2913. * but the adjusted_mode->crtc_clock in in KHz. To get the
  2914. * divisors, it is necessary to divide one by another, so we
  2915. * convert the virtual clock precision to KHz here for higher
  2916. * precision.
  2917. */
  2918. u32 iclk_virtual_root_freq = 172800 * 1000;
  2919. u32 iclk_pi_range = 64;
  2920. u32 desired_divisor, msb_divisor_value, pi_value;
  2921. desired_divisor = (iclk_virtual_root_freq / clock);
  2922. msb_divisor_value = desired_divisor / iclk_pi_range;
  2923. pi_value = desired_divisor % iclk_pi_range;
  2924. auxdiv = 0;
  2925. divsel = msb_divisor_value - 2;
  2926. phaseinc = pi_value;
  2927. }
  2928. /* This should not happen with any sane values */
  2929. WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) &
  2930. ~SBI_SSCDIVINTPHASE_DIVSEL_MASK);
  2931. WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) &
  2932. ~SBI_SSCDIVINTPHASE_INCVAL_MASK);
  2933. DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
  2934. clock,
  2935. auxdiv,
  2936. divsel,
  2937. phasedir,
  2938. phaseinc);
  2939. /* Program SSCDIVINTPHASE6 */
  2940. temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
  2941. temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK;
  2942. temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel);
  2943. temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK;
  2944. temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc);
  2945. temp |= SBI_SSCDIVINTPHASE_DIR(phasedir);
  2946. temp |= SBI_SSCDIVINTPHASE_PROPAGATE;
  2947. intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK);
  2948. /* Program SSCAUXDIV */
  2949. temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
  2950. temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
  2951. temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv);
  2952. intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK);
  2953. /* Enable modulator and associated divider */
  2954. temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
  2955. temp &= ~SBI_SSCCTL_DISABLE;
  2956. intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
  2957. /* Wait for initialization time */
  2958. udelay(24);
  2959. I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE);
  2960. mutex_unlock(&dev_priv->dpio_lock);
  2961. }
  2962. static void ironlake_pch_transcoder_set_timings(struct intel_crtc *crtc,
  2963. enum pipe pch_transcoder)
  2964. {
  2965. struct drm_device *dev = crtc->base.dev;
  2966. struct drm_i915_private *dev_priv = dev->dev_private;
  2967. enum transcoder cpu_transcoder = crtc->config.cpu_transcoder;
  2968. I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder),
  2969. I915_READ(HTOTAL(cpu_transcoder)));
  2970. I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder),
  2971. I915_READ(HBLANK(cpu_transcoder)));
  2972. I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder),
  2973. I915_READ(HSYNC(cpu_transcoder)));
  2974. I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder),
  2975. I915_READ(VTOTAL(cpu_transcoder)));
  2976. I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder),
  2977. I915_READ(VBLANK(cpu_transcoder)));
  2978. I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder),
  2979. I915_READ(VSYNC(cpu_transcoder)));
  2980. I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder),
  2981. I915_READ(VSYNCSHIFT(cpu_transcoder)));
  2982. }
  2983. static void cpt_enable_fdi_bc_bifurcation(struct drm_device *dev)
  2984. {
  2985. struct drm_i915_private *dev_priv = dev->dev_private;
  2986. uint32_t temp;
  2987. temp = I915_READ(SOUTH_CHICKEN1);
  2988. if (temp & FDI_BC_BIFURCATION_SELECT)
  2989. return;
  2990. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
  2991. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
  2992. temp |= FDI_BC_BIFURCATION_SELECT;
  2993. DRM_DEBUG_KMS("enabling fdi C rx\n");
  2994. I915_WRITE(SOUTH_CHICKEN1, temp);
  2995. POSTING_READ(SOUTH_CHICKEN1);
  2996. }
  2997. static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc *intel_crtc)
  2998. {
  2999. struct drm_device *dev = intel_crtc->base.dev;
  3000. struct drm_i915_private *dev_priv = dev->dev_private;
  3001. switch (intel_crtc->pipe) {
  3002. case PIPE_A:
  3003. break;
  3004. case PIPE_B:
  3005. if (intel_crtc->config.fdi_lanes > 2)
  3006. WARN_ON(I915_READ(SOUTH_CHICKEN1) & FDI_BC_BIFURCATION_SELECT);
  3007. else
  3008. cpt_enable_fdi_bc_bifurcation(dev);
  3009. break;
  3010. case PIPE_C:
  3011. cpt_enable_fdi_bc_bifurcation(dev);
  3012. break;
  3013. default:
  3014. BUG();
  3015. }
  3016. }
  3017. /*
  3018. * Enable PCH resources required for PCH ports:
  3019. * - PCH PLLs
  3020. * - FDI training & RX/TX
  3021. * - update transcoder timings
  3022. * - DP transcoding bits
  3023. * - transcoder
  3024. */
  3025. static void ironlake_pch_enable(struct drm_crtc *crtc)
  3026. {
  3027. struct drm_device *dev = crtc->dev;
  3028. struct drm_i915_private *dev_priv = dev->dev_private;
  3029. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3030. int pipe = intel_crtc->pipe;
  3031. u32 reg, temp;
  3032. assert_pch_transcoder_disabled(dev_priv, pipe);
  3033. if (IS_IVYBRIDGE(dev))
  3034. ivybridge_update_fdi_bc_bifurcation(intel_crtc);
  3035. /* Write the TU size bits before fdi link training, so that error
  3036. * detection works. */
  3037. I915_WRITE(FDI_RX_TUSIZE1(pipe),
  3038. I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
  3039. /* For PCH output, training FDI link */
  3040. dev_priv->display.fdi_link_train(crtc);
  3041. /* We need to program the right clock selection before writing the pixel
  3042. * mutliplier into the DPLL. */
  3043. if (HAS_PCH_CPT(dev)) {
  3044. u32 sel;
  3045. temp = I915_READ(PCH_DPLL_SEL);
  3046. temp |= TRANS_DPLL_ENABLE(pipe);
  3047. sel = TRANS_DPLLB_SEL(pipe);
  3048. if (intel_crtc->config.shared_dpll == DPLL_ID_PCH_PLL_B)
  3049. temp |= sel;
  3050. else
  3051. temp &= ~sel;
  3052. I915_WRITE(PCH_DPLL_SEL, temp);
  3053. }
  3054. /* XXX: pch pll's can be enabled any time before we enable the PCH
  3055. * transcoder, and we actually should do this to not upset any PCH
  3056. * transcoder that already use the clock when we share it.
  3057. *
  3058. * Note that enable_shared_dpll tries to do the right thing, but
  3059. * get_shared_dpll unconditionally resets the pll - we need that to have
  3060. * the right LVDS enable sequence. */
  3061. intel_enable_shared_dpll(intel_crtc);
  3062. /* set transcoder timing, panel must allow it */
  3063. assert_panel_unlocked(dev_priv, pipe);
  3064. ironlake_pch_transcoder_set_timings(intel_crtc, pipe);
  3065. intel_fdi_normal_train(crtc);
  3066. /* For PCH DP, enable TRANS_DP_CTL */
  3067. if (HAS_PCH_CPT(dev) &&
  3068. (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) ||
  3069. intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) {
  3070. u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5;
  3071. reg = TRANS_DP_CTL(pipe);
  3072. temp = I915_READ(reg);
  3073. temp &= ~(TRANS_DP_PORT_SEL_MASK |
  3074. TRANS_DP_SYNC_MASK |
  3075. TRANS_DP_BPC_MASK);
  3076. temp |= (TRANS_DP_OUTPUT_ENABLE |
  3077. TRANS_DP_ENH_FRAMING);
  3078. temp |= bpc << 9; /* same format but at 11:9 */
  3079. if (crtc->mode.flags & DRM_MODE_FLAG_PHSYNC)
  3080. temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
  3081. if (crtc->mode.flags & DRM_MODE_FLAG_PVSYNC)
  3082. temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
  3083. switch (intel_trans_dp_port_sel(crtc)) {
  3084. case PCH_DP_B:
  3085. temp |= TRANS_DP_PORT_SEL_B;
  3086. break;
  3087. case PCH_DP_C:
  3088. temp |= TRANS_DP_PORT_SEL_C;
  3089. break;
  3090. case PCH_DP_D:
  3091. temp |= TRANS_DP_PORT_SEL_D;
  3092. break;
  3093. default:
  3094. BUG();
  3095. }
  3096. I915_WRITE(reg, temp);
  3097. }
  3098. ironlake_enable_pch_transcoder(dev_priv, pipe);
  3099. }
  3100. static void lpt_pch_enable(struct drm_crtc *crtc)
  3101. {
  3102. struct drm_device *dev = crtc->dev;
  3103. struct drm_i915_private *dev_priv = dev->dev_private;
  3104. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3105. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  3106. assert_pch_transcoder_disabled(dev_priv, TRANSCODER_A);
  3107. lpt_program_iclkip(crtc);
  3108. /* Set transcoder timing. */
  3109. ironlake_pch_transcoder_set_timings(intel_crtc, PIPE_A);
  3110. lpt_enable_pch_transcoder(dev_priv, cpu_transcoder);
  3111. }
  3112. static void intel_put_shared_dpll(struct intel_crtc *crtc)
  3113. {
  3114. struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
  3115. if (pll == NULL)
  3116. return;
  3117. if (pll->refcount == 0) {
  3118. WARN(1, "bad %s refcount\n", pll->name);
  3119. return;
  3120. }
  3121. if (--pll->refcount == 0) {
  3122. WARN_ON(pll->on);
  3123. WARN_ON(pll->active);
  3124. }
  3125. crtc->config.shared_dpll = DPLL_ID_PRIVATE;
  3126. }
  3127. static struct intel_shared_dpll *intel_get_shared_dpll(struct intel_crtc *crtc)
  3128. {
  3129. struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
  3130. struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
  3131. enum intel_dpll_id i;
  3132. if (pll) {
  3133. DRM_DEBUG_KMS("CRTC:%d dropping existing %s\n",
  3134. crtc->base.base.id, pll->name);
  3135. intel_put_shared_dpll(crtc);
  3136. }
  3137. if (HAS_PCH_IBX(dev_priv->dev)) {
  3138. /* Ironlake PCH has a fixed PLL->PCH pipe mapping. */
  3139. i = (enum intel_dpll_id) crtc->pipe;
  3140. pll = &dev_priv->shared_dplls[i];
  3141. DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n",
  3142. crtc->base.base.id, pll->name);
  3143. WARN_ON(pll->refcount);
  3144. goto found;
  3145. }
  3146. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  3147. pll = &dev_priv->shared_dplls[i];
  3148. /* Only want to check enabled timings first */
  3149. if (pll->refcount == 0)
  3150. continue;
  3151. if (memcmp(&crtc->config.dpll_hw_state, &pll->hw_state,
  3152. sizeof(pll->hw_state)) == 0) {
  3153. DRM_DEBUG_KMS("CRTC:%d sharing existing %s (refcount %d, ative %d)\n",
  3154. crtc->base.base.id,
  3155. pll->name, pll->refcount, pll->active);
  3156. goto found;
  3157. }
  3158. }
  3159. /* Ok no matching timings, maybe there's a free one? */
  3160. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  3161. pll = &dev_priv->shared_dplls[i];
  3162. if (pll->refcount == 0) {
  3163. DRM_DEBUG_KMS("CRTC:%d allocated %s\n",
  3164. crtc->base.base.id, pll->name);
  3165. goto found;
  3166. }
  3167. }
  3168. return NULL;
  3169. found:
  3170. if (pll->refcount == 0)
  3171. pll->hw_state = crtc->config.dpll_hw_state;
  3172. crtc->config.shared_dpll = i;
  3173. DRM_DEBUG_DRIVER("using %s for pipe %c\n", pll->name,
  3174. pipe_name(crtc->pipe));
  3175. pll->refcount++;
  3176. return pll;
  3177. }
  3178. static void cpt_verify_modeset(struct drm_device *dev, int pipe)
  3179. {
  3180. struct drm_i915_private *dev_priv = dev->dev_private;
  3181. int dslreg = PIPEDSL(pipe);
  3182. u32 temp;
  3183. temp = I915_READ(dslreg);
  3184. udelay(500);
  3185. if (wait_for(I915_READ(dslreg) != temp, 5)) {
  3186. if (wait_for(I915_READ(dslreg) != temp, 5))
  3187. DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe));
  3188. }
  3189. }
  3190. static void ironlake_pfit_enable(struct intel_crtc *crtc)
  3191. {
  3192. struct drm_device *dev = crtc->base.dev;
  3193. struct drm_i915_private *dev_priv = dev->dev_private;
  3194. int pipe = crtc->pipe;
  3195. if (crtc->config.pch_pfit.enabled) {
  3196. /* Force use of hard-coded filter coefficients
  3197. * as some pre-programmed values are broken,
  3198. * e.g. x201.
  3199. */
  3200. if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev))
  3201. I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 |
  3202. PF_PIPE_SEL_IVB(pipe));
  3203. else
  3204. I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3);
  3205. I915_WRITE(PF_WIN_POS(pipe), crtc->config.pch_pfit.pos);
  3206. I915_WRITE(PF_WIN_SZ(pipe), crtc->config.pch_pfit.size);
  3207. }
  3208. }
  3209. static void intel_enable_planes(struct drm_crtc *crtc)
  3210. {
  3211. struct drm_device *dev = crtc->dev;
  3212. enum pipe pipe = to_intel_crtc(crtc)->pipe;
  3213. struct drm_plane *plane;
  3214. struct intel_plane *intel_plane;
  3215. drm_for_each_legacy_plane(plane, &dev->mode_config.plane_list) {
  3216. intel_plane = to_intel_plane(plane);
  3217. if (intel_plane->pipe == pipe)
  3218. intel_plane_restore(&intel_plane->base);
  3219. }
  3220. }
  3221. static void intel_disable_planes(struct drm_crtc *crtc)
  3222. {
  3223. struct drm_device *dev = crtc->dev;
  3224. enum pipe pipe = to_intel_crtc(crtc)->pipe;
  3225. struct drm_plane *plane;
  3226. struct intel_plane *intel_plane;
  3227. drm_for_each_legacy_plane(plane, &dev->mode_config.plane_list) {
  3228. intel_plane = to_intel_plane(plane);
  3229. if (intel_plane->pipe == pipe)
  3230. intel_plane_disable(&intel_plane->base);
  3231. }
  3232. }
  3233. void hsw_enable_ips(struct intel_crtc *crtc)
  3234. {
  3235. struct drm_device *dev = crtc->base.dev;
  3236. struct drm_i915_private *dev_priv = dev->dev_private;
  3237. if (!crtc->config.ips_enabled)
  3238. return;
  3239. /* We can only enable IPS after we enable a plane and wait for a vblank */
  3240. intel_wait_for_vblank(dev, crtc->pipe);
  3241. assert_plane_enabled(dev_priv, crtc->plane);
  3242. if (IS_BROADWELL(dev)) {
  3243. mutex_lock(&dev_priv->rps.hw_lock);
  3244. WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0xc0000000));
  3245. mutex_unlock(&dev_priv->rps.hw_lock);
  3246. /* Quoting Art Runyan: "its not safe to expect any particular
  3247. * value in IPS_CTL bit 31 after enabling IPS through the
  3248. * mailbox." Moreover, the mailbox may return a bogus state,
  3249. * so we need to just enable it and continue on.
  3250. */
  3251. } else {
  3252. I915_WRITE(IPS_CTL, IPS_ENABLE);
  3253. /* The bit only becomes 1 in the next vblank, so this wait here
  3254. * is essentially intel_wait_for_vblank. If we don't have this
  3255. * and don't wait for vblanks until the end of crtc_enable, then
  3256. * the HW state readout code will complain that the expected
  3257. * IPS_CTL value is not the one we read. */
  3258. if (wait_for(I915_READ_NOTRACE(IPS_CTL) & IPS_ENABLE, 50))
  3259. DRM_ERROR("Timed out waiting for IPS enable\n");
  3260. }
  3261. }
  3262. void hsw_disable_ips(struct intel_crtc *crtc)
  3263. {
  3264. struct drm_device *dev = crtc->base.dev;
  3265. struct drm_i915_private *dev_priv = dev->dev_private;
  3266. if (!crtc->config.ips_enabled)
  3267. return;
  3268. assert_plane_enabled(dev_priv, crtc->plane);
  3269. if (IS_BROADWELL(dev)) {
  3270. mutex_lock(&dev_priv->rps.hw_lock);
  3271. WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0));
  3272. mutex_unlock(&dev_priv->rps.hw_lock);
  3273. /* wait for pcode to finish disabling IPS, which may take up to 42ms */
  3274. if (wait_for((I915_READ(IPS_CTL) & IPS_ENABLE) == 0, 42))
  3275. DRM_ERROR("Timed out waiting for IPS disable\n");
  3276. } else {
  3277. I915_WRITE(IPS_CTL, 0);
  3278. POSTING_READ(IPS_CTL);
  3279. }
  3280. /* We need to wait for a vblank before we can disable the plane. */
  3281. intel_wait_for_vblank(dev, crtc->pipe);
  3282. }
  3283. /** Loads the palette/gamma unit for the CRTC with the prepared values */
  3284. static void intel_crtc_load_lut(struct drm_crtc *crtc)
  3285. {
  3286. struct drm_device *dev = crtc->dev;
  3287. struct drm_i915_private *dev_priv = dev->dev_private;
  3288. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3289. enum pipe pipe = intel_crtc->pipe;
  3290. int palreg = PALETTE(pipe);
  3291. int i;
  3292. bool reenable_ips = false;
  3293. /* The clocks have to be on to load the palette. */
  3294. if (!crtc->enabled || !intel_crtc->active)
  3295. return;
  3296. if (!HAS_PCH_SPLIT(dev_priv->dev)) {
  3297. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DSI))
  3298. assert_dsi_pll_enabled(dev_priv);
  3299. else
  3300. assert_pll_enabled(dev_priv, pipe);
  3301. }
  3302. /* use legacy palette for Ironlake */
  3303. if (HAS_PCH_SPLIT(dev))
  3304. palreg = LGC_PALETTE(pipe);
  3305. /* Workaround : Do not read or write the pipe palette/gamma data while
  3306. * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
  3307. */
  3308. if (IS_HASWELL(dev) && intel_crtc->config.ips_enabled &&
  3309. ((I915_READ(GAMMA_MODE(pipe)) & GAMMA_MODE_MODE_MASK) ==
  3310. GAMMA_MODE_MODE_SPLIT)) {
  3311. hsw_disable_ips(intel_crtc);
  3312. reenable_ips = true;
  3313. }
  3314. for (i = 0; i < 256; i++) {
  3315. I915_WRITE(palreg + 4 * i,
  3316. (intel_crtc->lut_r[i] << 16) |
  3317. (intel_crtc->lut_g[i] << 8) |
  3318. intel_crtc->lut_b[i]);
  3319. }
  3320. if (reenable_ips)
  3321. hsw_enable_ips(intel_crtc);
  3322. }
  3323. static void intel_crtc_dpms_overlay(struct intel_crtc *intel_crtc, bool enable)
  3324. {
  3325. if (!enable && intel_crtc->overlay) {
  3326. struct drm_device *dev = intel_crtc->base.dev;
  3327. struct drm_i915_private *dev_priv = dev->dev_private;
  3328. mutex_lock(&dev->struct_mutex);
  3329. dev_priv->mm.interruptible = false;
  3330. (void) intel_overlay_switch_off(intel_crtc->overlay);
  3331. dev_priv->mm.interruptible = true;
  3332. mutex_unlock(&dev->struct_mutex);
  3333. }
  3334. /* Let userspace switch the overlay on again. In most cases userspace
  3335. * has to recompute where to put it anyway.
  3336. */
  3337. }
  3338. /**
  3339. * i9xx_fixup_plane - ugly workaround for G45 to fire up the hardware
  3340. * cursor plane briefly if not already running after enabling the display
  3341. * plane.
  3342. * This workaround avoids occasional blank screens when self refresh is
  3343. * enabled.
  3344. */
  3345. static void
  3346. g4x_fixup_plane(struct drm_i915_private *dev_priv, enum pipe pipe)
  3347. {
  3348. u32 cntl = I915_READ(CURCNTR(pipe));
  3349. if ((cntl & CURSOR_MODE) == 0) {
  3350. u32 fw_bcl_self = I915_READ(FW_BLC_SELF);
  3351. I915_WRITE(FW_BLC_SELF, fw_bcl_self & ~FW_BLC_SELF_EN);
  3352. I915_WRITE(CURCNTR(pipe), CURSOR_MODE_64_ARGB_AX);
  3353. intel_wait_for_vblank(dev_priv->dev, pipe);
  3354. I915_WRITE(CURCNTR(pipe), cntl);
  3355. I915_WRITE(CURBASE(pipe), I915_READ(CURBASE(pipe)));
  3356. I915_WRITE(FW_BLC_SELF, fw_bcl_self);
  3357. }
  3358. }
  3359. static void intel_crtc_enable_planes(struct drm_crtc *crtc)
  3360. {
  3361. struct drm_device *dev = crtc->dev;
  3362. struct drm_i915_private *dev_priv = dev->dev_private;
  3363. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3364. int pipe = intel_crtc->pipe;
  3365. int plane = intel_crtc->plane;
  3366. drm_vblank_on(dev, pipe);
  3367. intel_enable_primary_hw_plane(dev_priv, plane, pipe);
  3368. intel_enable_planes(crtc);
  3369. /* The fixup needs to happen before cursor is enabled */
  3370. if (IS_G4X(dev))
  3371. g4x_fixup_plane(dev_priv, pipe);
  3372. intel_crtc_update_cursor(crtc, true);
  3373. intel_crtc_dpms_overlay(intel_crtc, true);
  3374. hsw_enable_ips(intel_crtc);
  3375. mutex_lock(&dev->struct_mutex);
  3376. intel_update_fbc(dev);
  3377. mutex_unlock(&dev->struct_mutex);
  3378. /*
  3379. * FIXME: Once we grow proper nuclear flip support out of this we need
  3380. * to compute the mask of flip planes precisely. For the time being
  3381. * consider this a flip from a NULL plane.
  3382. */
  3383. intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_ALL_MASK(pipe));
  3384. }
  3385. static void intel_crtc_disable_planes(struct drm_crtc *crtc)
  3386. {
  3387. struct drm_device *dev = crtc->dev;
  3388. struct drm_i915_private *dev_priv = dev->dev_private;
  3389. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3390. int pipe = intel_crtc->pipe;
  3391. int plane = intel_crtc->plane;
  3392. intel_crtc_wait_for_pending_flips(crtc);
  3393. if (dev_priv->fbc.plane == plane)
  3394. intel_disable_fbc(dev);
  3395. hsw_disable_ips(intel_crtc);
  3396. intel_crtc_dpms_overlay(intel_crtc, false);
  3397. intel_crtc_update_cursor(crtc, false);
  3398. intel_disable_planes(crtc);
  3399. intel_disable_primary_hw_plane(dev_priv, plane, pipe);
  3400. /*
  3401. * FIXME: Once we grow proper nuclear flip support out of this we need
  3402. * to compute the mask of flip planes precisely. For the time being
  3403. * consider this a flip to a NULL plane.
  3404. */
  3405. intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_ALL_MASK(pipe));
  3406. drm_vblank_off(dev, pipe);
  3407. }
  3408. static void ironlake_crtc_enable(struct drm_crtc *crtc)
  3409. {
  3410. struct drm_device *dev = crtc->dev;
  3411. struct drm_i915_private *dev_priv = dev->dev_private;
  3412. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3413. struct intel_encoder *encoder;
  3414. int pipe = intel_crtc->pipe;
  3415. enum plane plane = intel_crtc->plane;
  3416. WARN_ON(!crtc->enabled);
  3417. if (intel_crtc->active)
  3418. return;
  3419. if (intel_crtc->config.has_pch_encoder)
  3420. intel_prepare_shared_dpll(intel_crtc);
  3421. if (intel_crtc->config.has_dp_encoder)
  3422. intel_dp_set_m_n(intel_crtc);
  3423. intel_set_pipe_timings(intel_crtc);
  3424. if (intel_crtc->config.has_pch_encoder) {
  3425. intel_cpu_transcoder_set_m_n(intel_crtc,
  3426. &intel_crtc->config.fdi_m_n);
  3427. }
  3428. ironlake_set_pipeconf(crtc);
  3429. /* Set up the display plane register */
  3430. I915_WRITE(DSPCNTR(plane), DISPPLANE_GAMMA_ENABLE);
  3431. POSTING_READ(DSPCNTR(plane));
  3432. dev_priv->display.update_primary_plane(crtc, crtc->primary->fb,
  3433. crtc->x, crtc->y);
  3434. intel_crtc->active = true;
  3435. intel_set_cpu_fifo_underrun_reporting(dev, pipe, true);
  3436. intel_set_pch_fifo_underrun_reporting(dev, pipe, true);
  3437. for_each_encoder_on_crtc(dev, crtc, encoder)
  3438. if (encoder->pre_enable)
  3439. encoder->pre_enable(encoder);
  3440. if (intel_crtc->config.has_pch_encoder) {
  3441. /* Note: FDI PLL enabling _must_ be done before we enable the
  3442. * cpu pipes, hence this is separate from all the other fdi/pch
  3443. * enabling. */
  3444. ironlake_fdi_pll_enable(intel_crtc);
  3445. } else {
  3446. assert_fdi_tx_disabled(dev_priv, pipe);
  3447. assert_fdi_rx_disabled(dev_priv, pipe);
  3448. }
  3449. ironlake_pfit_enable(intel_crtc);
  3450. /*
  3451. * On ILK+ LUT must be loaded before the pipe is running but with
  3452. * clocks enabled
  3453. */
  3454. intel_crtc_load_lut(crtc);
  3455. intel_update_watermarks(crtc);
  3456. intel_enable_pipe(intel_crtc);
  3457. if (intel_crtc->config.has_pch_encoder)
  3458. ironlake_pch_enable(crtc);
  3459. for_each_encoder_on_crtc(dev, crtc, encoder)
  3460. encoder->enable(encoder);
  3461. if (HAS_PCH_CPT(dev))
  3462. cpt_verify_modeset(dev, intel_crtc->pipe);
  3463. intel_crtc_enable_planes(crtc);
  3464. }
  3465. /* IPS only exists on ULT machines and is tied to pipe A. */
  3466. static bool hsw_crtc_supports_ips(struct intel_crtc *crtc)
  3467. {
  3468. return HAS_IPS(crtc->base.dev) && crtc->pipe == PIPE_A;
  3469. }
  3470. /*
  3471. * This implements the workaround described in the "notes" section of the mode
  3472. * set sequence documentation. When going from no pipes or single pipe to
  3473. * multiple pipes, and planes are enabled after the pipe, we need to wait at
  3474. * least 2 vblanks on the first pipe before enabling planes on the second pipe.
  3475. */
  3476. static void haswell_mode_set_planes_workaround(struct intel_crtc *crtc)
  3477. {
  3478. struct drm_device *dev = crtc->base.dev;
  3479. struct intel_crtc *crtc_it, *other_active_crtc = NULL;
  3480. /* We want to get the other_active_crtc only if there's only 1 other
  3481. * active crtc. */
  3482. for_each_intel_crtc(dev, crtc_it) {
  3483. if (!crtc_it->active || crtc_it == crtc)
  3484. continue;
  3485. if (other_active_crtc)
  3486. return;
  3487. other_active_crtc = crtc_it;
  3488. }
  3489. if (!other_active_crtc)
  3490. return;
  3491. intel_wait_for_vblank(dev, other_active_crtc->pipe);
  3492. intel_wait_for_vblank(dev, other_active_crtc->pipe);
  3493. }
  3494. static void haswell_crtc_enable(struct drm_crtc *crtc)
  3495. {
  3496. struct drm_device *dev = crtc->dev;
  3497. struct drm_i915_private *dev_priv = dev->dev_private;
  3498. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3499. struct intel_encoder *encoder;
  3500. int pipe = intel_crtc->pipe;
  3501. enum plane plane = intel_crtc->plane;
  3502. WARN_ON(!crtc->enabled);
  3503. if (intel_crtc->active)
  3504. return;
  3505. if (intel_crtc->config.has_dp_encoder)
  3506. intel_dp_set_m_n(intel_crtc);
  3507. intel_set_pipe_timings(intel_crtc);
  3508. if (intel_crtc->config.has_pch_encoder) {
  3509. intel_cpu_transcoder_set_m_n(intel_crtc,
  3510. &intel_crtc->config.fdi_m_n);
  3511. }
  3512. haswell_set_pipeconf(crtc);
  3513. intel_set_pipe_csc(crtc);
  3514. /* Set up the display plane register */
  3515. I915_WRITE(DSPCNTR(plane), DISPPLANE_GAMMA_ENABLE | DISPPLANE_PIPE_CSC_ENABLE);
  3516. POSTING_READ(DSPCNTR(plane));
  3517. dev_priv->display.update_primary_plane(crtc, crtc->primary->fb,
  3518. crtc->x, crtc->y);
  3519. intel_crtc->active = true;
  3520. intel_set_cpu_fifo_underrun_reporting(dev, pipe, true);
  3521. if (intel_crtc->config.has_pch_encoder)
  3522. intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, true);
  3523. if (intel_crtc->config.has_pch_encoder)
  3524. dev_priv->display.fdi_link_train(crtc);
  3525. for_each_encoder_on_crtc(dev, crtc, encoder)
  3526. if (encoder->pre_enable)
  3527. encoder->pre_enable(encoder);
  3528. intel_ddi_enable_pipe_clock(intel_crtc);
  3529. ironlake_pfit_enable(intel_crtc);
  3530. /*
  3531. * On ILK+ LUT must be loaded before the pipe is running but with
  3532. * clocks enabled
  3533. */
  3534. intel_crtc_load_lut(crtc);
  3535. intel_ddi_set_pipe_settings(crtc);
  3536. intel_ddi_enable_transcoder_func(crtc);
  3537. intel_update_watermarks(crtc);
  3538. intel_enable_pipe(intel_crtc);
  3539. if (intel_crtc->config.has_pch_encoder)
  3540. lpt_pch_enable(crtc);
  3541. for_each_encoder_on_crtc(dev, crtc, encoder) {
  3542. encoder->enable(encoder);
  3543. intel_opregion_notify_encoder(encoder, true);
  3544. }
  3545. /* If we change the relative order between pipe/planes enabling, we need
  3546. * to change the workaround. */
  3547. haswell_mode_set_planes_workaround(intel_crtc);
  3548. intel_crtc_enable_planes(crtc);
  3549. }
  3550. static void ironlake_pfit_disable(struct intel_crtc *crtc)
  3551. {
  3552. struct drm_device *dev = crtc->base.dev;
  3553. struct drm_i915_private *dev_priv = dev->dev_private;
  3554. int pipe = crtc->pipe;
  3555. /* To avoid upsetting the power well on haswell only disable the pfit if
  3556. * it's in use. The hw state code will make sure we get this right. */
  3557. if (crtc->config.pch_pfit.enabled) {
  3558. I915_WRITE(PF_CTL(pipe), 0);
  3559. I915_WRITE(PF_WIN_POS(pipe), 0);
  3560. I915_WRITE(PF_WIN_SZ(pipe), 0);
  3561. }
  3562. }
  3563. static void ironlake_crtc_disable(struct drm_crtc *crtc)
  3564. {
  3565. struct drm_device *dev = crtc->dev;
  3566. struct drm_i915_private *dev_priv = dev->dev_private;
  3567. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3568. struct intel_encoder *encoder;
  3569. int pipe = intel_crtc->pipe;
  3570. u32 reg, temp;
  3571. if (!intel_crtc->active)
  3572. return;
  3573. intel_crtc_disable_planes(crtc);
  3574. for_each_encoder_on_crtc(dev, crtc, encoder)
  3575. encoder->disable(encoder);
  3576. if (intel_crtc->config.has_pch_encoder)
  3577. intel_set_pch_fifo_underrun_reporting(dev, pipe, false);
  3578. intel_disable_pipe(dev_priv, pipe);
  3579. ironlake_pfit_disable(intel_crtc);
  3580. for_each_encoder_on_crtc(dev, crtc, encoder)
  3581. if (encoder->post_disable)
  3582. encoder->post_disable(encoder);
  3583. if (intel_crtc->config.has_pch_encoder) {
  3584. ironlake_fdi_disable(crtc);
  3585. ironlake_disable_pch_transcoder(dev_priv, pipe);
  3586. intel_set_pch_fifo_underrun_reporting(dev, pipe, true);
  3587. if (HAS_PCH_CPT(dev)) {
  3588. /* disable TRANS_DP_CTL */
  3589. reg = TRANS_DP_CTL(pipe);
  3590. temp = I915_READ(reg);
  3591. temp &= ~(TRANS_DP_OUTPUT_ENABLE |
  3592. TRANS_DP_PORT_SEL_MASK);
  3593. temp |= TRANS_DP_PORT_SEL_NONE;
  3594. I915_WRITE(reg, temp);
  3595. /* disable DPLL_SEL */
  3596. temp = I915_READ(PCH_DPLL_SEL);
  3597. temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe));
  3598. I915_WRITE(PCH_DPLL_SEL, temp);
  3599. }
  3600. /* disable PCH DPLL */
  3601. intel_disable_shared_dpll(intel_crtc);
  3602. ironlake_fdi_pll_disable(intel_crtc);
  3603. }
  3604. intel_crtc->active = false;
  3605. intel_update_watermarks(crtc);
  3606. mutex_lock(&dev->struct_mutex);
  3607. intel_update_fbc(dev);
  3608. mutex_unlock(&dev->struct_mutex);
  3609. }
  3610. static void haswell_crtc_disable(struct drm_crtc *crtc)
  3611. {
  3612. struct drm_device *dev = crtc->dev;
  3613. struct drm_i915_private *dev_priv = dev->dev_private;
  3614. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3615. struct intel_encoder *encoder;
  3616. int pipe = intel_crtc->pipe;
  3617. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  3618. if (!intel_crtc->active)
  3619. return;
  3620. intel_crtc_disable_planes(crtc);
  3621. for_each_encoder_on_crtc(dev, crtc, encoder) {
  3622. intel_opregion_notify_encoder(encoder, false);
  3623. encoder->disable(encoder);
  3624. }
  3625. if (intel_crtc->config.has_pch_encoder)
  3626. intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, false);
  3627. intel_disable_pipe(dev_priv, pipe);
  3628. intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder);
  3629. ironlake_pfit_disable(intel_crtc);
  3630. intel_ddi_disable_pipe_clock(intel_crtc);
  3631. for_each_encoder_on_crtc(dev, crtc, encoder)
  3632. if (encoder->post_disable)
  3633. encoder->post_disable(encoder);
  3634. if (intel_crtc->config.has_pch_encoder) {
  3635. lpt_disable_pch_transcoder(dev_priv);
  3636. intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, true);
  3637. intel_ddi_fdi_disable(crtc);
  3638. }
  3639. intel_crtc->active = false;
  3640. intel_update_watermarks(crtc);
  3641. mutex_lock(&dev->struct_mutex);
  3642. intel_update_fbc(dev);
  3643. mutex_unlock(&dev->struct_mutex);
  3644. }
  3645. static void ironlake_crtc_off(struct drm_crtc *crtc)
  3646. {
  3647. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3648. intel_put_shared_dpll(intel_crtc);
  3649. }
  3650. static void haswell_crtc_off(struct drm_crtc *crtc)
  3651. {
  3652. intel_ddi_put_crtc_pll(crtc);
  3653. }
  3654. static void i9xx_pfit_enable(struct intel_crtc *crtc)
  3655. {
  3656. struct drm_device *dev = crtc->base.dev;
  3657. struct drm_i915_private *dev_priv = dev->dev_private;
  3658. struct intel_crtc_config *pipe_config = &crtc->config;
  3659. if (!crtc->config.gmch_pfit.control)
  3660. return;
  3661. /*
  3662. * The panel fitter should only be adjusted whilst the pipe is disabled,
  3663. * according to register description and PRM.
  3664. */
  3665. WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE);
  3666. assert_pipe_disabled(dev_priv, crtc->pipe);
  3667. I915_WRITE(PFIT_PGM_RATIOS, pipe_config->gmch_pfit.pgm_ratios);
  3668. I915_WRITE(PFIT_CONTROL, pipe_config->gmch_pfit.control);
  3669. /* Border color in case we don't scale up to the full screen. Black by
  3670. * default, change to something else for debugging. */
  3671. I915_WRITE(BCLRPAT(crtc->pipe), 0);
  3672. }
  3673. #define for_each_power_domain(domain, mask) \
  3674. for ((domain) = 0; (domain) < POWER_DOMAIN_NUM; (domain)++) \
  3675. if ((1 << (domain)) & (mask))
  3676. enum intel_display_power_domain
  3677. intel_display_port_power_domain(struct intel_encoder *intel_encoder)
  3678. {
  3679. struct drm_device *dev = intel_encoder->base.dev;
  3680. struct intel_digital_port *intel_dig_port;
  3681. switch (intel_encoder->type) {
  3682. case INTEL_OUTPUT_UNKNOWN:
  3683. /* Only DDI platforms should ever use this output type */
  3684. WARN_ON_ONCE(!HAS_DDI(dev));
  3685. case INTEL_OUTPUT_DISPLAYPORT:
  3686. case INTEL_OUTPUT_HDMI:
  3687. case INTEL_OUTPUT_EDP:
  3688. intel_dig_port = enc_to_dig_port(&intel_encoder->base);
  3689. switch (intel_dig_port->port) {
  3690. case PORT_A:
  3691. return POWER_DOMAIN_PORT_DDI_A_4_LANES;
  3692. case PORT_B:
  3693. return POWER_DOMAIN_PORT_DDI_B_4_LANES;
  3694. case PORT_C:
  3695. return POWER_DOMAIN_PORT_DDI_C_4_LANES;
  3696. case PORT_D:
  3697. return POWER_DOMAIN_PORT_DDI_D_4_LANES;
  3698. default:
  3699. WARN_ON_ONCE(1);
  3700. return POWER_DOMAIN_PORT_OTHER;
  3701. }
  3702. case INTEL_OUTPUT_ANALOG:
  3703. return POWER_DOMAIN_PORT_CRT;
  3704. case INTEL_OUTPUT_DSI:
  3705. return POWER_DOMAIN_PORT_DSI;
  3706. default:
  3707. return POWER_DOMAIN_PORT_OTHER;
  3708. }
  3709. }
  3710. static unsigned long get_crtc_power_domains(struct drm_crtc *crtc)
  3711. {
  3712. struct drm_device *dev = crtc->dev;
  3713. struct intel_encoder *intel_encoder;
  3714. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3715. enum pipe pipe = intel_crtc->pipe;
  3716. bool pfit_enabled = intel_crtc->config.pch_pfit.enabled;
  3717. unsigned long mask;
  3718. enum transcoder transcoder;
  3719. transcoder = intel_pipe_to_cpu_transcoder(dev->dev_private, pipe);
  3720. mask = BIT(POWER_DOMAIN_PIPE(pipe));
  3721. mask |= BIT(POWER_DOMAIN_TRANSCODER(transcoder));
  3722. if (pfit_enabled)
  3723. mask |= BIT(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe));
  3724. for_each_encoder_on_crtc(dev, crtc, intel_encoder)
  3725. mask |= BIT(intel_display_port_power_domain(intel_encoder));
  3726. return mask;
  3727. }
  3728. void intel_display_set_init_power(struct drm_i915_private *dev_priv,
  3729. bool enable)
  3730. {
  3731. if (dev_priv->power_domains.init_power_on == enable)
  3732. return;
  3733. if (enable)
  3734. intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
  3735. else
  3736. intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
  3737. dev_priv->power_domains.init_power_on = enable;
  3738. }
  3739. static void modeset_update_crtc_power_domains(struct drm_device *dev)
  3740. {
  3741. struct drm_i915_private *dev_priv = dev->dev_private;
  3742. unsigned long pipe_domains[I915_MAX_PIPES] = { 0, };
  3743. struct intel_crtc *crtc;
  3744. /*
  3745. * First get all needed power domains, then put all unneeded, to avoid
  3746. * any unnecessary toggling of the power wells.
  3747. */
  3748. for_each_intel_crtc(dev, crtc) {
  3749. enum intel_display_power_domain domain;
  3750. if (!crtc->base.enabled)
  3751. continue;
  3752. pipe_domains[crtc->pipe] = get_crtc_power_domains(&crtc->base);
  3753. for_each_power_domain(domain, pipe_domains[crtc->pipe])
  3754. intel_display_power_get(dev_priv, domain);
  3755. }
  3756. for_each_intel_crtc(dev, crtc) {
  3757. enum intel_display_power_domain domain;
  3758. for_each_power_domain(domain, crtc->enabled_power_domains)
  3759. intel_display_power_put(dev_priv, domain);
  3760. crtc->enabled_power_domains = pipe_domains[crtc->pipe];
  3761. }
  3762. intel_display_set_init_power(dev_priv, false);
  3763. }
  3764. int valleyview_get_vco(struct drm_i915_private *dev_priv)
  3765. {
  3766. int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 };
  3767. /* Obtain SKU information */
  3768. mutex_lock(&dev_priv->dpio_lock);
  3769. hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) &
  3770. CCK_FUSE_HPLL_FREQ_MASK;
  3771. mutex_unlock(&dev_priv->dpio_lock);
  3772. return vco_freq[hpll_freq];
  3773. }
  3774. /* Adjust CDclk dividers to allow high res or save power if possible */
  3775. static void valleyview_set_cdclk(struct drm_device *dev, int cdclk)
  3776. {
  3777. struct drm_i915_private *dev_priv = dev->dev_private;
  3778. u32 val, cmd;
  3779. WARN_ON(valleyview_cur_cdclk(dev_priv) != dev_priv->vlv_cdclk_freq);
  3780. dev_priv->vlv_cdclk_freq = cdclk;
  3781. if (cdclk >= 320) /* jump to highest voltage for 400MHz too */
  3782. cmd = 2;
  3783. else if (cdclk == 266)
  3784. cmd = 1;
  3785. else
  3786. cmd = 0;
  3787. mutex_lock(&dev_priv->rps.hw_lock);
  3788. val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
  3789. val &= ~DSPFREQGUAR_MASK;
  3790. val |= (cmd << DSPFREQGUAR_SHIFT);
  3791. vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val);
  3792. if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) &
  3793. DSPFREQSTAT_MASK) == (cmd << DSPFREQSTAT_SHIFT),
  3794. 50)) {
  3795. DRM_ERROR("timed out waiting for CDclk change\n");
  3796. }
  3797. mutex_unlock(&dev_priv->rps.hw_lock);
  3798. if (cdclk == 400) {
  3799. u32 divider, vco;
  3800. vco = valleyview_get_vco(dev_priv);
  3801. divider = ((vco << 1) / cdclk) - 1;
  3802. mutex_lock(&dev_priv->dpio_lock);
  3803. /* adjust cdclk divider */
  3804. val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL);
  3805. val &= ~0xf;
  3806. val |= divider;
  3807. vlv_cck_write(dev_priv, CCK_DISPLAY_CLOCK_CONTROL, val);
  3808. mutex_unlock(&dev_priv->dpio_lock);
  3809. }
  3810. mutex_lock(&dev_priv->dpio_lock);
  3811. /* adjust self-refresh exit latency value */
  3812. val = vlv_bunit_read(dev_priv, BUNIT_REG_BISOC);
  3813. val &= ~0x7f;
  3814. /*
  3815. * For high bandwidth configs, we set a higher latency in the bunit
  3816. * so that the core display fetch happens in time to avoid underruns.
  3817. */
  3818. if (cdclk == 400)
  3819. val |= 4500 / 250; /* 4.5 usec */
  3820. else
  3821. val |= 3000 / 250; /* 3.0 usec */
  3822. vlv_bunit_write(dev_priv, BUNIT_REG_BISOC, val);
  3823. mutex_unlock(&dev_priv->dpio_lock);
  3824. /* Since we changed the CDclk, we need to update the GMBUSFREQ too */
  3825. intel_i2c_reset(dev);
  3826. }
  3827. int valleyview_cur_cdclk(struct drm_i915_private *dev_priv)
  3828. {
  3829. int cur_cdclk, vco;
  3830. int divider;
  3831. vco = valleyview_get_vco(dev_priv);
  3832. mutex_lock(&dev_priv->dpio_lock);
  3833. divider = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL);
  3834. mutex_unlock(&dev_priv->dpio_lock);
  3835. divider &= 0xf;
  3836. cur_cdclk = (vco << 1) / (divider + 1);
  3837. return cur_cdclk;
  3838. }
  3839. static int valleyview_calc_cdclk(struct drm_i915_private *dev_priv,
  3840. int max_pixclk)
  3841. {
  3842. /*
  3843. * Really only a few cases to deal with, as only 4 CDclks are supported:
  3844. * 200MHz
  3845. * 267MHz
  3846. * 320MHz
  3847. * 400MHz
  3848. * So we check to see whether we're above 90% of the lower bin and
  3849. * adjust if needed.
  3850. */
  3851. if (max_pixclk > 288000) {
  3852. return 400;
  3853. } else if (max_pixclk > 240000) {
  3854. return 320;
  3855. } else
  3856. return 266;
  3857. /* Looks like the 200MHz CDclk freq doesn't work on some configs */
  3858. }
  3859. /* compute the max pixel clock for new configuration */
  3860. static int intel_mode_max_pixclk(struct drm_i915_private *dev_priv)
  3861. {
  3862. struct drm_device *dev = dev_priv->dev;
  3863. struct intel_crtc *intel_crtc;
  3864. int max_pixclk = 0;
  3865. for_each_intel_crtc(dev, intel_crtc) {
  3866. if (intel_crtc->new_enabled)
  3867. max_pixclk = max(max_pixclk,
  3868. intel_crtc->new_config->adjusted_mode.crtc_clock);
  3869. }
  3870. return max_pixclk;
  3871. }
  3872. static void valleyview_modeset_global_pipes(struct drm_device *dev,
  3873. unsigned *prepare_pipes)
  3874. {
  3875. struct drm_i915_private *dev_priv = dev->dev_private;
  3876. struct intel_crtc *intel_crtc;
  3877. int max_pixclk = intel_mode_max_pixclk(dev_priv);
  3878. if (valleyview_calc_cdclk(dev_priv, max_pixclk) ==
  3879. dev_priv->vlv_cdclk_freq)
  3880. return;
  3881. /* disable/enable all currently active pipes while we change cdclk */
  3882. for_each_intel_crtc(dev, intel_crtc)
  3883. if (intel_crtc->base.enabled)
  3884. *prepare_pipes |= (1 << intel_crtc->pipe);
  3885. }
  3886. static void valleyview_modeset_global_resources(struct drm_device *dev)
  3887. {
  3888. struct drm_i915_private *dev_priv = dev->dev_private;
  3889. int max_pixclk = intel_mode_max_pixclk(dev_priv);
  3890. int req_cdclk = valleyview_calc_cdclk(dev_priv, max_pixclk);
  3891. if (req_cdclk != dev_priv->vlv_cdclk_freq)
  3892. valleyview_set_cdclk(dev, req_cdclk);
  3893. modeset_update_crtc_power_domains(dev);
  3894. }
  3895. static void valleyview_crtc_enable(struct drm_crtc *crtc)
  3896. {
  3897. struct drm_device *dev = crtc->dev;
  3898. struct drm_i915_private *dev_priv = dev->dev_private;
  3899. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3900. struct intel_encoder *encoder;
  3901. int pipe = intel_crtc->pipe;
  3902. int plane = intel_crtc->plane;
  3903. bool is_dsi;
  3904. u32 dspcntr;
  3905. WARN_ON(!crtc->enabled);
  3906. if (intel_crtc->active)
  3907. return;
  3908. vlv_prepare_pll(intel_crtc);
  3909. /* Set up the display plane register */
  3910. dspcntr = DISPPLANE_GAMMA_ENABLE;
  3911. if (intel_crtc->config.has_dp_encoder)
  3912. intel_dp_set_m_n(intel_crtc);
  3913. intel_set_pipe_timings(intel_crtc);
  3914. /* pipesrc and dspsize control the size that is scaled from,
  3915. * which should always be the user's requested size.
  3916. */
  3917. I915_WRITE(DSPSIZE(plane),
  3918. ((intel_crtc->config.pipe_src_h - 1) << 16) |
  3919. (intel_crtc->config.pipe_src_w - 1));
  3920. I915_WRITE(DSPPOS(plane), 0);
  3921. i9xx_set_pipeconf(intel_crtc);
  3922. I915_WRITE(DSPCNTR(plane), dspcntr);
  3923. POSTING_READ(DSPCNTR(plane));
  3924. dev_priv->display.update_primary_plane(crtc, crtc->primary->fb,
  3925. crtc->x, crtc->y);
  3926. intel_crtc->active = true;
  3927. intel_set_cpu_fifo_underrun_reporting(dev, pipe, true);
  3928. for_each_encoder_on_crtc(dev, crtc, encoder)
  3929. if (encoder->pre_pll_enable)
  3930. encoder->pre_pll_enable(encoder);
  3931. is_dsi = intel_pipe_has_type(crtc, INTEL_OUTPUT_DSI);
  3932. if (!is_dsi) {
  3933. if (IS_CHERRYVIEW(dev))
  3934. chv_enable_pll(intel_crtc);
  3935. else
  3936. vlv_enable_pll(intel_crtc);
  3937. }
  3938. for_each_encoder_on_crtc(dev, crtc, encoder)
  3939. if (encoder->pre_enable)
  3940. encoder->pre_enable(encoder);
  3941. i9xx_pfit_enable(intel_crtc);
  3942. intel_crtc_load_lut(crtc);
  3943. intel_update_watermarks(crtc);
  3944. intel_enable_pipe(intel_crtc);
  3945. for_each_encoder_on_crtc(dev, crtc, encoder)
  3946. encoder->enable(encoder);
  3947. intel_crtc_enable_planes(crtc);
  3948. /* Underruns don't raise interrupts, so check manually. */
  3949. i9xx_check_fifo_underruns(dev);
  3950. }
  3951. static void i9xx_set_pll_dividers(struct intel_crtc *crtc)
  3952. {
  3953. struct drm_device *dev = crtc->base.dev;
  3954. struct drm_i915_private *dev_priv = dev->dev_private;
  3955. I915_WRITE(FP0(crtc->pipe), crtc->config.dpll_hw_state.fp0);
  3956. I915_WRITE(FP1(crtc->pipe), crtc->config.dpll_hw_state.fp1);
  3957. }
  3958. static void i9xx_crtc_enable(struct drm_crtc *crtc)
  3959. {
  3960. struct drm_device *dev = crtc->dev;
  3961. struct drm_i915_private *dev_priv = dev->dev_private;
  3962. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3963. struct intel_encoder *encoder;
  3964. int pipe = intel_crtc->pipe;
  3965. int plane = intel_crtc->plane;
  3966. u32 dspcntr;
  3967. WARN_ON(!crtc->enabled);
  3968. if (intel_crtc->active)
  3969. return;
  3970. i9xx_set_pll_dividers(intel_crtc);
  3971. /* Set up the display plane register */
  3972. dspcntr = DISPPLANE_GAMMA_ENABLE;
  3973. if (pipe == 0)
  3974. dspcntr &= ~DISPPLANE_SEL_PIPE_MASK;
  3975. else
  3976. dspcntr |= DISPPLANE_SEL_PIPE_B;
  3977. if (intel_crtc->config.has_dp_encoder)
  3978. intel_dp_set_m_n(intel_crtc);
  3979. intel_set_pipe_timings(intel_crtc);
  3980. /* pipesrc and dspsize control the size that is scaled from,
  3981. * which should always be the user's requested size.
  3982. */
  3983. I915_WRITE(DSPSIZE(plane),
  3984. ((intel_crtc->config.pipe_src_h - 1) << 16) |
  3985. (intel_crtc->config.pipe_src_w - 1));
  3986. I915_WRITE(DSPPOS(plane), 0);
  3987. i9xx_set_pipeconf(intel_crtc);
  3988. I915_WRITE(DSPCNTR(plane), dspcntr);
  3989. POSTING_READ(DSPCNTR(plane));
  3990. dev_priv->display.update_primary_plane(crtc, crtc->primary->fb,
  3991. crtc->x, crtc->y);
  3992. intel_crtc->active = true;
  3993. if (!IS_GEN2(dev))
  3994. intel_set_cpu_fifo_underrun_reporting(dev, pipe, true);
  3995. for_each_encoder_on_crtc(dev, crtc, encoder)
  3996. if (encoder->pre_enable)
  3997. encoder->pre_enable(encoder);
  3998. i9xx_enable_pll(intel_crtc);
  3999. i9xx_pfit_enable(intel_crtc);
  4000. intel_crtc_load_lut(crtc);
  4001. intel_update_watermarks(crtc);
  4002. intel_enable_pipe(intel_crtc);
  4003. for_each_encoder_on_crtc(dev, crtc, encoder)
  4004. encoder->enable(encoder);
  4005. intel_crtc_enable_planes(crtc);
  4006. /*
  4007. * Gen2 reports pipe underruns whenever all planes are disabled.
  4008. * So don't enable underrun reporting before at least some planes
  4009. * are enabled.
  4010. * FIXME: Need to fix the logic to work when we turn off all planes
  4011. * but leave the pipe running.
  4012. */
  4013. if (IS_GEN2(dev))
  4014. intel_set_cpu_fifo_underrun_reporting(dev, pipe, true);
  4015. /* Underruns don't raise interrupts, so check manually. */
  4016. i9xx_check_fifo_underruns(dev);
  4017. }
  4018. static void i9xx_pfit_disable(struct intel_crtc *crtc)
  4019. {
  4020. struct drm_device *dev = crtc->base.dev;
  4021. struct drm_i915_private *dev_priv = dev->dev_private;
  4022. if (!crtc->config.gmch_pfit.control)
  4023. return;
  4024. assert_pipe_disabled(dev_priv, crtc->pipe);
  4025. DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n",
  4026. I915_READ(PFIT_CONTROL));
  4027. I915_WRITE(PFIT_CONTROL, 0);
  4028. }
  4029. static void i9xx_crtc_disable(struct drm_crtc *crtc)
  4030. {
  4031. struct drm_device *dev = crtc->dev;
  4032. struct drm_i915_private *dev_priv = dev->dev_private;
  4033. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4034. struct intel_encoder *encoder;
  4035. int pipe = intel_crtc->pipe;
  4036. if (!intel_crtc->active)
  4037. return;
  4038. /*
  4039. * Gen2 reports pipe underruns whenever all planes are disabled.
  4040. * So diasble underrun reporting before all the planes get disabled.
  4041. * FIXME: Need to fix the logic to work when we turn off all planes
  4042. * but leave the pipe running.
  4043. */
  4044. if (IS_GEN2(dev))
  4045. intel_set_cpu_fifo_underrun_reporting(dev, pipe, false);
  4046. intel_crtc_disable_planes(crtc);
  4047. for_each_encoder_on_crtc(dev, crtc, encoder)
  4048. encoder->disable(encoder);
  4049. /*
  4050. * On gen2 planes are double buffered but the pipe isn't, so we must
  4051. * wait for planes to fully turn off before disabling the pipe.
  4052. */
  4053. if (IS_GEN2(dev))
  4054. intel_wait_for_vblank(dev, pipe);
  4055. intel_disable_pipe(dev_priv, pipe);
  4056. i9xx_pfit_disable(intel_crtc);
  4057. for_each_encoder_on_crtc(dev, crtc, encoder)
  4058. if (encoder->post_disable)
  4059. encoder->post_disable(encoder);
  4060. if (!intel_pipe_has_type(crtc, INTEL_OUTPUT_DSI)) {
  4061. if (IS_CHERRYVIEW(dev))
  4062. chv_disable_pll(dev_priv, pipe);
  4063. else if (IS_VALLEYVIEW(dev))
  4064. vlv_disable_pll(dev_priv, pipe);
  4065. else
  4066. i9xx_disable_pll(dev_priv, pipe);
  4067. }
  4068. if (!IS_GEN2(dev))
  4069. intel_set_cpu_fifo_underrun_reporting(dev, pipe, false);
  4070. intel_crtc->active = false;
  4071. intel_update_watermarks(crtc);
  4072. mutex_lock(&dev->struct_mutex);
  4073. intel_update_fbc(dev);
  4074. mutex_unlock(&dev->struct_mutex);
  4075. }
  4076. static void i9xx_crtc_off(struct drm_crtc *crtc)
  4077. {
  4078. }
  4079. static void intel_crtc_update_sarea(struct drm_crtc *crtc,
  4080. bool enabled)
  4081. {
  4082. struct drm_device *dev = crtc->dev;
  4083. struct drm_i915_master_private *master_priv;
  4084. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4085. int pipe = intel_crtc->pipe;
  4086. if (!dev->primary->master)
  4087. return;
  4088. master_priv = dev->primary->master->driver_priv;
  4089. if (!master_priv->sarea_priv)
  4090. return;
  4091. switch (pipe) {
  4092. case 0:
  4093. master_priv->sarea_priv->pipeA_w = enabled ? crtc->mode.hdisplay : 0;
  4094. master_priv->sarea_priv->pipeA_h = enabled ? crtc->mode.vdisplay : 0;
  4095. break;
  4096. case 1:
  4097. master_priv->sarea_priv->pipeB_w = enabled ? crtc->mode.hdisplay : 0;
  4098. master_priv->sarea_priv->pipeB_h = enabled ? crtc->mode.vdisplay : 0;
  4099. break;
  4100. default:
  4101. DRM_ERROR("Can't update pipe %c in SAREA\n", pipe_name(pipe));
  4102. break;
  4103. }
  4104. }
  4105. /**
  4106. * Sets the power management mode of the pipe and plane.
  4107. */
  4108. void intel_crtc_update_dpms(struct drm_crtc *crtc)
  4109. {
  4110. struct drm_device *dev = crtc->dev;
  4111. struct drm_i915_private *dev_priv = dev->dev_private;
  4112. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4113. struct intel_encoder *intel_encoder;
  4114. enum intel_display_power_domain domain;
  4115. unsigned long domains;
  4116. bool enable = false;
  4117. for_each_encoder_on_crtc(dev, crtc, intel_encoder)
  4118. enable |= intel_encoder->connectors_active;
  4119. if (enable) {
  4120. if (!intel_crtc->active) {
  4121. /*
  4122. * FIXME: DDI plls and relevant code isn't converted
  4123. * yet, so do runtime PM for DPMS only for all other
  4124. * platforms for now.
  4125. */
  4126. if (!HAS_DDI(dev)) {
  4127. domains = get_crtc_power_domains(crtc);
  4128. for_each_power_domain(domain, domains)
  4129. intel_display_power_get(dev_priv, domain);
  4130. intel_crtc->enabled_power_domains = domains;
  4131. }
  4132. dev_priv->display.crtc_enable(crtc);
  4133. }
  4134. } else {
  4135. if (intel_crtc->active) {
  4136. dev_priv->display.crtc_disable(crtc);
  4137. if (!HAS_DDI(dev)) {
  4138. domains = intel_crtc->enabled_power_domains;
  4139. for_each_power_domain(domain, domains)
  4140. intel_display_power_put(dev_priv, domain);
  4141. intel_crtc->enabled_power_domains = 0;
  4142. }
  4143. }
  4144. }
  4145. intel_crtc_update_sarea(crtc, enable);
  4146. }
  4147. static void intel_crtc_disable(struct drm_crtc *crtc)
  4148. {
  4149. struct drm_device *dev = crtc->dev;
  4150. struct drm_connector *connector;
  4151. struct drm_i915_private *dev_priv = dev->dev_private;
  4152. struct drm_i915_gem_object *old_obj;
  4153. enum pipe pipe = to_intel_crtc(crtc)->pipe;
  4154. /* crtc should still be enabled when we disable it. */
  4155. WARN_ON(!crtc->enabled);
  4156. dev_priv->display.crtc_disable(crtc);
  4157. intel_crtc_update_sarea(crtc, false);
  4158. dev_priv->display.off(crtc);
  4159. assert_plane_disabled(dev->dev_private, to_intel_crtc(crtc)->plane);
  4160. assert_cursor_disabled(dev_priv, pipe);
  4161. assert_pipe_disabled(dev->dev_private, pipe);
  4162. if (crtc->primary->fb) {
  4163. old_obj = to_intel_framebuffer(crtc->primary->fb)->obj;
  4164. mutex_lock(&dev->struct_mutex);
  4165. intel_unpin_fb_obj(old_obj);
  4166. i915_gem_track_fb(old_obj, NULL,
  4167. INTEL_FRONTBUFFER_PRIMARY(pipe));
  4168. mutex_unlock(&dev->struct_mutex);
  4169. crtc->primary->fb = NULL;
  4170. }
  4171. /* Update computed state. */
  4172. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  4173. if (!connector->encoder || !connector->encoder->crtc)
  4174. continue;
  4175. if (connector->encoder->crtc != crtc)
  4176. continue;
  4177. connector->dpms = DRM_MODE_DPMS_OFF;
  4178. to_intel_encoder(connector->encoder)->connectors_active = false;
  4179. }
  4180. }
  4181. void intel_encoder_destroy(struct drm_encoder *encoder)
  4182. {
  4183. struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
  4184. drm_encoder_cleanup(encoder);
  4185. kfree(intel_encoder);
  4186. }
  4187. /* Simple dpms helper for encoders with just one connector, no cloning and only
  4188. * one kind of off state. It clamps all !ON modes to fully OFF and changes the
  4189. * state of the entire output pipe. */
  4190. static void intel_encoder_dpms(struct intel_encoder *encoder, int mode)
  4191. {
  4192. if (mode == DRM_MODE_DPMS_ON) {
  4193. encoder->connectors_active = true;
  4194. intel_crtc_update_dpms(encoder->base.crtc);
  4195. } else {
  4196. encoder->connectors_active = false;
  4197. intel_crtc_update_dpms(encoder->base.crtc);
  4198. }
  4199. }
  4200. /* Cross check the actual hw state with our own modeset state tracking (and it's
  4201. * internal consistency). */
  4202. static void intel_connector_check_state(struct intel_connector *connector)
  4203. {
  4204. if (connector->get_hw_state(connector)) {
  4205. struct intel_encoder *encoder = connector->encoder;
  4206. struct drm_crtc *crtc;
  4207. bool encoder_enabled;
  4208. enum pipe pipe;
  4209. DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
  4210. connector->base.base.id,
  4211. connector->base.name);
  4212. WARN(connector->base.dpms == DRM_MODE_DPMS_OFF,
  4213. "wrong connector dpms state\n");
  4214. WARN(connector->base.encoder != &encoder->base,
  4215. "active connector not linked to encoder\n");
  4216. WARN(!encoder->connectors_active,
  4217. "encoder->connectors_active not set\n");
  4218. encoder_enabled = encoder->get_hw_state(encoder, &pipe);
  4219. WARN(!encoder_enabled, "encoder not enabled\n");
  4220. if (WARN_ON(!encoder->base.crtc))
  4221. return;
  4222. crtc = encoder->base.crtc;
  4223. WARN(!crtc->enabled, "crtc not enabled\n");
  4224. WARN(!to_intel_crtc(crtc)->active, "crtc not active\n");
  4225. WARN(pipe != to_intel_crtc(crtc)->pipe,
  4226. "encoder active on the wrong pipe\n");
  4227. }
  4228. }
  4229. /* Even simpler default implementation, if there's really no special case to
  4230. * consider. */
  4231. void intel_connector_dpms(struct drm_connector *connector, int mode)
  4232. {
  4233. /* All the simple cases only support two dpms states. */
  4234. if (mode != DRM_MODE_DPMS_ON)
  4235. mode = DRM_MODE_DPMS_OFF;
  4236. if (mode == connector->dpms)
  4237. return;
  4238. connector->dpms = mode;
  4239. /* Only need to change hw state when actually enabled */
  4240. if (connector->encoder)
  4241. intel_encoder_dpms(to_intel_encoder(connector->encoder), mode);
  4242. intel_modeset_check_state(connector->dev);
  4243. }
  4244. /* Simple connector->get_hw_state implementation for encoders that support only
  4245. * one connector and no cloning and hence the encoder state determines the state
  4246. * of the connector. */
  4247. bool intel_connector_get_hw_state(struct intel_connector *connector)
  4248. {
  4249. enum pipe pipe = 0;
  4250. struct intel_encoder *encoder = connector->encoder;
  4251. return encoder->get_hw_state(encoder, &pipe);
  4252. }
  4253. static bool ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe,
  4254. struct intel_crtc_config *pipe_config)
  4255. {
  4256. struct drm_i915_private *dev_priv = dev->dev_private;
  4257. struct intel_crtc *pipe_B_crtc =
  4258. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_B]);
  4259. DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
  4260. pipe_name(pipe), pipe_config->fdi_lanes);
  4261. if (pipe_config->fdi_lanes > 4) {
  4262. DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
  4263. pipe_name(pipe), pipe_config->fdi_lanes);
  4264. return false;
  4265. }
  4266. if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
  4267. if (pipe_config->fdi_lanes > 2) {
  4268. DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
  4269. pipe_config->fdi_lanes);
  4270. return false;
  4271. } else {
  4272. return true;
  4273. }
  4274. }
  4275. if (INTEL_INFO(dev)->num_pipes == 2)
  4276. return true;
  4277. /* Ivybridge 3 pipe is really complicated */
  4278. switch (pipe) {
  4279. case PIPE_A:
  4280. return true;
  4281. case PIPE_B:
  4282. if (dev_priv->pipe_to_crtc_mapping[PIPE_C]->enabled &&
  4283. pipe_config->fdi_lanes > 2) {
  4284. DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
  4285. pipe_name(pipe), pipe_config->fdi_lanes);
  4286. return false;
  4287. }
  4288. return true;
  4289. case PIPE_C:
  4290. if (!pipe_has_enabled_pch(pipe_B_crtc) ||
  4291. pipe_B_crtc->config.fdi_lanes <= 2) {
  4292. if (pipe_config->fdi_lanes > 2) {
  4293. DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
  4294. pipe_name(pipe), pipe_config->fdi_lanes);
  4295. return false;
  4296. }
  4297. } else {
  4298. DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
  4299. return false;
  4300. }
  4301. return true;
  4302. default:
  4303. BUG();
  4304. }
  4305. }
  4306. #define RETRY 1
  4307. static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc,
  4308. struct intel_crtc_config *pipe_config)
  4309. {
  4310. struct drm_device *dev = intel_crtc->base.dev;
  4311. struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
  4312. int lane, link_bw, fdi_dotclock;
  4313. bool setup_ok, needs_recompute = false;
  4314. retry:
  4315. /* FDI is a binary signal running at ~2.7GHz, encoding
  4316. * each output octet as 10 bits. The actual frequency
  4317. * is stored as a divider into a 100MHz clock, and the
  4318. * mode pixel clock is stored in units of 1KHz.
  4319. * Hence the bw of each lane in terms of the mode signal
  4320. * is:
  4321. */
  4322. link_bw = intel_fdi_link_freq(dev) * MHz(100)/KHz(1)/10;
  4323. fdi_dotclock = adjusted_mode->crtc_clock;
  4324. lane = ironlake_get_lanes_required(fdi_dotclock, link_bw,
  4325. pipe_config->pipe_bpp);
  4326. pipe_config->fdi_lanes = lane;
  4327. intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock,
  4328. link_bw, &pipe_config->fdi_m_n);
  4329. setup_ok = ironlake_check_fdi_lanes(intel_crtc->base.dev,
  4330. intel_crtc->pipe, pipe_config);
  4331. if (!setup_ok && pipe_config->pipe_bpp > 6*3) {
  4332. pipe_config->pipe_bpp -= 2*3;
  4333. DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
  4334. pipe_config->pipe_bpp);
  4335. needs_recompute = true;
  4336. pipe_config->bw_constrained = true;
  4337. goto retry;
  4338. }
  4339. if (needs_recompute)
  4340. return RETRY;
  4341. return setup_ok ? 0 : -EINVAL;
  4342. }
  4343. static void hsw_compute_ips_config(struct intel_crtc *crtc,
  4344. struct intel_crtc_config *pipe_config)
  4345. {
  4346. pipe_config->ips_enabled = i915.enable_ips &&
  4347. hsw_crtc_supports_ips(crtc) &&
  4348. pipe_config->pipe_bpp <= 24;
  4349. }
  4350. static int intel_crtc_compute_config(struct intel_crtc *crtc,
  4351. struct intel_crtc_config *pipe_config)
  4352. {
  4353. struct drm_device *dev = crtc->base.dev;
  4354. struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
  4355. /* FIXME should check pixel clock limits on all platforms */
  4356. if (INTEL_INFO(dev)->gen < 4) {
  4357. struct drm_i915_private *dev_priv = dev->dev_private;
  4358. int clock_limit =
  4359. dev_priv->display.get_display_clock_speed(dev);
  4360. /*
  4361. * Enable pixel doubling when the dot clock
  4362. * is > 90% of the (display) core speed.
  4363. *
  4364. * GDG double wide on either pipe,
  4365. * otherwise pipe A only.
  4366. */
  4367. if ((crtc->pipe == PIPE_A || IS_I915G(dev)) &&
  4368. adjusted_mode->crtc_clock > clock_limit * 9 / 10) {
  4369. clock_limit *= 2;
  4370. pipe_config->double_wide = true;
  4371. }
  4372. if (adjusted_mode->crtc_clock > clock_limit * 9 / 10)
  4373. return -EINVAL;
  4374. }
  4375. /*
  4376. * Pipe horizontal size must be even in:
  4377. * - DVO ganged mode
  4378. * - LVDS dual channel mode
  4379. * - Double wide pipe
  4380. */
  4381. if ((intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) &&
  4382. intel_is_dual_link_lvds(dev)) || pipe_config->double_wide)
  4383. pipe_config->pipe_src_w &= ~1;
  4384. /* Cantiga+ cannot handle modes with a hsync front porch of 0.
  4385. * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
  4386. */
  4387. if ((INTEL_INFO(dev)->gen > 4 || IS_G4X(dev)) &&
  4388. adjusted_mode->hsync_start == adjusted_mode->hdisplay)
  4389. return -EINVAL;
  4390. if ((IS_G4X(dev) || IS_VALLEYVIEW(dev)) && pipe_config->pipe_bpp > 10*3) {
  4391. pipe_config->pipe_bpp = 10*3; /* 12bpc is gen5+ */
  4392. } else if (INTEL_INFO(dev)->gen <= 4 && pipe_config->pipe_bpp > 8*3) {
  4393. /* only a 8bpc pipe, with 6bpc dither through the panel fitter
  4394. * for lvds. */
  4395. pipe_config->pipe_bpp = 8*3;
  4396. }
  4397. if (HAS_IPS(dev))
  4398. hsw_compute_ips_config(crtc, pipe_config);
  4399. /* XXX: PCH clock sharing is done in ->mode_set, so make sure the old
  4400. * clock survives for now. */
  4401. if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
  4402. pipe_config->shared_dpll = crtc->config.shared_dpll;
  4403. if (pipe_config->has_pch_encoder)
  4404. return ironlake_fdi_compute_config(crtc, pipe_config);
  4405. return 0;
  4406. }
  4407. static int valleyview_get_display_clock_speed(struct drm_device *dev)
  4408. {
  4409. return 400000; /* FIXME */
  4410. }
  4411. static int i945_get_display_clock_speed(struct drm_device *dev)
  4412. {
  4413. return 400000;
  4414. }
  4415. static int i915_get_display_clock_speed(struct drm_device *dev)
  4416. {
  4417. return 333000;
  4418. }
  4419. static int i9xx_misc_get_display_clock_speed(struct drm_device *dev)
  4420. {
  4421. return 200000;
  4422. }
  4423. static int pnv_get_display_clock_speed(struct drm_device *dev)
  4424. {
  4425. u16 gcfgc = 0;
  4426. pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
  4427. switch (gcfgc & GC_DISPLAY_CLOCK_MASK) {
  4428. case GC_DISPLAY_CLOCK_267_MHZ_PNV:
  4429. return 267000;
  4430. case GC_DISPLAY_CLOCK_333_MHZ_PNV:
  4431. return 333000;
  4432. case GC_DISPLAY_CLOCK_444_MHZ_PNV:
  4433. return 444000;
  4434. case GC_DISPLAY_CLOCK_200_MHZ_PNV:
  4435. return 200000;
  4436. default:
  4437. DRM_ERROR("Unknown pnv display core clock 0x%04x\n", gcfgc);
  4438. case GC_DISPLAY_CLOCK_133_MHZ_PNV:
  4439. return 133000;
  4440. case GC_DISPLAY_CLOCK_167_MHZ_PNV:
  4441. return 167000;
  4442. }
  4443. }
  4444. static int i915gm_get_display_clock_speed(struct drm_device *dev)
  4445. {
  4446. u16 gcfgc = 0;
  4447. pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
  4448. if (gcfgc & GC_LOW_FREQUENCY_ENABLE)
  4449. return 133000;
  4450. else {
  4451. switch (gcfgc & GC_DISPLAY_CLOCK_MASK) {
  4452. case GC_DISPLAY_CLOCK_333_MHZ:
  4453. return 333000;
  4454. default:
  4455. case GC_DISPLAY_CLOCK_190_200_MHZ:
  4456. return 190000;
  4457. }
  4458. }
  4459. }
  4460. static int i865_get_display_clock_speed(struct drm_device *dev)
  4461. {
  4462. return 266000;
  4463. }
  4464. static int i855_get_display_clock_speed(struct drm_device *dev)
  4465. {
  4466. u16 hpllcc = 0;
  4467. /* Assume that the hardware is in the high speed state. This
  4468. * should be the default.
  4469. */
  4470. switch (hpllcc & GC_CLOCK_CONTROL_MASK) {
  4471. case GC_CLOCK_133_200:
  4472. case GC_CLOCK_100_200:
  4473. return 200000;
  4474. case GC_CLOCK_166_250:
  4475. return 250000;
  4476. case GC_CLOCK_100_133:
  4477. return 133000;
  4478. }
  4479. /* Shouldn't happen */
  4480. return 0;
  4481. }
  4482. static int i830_get_display_clock_speed(struct drm_device *dev)
  4483. {
  4484. return 133000;
  4485. }
  4486. static void
  4487. intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den)
  4488. {
  4489. while (*num > DATA_LINK_M_N_MASK ||
  4490. *den > DATA_LINK_M_N_MASK) {
  4491. *num >>= 1;
  4492. *den >>= 1;
  4493. }
  4494. }
  4495. static void compute_m_n(unsigned int m, unsigned int n,
  4496. uint32_t *ret_m, uint32_t *ret_n)
  4497. {
  4498. *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
  4499. *ret_m = div_u64((uint64_t) m * *ret_n, n);
  4500. intel_reduce_m_n_ratio(ret_m, ret_n);
  4501. }
  4502. void
  4503. intel_link_compute_m_n(int bits_per_pixel, int nlanes,
  4504. int pixel_clock, int link_clock,
  4505. struct intel_link_m_n *m_n)
  4506. {
  4507. m_n->tu = 64;
  4508. compute_m_n(bits_per_pixel * pixel_clock,
  4509. link_clock * nlanes * 8,
  4510. &m_n->gmch_m, &m_n->gmch_n);
  4511. compute_m_n(pixel_clock, link_clock,
  4512. &m_n->link_m, &m_n->link_n);
  4513. }
  4514. static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
  4515. {
  4516. if (i915.panel_use_ssc >= 0)
  4517. return i915.panel_use_ssc != 0;
  4518. return dev_priv->vbt.lvds_use_ssc
  4519. && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE);
  4520. }
  4521. static int i9xx_get_refclk(struct drm_crtc *crtc, int num_connectors)
  4522. {
  4523. struct drm_device *dev = crtc->dev;
  4524. struct drm_i915_private *dev_priv = dev->dev_private;
  4525. int refclk;
  4526. if (IS_VALLEYVIEW(dev)) {
  4527. refclk = 100000;
  4528. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
  4529. intel_panel_use_ssc(dev_priv) && num_connectors < 2) {
  4530. refclk = dev_priv->vbt.lvds_ssc_freq;
  4531. DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
  4532. } else if (!IS_GEN2(dev)) {
  4533. refclk = 96000;
  4534. } else {
  4535. refclk = 48000;
  4536. }
  4537. return refclk;
  4538. }
  4539. static uint32_t pnv_dpll_compute_fp(struct dpll *dpll)
  4540. {
  4541. return (1 << dpll->n) << 16 | dpll->m2;
  4542. }
  4543. static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll)
  4544. {
  4545. return dpll->n << 16 | dpll->m1 << 8 | dpll->m2;
  4546. }
  4547. static void i9xx_update_pll_dividers(struct intel_crtc *crtc,
  4548. intel_clock_t *reduced_clock)
  4549. {
  4550. struct drm_device *dev = crtc->base.dev;
  4551. u32 fp, fp2 = 0;
  4552. if (IS_PINEVIEW(dev)) {
  4553. fp = pnv_dpll_compute_fp(&crtc->config.dpll);
  4554. if (reduced_clock)
  4555. fp2 = pnv_dpll_compute_fp(reduced_clock);
  4556. } else {
  4557. fp = i9xx_dpll_compute_fp(&crtc->config.dpll);
  4558. if (reduced_clock)
  4559. fp2 = i9xx_dpll_compute_fp(reduced_clock);
  4560. }
  4561. crtc->config.dpll_hw_state.fp0 = fp;
  4562. crtc->lowfreq_avail = false;
  4563. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) &&
  4564. reduced_clock && i915.powersave) {
  4565. crtc->config.dpll_hw_state.fp1 = fp2;
  4566. crtc->lowfreq_avail = true;
  4567. } else {
  4568. crtc->config.dpll_hw_state.fp1 = fp;
  4569. }
  4570. }
  4571. static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe
  4572. pipe)
  4573. {
  4574. u32 reg_val;
  4575. /*
  4576. * PLLB opamp always calibrates to max value of 0x3f, force enable it
  4577. * and set it to a reasonable value instead.
  4578. */
  4579. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
  4580. reg_val &= 0xffffff00;
  4581. reg_val |= 0x00000030;
  4582. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
  4583. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
  4584. reg_val &= 0x8cffffff;
  4585. reg_val = 0x8c000000;
  4586. vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
  4587. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
  4588. reg_val &= 0xffffff00;
  4589. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
  4590. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
  4591. reg_val &= 0x00ffffff;
  4592. reg_val |= 0xb0000000;
  4593. vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
  4594. }
  4595. static void intel_pch_transcoder_set_m_n(struct intel_crtc *crtc,
  4596. struct intel_link_m_n *m_n)
  4597. {
  4598. struct drm_device *dev = crtc->base.dev;
  4599. struct drm_i915_private *dev_priv = dev->dev_private;
  4600. int pipe = crtc->pipe;
  4601. I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
  4602. I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n);
  4603. I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m);
  4604. I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n);
  4605. }
  4606. static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc,
  4607. struct intel_link_m_n *m_n)
  4608. {
  4609. struct drm_device *dev = crtc->base.dev;
  4610. struct drm_i915_private *dev_priv = dev->dev_private;
  4611. int pipe = crtc->pipe;
  4612. enum transcoder transcoder = crtc->config.cpu_transcoder;
  4613. if (INTEL_INFO(dev)->gen >= 5) {
  4614. I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m);
  4615. I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n);
  4616. I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m);
  4617. I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n);
  4618. } else {
  4619. I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
  4620. I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n);
  4621. I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m);
  4622. I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n);
  4623. }
  4624. }
  4625. static void intel_dp_set_m_n(struct intel_crtc *crtc)
  4626. {
  4627. if (crtc->config.has_pch_encoder)
  4628. intel_pch_transcoder_set_m_n(crtc, &crtc->config.dp_m_n);
  4629. else
  4630. intel_cpu_transcoder_set_m_n(crtc, &crtc->config.dp_m_n);
  4631. }
  4632. static void vlv_update_pll(struct intel_crtc *crtc)
  4633. {
  4634. u32 dpll, dpll_md;
  4635. /*
  4636. * Enable DPIO clock input. We should never disable the reference
  4637. * clock for pipe B, since VGA hotplug / manual detection depends
  4638. * on it.
  4639. */
  4640. dpll = DPLL_EXT_BUFFER_ENABLE_VLV | DPLL_REFA_CLK_ENABLE_VLV |
  4641. DPLL_VGA_MODE_DIS | DPLL_INTEGRATED_CLOCK_VLV;
  4642. /* We should never disable this, set it here for state tracking */
  4643. if (crtc->pipe == PIPE_B)
  4644. dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
  4645. dpll |= DPLL_VCO_ENABLE;
  4646. crtc->config.dpll_hw_state.dpll = dpll;
  4647. dpll_md = (crtc->config.pixel_multiplier - 1)
  4648. << DPLL_MD_UDI_MULTIPLIER_SHIFT;
  4649. crtc->config.dpll_hw_state.dpll_md = dpll_md;
  4650. }
  4651. static void vlv_prepare_pll(struct intel_crtc *crtc)
  4652. {
  4653. struct drm_device *dev = crtc->base.dev;
  4654. struct drm_i915_private *dev_priv = dev->dev_private;
  4655. int pipe = crtc->pipe;
  4656. u32 mdiv;
  4657. u32 bestn, bestm1, bestm2, bestp1, bestp2;
  4658. u32 coreclk, reg_val;
  4659. mutex_lock(&dev_priv->dpio_lock);
  4660. bestn = crtc->config.dpll.n;
  4661. bestm1 = crtc->config.dpll.m1;
  4662. bestm2 = crtc->config.dpll.m2;
  4663. bestp1 = crtc->config.dpll.p1;
  4664. bestp2 = crtc->config.dpll.p2;
  4665. /* See eDP HDMI DPIO driver vbios notes doc */
  4666. /* PLL B needs special handling */
  4667. if (pipe == PIPE_B)
  4668. vlv_pllb_recal_opamp(dev_priv, pipe);
  4669. /* Set up Tx target for periodic Rcomp update */
  4670. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f);
  4671. /* Disable target IRef on PLL */
  4672. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe));
  4673. reg_val &= 0x00ffffff;
  4674. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val);
  4675. /* Disable fast lock */
  4676. vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610);
  4677. /* Set idtafcrecal before PLL is enabled */
  4678. mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK));
  4679. mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT));
  4680. mdiv |= ((bestn << DPIO_N_SHIFT));
  4681. mdiv |= (1 << DPIO_K_SHIFT);
  4682. /*
  4683. * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
  4684. * but we don't support that).
  4685. * Note: don't use the DAC post divider as it seems unstable.
  4686. */
  4687. mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT);
  4688. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
  4689. mdiv |= DPIO_ENABLE_CALIBRATION;
  4690. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
  4691. /* Set HBR and RBR LPF coefficients */
  4692. if (crtc->config.port_clock == 162000 ||
  4693. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_ANALOG) ||
  4694. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_HDMI))
  4695. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
  4696. 0x009f0003);
  4697. else
  4698. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
  4699. 0x00d0000f);
  4700. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_EDP) ||
  4701. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DISPLAYPORT)) {
  4702. /* Use SSC source */
  4703. if (pipe == PIPE_A)
  4704. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
  4705. 0x0df40000);
  4706. else
  4707. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
  4708. 0x0df70000);
  4709. } else { /* HDMI or VGA */
  4710. /* Use bend source */
  4711. if (pipe == PIPE_A)
  4712. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
  4713. 0x0df70000);
  4714. else
  4715. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
  4716. 0x0df40000);
  4717. }
  4718. coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe));
  4719. coreclk = (coreclk & 0x0000ff00) | 0x01c00000;
  4720. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DISPLAYPORT) ||
  4721. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_EDP))
  4722. coreclk |= 0x01000000;
  4723. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk);
  4724. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000);
  4725. mutex_unlock(&dev_priv->dpio_lock);
  4726. }
  4727. static void chv_update_pll(struct intel_crtc *crtc)
  4728. {
  4729. struct drm_device *dev = crtc->base.dev;
  4730. struct drm_i915_private *dev_priv = dev->dev_private;
  4731. int pipe = crtc->pipe;
  4732. int dpll_reg = DPLL(crtc->pipe);
  4733. enum dpio_channel port = vlv_pipe_to_channel(pipe);
  4734. u32 loopfilter, intcoeff;
  4735. u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac;
  4736. int refclk;
  4737. crtc->config.dpll_hw_state.dpll = DPLL_SSC_REF_CLOCK_CHV |
  4738. DPLL_REFA_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS |
  4739. DPLL_VCO_ENABLE;
  4740. if (pipe != PIPE_A)
  4741. crtc->config.dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
  4742. crtc->config.dpll_hw_state.dpll_md =
  4743. (crtc->config.pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
  4744. bestn = crtc->config.dpll.n;
  4745. bestm2_frac = crtc->config.dpll.m2 & 0x3fffff;
  4746. bestm1 = crtc->config.dpll.m1;
  4747. bestm2 = crtc->config.dpll.m2 >> 22;
  4748. bestp1 = crtc->config.dpll.p1;
  4749. bestp2 = crtc->config.dpll.p2;
  4750. /*
  4751. * Enable Refclk and SSC
  4752. */
  4753. I915_WRITE(dpll_reg,
  4754. crtc->config.dpll_hw_state.dpll & ~DPLL_VCO_ENABLE);
  4755. mutex_lock(&dev_priv->dpio_lock);
  4756. /* p1 and p2 divider */
  4757. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port),
  4758. 5 << DPIO_CHV_S1_DIV_SHIFT |
  4759. bestp1 << DPIO_CHV_P1_DIV_SHIFT |
  4760. bestp2 << DPIO_CHV_P2_DIV_SHIFT |
  4761. 1 << DPIO_CHV_K_DIV_SHIFT);
  4762. /* Feedback post-divider - m2 */
  4763. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2);
  4764. /* Feedback refclk divider - n and m1 */
  4765. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port),
  4766. DPIO_CHV_M1_DIV_BY_2 |
  4767. 1 << DPIO_CHV_N_DIV_SHIFT);
  4768. /* M2 fraction division */
  4769. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac);
  4770. /* M2 fraction division enable */
  4771. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port),
  4772. DPIO_CHV_FRAC_DIV_EN |
  4773. (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT));
  4774. /* Loop filter */
  4775. refclk = i9xx_get_refclk(&crtc->base, 0);
  4776. loopfilter = 5 << DPIO_CHV_PROP_COEFF_SHIFT |
  4777. 2 << DPIO_CHV_GAIN_CTRL_SHIFT;
  4778. if (refclk == 100000)
  4779. intcoeff = 11;
  4780. else if (refclk == 38400)
  4781. intcoeff = 10;
  4782. else
  4783. intcoeff = 9;
  4784. loopfilter |= intcoeff << DPIO_CHV_INT_COEFF_SHIFT;
  4785. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter);
  4786. /* AFC Recal */
  4787. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port),
  4788. vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) |
  4789. DPIO_AFC_RECAL);
  4790. mutex_unlock(&dev_priv->dpio_lock);
  4791. }
  4792. static void i9xx_update_pll(struct intel_crtc *crtc,
  4793. intel_clock_t *reduced_clock,
  4794. int num_connectors)
  4795. {
  4796. struct drm_device *dev = crtc->base.dev;
  4797. struct drm_i915_private *dev_priv = dev->dev_private;
  4798. u32 dpll;
  4799. bool is_sdvo;
  4800. struct dpll *clock = &crtc->config.dpll;
  4801. i9xx_update_pll_dividers(crtc, reduced_clock);
  4802. is_sdvo = intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_SDVO) ||
  4803. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_HDMI);
  4804. dpll = DPLL_VGA_MODE_DIS;
  4805. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS))
  4806. dpll |= DPLLB_MODE_LVDS;
  4807. else
  4808. dpll |= DPLLB_MODE_DAC_SERIAL;
  4809. if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) {
  4810. dpll |= (crtc->config.pixel_multiplier - 1)
  4811. << SDVO_MULTIPLIER_SHIFT_HIRES;
  4812. }
  4813. if (is_sdvo)
  4814. dpll |= DPLL_SDVO_HIGH_SPEED;
  4815. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DISPLAYPORT))
  4816. dpll |= DPLL_SDVO_HIGH_SPEED;
  4817. /* compute bitmask from p1 value */
  4818. if (IS_PINEVIEW(dev))
  4819. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
  4820. else {
  4821. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  4822. if (IS_G4X(dev) && reduced_clock)
  4823. dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
  4824. }
  4825. switch (clock->p2) {
  4826. case 5:
  4827. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
  4828. break;
  4829. case 7:
  4830. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
  4831. break;
  4832. case 10:
  4833. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
  4834. break;
  4835. case 14:
  4836. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
  4837. break;
  4838. }
  4839. if (INTEL_INFO(dev)->gen >= 4)
  4840. dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
  4841. if (crtc->config.sdvo_tv_clock)
  4842. dpll |= PLL_REF_INPUT_TVCLKINBC;
  4843. else if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) &&
  4844. intel_panel_use_ssc(dev_priv) && num_connectors < 2)
  4845. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  4846. else
  4847. dpll |= PLL_REF_INPUT_DREFCLK;
  4848. dpll |= DPLL_VCO_ENABLE;
  4849. crtc->config.dpll_hw_state.dpll = dpll;
  4850. if (INTEL_INFO(dev)->gen >= 4) {
  4851. u32 dpll_md = (crtc->config.pixel_multiplier - 1)
  4852. << DPLL_MD_UDI_MULTIPLIER_SHIFT;
  4853. crtc->config.dpll_hw_state.dpll_md = dpll_md;
  4854. }
  4855. }
  4856. static void i8xx_update_pll(struct intel_crtc *crtc,
  4857. intel_clock_t *reduced_clock,
  4858. int num_connectors)
  4859. {
  4860. struct drm_device *dev = crtc->base.dev;
  4861. struct drm_i915_private *dev_priv = dev->dev_private;
  4862. u32 dpll;
  4863. struct dpll *clock = &crtc->config.dpll;
  4864. i9xx_update_pll_dividers(crtc, reduced_clock);
  4865. dpll = DPLL_VGA_MODE_DIS;
  4866. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS)) {
  4867. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  4868. } else {
  4869. if (clock->p1 == 2)
  4870. dpll |= PLL_P1_DIVIDE_BY_TWO;
  4871. else
  4872. dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  4873. if (clock->p2 == 4)
  4874. dpll |= PLL_P2_DIVIDE_BY_4;
  4875. }
  4876. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DVO))
  4877. dpll |= DPLL_DVO_2X_MODE;
  4878. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) &&
  4879. intel_panel_use_ssc(dev_priv) && num_connectors < 2)
  4880. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  4881. else
  4882. dpll |= PLL_REF_INPUT_DREFCLK;
  4883. dpll |= DPLL_VCO_ENABLE;
  4884. crtc->config.dpll_hw_state.dpll = dpll;
  4885. }
  4886. static void intel_set_pipe_timings(struct intel_crtc *intel_crtc)
  4887. {
  4888. struct drm_device *dev = intel_crtc->base.dev;
  4889. struct drm_i915_private *dev_priv = dev->dev_private;
  4890. enum pipe pipe = intel_crtc->pipe;
  4891. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  4892. struct drm_display_mode *adjusted_mode =
  4893. &intel_crtc->config.adjusted_mode;
  4894. uint32_t crtc_vtotal, crtc_vblank_end;
  4895. int vsyncshift = 0;
  4896. /* We need to be careful not to changed the adjusted mode, for otherwise
  4897. * the hw state checker will get angry at the mismatch. */
  4898. crtc_vtotal = adjusted_mode->crtc_vtotal;
  4899. crtc_vblank_end = adjusted_mode->crtc_vblank_end;
  4900. if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
  4901. /* the chip adds 2 halflines automatically */
  4902. crtc_vtotal -= 1;
  4903. crtc_vblank_end -= 1;
  4904. if (intel_pipe_has_type(&intel_crtc->base, INTEL_OUTPUT_SDVO))
  4905. vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2;
  4906. else
  4907. vsyncshift = adjusted_mode->crtc_hsync_start -
  4908. adjusted_mode->crtc_htotal / 2;
  4909. if (vsyncshift < 0)
  4910. vsyncshift += adjusted_mode->crtc_htotal;
  4911. }
  4912. if (INTEL_INFO(dev)->gen > 3)
  4913. I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift);
  4914. I915_WRITE(HTOTAL(cpu_transcoder),
  4915. (adjusted_mode->crtc_hdisplay - 1) |
  4916. ((adjusted_mode->crtc_htotal - 1) << 16));
  4917. I915_WRITE(HBLANK(cpu_transcoder),
  4918. (adjusted_mode->crtc_hblank_start - 1) |
  4919. ((adjusted_mode->crtc_hblank_end - 1) << 16));
  4920. I915_WRITE(HSYNC(cpu_transcoder),
  4921. (adjusted_mode->crtc_hsync_start - 1) |
  4922. ((adjusted_mode->crtc_hsync_end - 1) << 16));
  4923. I915_WRITE(VTOTAL(cpu_transcoder),
  4924. (adjusted_mode->crtc_vdisplay - 1) |
  4925. ((crtc_vtotal - 1) << 16));
  4926. I915_WRITE(VBLANK(cpu_transcoder),
  4927. (adjusted_mode->crtc_vblank_start - 1) |
  4928. ((crtc_vblank_end - 1) << 16));
  4929. I915_WRITE(VSYNC(cpu_transcoder),
  4930. (adjusted_mode->crtc_vsync_start - 1) |
  4931. ((adjusted_mode->crtc_vsync_end - 1) << 16));
  4932. /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
  4933. * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
  4934. * documented on the DDI_FUNC_CTL register description, EDP Input Select
  4935. * bits. */
  4936. if (IS_HASWELL(dev) && cpu_transcoder == TRANSCODER_EDP &&
  4937. (pipe == PIPE_B || pipe == PIPE_C))
  4938. I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder)));
  4939. /* pipesrc controls the size that is scaled from, which should
  4940. * always be the user's requested size.
  4941. */
  4942. I915_WRITE(PIPESRC(pipe),
  4943. ((intel_crtc->config.pipe_src_w - 1) << 16) |
  4944. (intel_crtc->config.pipe_src_h - 1));
  4945. }
  4946. static void intel_get_pipe_timings(struct intel_crtc *crtc,
  4947. struct intel_crtc_config *pipe_config)
  4948. {
  4949. struct drm_device *dev = crtc->base.dev;
  4950. struct drm_i915_private *dev_priv = dev->dev_private;
  4951. enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
  4952. uint32_t tmp;
  4953. tmp = I915_READ(HTOTAL(cpu_transcoder));
  4954. pipe_config->adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1;
  4955. pipe_config->adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1;
  4956. tmp = I915_READ(HBLANK(cpu_transcoder));
  4957. pipe_config->adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1;
  4958. pipe_config->adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1;
  4959. tmp = I915_READ(HSYNC(cpu_transcoder));
  4960. pipe_config->adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1;
  4961. pipe_config->adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1;
  4962. tmp = I915_READ(VTOTAL(cpu_transcoder));
  4963. pipe_config->adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1;
  4964. pipe_config->adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1;
  4965. tmp = I915_READ(VBLANK(cpu_transcoder));
  4966. pipe_config->adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1;
  4967. pipe_config->adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1;
  4968. tmp = I915_READ(VSYNC(cpu_transcoder));
  4969. pipe_config->adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1;
  4970. pipe_config->adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1;
  4971. if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) {
  4972. pipe_config->adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE;
  4973. pipe_config->adjusted_mode.crtc_vtotal += 1;
  4974. pipe_config->adjusted_mode.crtc_vblank_end += 1;
  4975. }
  4976. tmp = I915_READ(PIPESRC(crtc->pipe));
  4977. pipe_config->pipe_src_h = (tmp & 0xffff) + 1;
  4978. pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1;
  4979. pipe_config->requested_mode.vdisplay = pipe_config->pipe_src_h;
  4980. pipe_config->requested_mode.hdisplay = pipe_config->pipe_src_w;
  4981. }
  4982. void intel_mode_from_pipe_config(struct drm_display_mode *mode,
  4983. struct intel_crtc_config *pipe_config)
  4984. {
  4985. mode->hdisplay = pipe_config->adjusted_mode.crtc_hdisplay;
  4986. mode->htotal = pipe_config->adjusted_mode.crtc_htotal;
  4987. mode->hsync_start = pipe_config->adjusted_mode.crtc_hsync_start;
  4988. mode->hsync_end = pipe_config->adjusted_mode.crtc_hsync_end;
  4989. mode->vdisplay = pipe_config->adjusted_mode.crtc_vdisplay;
  4990. mode->vtotal = pipe_config->adjusted_mode.crtc_vtotal;
  4991. mode->vsync_start = pipe_config->adjusted_mode.crtc_vsync_start;
  4992. mode->vsync_end = pipe_config->adjusted_mode.crtc_vsync_end;
  4993. mode->flags = pipe_config->adjusted_mode.flags;
  4994. mode->clock = pipe_config->adjusted_mode.crtc_clock;
  4995. mode->flags |= pipe_config->adjusted_mode.flags;
  4996. }
  4997. static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc)
  4998. {
  4999. struct drm_device *dev = intel_crtc->base.dev;
  5000. struct drm_i915_private *dev_priv = dev->dev_private;
  5001. uint32_t pipeconf;
  5002. pipeconf = 0;
  5003. if (dev_priv->quirks & QUIRK_PIPEA_FORCE &&
  5004. I915_READ(PIPECONF(intel_crtc->pipe)) & PIPECONF_ENABLE)
  5005. pipeconf |= PIPECONF_ENABLE;
  5006. if (intel_crtc->config.double_wide)
  5007. pipeconf |= PIPECONF_DOUBLE_WIDE;
  5008. /* only g4x and later have fancy bpc/dither controls */
  5009. if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) {
  5010. /* Bspec claims that we can't use dithering for 30bpp pipes. */
  5011. if (intel_crtc->config.dither && intel_crtc->config.pipe_bpp != 30)
  5012. pipeconf |= PIPECONF_DITHER_EN |
  5013. PIPECONF_DITHER_TYPE_SP;
  5014. switch (intel_crtc->config.pipe_bpp) {
  5015. case 18:
  5016. pipeconf |= PIPECONF_6BPC;
  5017. break;
  5018. case 24:
  5019. pipeconf |= PIPECONF_8BPC;
  5020. break;
  5021. case 30:
  5022. pipeconf |= PIPECONF_10BPC;
  5023. break;
  5024. default:
  5025. /* Case prevented by intel_choose_pipe_bpp_dither. */
  5026. BUG();
  5027. }
  5028. }
  5029. if (HAS_PIPE_CXSR(dev)) {
  5030. if (intel_crtc->lowfreq_avail) {
  5031. DRM_DEBUG_KMS("enabling CxSR downclocking\n");
  5032. pipeconf |= PIPECONF_CXSR_DOWNCLOCK;
  5033. } else {
  5034. DRM_DEBUG_KMS("disabling CxSR downclocking\n");
  5035. }
  5036. }
  5037. if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
  5038. if (INTEL_INFO(dev)->gen < 4 ||
  5039. intel_pipe_has_type(&intel_crtc->base, INTEL_OUTPUT_SDVO))
  5040. pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
  5041. else
  5042. pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT;
  5043. } else
  5044. pipeconf |= PIPECONF_PROGRESSIVE;
  5045. if (IS_VALLEYVIEW(dev) && intel_crtc->config.limited_color_range)
  5046. pipeconf |= PIPECONF_COLOR_RANGE_SELECT;
  5047. I915_WRITE(PIPECONF(intel_crtc->pipe), pipeconf);
  5048. POSTING_READ(PIPECONF(intel_crtc->pipe));
  5049. }
  5050. static int i9xx_crtc_mode_set(struct drm_crtc *crtc,
  5051. int x, int y,
  5052. struct drm_framebuffer *fb)
  5053. {
  5054. struct drm_device *dev = crtc->dev;
  5055. struct drm_i915_private *dev_priv = dev->dev_private;
  5056. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5057. int refclk, num_connectors = 0;
  5058. intel_clock_t clock, reduced_clock;
  5059. bool ok, has_reduced_clock = false;
  5060. bool is_lvds = false, is_dsi = false;
  5061. struct intel_encoder *encoder;
  5062. const intel_limit_t *limit;
  5063. for_each_encoder_on_crtc(dev, crtc, encoder) {
  5064. switch (encoder->type) {
  5065. case INTEL_OUTPUT_LVDS:
  5066. is_lvds = true;
  5067. break;
  5068. case INTEL_OUTPUT_DSI:
  5069. is_dsi = true;
  5070. break;
  5071. }
  5072. num_connectors++;
  5073. }
  5074. if (is_dsi)
  5075. return 0;
  5076. if (!intel_crtc->config.clock_set) {
  5077. refclk = i9xx_get_refclk(crtc, num_connectors);
  5078. /*
  5079. * Returns a set of divisors for the desired target clock with
  5080. * the given refclk, or FALSE. The returned values represent
  5081. * the clock equation: reflck * (5 * (m1 + 2) + (m2 + 2)) / (n +
  5082. * 2) / p1 / p2.
  5083. */
  5084. limit = intel_limit(crtc, refclk);
  5085. ok = dev_priv->display.find_dpll(limit, crtc,
  5086. intel_crtc->config.port_clock,
  5087. refclk, NULL, &clock);
  5088. if (!ok) {
  5089. DRM_ERROR("Couldn't find PLL settings for mode!\n");
  5090. return -EINVAL;
  5091. }
  5092. if (is_lvds && dev_priv->lvds_downclock_avail) {
  5093. /*
  5094. * Ensure we match the reduced clock's P to the target
  5095. * clock. If the clocks don't match, we can't switch
  5096. * the display clock by using the FP0/FP1. In such case
  5097. * we will disable the LVDS downclock feature.
  5098. */
  5099. has_reduced_clock =
  5100. dev_priv->display.find_dpll(limit, crtc,
  5101. dev_priv->lvds_downclock,
  5102. refclk, &clock,
  5103. &reduced_clock);
  5104. }
  5105. /* Compat-code for transition, will disappear. */
  5106. intel_crtc->config.dpll.n = clock.n;
  5107. intel_crtc->config.dpll.m1 = clock.m1;
  5108. intel_crtc->config.dpll.m2 = clock.m2;
  5109. intel_crtc->config.dpll.p1 = clock.p1;
  5110. intel_crtc->config.dpll.p2 = clock.p2;
  5111. }
  5112. if (IS_GEN2(dev)) {
  5113. i8xx_update_pll(intel_crtc,
  5114. has_reduced_clock ? &reduced_clock : NULL,
  5115. num_connectors);
  5116. } else if (IS_CHERRYVIEW(dev)) {
  5117. chv_update_pll(intel_crtc);
  5118. } else if (IS_VALLEYVIEW(dev)) {
  5119. vlv_update_pll(intel_crtc);
  5120. } else {
  5121. i9xx_update_pll(intel_crtc,
  5122. has_reduced_clock ? &reduced_clock : NULL,
  5123. num_connectors);
  5124. }
  5125. return 0;
  5126. }
  5127. static void i9xx_get_pfit_config(struct intel_crtc *crtc,
  5128. struct intel_crtc_config *pipe_config)
  5129. {
  5130. struct drm_device *dev = crtc->base.dev;
  5131. struct drm_i915_private *dev_priv = dev->dev_private;
  5132. uint32_t tmp;
  5133. if (INTEL_INFO(dev)->gen <= 3 && (IS_I830(dev) || !IS_MOBILE(dev)))
  5134. return;
  5135. tmp = I915_READ(PFIT_CONTROL);
  5136. if (!(tmp & PFIT_ENABLE))
  5137. return;
  5138. /* Check whether the pfit is attached to our pipe. */
  5139. if (INTEL_INFO(dev)->gen < 4) {
  5140. if (crtc->pipe != PIPE_B)
  5141. return;
  5142. } else {
  5143. if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT))
  5144. return;
  5145. }
  5146. pipe_config->gmch_pfit.control = tmp;
  5147. pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS);
  5148. if (INTEL_INFO(dev)->gen < 5)
  5149. pipe_config->gmch_pfit.lvds_border_bits =
  5150. I915_READ(LVDS) & LVDS_BORDER_ENABLE;
  5151. }
  5152. static void vlv_crtc_clock_get(struct intel_crtc *crtc,
  5153. struct intel_crtc_config *pipe_config)
  5154. {
  5155. struct drm_device *dev = crtc->base.dev;
  5156. struct drm_i915_private *dev_priv = dev->dev_private;
  5157. int pipe = pipe_config->cpu_transcoder;
  5158. intel_clock_t clock;
  5159. u32 mdiv;
  5160. int refclk = 100000;
  5161. mutex_lock(&dev_priv->dpio_lock);
  5162. mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe));
  5163. mutex_unlock(&dev_priv->dpio_lock);
  5164. clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7;
  5165. clock.m2 = mdiv & DPIO_M2DIV_MASK;
  5166. clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf;
  5167. clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7;
  5168. clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f;
  5169. vlv_clock(refclk, &clock);
  5170. /* clock.dot is the fast clock */
  5171. pipe_config->port_clock = clock.dot / 5;
  5172. }
  5173. static void i9xx_get_plane_config(struct intel_crtc *crtc,
  5174. struct intel_plane_config *plane_config)
  5175. {
  5176. struct drm_device *dev = crtc->base.dev;
  5177. struct drm_i915_private *dev_priv = dev->dev_private;
  5178. u32 val, base, offset;
  5179. int pipe = crtc->pipe, plane = crtc->plane;
  5180. int fourcc, pixel_format;
  5181. int aligned_height;
  5182. crtc->base.primary->fb = kzalloc(sizeof(struct intel_framebuffer), GFP_KERNEL);
  5183. if (!crtc->base.primary->fb) {
  5184. DRM_DEBUG_KMS("failed to alloc fb\n");
  5185. return;
  5186. }
  5187. val = I915_READ(DSPCNTR(plane));
  5188. if (INTEL_INFO(dev)->gen >= 4)
  5189. if (val & DISPPLANE_TILED)
  5190. plane_config->tiled = true;
  5191. pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
  5192. fourcc = intel_format_to_fourcc(pixel_format);
  5193. crtc->base.primary->fb->pixel_format = fourcc;
  5194. crtc->base.primary->fb->bits_per_pixel =
  5195. drm_format_plane_cpp(fourcc, 0) * 8;
  5196. if (INTEL_INFO(dev)->gen >= 4) {
  5197. if (plane_config->tiled)
  5198. offset = I915_READ(DSPTILEOFF(plane));
  5199. else
  5200. offset = I915_READ(DSPLINOFF(plane));
  5201. base = I915_READ(DSPSURF(plane)) & 0xfffff000;
  5202. } else {
  5203. base = I915_READ(DSPADDR(plane));
  5204. }
  5205. plane_config->base = base;
  5206. val = I915_READ(PIPESRC(pipe));
  5207. crtc->base.primary->fb->width = ((val >> 16) & 0xfff) + 1;
  5208. crtc->base.primary->fb->height = ((val >> 0) & 0xfff) + 1;
  5209. val = I915_READ(DSPSTRIDE(pipe));
  5210. crtc->base.primary->fb->pitches[0] = val & 0xffffff80;
  5211. aligned_height = intel_align_height(dev, crtc->base.primary->fb->height,
  5212. plane_config->tiled);
  5213. plane_config->size = PAGE_ALIGN(crtc->base.primary->fb->pitches[0] *
  5214. aligned_height);
  5215. DRM_DEBUG_KMS("pipe/plane %d/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
  5216. pipe, plane, crtc->base.primary->fb->width,
  5217. crtc->base.primary->fb->height,
  5218. crtc->base.primary->fb->bits_per_pixel, base,
  5219. crtc->base.primary->fb->pitches[0],
  5220. plane_config->size);
  5221. }
  5222. static void chv_crtc_clock_get(struct intel_crtc *crtc,
  5223. struct intel_crtc_config *pipe_config)
  5224. {
  5225. struct drm_device *dev = crtc->base.dev;
  5226. struct drm_i915_private *dev_priv = dev->dev_private;
  5227. int pipe = pipe_config->cpu_transcoder;
  5228. enum dpio_channel port = vlv_pipe_to_channel(pipe);
  5229. intel_clock_t clock;
  5230. u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2;
  5231. int refclk = 100000;
  5232. mutex_lock(&dev_priv->dpio_lock);
  5233. cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port));
  5234. pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port));
  5235. pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port));
  5236. pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port));
  5237. mutex_unlock(&dev_priv->dpio_lock);
  5238. clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0;
  5239. clock.m2 = ((pll_dw0 & 0xff) << 22) | (pll_dw2 & 0x3fffff);
  5240. clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf;
  5241. clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7;
  5242. clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f;
  5243. chv_clock(refclk, &clock);
  5244. /* clock.dot is the fast clock */
  5245. pipe_config->port_clock = clock.dot / 5;
  5246. }
  5247. static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
  5248. struct intel_crtc_config *pipe_config)
  5249. {
  5250. struct drm_device *dev = crtc->base.dev;
  5251. struct drm_i915_private *dev_priv = dev->dev_private;
  5252. uint32_t tmp;
  5253. if (!intel_display_power_enabled(dev_priv,
  5254. POWER_DOMAIN_PIPE(crtc->pipe)))
  5255. return false;
  5256. pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
  5257. pipe_config->shared_dpll = DPLL_ID_PRIVATE;
  5258. tmp = I915_READ(PIPECONF(crtc->pipe));
  5259. if (!(tmp & PIPECONF_ENABLE))
  5260. return false;
  5261. if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) {
  5262. switch (tmp & PIPECONF_BPC_MASK) {
  5263. case PIPECONF_6BPC:
  5264. pipe_config->pipe_bpp = 18;
  5265. break;
  5266. case PIPECONF_8BPC:
  5267. pipe_config->pipe_bpp = 24;
  5268. break;
  5269. case PIPECONF_10BPC:
  5270. pipe_config->pipe_bpp = 30;
  5271. break;
  5272. default:
  5273. break;
  5274. }
  5275. }
  5276. if (IS_VALLEYVIEW(dev) && (tmp & PIPECONF_COLOR_RANGE_SELECT))
  5277. pipe_config->limited_color_range = true;
  5278. if (INTEL_INFO(dev)->gen < 4)
  5279. pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE;
  5280. intel_get_pipe_timings(crtc, pipe_config);
  5281. i9xx_get_pfit_config(crtc, pipe_config);
  5282. if (INTEL_INFO(dev)->gen >= 4) {
  5283. tmp = I915_READ(DPLL_MD(crtc->pipe));
  5284. pipe_config->pixel_multiplier =
  5285. ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK)
  5286. >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1;
  5287. pipe_config->dpll_hw_state.dpll_md = tmp;
  5288. } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) {
  5289. tmp = I915_READ(DPLL(crtc->pipe));
  5290. pipe_config->pixel_multiplier =
  5291. ((tmp & SDVO_MULTIPLIER_MASK)
  5292. >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1;
  5293. } else {
  5294. /* Note that on i915G/GM the pixel multiplier is in the sdvo
  5295. * port and will be fixed up in the encoder->get_config
  5296. * function. */
  5297. pipe_config->pixel_multiplier = 1;
  5298. }
  5299. pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe));
  5300. if (!IS_VALLEYVIEW(dev)) {
  5301. pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe));
  5302. pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe));
  5303. } else {
  5304. /* Mask out read-only status bits. */
  5305. pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV |
  5306. DPLL_PORTC_READY_MASK |
  5307. DPLL_PORTB_READY_MASK);
  5308. }
  5309. if (IS_CHERRYVIEW(dev))
  5310. chv_crtc_clock_get(crtc, pipe_config);
  5311. else if (IS_VALLEYVIEW(dev))
  5312. vlv_crtc_clock_get(crtc, pipe_config);
  5313. else
  5314. i9xx_crtc_clock_get(crtc, pipe_config);
  5315. return true;
  5316. }
  5317. static void ironlake_init_pch_refclk(struct drm_device *dev)
  5318. {
  5319. struct drm_i915_private *dev_priv = dev->dev_private;
  5320. struct drm_mode_config *mode_config = &dev->mode_config;
  5321. struct intel_encoder *encoder;
  5322. u32 val, final;
  5323. bool has_lvds = false;
  5324. bool has_cpu_edp = false;
  5325. bool has_panel = false;
  5326. bool has_ck505 = false;
  5327. bool can_ssc = false;
  5328. /* We need to take the global config into account */
  5329. list_for_each_entry(encoder, &mode_config->encoder_list,
  5330. base.head) {
  5331. switch (encoder->type) {
  5332. case INTEL_OUTPUT_LVDS:
  5333. has_panel = true;
  5334. has_lvds = true;
  5335. break;
  5336. case INTEL_OUTPUT_EDP:
  5337. has_panel = true;
  5338. if (enc_to_dig_port(&encoder->base)->port == PORT_A)
  5339. has_cpu_edp = true;
  5340. break;
  5341. }
  5342. }
  5343. if (HAS_PCH_IBX(dev)) {
  5344. has_ck505 = dev_priv->vbt.display_clock_mode;
  5345. can_ssc = has_ck505;
  5346. } else {
  5347. has_ck505 = false;
  5348. can_ssc = true;
  5349. }
  5350. DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d\n",
  5351. has_panel, has_lvds, has_ck505);
  5352. /* Ironlake: try to setup display ref clock before DPLL
  5353. * enabling. This is only under driver's control after
  5354. * PCH B stepping, previous chipset stepping should be
  5355. * ignoring this setting.
  5356. */
  5357. val = I915_READ(PCH_DREF_CONTROL);
  5358. /* As we must carefully and slowly disable/enable each source in turn,
  5359. * compute the final state we want first and check if we need to
  5360. * make any changes at all.
  5361. */
  5362. final = val;
  5363. final &= ~DREF_NONSPREAD_SOURCE_MASK;
  5364. if (has_ck505)
  5365. final |= DREF_NONSPREAD_CK505_ENABLE;
  5366. else
  5367. final |= DREF_NONSPREAD_SOURCE_ENABLE;
  5368. final &= ~DREF_SSC_SOURCE_MASK;
  5369. final &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
  5370. final &= ~DREF_SSC1_ENABLE;
  5371. if (has_panel) {
  5372. final |= DREF_SSC_SOURCE_ENABLE;
  5373. if (intel_panel_use_ssc(dev_priv) && can_ssc)
  5374. final |= DREF_SSC1_ENABLE;
  5375. if (has_cpu_edp) {
  5376. if (intel_panel_use_ssc(dev_priv) && can_ssc)
  5377. final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
  5378. else
  5379. final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
  5380. } else
  5381. final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  5382. } else {
  5383. final |= DREF_SSC_SOURCE_DISABLE;
  5384. final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  5385. }
  5386. if (final == val)
  5387. return;
  5388. /* Always enable nonspread source */
  5389. val &= ~DREF_NONSPREAD_SOURCE_MASK;
  5390. if (has_ck505)
  5391. val |= DREF_NONSPREAD_CK505_ENABLE;
  5392. else
  5393. val |= DREF_NONSPREAD_SOURCE_ENABLE;
  5394. if (has_panel) {
  5395. val &= ~DREF_SSC_SOURCE_MASK;
  5396. val |= DREF_SSC_SOURCE_ENABLE;
  5397. /* SSC must be turned on before enabling the CPU output */
  5398. if (intel_panel_use_ssc(dev_priv) && can_ssc) {
  5399. DRM_DEBUG_KMS("Using SSC on panel\n");
  5400. val |= DREF_SSC1_ENABLE;
  5401. } else
  5402. val &= ~DREF_SSC1_ENABLE;
  5403. /* Get SSC going before enabling the outputs */
  5404. I915_WRITE(PCH_DREF_CONTROL, val);
  5405. POSTING_READ(PCH_DREF_CONTROL);
  5406. udelay(200);
  5407. val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
  5408. /* Enable CPU source on CPU attached eDP */
  5409. if (has_cpu_edp) {
  5410. if (intel_panel_use_ssc(dev_priv) && can_ssc) {
  5411. DRM_DEBUG_KMS("Using SSC on eDP\n");
  5412. val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
  5413. } else
  5414. val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
  5415. } else
  5416. val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  5417. I915_WRITE(PCH_DREF_CONTROL, val);
  5418. POSTING_READ(PCH_DREF_CONTROL);
  5419. udelay(200);
  5420. } else {
  5421. DRM_DEBUG_KMS("Disabling SSC entirely\n");
  5422. val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
  5423. /* Turn off CPU output */
  5424. val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  5425. I915_WRITE(PCH_DREF_CONTROL, val);
  5426. POSTING_READ(PCH_DREF_CONTROL);
  5427. udelay(200);
  5428. /* Turn off the SSC source */
  5429. val &= ~DREF_SSC_SOURCE_MASK;
  5430. val |= DREF_SSC_SOURCE_DISABLE;
  5431. /* Turn off SSC1 */
  5432. val &= ~DREF_SSC1_ENABLE;
  5433. I915_WRITE(PCH_DREF_CONTROL, val);
  5434. POSTING_READ(PCH_DREF_CONTROL);
  5435. udelay(200);
  5436. }
  5437. BUG_ON(val != final);
  5438. }
  5439. static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv)
  5440. {
  5441. uint32_t tmp;
  5442. tmp = I915_READ(SOUTH_CHICKEN2);
  5443. tmp |= FDI_MPHY_IOSFSB_RESET_CTL;
  5444. I915_WRITE(SOUTH_CHICKEN2, tmp);
  5445. if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2) &
  5446. FDI_MPHY_IOSFSB_RESET_STATUS, 100))
  5447. DRM_ERROR("FDI mPHY reset assert timeout\n");
  5448. tmp = I915_READ(SOUTH_CHICKEN2);
  5449. tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL;
  5450. I915_WRITE(SOUTH_CHICKEN2, tmp);
  5451. if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2) &
  5452. FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100))
  5453. DRM_ERROR("FDI mPHY reset de-assert timeout\n");
  5454. }
  5455. /* WaMPhyProgramming:hsw */
  5456. static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv)
  5457. {
  5458. uint32_t tmp;
  5459. tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY);
  5460. tmp &= ~(0xFF << 24);
  5461. tmp |= (0x12 << 24);
  5462. intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY);
  5463. tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY);
  5464. tmp |= (1 << 11);
  5465. intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY);
  5466. tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY);
  5467. tmp |= (1 << 11);
  5468. intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY);
  5469. tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY);
  5470. tmp |= (1 << 24) | (1 << 21) | (1 << 18);
  5471. intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY);
  5472. tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY);
  5473. tmp |= (1 << 24) | (1 << 21) | (1 << 18);
  5474. intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY);
  5475. tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY);
  5476. tmp &= ~(7 << 13);
  5477. tmp |= (5 << 13);
  5478. intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY);
  5479. tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY);
  5480. tmp &= ~(7 << 13);
  5481. tmp |= (5 << 13);
  5482. intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY);
  5483. tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY);
  5484. tmp &= ~0xFF;
  5485. tmp |= 0x1C;
  5486. intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY);
  5487. tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY);
  5488. tmp &= ~0xFF;
  5489. tmp |= 0x1C;
  5490. intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY);
  5491. tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY);
  5492. tmp &= ~(0xFF << 16);
  5493. tmp |= (0x1C << 16);
  5494. intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY);
  5495. tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY);
  5496. tmp &= ~(0xFF << 16);
  5497. tmp |= (0x1C << 16);
  5498. intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY);
  5499. tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY);
  5500. tmp |= (1 << 27);
  5501. intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY);
  5502. tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY);
  5503. tmp |= (1 << 27);
  5504. intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY);
  5505. tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY);
  5506. tmp &= ~(0xF << 28);
  5507. tmp |= (4 << 28);
  5508. intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY);
  5509. tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY);
  5510. tmp &= ~(0xF << 28);
  5511. tmp |= (4 << 28);
  5512. intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY);
  5513. }
  5514. /* Implements 3 different sequences from BSpec chapter "Display iCLK
  5515. * Programming" based on the parameters passed:
  5516. * - Sequence to enable CLKOUT_DP
  5517. * - Sequence to enable CLKOUT_DP without spread
  5518. * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
  5519. */
  5520. static void lpt_enable_clkout_dp(struct drm_device *dev, bool with_spread,
  5521. bool with_fdi)
  5522. {
  5523. struct drm_i915_private *dev_priv = dev->dev_private;
  5524. uint32_t reg, tmp;
  5525. if (WARN(with_fdi && !with_spread, "FDI requires downspread\n"))
  5526. with_spread = true;
  5527. if (WARN(dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE &&
  5528. with_fdi, "LP PCH doesn't have FDI\n"))
  5529. with_fdi = false;
  5530. mutex_lock(&dev_priv->dpio_lock);
  5531. tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
  5532. tmp &= ~SBI_SSCCTL_DISABLE;
  5533. tmp |= SBI_SSCCTL_PATHALT;
  5534. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  5535. udelay(24);
  5536. if (with_spread) {
  5537. tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
  5538. tmp &= ~SBI_SSCCTL_PATHALT;
  5539. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  5540. if (with_fdi) {
  5541. lpt_reset_fdi_mphy(dev_priv);
  5542. lpt_program_fdi_mphy(dev_priv);
  5543. }
  5544. }
  5545. reg = (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) ?
  5546. SBI_GEN0 : SBI_DBUFF0;
  5547. tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
  5548. tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE;
  5549. intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
  5550. mutex_unlock(&dev_priv->dpio_lock);
  5551. }
  5552. /* Sequence to disable CLKOUT_DP */
  5553. static void lpt_disable_clkout_dp(struct drm_device *dev)
  5554. {
  5555. struct drm_i915_private *dev_priv = dev->dev_private;
  5556. uint32_t reg, tmp;
  5557. mutex_lock(&dev_priv->dpio_lock);
  5558. reg = (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) ?
  5559. SBI_GEN0 : SBI_DBUFF0;
  5560. tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
  5561. tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE;
  5562. intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
  5563. tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
  5564. if (!(tmp & SBI_SSCCTL_DISABLE)) {
  5565. if (!(tmp & SBI_SSCCTL_PATHALT)) {
  5566. tmp |= SBI_SSCCTL_PATHALT;
  5567. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  5568. udelay(32);
  5569. }
  5570. tmp |= SBI_SSCCTL_DISABLE;
  5571. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  5572. }
  5573. mutex_unlock(&dev_priv->dpio_lock);
  5574. }
  5575. static void lpt_init_pch_refclk(struct drm_device *dev)
  5576. {
  5577. struct drm_mode_config *mode_config = &dev->mode_config;
  5578. struct intel_encoder *encoder;
  5579. bool has_vga = false;
  5580. list_for_each_entry(encoder, &mode_config->encoder_list, base.head) {
  5581. switch (encoder->type) {
  5582. case INTEL_OUTPUT_ANALOG:
  5583. has_vga = true;
  5584. break;
  5585. }
  5586. }
  5587. if (has_vga)
  5588. lpt_enable_clkout_dp(dev, true, true);
  5589. else
  5590. lpt_disable_clkout_dp(dev);
  5591. }
  5592. /*
  5593. * Initialize reference clocks when the driver loads
  5594. */
  5595. void intel_init_pch_refclk(struct drm_device *dev)
  5596. {
  5597. if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
  5598. ironlake_init_pch_refclk(dev);
  5599. else if (HAS_PCH_LPT(dev))
  5600. lpt_init_pch_refclk(dev);
  5601. }
  5602. static int ironlake_get_refclk(struct drm_crtc *crtc)
  5603. {
  5604. struct drm_device *dev = crtc->dev;
  5605. struct drm_i915_private *dev_priv = dev->dev_private;
  5606. struct intel_encoder *encoder;
  5607. int num_connectors = 0;
  5608. bool is_lvds = false;
  5609. for_each_encoder_on_crtc(dev, crtc, encoder) {
  5610. switch (encoder->type) {
  5611. case INTEL_OUTPUT_LVDS:
  5612. is_lvds = true;
  5613. break;
  5614. }
  5615. num_connectors++;
  5616. }
  5617. if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) {
  5618. DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
  5619. dev_priv->vbt.lvds_ssc_freq);
  5620. return dev_priv->vbt.lvds_ssc_freq;
  5621. }
  5622. return 120000;
  5623. }
  5624. static void ironlake_set_pipeconf(struct drm_crtc *crtc)
  5625. {
  5626. struct drm_i915_private *dev_priv = crtc->dev->dev_private;
  5627. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5628. int pipe = intel_crtc->pipe;
  5629. uint32_t val;
  5630. val = 0;
  5631. switch (intel_crtc->config.pipe_bpp) {
  5632. case 18:
  5633. val |= PIPECONF_6BPC;
  5634. break;
  5635. case 24:
  5636. val |= PIPECONF_8BPC;
  5637. break;
  5638. case 30:
  5639. val |= PIPECONF_10BPC;
  5640. break;
  5641. case 36:
  5642. val |= PIPECONF_12BPC;
  5643. break;
  5644. default:
  5645. /* Case prevented by intel_choose_pipe_bpp_dither. */
  5646. BUG();
  5647. }
  5648. if (intel_crtc->config.dither)
  5649. val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
  5650. if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
  5651. val |= PIPECONF_INTERLACED_ILK;
  5652. else
  5653. val |= PIPECONF_PROGRESSIVE;
  5654. if (intel_crtc->config.limited_color_range)
  5655. val |= PIPECONF_COLOR_RANGE_SELECT;
  5656. I915_WRITE(PIPECONF(pipe), val);
  5657. POSTING_READ(PIPECONF(pipe));
  5658. }
  5659. /*
  5660. * Set up the pipe CSC unit.
  5661. *
  5662. * Currently only full range RGB to limited range RGB conversion
  5663. * is supported, but eventually this should handle various
  5664. * RGB<->YCbCr scenarios as well.
  5665. */
  5666. static void intel_set_pipe_csc(struct drm_crtc *crtc)
  5667. {
  5668. struct drm_device *dev = crtc->dev;
  5669. struct drm_i915_private *dev_priv = dev->dev_private;
  5670. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5671. int pipe = intel_crtc->pipe;
  5672. uint16_t coeff = 0x7800; /* 1.0 */
  5673. /*
  5674. * TODO: Check what kind of values actually come out of the pipe
  5675. * with these coeff/postoff values and adjust to get the best
  5676. * accuracy. Perhaps we even need to take the bpc value into
  5677. * consideration.
  5678. */
  5679. if (intel_crtc->config.limited_color_range)
  5680. coeff = ((235 - 16) * (1 << 12) / 255) & 0xff8; /* 0.xxx... */
  5681. /*
  5682. * GY/GU and RY/RU should be the other way around according
  5683. * to BSpec, but reality doesn't agree. Just set them up in
  5684. * a way that results in the correct picture.
  5685. */
  5686. I915_WRITE(PIPE_CSC_COEFF_RY_GY(pipe), coeff << 16);
  5687. I915_WRITE(PIPE_CSC_COEFF_BY(pipe), 0);
  5688. I915_WRITE(PIPE_CSC_COEFF_RU_GU(pipe), coeff);
  5689. I915_WRITE(PIPE_CSC_COEFF_BU(pipe), 0);
  5690. I915_WRITE(PIPE_CSC_COEFF_RV_GV(pipe), 0);
  5691. I915_WRITE(PIPE_CSC_COEFF_BV(pipe), coeff << 16);
  5692. I915_WRITE(PIPE_CSC_PREOFF_HI(pipe), 0);
  5693. I915_WRITE(PIPE_CSC_PREOFF_ME(pipe), 0);
  5694. I915_WRITE(PIPE_CSC_PREOFF_LO(pipe), 0);
  5695. if (INTEL_INFO(dev)->gen > 6) {
  5696. uint16_t postoff = 0;
  5697. if (intel_crtc->config.limited_color_range)
  5698. postoff = (16 * (1 << 12) / 255) & 0x1fff;
  5699. I915_WRITE(PIPE_CSC_POSTOFF_HI(pipe), postoff);
  5700. I915_WRITE(PIPE_CSC_POSTOFF_ME(pipe), postoff);
  5701. I915_WRITE(PIPE_CSC_POSTOFF_LO(pipe), postoff);
  5702. I915_WRITE(PIPE_CSC_MODE(pipe), 0);
  5703. } else {
  5704. uint32_t mode = CSC_MODE_YUV_TO_RGB;
  5705. if (intel_crtc->config.limited_color_range)
  5706. mode |= CSC_BLACK_SCREEN_OFFSET;
  5707. I915_WRITE(PIPE_CSC_MODE(pipe), mode);
  5708. }
  5709. }
  5710. static void haswell_set_pipeconf(struct drm_crtc *crtc)
  5711. {
  5712. struct drm_device *dev = crtc->dev;
  5713. struct drm_i915_private *dev_priv = dev->dev_private;
  5714. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5715. enum pipe pipe = intel_crtc->pipe;
  5716. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  5717. uint32_t val;
  5718. val = 0;
  5719. if (IS_HASWELL(dev) && intel_crtc->config.dither)
  5720. val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
  5721. if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
  5722. val |= PIPECONF_INTERLACED_ILK;
  5723. else
  5724. val |= PIPECONF_PROGRESSIVE;
  5725. I915_WRITE(PIPECONF(cpu_transcoder), val);
  5726. POSTING_READ(PIPECONF(cpu_transcoder));
  5727. I915_WRITE(GAMMA_MODE(intel_crtc->pipe), GAMMA_MODE_MODE_8BIT);
  5728. POSTING_READ(GAMMA_MODE(intel_crtc->pipe));
  5729. if (IS_BROADWELL(dev)) {
  5730. val = 0;
  5731. switch (intel_crtc->config.pipe_bpp) {
  5732. case 18:
  5733. val |= PIPEMISC_DITHER_6_BPC;
  5734. break;
  5735. case 24:
  5736. val |= PIPEMISC_DITHER_8_BPC;
  5737. break;
  5738. case 30:
  5739. val |= PIPEMISC_DITHER_10_BPC;
  5740. break;
  5741. case 36:
  5742. val |= PIPEMISC_DITHER_12_BPC;
  5743. break;
  5744. default:
  5745. /* Case prevented by pipe_config_set_bpp. */
  5746. BUG();
  5747. }
  5748. if (intel_crtc->config.dither)
  5749. val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP;
  5750. I915_WRITE(PIPEMISC(pipe), val);
  5751. }
  5752. }
  5753. static bool ironlake_compute_clocks(struct drm_crtc *crtc,
  5754. intel_clock_t *clock,
  5755. bool *has_reduced_clock,
  5756. intel_clock_t *reduced_clock)
  5757. {
  5758. struct drm_device *dev = crtc->dev;
  5759. struct drm_i915_private *dev_priv = dev->dev_private;
  5760. struct intel_encoder *intel_encoder;
  5761. int refclk;
  5762. const intel_limit_t *limit;
  5763. bool ret, is_lvds = false;
  5764. for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
  5765. switch (intel_encoder->type) {
  5766. case INTEL_OUTPUT_LVDS:
  5767. is_lvds = true;
  5768. break;
  5769. }
  5770. }
  5771. refclk = ironlake_get_refclk(crtc);
  5772. /*
  5773. * Returns a set of divisors for the desired target clock with the given
  5774. * refclk, or FALSE. The returned values represent the clock equation:
  5775. * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
  5776. */
  5777. limit = intel_limit(crtc, refclk);
  5778. ret = dev_priv->display.find_dpll(limit, crtc,
  5779. to_intel_crtc(crtc)->config.port_clock,
  5780. refclk, NULL, clock);
  5781. if (!ret)
  5782. return false;
  5783. if (is_lvds && dev_priv->lvds_downclock_avail) {
  5784. /*
  5785. * Ensure we match the reduced clock's P to the target clock.
  5786. * If the clocks don't match, we can't switch the display clock
  5787. * by using the FP0/FP1. In such case we will disable the LVDS
  5788. * downclock feature.
  5789. */
  5790. *has_reduced_clock =
  5791. dev_priv->display.find_dpll(limit, crtc,
  5792. dev_priv->lvds_downclock,
  5793. refclk, clock,
  5794. reduced_clock);
  5795. }
  5796. return true;
  5797. }
  5798. int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp)
  5799. {
  5800. /*
  5801. * Account for spread spectrum to avoid
  5802. * oversubscribing the link. Max center spread
  5803. * is 2.5%; use 5% for safety's sake.
  5804. */
  5805. u32 bps = target_clock * bpp * 21 / 20;
  5806. return DIV_ROUND_UP(bps, link_bw * 8);
  5807. }
  5808. static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor)
  5809. {
  5810. return i9xx_dpll_compute_m(dpll) < factor * dpll->n;
  5811. }
  5812. static uint32_t ironlake_compute_dpll(struct intel_crtc *intel_crtc,
  5813. u32 *fp,
  5814. intel_clock_t *reduced_clock, u32 *fp2)
  5815. {
  5816. struct drm_crtc *crtc = &intel_crtc->base;
  5817. struct drm_device *dev = crtc->dev;
  5818. struct drm_i915_private *dev_priv = dev->dev_private;
  5819. struct intel_encoder *intel_encoder;
  5820. uint32_t dpll;
  5821. int factor, num_connectors = 0;
  5822. bool is_lvds = false, is_sdvo = false;
  5823. for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
  5824. switch (intel_encoder->type) {
  5825. case INTEL_OUTPUT_LVDS:
  5826. is_lvds = true;
  5827. break;
  5828. case INTEL_OUTPUT_SDVO:
  5829. case INTEL_OUTPUT_HDMI:
  5830. is_sdvo = true;
  5831. break;
  5832. }
  5833. num_connectors++;
  5834. }
  5835. /* Enable autotuning of the PLL clock (if permissible) */
  5836. factor = 21;
  5837. if (is_lvds) {
  5838. if ((intel_panel_use_ssc(dev_priv) &&
  5839. dev_priv->vbt.lvds_ssc_freq == 100000) ||
  5840. (HAS_PCH_IBX(dev) && intel_is_dual_link_lvds(dev)))
  5841. factor = 25;
  5842. } else if (intel_crtc->config.sdvo_tv_clock)
  5843. factor = 20;
  5844. if (ironlake_needs_fb_cb_tune(&intel_crtc->config.dpll, factor))
  5845. *fp |= FP_CB_TUNE;
  5846. if (fp2 && (reduced_clock->m < factor * reduced_clock->n))
  5847. *fp2 |= FP_CB_TUNE;
  5848. dpll = 0;
  5849. if (is_lvds)
  5850. dpll |= DPLLB_MODE_LVDS;
  5851. else
  5852. dpll |= DPLLB_MODE_DAC_SERIAL;
  5853. dpll |= (intel_crtc->config.pixel_multiplier - 1)
  5854. << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
  5855. if (is_sdvo)
  5856. dpll |= DPLL_SDVO_HIGH_SPEED;
  5857. if (intel_crtc->config.has_dp_encoder)
  5858. dpll |= DPLL_SDVO_HIGH_SPEED;
  5859. /* compute bitmask from p1 value */
  5860. dpll |= (1 << (intel_crtc->config.dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  5861. /* also FPA1 */
  5862. dpll |= (1 << (intel_crtc->config.dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
  5863. switch (intel_crtc->config.dpll.p2) {
  5864. case 5:
  5865. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
  5866. break;
  5867. case 7:
  5868. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
  5869. break;
  5870. case 10:
  5871. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
  5872. break;
  5873. case 14:
  5874. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
  5875. break;
  5876. }
  5877. if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2)
  5878. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  5879. else
  5880. dpll |= PLL_REF_INPUT_DREFCLK;
  5881. return dpll | DPLL_VCO_ENABLE;
  5882. }
  5883. static int ironlake_crtc_mode_set(struct drm_crtc *crtc,
  5884. int x, int y,
  5885. struct drm_framebuffer *fb)
  5886. {
  5887. struct drm_device *dev = crtc->dev;
  5888. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5889. int num_connectors = 0;
  5890. intel_clock_t clock, reduced_clock;
  5891. u32 dpll = 0, fp = 0, fp2 = 0;
  5892. bool ok, has_reduced_clock = false;
  5893. bool is_lvds = false;
  5894. struct intel_encoder *encoder;
  5895. struct intel_shared_dpll *pll;
  5896. for_each_encoder_on_crtc(dev, crtc, encoder) {
  5897. switch (encoder->type) {
  5898. case INTEL_OUTPUT_LVDS:
  5899. is_lvds = true;
  5900. break;
  5901. }
  5902. num_connectors++;
  5903. }
  5904. WARN(!(HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)),
  5905. "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev));
  5906. ok = ironlake_compute_clocks(crtc, &clock,
  5907. &has_reduced_clock, &reduced_clock);
  5908. if (!ok && !intel_crtc->config.clock_set) {
  5909. DRM_ERROR("Couldn't find PLL settings for mode!\n");
  5910. return -EINVAL;
  5911. }
  5912. /* Compat-code for transition, will disappear. */
  5913. if (!intel_crtc->config.clock_set) {
  5914. intel_crtc->config.dpll.n = clock.n;
  5915. intel_crtc->config.dpll.m1 = clock.m1;
  5916. intel_crtc->config.dpll.m2 = clock.m2;
  5917. intel_crtc->config.dpll.p1 = clock.p1;
  5918. intel_crtc->config.dpll.p2 = clock.p2;
  5919. }
  5920. /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
  5921. if (intel_crtc->config.has_pch_encoder) {
  5922. fp = i9xx_dpll_compute_fp(&intel_crtc->config.dpll);
  5923. if (has_reduced_clock)
  5924. fp2 = i9xx_dpll_compute_fp(&reduced_clock);
  5925. dpll = ironlake_compute_dpll(intel_crtc,
  5926. &fp, &reduced_clock,
  5927. has_reduced_clock ? &fp2 : NULL);
  5928. intel_crtc->config.dpll_hw_state.dpll = dpll;
  5929. intel_crtc->config.dpll_hw_state.fp0 = fp;
  5930. if (has_reduced_clock)
  5931. intel_crtc->config.dpll_hw_state.fp1 = fp2;
  5932. else
  5933. intel_crtc->config.dpll_hw_state.fp1 = fp;
  5934. pll = intel_get_shared_dpll(intel_crtc);
  5935. if (pll == NULL) {
  5936. DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
  5937. pipe_name(intel_crtc->pipe));
  5938. return -EINVAL;
  5939. }
  5940. } else
  5941. intel_put_shared_dpll(intel_crtc);
  5942. if (is_lvds && has_reduced_clock && i915.powersave)
  5943. intel_crtc->lowfreq_avail = true;
  5944. else
  5945. intel_crtc->lowfreq_avail = false;
  5946. return 0;
  5947. }
  5948. static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc,
  5949. struct intel_link_m_n *m_n)
  5950. {
  5951. struct drm_device *dev = crtc->base.dev;
  5952. struct drm_i915_private *dev_priv = dev->dev_private;
  5953. enum pipe pipe = crtc->pipe;
  5954. m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe));
  5955. m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe));
  5956. m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe))
  5957. & ~TU_SIZE_MASK;
  5958. m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe));
  5959. m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe))
  5960. & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
  5961. }
  5962. static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc,
  5963. enum transcoder transcoder,
  5964. struct intel_link_m_n *m_n)
  5965. {
  5966. struct drm_device *dev = crtc->base.dev;
  5967. struct drm_i915_private *dev_priv = dev->dev_private;
  5968. enum pipe pipe = crtc->pipe;
  5969. if (INTEL_INFO(dev)->gen >= 5) {
  5970. m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder));
  5971. m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder));
  5972. m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder))
  5973. & ~TU_SIZE_MASK;
  5974. m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder));
  5975. m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder))
  5976. & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
  5977. } else {
  5978. m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe));
  5979. m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe));
  5980. m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe))
  5981. & ~TU_SIZE_MASK;
  5982. m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe));
  5983. m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe))
  5984. & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
  5985. }
  5986. }
  5987. void intel_dp_get_m_n(struct intel_crtc *crtc,
  5988. struct intel_crtc_config *pipe_config)
  5989. {
  5990. if (crtc->config.has_pch_encoder)
  5991. intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n);
  5992. else
  5993. intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
  5994. &pipe_config->dp_m_n);
  5995. }
  5996. static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc,
  5997. struct intel_crtc_config *pipe_config)
  5998. {
  5999. intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
  6000. &pipe_config->fdi_m_n);
  6001. }
  6002. static void ironlake_get_pfit_config(struct intel_crtc *crtc,
  6003. struct intel_crtc_config *pipe_config)
  6004. {
  6005. struct drm_device *dev = crtc->base.dev;
  6006. struct drm_i915_private *dev_priv = dev->dev_private;
  6007. uint32_t tmp;
  6008. tmp = I915_READ(PF_CTL(crtc->pipe));
  6009. if (tmp & PF_ENABLE) {
  6010. pipe_config->pch_pfit.enabled = true;
  6011. pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe));
  6012. pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe));
  6013. /* We currently do not free assignements of panel fitters on
  6014. * ivb/hsw (since we don't use the higher upscaling modes which
  6015. * differentiates them) so just WARN about this case for now. */
  6016. if (IS_GEN7(dev)) {
  6017. WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) !=
  6018. PF_PIPE_SEL_IVB(crtc->pipe));
  6019. }
  6020. }
  6021. }
  6022. static void ironlake_get_plane_config(struct intel_crtc *crtc,
  6023. struct intel_plane_config *plane_config)
  6024. {
  6025. struct drm_device *dev = crtc->base.dev;
  6026. struct drm_i915_private *dev_priv = dev->dev_private;
  6027. u32 val, base, offset;
  6028. int pipe = crtc->pipe, plane = crtc->plane;
  6029. int fourcc, pixel_format;
  6030. int aligned_height;
  6031. crtc->base.primary->fb = kzalloc(sizeof(struct intel_framebuffer), GFP_KERNEL);
  6032. if (!crtc->base.primary->fb) {
  6033. DRM_DEBUG_KMS("failed to alloc fb\n");
  6034. return;
  6035. }
  6036. val = I915_READ(DSPCNTR(plane));
  6037. if (INTEL_INFO(dev)->gen >= 4)
  6038. if (val & DISPPLANE_TILED)
  6039. plane_config->tiled = true;
  6040. pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
  6041. fourcc = intel_format_to_fourcc(pixel_format);
  6042. crtc->base.primary->fb->pixel_format = fourcc;
  6043. crtc->base.primary->fb->bits_per_pixel =
  6044. drm_format_plane_cpp(fourcc, 0) * 8;
  6045. base = I915_READ(DSPSURF(plane)) & 0xfffff000;
  6046. if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
  6047. offset = I915_READ(DSPOFFSET(plane));
  6048. } else {
  6049. if (plane_config->tiled)
  6050. offset = I915_READ(DSPTILEOFF(plane));
  6051. else
  6052. offset = I915_READ(DSPLINOFF(plane));
  6053. }
  6054. plane_config->base = base;
  6055. val = I915_READ(PIPESRC(pipe));
  6056. crtc->base.primary->fb->width = ((val >> 16) & 0xfff) + 1;
  6057. crtc->base.primary->fb->height = ((val >> 0) & 0xfff) + 1;
  6058. val = I915_READ(DSPSTRIDE(pipe));
  6059. crtc->base.primary->fb->pitches[0] = val & 0xffffff80;
  6060. aligned_height = intel_align_height(dev, crtc->base.primary->fb->height,
  6061. plane_config->tiled);
  6062. plane_config->size = PAGE_ALIGN(crtc->base.primary->fb->pitches[0] *
  6063. aligned_height);
  6064. DRM_DEBUG_KMS("pipe/plane %d/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
  6065. pipe, plane, crtc->base.primary->fb->width,
  6066. crtc->base.primary->fb->height,
  6067. crtc->base.primary->fb->bits_per_pixel, base,
  6068. crtc->base.primary->fb->pitches[0],
  6069. plane_config->size);
  6070. }
  6071. static bool ironlake_get_pipe_config(struct intel_crtc *crtc,
  6072. struct intel_crtc_config *pipe_config)
  6073. {
  6074. struct drm_device *dev = crtc->base.dev;
  6075. struct drm_i915_private *dev_priv = dev->dev_private;
  6076. uint32_t tmp;
  6077. pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
  6078. pipe_config->shared_dpll = DPLL_ID_PRIVATE;
  6079. tmp = I915_READ(PIPECONF(crtc->pipe));
  6080. if (!(tmp & PIPECONF_ENABLE))
  6081. return false;
  6082. switch (tmp & PIPECONF_BPC_MASK) {
  6083. case PIPECONF_6BPC:
  6084. pipe_config->pipe_bpp = 18;
  6085. break;
  6086. case PIPECONF_8BPC:
  6087. pipe_config->pipe_bpp = 24;
  6088. break;
  6089. case PIPECONF_10BPC:
  6090. pipe_config->pipe_bpp = 30;
  6091. break;
  6092. case PIPECONF_12BPC:
  6093. pipe_config->pipe_bpp = 36;
  6094. break;
  6095. default:
  6096. break;
  6097. }
  6098. if (tmp & PIPECONF_COLOR_RANGE_SELECT)
  6099. pipe_config->limited_color_range = true;
  6100. if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) {
  6101. struct intel_shared_dpll *pll;
  6102. pipe_config->has_pch_encoder = true;
  6103. tmp = I915_READ(FDI_RX_CTL(crtc->pipe));
  6104. pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
  6105. FDI_DP_PORT_WIDTH_SHIFT) + 1;
  6106. ironlake_get_fdi_m_n_config(crtc, pipe_config);
  6107. if (HAS_PCH_IBX(dev_priv->dev)) {
  6108. pipe_config->shared_dpll =
  6109. (enum intel_dpll_id) crtc->pipe;
  6110. } else {
  6111. tmp = I915_READ(PCH_DPLL_SEL);
  6112. if (tmp & TRANS_DPLLB_SEL(crtc->pipe))
  6113. pipe_config->shared_dpll = DPLL_ID_PCH_PLL_B;
  6114. else
  6115. pipe_config->shared_dpll = DPLL_ID_PCH_PLL_A;
  6116. }
  6117. pll = &dev_priv->shared_dplls[pipe_config->shared_dpll];
  6118. WARN_ON(!pll->get_hw_state(dev_priv, pll,
  6119. &pipe_config->dpll_hw_state));
  6120. tmp = pipe_config->dpll_hw_state.dpll;
  6121. pipe_config->pixel_multiplier =
  6122. ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK)
  6123. >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1;
  6124. ironlake_pch_clock_get(crtc, pipe_config);
  6125. } else {
  6126. pipe_config->pixel_multiplier = 1;
  6127. }
  6128. intel_get_pipe_timings(crtc, pipe_config);
  6129. ironlake_get_pfit_config(crtc, pipe_config);
  6130. return true;
  6131. }
  6132. static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv)
  6133. {
  6134. struct drm_device *dev = dev_priv->dev;
  6135. struct intel_ddi_plls *plls = &dev_priv->ddi_plls;
  6136. struct intel_crtc *crtc;
  6137. for_each_intel_crtc(dev, crtc)
  6138. WARN(crtc->active, "CRTC for pipe %c enabled\n",
  6139. pipe_name(crtc->pipe));
  6140. WARN(I915_READ(HSW_PWR_WELL_DRIVER), "Power well on\n");
  6141. WARN(plls->spll_refcount, "SPLL enabled\n");
  6142. WARN(plls->wrpll1_refcount, "WRPLL1 enabled\n");
  6143. WARN(plls->wrpll2_refcount, "WRPLL2 enabled\n");
  6144. WARN(I915_READ(PCH_PP_STATUS) & PP_ON, "Panel power on\n");
  6145. WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE,
  6146. "CPU PWM1 enabled\n");
  6147. WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE,
  6148. "CPU PWM2 enabled\n");
  6149. WARN(I915_READ(BLC_PWM_PCH_CTL1) & BLM_PCH_PWM_ENABLE,
  6150. "PCH PWM1 enabled\n");
  6151. WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
  6152. "Utility pin enabled\n");
  6153. WARN(I915_READ(PCH_GTC_CTL) & PCH_GTC_ENABLE, "PCH GTC enabled\n");
  6154. /*
  6155. * In theory we can still leave IRQs enabled, as long as only the HPD
  6156. * interrupts remain enabled. We used to check for that, but since it's
  6157. * gen-specific and since we only disable LCPLL after we fully disable
  6158. * the interrupts, the check below should be enough.
  6159. */
  6160. WARN(!dev_priv->pm.irqs_disabled, "IRQs enabled\n");
  6161. }
  6162. static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val)
  6163. {
  6164. struct drm_device *dev = dev_priv->dev;
  6165. if (IS_HASWELL(dev)) {
  6166. mutex_lock(&dev_priv->rps.hw_lock);
  6167. if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP,
  6168. val))
  6169. DRM_ERROR("Failed to disable D_COMP\n");
  6170. mutex_unlock(&dev_priv->rps.hw_lock);
  6171. } else {
  6172. I915_WRITE(D_COMP, val);
  6173. }
  6174. POSTING_READ(D_COMP);
  6175. }
  6176. /*
  6177. * This function implements pieces of two sequences from BSpec:
  6178. * - Sequence for display software to disable LCPLL
  6179. * - Sequence for display software to allow package C8+
  6180. * The steps implemented here are just the steps that actually touch the LCPLL
  6181. * register. Callers should take care of disabling all the display engine
  6182. * functions, doing the mode unset, fixing interrupts, etc.
  6183. */
  6184. static void hsw_disable_lcpll(struct drm_i915_private *dev_priv,
  6185. bool switch_to_fclk, bool allow_power_down)
  6186. {
  6187. uint32_t val;
  6188. assert_can_disable_lcpll(dev_priv);
  6189. val = I915_READ(LCPLL_CTL);
  6190. if (switch_to_fclk) {
  6191. val |= LCPLL_CD_SOURCE_FCLK;
  6192. I915_WRITE(LCPLL_CTL, val);
  6193. if (wait_for_atomic_us(I915_READ(LCPLL_CTL) &
  6194. LCPLL_CD_SOURCE_FCLK_DONE, 1))
  6195. DRM_ERROR("Switching to FCLK failed\n");
  6196. val = I915_READ(LCPLL_CTL);
  6197. }
  6198. val |= LCPLL_PLL_DISABLE;
  6199. I915_WRITE(LCPLL_CTL, val);
  6200. POSTING_READ(LCPLL_CTL);
  6201. if (wait_for((I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK) == 0, 1))
  6202. DRM_ERROR("LCPLL still locked\n");
  6203. val = I915_READ(D_COMP);
  6204. val |= D_COMP_COMP_DISABLE;
  6205. hsw_write_dcomp(dev_priv, val);
  6206. ndelay(100);
  6207. if (wait_for((I915_READ(D_COMP) & D_COMP_RCOMP_IN_PROGRESS) == 0, 1))
  6208. DRM_ERROR("D_COMP RCOMP still in progress\n");
  6209. if (allow_power_down) {
  6210. val = I915_READ(LCPLL_CTL);
  6211. val |= LCPLL_POWER_DOWN_ALLOW;
  6212. I915_WRITE(LCPLL_CTL, val);
  6213. POSTING_READ(LCPLL_CTL);
  6214. }
  6215. }
  6216. /*
  6217. * Fully restores LCPLL, disallowing power down and switching back to LCPLL
  6218. * source.
  6219. */
  6220. static void hsw_restore_lcpll(struct drm_i915_private *dev_priv)
  6221. {
  6222. uint32_t val;
  6223. unsigned long irqflags;
  6224. val = I915_READ(LCPLL_CTL);
  6225. if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK |
  6226. LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK)
  6227. return;
  6228. /*
  6229. * Make sure we're not on PC8 state before disabling PC8, otherwise
  6230. * we'll hang the machine. To prevent PC8 state, just enable force_wake.
  6231. *
  6232. * The other problem is that hsw_restore_lcpll() is called as part of
  6233. * the runtime PM resume sequence, so we can't just call
  6234. * gen6_gt_force_wake_get() because that function calls
  6235. * intel_runtime_pm_get(), and we can't change the runtime PM refcount
  6236. * while we are on the resume sequence. So to solve this problem we have
  6237. * to call special forcewake code that doesn't touch runtime PM and
  6238. * doesn't enable the forcewake delayed work.
  6239. */
  6240. spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
  6241. if (dev_priv->uncore.forcewake_count++ == 0)
  6242. dev_priv->uncore.funcs.force_wake_get(dev_priv, FORCEWAKE_ALL);
  6243. spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
  6244. if (val & LCPLL_POWER_DOWN_ALLOW) {
  6245. val &= ~LCPLL_POWER_DOWN_ALLOW;
  6246. I915_WRITE(LCPLL_CTL, val);
  6247. POSTING_READ(LCPLL_CTL);
  6248. }
  6249. val = I915_READ(D_COMP);
  6250. val |= D_COMP_COMP_FORCE;
  6251. val &= ~D_COMP_COMP_DISABLE;
  6252. hsw_write_dcomp(dev_priv, val);
  6253. val = I915_READ(LCPLL_CTL);
  6254. val &= ~LCPLL_PLL_DISABLE;
  6255. I915_WRITE(LCPLL_CTL, val);
  6256. if (wait_for(I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK, 5))
  6257. DRM_ERROR("LCPLL not locked yet\n");
  6258. if (val & LCPLL_CD_SOURCE_FCLK) {
  6259. val = I915_READ(LCPLL_CTL);
  6260. val &= ~LCPLL_CD_SOURCE_FCLK;
  6261. I915_WRITE(LCPLL_CTL, val);
  6262. if (wait_for_atomic_us((I915_READ(LCPLL_CTL) &
  6263. LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1))
  6264. DRM_ERROR("Switching back to LCPLL failed\n");
  6265. }
  6266. /* See the big comment above. */
  6267. spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
  6268. if (--dev_priv->uncore.forcewake_count == 0)
  6269. dev_priv->uncore.funcs.force_wake_put(dev_priv, FORCEWAKE_ALL);
  6270. spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
  6271. }
  6272. /*
  6273. * Package states C8 and deeper are really deep PC states that can only be
  6274. * reached when all the devices on the system allow it, so even if the graphics
  6275. * device allows PC8+, it doesn't mean the system will actually get to these
  6276. * states. Our driver only allows PC8+ when going into runtime PM.
  6277. *
  6278. * The requirements for PC8+ are that all the outputs are disabled, the power
  6279. * well is disabled and most interrupts are disabled, and these are also
  6280. * requirements for runtime PM. When these conditions are met, we manually do
  6281. * the other conditions: disable the interrupts, clocks and switch LCPLL refclk
  6282. * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard
  6283. * hang the machine.
  6284. *
  6285. * When we really reach PC8 or deeper states (not just when we allow it) we lose
  6286. * the state of some registers, so when we come back from PC8+ we need to
  6287. * restore this state. We don't get into PC8+ if we're not in RC6, so we don't
  6288. * need to take care of the registers kept by RC6. Notice that this happens even
  6289. * if we don't put the device in PCI D3 state (which is what currently happens
  6290. * because of the runtime PM support).
  6291. *
  6292. * For more, read "Display Sequences for Package C8" on the hardware
  6293. * documentation.
  6294. */
  6295. void hsw_enable_pc8(struct drm_i915_private *dev_priv)
  6296. {
  6297. struct drm_device *dev = dev_priv->dev;
  6298. uint32_t val;
  6299. DRM_DEBUG_KMS("Enabling package C8+\n");
  6300. if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) {
  6301. val = I915_READ(SOUTH_DSPCLK_GATE_D);
  6302. val &= ~PCH_LP_PARTITION_LEVEL_DISABLE;
  6303. I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
  6304. }
  6305. lpt_disable_clkout_dp(dev);
  6306. hsw_disable_lcpll(dev_priv, true, true);
  6307. }
  6308. void hsw_disable_pc8(struct drm_i915_private *dev_priv)
  6309. {
  6310. struct drm_device *dev = dev_priv->dev;
  6311. uint32_t val;
  6312. DRM_DEBUG_KMS("Disabling package C8+\n");
  6313. hsw_restore_lcpll(dev_priv);
  6314. lpt_init_pch_refclk(dev);
  6315. if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) {
  6316. val = I915_READ(SOUTH_DSPCLK_GATE_D);
  6317. val |= PCH_LP_PARTITION_LEVEL_DISABLE;
  6318. I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
  6319. }
  6320. intel_prepare_ddi(dev);
  6321. }
  6322. static void snb_modeset_global_resources(struct drm_device *dev)
  6323. {
  6324. modeset_update_crtc_power_domains(dev);
  6325. }
  6326. static void haswell_modeset_global_resources(struct drm_device *dev)
  6327. {
  6328. modeset_update_crtc_power_domains(dev);
  6329. }
  6330. static int haswell_crtc_mode_set(struct drm_crtc *crtc,
  6331. int x, int y,
  6332. struct drm_framebuffer *fb)
  6333. {
  6334. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6335. if (!intel_ddi_pll_select(intel_crtc))
  6336. return -EINVAL;
  6337. intel_ddi_pll_enable(intel_crtc);
  6338. intel_crtc->lowfreq_avail = false;
  6339. return 0;
  6340. }
  6341. static bool haswell_get_pipe_config(struct intel_crtc *crtc,
  6342. struct intel_crtc_config *pipe_config)
  6343. {
  6344. struct drm_device *dev = crtc->base.dev;
  6345. struct drm_i915_private *dev_priv = dev->dev_private;
  6346. enum intel_display_power_domain pfit_domain;
  6347. uint32_t tmp;
  6348. if (!intel_display_power_enabled(dev_priv,
  6349. POWER_DOMAIN_PIPE(crtc->pipe)))
  6350. return false;
  6351. pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
  6352. pipe_config->shared_dpll = DPLL_ID_PRIVATE;
  6353. tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
  6354. if (tmp & TRANS_DDI_FUNC_ENABLE) {
  6355. enum pipe trans_edp_pipe;
  6356. switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
  6357. default:
  6358. WARN(1, "unknown pipe linked to edp transcoder\n");
  6359. case TRANS_DDI_EDP_INPUT_A_ONOFF:
  6360. case TRANS_DDI_EDP_INPUT_A_ON:
  6361. trans_edp_pipe = PIPE_A;
  6362. break;
  6363. case TRANS_DDI_EDP_INPUT_B_ONOFF:
  6364. trans_edp_pipe = PIPE_B;
  6365. break;
  6366. case TRANS_DDI_EDP_INPUT_C_ONOFF:
  6367. trans_edp_pipe = PIPE_C;
  6368. break;
  6369. }
  6370. if (trans_edp_pipe == crtc->pipe)
  6371. pipe_config->cpu_transcoder = TRANSCODER_EDP;
  6372. }
  6373. if (!intel_display_power_enabled(dev_priv,
  6374. POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder)))
  6375. return false;
  6376. tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder));
  6377. if (!(tmp & PIPECONF_ENABLE))
  6378. return false;
  6379. /*
  6380. * Haswell has only FDI/PCH transcoder A. It is which is connected to
  6381. * DDI E. So just check whether this pipe is wired to DDI E and whether
  6382. * the PCH transcoder is on.
  6383. */
  6384. tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder));
  6385. if ((tmp & TRANS_DDI_PORT_MASK) == TRANS_DDI_SELECT_PORT(PORT_E) &&
  6386. I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) {
  6387. pipe_config->has_pch_encoder = true;
  6388. tmp = I915_READ(FDI_RX_CTL(PIPE_A));
  6389. pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
  6390. FDI_DP_PORT_WIDTH_SHIFT) + 1;
  6391. ironlake_get_fdi_m_n_config(crtc, pipe_config);
  6392. }
  6393. intel_get_pipe_timings(crtc, pipe_config);
  6394. pfit_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe);
  6395. if (intel_display_power_enabled(dev_priv, pfit_domain))
  6396. ironlake_get_pfit_config(crtc, pipe_config);
  6397. if (IS_HASWELL(dev))
  6398. pipe_config->ips_enabled = hsw_crtc_supports_ips(crtc) &&
  6399. (I915_READ(IPS_CTL) & IPS_ENABLE);
  6400. pipe_config->pixel_multiplier = 1;
  6401. return true;
  6402. }
  6403. static struct {
  6404. int clock;
  6405. u32 config;
  6406. } hdmi_audio_clock[] = {
  6407. { DIV_ROUND_UP(25200 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_25175 },
  6408. { 25200, AUD_CONFIG_PIXEL_CLOCK_HDMI_25200 }, /* default per bspec */
  6409. { 27000, AUD_CONFIG_PIXEL_CLOCK_HDMI_27000 },
  6410. { 27000 * 1001 / 1000, AUD_CONFIG_PIXEL_CLOCK_HDMI_27027 },
  6411. { 54000, AUD_CONFIG_PIXEL_CLOCK_HDMI_54000 },
  6412. { 54000 * 1001 / 1000, AUD_CONFIG_PIXEL_CLOCK_HDMI_54054 },
  6413. { DIV_ROUND_UP(74250 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_74176 },
  6414. { 74250, AUD_CONFIG_PIXEL_CLOCK_HDMI_74250 },
  6415. { DIV_ROUND_UP(148500 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_148352 },
  6416. { 148500, AUD_CONFIG_PIXEL_CLOCK_HDMI_148500 },
  6417. };
  6418. /* get AUD_CONFIG_PIXEL_CLOCK_HDMI_* value for mode */
  6419. static u32 audio_config_hdmi_pixel_clock(struct drm_display_mode *mode)
  6420. {
  6421. int i;
  6422. for (i = 0; i < ARRAY_SIZE(hdmi_audio_clock); i++) {
  6423. if (mode->clock == hdmi_audio_clock[i].clock)
  6424. break;
  6425. }
  6426. if (i == ARRAY_SIZE(hdmi_audio_clock)) {
  6427. DRM_DEBUG_KMS("HDMI audio pixel clock setting for %d not found, falling back to defaults\n", mode->clock);
  6428. i = 1;
  6429. }
  6430. DRM_DEBUG_KMS("Configuring HDMI audio for pixel clock %d (0x%08x)\n",
  6431. hdmi_audio_clock[i].clock,
  6432. hdmi_audio_clock[i].config);
  6433. return hdmi_audio_clock[i].config;
  6434. }
  6435. static bool intel_eld_uptodate(struct drm_connector *connector,
  6436. int reg_eldv, uint32_t bits_eldv,
  6437. int reg_elda, uint32_t bits_elda,
  6438. int reg_edid)
  6439. {
  6440. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  6441. uint8_t *eld = connector->eld;
  6442. uint32_t i;
  6443. i = I915_READ(reg_eldv);
  6444. i &= bits_eldv;
  6445. if (!eld[0])
  6446. return !i;
  6447. if (!i)
  6448. return false;
  6449. i = I915_READ(reg_elda);
  6450. i &= ~bits_elda;
  6451. I915_WRITE(reg_elda, i);
  6452. for (i = 0; i < eld[2]; i++)
  6453. if (I915_READ(reg_edid) != *((uint32_t *)eld + i))
  6454. return false;
  6455. return true;
  6456. }
  6457. static void g4x_write_eld(struct drm_connector *connector,
  6458. struct drm_crtc *crtc,
  6459. struct drm_display_mode *mode)
  6460. {
  6461. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  6462. uint8_t *eld = connector->eld;
  6463. uint32_t eldv;
  6464. uint32_t len;
  6465. uint32_t i;
  6466. i = I915_READ(G4X_AUD_VID_DID);
  6467. if (i == INTEL_AUDIO_DEVBLC || i == INTEL_AUDIO_DEVCL)
  6468. eldv = G4X_ELDV_DEVCL_DEVBLC;
  6469. else
  6470. eldv = G4X_ELDV_DEVCTG;
  6471. if (intel_eld_uptodate(connector,
  6472. G4X_AUD_CNTL_ST, eldv,
  6473. G4X_AUD_CNTL_ST, G4X_ELD_ADDR,
  6474. G4X_HDMIW_HDMIEDID))
  6475. return;
  6476. i = I915_READ(G4X_AUD_CNTL_ST);
  6477. i &= ~(eldv | G4X_ELD_ADDR);
  6478. len = (i >> 9) & 0x1f; /* ELD buffer size */
  6479. I915_WRITE(G4X_AUD_CNTL_ST, i);
  6480. if (!eld[0])
  6481. return;
  6482. len = min_t(uint8_t, eld[2], len);
  6483. DRM_DEBUG_DRIVER("ELD size %d\n", len);
  6484. for (i = 0; i < len; i++)
  6485. I915_WRITE(G4X_HDMIW_HDMIEDID, *((uint32_t *)eld + i));
  6486. i = I915_READ(G4X_AUD_CNTL_ST);
  6487. i |= eldv;
  6488. I915_WRITE(G4X_AUD_CNTL_ST, i);
  6489. }
  6490. static void haswell_write_eld(struct drm_connector *connector,
  6491. struct drm_crtc *crtc,
  6492. struct drm_display_mode *mode)
  6493. {
  6494. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  6495. uint8_t *eld = connector->eld;
  6496. uint32_t eldv;
  6497. uint32_t i;
  6498. int len;
  6499. int pipe = to_intel_crtc(crtc)->pipe;
  6500. int tmp;
  6501. int hdmiw_hdmiedid = HSW_AUD_EDID_DATA(pipe);
  6502. int aud_cntl_st = HSW_AUD_DIP_ELD_CTRL(pipe);
  6503. int aud_config = HSW_AUD_CFG(pipe);
  6504. int aud_cntrl_st2 = HSW_AUD_PIN_ELD_CP_VLD;
  6505. /* Audio output enable */
  6506. DRM_DEBUG_DRIVER("HDMI audio: enable codec\n");
  6507. tmp = I915_READ(aud_cntrl_st2);
  6508. tmp |= (AUDIO_OUTPUT_ENABLE_A << (pipe * 4));
  6509. I915_WRITE(aud_cntrl_st2, tmp);
  6510. POSTING_READ(aud_cntrl_st2);
  6511. assert_pipe_disabled(dev_priv, to_intel_crtc(crtc)->pipe);
  6512. /* Set ELD valid state */
  6513. tmp = I915_READ(aud_cntrl_st2);
  6514. DRM_DEBUG_DRIVER("HDMI audio: pin eld vld status=0x%08x\n", tmp);
  6515. tmp |= (AUDIO_ELD_VALID_A << (pipe * 4));
  6516. I915_WRITE(aud_cntrl_st2, tmp);
  6517. tmp = I915_READ(aud_cntrl_st2);
  6518. DRM_DEBUG_DRIVER("HDMI audio: eld vld status=0x%08x\n", tmp);
  6519. /* Enable HDMI mode */
  6520. tmp = I915_READ(aud_config);
  6521. DRM_DEBUG_DRIVER("HDMI audio: audio conf: 0x%08x\n", tmp);
  6522. /* clear N_programing_enable and N_value_index */
  6523. tmp &= ~(AUD_CONFIG_N_VALUE_INDEX | AUD_CONFIG_N_PROG_ENABLE);
  6524. I915_WRITE(aud_config, tmp);
  6525. DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe));
  6526. eldv = AUDIO_ELD_VALID_A << (pipe * 4);
  6527. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) {
  6528. DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
  6529. eld[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
  6530. I915_WRITE(aud_config, AUD_CONFIG_N_VALUE_INDEX); /* 0x1 = DP */
  6531. } else {
  6532. I915_WRITE(aud_config, audio_config_hdmi_pixel_clock(mode));
  6533. }
  6534. if (intel_eld_uptodate(connector,
  6535. aud_cntrl_st2, eldv,
  6536. aud_cntl_st, IBX_ELD_ADDRESS,
  6537. hdmiw_hdmiedid))
  6538. return;
  6539. i = I915_READ(aud_cntrl_st2);
  6540. i &= ~eldv;
  6541. I915_WRITE(aud_cntrl_st2, i);
  6542. if (!eld[0])
  6543. return;
  6544. i = I915_READ(aud_cntl_st);
  6545. i &= ~IBX_ELD_ADDRESS;
  6546. I915_WRITE(aud_cntl_st, i);
  6547. i = (i >> 29) & DIP_PORT_SEL_MASK; /* DIP_Port_Select, 0x1 = PortB */
  6548. DRM_DEBUG_DRIVER("port num:%d\n", i);
  6549. len = min_t(uint8_t, eld[2], 21); /* 84 bytes of hw ELD buffer */
  6550. DRM_DEBUG_DRIVER("ELD size %d\n", len);
  6551. for (i = 0; i < len; i++)
  6552. I915_WRITE(hdmiw_hdmiedid, *((uint32_t *)eld + i));
  6553. i = I915_READ(aud_cntrl_st2);
  6554. i |= eldv;
  6555. I915_WRITE(aud_cntrl_st2, i);
  6556. }
  6557. static void ironlake_write_eld(struct drm_connector *connector,
  6558. struct drm_crtc *crtc,
  6559. struct drm_display_mode *mode)
  6560. {
  6561. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  6562. uint8_t *eld = connector->eld;
  6563. uint32_t eldv;
  6564. uint32_t i;
  6565. int len;
  6566. int hdmiw_hdmiedid;
  6567. int aud_config;
  6568. int aud_cntl_st;
  6569. int aud_cntrl_st2;
  6570. int pipe = to_intel_crtc(crtc)->pipe;
  6571. if (HAS_PCH_IBX(connector->dev)) {
  6572. hdmiw_hdmiedid = IBX_HDMIW_HDMIEDID(pipe);
  6573. aud_config = IBX_AUD_CFG(pipe);
  6574. aud_cntl_st = IBX_AUD_CNTL_ST(pipe);
  6575. aud_cntrl_st2 = IBX_AUD_CNTL_ST2;
  6576. } else if (IS_VALLEYVIEW(connector->dev)) {
  6577. hdmiw_hdmiedid = VLV_HDMIW_HDMIEDID(pipe);
  6578. aud_config = VLV_AUD_CFG(pipe);
  6579. aud_cntl_st = VLV_AUD_CNTL_ST(pipe);
  6580. aud_cntrl_st2 = VLV_AUD_CNTL_ST2;
  6581. } else {
  6582. hdmiw_hdmiedid = CPT_HDMIW_HDMIEDID(pipe);
  6583. aud_config = CPT_AUD_CFG(pipe);
  6584. aud_cntl_st = CPT_AUD_CNTL_ST(pipe);
  6585. aud_cntrl_st2 = CPT_AUD_CNTRL_ST2;
  6586. }
  6587. DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe));
  6588. if (IS_VALLEYVIEW(connector->dev)) {
  6589. struct intel_encoder *intel_encoder;
  6590. struct intel_digital_port *intel_dig_port;
  6591. intel_encoder = intel_attached_encoder(connector);
  6592. intel_dig_port = enc_to_dig_port(&intel_encoder->base);
  6593. i = intel_dig_port->port;
  6594. } else {
  6595. i = I915_READ(aud_cntl_st);
  6596. i = (i >> 29) & DIP_PORT_SEL_MASK;
  6597. /* DIP_Port_Select, 0x1 = PortB */
  6598. }
  6599. if (!i) {
  6600. DRM_DEBUG_DRIVER("Audio directed to unknown port\n");
  6601. /* operate blindly on all ports */
  6602. eldv = IBX_ELD_VALIDB;
  6603. eldv |= IBX_ELD_VALIDB << 4;
  6604. eldv |= IBX_ELD_VALIDB << 8;
  6605. } else {
  6606. DRM_DEBUG_DRIVER("ELD on port %c\n", port_name(i));
  6607. eldv = IBX_ELD_VALIDB << ((i - 1) * 4);
  6608. }
  6609. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) {
  6610. DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
  6611. eld[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
  6612. I915_WRITE(aud_config, AUD_CONFIG_N_VALUE_INDEX); /* 0x1 = DP */
  6613. } else {
  6614. I915_WRITE(aud_config, audio_config_hdmi_pixel_clock(mode));
  6615. }
  6616. if (intel_eld_uptodate(connector,
  6617. aud_cntrl_st2, eldv,
  6618. aud_cntl_st, IBX_ELD_ADDRESS,
  6619. hdmiw_hdmiedid))
  6620. return;
  6621. i = I915_READ(aud_cntrl_st2);
  6622. i &= ~eldv;
  6623. I915_WRITE(aud_cntrl_st2, i);
  6624. if (!eld[0])
  6625. return;
  6626. i = I915_READ(aud_cntl_st);
  6627. i &= ~IBX_ELD_ADDRESS;
  6628. I915_WRITE(aud_cntl_st, i);
  6629. len = min_t(uint8_t, eld[2], 21); /* 84 bytes of hw ELD buffer */
  6630. DRM_DEBUG_DRIVER("ELD size %d\n", len);
  6631. for (i = 0; i < len; i++)
  6632. I915_WRITE(hdmiw_hdmiedid, *((uint32_t *)eld + i));
  6633. i = I915_READ(aud_cntrl_st2);
  6634. i |= eldv;
  6635. I915_WRITE(aud_cntrl_st2, i);
  6636. }
  6637. void intel_write_eld(struct drm_encoder *encoder,
  6638. struct drm_display_mode *mode)
  6639. {
  6640. struct drm_crtc *crtc = encoder->crtc;
  6641. struct drm_connector *connector;
  6642. struct drm_device *dev = encoder->dev;
  6643. struct drm_i915_private *dev_priv = dev->dev_private;
  6644. connector = drm_select_eld(encoder, mode);
  6645. if (!connector)
  6646. return;
  6647. DRM_DEBUG_DRIVER("ELD on [CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
  6648. connector->base.id,
  6649. connector->name,
  6650. connector->encoder->base.id,
  6651. connector->encoder->name);
  6652. connector->eld[6] = drm_av_sync_delay(connector, mode) / 2;
  6653. if (dev_priv->display.write_eld)
  6654. dev_priv->display.write_eld(connector, crtc, mode);
  6655. }
  6656. static void i845_update_cursor(struct drm_crtc *crtc, u32 base)
  6657. {
  6658. struct drm_device *dev = crtc->dev;
  6659. struct drm_i915_private *dev_priv = dev->dev_private;
  6660. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6661. uint32_t cntl;
  6662. if (base != intel_crtc->cursor_base) {
  6663. /* On these chipsets we can only modify the base whilst
  6664. * the cursor is disabled.
  6665. */
  6666. if (intel_crtc->cursor_cntl) {
  6667. I915_WRITE(_CURACNTR, 0);
  6668. POSTING_READ(_CURACNTR);
  6669. intel_crtc->cursor_cntl = 0;
  6670. }
  6671. I915_WRITE(_CURABASE, base);
  6672. POSTING_READ(_CURABASE);
  6673. }
  6674. /* XXX width must be 64, stride 256 => 0x00 << 28 */
  6675. cntl = 0;
  6676. if (base)
  6677. cntl = (CURSOR_ENABLE |
  6678. CURSOR_GAMMA_ENABLE |
  6679. CURSOR_FORMAT_ARGB);
  6680. if (intel_crtc->cursor_cntl != cntl) {
  6681. I915_WRITE(_CURACNTR, cntl);
  6682. POSTING_READ(_CURACNTR);
  6683. intel_crtc->cursor_cntl = cntl;
  6684. }
  6685. }
  6686. static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base)
  6687. {
  6688. struct drm_device *dev = crtc->dev;
  6689. struct drm_i915_private *dev_priv = dev->dev_private;
  6690. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6691. int pipe = intel_crtc->pipe;
  6692. uint32_t cntl;
  6693. cntl = 0;
  6694. if (base) {
  6695. cntl = MCURSOR_GAMMA_ENABLE;
  6696. switch (intel_crtc->cursor_width) {
  6697. case 64:
  6698. cntl |= CURSOR_MODE_64_ARGB_AX;
  6699. break;
  6700. case 128:
  6701. cntl |= CURSOR_MODE_128_ARGB_AX;
  6702. break;
  6703. case 256:
  6704. cntl |= CURSOR_MODE_256_ARGB_AX;
  6705. break;
  6706. default:
  6707. WARN_ON(1);
  6708. return;
  6709. }
  6710. cntl |= pipe << 28; /* Connect to correct pipe */
  6711. }
  6712. if (intel_crtc->cursor_cntl != cntl) {
  6713. I915_WRITE(CURCNTR(pipe), cntl);
  6714. POSTING_READ(CURCNTR(pipe));
  6715. intel_crtc->cursor_cntl = cntl;
  6716. }
  6717. /* and commit changes on next vblank */
  6718. I915_WRITE(CURBASE(pipe), base);
  6719. POSTING_READ(CURBASE(pipe));
  6720. }
  6721. static void ivb_update_cursor(struct drm_crtc *crtc, u32 base)
  6722. {
  6723. struct drm_device *dev = crtc->dev;
  6724. struct drm_i915_private *dev_priv = dev->dev_private;
  6725. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6726. int pipe = intel_crtc->pipe;
  6727. uint32_t cntl;
  6728. cntl = 0;
  6729. if (base) {
  6730. cntl = MCURSOR_GAMMA_ENABLE;
  6731. switch (intel_crtc->cursor_width) {
  6732. case 64:
  6733. cntl |= CURSOR_MODE_64_ARGB_AX;
  6734. break;
  6735. case 128:
  6736. cntl |= CURSOR_MODE_128_ARGB_AX;
  6737. break;
  6738. case 256:
  6739. cntl |= CURSOR_MODE_256_ARGB_AX;
  6740. break;
  6741. default:
  6742. WARN_ON(1);
  6743. return;
  6744. }
  6745. }
  6746. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  6747. cntl |= CURSOR_PIPE_CSC_ENABLE;
  6748. if (intel_crtc->cursor_cntl != cntl) {
  6749. I915_WRITE(CURCNTR(pipe), cntl);
  6750. POSTING_READ(CURCNTR(pipe));
  6751. intel_crtc->cursor_cntl = cntl;
  6752. }
  6753. /* and commit changes on next vblank */
  6754. I915_WRITE(CURBASE(pipe), base);
  6755. POSTING_READ(CURBASE(pipe));
  6756. }
  6757. /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */
  6758. static void intel_crtc_update_cursor(struct drm_crtc *crtc,
  6759. bool on)
  6760. {
  6761. struct drm_device *dev = crtc->dev;
  6762. struct drm_i915_private *dev_priv = dev->dev_private;
  6763. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6764. int pipe = intel_crtc->pipe;
  6765. int x = crtc->cursor_x;
  6766. int y = crtc->cursor_y;
  6767. u32 base = 0, pos = 0;
  6768. if (on)
  6769. base = intel_crtc->cursor_addr;
  6770. if (x >= intel_crtc->config.pipe_src_w)
  6771. base = 0;
  6772. if (y >= intel_crtc->config.pipe_src_h)
  6773. base = 0;
  6774. if (x < 0) {
  6775. if (x + intel_crtc->cursor_width <= 0)
  6776. base = 0;
  6777. pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
  6778. x = -x;
  6779. }
  6780. pos |= x << CURSOR_X_SHIFT;
  6781. if (y < 0) {
  6782. if (y + intel_crtc->cursor_height <= 0)
  6783. base = 0;
  6784. pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
  6785. y = -y;
  6786. }
  6787. pos |= y << CURSOR_Y_SHIFT;
  6788. if (base == 0 && intel_crtc->cursor_base == 0)
  6789. return;
  6790. I915_WRITE(CURPOS(pipe), pos);
  6791. if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev) || IS_BROADWELL(dev))
  6792. ivb_update_cursor(crtc, base);
  6793. else if (IS_845G(dev) || IS_I865G(dev))
  6794. i845_update_cursor(crtc, base);
  6795. else
  6796. i9xx_update_cursor(crtc, base);
  6797. intel_crtc->cursor_base = base;
  6798. }
  6799. /*
  6800. * intel_crtc_cursor_set_obj - Set cursor to specified GEM object
  6801. *
  6802. * Note that the object's reference will be consumed if the update fails. If
  6803. * the update succeeds, the reference of the old object (if any) will be
  6804. * consumed.
  6805. */
  6806. static int intel_crtc_cursor_set_obj(struct drm_crtc *crtc,
  6807. struct drm_i915_gem_object *obj,
  6808. uint32_t width, uint32_t height)
  6809. {
  6810. struct drm_device *dev = crtc->dev;
  6811. struct drm_i915_private *dev_priv = dev->dev_private;
  6812. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6813. enum pipe pipe = intel_crtc->pipe;
  6814. unsigned old_width;
  6815. uint32_t addr;
  6816. int ret;
  6817. /* if we want to turn off the cursor ignore width and height */
  6818. if (!obj) {
  6819. DRM_DEBUG_KMS("cursor off\n");
  6820. addr = 0;
  6821. obj = NULL;
  6822. mutex_lock(&dev->struct_mutex);
  6823. goto finish;
  6824. }
  6825. /* Check for which cursor types we support */
  6826. if (!((width == 64 && height == 64) ||
  6827. (width == 128 && height == 128 && !IS_GEN2(dev)) ||
  6828. (width == 256 && height == 256 && !IS_GEN2(dev)))) {
  6829. DRM_DEBUG("Cursor dimension not supported\n");
  6830. return -EINVAL;
  6831. }
  6832. if (obj->base.size < width * height * 4) {
  6833. DRM_DEBUG_KMS("buffer is too small\n");
  6834. ret = -ENOMEM;
  6835. goto fail;
  6836. }
  6837. /* we only need to pin inside GTT if cursor is non-phy */
  6838. mutex_lock(&dev->struct_mutex);
  6839. if (!INTEL_INFO(dev)->cursor_needs_physical) {
  6840. unsigned alignment;
  6841. if (obj->tiling_mode) {
  6842. DRM_DEBUG_KMS("cursor cannot be tiled\n");
  6843. ret = -EINVAL;
  6844. goto fail_locked;
  6845. }
  6846. /* Note that the w/a also requires 2 PTE of padding following
  6847. * the bo. We currently fill all unused PTE with the shadow
  6848. * page and so we should always have valid PTE following the
  6849. * cursor preventing the VT-d warning.
  6850. */
  6851. alignment = 0;
  6852. if (need_vtd_wa(dev))
  6853. alignment = 64*1024;
  6854. ret = i915_gem_object_pin_to_display_plane(obj, alignment, NULL);
  6855. if (ret) {
  6856. DRM_DEBUG_KMS("failed to move cursor bo into the GTT\n");
  6857. goto fail_locked;
  6858. }
  6859. ret = i915_gem_object_put_fence(obj);
  6860. if (ret) {
  6861. DRM_DEBUG_KMS("failed to release fence for cursor");
  6862. goto fail_unpin;
  6863. }
  6864. addr = i915_gem_obj_ggtt_offset(obj);
  6865. } else {
  6866. int align = IS_I830(dev) ? 16 * 1024 : 256;
  6867. ret = i915_gem_object_attach_phys(obj, align);
  6868. if (ret) {
  6869. DRM_DEBUG_KMS("failed to attach phys object\n");
  6870. goto fail_locked;
  6871. }
  6872. addr = obj->phys_handle->busaddr;
  6873. }
  6874. if (IS_GEN2(dev))
  6875. I915_WRITE(CURSIZE, (height << 12) | width);
  6876. finish:
  6877. if (intel_crtc->cursor_bo) {
  6878. if (!INTEL_INFO(dev)->cursor_needs_physical)
  6879. i915_gem_object_unpin_from_display_plane(intel_crtc->cursor_bo);
  6880. }
  6881. i915_gem_track_fb(intel_crtc->cursor_bo, obj,
  6882. INTEL_FRONTBUFFER_CURSOR(pipe));
  6883. mutex_unlock(&dev->struct_mutex);
  6884. old_width = intel_crtc->cursor_width;
  6885. intel_crtc->cursor_addr = addr;
  6886. intel_crtc->cursor_bo = obj;
  6887. intel_crtc->cursor_width = width;
  6888. intel_crtc->cursor_height = height;
  6889. if (intel_crtc->active) {
  6890. if (old_width != width)
  6891. intel_update_watermarks(crtc);
  6892. intel_crtc_update_cursor(crtc, intel_crtc->cursor_bo != NULL);
  6893. }
  6894. intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_CURSOR(pipe));
  6895. return 0;
  6896. fail_unpin:
  6897. i915_gem_object_unpin_from_display_plane(obj);
  6898. fail_locked:
  6899. mutex_unlock(&dev->struct_mutex);
  6900. fail:
  6901. drm_gem_object_unreference_unlocked(&obj->base);
  6902. return ret;
  6903. }
  6904. static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
  6905. u16 *blue, uint32_t start, uint32_t size)
  6906. {
  6907. int end = (start + size > 256) ? 256 : start + size, i;
  6908. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6909. for (i = start; i < end; i++) {
  6910. intel_crtc->lut_r[i] = red[i] >> 8;
  6911. intel_crtc->lut_g[i] = green[i] >> 8;
  6912. intel_crtc->lut_b[i] = blue[i] >> 8;
  6913. }
  6914. intel_crtc_load_lut(crtc);
  6915. }
  6916. /* VESA 640x480x72Hz mode to set on the pipe */
  6917. static struct drm_display_mode load_detect_mode = {
  6918. DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
  6919. 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  6920. };
  6921. struct drm_framebuffer *
  6922. __intel_framebuffer_create(struct drm_device *dev,
  6923. struct drm_mode_fb_cmd2 *mode_cmd,
  6924. struct drm_i915_gem_object *obj)
  6925. {
  6926. struct intel_framebuffer *intel_fb;
  6927. int ret;
  6928. intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
  6929. if (!intel_fb) {
  6930. drm_gem_object_unreference_unlocked(&obj->base);
  6931. return ERR_PTR(-ENOMEM);
  6932. }
  6933. ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj);
  6934. if (ret)
  6935. goto err;
  6936. return &intel_fb->base;
  6937. err:
  6938. drm_gem_object_unreference_unlocked(&obj->base);
  6939. kfree(intel_fb);
  6940. return ERR_PTR(ret);
  6941. }
  6942. static struct drm_framebuffer *
  6943. intel_framebuffer_create(struct drm_device *dev,
  6944. struct drm_mode_fb_cmd2 *mode_cmd,
  6945. struct drm_i915_gem_object *obj)
  6946. {
  6947. struct drm_framebuffer *fb;
  6948. int ret;
  6949. ret = i915_mutex_lock_interruptible(dev);
  6950. if (ret)
  6951. return ERR_PTR(ret);
  6952. fb = __intel_framebuffer_create(dev, mode_cmd, obj);
  6953. mutex_unlock(&dev->struct_mutex);
  6954. return fb;
  6955. }
  6956. static u32
  6957. intel_framebuffer_pitch_for_width(int width, int bpp)
  6958. {
  6959. u32 pitch = DIV_ROUND_UP(width * bpp, 8);
  6960. return ALIGN(pitch, 64);
  6961. }
  6962. static u32
  6963. intel_framebuffer_size_for_mode(struct drm_display_mode *mode, int bpp)
  6964. {
  6965. u32 pitch = intel_framebuffer_pitch_for_width(mode->hdisplay, bpp);
  6966. return PAGE_ALIGN(pitch * mode->vdisplay);
  6967. }
  6968. static struct drm_framebuffer *
  6969. intel_framebuffer_create_for_mode(struct drm_device *dev,
  6970. struct drm_display_mode *mode,
  6971. int depth, int bpp)
  6972. {
  6973. struct drm_i915_gem_object *obj;
  6974. struct drm_mode_fb_cmd2 mode_cmd = { 0 };
  6975. obj = i915_gem_alloc_object(dev,
  6976. intel_framebuffer_size_for_mode(mode, bpp));
  6977. if (obj == NULL)
  6978. return ERR_PTR(-ENOMEM);
  6979. mode_cmd.width = mode->hdisplay;
  6980. mode_cmd.height = mode->vdisplay;
  6981. mode_cmd.pitches[0] = intel_framebuffer_pitch_for_width(mode_cmd.width,
  6982. bpp);
  6983. mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth);
  6984. return intel_framebuffer_create(dev, &mode_cmd, obj);
  6985. }
  6986. static struct drm_framebuffer *
  6987. mode_fits_in_fbdev(struct drm_device *dev,
  6988. struct drm_display_mode *mode)
  6989. {
  6990. #ifdef CONFIG_DRM_I915_FBDEV
  6991. struct drm_i915_private *dev_priv = dev->dev_private;
  6992. struct drm_i915_gem_object *obj;
  6993. struct drm_framebuffer *fb;
  6994. if (!dev_priv->fbdev)
  6995. return NULL;
  6996. if (!dev_priv->fbdev->fb)
  6997. return NULL;
  6998. obj = dev_priv->fbdev->fb->obj;
  6999. BUG_ON(!obj);
  7000. fb = &dev_priv->fbdev->fb->base;
  7001. if (fb->pitches[0] < intel_framebuffer_pitch_for_width(mode->hdisplay,
  7002. fb->bits_per_pixel))
  7003. return NULL;
  7004. if (obj->base.size < mode->vdisplay * fb->pitches[0])
  7005. return NULL;
  7006. return fb;
  7007. #else
  7008. return NULL;
  7009. #endif
  7010. }
  7011. bool intel_get_load_detect_pipe(struct drm_connector *connector,
  7012. struct drm_display_mode *mode,
  7013. struct intel_load_detect_pipe *old,
  7014. struct drm_modeset_acquire_ctx *ctx)
  7015. {
  7016. struct intel_crtc *intel_crtc;
  7017. struct intel_encoder *intel_encoder =
  7018. intel_attached_encoder(connector);
  7019. struct drm_crtc *possible_crtc;
  7020. struct drm_encoder *encoder = &intel_encoder->base;
  7021. struct drm_crtc *crtc = NULL;
  7022. struct drm_device *dev = encoder->dev;
  7023. struct drm_framebuffer *fb;
  7024. struct drm_mode_config *config = &dev->mode_config;
  7025. int ret, i = -1;
  7026. DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
  7027. connector->base.id, connector->name,
  7028. encoder->base.id, encoder->name);
  7029. drm_modeset_acquire_init(ctx, 0);
  7030. retry:
  7031. ret = drm_modeset_lock(&config->connection_mutex, ctx);
  7032. if (ret)
  7033. goto fail_unlock;
  7034. /*
  7035. * Algorithm gets a little messy:
  7036. *
  7037. * - if the connector already has an assigned crtc, use it (but make
  7038. * sure it's on first)
  7039. *
  7040. * - try to find the first unused crtc that can drive this connector,
  7041. * and use that if we find one
  7042. */
  7043. /* See if we already have a CRTC for this connector */
  7044. if (encoder->crtc) {
  7045. crtc = encoder->crtc;
  7046. ret = drm_modeset_lock(&crtc->mutex, ctx);
  7047. if (ret)
  7048. goto fail_unlock;
  7049. old->dpms_mode = connector->dpms;
  7050. old->load_detect_temp = false;
  7051. /* Make sure the crtc and connector are running */
  7052. if (connector->dpms != DRM_MODE_DPMS_ON)
  7053. connector->funcs->dpms(connector, DRM_MODE_DPMS_ON);
  7054. return true;
  7055. }
  7056. /* Find an unused one (if possible) */
  7057. for_each_crtc(dev, possible_crtc) {
  7058. i++;
  7059. if (!(encoder->possible_crtcs & (1 << i)))
  7060. continue;
  7061. if (!possible_crtc->enabled) {
  7062. crtc = possible_crtc;
  7063. break;
  7064. }
  7065. }
  7066. /*
  7067. * If we didn't find an unused CRTC, don't use any.
  7068. */
  7069. if (!crtc) {
  7070. DRM_DEBUG_KMS("no pipe available for load-detect\n");
  7071. goto fail_unlock;
  7072. }
  7073. ret = drm_modeset_lock(&crtc->mutex, ctx);
  7074. if (ret)
  7075. goto fail_unlock;
  7076. intel_encoder->new_crtc = to_intel_crtc(crtc);
  7077. to_intel_connector(connector)->new_encoder = intel_encoder;
  7078. intel_crtc = to_intel_crtc(crtc);
  7079. intel_crtc->new_enabled = true;
  7080. intel_crtc->new_config = &intel_crtc->config;
  7081. old->dpms_mode = connector->dpms;
  7082. old->load_detect_temp = true;
  7083. old->release_fb = NULL;
  7084. if (!mode)
  7085. mode = &load_detect_mode;
  7086. /* We need a framebuffer large enough to accommodate all accesses
  7087. * that the plane may generate whilst we perform load detection.
  7088. * We can not rely on the fbcon either being present (we get called
  7089. * during its initialisation to detect all boot displays, or it may
  7090. * not even exist) or that it is large enough to satisfy the
  7091. * requested mode.
  7092. */
  7093. fb = mode_fits_in_fbdev(dev, mode);
  7094. if (fb == NULL) {
  7095. DRM_DEBUG_KMS("creating tmp fb for load-detection\n");
  7096. fb = intel_framebuffer_create_for_mode(dev, mode, 24, 32);
  7097. old->release_fb = fb;
  7098. } else
  7099. DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n");
  7100. if (IS_ERR(fb)) {
  7101. DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n");
  7102. goto fail;
  7103. }
  7104. if (intel_set_mode(crtc, mode, 0, 0, fb)) {
  7105. DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
  7106. if (old->release_fb)
  7107. old->release_fb->funcs->destroy(old->release_fb);
  7108. goto fail;
  7109. }
  7110. /* let the connector get through one full cycle before testing */
  7111. intel_wait_for_vblank(dev, intel_crtc->pipe);
  7112. return true;
  7113. fail:
  7114. intel_crtc->new_enabled = crtc->enabled;
  7115. if (intel_crtc->new_enabled)
  7116. intel_crtc->new_config = &intel_crtc->config;
  7117. else
  7118. intel_crtc->new_config = NULL;
  7119. fail_unlock:
  7120. if (ret == -EDEADLK) {
  7121. drm_modeset_backoff(ctx);
  7122. goto retry;
  7123. }
  7124. drm_modeset_drop_locks(ctx);
  7125. drm_modeset_acquire_fini(ctx);
  7126. return false;
  7127. }
  7128. void intel_release_load_detect_pipe(struct drm_connector *connector,
  7129. struct intel_load_detect_pipe *old,
  7130. struct drm_modeset_acquire_ctx *ctx)
  7131. {
  7132. struct intel_encoder *intel_encoder =
  7133. intel_attached_encoder(connector);
  7134. struct drm_encoder *encoder = &intel_encoder->base;
  7135. struct drm_crtc *crtc = encoder->crtc;
  7136. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7137. DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
  7138. connector->base.id, connector->name,
  7139. encoder->base.id, encoder->name);
  7140. if (old->load_detect_temp) {
  7141. to_intel_connector(connector)->new_encoder = NULL;
  7142. intel_encoder->new_crtc = NULL;
  7143. intel_crtc->new_enabled = false;
  7144. intel_crtc->new_config = NULL;
  7145. intel_set_mode(crtc, NULL, 0, 0, NULL);
  7146. if (old->release_fb) {
  7147. drm_framebuffer_unregister_private(old->release_fb);
  7148. drm_framebuffer_unreference(old->release_fb);
  7149. }
  7150. goto unlock;
  7151. return;
  7152. }
  7153. /* Switch crtc and encoder back off if necessary */
  7154. if (old->dpms_mode != DRM_MODE_DPMS_ON)
  7155. connector->funcs->dpms(connector, old->dpms_mode);
  7156. unlock:
  7157. drm_modeset_drop_locks(ctx);
  7158. drm_modeset_acquire_fini(ctx);
  7159. }
  7160. static int i9xx_pll_refclk(struct drm_device *dev,
  7161. const struct intel_crtc_config *pipe_config)
  7162. {
  7163. struct drm_i915_private *dev_priv = dev->dev_private;
  7164. u32 dpll = pipe_config->dpll_hw_state.dpll;
  7165. if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN)
  7166. return dev_priv->vbt.lvds_ssc_freq;
  7167. else if (HAS_PCH_SPLIT(dev))
  7168. return 120000;
  7169. else if (!IS_GEN2(dev))
  7170. return 96000;
  7171. else
  7172. return 48000;
  7173. }
  7174. /* Returns the clock of the currently programmed mode of the given pipe. */
  7175. static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
  7176. struct intel_crtc_config *pipe_config)
  7177. {
  7178. struct drm_device *dev = crtc->base.dev;
  7179. struct drm_i915_private *dev_priv = dev->dev_private;
  7180. int pipe = pipe_config->cpu_transcoder;
  7181. u32 dpll = pipe_config->dpll_hw_state.dpll;
  7182. u32 fp;
  7183. intel_clock_t clock;
  7184. int refclk = i9xx_pll_refclk(dev, pipe_config);
  7185. if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
  7186. fp = pipe_config->dpll_hw_state.fp0;
  7187. else
  7188. fp = pipe_config->dpll_hw_state.fp1;
  7189. clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
  7190. if (IS_PINEVIEW(dev)) {
  7191. clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
  7192. clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
  7193. } else {
  7194. clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
  7195. clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
  7196. }
  7197. if (!IS_GEN2(dev)) {
  7198. if (IS_PINEVIEW(dev))
  7199. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
  7200. DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
  7201. else
  7202. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
  7203. DPLL_FPA01_P1_POST_DIV_SHIFT);
  7204. switch (dpll & DPLL_MODE_MASK) {
  7205. case DPLLB_MODE_DAC_SERIAL:
  7206. clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
  7207. 5 : 10;
  7208. break;
  7209. case DPLLB_MODE_LVDS:
  7210. clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
  7211. 7 : 14;
  7212. break;
  7213. default:
  7214. DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
  7215. "mode\n", (int)(dpll & DPLL_MODE_MASK));
  7216. return;
  7217. }
  7218. if (IS_PINEVIEW(dev))
  7219. pineview_clock(refclk, &clock);
  7220. else
  7221. i9xx_clock(refclk, &clock);
  7222. } else {
  7223. u32 lvds = IS_I830(dev) ? 0 : I915_READ(LVDS);
  7224. bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN);
  7225. if (is_lvds) {
  7226. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
  7227. DPLL_FPA01_P1_POST_DIV_SHIFT);
  7228. if (lvds & LVDS_CLKB_POWER_UP)
  7229. clock.p2 = 7;
  7230. else
  7231. clock.p2 = 14;
  7232. } else {
  7233. if (dpll & PLL_P1_DIVIDE_BY_TWO)
  7234. clock.p1 = 2;
  7235. else {
  7236. clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
  7237. DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
  7238. }
  7239. if (dpll & PLL_P2_DIVIDE_BY_4)
  7240. clock.p2 = 4;
  7241. else
  7242. clock.p2 = 2;
  7243. }
  7244. i9xx_clock(refclk, &clock);
  7245. }
  7246. /*
  7247. * This value includes pixel_multiplier. We will use
  7248. * port_clock to compute adjusted_mode.crtc_clock in the
  7249. * encoder's get_config() function.
  7250. */
  7251. pipe_config->port_clock = clock.dot;
  7252. }
  7253. int intel_dotclock_calculate(int link_freq,
  7254. const struct intel_link_m_n *m_n)
  7255. {
  7256. /*
  7257. * The calculation for the data clock is:
  7258. * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
  7259. * But we want to avoid losing precison if possible, so:
  7260. * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
  7261. *
  7262. * and the link clock is simpler:
  7263. * link_clock = (m * link_clock) / n
  7264. */
  7265. if (!m_n->link_n)
  7266. return 0;
  7267. return div_u64((u64)m_n->link_m * link_freq, m_n->link_n);
  7268. }
  7269. static void ironlake_pch_clock_get(struct intel_crtc *crtc,
  7270. struct intel_crtc_config *pipe_config)
  7271. {
  7272. struct drm_device *dev = crtc->base.dev;
  7273. /* read out port_clock from the DPLL */
  7274. i9xx_crtc_clock_get(crtc, pipe_config);
  7275. /*
  7276. * This value does not include pixel_multiplier.
  7277. * We will check that port_clock and adjusted_mode.crtc_clock
  7278. * agree once we know their relationship in the encoder's
  7279. * get_config() function.
  7280. */
  7281. pipe_config->adjusted_mode.crtc_clock =
  7282. intel_dotclock_calculate(intel_fdi_link_freq(dev) * 10000,
  7283. &pipe_config->fdi_m_n);
  7284. }
  7285. /** Returns the currently programmed mode of the given pipe. */
  7286. struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev,
  7287. struct drm_crtc *crtc)
  7288. {
  7289. struct drm_i915_private *dev_priv = dev->dev_private;
  7290. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7291. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  7292. struct drm_display_mode *mode;
  7293. struct intel_crtc_config pipe_config;
  7294. int htot = I915_READ(HTOTAL(cpu_transcoder));
  7295. int hsync = I915_READ(HSYNC(cpu_transcoder));
  7296. int vtot = I915_READ(VTOTAL(cpu_transcoder));
  7297. int vsync = I915_READ(VSYNC(cpu_transcoder));
  7298. enum pipe pipe = intel_crtc->pipe;
  7299. mode = kzalloc(sizeof(*mode), GFP_KERNEL);
  7300. if (!mode)
  7301. return NULL;
  7302. /*
  7303. * Construct a pipe_config sufficient for getting the clock info
  7304. * back out of crtc_clock_get.
  7305. *
  7306. * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need
  7307. * to use a real value here instead.
  7308. */
  7309. pipe_config.cpu_transcoder = (enum transcoder) pipe;
  7310. pipe_config.pixel_multiplier = 1;
  7311. pipe_config.dpll_hw_state.dpll = I915_READ(DPLL(pipe));
  7312. pipe_config.dpll_hw_state.fp0 = I915_READ(FP0(pipe));
  7313. pipe_config.dpll_hw_state.fp1 = I915_READ(FP1(pipe));
  7314. i9xx_crtc_clock_get(intel_crtc, &pipe_config);
  7315. mode->clock = pipe_config.port_clock / pipe_config.pixel_multiplier;
  7316. mode->hdisplay = (htot & 0xffff) + 1;
  7317. mode->htotal = ((htot & 0xffff0000) >> 16) + 1;
  7318. mode->hsync_start = (hsync & 0xffff) + 1;
  7319. mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1;
  7320. mode->vdisplay = (vtot & 0xffff) + 1;
  7321. mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1;
  7322. mode->vsync_start = (vsync & 0xffff) + 1;
  7323. mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1;
  7324. drm_mode_set_name(mode);
  7325. return mode;
  7326. }
  7327. static void intel_increase_pllclock(struct drm_device *dev,
  7328. enum pipe pipe)
  7329. {
  7330. struct drm_i915_private *dev_priv = dev->dev_private;
  7331. int dpll_reg = DPLL(pipe);
  7332. int dpll;
  7333. if (HAS_PCH_SPLIT(dev))
  7334. return;
  7335. if (!dev_priv->lvds_downclock_avail)
  7336. return;
  7337. dpll = I915_READ(dpll_reg);
  7338. if (!HAS_PIPE_CXSR(dev) && (dpll & DISPLAY_RATE_SELECT_FPA1)) {
  7339. DRM_DEBUG_DRIVER("upclocking LVDS\n");
  7340. assert_panel_unlocked(dev_priv, pipe);
  7341. dpll &= ~DISPLAY_RATE_SELECT_FPA1;
  7342. I915_WRITE(dpll_reg, dpll);
  7343. intel_wait_for_vblank(dev, pipe);
  7344. dpll = I915_READ(dpll_reg);
  7345. if (dpll & DISPLAY_RATE_SELECT_FPA1)
  7346. DRM_DEBUG_DRIVER("failed to upclock LVDS!\n");
  7347. }
  7348. }
  7349. static void intel_decrease_pllclock(struct drm_crtc *crtc)
  7350. {
  7351. struct drm_device *dev = crtc->dev;
  7352. struct drm_i915_private *dev_priv = dev->dev_private;
  7353. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7354. if (HAS_PCH_SPLIT(dev))
  7355. return;
  7356. if (!dev_priv->lvds_downclock_avail)
  7357. return;
  7358. /*
  7359. * Since this is called by a timer, we should never get here in
  7360. * the manual case.
  7361. */
  7362. if (!HAS_PIPE_CXSR(dev) && intel_crtc->lowfreq_avail) {
  7363. int pipe = intel_crtc->pipe;
  7364. int dpll_reg = DPLL(pipe);
  7365. int dpll;
  7366. DRM_DEBUG_DRIVER("downclocking LVDS\n");
  7367. assert_panel_unlocked(dev_priv, pipe);
  7368. dpll = I915_READ(dpll_reg);
  7369. dpll |= DISPLAY_RATE_SELECT_FPA1;
  7370. I915_WRITE(dpll_reg, dpll);
  7371. intel_wait_for_vblank(dev, pipe);
  7372. dpll = I915_READ(dpll_reg);
  7373. if (!(dpll & DISPLAY_RATE_SELECT_FPA1))
  7374. DRM_DEBUG_DRIVER("failed to downclock LVDS!\n");
  7375. }
  7376. }
  7377. void intel_mark_busy(struct drm_device *dev)
  7378. {
  7379. struct drm_i915_private *dev_priv = dev->dev_private;
  7380. if (dev_priv->mm.busy)
  7381. return;
  7382. intel_runtime_pm_get(dev_priv);
  7383. i915_update_gfx_val(dev_priv);
  7384. dev_priv->mm.busy = true;
  7385. }
  7386. void intel_mark_idle(struct drm_device *dev)
  7387. {
  7388. struct drm_i915_private *dev_priv = dev->dev_private;
  7389. struct drm_crtc *crtc;
  7390. if (!dev_priv->mm.busy)
  7391. return;
  7392. dev_priv->mm.busy = false;
  7393. if (!i915.powersave)
  7394. goto out;
  7395. for_each_crtc(dev, crtc) {
  7396. if (!crtc->primary->fb)
  7397. continue;
  7398. intel_decrease_pllclock(crtc);
  7399. }
  7400. if (INTEL_INFO(dev)->gen >= 6)
  7401. gen6_rps_idle(dev->dev_private);
  7402. out:
  7403. intel_runtime_pm_put(dev_priv);
  7404. }
  7405. /**
  7406. * intel_mark_fb_busy - mark given planes as busy
  7407. * @dev: DRM device
  7408. * @frontbuffer_bits: bits for the affected planes
  7409. * @ring: optional ring for asynchronous commands
  7410. *
  7411. * This function gets called every time the screen contents change. It can be
  7412. * used to keep e.g. the update rate at the nominal refresh rate with DRRS.
  7413. */
  7414. static void intel_mark_fb_busy(struct drm_device *dev,
  7415. unsigned frontbuffer_bits,
  7416. struct intel_engine_cs *ring)
  7417. {
  7418. enum pipe pipe;
  7419. if (!i915.powersave)
  7420. return;
  7421. for_each_pipe(pipe) {
  7422. if (!(frontbuffer_bits & INTEL_FRONTBUFFER_ALL_MASK(pipe)))
  7423. continue;
  7424. intel_increase_pllclock(dev, pipe);
  7425. if (ring && intel_fbc_enabled(dev))
  7426. ring->fbc_dirty = true;
  7427. }
  7428. }
  7429. /**
  7430. * intel_fb_obj_invalidate - invalidate frontbuffer object
  7431. * @obj: GEM object to invalidate
  7432. * @ring: set for asynchronous rendering
  7433. *
  7434. * This function gets called every time rendering on the given object starts and
  7435. * frontbuffer caching (fbc, low refresh rate for DRRS, panel self refresh) must
  7436. * be invalidated. If @ring is non-NULL any subsequent invalidation will be delayed
  7437. * until the rendering completes or a flip on this frontbuffer plane is
  7438. * scheduled.
  7439. */
  7440. void intel_fb_obj_invalidate(struct drm_i915_gem_object *obj,
  7441. struct intel_engine_cs *ring)
  7442. {
  7443. struct drm_device *dev = obj->base.dev;
  7444. struct drm_i915_private *dev_priv = dev->dev_private;
  7445. WARN_ON(!mutex_is_locked(&dev->struct_mutex));
  7446. if (!obj->frontbuffer_bits)
  7447. return;
  7448. if (ring) {
  7449. mutex_lock(&dev_priv->fb_tracking.lock);
  7450. dev_priv->fb_tracking.busy_bits
  7451. |= obj->frontbuffer_bits;
  7452. dev_priv->fb_tracking.flip_bits
  7453. &= ~obj->frontbuffer_bits;
  7454. mutex_unlock(&dev_priv->fb_tracking.lock);
  7455. }
  7456. intel_mark_fb_busy(dev, obj->frontbuffer_bits, ring);
  7457. intel_edp_psr_exit(dev);
  7458. }
  7459. /**
  7460. * intel_frontbuffer_flush - flush frontbuffer
  7461. * @dev: DRM device
  7462. * @frontbuffer_bits: frontbuffer plane tracking bits
  7463. *
  7464. * This function gets called every time rendering on the given planes has
  7465. * completed and frontbuffer caching can be started again. Flushes will get
  7466. * delayed if they're blocked by some oustanding asynchronous rendering.
  7467. *
  7468. * Can be called without any locks held.
  7469. */
  7470. void intel_frontbuffer_flush(struct drm_device *dev,
  7471. unsigned frontbuffer_bits)
  7472. {
  7473. struct drm_i915_private *dev_priv = dev->dev_private;
  7474. /* Delay flushing when rings are still busy.*/
  7475. mutex_lock(&dev_priv->fb_tracking.lock);
  7476. frontbuffer_bits &= ~dev_priv->fb_tracking.busy_bits;
  7477. mutex_unlock(&dev_priv->fb_tracking.lock);
  7478. intel_mark_fb_busy(dev, frontbuffer_bits, NULL);
  7479. intel_edp_psr_exit(dev);
  7480. }
  7481. /**
  7482. * intel_fb_obj_flush - flush frontbuffer object
  7483. * @obj: GEM object to flush
  7484. * @retire: set when retiring asynchronous rendering
  7485. *
  7486. * This function gets called every time rendering on the given object has
  7487. * completed and frontbuffer caching can be started again. If @retire is true
  7488. * then any delayed flushes will be unblocked.
  7489. */
  7490. void intel_fb_obj_flush(struct drm_i915_gem_object *obj,
  7491. bool retire)
  7492. {
  7493. struct drm_device *dev = obj->base.dev;
  7494. struct drm_i915_private *dev_priv = dev->dev_private;
  7495. unsigned frontbuffer_bits;
  7496. WARN_ON(!mutex_is_locked(&dev->struct_mutex));
  7497. if (!obj->frontbuffer_bits)
  7498. return;
  7499. frontbuffer_bits = obj->frontbuffer_bits;
  7500. if (retire) {
  7501. mutex_lock(&dev_priv->fb_tracking.lock);
  7502. /* Filter out new bits since rendering started. */
  7503. frontbuffer_bits &= dev_priv->fb_tracking.busy_bits;
  7504. dev_priv->fb_tracking.busy_bits &= ~frontbuffer_bits;
  7505. mutex_unlock(&dev_priv->fb_tracking.lock);
  7506. }
  7507. intel_frontbuffer_flush(dev, frontbuffer_bits);
  7508. }
  7509. /**
  7510. * intel_frontbuffer_flip_prepare - prepare asnychronous frontbuffer flip
  7511. * @dev: DRM device
  7512. * @frontbuffer_bits: frontbuffer plane tracking bits
  7513. *
  7514. * This function gets called after scheduling a flip on @obj. The actual
  7515. * frontbuffer flushing will be delayed until completion is signalled with
  7516. * intel_frontbuffer_flip_complete. If an invalidate happens in between this
  7517. * flush will be cancelled.
  7518. *
  7519. * Can be called without any locks held.
  7520. */
  7521. void intel_frontbuffer_flip_prepare(struct drm_device *dev,
  7522. unsigned frontbuffer_bits)
  7523. {
  7524. struct drm_i915_private *dev_priv = dev->dev_private;
  7525. mutex_lock(&dev_priv->fb_tracking.lock);
  7526. dev_priv->fb_tracking.flip_bits
  7527. |= frontbuffer_bits;
  7528. mutex_unlock(&dev_priv->fb_tracking.lock);
  7529. }
  7530. /**
  7531. * intel_frontbuffer_flip_complete - complete asynchronous frontbuffer flush
  7532. * @dev: DRM device
  7533. * @frontbuffer_bits: frontbuffer plane tracking bits
  7534. *
  7535. * This function gets called after the flip has been latched and will complete
  7536. * on the next vblank. It will execute the fush if it hasn't been cancalled yet.
  7537. *
  7538. * Can be called without any locks held.
  7539. */
  7540. void intel_frontbuffer_flip_complete(struct drm_device *dev,
  7541. unsigned frontbuffer_bits)
  7542. {
  7543. struct drm_i915_private *dev_priv = dev->dev_private;
  7544. mutex_lock(&dev_priv->fb_tracking.lock);
  7545. /* Mask any cancelled flips. */
  7546. frontbuffer_bits &= dev_priv->fb_tracking.flip_bits;
  7547. dev_priv->fb_tracking.flip_bits &= ~frontbuffer_bits;
  7548. mutex_unlock(&dev_priv->fb_tracking.lock);
  7549. intel_frontbuffer_flush(dev, frontbuffer_bits);
  7550. }
  7551. static void intel_crtc_destroy(struct drm_crtc *crtc)
  7552. {
  7553. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7554. struct drm_device *dev = crtc->dev;
  7555. struct intel_unpin_work *work;
  7556. unsigned long flags;
  7557. spin_lock_irqsave(&dev->event_lock, flags);
  7558. work = intel_crtc->unpin_work;
  7559. intel_crtc->unpin_work = NULL;
  7560. spin_unlock_irqrestore(&dev->event_lock, flags);
  7561. if (work) {
  7562. cancel_work_sync(&work->work);
  7563. kfree(work);
  7564. }
  7565. drm_crtc_cleanup(crtc);
  7566. kfree(intel_crtc);
  7567. }
  7568. static void intel_unpin_work_fn(struct work_struct *__work)
  7569. {
  7570. struct intel_unpin_work *work =
  7571. container_of(__work, struct intel_unpin_work, work);
  7572. struct drm_device *dev = work->crtc->dev;
  7573. enum pipe pipe = to_intel_crtc(work->crtc)->pipe;
  7574. mutex_lock(&dev->struct_mutex);
  7575. intel_unpin_fb_obj(work->old_fb_obj);
  7576. drm_gem_object_unreference(&work->pending_flip_obj->base);
  7577. drm_gem_object_unreference(&work->old_fb_obj->base);
  7578. intel_update_fbc(dev);
  7579. mutex_unlock(&dev->struct_mutex);
  7580. intel_frontbuffer_flip_complete(dev, INTEL_FRONTBUFFER_PRIMARY(pipe));
  7581. BUG_ON(atomic_read(&to_intel_crtc(work->crtc)->unpin_work_count) == 0);
  7582. atomic_dec(&to_intel_crtc(work->crtc)->unpin_work_count);
  7583. kfree(work);
  7584. }
  7585. static void do_intel_finish_page_flip(struct drm_device *dev,
  7586. struct drm_crtc *crtc)
  7587. {
  7588. struct drm_i915_private *dev_priv = dev->dev_private;
  7589. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7590. struct intel_unpin_work *work;
  7591. unsigned long flags;
  7592. /* Ignore early vblank irqs */
  7593. if (intel_crtc == NULL)
  7594. return;
  7595. spin_lock_irqsave(&dev->event_lock, flags);
  7596. work = intel_crtc->unpin_work;
  7597. /* Ensure we don't miss a work->pending update ... */
  7598. smp_rmb();
  7599. if (work == NULL || atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) {
  7600. spin_unlock_irqrestore(&dev->event_lock, flags);
  7601. return;
  7602. }
  7603. /* and that the unpin work is consistent wrt ->pending. */
  7604. smp_rmb();
  7605. intel_crtc->unpin_work = NULL;
  7606. if (work->event)
  7607. drm_send_vblank_event(dev, intel_crtc->pipe, work->event);
  7608. drm_crtc_vblank_put(crtc);
  7609. spin_unlock_irqrestore(&dev->event_lock, flags);
  7610. wake_up_all(&dev_priv->pending_flip_queue);
  7611. queue_work(dev_priv->wq, &work->work);
  7612. trace_i915_flip_complete(intel_crtc->plane, work->pending_flip_obj);
  7613. }
  7614. void intel_finish_page_flip(struct drm_device *dev, int pipe)
  7615. {
  7616. struct drm_i915_private *dev_priv = dev->dev_private;
  7617. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  7618. do_intel_finish_page_flip(dev, crtc);
  7619. }
  7620. void intel_finish_page_flip_plane(struct drm_device *dev, int plane)
  7621. {
  7622. struct drm_i915_private *dev_priv = dev->dev_private;
  7623. struct drm_crtc *crtc = dev_priv->plane_to_crtc_mapping[plane];
  7624. do_intel_finish_page_flip(dev, crtc);
  7625. }
  7626. /* Is 'a' after or equal to 'b'? */
  7627. static bool g4x_flip_count_after_eq(u32 a, u32 b)
  7628. {
  7629. return !((a - b) & 0x80000000);
  7630. }
  7631. static bool page_flip_finished(struct intel_crtc *crtc)
  7632. {
  7633. struct drm_device *dev = crtc->base.dev;
  7634. struct drm_i915_private *dev_priv = dev->dev_private;
  7635. /*
  7636. * The relevant registers doen't exist on pre-ctg.
  7637. * As the flip done interrupt doesn't trigger for mmio
  7638. * flips on gmch platforms, a flip count check isn't
  7639. * really needed there. But since ctg has the registers,
  7640. * include it in the check anyway.
  7641. */
  7642. if (INTEL_INFO(dev)->gen < 5 && !IS_G4X(dev))
  7643. return true;
  7644. /*
  7645. * A DSPSURFLIVE check isn't enough in case the mmio and CS flips
  7646. * used the same base address. In that case the mmio flip might
  7647. * have completed, but the CS hasn't even executed the flip yet.
  7648. *
  7649. * A flip count check isn't enough as the CS might have updated
  7650. * the base address just after start of vblank, but before we
  7651. * managed to process the interrupt. This means we'd complete the
  7652. * CS flip too soon.
  7653. *
  7654. * Combining both checks should get us a good enough result. It may
  7655. * still happen that the CS flip has been executed, but has not
  7656. * yet actually completed. But in case the base address is the same
  7657. * anyway, we don't really care.
  7658. */
  7659. return (I915_READ(DSPSURFLIVE(crtc->plane)) & ~0xfff) ==
  7660. crtc->unpin_work->gtt_offset &&
  7661. g4x_flip_count_after_eq(I915_READ(PIPE_FLIPCOUNT_GM45(crtc->pipe)),
  7662. crtc->unpin_work->flip_count);
  7663. }
  7664. void intel_prepare_page_flip(struct drm_device *dev, int plane)
  7665. {
  7666. struct drm_i915_private *dev_priv = dev->dev_private;
  7667. struct intel_crtc *intel_crtc =
  7668. to_intel_crtc(dev_priv->plane_to_crtc_mapping[plane]);
  7669. unsigned long flags;
  7670. /* NB: An MMIO update of the plane base pointer will also
  7671. * generate a page-flip completion irq, i.e. every modeset
  7672. * is also accompanied by a spurious intel_prepare_page_flip().
  7673. */
  7674. spin_lock_irqsave(&dev->event_lock, flags);
  7675. if (intel_crtc->unpin_work && page_flip_finished(intel_crtc))
  7676. atomic_inc_not_zero(&intel_crtc->unpin_work->pending);
  7677. spin_unlock_irqrestore(&dev->event_lock, flags);
  7678. }
  7679. static inline void intel_mark_page_flip_active(struct intel_crtc *intel_crtc)
  7680. {
  7681. /* Ensure that the work item is consistent when activating it ... */
  7682. smp_wmb();
  7683. atomic_set(&intel_crtc->unpin_work->pending, INTEL_FLIP_PENDING);
  7684. /* and that it is marked active as soon as the irq could fire. */
  7685. smp_wmb();
  7686. }
  7687. static int intel_gen2_queue_flip(struct drm_device *dev,
  7688. struct drm_crtc *crtc,
  7689. struct drm_framebuffer *fb,
  7690. struct drm_i915_gem_object *obj,
  7691. struct intel_engine_cs *ring,
  7692. uint32_t flags)
  7693. {
  7694. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7695. u32 flip_mask;
  7696. int ret;
  7697. ret = intel_ring_begin(ring, 6);
  7698. if (ret)
  7699. return ret;
  7700. /* Can't queue multiple flips, so wait for the previous
  7701. * one to finish before executing the next.
  7702. */
  7703. if (intel_crtc->plane)
  7704. flip_mask = MI_WAIT_FOR_PLANE_B_FLIP;
  7705. else
  7706. flip_mask = MI_WAIT_FOR_PLANE_A_FLIP;
  7707. intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask);
  7708. intel_ring_emit(ring, MI_NOOP);
  7709. intel_ring_emit(ring, MI_DISPLAY_FLIP |
  7710. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  7711. intel_ring_emit(ring, fb->pitches[0]);
  7712. intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset);
  7713. intel_ring_emit(ring, 0); /* aux display base address, unused */
  7714. intel_mark_page_flip_active(intel_crtc);
  7715. __intel_ring_advance(ring);
  7716. return 0;
  7717. }
  7718. static int intel_gen3_queue_flip(struct drm_device *dev,
  7719. struct drm_crtc *crtc,
  7720. struct drm_framebuffer *fb,
  7721. struct drm_i915_gem_object *obj,
  7722. struct intel_engine_cs *ring,
  7723. uint32_t flags)
  7724. {
  7725. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7726. u32 flip_mask;
  7727. int ret;
  7728. ret = intel_ring_begin(ring, 6);
  7729. if (ret)
  7730. return ret;
  7731. if (intel_crtc->plane)
  7732. flip_mask = MI_WAIT_FOR_PLANE_B_FLIP;
  7733. else
  7734. flip_mask = MI_WAIT_FOR_PLANE_A_FLIP;
  7735. intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask);
  7736. intel_ring_emit(ring, MI_NOOP);
  7737. intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 |
  7738. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  7739. intel_ring_emit(ring, fb->pitches[0]);
  7740. intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset);
  7741. intel_ring_emit(ring, MI_NOOP);
  7742. intel_mark_page_flip_active(intel_crtc);
  7743. __intel_ring_advance(ring);
  7744. return 0;
  7745. }
  7746. static int intel_gen4_queue_flip(struct drm_device *dev,
  7747. struct drm_crtc *crtc,
  7748. struct drm_framebuffer *fb,
  7749. struct drm_i915_gem_object *obj,
  7750. struct intel_engine_cs *ring,
  7751. uint32_t flags)
  7752. {
  7753. struct drm_i915_private *dev_priv = dev->dev_private;
  7754. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7755. uint32_t pf, pipesrc;
  7756. int ret;
  7757. ret = intel_ring_begin(ring, 4);
  7758. if (ret)
  7759. return ret;
  7760. /* i965+ uses the linear or tiled offsets from the
  7761. * Display Registers (which do not change across a page-flip)
  7762. * so we need only reprogram the base address.
  7763. */
  7764. intel_ring_emit(ring, MI_DISPLAY_FLIP |
  7765. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  7766. intel_ring_emit(ring, fb->pitches[0]);
  7767. intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset |
  7768. obj->tiling_mode);
  7769. /* XXX Enabling the panel-fitter across page-flip is so far
  7770. * untested on non-native modes, so ignore it for now.
  7771. * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE;
  7772. */
  7773. pf = 0;
  7774. pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
  7775. intel_ring_emit(ring, pf | pipesrc);
  7776. intel_mark_page_flip_active(intel_crtc);
  7777. __intel_ring_advance(ring);
  7778. return 0;
  7779. }
  7780. static int intel_gen6_queue_flip(struct drm_device *dev,
  7781. struct drm_crtc *crtc,
  7782. struct drm_framebuffer *fb,
  7783. struct drm_i915_gem_object *obj,
  7784. struct intel_engine_cs *ring,
  7785. uint32_t flags)
  7786. {
  7787. struct drm_i915_private *dev_priv = dev->dev_private;
  7788. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7789. uint32_t pf, pipesrc;
  7790. int ret;
  7791. ret = intel_ring_begin(ring, 4);
  7792. if (ret)
  7793. return ret;
  7794. intel_ring_emit(ring, MI_DISPLAY_FLIP |
  7795. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  7796. intel_ring_emit(ring, fb->pitches[0] | obj->tiling_mode);
  7797. intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset);
  7798. /* Contrary to the suggestions in the documentation,
  7799. * "Enable Panel Fitter" does not seem to be required when page
  7800. * flipping with a non-native mode, and worse causes a normal
  7801. * modeset to fail.
  7802. * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE;
  7803. */
  7804. pf = 0;
  7805. pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
  7806. intel_ring_emit(ring, pf | pipesrc);
  7807. intel_mark_page_flip_active(intel_crtc);
  7808. __intel_ring_advance(ring);
  7809. return 0;
  7810. }
  7811. static int intel_gen7_queue_flip(struct drm_device *dev,
  7812. struct drm_crtc *crtc,
  7813. struct drm_framebuffer *fb,
  7814. struct drm_i915_gem_object *obj,
  7815. struct intel_engine_cs *ring,
  7816. uint32_t flags)
  7817. {
  7818. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7819. uint32_t plane_bit = 0;
  7820. int len, ret;
  7821. switch (intel_crtc->plane) {
  7822. case PLANE_A:
  7823. plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_A;
  7824. break;
  7825. case PLANE_B:
  7826. plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_B;
  7827. break;
  7828. case PLANE_C:
  7829. plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_C;
  7830. break;
  7831. default:
  7832. WARN_ONCE(1, "unknown plane in flip command\n");
  7833. return -ENODEV;
  7834. }
  7835. len = 4;
  7836. if (ring->id == RCS) {
  7837. len += 6;
  7838. /*
  7839. * On Gen 8, SRM is now taking an extra dword to accommodate
  7840. * 48bits addresses, and we need a NOOP for the batch size to
  7841. * stay even.
  7842. */
  7843. if (IS_GEN8(dev))
  7844. len += 2;
  7845. }
  7846. /*
  7847. * BSpec MI_DISPLAY_FLIP for IVB:
  7848. * "The full packet must be contained within the same cache line."
  7849. *
  7850. * Currently the LRI+SRM+MI_DISPLAY_FLIP all fit within the same
  7851. * cacheline, if we ever start emitting more commands before
  7852. * the MI_DISPLAY_FLIP we may need to first emit everything else,
  7853. * then do the cacheline alignment, and finally emit the
  7854. * MI_DISPLAY_FLIP.
  7855. */
  7856. ret = intel_ring_cacheline_align(ring);
  7857. if (ret)
  7858. return ret;
  7859. ret = intel_ring_begin(ring, len);
  7860. if (ret)
  7861. return ret;
  7862. /* Unmask the flip-done completion message. Note that the bspec says that
  7863. * we should do this for both the BCS and RCS, and that we must not unmask
  7864. * more than one flip event at any time (or ensure that one flip message
  7865. * can be sent by waiting for flip-done prior to queueing new flips).
  7866. * Experimentation says that BCS works despite DERRMR masking all
  7867. * flip-done completion events and that unmasking all planes at once
  7868. * for the RCS also doesn't appear to drop events. Setting the DERRMR
  7869. * to zero does lead to lockups within MI_DISPLAY_FLIP.
  7870. */
  7871. if (ring->id == RCS) {
  7872. intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1));
  7873. intel_ring_emit(ring, DERRMR);
  7874. intel_ring_emit(ring, ~(DERRMR_PIPEA_PRI_FLIP_DONE |
  7875. DERRMR_PIPEB_PRI_FLIP_DONE |
  7876. DERRMR_PIPEC_PRI_FLIP_DONE));
  7877. if (IS_GEN8(dev))
  7878. intel_ring_emit(ring, MI_STORE_REGISTER_MEM_GEN8(1) |
  7879. MI_SRM_LRM_GLOBAL_GTT);
  7880. else
  7881. intel_ring_emit(ring, MI_STORE_REGISTER_MEM(1) |
  7882. MI_SRM_LRM_GLOBAL_GTT);
  7883. intel_ring_emit(ring, DERRMR);
  7884. intel_ring_emit(ring, ring->scratch.gtt_offset + 256);
  7885. if (IS_GEN8(dev)) {
  7886. intel_ring_emit(ring, 0);
  7887. intel_ring_emit(ring, MI_NOOP);
  7888. }
  7889. }
  7890. intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | plane_bit);
  7891. intel_ring_emit(ring, (fb->pitches[0] | obj->tiling_mode));
  7892. intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset);
  7893. intel_ring_emit(ring, (MI_NOOP));
  7894. intel_mark_page_flip_active(intel_crtc);
  7895. __intel_ring_advance(ring);
  7896. return 0;
  7897. }
  7898. static bool use_mmio_flip(struct intel_engine_cs *ring,
  7899. struct drm_i915_gem_object *obj)
  7900. {
  7901. /*
  7902. * This is not being used for older platforms, because
  7903. * non-availability of flip done interrupt forces us to use
  7904. * CS flips. Older platforms derive flip done using some clever
  7905. * tricks involving the flip_pending status bits and vblank irqs.
  7906. * So using MMIO flips there would disrupt this mechanism.
  7907. */
  7908. if (INTEL_INFO(ring->dev)->gen < 5)
  7909. return false;
  7910. if (i915.use_mmio_flip < 0)
  7911. return false;
  7912. else if (i915.use_mmio_flip > 0)
  7913. return true;
  7914. else
  7915. return ring != obj->ring;
  7916. }
  7917. static void intel_do_mmio_flip(struct intel_crtc *intel_crtc)
  7918. {
  7919. struct drm_device *dev = intel_crtc->base.dev;
  7920. struct drm_i915_private *dev_priv = dev->dev_private;
  7921. struct intel_framebuffer *intel_fb =
  7922. to_intel_framebuffer(intel_crtc->base.primary->fb);
  7923. struct drm_i915_gem_object *obj = intel_fb->obj;
  7924. u32 dspcntr;
  7925. u32 reg;
  7926. intel_mark_page_flip_active(intel_crtc);
  7927. reg = DSPCNTR(intel_crtc->plane);
  7928. dspcntr = I915_READ(reg);
  7929. if (INTEL_INFO(dev)->gen >= 4) {
  7930. if (obj->tiling_mode != I915_TILING_NONE)
  7931. dspcntr |= DISPPLANE_TILED;
  7932. else
  7933. dspcntr &= ~DISPPLANE_TILED;
  7934. }
  7935. I915_WRITE(reg, dspcntr);
  7936. I915_WRITE(DSPSURF(intel_crtc->plane),
  7937. intel_crtc->unpin_work->gtt_offset);
  7938. POSTING_READ(DSPSURF(intel_crtc->plane));
  7939. }
  7940. static int intel_postpone_flip(struct drm_i915_gem_object *obj)
  7941. {
  7942. struct intel_engine_cs *ring;
  7943. int ret;
  7944. lockdep_assert_held(&obj->base.dev->struct_mutex);
  7945. if (!obj->last_write_seqno)
  7946. return 0;
  7947. ring = obj->ring;
  7948. if (i915_seqno_passed(ring->get_seqno(ring, true),
  7949. obj->last_write_seqno))
  7950. return 0;
  7951. ret = i915_gem_check_olr(ring, obj->last_write_seqno);
  7952. if (ret)
  7953. return ret;
  7954. if (WARN_ON(!ring->irq_get(ring)))
  7955. return 0;
  7956. return 1;
  7957. }
  7958. void intel_notify_mmio_flip(struct intel_engine_cs *ring)
  7959. {
  7960. struct drm_i915_private *dev_priv = to_i915(ring->dev);
  7961. struct intel_crtc *intel_crtc;
  7962. unsigned long irq_flags;
  7963. u32 seqno;
  7964. seqno = ring->get_seqno(ring, false);
  7965. spin_lock_irqsave(&dev_priv->mmio_flip_lock, irq_flags);
  7966. for_each_intel_crtc(ring->dev, intel_crtc) {
  7967. struct intel_mmio_flip *mmio_flip;
  7968. mmio_flip = &intel_crtc->mmio_flip;
  7969. if (mmio_flip->seqno == 0)
  7970. continue;
  7971. if (ring->id != mmio_flip->ring_id)
  7972. continue;
  7973. if (i915_seqno_passed(seqno, mmio_flip->seqno)) {
  7974. intel_do_mmio_flip(intel_crtc);
  7975. mmio_flip->seqno = 0;
  7976. ring->irq_put(ring);
  7977. }
  7978. }
  7979. spin_unlock_irqrestore(&dev_priv->mmio_flip_lock, irq_flags);
  7980. }
  7981. static int intel_queue_mmio_flip(struct drm_device *dev,
  7982. struct drm_crtc *crtc,
  7983. struct drm_framebuffer *fb,
  7984. struct drm_i915_gem_object *obj,
  7985. struct intel_engine_cs *ring,
  7986. uint32_t flags)
  7987. {
  7988. struct drm_i915_private *dev_priv = dev->dev_private;
  7989. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7990. unsigned long irq_flags;
  7991. int ret;
  7992. if (WARN_ON(intel_crtc->mmio_flip.seqno))
  7993. return -EBUSY;
  7994. ret = intel_postpone_flip(obj);
  7995. if (ret < 0)
  7996. return ret;
  7997. if (ret == 0) {
  7998. intel_do_mmio_flip(intel_crtc);
  7999. return 0;
  8000. }
  8001. spin_lock_irqsave(&dev_priv->mmio_flip_lock, irq_flags);
  8002. intel_crtc->mmio_flip.seqno = obj->last_write_seqno;
  8003. intel_crtc->mmio_flip.ring_id = obj->ring->id;
  8004. spin_unlock_irqrestore(&dev_priv->mmio_flip_lock, irq_flags);
  8005. /*
  8006. * Double check to catch cases where irq fired before
  8007. * mmio flip data was ready
  8008. */
  8009. intel_notify_mmio_flip(obj->ring);
  8010. return 0;
  8011. }
  8012. static int intel_default_queue_flip(struct drm_device *dev,
  8013. struct drm_crtc *crtc,
  8014. struct drm_framebuffer *fb,
  8015. struct drm_i915_gem_object *obj,
  8016. struct intel_engine_cs *ring,
  8017. uint32_t flags)
  8018. {
  8019. return -ENODEV;
  8020. }
  8021. static int intel_crtc_page_flip(struct drm_crtc *crtc,
  8022. struct drm_framebuffer *fb,
  8023. struct drm_pending_vblank_event *event,
  8024. uint32_t page_flip_flags)
  8025. {
  8026. struct drm_device *dev = crtc->dev;
  8027. struct drm_i915_private *dev_priv = dev->dev_private;
  8028. struct drm_framebuffer *old_fb = crtc->primary->fb;
  8029. struct drm_i915_gem_object *obj = to_intel_framebuffer(fb)->obj;
  8030. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  8031. enum pipe pipe = intel_crtc->pipe;
  8032. struct intel_unpin_work *work;
  8033. struct intel_engine_cs *ring;
  8034. unsigned long flags;
  8035. int ret;
  8036. /* Can't change pixel format via MI display flips. */
  8037. if (fb->pixel_format != crtc->primary->fb->pixel_format)
  8038. return -EINVAL;
  8039. /*
  8040. * TILEOFF/LINOFF registers can't be changed via MI display flips.
  8041. * Note that pitch changes could also affect these register.
  8042. */
  8043. if (INTEL_INFO(dev)->gen > 3 &&
  8044. (fb->offsets[0] != crtc->primary->fb->offsets[0] ||
  8045. fb->pitches[0] != crtc->primary->fb->pitches[0]))
  8046. return -EINVAL;
  8047. if (i915_terminally_wedged(&dev_priv->gpu_error))
  8048. goto out_hang;
  8049. work = kzalloc(sizeof(*work), GFP_KERNEL);
  8050. if (work == NULL)
  8051. return -ENOMEM;
  8052. work->event = event;
  8053. work->crtc = crtc;
  8054. work->old_fb_obj = to_intel_framebuffer(old_fb)->obj;
  8055. INIT_WORK(&work->work, intel_unpin_work_fn);
  8056. ret = drm_crtc_vblank_get(crtc);
  8057. if (ret)
  8058. goto free_work;
  8059. /* We borrow the event spin lock for protecting unpin_work */
  8060. spin_lock_irqsave(&dev->event_lock, flags);
  8061. if (intel_crtc->unpin_work) {
  8062. spin_unlock_irqrestore(&dev->event_lock, flags);
  8063. kfree(work);
  8064. drm_crtc_vblank_put(crtc);
  8065. DRM_DEBUG_DRIVER("flip queue: crtc already busy\n");
  8066. return -EBUSY;
  8067. }
  8068. intel_crtc->unpin_work = work;
  8069. spin_unlock_irqrestore(&dev->event_lock, flags);
  8070. if (atomic_read(&intel_crtc->unpin_work_count) >= 2)
  8071. flush_workqueue(dev_priv->wq);
  8072. ret = i915_mutex_lock_interruptible(dev);
  8073. if (ret)
  8074. goto cleanup;
  8075. /* Reference the objects for the scheduled work. */
  8076. drm_gem_object_reference(&work->old_fb_obj->base);
  8077. drm_gem_object_reference(&obj->base);
  8078. crtc->primary->fb = fb;
  8079. work->pending_flip_obj = obj;
  8080. work->enable_stall_check = true;
  8081. atomic_inc(&intel_crtc->unpin_work_count);
  8082. intel_crtc->reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter);
  8083. if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev))
  8084. work->flip_count = I915_READ(PIPE_FLIPCOUNT_GM45(pipe)) + 1;
  8085. if (IS_VALLEYVIEW(dev)) {
  8086. ring = &dev_priv->ring[BCS];
  8087. } else if (INTEL_INFO(dev)->gen >= 7) {
  8088. ring = obj->ring;
  8089. if (ring == NULL || ring->id != RCS)
  8090. ring = &dev_priv->ring[BCS];
  8091. } else {
  8092. ring = &dev_priv->ring[RCS];
  8093. }
  8094. ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
  8095. if (ret)
  8096. goto cleanup_pending;
  8097. work->gtt_offset =
  8098. i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset;
  8099. if (use_mmio_flip(ring, obj))
  8100. ret = intel_queue_mmio_flip(dev, crtc, fb, obj, ring,
  8101. page_flip_flags);
  8102. else
  8103. ret = dev_priv->display.queue_flip(dev, crtc, fb, obj, ring,
  8104. page_flip_flags);
  8105. if (ret)
  8106. goto cleanup_unpin;
  8107. i915_gem_track_fb(work->old_fb_obj, obj,
  8108. INTEL_FRONTBUFFER_PRIMARY(pipe));
  8109. intel_disable_fbc(dev);
  8110. intel_frontbuffer_flip_prepare(dev, INTEL_FRONTBUFFER_PRIMARY(pipe));
  8111. mutex_unlock(&dev->struct_mutex);
  8112. trace_i915_flip_request(intel_crtc->plane, obj);
  8113. return 0;
  8114. cleanup_unpin:
  8115. intel_unpin_fb_obj(obj);
  8116. cleanup_pending:
  8117. atomic_dec(&intel_crtc->unpin_work_count);
  8118. crtc->primary->fb = old_fb;
  8119. drm_gem_object_unreference(&work->old_fb_obj->base);
  8120. drm_gem_object_unreference(&obj->base);
  8121. mutex_unlock(&dev->struct_mutex);
  8122. cleanup:
  8123. spin_lock_irqsave(&dev->event_lock, flags);
  8124. intel_crtc->unpin_work = NULL;
  8125. spin_unlock_irqrestore(&dev->event_lock, flags);
  8126. drm_crtc_vblank_put(crtc);
  8127. free_work:
  8128. kfree(work);
  8129. if (ret == -EIO) {
  8130. out_hang:
  8131. intel_crtc_wait_for_pending_flips(crtc);
  8132. ret = intel_pipe_set_base(crtc, crtc->x, crtc->y, fb);
  8133. if (ret == 0 && event)
  8134. drm_send_vblank_event(dev, pipe, event);
  8135. }
  8136. return ret;
  8137. }
  8138. static struct drm_crtc_helper_funcs intel_helper_funcs = {
  8139. .mode_set_base_atomic = intel_pipe_set_base_atomic,
  8140. .load_lut = intel_crtc_load_lut,
  8141. };
  8142. /**
  8143. * intel_modeset_update_staged_output_state
  8144. *
  8145. * Updates the staged output configuration state, e.g. after we've read out the
  8146. * current hw state.
  8147. */
  8148. static void intel_modeset_update_staged_output_state(struct drm_device *dev)
  8149. {
  8150. struct intel_crtc *crtc;
  8151. struct intel_encoder *encoder;
  8152. struct intel_connector *connector;
  8153. list_for_each_entry(connector, &dev->mode_config.connector_list,
  8154. base.head) {
  8155. connector->new_encoder =
  8156. to_intel_encoder(connector->base.encoder);
  8157. }
  8158. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  8159. base.head) {
  8160. encoder->new_crtc =
  8161. to_intel_crtc(encoder->base.crtc);
  8162. }
  8163. for_each_intel_crtc(dev, crtc) {
  8164. crtc->new_enabled = crtc->base.enabled;
  8165. if (crtc->new_enabled)
  8166. crtc->new_config = &crtc->config;
  8167. else
  8168. crtc->new_config = NULL;
  8169. }
  8170. }
  8171. /**
  8172. * intel_modeset_commit_output_state
  8173. *
  8174. * This function copies the stage display pipe configuration to the real one.
  8175. */
  8176. static void intel_modeset_commit_output_state(struct drm_device *dev)
  8177. {
  8178. struct intel_crtc *crtc;
  8179. struct intel_encoder *encoder;
  8180. struct intel_connector *connector;
  8181. list_for_each_entry(connector, &dev->mode_config.connector_list,
  8182. base.head) {
  8183. connector->base.encoder = &connector->new_encoder->base;
  8184. }
  8185. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  8186. base.head) {
  8187. encoder->base.crtc = &encoder->new_crtc->base;
  8188. }
  8189. for_each_intel_crtc(dev, crtc) {
  8190. crtc->base.enabled = crtc->new_enabled;
  8191. }
  8192. }
  8193. static void
  8194. connected_sink_compute_bpp(struct intel_connector *connector,
  8195. struct intel_crtc_config *pipe_config)
  8196. {
  8197. int bpp = pipe_config->pipe_bpp;
  8198. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n",
  8199. connector->base.base.id,
  8200. connector->base.name);
  8201. /* Don't use an invalid EDID bpc value */
  8202. if (connector->base.display_info.bpc &&
  8203. connector->base.display_info.bpc * 3 < bpp) {
  8204. DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n",
  8205. bpp, connector->base.display_info.bpc*3);
  8206. pipe_config->pipe_bpp = connector->base.display_info.bpc*3;
  8207. }
  8208. /* Clamp bpp to 8 on screens without EDID 1.4 */
  8209. if (connector->base.display_info.bpc == 0 && bpp > 24) {
  8210. DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n",
  8211. bpp);
  8212. pipe_config->pipe_bpp = 24;
  8213. }
  8214. }
  8215. static int
  8216. compute_baseline_pipe_bpp(struct intel_crtc *crtc,
  8217. struct drm_framebuffer *fb,
  8218. struct intel_crtc_config *pipe_config)
  8219. {
  8220. struct drm_device *dev = crtc->base.dev;
  8221. struct intel_connector *connector;
  8222. int bpp;
  8223. switch (fb->pixel_format) {
  8224. case DRM_FORMAT_C8:
  8225. bpp = 8*3; /* since we go through a colormap */
  8226. break;
  8227. case DRM_FORMAT_XRGB1555:
  8228. case DRM_FORMAT_ARGB1555:
  8229. /* checked in intel_framebuffer_init already */
  8230. if (WARN_ON(INTEL_INFO(dev)->gen > 3))
  8231. return -EINVAL;
  8232. case DRM_FORMAT_RGB565:
  8233. bpp = 6*3; /* min is 18bpp */
  8234. break;
  8235. case DRM_FORMAT_XBGR8888:
  8236. case DRM_FORMAT_ABGR8888:
  8237. /* checked in intel_framebuffer_init already */
  8238. if (WARN_ON(INTEL_INFO(dev)->gen < 4))
  8239. return -EINVAL;
  8240. case DRM_FORMAT_XRGB8888:
  8241. case DRM_FORMAT_ARGB8888:
  8242. bpp = 8*3;
  8243. break;
  8244. case DRM_FORMAT_XRGB2101010:
  8245. case DRM_FORMAT_ARGB2101010:
  8246. case DRM_FORMAT_XBGR2101010:
  8247. case DRM_FORMAT_ABGR2101010:
  8248. /* checked in intel_framebuffer_init already */
  8249. if (WARN_ON(INTEL_INFO(dev)->gen < 4))
  8250. return -EINVAL;
  8251. bpp = 10*3;
  8252. break;
  8253. /* TODO: gen4+ supports 16 bpc floating point, too. */
  8254. default:
  8255. DRM_DEBUG_KMS("unsupported depth\n");
  8256. return -EINVAL;
  8257. }
  8258. pipe_config->pipe_bpp = bpp;
  8259. /* Clamp display bpp to EDID value */
  8260. list_for_each_entry(connector, &dev->mode_config.connector_list,
  8261. base.head) {
  8262. if (!connector->new_encoder ||
  8263. connector->new_encoder->new_crtc != crtc)
  8264. continue;
  8265. connected_sink_compute_bpp(connector, pipe_config);
  8266. }
  8267. return bpp;
  8268. }
  8269. static void intel_dump_crtc_timings(const struct drm_display_mode *mode)
  8270. {
  8271. DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
  8272. "type: 0x%x flags: 0x%x\n",
  8273. mode->crtc_clock,
  8274. mode->crtc_hdisplay, mode->crtc_hsync_start,
  8275. mode->crtc_hsync_end, mode->crtc_htotal,
  8276. mode->crtc_vdisplay, mode->crtc_vsync_start,
  8277. mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags);
  8278. }
  8279. static void intel_dump_pipe_config(struct intel_crtc *crtc,
  8280. struct intel_crtc_config *pipe_config,
  8281. const char *context)
  8282. {
  8283. DRM_DEBUG_KMS("[CRTC:%d]%s config for pipe %c\n", crtc->base.base.id,
  8284. context, pipe_name(crtc->pipe));
  8285. DRM_DEBUG_KMS("cpu_transcoder: %c\n", transcoder_name(pipe_config->cpu_transcoder));
  8286. DRM_DEBUG_KMS("pipe bpp: %i, dithering: %i\n",
  8287. pipe_config->pipe_bpp, pipe_config->dither);
  8288. DRM_DEBUG_KMS("fdi/pch: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
  8289. pipe_config->has_pch_encoder,
  8290. pipe_config->fdi_lanes,
  8291. pipe_config->fdi_m_n.gmch_m, pipe_config->fdi_m_n.gmch_n,
  8292. pipe_config->fdi_m_n.link_m, pipe_config->fdi_m_n.link_n,
  8293. pipe_config->fdi_m_n.tu);
  8294. DRM_DEBUG_KMS("dp: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
  8295. pipe_config->has_dp_encoder,
  8296. pipe_config->dp_m_n.gmch_m, pipe_config->dp_m_n.gmch_n,
  8297. pipe_config->dp_m_n.link_m, pipe_config->dp_m_n.link_n,
  8298. pipe_config->dp_m_n.tu);
  8299. DRM_DEBUG_KMS("requested mode:\n");
  8300. drm_mode_debug_printmodeline(&pipe_config->requested_mode);
  8301. DRM_DEBUG_KMS("adjusted mode:\n");
  8302. drm_mode_debug_printmodeline(&pipe_config->adjusted_mode);
  8303. intel_dump_crtc_timings(&pipe_config->adjusted_mode);
  8304. DRM_DEBUG_KMS("port clock: %d\n", pipe_config->port_clock);
  8305. DRM_DEBUG_KMS("pipe src size: %dx%d\n",
  8306. pipe_config->pipe_src_w, pipe_config->pipe_src_h);
  8307. DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
  8308. pipe_config->gmch_pfit.control,
  8309. pipe_config->gmch_pfit.pgm_ratios,
  8310. pipe_config->gmch_pfit.lvds_border_bits);
  8311. DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n",
  8312. pipe_config->pch_pfit.pos,
  8313. pipe_config->pch_pfit.size,
  8314. pipe_config->pch_pfit.enabled ? "enabled" : "disabled");
  8315. DRM_DEBUG_KMS("ips: %i\n", pipe_config->ips_enabled);
  8316. DRM_DEBUG_KMS("double wide: %i\n", pipe_config->double_wide);
  8317. }
  8318. static bool encoders_cloneable(const struct intel_encoder *a,
  8319. const struct intel_encoder *b)
  8320. {
  8321. /* masks could be asymmetric, so check both ways */
  8322. return a == b || (a->cloneable & (1 << b->type) &&
  8323. b->cloneable & (1 << a->type));
  8324. }
  8325. static bool check_single_encoder_cloning(struct intel_crtc *crtc,
  8326. struct intel_encoder *encoder)
  8327. {
  8328. struct drm_device *dev = crtc->base.dev;
  8329. struct intel_encoder *source_encoder;
  8330. list_for_each_entry(source_encoder,
  8331. &dev->mode_config.encoder_list, base.head) {
  8332. if (source_encoder->new_crtc != crtc)
  8333. continue;
  8334. if (!encoders_cloneable(encoder, source_encoder))
  8335. return false;
  8336. }
  8337. return true;
  8338. }
  8339. static bool check_encoder_cloning(struct intel_crtc *crtc)
  8340. {
  8341. struct drm_device *dev = crtc->base.dev;
  8342. struct intel_encoder *encoder;
  8343. list_for_each_entry(encoder,
  8344. &dev->mode_config.encoder_list, base.head) {
  8345. if (encoder->new_crtc != crtc)
  8346. continue;
  8347. if (!check_single_encoder_cloning(crtc, encoder))
  8348. return false;
  8349. }
  8350. return true;
  8351. }
  8352. static struct intel_crtc_config *
  8353. intel_modeset_pipe_config(struct drm_crtc *crtc,
  8354. struct drm_framebuffer *fb,
  8355. struct drm_display_mode *mode)
  8356. {
  8357. struct drm_device *dev = crtc->dev;
  8358. struct intel_encoder *encoder;
  8359. struct intel_crtc_config *pipe_config;
  8360. int plane_bpp, ret = -EINVAL;
  8361. bool retry = true;
  8362. if (!check_encoder_cloning(to_intel_crtc(crtc))) {
  8363. DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
  8364. return ERR_PTR(-EINVAL);
  8365. }
  8366. pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL);
  8367. if (!pipe_config)
  8368. return ERR_PTR(-ENOMEM);
  8369. drm_mode_copy(&pipe_config->adjusted_mode, mode);
  8370. drm_mode_copy(&pipe_config->requested_mode, mode);
  8371. pipe_config->cpu_transcoder =
  8372. (enum transcoder) to_intel_crtc(crtc)->pipe;
  8373. pipe_config->shared_dpll = DPLL_ID_PRIVATE;
  8374. /*
  8375. * Sanitize sync polarity flags based on requested ones. If neither
  8376. * positive or negative polarity is requested, treat this as meaning
  8377. * negative polarity.
  8378. */
  8379. if (!(pipe_config->adjusted_mode.flags &
  8380. (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC)))
  8381. pipe_config->adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC;
  8382. if (!(pipe_config->adjusted_mode.flags &
  8383. (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC)))
  8384. pipe_config->adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC;
  8385. /* Compute a starting value for pipe_config->pipe_bpp taking the source
  8386. * plane pixel format and any sink constraints into account. Returns the
  8387. * source plane bpp so that dithering can be selected on mismatches
  8388. * after encoders and crtc also have had their say. */
  8389. plane_bpp = compute_baseline_pipe_bpp(to_intel_crtc(crtc),
  8390. fb, pipe_config);
  8391. if (plane_bpp < 0)
  8392. goto fail;
  8393. /*
  8394. * Determine the real pipe dimensions. Note that stereo modes can
  8395. * increase the actual pipe size due to the frame doubling and
  8396. * insertion of additional space for blanks between the frame. This
  8397. * is stored in the crtc timings. We use the requested mode to do this
  8398. * computation to clearly distinguish it from the adjusted mode, which
  8399. * can be changed by the connectors in the below retry loop.
  8400. */
  8401. drm_mode_set_crtcinfo(&pipe_config->requested_mode, CRTC_STEREO_DOUBLE);
  8402. pipe_config->pipe_src_w = pipe_config->requested_mode.crtc_hdisplay;
  8403. pipe_config->pipe_src_h = pipe_config->requested_mode.crtc_vdisplay;
  8404. encoder_retry:
  8405. /* Ensure the port clock defaults are reset when retrying. */
  8406. pipe_config->port_clock = 0;
  8407. pipe_config->pixel_multiplier = 1;
  8408. /* Fill in default crtc timings, allow encoders to overwrite them. */
  8409. drm_mode_set_crtcinfo(&pipe_config->adjusted_mode, CRTC_STEREO_DOUBLE);
  8410. /* Pass our mode to the connectors and the CRTC to give them a chance to
  8411. * adjust it according to limitations or connector properties, and also
  8412. * a chance to reject the mode entirely.
  8413. */
  8414. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  8415. base.head) {
  8416. if (&encoder->new_crtc->base != crtc)
  8417. continue;
  8418. if (!(encoder->compute_config(encoder, pipe_config))) {
  8419. DRM_DEBUG_KMS("Encoder config failure\n");
  8420. goto fail;
  8421. }
  8422. }
  8423. /* Set default port clock if not overwritten by the encoder. Needs to be
  8424. * done afterwards in case the encoder adjusts the mode. */
  8425. if (!pipe_config->port_clock)
  8426. pipe_config->port_clock = pipe_config->adjusted_mode.crtc_clock
  8427. * pipe_config->pixel_multiplier;
  8428. ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config);
  8429. if (ret < 0) {
  8430. DRM_DEBUG_KMS("CRTC fixup failed\n");
  8431. goto fail;
  8432. }
  8433. if (ret == RETRY) {
  8434. if (WARN(!retry, "loop in pipe configuration computation\n")) {
  8435. ret = -EINVAL;
  8436. goto fail;
  8437. }
  8438. DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
  8439. retry = false;
  8440. goto encoder_retry;
  8441. }
  8442. pipe_config->dither = pipe_config->pipe_bpp != plane_bpp;
  8443. DRM_DEBUG_KMS("plane bpp: %i, pipe bpp: %i, dithering: %i\n",
  8444. plane_bpp, pipe_config->pipe_bpp, pipe_config->dither);
  8445. return pipe_config;
  8446. fail:
  8447. kfree(pipe_config);
  8448. return ERR_PTR(ret);
  8449. }
  8450. /* Computes which crtcs are affected and sets the relevant bits in the mask. For
  8451. * simplicity we use the crtc's pipe number (because it's easier to obtain). */
  8452. static void
  8453. intel_modeset_affected_pipes(struct drm_crtc *crtc, unsigned *modeset_pipes,
  8454. unsigned *prepare_pipes, unsigned *disable_pipes)
  8455. {
  8456. struct intel_crtc *intel_crtc;
  8457. struct drm_device *dev = crtc->dev;
  8458. struct intel_encoder *encoder;
  8459. struct intel_connector *connector;
  8460. struct drm_crtc *tmp_crtc;
  8461. *disable_pipes = *modeset_pipes = *prepare_pipes = 0;
  8462. /* Check which crtcs have changed outputs connected to them, these need
  8463. * to be part of the prepare_pipes mask. We don't (yet) support global
  8464. * modeset across multiple crtcs, so modeset_pipes will only have one
  8465. * bit set at most. */
  8466. list_for_each_entry(connector, &dev->mode_config.connector_list,
  8467. base.head) {
  8468. if (connector->base.encoder == &connector->new_encoder->base)
  8469. continue;
  8470. if (connector->base.encoder) {
  8471. tmp_crtc = connector->base.encoder->crtc;
  8472. *prepare_pipes |= 1 << to_intel_crtc(tmp_crtc)->pipe;
  8473. }
  8474. if (connector->new_encoder)
  8475. *prepare_pipes |=
  8476. 1 << connector->new_encoder->new_crtc->pipe;
  8477. }
  8478. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  8479. base.head) {
  8480. if (encoder->base.crtc == &encoder->new_crtc->base)
  8481. continue;
  8482. if (encoder->base.crtc) {
  8483. tmp_crtc = encoder->base.crtc;
  8484. *prepare_pipes |= 1 << to_intel_crtc(tmp_crtc)->pipe;
  8485. }
  8486. if (encoder->new_crtc)
  8487. *prepare_pipes |= 1 << encoder->new_crtc->pipe;
  8488. }
  8489. /* Check for pipes that will be enabled/disabled ... */
  8490. for_each_intel_crtc(dev, intel_crtc) {
  8491. if (intel_crtc->base.enabled == intel_crtc->new_enabled)
  8492. continue;
  8493. if (!intel_crtc->new_enabled)
  8494. *disable_pipes |= 1 << intel_crtc->pipe;
  8495. else
  8496. *prepare_pipes |= 1 << intel_crtc->pipe;
  8497. }
  8498. /* set_mode is also used to update properties on life display pipes. */
  8499. intel_crtc = to_intel_crtc(crtc);
  8500. if (intel_crtc->new_enabled)
  8501. *prepare_pipes |= 1 << intel_crtc->pipe;
  8502. /*
  8503. * For simplicity do a full modeset on any pipe where the output routing
  8504. * changed. We could be more clever, but that would require us to be
  8505. * more careful with calling the relevant encoder->mode_set functions.
  8506. */
  8507. if (*prepare_pipes)
  8508. *modeset_pipes = *prepare_pipes;
  8509. /* ... and mask these out. */
  8510. *modeset_pipes &= ~(*disable_pipes);
  8511. *prepare_pipes &= ~(*disable_pipes);
  8512. /*
  8513. * HACK: We don't (yet) fully support global modesets. intel_set_config
  8514. * obies this rule, but the modeset restore mode of
  8515. * intel_modeset_setup_hw_state does not.
  8516. */
  8517. *modeset_pipes &= 1 << intel_crtc->pipe;
  8518. *prepare_pipes &= 1 << intel_crtc->pipe;
  8519. DRM_DEBUG_KMS("set mode pipe masks: modeset: %x, prepare: %x, disable: %x\n",
  8520. *modeset_pipes, *prepare_pipes, *disable_pipes);
  8521. }
  8522. static bool intel_crtc_in_use(struct drm_crtc *crtc)
  8523. {
  8524. struct drm_encoder *encoder;
  8525. struct drm_device *dev = crtc->dev;
  8526. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head)
  8527. if (encoder->crtc == crtc)
  8528. return true;
  8529. return false;
  8530. }
  8531. static void
  8532. intel_modeset_update_state(struct drm_device *dev, unsigned prepare_pipes)
  8533. {
  8534. struct intel_encoder *intel_encoder;
  8535. struct intel_crtc *intel_crtc;
  8536. struct drm_connector *connector;
  8537. list_for_each_entry(intel_encoder, &dev->mode_config.encoder_list,
  8538. base.head) {
  8539. if (!intel_encoder->base.crtc)
  8540. continue;
  8541. intel_crtc = to_intel_crtc(intel_encoder->base.crtc);
  8542. if (prepare_pipes & (1 << intel_crtc->pipe))
  8543. intel_encoder->connectors_active = false;
  8544. }
  8545. intel_modeset_commit_output_state(dev);
  8546. /* Double check state. */
  8547. for_each_intel_crtc(dev, intel_crtc) {
  8548. WARN_ON(intel_crtc->base.enabled != intel_crtc_in_use(&intel_crtc->base));
  8549. WARN_ON(intel_crtc->new_config &&
  8550. intel_crtc->new_config != &intel_crtc->config);
  8551. WARN_ON(intel_crtc->base.enabled != !!intel_crtc->new_config);
  8552. }
  8553. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  8554. if (!connector->encoder || !connector->encoder->crtc)
  8555. continue;
  8556. intel_crtc = to_intel_crtc(connector->encoder->crtc);
  8557. if (prepare_pipes & (1 << intel_crtc->pipe)) {
  8558. struct drm_property *dpms_property =
  8559. dev->mode_config.dpms_property;
  8560. connector->dpms = DRM_MODE_DPMS_ON;
  8561. drm_object_property_set_value(&connector->base,
  8562. dpms_property,
  8563. DRM_MODE_DPMS_ON);
  8564. intel_encoder = to_intel_encoder(connector->encoder);
  8565. intel_encoder->connectors_active = true;
  8566. }
  8567. }
  8568. }
  8569. static bool intel_fuzzy_clock_check(int clock1, int clock2)
  8570. {
  8571. int diff;
  8572. if (clock1 == clock2)
  8573. return true;
  8574. if (!clock1 || !clock2)
  8575. return false;
  8576. diff = abs(clock1 - clock2);
  8577. if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105)
  8578. return true;
  8579. return false;
  8580. }
  8581. #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \
  8582. list_for_each_entry((intel_crtc), \
  8583. &(dev)->mode_config.crtc_list, \
  8584. base.head) \
  8585. if (mask & (1 <<(intel_crtc)->pipe))
  8586. static bool
  8587. intel_pipe_config_compare(struct drm_device *dev,
  8588. struct intel_crtc_config *current_config,
  8589. struct intel_crtc_config *pipe_config)
  8590. {
  8591. #define PIPE_CONF_CHECK_X(name) \
  8592. if (current_config->name != pipe_config->name) { \
  8593. DRM_ERROR("mismatch in " #name " " \
  8594. "(expected 0x%08x, found 0x%08x)\n", \
  8595. current_config->name, \
  8596. pipe_config->name); \
  8597. return false; \
  8598. }
  8599. #define PIPE_CONF_CHECK_I(name) \
  8600. if (current_config->name != pipe_config->name) { \
  8601. DRM_ERROR("mismatch in " #name " " \
  8602. "(expected %i, found %i)\n", \
  8603. current_config->name, \
  8604. pipe_config->name); \
  8605. return false; \
  8606. }
  8607. #define PIPE_CONF_CHECK_FLAGS(name, mask) \
  8608. if ((current_config->name ^ pipe_config->name) & (mask)) { \
  8609. DRM_ERROR("mismatch in " #name "(" #mask ") " \
  8610. "(expected %i, found %i)\n", \
  8611. current_config->name & (mask), \
  8612. pipe_config->name & (mask)); \
  8613. return false; \
  8614. }
  8615. #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \
  8616. if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
  8617. DRM_ERROR("mismatch in " #name " " \
  8618. "(expected %i, found %i)\n", \
  8619. current_config->name, \
  8620. pipe_config->name); \
  8621. return false; \
  8622. }
  8623. #define PIPE_CONF_QUIRK(quirk) \
  8624. ((current_config->quirks | pipe_config->quirks) & (quirk))
  8625. PIPE_CONF_CHECK_I(cpu_transcoder);
  8626. PIPE_CONF_CHECK_I(has_pch_encoder);
  8627. PIPE_CONF_CHECK_I(fdi_lanes);
  8628. PIPE_CONF_CHECK_I(fdi_m_n.gmch_m);
  8629. PIPE_CONF_CHECK_I(fdi_m_n.gmch_n);
  8630. PIPE_CONF_CHECK_I(fdi_m_n.link_m);
  8631. PIPE_CONF_CHECK_I(fdi_m_n.link_n);
  8632. PIPE_CONF_CHECK_I(fdi_m_n.tu);
  8633. PIPE_CONF_CHECK_I(has_dp_encoder);
  8634. PIPE_CONF_CHECK_I(dp_m_n.gmch_m);
  8635. PIPE_CONF_CHECK_I(dp_m_n.gmch_n);
  8636. PIPE_CONF_CHECK_I(dp_m_n.link_m);
  8637. PIPE_CONF_CHECK_I(dp_m_n.link_n);
  8638. PIPE_CONF_CHECK_I(dp_m_n.tu);
  8639. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hdisplay);
  8640. PIPE_CONF_CHECK_I(adjusted_mode.crtc_htotal);
  8641. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hblank_start);
  8642. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hblank_end);
  8643. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hsync_start);
  8644. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hsync_end);
  8645. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vdisplay);
  8646. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vtotal);
  8647. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vblank_start);
  8648. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vblank_end);
  8649. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vsync_start);
  8650. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vsync_end);
  8651. PIPE_CONF_CHECK_I(pixel_multiplier);
  8652. PIPE_CONF_CHECK_I(has_hdmi_sink);
  8653. if ((INTEL_INFO(dev)->gen < 8 && !IS_HASWELL(dev)) ||
  8654. IS_VALLEYVIEW(dev))
  8655. PIPE_CONF_CHECK_I(limited_color_range);
  8656. PIPE_CONF_CHECK_I(has_audio);
  8657. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  8658. DRM_MODE_FLAG_INTERLACE);
  8659. if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) {
  8660. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  8661. DRM_MODE_FLAG_PHSYNC);
  8662. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  8663. DRM_MODE_FLAG_NHSYNC);
  8664. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  8665. DRM_MODE_FLAG_PVSYNC);
  8666. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  8667. DRM_MODE_FLAG_NVSYNC);
  8668. }
  8669. PIPE_CONF_CHECK_I(pipe_src_w);
  8670. PIPE_CONF_CHECK_I(pipe_src_h);
  8671. /*
  8672. * FIXME: BIOS likes to set up a cloned config with lvds+external
  8673. * screen. Since we don't yet re-compute the pipe config when moving
  8674. * just the lvds port away to another pipe the sw tracking won't match.
  8675. *
  8676. * Proper atomic modesets with recomputed global state will fix this.
  8677. * Until then just don't check gmch state for inherited modes.
  8678. */
  8679. if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_INHERITED_MODE)) {
  8680. PIPE_CONF_CHECK_I(gmch_pfit.control);
  8681. /* pfit ratios are autocomputed by the hw on gen4+ */
  8682. if (INTEL_INFO(dev)->gen < 4)
  8683. PIPE_CONF_CHECK_I(gmch_pfit.pgm_ratios);
  8684. PIPE_CONF_CHECK_I(gmch_pfit.lvds_border_bits);
  8685. }
  8686. PIPE_CONF_CHECK_I(pch_pfit.enabled);
  8687. if (current_config->pch_pfit.enabled) {
  8688. PIPE_CONF_CHECK_I(pch_pfit.pos);
  8689. PIPE_CONF_CHECK_I(pch_pfit.size);
  8690. }
  8691. /* BDW+ don't expose a synchronous way to read the state */
  8692. if (IS_HASWELL(dev))
  8693. PIPE_CONF_CHECK_I(ips_enabled);
  8694. PIPE_CONF_CHECK_I(double_wide);
  8695. PIPE_CONF_CHECK_I(shared_dpll);
  8696. PIPE_CONF_CHECK_X(dpll_hw_state.dpll);
  8697. PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md);
  8698. PIPE_CONF_CHECK_X(dpll_hw_state.fp0);
  8699. PIPE_CONF_CHECK_X(dpll_hw_state.fp1);
  8700. if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5)
  8701. PIPE_CONF_CHECK_I(pipe_bpp);
  8702. PIPE_CONF_CHECK_CLOCK_FUZZY(adjusted_mode.crtc_clock);
  8703. PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock);
  8704. #undef PIPE_CONF_CHECK_X
  8705. #undef PIPE_CONF_CHECK_I
  8706. #undef PIPE_CONF_CHECK_FLAGS
  8707. #undef PIPE_CONF_CHECK_CLOCK_FUZZY
  8708. #undef PIPE_CONF_QUIRK
  8709. return true;
  8710. }
  8711. static void
  8712. check_connector_state(struct drm_device *dev)
  8713. {
  8714. struct intel_connector *connector;
  8715. list_for_each_entry(connector, &dev->mode_config.connector_list,
  8716. base.head) {
  8717. /* This also checks the encoder/connector hw state with the
  8718. * ->get_hw_state callbacks. */
  8719. intel_connector_check_state(connector);
  8720. WARN(&connector->new_encoder->base != connector->base.encoder,
  8721. "connector's staged encoder doesn't match current encoder\n");
  8722. }
  8723. }
  8724. static void
  8725. check_encoder_state(struct drm_device *dev)
  8726. {
  8727. struct intel_encoder *encoder;
  8728. struct intel_connector *connector;
  8729. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  8730. base.head) {
  8731. bool enabled = false;
  8732. bool active = false;
  8733. enum pipe pipe, tracked_pipe;
  8734. DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
  8735. encoder->base.base.id,
  8736. encoder->base.name);
  8737. WARN(&encoder->new_crtc->base != encoder->base.crtc,
  8738. "encoder's stage crtc doesn't match current crtc\n");
  8739. WARN(encoder->connectors_active && !encoder->base.crtc,
  8740. "encoder's active_connectors set, but no crtc\n");
  8741. list_for_each_entry(connector, &dev->mode_config.connector_list,
  8742. base.head) {
  8743. if (connector->base.encoder != &encoder->base)
  8744. continue;
  8745. enabled = true;
  8746. if (connector->base.dpms != DRM_MODE_DPMS_OFF)
  8747. active = true;
  8748. }
  8749. WARN(!!encoder->base.crtc != enabled,
  8750. "encoder's enabled state mismatch "
  8751. "(expected %i, found %i)\n",
  8752. !!encoder->base.crtc, enabled);
  8753. WARN(active && !encoder->base.crtc,
  8754. "active encoder with no crtc\n");
  8755. WARN(encoder->connectors_active != active,
  8756. "encoder's computed active state doesn't match tracked active state "
  8757. "(expected %i, found %i)\n", active, encoder->connectors_active);
  8758. active = encoder->get_hw_state(encoder, &pipe);
  8759. WARN(active != encoder->connectors_active,
  8760. "encoder's hw state doesn't match sw tracking "
  8761. "(expected %i, found %i)\n",
  8762. encoder->connectors_active, active);
  8763. if (!encoder->base.crtc)
  8764. continue;
  8765. tracked_pipe = to_intel_crtc(encoder->base.crtc)->pipe;
  8766. WARN(active && pipe != tracked_pipe,
  8767. "active encoder's pipe doesn't match"
  8768. "(expected %i, found %i)\n",
  8769. tracked_pipe, pipe);
  8770. }
  8771. }
  8772. static void
  8773. check_crtc_state(struct drm_device *dev)
  8774. {
  8775. struct drm_i915_private *dev_priv = dev->dev_private;
  8776. struct intel_crtc *crtc;
  8777. struct intel_encoder *encoder;
  8778. struct intel_crtc_config pipe_config;
  8779. for_each_intel_crtc(dev, crtc) {
  8780. bool enabled = false;
  8781. bool active = false;
  8782. memset(&pipe_config, 0, sizeof(pipe_config));
  8783. DRM_DEBUG_KMS("[CRTC:%d]\n",
  8784. crtc->base.base.id);
  8785. WARN(crtc->active && !crtc->base.enabled,
  8786. "active crtc, but not enabled in sw tracking\n");
  8787. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  8788. base.head) {
  8789. if (encoder->base.crtc != &crtc->base)
  8790. continue;
  8791. enabled = true;
  8792. if (encoder->connectors_active)
  8793. active = true;
  8794. }
  8795. WARN(active != crtc->active,
  8796. "crtc's computed active state doesn't match tracked active state "
  8797. "(expected %i, found %i)\n", active, crtc->active);
  8798. WARN(enabled != crtc->base.enabled,
  8799. "crtc's computed enabled state doesn't match tracked enabled state "
  8800. "(expected %i, found %i)\n", enabled, crtc->base.enabled);
  8801. active = dev_priv->display.get_pipe_config(crtc,
  8802. &pipe_config);
  8803. /* hw state is inconsistent with the pipe A quirk */
  8804. if (crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE)
  8805. active = crtc->active;
  8806. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  8807. base.head) {
  8808. enum pipe pipe;
  8809. if (encoder->base.crtc != &crtc->base)
  8810. continue;
  8811. if (encoder->get_hw_state(encoder, &pipe))
  8812. encoder->get_config(encoder, &pipe_config);
  8813. }
  8814. WARN(crtc->active != active,
  8815. "crtc active state doesn't match with hw state "
  8816. "(expected %i, found %i)\n", crtc->active, active);
  8817. if (active &&
  8818. !intel_pipe_config_compare(dev, &crtc->config, &pipe_config)) {
  8819. WARN(1, "pipe state doesn't match!\n");
  8820. intel_dump_pipe_config(crtc, &pipe_config,
  8821. "[hw state]");
  8822. intel_dump_pipe_config(crtc, &crtc->config,
  8823. "[sw state]");
  8824. }
  8825. }
  8826. }
  8827. static void
  8828. check_shared_dpll_state(struct drm_device *dev)
  8829. {
  8830. struct drm_i915_private *dev_priv = dev->dev_private;
  8831. struct intel_crtc *crtc;
  8832. struct intel_dpll_hw_state dpll_hw_state;
  8833. int i;
  8834. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  8835. struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
  8836. int enabled_crtcs = 0, active_crtcs = 0;
  8837. bool active;
  8838. memset(&dpll_hw_state, 0, sizeof(dpll_hw_state));
  8839. DRM_DEBUG_KMS("%s\n", pll->name);
  8840. active = pll->get_hw_state(dev_priv, pll, &dpll_hw_state);
  8841. WARN(pll->active > pll->refcount,
  8842. "more active pll users than references: %i vs %i\n",
  8843. pll->active, pll->refcount);
  8844. WARN(pll->active && !pll->on,
  8845. "pll in active use but not on in sw tracking\n");
  8846. WARN(pll->on && !pll->active,
  8847. "pll in on but not on in use in sw tracking\n");
  8848. WARN(pll->on != active,
  8849. "pll on state mismatch (expected %i, found %i)\n",
  8850. pll->on, active);
  8851. for_each_intel_crtc(dev, crtc) {
  8852. if (crtc->base.enabled && intel_crtc_to_shared_dpll(crtc) == pll)
  8853. enabled_crtcs++;
  8854. if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll)
  8855. active_crtcs++;
  8856. }
  8857. WARN(pll->active != active_crtcs,
  8858. "pll active crtcs mismatch (expected %i, found %i)\n",
  8859. pll->active, active_crtcs);
  8860. WARN(pll->refcount != enabled_crtcs,
  8861. "pll enabled crtcs mismatch (expected %i, found %i)\n",
  8862. pll->refcount, enabled_crtcs);
  8863. WARN(pll->on && memcmp(&pll->hw_state, &dpll_hw_state,
  8864. sizeof(dpll_hw_state)),
  8865. "pll hw state mismatch\n");
  8866. }
  8867. }
  8868. void
  8869. intel_modeset_check_state(struct drm_device *dev)
  8870. {
  8871. check_connector_state(dev);
  8872. check_encoder_state(dev);
  8873. check_crtc_state(dev);
  8874. check_shared_dpll_state(dev);
  8875. }
  8876. void ironlake_check_encoder_dotclock(const struct intel_crtc_config *pipe_config,
  8877. int dotclock)
  8878. {
  8879. /*
  8880. * FDI already provided one idea for the dotclock.
  8881. * Yell if the encoder disagrees.
  8882. */
  8883. WARN(!intel_fuzzy_clock_check(pipe_config->adjusted_mode.crtc_clock, dotclock),
  8884. "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
  8885. pipe_config->adjusted_mode.crtc_clock, dotclock);
  8886. }
  8887. static void update_scanline_offset(struct intel_crtc *crtc)
  8888. {
  8889. struct drm_device *dev = crtc->base.dev;
  8890. /*
  8891. * The scanline counter increments at the leading edge of hsync.
  8892. *
  8893. * On most platforms it starts counting from vtotal-1 on the
  8894. * first active line. That means the scanline counter value is
  8895. * always one less than what we would expect. Ie. just after
  8896. * start of vblank, which also occurs at start of hsync (on the
  8897. * last active line), the scanline counter will read vblank_start-1.
  8898. *
  8899. * On gen2 the scanline counter starts counting from 1 instead
  8900. * of vtotal-1, so we have to subtract one (or rather add vtotal-1
  8901. * to keep the value positive), instead of adding one.
  8902. *
  8903. * On HSW+ the behaviour of the scanline counter depends on the output
  8904. * type. For DP ports it behaves like most other platforms, but on HDMI
  8905. * there's an extra 1 line difference. So we need to add two instead of
  8906. * one to the value.
  8907. */
  8908. if (IS_GEN2(dev)) {
  8909. const struct drm_display_mode *mode = &crtc->config.adjusted_mode;
  8910. int vtotal;
  8911. vtotal = mode->crtc_vtotal;
  8912. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  8913. vtotal /= 2;
  8914. crtc->scanline_offset = vtotal - 1;
  8915. } else if (HAS_DDI(dev) &&
  8916. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_HDMI)) {
  8917. crtc->scanline_offset = 2;
  8918. } else
  8919. crtc->scanline_offset = 1;
  8920. }
  8921. static int __intel_set_mode(struct drm_crtc *crtc,
  8922. struct drm_display_mode *mode,
  8923. int x, int y, struct drm_framebuffer *fb)
  8924. {
  8925. struct drm_device *dev = crtc->dev;
  8926. struct drm_i915_private *dev_priv = dev->dev_private;
  8927. struct drm_display_mode *saved_mode;
  8928. struct intel_crtc_config *pipe_config = NULL;
  8929. struct intel_crtc *intel_crtc;
  8930. unsigned disable_pipes, prepare_pipes, modeset_pipes;
  8931. int ret = 0;
  8932. saved_mode = kmalloc(sizeof(*saved_mode), GFP_KERNEL);
  8933. if (!saved_mode)
  8934. return -ENOMEM;
  8935. intel_modeset_affected_pipes(crtc, &modeset_pipes,
  8936. &prepare_pipes, &disable_pipes);
  8937. *saved_mode = crtc->mode;
  8938. /* Hack: Because we don't (yet) support global modeset on multiple
  8939. * crtcs, we don't keep track of the new mode for more than one crtc.
  8940. * Hence simply check whether any bit is set in modeset_pipes in all the
  8941. * pieces of code that are not yet converted to deal with mutliple crtcs
  8942. * changing their mode at the same time. */
  8943. if (modeset_pipes) {
  8944. pipe_config = intel_modeset_pipe_config(crtc, fb, mode);
  8945. if (IS_ERR(pipe_config)) {
  8946. ret = PTR_ERR(pipe_config);
  8947. pipe_config = NULL;
  8948. goto out;
  8949. }
  8950. intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config,
  8951. "[modeset]");
  8952. to_intel_crtc(crtc)->new_config = pipe_config;
  8953. }
  8954. /*
  8955. * See if the config requires any additional preparation, e.g.
  8956. * to adjust global state with pipes off. We need to do this
  8957. * here so we can get the modeset_pipe updated config for the new
  8958. * mode set on this crtc. For other crtcs we need to use the
  8959. * adjusted_mode bits in the crtc directly.
  8960. */
  8961. if (IS_VALLEYVIEW(dev)) {
  8962. valleyview_modeset_global_pipes(dev, &prepare_pipes);
  8963. /* may have added more to prepare_pipes than we should */
  8964. prepare_pipes &= ~disable_pipes;
  8965. }
  8966. for_each_intel_crtc_masked(dev, disable_pipes, intel_crtc)
  8967. intel_crtc_disable(&intel_crtc->base);
  8968. for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc) {
  8969. if (intel_crtc->base.enabled)
  8970. dev_priv->display.crtc_disable(&intel_crtc->base);
  8971. }
  8972. /* crtc->mode is already used by the ->mode_set callbacks, hence we need
  8973. * to set it here already despite that we pass it down the callchain.
  8974. */
  8975. if (modeset_pipes) {
  8976. crtc->mode = *mode;
  8977. /* mode_set/enable/disable functions rely on a correct pipe
  8978. * config. */
  8979. to_intel_crtc(crtc)->config = *pipe_config;
  8980. to_intel_crtc(crtc)->new_config = &to_intel_crtc(crtc)->config;
  8981. /*
  8982. * Calculate and store various constants which
  8983. * are later needed by vblank and swap-completion
  8984. * timestamping. They are derived from true hwmode.
  8985. */
  8986. drm_calc_timestamping_constants(crtc,
  8987. &pipe_config->adjusted_mode);
  8988. }
  8989. /* Only after disabling all output pipelines that will be changed can we
  8990. * update the the output configuration. */
  8991. intel_modeset_update_state(dev, prepare_pipes);
  8992. if (dev_priv->display.modeset_global_resources)
  8993. dev_priv->display.modeset_global_resources(dev);
  8994. /* Set up the DPLL and any encoders state that needs to adjust or depend
  8995. * on the DPLL.
  8996. */
  8997. for_each_intel_crtc_masked(dev, modeset_pipes, intel_crtc) {
  8998. struct drm_framebuffer *old_fb;
  8999. struct drm_i915_gem_object *old_obj = NULL;
  9000. struct drm_i915_gem_object *obj =
  9001. to_intel_framebuffer(fb)->obj;
  9002. mutex_lock(&dev->struct_mutex);
  9003. ret = intel_pin_and_fence_fb_obj(dev,
  9004. obj,
  9005. NULL);
  9006. if (ret != 0) {
  9007. DRM_ERROR("pin & fence failed\n");
  9008. mutex_unlock(&dev->struct_mutex);
  9009. goto done;
  9010. }
  9011. old_fb = crtc->primary->fb;
  9012. if (old_fb) {
  9013. old_obj = to_intel_framebuffer(old_fb)->obj;
  9014. intel_unpin_fb_obj(old_obj);
  9015. }
  9016. i915_gem_track_fb(old_obj, obj,
  9017. INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe));
  9018. mutex_unlock(&dev->struct_mutex);
  9019. crtc->primary->fb = fb;
  9020. crtc->x = x;
  9021. crtc->y = y;
  9022. ret = dev_priv->display.crtc_mode_set(&intel_crtc->base,
  9023. x, y, fb);
  9024. if (ret)
  9025. goto done;
  9026. }
  9027. /* Now enable the clocks, plane, pipe, and connectors that we set up. */
  9028. for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc) {
  9029. update_scanline_offset(intel_crtc);
  9030. dev_priv->display.crtc_enable(&intel_crtc->base);
  9031. }
  9032. /* FIXME: add subpixel order */
  9033. done:
  9034. if (ret && crtc->enabled)
  9035. crtc->mode = *saved_mode;
  9036. out:
  9037. kfree(pipe_config);
  9038. kfree(saved_mode);
  9039. return ret;
  9040. }
  9041. static int intel_set_mode(struct drm_crtc *crtc,
  9042. struct drm_display_mode *mode,
  9043. int x, int y, struct drm_framebuffer *fb)
  9044. {
  9045. int ret;
  9046. ret = __intel_set_mode(crtc, mode, x, y, fb);
  9047. if (ret == 0)
  9048. intel_modeset_check_state(crtc->dev);
  9049. return ret;
  9050. }
  9051. void intel_crtc_restore_mode(struct drm_crtc *crtc)
  9052. {
  9053. intel_set_mode(crtc, &crtc->mode, crtc->x, crtc->y, crtc->primary->fb);
  9054. }
  9055. #undef for_each_intel_crtc_masked
  9056. static void intel_set_config_free(struct intel_set_config *config)
  9057. {
  9058. if (!config)
  9059. return;
  9060. kfree(config->save_connector_encoders);
  9061. kfree(config->save_encoder_crtcs);
  9062. kfree(config->save_crtc_enabled);
  9063. kfree(config);
  9064. }
  9065. static int intel_set_config_save_state(struct drm_device *dev,
  9066. struct intel_set_config *config)
  9067. {
  9068. struct drm_crtc *crtc;
  9069. struct drm_encoder *encoder;
  9070. struct drm_connector *connector;
  9071. int count;
  9072. config->save_crtc_enabled =
  9073. kcalloc(dev->mode_config.num_crtc,
  9074. sizeof(bool), GFP_KERNEL);
  9075. if (!config->save_crtc_enabled)
  9076. return -ENOMEM;
  9077. config->save_encoder_crtcs =
  9078. kcalloc(dev->mode_config.num_encoder,
  9079. sizeof(struct drm_crtc *), GFP_KERNEL);
  9080. if (!config->save_encoder_crtcs)
  9081. return -ENOMEM;
  9082. config->save_connector_encoders =
  9083. kcalloc(dev->mode_config.num_connector,
  9084. sizeof(struct drm_encoder *), GFP_KERNEL);
  9085. if (!config->save_connector_encoders)
  9086. return -ENOMEM;
  9087. /* Copy data. Note that driver private data is not affected.
  9088. * Should anything bad happen only the expected state is
  9089. * restored, not the drivers personal bookkeeping.
  9090. */
  9091. count = 0;
  9092. for_each_crtc(dev, crtc) {
  9093. config->save_crtc_enabled[count++] = crtc->enabled;
  9094. }
  9095. count = 0;
  9096. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  9097. config->save_encoder_crtcs[count++] = encoder->crtc;
  9098. }
  9099. count = 0;
  9100. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  9101. config->save_connector_encoders[count++] = connector->encoder;
  9102. }
  9103. return 0;
  9104. }
  9105. static void intel_set_config_restore_state(struct drm_device *dev,
  9106. struct intel_set_config *config)
  9107. {
  9108. struct intel_crtc *crtc;
  9109. struct intel_encoder *encoder;
  9110. struct intel_connector *connector;
  9111. int count;
  9112. count = 0;
  9113. for_each_intel_crtc(dev, crtc) {
  9114. crtc->new_enabled = config->save_crtc_enabled[count++];
  9115. if (crtc->new_enabled)
  9116. crtc->new_config = &crtc->config;
  9117. else
  9118. crtc->new_config = NULL;
  9119. }
  9120. count = 0;
  9121. list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head) {
  9122. encoder->new_crtc =
  9123. to_intel_crtc(config->save_encoder_crtcs[count++]);
  9124. }
  9125. count = 0;
  9126. list_for_each_entry(connector, &dev->mode_config.connector_list, base.head) {
  9127. connector->new_encoder =
  9128. to_intel_encoder(config->save_connector_encoders[count++]);
  9129. }
  9130. }
  9131. static bool
  9132. is_crtc_connector_off(struct drm_mode_set *set)
  9133. {
  9134. int i;
  9135. if (set->num_connectors == 0)
  9136. return false;
  9137. if (WARN_ON(set->connectors == NULL))
  9138. return false;
  9139. for (i = 0; i < set->num_connectors; i++)
  9140. if (set->connectors[i]->encoder &&
  9141. set->connectors[i]->encoder->crtc == set->crtc &&
  9142. set->connectors[i]->dpms != DRM_MODE_DPMS_ON)
  9143. return true;
  9144. return false;
  9145. }
  9146. static void
  9147. intel_set_config_compute_mode_changes(struct drm_mode_set *set,
  9148. struct intel_set_config *config)
  9149. {
  9150. /* We should be able to check here if the fb has the same properties
  9151. * and then just flip_or_move it */
  9152. if (is_crtc_connector_off(set)) {
  9153. config->mode_changed = true;
  9154. } else if (set->crtc->primary->fb != set->fb) {
  9155. /*
  9156. * If we have no fb, we can only flip as long as the crtc is
  9157. * active, otherwise we need a full mode set. The crtc may
  9158. * be active if we've only disabled the primary plane, or
  9159. * in fastboot situations.
  9160. */
  9161. if (set->crtc->primary->fb == NULL) {
  9162. struct intel_crtc *intel_crtc =
  9163. to_intel_crtc(set->crtc);
  9164. if (intel_crtc->active) {
  9165. DRM_DEBUG_KMS("crtc has no fb, will flip\n");
  9166. config->fb_changed = true;
  9167. } else {
  9168. DRM_DEBUG_KMS("inactive crtc, full mode set\n");
  9169. config->mode_changed = true;
  9170. }
  9171. } else if (set->fb == NULL) {
  9172. config->mode_changed = true;
  9173. } else if (set->fb->pixel_format !=
  9174. set->crtc->primary->fb->pixel_format) {
  9175. config->mode_changed = true;
  9176. } else {
  9177. config->fb_changed = true;
  9178. }
  9179. }
  9180. if (set->fb && (set->x != set->crtc->x || set->y != set->crtc->y))
  9181. config->fb_changed = true;
  9182. if (set->mode && !drm_mode_equal(set->mode, &set->crtc->mode)) {
  9183. DRM_DEBUG_KMS("modes are different, full mode set\n");
  9184. drm_mode_debug_printmodeline(&set->crtc->mode);
  9185. drm_mode_debug_printmodeline(set->mode);
  9186. config->mode_changed = true;
  9187. }
  9188. DRM_DEBUG_KMS("computed changes for [CRTC:%d], mode_changed=%d, fb_changed=%d\n",
  9189. set->crtc->base.id, config->mode_changed, config->fb_changed);
  9190. }
  9191. static int
  9192. intel_modeset_stage_output_state(struct drm_device *dev,
  9193. struct drm_mode_set *set,
  9194. struct intel_set_config *config)
  9195. {
  9196. struct intel_connector *connector;
  9197. struct intel_encoder *encoder;
  9198. struct intel_crtc *crtc;
  9199. int ro;
  9200. /* The upper layers ensure that we either disable a crtc or have a list
  9201. * of connectors. For paranoia, double-check this. */
  9202. WARN_ON(!set->fb && (set->num_connectors != 0));
  9203. WARN_ON(set->fb && (set->num_connectors == 0));
  9204. list_for_each_entry(connector, &dev->mode_config.connector_list,
  9205. base.head) {
  9206. /* Otherwise traverse passed in connector list and get encoders
  9207. * for them. */
  9208. for (ro = 0; ro < set->num_connectors; ro++) {
  9209. if (set->connectors[ro] == &connector->base) {
  9210. connector->new_encoder = connector->encoder;
  9211. break;
  9212. }
  9213. }
  9214. /* If we disable the crtc, disable all its connectors. Also, if
  9215. * the connector is on the changing crtc but not on the new
  9216. * connector list, disable it. */
  9217. if ((!set->fb || ro == set->num_connectors) &&
  9218. connector->base.encoder &&
  9219. connector->base.encoder->crtc == set->crtc) {
  9220. connector->new_encoder = NULL;
  9221. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n",
  9222. connector->base.base.id,
  9223. connector->base.name);
  9224. }
  9225. if (&connector->new_encoder->base != connector->base.encoder) {
  9226. DRM_DEBUG_KMS("encoder changed, full mode switch\n");
  9227. config->mode_changed = true;
  9228. }
  9229. }
  9230. /* connector->new_encoder is now updated for all connectors. */
  9231. /* Update crtc of enabled connectors. */
  9232. list_for_each_entry(connector, &dev->mode_config.connector_list,
  9233. base.head) {
  9234. struct drm_crtc *new_crtc;
  9235. if (!connector->new_encoder)
  9236. continue;
  9237. new_crtc = connector->new_encoder->base.crtc;
  9238. for (ro = 0; ro < set->num_connectors; ro++) {
  9239. if (set->connectors[ro] == &connector->base)
  9240. new_crtc = set->crtc;
  9241. }
  9242. /* Make sure the new CRTC will work with the encoder */
  9243. if (!drm_encoder_crtc_ok(&connector->new_encoder->base,
  9244. new_crtc)) {
  9245. return -EINVAL;
  9246. }
  9247. connector->encoder->new_crtc = to_intel_crtc(new_crtc);
  9248. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n",
  9249. connector->base.base.id,
  9250. connector->base.name,
  9251. new_crtc->base.id);
  9252. }
  9253. /* Check for any encoders that needs to be disabled. */
  9254. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  9255. base.head) {
  9256. int num_connectors = 0;
  9257. list_for_each_entry(connector,
  9258. &dev->mode_config.connector_list,
  9259. base.head) {
  9260. if (connector->new_encoder == encoder) {
  9261. WARN_ON(!connector->new_encoder->new_crtc);
  9262. num_connectors++;
  9263. }
  9264. }
  9265. if (num_connectors == 0)
  9266. encoder->new_crtc = NULL;
  9267. else if (num_connectors > 1)
  9268. return -EINVAL;
  9269. /* Only now check for crtc changes so we don't miss encoders
  9270. * that will be disabled. */
  9271. if (&encoder->new_crtc->base != encoder->base.crtc) {
  9272. DRM_DEBUG_KMS("crtc changed, full mode switch\n");
  9273. config->mode_changed = true;
  9274. }
  9275. }
  9276. /* Now we've also updated encoder->new_crtc for all encoders. */
  9277. for_each_intel_crtc(dev, crtc) {
  9278. crtc->new_enabled = false;
  9279. list_for_each_entry(encoder,
  9280. &dev->mode_config.encoder_list,
  9281. base.head) {
  9282. if (encoder->new_crtc == crtc) {
  9283. crtc->new_enabled = true;
  9284. break;
  9285. }
  9286. }
  9287. if (crtc->new_enabled != crtc->base.enabled) {
  9288. DRM_DEBUG_KMS("crtc %sabled, full mode switch\n",
  9289. crtc->new_enabled ? "en" : "dis");
  9290. config->mode_changed = true;
  9291. }
  9292. if (crtc->new_enabled)
  9293. crtc->new_config = &crtc->config;
  9294. else
  9295. crtc->new_config = NULL;
  9296. }
  9297. return 0;
  9298. }
  9299. static void disable_crtc_nofb(struct intel_crtc *crtc)
  9300. {
  9301. struct drm_device *dev = crtc->base.dev;
  9302. struct intel_encoder *encoder;
  9303. struct intel_connector *connector;
  9304. DRM_DEBUG_KMS("Trying to restore without FB -> disabling pipe %c\n",
  9305. pipe_name(crtc->pipe));
  9306. list_for_each_entry(connector, &dev->mode_config.connector_list, base.head) {
  9307. if (connector->new_encoder &&
  9308. connector->new_encoder->new_crtc == crtc)
  9309. connector->new_encoder = NULL;
  9310. }
  9311. list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head) {
  9312. if (encoder->new_crtc == crtc)
  9313. encoder->new_crtc = NULL;
  9314. }
  9315. crtc->new_enabled = false;
  9316. crtc->new_config = NULL;
  9317. }
  9318. static int intel_crtc_set_config(struct drm_mode_set *set)
  9319. {
  9320. struct drm_device *dev;
  9321. struct drm_mode_set save_set;
  9322. struct intel_set_config *config;
  9323. int ret;
  9324. BUG_ON(!set);
  9325. BUG_ON(!set->crtc);
  9326. BUG_ON(!set->crtc->helper_private);
  9327. /* Enforce sane interface api - has been abused by the fb helper. */
  9328. BUG_ON(!set->mode && set->fb);
  9329. BUG_ON(set->fb && set->num_connectors == 0);
  9330. if (set->fb) {
  9331. DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n",
  9332. set->crtc->base.id, set->fb->base.id,
  9333. (int)set->num_connectors, set->x, set->y);
  9334. } else {
  9335. DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set->crtc->base.id);
  9336. }
  9337. dev = set->crtc->dev;
  9338. ret = -ENOMEM;
  9339. config = kzalloc(sizeof(*config), GFP_KERNEL);
  9340. if (!config)
  9341. goto out_config;
  9342. ret = intel_set_config_save_state(dev, config);
  9343. if (ret)
  9344. goto out_config;
  9345. save_set.crtc = set->crtc;
  9346. save_set.mode = &set->crtc->mode;
  9347. save_set.x = set->crtc->x;
  9348. save_set.y = set->crtc->y;
  9349. save_set.fb = set->crtc->primary->fb;
  9350. /* Compute whether we need a full modeset, only an fb base update or no
  9351. * change at all. In the future we might also check whether only the
  9352. * mode changed, e.g. for LVDS where we only change the panel fitter in
  9353. * such cases. */
  9354. intel_set_config_compute_mode_changes(set, config);
  9355. ret = intel_modeset_stage_output_state(dev, set, config);
  9356. if (ret)
  9357. goto fail;
  9358. if (config->mode_changed) {
  9359. ret = intel_set_mode(set->crtc, set->mode,
  9360. set->x, set->y, set->fb);
  9361. } else if (config->fb_changed) {
  9362. struct drm_i915_private *dev_priv = dev->dev_private;
  9363. struct intel_crtc *intel_crtc = to_intel_crtc(set->crtc);
  9364. intel_crtc_wait_for_pending_flips(set->crtc);
  9365. ret = intel_pipe_set_base(set->crtc,
  9366. set->x, set->y, set->fb);
  9367. /*
  9368. * We need to make sure the primary plane is re-enabled if it
  9369. * has previously been turned off.
  9370. */
  9371. if (!intel_crtc->primary_enabled && ret == 0) {
  9372. WARN_ON(!intel_crtc->active);
  9373. intel_enable_primary_hw_plane(dev_priv, intel_crtc->plane,
  9374. intel_crtc->pipe);
  9375. }
  9376. /*
  9377. * In the fastboot case this may be our only check of the
  9378. * state after boot. It would be better to only do it on
  9379. * the first update, but we don't have a nice way of doing that
  9380. * (and really, set_config isn't used much for high freq page
  9381. * flipping, so increasing its cost here shouldn't be a big
  9382. * deal).
  9383. */
  9384. if (i915.fastboot && ret == 0)
  9385. intel_modeset_check_state(set->crtc->dev);
  9386. }
  9387. if (ret) {
  9388. DRM_DEBUG_KMS("failed to set mode on [CRTC:%d], err = %d\n",
  9389. set->crtc->base.id, ret);
  9390. fail:
  9391. intel_set_config_restore_state(dev, config);
  9392. /*
  9393. * HACK: if the pipe was on, but we didn't have a framebuffer,
  9394. * force the pipe off to avoid oopsing in the modeset code
  9395. * due to fb==NULL. This should only happen during boot since
  9396. * we don't yet reconstruct the FB from the hardware state.
  9397. */
  9398. if (to_intel_crtc(save_set.crtc)->new_enabled && !save_set.fb)
  9399. disable_crtc_nofb(to_intel_crtc(save_set.crtc));
  9400. /* Try to restore the config */
  9401. if (config->mode_changed &&
  9402. intel_set_mode(save_set.crtc, save_set.mode,
  9403. save_set.x, save_set.y, save_set.fb))
  9404. DRM_ERROR("failed to restore config after modeset failure\n");
  9405. }
  9406. out_config:
  9407. intel_set_config_free(config);
  9408. return ret;
  9409. }
  9410. static const struct drm_crtc_funcs intel_crtc_funcs = {
  9411. .gamma_set = intel_crtc_gamma_set,
  9412. .set_config = intel_crtc_set_config,
  9413. .destroy = intel_crtc_destroy,
  9414. .page_flip = intel_crtc_page_flip,
  9415. };
  9416. static void intel_cpu_pll_init(struct drm_device *dev)
  9417. {
  9418. if (HAS_DDI(dev))
  9419. intel_ddi_pll_init(dev);
  9420. }
  9421. static bool ibx_pch_dpll_get_hw_state(struct drm_i915_private *dev_priv,
  9422. struct intel_shared_dpll *pll,
  9423. struct intel_dpll_hw_state *hw_state)
  9424. {
  9425. uint32_t val;
  9426. val = I915_READ(PCH_DPLL(pll->id));
  9427. hw_state->dpll = val;
  9428. hw_state->fp0 = I915_READ(PCH_FP0(pll->id));
  9429. hw_state->fp1 = I915_READ(PCH_FP1(pll->id));
  9430. return val & DPLL_VCO_ENABLE;
  9431. }
  9432. static void ibx_pch_dpll_mode_set(struct drm_i915_private *dev_priv,
  9433. struct intel_shared_dpll *pll)
  9434. {
  9435. I915_WRITE(PCH_FP0(pll->id), pll->hw_state.fp0);
  9436. I915_WRITE(PCH_FP1(pll->id), pll->hw_state.fp1);
  9437. }
  9438. static void ibx_pch_dpll_enable(struct drm_i915_private *dev_priv,
  9439. struct intel_shared_dpll *pll)
  9440. {
  9441. /* PCH refclock must be enabled first */
  9442. ibx_assert_pch_refclk_enabled(dev_priv);
  9443. I915_WRITE(PCH_DPLL(pll->id), pll->hw_state.dpll);
  9444. /* Wait for the clocks to stabilize. */
  9445. POSTING_READ(PCH_DPLL(pll->id));
  9446. udelay(150);
  9447. /* The pixel multiplier can only be updated once the
  9448. * DPLL is enabled and the clocks are stable.
  9449. *
  9450. * So write it again.
  9451. */
  9452. I915_WRITE(PCH_DPLL(pll->id), pll->hw_state.dpll);
  9453. POSTING_READ(PCH_DPLL(pll->id));
  9454. udelay(200);
  9455. }
  9456. static void ibx_pch_dpll_disable(struct drm_i915_private *dev_priv,
  9457. struct intel_shared_dpll *pll)
  9458. {
  9459. struct drm_device *dev = dev_priv->dev;
  9460. struct intel_crtc *crtc;
  9461. /* Make sure no transcoder isn't still depending on us. */
  9462. for_each_intel_crtc(dev, crtc) {
  9463. if (intel_crtc_to_shared_dpll(crtc) == pll)
  9464. assert_pch_transcoder_disabled(dev_priv, crtc->pipe);
  9465. }
  9466. I915_WRITE(PCH_DPLL(pll->id), 0);
  9467. POSTING_READ(PCH_DPLL(pll->id));
  9468. udelay(200);
  9469. }
  9470. static char *ibx_pch_dpll_names[] = {
  9471. "PCH DPLL A",
  9472. "PCH DPLL B",
  9473. };
  9474. static void ibx_pch_dpll_init(struct drm_device *dev)
  9475. {
  9476. struct drm_i915_private *dev_priv = dev->dev_private;
  9477. int i;
  9478. dev_priv->num_shared_dpll = 2;
  9479. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  9480. dev_priv->shared_dplls[i].id = i;
  9481. dev_priv->shared_dplls[i].name = ibx_pch_dpll_names[i];
  9482. dev_priv->shared_dplls[i].mode_set = ibx_pch_dpll_mode_set;
  9483. dev_priv->shared_dplls[i].enable = ibx_pch_dpll_enable;
  9484. dev_priv->shared_dplls[i].disable = ibx_pch_dpll_disable;
  9485. dev_priv->shared_dplls[i].get_hw_state =
  9486. ibx_pch_dpll_get_hw_state;
  9487. }
  9488. }
  9489. static void intel_shared_dpll_init(struct drm_device *dev)
  9490. {
  9491. struct drm_i915_private *dev_priv = dev->dev_private;
  9492. if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
  9493. ibx_pch_dpll_init(dev);
  9494. else
  9495. dev_priv->num_shared_dpll = 0;
  9496. BUG_ON(dev_priv->num_shared_dpll > I915_NUM_PLLS);
  9497. }
  9498. static int
  9499. intel_primary_plane_disable(struct drm_plane *plane)
  9500. {
  9501. struct drm_device *dev = plane->dev;
  9502. struct drm_i915_private *dev_priv = dev->dev_private;
  9503. struct intel_plane *intel_plane = to_intel_plane(plane);
  9504. struct intel_crtc *intel_crtc;
  9505. if (!plane->fb)
  9506. return 0;
  9507. BUG_ON(!plane->crtc);
  9508. intel_crtc = to_intel_crtc(plane->crtc);
  9509. /*
  9510. * Even though we checked plane->fb above, it's still possible that
  9511. * the primary plane has been implicitly disabled because the crtc
  9512. * coordinates given weren't visible, or because we detected
  9513. * that it was 100% covered by a sprite plane. Or, the CRTC may be
  9514. * off and we've set a fb, but haven't actually turned on the CRTC yet.
  9515. * In either case, we need to unpin the FB and let the fb pointer get
  9516. * updated, but otherwise we don't need to touch the hardware.
  9517. */
  9518. if (!intel_crtc->primary_enabled)
  9519. goto disable_unpin;
  9520. intel_crtc_wait_for_pending_flips(plane->crtc);
  9521. intel_disable_primary_hw_plane(dev_priv, intel_plane->plane,
  9522. intel_plane->pipe);
  9523. disable_unpin:
  9524. i915_gem_track_fb(to_intel_framebuffer(plane->fb)->obj, NULL,
  9525. INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe));
  9526. intel_unpin_fb_obj(to_intel_framebuffer(plane->fb)->obj);
  9527. plane->fb = NULL;
  9528. return 0;
  9529. }
  9530. static int
  9531. intel_primary_plane_setplane(struct drm_plane *plane, struct drm_crtc *crtc,
  9532. struct drm_framebuffer *fb, int crtc_x, int crtc_y,
  9533. unsigned int crtc_w, unsigned int crtc_h,
  9534. uint32_t src_x, uint32_t src_y,
  9535. uint32_t src_w, uint32_t src_h)
  9536. {
  9537. struct drm_device *dev = crtc->dev;
  9538. struct drm_i915_private *dev_priv = dev->dev_private;
  9539. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  9540. struct intel_plane *intel_plane = to_intel_plane(plane);
  9541. struct drm_i915_gem_object *obj, *old_obj = NULL;
  9542. struct drm_rect dest = {
  9543. /* integer pixels */
  9544. .x1 = crtc_x,
  9545. .y1 = crtc_y,
  9546. .x2 = crtc_x + crtc_w,
  9547. .y2 = crtc_y + crtc_h,
  9548. };
  9549. struct drm_rect src = {
  9550. /* 16.16 fixed point */
  9551. .x1 = src_x,
  9552. .y1 = src_y,
  9553. .x2 = src_x + src_w,
  9554. .y2 = src_y + src_h,
  9555. };
  9556. const struct drm_rect clip = {
  9557. /* integer pixels */
  9558. .x2 = intel_crtc->active ? intel_crtc->config.pipe_src_w : 0,
  9559. .y2 = intel_crtc->active ? intel_crtc->config.pipe_src_h : 0,
  9560. };
  9561. bool visible;
  9562. int ret;
  9563. ret = drm_plane_helper_check_update(plane, crtc, fb,
  9564. &src, &dest, &clip,
  9565. DRM_PLANE_HELPER_NO_SCALING,
  9566. DRM_PLANE_HELPER_NO_SCALING,
  9567. false, true, &visible);
  9568. if (ret)
  9569. return ret;
  9570. if (plane->fb)
  9571. old_obj = to_intel_framebuffer(plane->fb)->obj;
  9572. obj = to_intel_framebuffer(fb)->obj;
  9573. /*
  9574. * If the CRTC isn't enabled, we're just pinning the framebuffer,
  9575. * updating the fb pointer, and returning without touching the
  9576. * hardware. This allows us to later do a drmModeSetCrtc with fb=-1 to
  9577. * turn on the display with all planes setup as desired.
  9578. */
  9579. if (!crtc->enabled) {
  9580. /*
  9581. * If we already called setplane while the crtc was disabled,
  9582. * we may have an fb pinned; unpin it.
  9583. */
  9584. if (plane->fb)
  9585. intel_unpin_fb_obj(old_obj);
  9586. i915_gem_track_fb(old_obj, obj,
  9587. INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe));
  9588. /* Pin and return without programming hardware */
  9589. return intel_pin_and_fence_fb_obj(dev, obj, NULL);
  9590. }
  9591. intel_crtc_wait_for_pending_flips(crtc);
  9592. /*
  9593. * If clipping results in a non-visible primary plane, we'll disable
  9594. * the primary plane. Note that this is a bit different than what
  9595. * happens if userspace explicitly disables the plane by passing fb=0
  9596. * because plane->fb still gets set and pinned.
  9597. */
  9598. if (!visible) {
  9599. /*
  9600. * Try to pin the new fb first so that we can bail out if we
  9601. * fail.
  9602. */
  9603. if (plane->fb != fb) {
  9604. ret = intel_pin_and_fence_fb_obj(dev, obj, NULL);
  9605. if (ret)
  9606. return ret;
  9607. }
  9608. i915_gem_track_fb(old_obj, obj,
  9609. INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe));
  9610. if (intel_crtc->primary_enabled)
  9611. intel_disable_primary_hw_plane(dev_priv,
  9612. intel_plane->plane,
  9613. intel_plane->pipe);
  9614. if (plane->fb != fb)
  9615. if (plane->fb)
  9616. intel_unpin_fb_obj(old_obj);
  9617. return 0;
  9618. }
  9619. ret = intel_pipe_set_base(crtc, src.x1, src.y1, fb);
  9620. if (ret)
  9621. return ret;
  9622. if (!intel_crtc->primary_enabled)
  9623. intel_enable_primary_hw_plane(dev_priv, intel_crtc->plane,
  9624. intel_crtc->pipe);
  9625. return 0;
  9626. }
  9627. /* Common destruction function for both primary and cursor planes */
  9628. static void intel_plane_destroy(struct drm_plane *plane)
  9629. {
  9630. struct intel_plane *intel_plane = to_intel_plane(plane);
  9631. drm_plane_cleanup(plane);
  9632. kfree(intel_plane);
  9633. }
  9634. static const struct drm_plane_funcs intel_primary_plane_funcs = {
  9635. .update_plane = intel_primary_plane_setplane,
  9636. .disable_plane = intel_primary_plane_disable,
  9637. .destroy = intel_plane_destroy,
  9638. };
  9639. static struct drm_plane *intel_primary_plane_create(struct drm_device *dev,
  9640. int pipe)
  9641. {
  9642. struct intel_plane *primary;
  9643. const uint32_t *intel_primary_formats;
  9644. int num_formats;
  9645. primary = kzalloc(sizeof(*primary), GFP_KERNEL);
  9646. if (primary == NULL)
  9647. return NULL;
  9648. primary->can_scale = false;
  9649. primary->max_downscale = 1;
  9650. primary->pipe = pipe;
  9651. primary->plane = pipe;
  9652. if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4)
  9653. primary->plane = !pipe;
  9654. if (INTEL_INFO(dev)->gen <= 3) {
  9655. intel_primary_formats = intel_primary_formats_gen2;
  9656. num_formats = ARRAY_SIZE(intel_primary_formats_gen2);
  9657. } else {
  9658. intel_primary_formats = intel_primary_formats_gen4;
  9659. num_formats = ARRAY_SIZE(intel_primary_formats_gen4);
  9660. }
  9661. drm_universal_plane_init(dev, &primary->base, 0,
  9662. &intel_primary_plane_funcs,
  9663. intel_primary_formats, num_formats,
  9664. DRM_PLANE_TYPE_PRIMARY);
  9665. return &primary->base;
  9666. }
  9667. static int
  9668. intel_cursor_plane_disable(struct drm_plane *plane)
  9669. {
  9670. if (!plane->fb)
  9671. return 0;
  9672. BUG_ON(!plane->crtc);
  9673. return intel_crtc_cursor_set_obj(plane->crtc, NULL, 0, 0);
  9674. }
  9675. static int
  9676. intel_cursor_plane_update(struct drm_plane *plane, struct drm_crtc *crtc,
  9677. struct drm_framebuffer *fb, int crtc_x, int crtc_y,
  9678. unsigned int crtc_w, unsigned int crtc_h,
  9679. uint32_t src_x, uint32_t src_y,
  9680. uint32_t src_w, uint32_t src_h)
  9681. {
  9682. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  9683. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  9684. struct drm_i915_gem_object *obj = intel_fb->obj;
  9685. struct drm_rect dest = {
  9686. /* integer pixels */
  9687. .x1 = crtc_x,
  9688. .y1 = crtc_y,
  9689. .x2 = crtc_x + crtc_w,
  9690. .y2 = crtc_y + crtc_h,
  9691. };
  9692. struct drm_rect src = {
  9693. /* 16.16 fixed point */
  9694. .x1 = src_x,
  9695. .y1 = src_y,
  9696. .x2 = src_x + src_w,
  9697. .y2 = src_y + src_h,
  9698. };
  9699. const struct drm_rect clip = {
  9700. /* integer pixels */
  9701. .x2 = intel_crtc->config.pipe_src_w,
  9702. .y2 = intel_crtc->config.pipe_src_h,
  9703. };
  9704. bool visible;
  9705. int ret;
  9706. ret = drm_plane_helper_check_update(plane, crtc, fb,
  9707. &src, &dest, &clip,
  9708. DRM_PLANE_HELPER_NO_SCALING,
  9709. DRM_PLANE_HELPER_NO_SCALING,
  9710. true, true, &visible);
  9711. if (ret)
  9712. return ret;
  9713. crtc->cursor_x = crtc_x;
  9714. crtc->cursor_y = crtc_y;
  9715. if (fb != crtc->cursor->fb) {
  9716. return intel_crtc_cursor_set_obj(crtc, obj, crtc_w, crtc_h);
  9717. } else {
  9718. intel_crtc_update_cursor(crtc, visible);
  9719. return 0;
  9720. }
  9721. }
  9722. static const struct drm_plane_funcs intel_cursor_plane_funcs = {
  9723. .update_plane = intel_cursor_plane_update,
  9724. .disable_plane = intel_cursor_plane_disable,
  9725. .destroy = intel_plane_destroy,
  9726. };
  9727. static struct drm_plane *intel_cursor_plane_create(struct drm_device *dev,
  9728. int pipe)
  9729. {
  9730. struct intel_plane *cursor;
  9731. cursor = kzalloc(sizeof(*cursor), GFP_KERNEL);
  9732. if (cursor == NULL)
  9733. return NULL;
  9734. cursor->can_scale = false;
  9735. cursor->max_downscale = 1;
  9736. cursor->pipe = pipe;
  9737. cursor->plane = pipe;
  9738. drm_universal_plane_init(dev, &cursor->base, 0,
  9739. &intel_cursor_plane_funcs,
  9740. intel_cursor_formats,
  9741. ARRAY_SIZE(intel_cursor_formats),
  9742. DRM_PLANE_TYPE_CURSOR);
  9743. return &cursor->base;
  9744. }
  9745. static void intel_crtc_init(struct drm_device *dev, int pipe)
  9746. {
  9747. struct drm_i915_private *dev_priv = dev->dev_private;
  9748. struct intel_crtc *intel_crtc;
  9749. struct drm_plane *primary = NULL;
  9750. struct drm_plane *cursor = NULL;
  9751. int i, ret;
  9752. intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL);
  9753. if (intel_crtc == NULL)
  9754. return;
  9755. primary = intel_primary_plane_create(dev, pipe);
  9756. if (!primary)
  9757. goto fail;
  9758. cursor = intel_cursor_plane_create(dev, pipe);
  9759. if (!cursor)
  9760. goto fail;
  9761. ret = drm_crtc_init_with_planes(dev, &intel_crtc->base, primary,
  9762. cursor, &intel_crtc_funcs);
  9763. if (ret)
  9764. goto fail;
  9765. drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256);
  9766. for (i = 0; i < 256; i++) {
  9767. intel_crtc->lut_r[i] = i;
  9768. intel_crtc->lut_g[i] = i;
  9769. intel_crtc->lut_b[i] = i;
  9770. }
  9771. /*
  9772. * On gen2/3 only plane A can do fbc, but the panel fitter and lvds port
  9773. * is hooked to pipe B. Hence we want plane A feeding pipe B.
  9774. */
  9775. intel_crtc->pipe = pipe;
  9776. intel_crtc->plane = pipe;
  9777. if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) {
  9778. DRM_DEBUG_KMS("swapping pipes & planes for FBC\n");
  9779. intel_crtc->plane = !pipe;
  9780. }
  9781. intel_crtc->cursor_base = ~0;
  9782. intel_crtc->cursor_cntl = ~0;
  9783. init_waitqueue_head(&intel_crtc->vbl_wait);
  9784. BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
  9785. dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL);
  9786. dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base;
  9787. dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base;
  9788. drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
  9789. WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe);
  9790. return;
  9791. fail:
  9792. if (primary)
  9793. drm_plane_cleanup(primary);
  9794. if (cursor)
  9795. drm_plane_cleanup(cursor);
  9796. kfree(intel_crtc);
  9797. }
  9798. enum pipe intel_get_pipe_from_connector(struct intel_connector *connector)
  9799. {
  9800. struct drm_encoder *encoder = connector->base.encoder;
  9801. struct drm_device *dev = connector->base.dev;
  9802. WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
  9803. if (!encoder)
  9804. return INVALID_PIPE;
  9805. return to_intel_crtc(encoder->crtc)->pipe;
  9806. }
  9807. int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data,
  9808. struct drm_file *file)
  9809. {
  9810. struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
  9811. struct drm_mode_object *drmmode_obj;
  9812. struct intel_crtc *crtc;
  9813. if (!drm_core_check_feature(dev, DRIVER_MODESET))
  9814. return -ENODEV;
  9815. drmmode_obj = drm_mode_object_find(dev, pipe_from_crtc_id->crtc_id,
  9816. DRM_MODE_OBJECT_CRTC);
  9817. if (!drmmode_obj) {
  9818. DRM_ERROR("no such CRTC id\n");
  9819. return -ENOENT;
  9820. }
  9821. crtc = to_intel_crtc(obj_to_crtc(drmmode_obj));
  9822. pipe_from_crtc_id->pipe = crtc->pipe;
  9823. return 0;
  9824. }
  9825. static int intel_encoder_clones(struct intel_encoder *encoder)
  9826. {
  9827. struct drm_device *dev = encoder->base.dev;
  9828. struct intel_encoder *source_encoder;
  9829. int index_mask = 0;
  9830. int entry = 0;
  9831. list_for_each_entry(source_encoder,
  9832. &dev->mode_config.encoder_list, base.head) {
  9833. if (encoders_cloneable(encoder, source_encoder))
  9834. index_mask |= (1 << entry);
  9835. entry++;
  9836. }
  9837. return index_mask;
  9838. }
  9839. static bool has_edp_a(struct drm_device *dev)
  9840. {
  9841. struct drm_i915_private *dev_priv = dev->dev_private;
  9842. if (!IS_MOBILE(dev))
  9843. return false;
  9844. if ((I915_READ(DP_A) & DP_DETECTED) == 0)
  9845. return false;
  9846. if (IS_GEN5(dev) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE))
  9847. return false;
  9848. return true;
  9849. }
  9850. const char *intel_output_name(int output)
  9851. {
  9852. static const char *names[] = {
  9853. [INTEL_OUTPUT_UNUSED] = "Unused",
  9854. [INTEL_OUTPUT_ANALOG] = "Analog",
  9855. [INTEL_OUTPUT_DVO] = "DVO",
  9856. [INTEL_OUTPUT_SDVO] = "SDVO",
  9857. [INTEL_OUTPUT_LVDS] = "LVDS",
  9858. [INTEL_OUTPUT_TVOUT] = "TV",
  9859. [INTEL_OUTPUT_HDMI] = "HDMI",
  9860. [INTEL_OUTPUT_DISPLAYPORT] = "DisplayPort",
  9861. [INTEL_OUTPUT_EDP] = "eDP",
  9862. [INTEL_OUTPUT_DSI] = "DSI",
  9863. [INTEL_OUTPUT_UNKNOWN] = "Unknown",
  9864. };
  9865. if (output < 0 || output >= ARRAY_SIZE(names) || !names[output])
  9866. return "Invalid";
  9867. return names[output];
  9868. }
  9869. static void intel_setup_outputs(struct drm_device *dev)
  9870. {
  9871. struct drm_i915_private *dev_priv = dev->dev_private;
  9872. struct intel_encoder *encoder;
  9873. bool dpd_is_edp = false;
  9874. intel_lvds_init(dev);
  9875. if (!IS_ULT(dev) && !IS_CHERRYVIEW(dev) && dev_priv->vbt.int_crt_support)
  9876. intel_crt_init(dev);
  9877. if (HAS_DDI(dev)) {
  9878. int found;
  9879. /* Haswell uses DDI functions to detect digital outputs */
  9880. found = I915_READ(DDI_BUF_CTL_A) & DDI_INIT_DISPLAY_DETECTED;
  9881. /* DDI A only supports eDP */
  9882. if (found)
  9883. intel_ddi_init(dev, PORT_A);
  9884. /* DDI B, C and D detection is indicated by the SFUSE_STRAP
  9885. * register */
  9886. found = I915_READ(SFUSE_STRAP);
  9887. if (found & SFUSE_STRAP_DDIB_DETECTED)
  9888. intel_ddi_init(dev, PORT_B);
  9889. if (found & SFUSE_STRAP_DDIC_DETECTED)
  9890. intel_ddi_init(dev, PORT_C);
  9891. if (found & SFUSE_STRAP_DDID_DETECTED)
  9892. intel_ddi_init(dev, PORT_D);
  9893. } else if (HAS_PCH_SPLIT(dev)) {
  9894. int found;
  9895. dpd_is_edp = intel_dp_is_edp(dev, PORT_D);
  9896. if (has_edp_a(dev))
  9897. intel_dp_init(dev, DP_A, PORT_A);
  9898. if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) {
  9899. /* PCH SDVOB multiplex with HDMIB */
  9900. found = intel_sdvo_init(dev, PCH_SDVOB, true);
  9901. if (!found)
  9902. intel_hdmi_init(dev, PCH_HDMIB, PORT_B);
  9903. if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
  9904. intel_dp_init(dev, PCH_DP_B, PORT_B);
  9905. }
  9906. if (I915_READ(PCH_HDMIC) & SDVO_DETECTED)
  9907. intel_hdmi_init(dev, PCH_HDMIC, PORT_C);
  9908. if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED)
  9909. intel_hdmi_init(dev, PCH_HDMID, PORT_D);
  9910. if (I915_READ(PCH_DP_C) & DP_DETECTED)
  9911. intel_dp_init(dev, PCH_DP_C, PORT_C);
  9912. if (I915_READ(PCH_DP_D) & DP_DETECTED)
  9913. intel_dp_init(dev, PCH_DP_D, PORT_D);
  9914. } else if (IS_VALLEYVIEW(dev)) {
  9915. if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIB) & SDVO_DETECTED) {
  9916. intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIB,
  9917. PORT_B);
  9918. if (I915_READ(VLV_DISPLAY_BASE + DP_B) & DP_DETECTED)
  9919. intel_dp_init(dev, VLV_DISPLAY_BASE + DP_B, PORT_B);
  9920. }
  9921. if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIC) & SDVO_DETECTED) {
  9922. intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIC,
  9923. PORT_C);
  9924. if (I915_READ(VLV_DISPLAY_BASE + DP_C) & DP_DETECTED)
  9925. intel_dp_init(dev, VLV_DISPLAY_BASE + DP_C, PORT_C);
  9926. }
  9927. if (IS_CHERRYVIEW(dev)) {
  9928. if (I915_READ(VLV_DISPLAY_BASE + CHV_HDMID) & SDVO_DETECTED) {
  9929. intel_hdmi_init(dev, VLV_DISPLAY_BASE + CHV_HDMID,
  9930. PORT_D);
  9931. if (I915_READ(VLV_DISPLAY_BASE + DP_D) & DP_DETECTED)
  9932. intel_dp_init(dev, VLV_DISPLAY_BASE + DP_D, PORT_D);
  9933. }
  9934. }
  9935. intel_dsi_init(dev);
  9936. } else if (SUPPORTS_DIGITAL_OUTPUTS(dev)) {
  9937. bool found = false;
  9938. if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
  9939. DRM_DEBUG_KMS("probing SDVOB\n");
  9940. found = intel_sdvo_init(dev, GEN3_SDVOB, true);
  9941. if (!found && SUPPORTS_INTEGRATED_HDMI(dev)) {
  9942. DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
  9943. intel_hdmi_init(dev, GEN4_HDMIB, PORT_B);
  9944. }
  9945. if (!found && SUPPORTS_INTEGRATED_DP(dev))
  9946. intel_dp_init(dev, DP_B, PORT_B);
  9947. }
  9948. /* Before G4X SDVOC doesn't have its own detect register */
  9949. if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
  9950. DRM_DEBUG_KMS("probing SDVOC\n");
  9951. found = intel_sdvo_init(dev, GEN3_SDVOC, false);
  9952. }
  9953. if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) {
  9954. if (SUPPORTS_INTEGRATED_HDMI(dev)) {
  9955. DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
  9956. intel_hdmi_init(dev, GEN4_HDMIC, PORT_C);
  9957. }
  9958. if (SUPPORTS_INTEGRATED_DP(dev))
  9959. intel_dp_init(dev, DP_C, PORT_C);
  9960. }
  9961. if (SUPPORTS_INTEGRATED_DP(dev) &&
  9962. (I915_READ(DP_D) & DP_DETECTED))
  9963. intel_dp_init(dev, DP_D, PORT_D);
  9964. } else if (IS_GEN2(dev))
  9965. intel_dvo_init(dev);
  9966. if (SUPPORTS_TV(dev))
  9967. intel_tv_init(dev);
  9968. intel_edp_psr_init(dev);
  9969. list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head) {
  9970. encoder->base.possible_crtcs = encoder->crtc_mask;
  9971. encoder->base.possible_clones =
  9972. intel_encoder_clones(encoder);
  9973. }
  9974. intel_init_pch_refclk(dev);
  9975. drm_helper_move_panel_connectors_to_head(dev);
  9976. }
  9977. static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
  9978. {
  9979. struct drm_device *dev = fb->dev;
  9980. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  9981. drm_framebuffer_cleanup(fb);
  9982. mutex_lock(&dev->struct_mutex);
  9983. WARN_ON(!intel_fb->obj->framebuffer_references--);
  9984. drm_gem_object_unreference(&intel_fb->obj->base);
  9985. mutex_unlock(&dev->struct_mutex);
  9986. kfree(intel_fb);
  9987. }
  9988. static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
  9989. struct drm_file *file,
  9990. unsigned int *handle)
  9991. {
  9992. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  9993. struct drm_i915_gem_object *obj = intel_fb->obj;
  9994. return drm_gem_handle_create(file, &obj->base, handle);
  9995. }
  9996. static const struct drm_framebuffer_funcs intel_fb_funcs = {
  9997. .destroy = intel_user_framebuffer_destroy,
  9998. .create_handle = intel_user_framebuffer_create_handle,
  9999. };
  10000. static int intel_framebuffer_init(struct drm_device *dev,
  10001. struct intel_framebuffer *intel_fb,
  10002. struct drm_mode_fb_cmd2 *mode_cmd,
  10003. struct drm_i915_gem_object *obj)
  10004. {
  10005. int aligned_height;
  10006. int pitch_limit;
  10007. int ret;
  10008. WARN_ON(!mutex_is_locked(&dev->struct_mutex));
  10009. if (obj->tiling_mode == I915_TILING_Y) {
  10010. DRM_DEBUG("hardware does not support tiling Y\n");
  10011. return -EINVAL;
  10012. }
  10013. if (mode_cmd->pitches[0] & 63) {
  10014. DRM_DEBUG("pitch (%d) must be at least 64 byte aligned\n",
  10015. mode_cmd->pitches[0]);
  10016. return -EINVAL;
  10017. }
  10018. if (INTEL_INFO(dev)->gen >= 5 && !IS_VALLEYVIEW(dev)) {
  10019. pitch_limit = 32*1024;
  10020. } else if (INTEL_INFO(dev)->gen >= 4) {
  10021. if (obj->tiling_mode)
  10022. pitch_limit = 16*1024;
  10023. else
  10024. pitch_limit = 32*1024;
  10025. } else if (INTEL_INFO(dev)->gen >= 3) {
  10026. if (obj->tiling_mode)
  10027. pitch_limit = 8*1024;
  10028. else
  10029. pitch_limit = 16*1024;
  10030. } else
  10031. /* XXX DSPC is limited to 4k tiled */
  10032. pitch_limit = 8*1024;
  10033. if (mode_cmd->pitches[0] > pitch_limit) {
  10034. DRM_DEBUG("%s pitch (%d) must be at less than %d\n",
  10035. obj->tiling_mode ? "tiled" : "linear",
  10036. mode_cmd->pitches[0], pitch_limit);
  10037. return -EINVAL;
  10038. }
  10039. if (obj->tiling_mode != I915_TILING_NONE &&
  10040. mode_cmd->pitches[0] != obj->stride) {
  10041. DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n",
  10042. mode_cmd->pitches[0], obj->stride);
  10043. return -EINVAL;
  10044. }
  10045. /* Reject formats not supported by any plane early. */
  10046. switch (mode_cmd->pixel_format) {
  10047. case DRM_FORMAT_C8:
  10048. case DRM_FORMAT_RGB565:
  10049. case DRM_FORMAT_XRGB8888:
  10050. case DRM_FORMAT_ARGB8888:
  10051. break;
  10052. case DRM_FORMAT_XRGB1555:
  10053. case DRM_FORMAT_ARGB1555:
  10054. if (INTEL_INFO(dev)->gen > 3) {
  10055. DRM_DEBUG("unsupported pixel format: %s\n",
  10056. drm_get_format_name(mode_cmd->pixel_format));
  10057. return -EINVAL;
  10058. }
  10059. break;
  10060. case DRM_FORMAT_XBGR8888:
  10061. case DRM_FORMAT_ABGR8888:
  10062. case DRM_FORMAT_XRGB2101010:
  10063. case DRM_FORMAT_ARGB2101010:
  10064. case DRM_FORMAT_XBGR2101010:
  10065. case DRM_FORMAT_ABGR2101010:
  10066. if (INTEL_INFO(dev)->gen < 4) {
  10067. DRM_DEBUG("unsupported pixel format: %s\n",
  10068. drm_get_format_name(mode_cmd->pixel_format));
  10069. return -EINVAL;
  10070. }
  10071. break;
  10072. case DRM_FORMAT_YUYV:
  10073. case DRM_FORMAT_UYVY:
  10074. case DRM_FORMAT_YVYU:
  10075. case DRM_FORMAT_VYUY:
  10076. if (INTEL_INFO(dev)->gen < 5) {
  10077. DRM_DEBUG("unsupported pixel format: %s\n",
  10078. drm_get_format_name(mode_cmd->pixel_format));
  10079. return -EINVAL;
  10080. }
  10081. break;
  10082. default:
  10083. DRM_DEBUG("unsupported pixel format: %s\n",
  10084. drm_get_format_name(mode_cmd->pixel_format));
  10085. return -EINVAL;
  10086. }
  10087. /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
  10088. if (mode_cmd->offsets[0] != 0)
  10089. return -EINVAL;
  10090. aligned_height = intel_align_height(dev, mode_cmd->height,
  10091. obj->tiling_mode);
  10092. /* FIXME drm helper for size checks (especially planar formats)? */
  10093. if (obj->base.size < aligned_height * mode_cmd->pitches[0])
  10094. return -EINVAL;
  10095. drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd);
  10096. intel_fb->obj = obj;
  10097. intel_fb->obj->framebuffer_references++;
  10098. ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs);
  10099. if (ret) {
  10100. DRM_ERROR("framebuffer init failed %d\n", ret);
  10101. return ret;
  10102. }
  10103. return 0;
  10104. }
  10105. static struct drm_framebuffer *
  10106. intel_user_framebuffer_create(struct drm_device *dev,
  10107. struct drm_file *filp,
  10108. struct drm_mode_fb_cmd2 *mode_cmd)
  10109. {
  10110. struct drm_i915_gem_object *obj;
  10111. obj = to_intel_bo(drm_gem_object_lookup(dev, filp,
  10112. mode_cmd->handles[0]));
  10113. if (&obj->base == NULL)
  10114. return ERR_PTR(-ENOENT);
  10115. return intel_framebuffer_create(dev, mode_cmd, obj);
  10116. }
  10117. #ifndef CONFIG_DRM_I915_FBDEV
  10118. static inline void intel_fbdev_output_poll_changed(struct drm_device *dev)
  10119. {
  10120. }
  10121. #endif
  10122. static const struct drm_mode_config_funcs intel_mode_funcs = {
  10123. .fb_create = intel_user_framebuffer_create,
  10124. .output_poll_changed = intel_fbdev_output_poll_changed,
  10125. };
  10126. /* Set up chip specific display functions */
  10127. static void intel_init_display(struct drm_device *dev)
  10128. {
  10129. struct drm_i915_private *dev_priv = dev->dev_private;
  10130. if (HAS_PCH_SPLIT(dev) || IS_G4X(dev))
  10131. dev_priv->display.find_dpll = g4x_find_best_dpll;
  10132. else if (IS_CHERRYVIEW(dev))
  10133. dev_priv->display.find_dpll = chv_find_best_dpll;
  10134. else if (IS_VALLEYVIEW(dev))
  10135. dev_priv->display.find_dpll = vlv_find_best_dpll;
  10136. else if (IS_PINEVIEW(dev))
  10137. dev_priv->display.find_dpll = pnv_find_best_dpll;
  10138. else
  10139. dev_priv->display.find_dpll = i9xx_find_best_dpll;
  10140. if (HAS_DDI(dev)) {
  10141. dev_priv->display.get_pipe_config = haswell_get_pipe_config;
  10142. dev_priv->display.get_plane_config = ironlake_get_plane_config;
  10143. dev_priv->display.crtc_mode_set = haswell_crtc_mode_set;
  10144. dev_priv->display.crtc_enable = haswell_crtc_enable;
  10145. dev_priv->display.crtc_disable = haswell_crtc_disable;
  10146. dev_priv->display.off = haswell_crtc_off;
  10147. dev_priv->display.update_primary_plane =
  10148. ironlake_update_primary_plane;
  10149. } else if (HAS_PCH_SPLIT(dev)) {
  10150. dev_priv->display.get_pipe_config = ironlake_get_pipe_config;
  10151. dev_priv->display.get_plane_config = ironlake_get_plane_config;
  10152. dev_priv->display.crtc_mode_set = ironlake_crtc_mode_set;
  10153. dev_priv->display.crtc_enable = ironlake_crtc_enable;
  10154. dev_priv->display.crtc_disable = ironlake_crtc_disable;
  10155. dev_priv->display.off = ironlake_crtc_off;
  10156. dev_priv->display.update_primary_plane =
  10157. ironlake_update_primary_plane;
  10158. } else if (IS_VALLEYVIEW(dev)) {
  10159. dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
  10160. dev_priv->display.get_plane_config = i9xx_get_plane_config;
  10161. dev_priv->display.crtc_mode_set = i9xx_crtc_mode_set;
  10162. dev_priv->display.crtc_enable = valleyview_crtc_enable;
  10163. dev_priv->display.crtc_disable = i9xx_crtc_disable;
  10164. dev_priv->display.off = i9xx_crtc_off;
  10165. dev_priv->display.update_primary_plane =
  10166. i9xx_update_primary_plane;
  10167. } else {
  10168. dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
  10169. dev_priv->display.get_plane_config = i9xx_get_plane_config;
  10170. dev_priv->display.crtc_mode_set = i9xx_crtc_mode_set;
  10171. dev_priv->display.crtc_enable = i9xx_crtc_enable;
  10172. dev_priv->display.crtc_disable = i9xx_crtc_disable;
  10173. dev_priv->display.off = i9xx_crtc_off;
  10174. dev_priv->display.update_primary_plane =
  10175. i9xx_update_primary_plane;
  10176. }
  10177. /* Returns the core display clock speed */
  10178. if (IS_VALLEYVIEW(dev))
  10179. dev_priv->display.get_display_clock_speed =
  10180. valleyview_get_display_clock_speed;
  10181. else if (IS_I945G(dev) || (IS_G33(dev) && !IS_PINEVIEW_M(dev)))
  10182. dev_priv->display.get_display_clock_speed =
  10183. i945_get_display_clock_speed;
  10184. else if (IS_I915G(dev))
  10185. dev_priv->display.get_display_clock_speed =
  10186. i915_get_display_clock_speed;
  10187. else if (IS_I945GM(dev) || IS_845G(dev))
  10188. dev_priv->display.get_display_clock_speed =
  10189. i9xx_misc_get_display_clock_speed;
  10190. else if (IS_PINEVIEW(dev))
  10191. dev_priv->display.get_display_clock_speed =
  10192. pnv_get_display_clock_speed;
  10193. else if (IS_I915GM(dev))
  10194. dev_priv->display.get_display_clock_speed =
  10195. i915gm_get_display_clock_speed;
  10196. else if (IS_I865G(dev))
  10197. dev_priv->display.get_display_clock_speed =
  10198. i865_get_display_clock_speed;
  10199. else if (IS_I85X(dev))
  10200. dev_priv->display.get_display_clock_speed =
  10201. i855_get_display_clock_speed;
  10202. else /* 852, 830 */
  10203. dev_priv->display.get_display_clock_speed =
  10204. i830_get_display_clock_speed;
  10205. if (HAS_PCH_SPLIT(dev)) {
  10206. if (IS_GEN5(dev)) {
  10207. dev_priv->display.fdi_link_train = ironlake_fdi_link_train;
  10208. dev_priv->display.write_eld = ironlake_write_eld;
  10209. } else if (IS_GEN6(dev)) {
  10210. dev_priv->display.fdi_link_train = gen6_fdi_link_train;
  10211. dev_priv->display.write_eld = ironlake_write_eld;
  10212. dev_priv->display.modeset_global_resources =
  10213. snb_modeset_global_resources;
  10214. } else if (IS_IVYBRIDGE(dev)) {
  10215. /* FIXME: detect B0+ stepping and use auto training */
  10216. dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train;
  10217. dev_priv->display.write_eld = ironlake_write_eld;
  10218. dev_priv->display.modeset_global_resources =
  10219. ivb_modeset_global_resources;
  10220. } else if (IS_HASWELL(dev) || IS_GEN8(dev)) {
  10221. dev_priv->display.fdi_link_train = hsw_fdi_link_train;
  10222. dev_priv->display.write_eld = haswell_write_eld;
  10223. dev_priv->display.modeset_global_resources =
  10224. haswell_modeset_global_resources;
  10225. }
  10226. } else if (IS_G4X(dev)) {
  10227. dev_priv->display.write_eld = g4x_write_eld;
  10228. } else if (IS_VALLEYVIEW(dev)) {
  10229. dev_priv->display.modeset_global_resources =
  10230. valleyview_modeset_global_resources;
  10231. dev_priv->display.write_eld = ironlake_write_eld;
  10232. }
  10233. /* Default just returns -ENODEV to indicate unsupported */
  10234. dev_priv->display.queue_flip = intel_default_queue_flip;
  10235. switch (INTEL_INFO(dev)->gen) {
  10236. case 2:
  10237. dev_priv->display.queue_flip = intel_gen2_queue_flip;
  10238. break;
  10239. case 3:
  10240. dev_priv->display.queue_flip = intel_gen3_queue_flip;
  10241. break;
  10242. case 4:
  10243. case 5:
  10244. dev_priv->display.queue_flip = intel_gen4_queue_flip;
  10245. break;
  10246. case 6:
  10247. dev_priv->display.queue_flip = intel_gen6_queue_flip;
  10248. break;
  10249. case 7:
  10250. case 8: /* FIXME(BDW): Check that the gen8 RCS flip works. */
  10251. dev_priv->display.queue_flip = intel_gen7_queue_flip;
  10252. break;
  10253. }
  10254. intel_panel_init_backlight_funcs(dev);
  10255. }
  10256. /*
  10257. * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend,
  10258. * resume, or other times. This quirk makes sure that's the case for
  10259. * affected systems.
  10260. */
  10261. static void quirk_pipea_force(struct drm_device *dev)
  10262. {
  10263. struct drm_i915_private *dev_priv = dev->dev_private;
  10264. dev_priv->quirks |= QUIRK_PIPEA_FORCE;
  10265. DRM_INFO("applying pipe a force quirk\n");
  10266. }
  10267. /*
  10268. * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason
  10269. */
  10270. static void quirk_ssc_force_disable(struct drm_device *dev)
  10271. {
  10272. struct drm_i915_private *dev_priv = dev->dev_private;
  10273. dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE;
  10274. DRM_INFO("applying lvds SSC disable quirk\n");
  10275. }
  10276. /*
  10277. * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight
  10278. * brightness value
  10279. */
  10280. static void quirk_invert_brightness(struct drm_device *dev)
  10281. {
  10282. struct drm_i915_private *dev_priv = dev->dev_private;
  10283. dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS;
  10284. DRM_INFO("applying inverted panel brightness quirk\n");
  10285. }
  10286. struct intel_quirk {
  10287. int device;
  10288. int subsystem_vendor;
  10289. int subsystem_device;
  10290. void (*hook)(struct drm_device *dev);
  10291. };
  10292. /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
  10293. struct intel_dmi_quirk {
  10294. void (*hook)(struct drm_device *dev);
  10295. const struct dmi_system_id (*dmi_id_list)[];
  10296. };
  10297. static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
  10298. {
  10299. DRM_INFO("Backlight polarity reversed on %s\n", id->ident);
  10300. return 1;
  10301. }
  10302. static const struct intel_dmi_quirk intel_dmi_quirks[] = {
  10303. {
  10304. .dmi_id_list = &(const struct dmi_system_id[]) {
  10305. {
  10306. .callback = intel_dmi_reverse_brightness,
  10307. .ident = "NCR Corporation",
  10308. .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
  10309. DMI_MATCH(DMI_PRODUCT_NAME, ""),
  10310. },
  10311. },
  10312. { } /* terminating entry */
  10313. },
  10314. .hook = quirk_invert_brightness,
  10315. },
  10316. };
  10317. static struct intel_quirk intel_quirks[] = {
  10318. /* HP Mini needs pipe A force quirk (LP: #322104) */
  10319. { 0x27ae, 0x103c, 0x361a, quirk_pipea_force },
  10320. /* Toshiba Protege R-205, S-209 needs pipe A force quirk */
  10321. { 0x2592, 0x1179, 0x0001, quirk_pipea_force },
  10322. /* ThinkPad T60 needs pipe A force quirk (bug #16494) */
  10323. { 0x2782, 0x17aa, 0x201a, quirk_pipea_force },
  10324. /* Lenovo U160 cannot use SSC on LVDS */
  10325. { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable },
  10326. /* Sony Vaio Y cannot use SSC on LVDS */
  10327. { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable },
  10328. /* Acer Aspire 5734Z must invert backlight brightness */
  10329. { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness },
  10330. /* Acer/eMachines G725 */
  10331. { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness },
  10332. /* Acer/eMachines e725 */
  10333. { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness },
  10334. /* Acer/Packard Bell NCL20 */
  10335. { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness },
  10336. /* Acer Aspire 4736Z */
  10337. { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness },
  10338. /* Acer Aspire 5336 */
  10339. { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness },
  10340. };
  10341. static void intel_init_quirks(struct drm_device *dev)
  10342. {
  10343. struct pci_dev *d = dev->pdev;
  10344. int i;
  10345. for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) {
  10346. struct intel_quirk *q = &intel_quirks[i];
  10347. if (d->device == q->device &&
  10348. (d->subsystem_vendor == q->subsystem_vendor ||
  10349. q->subsystem_vendor == PCI_ANY_ID) &&
  10350. (d->subsystem_device == q->subsystem_device ||
  10351. q->subsystem_device == PCI_ANY_ID))
  10352. q->hook(dev);
  10353. }
  10354. for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) {
  10355. if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0)
  10356. intel_dmi_quirks[i].hook(dev);
  10357. }
  10358. }
  10359. /* Disable the VGA plane that we never use */
  10360. static void i915_disable_vga(struct drm_device *dev)
  10361. {
  10362. struct drm_i915_private *dev_priv = dev->dev_private;
  10363. u8 sr1;
  10364. u32 vga_reg = i915_vgacntrl_reg(dev);
  10365. /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
  10366. vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO);
  10367. outb(SR01, VGA_SR_INDEX);
  10368. sr1 = inb(VGA_SR_DATA);
  10369. outb(sr1 | 1<<5, VGA_SR_DATA);
  10370. vga_put(dev->pdev, VGA_RSRC_LEGACY_IO);
  10371. udelay(300);
  10372. I915_WRITE(vga_reg, VGA_DISP_DISABLE);
  10373. POSTING_READ(vga_reg);
  10374. }
  10375. void intel_modeset_init_hw(struct drm_device *dev)
  10376. {
  10377. intel_prepare_ddi(dev);
  10378. intel_init_clock_gating(dev);
  10379. intel_reset_dpio(dev);
  10380. intel_enable_gt_powersave(dev);
  10381. }
  10382. void intel_modeset_suspend_hw(struct drm_device *dev)
  10383. {
  10384. intel_suspend_hw(dev);
  10385. }
  10386. void intel_modeset_init(struct drm_device *dev)
  10387. {
  10388. struct drm_i915_private *dev_priv = dev->dev_private;
  10389. int sprite, ret;
  10390. enum pipe pipe;
  10391. struct intel_crtc *crtc;
  10392. drm_mode_config_init(dev);
  10393. dev->mode_config.min_width = 0;
  10394. dev->mode_config.min_height = 0;
  10395. dev->mode_config.preferred_depth = 24;
  10396. dev->mode_config.prefer_shadow = 1;
  10397. dev->mode_config.funcs = &intel_mode_funcs;
  10398. intel_init_quirks(dev);
  10399. intel_init_pm(dev);
  10400. if (INTEL_INFO(dev)->num_pipes == 0)
  10401. return;
  10402. intel_init_display(dev);
  10403. if (IS_GEN2(dev)) {
  10404. dev->mode_config.max_width = 2048;
  10405. dev->mode_config.max_height = 2048;
  10406. } else if (IS_GEN3(dev)) {
  10407. dev->mode_config.max_width = 4096;
  10408. dev->mode_config.max_height = 4096;
  10409. } else {
  10410. dev->mode_config.max_width = 8192;
  10411. dev->mode_config.max_height = 8192;
  10412. }
  10413. if (IS_GEN2(dev)) {
  10414. dev->mode_config.cursor_width = GEN2_CURSOR_WIDTH;
  10415. dev->mode_config.cursor_height = GEN2_CURSOR_HEIGHT;
  10416. } else {
  10417. dev->mode_config.cursor_width = MAX_CURSOR_WIDTH;
  10418. dev->mode_config.cursor_height = MAX_CURSOR_HEIGHT;
  10419. }
  10420. dev->mode_config.fb_base = dev_priv->gtt.mappable_base;
  10421. DRM_DEBUG_KMS("%d display pipe%s available.\n",
  10422. INTEL_INFO(dev)->num_pipes,
  10423. INTEL_INFO(dev)->num_pipes > 1 ? "s" : "");
  10424. for_each_pipe(pipe) {
  10425. intel_crtc_init(dev, pipe);
  10426. for_each_sprite(pipe, sprite) {
  10427. ret = intel_plane_init(dev, pipe, sprite);
  10428. if (ret)
  10429. DRM_DEBUG_KMS("pipe %c sprite %c init failed: %d\n",
  10430. pipe_name(pipe), sprite_name(pipe, sprite), ret);
  10431. }
  10432. }
  10433. intel_init_dpio(dev);
  10434. intel_reset_dpio(dev);
  10435. intel_cpu_pll_init(dev);
  10436. intel_shared_dpll_init(dev);
  10437. /* Just disable it once at startup */
  10438. i915_disable_vga(dev);
  10439. intel_setup_outputs(dev);
  10440. /* Just in case the BIOS is doing something questionable. */
  10441. intel_disable_fbc(dev);
  10442. drm_modeset_lock_all(dev);
  10443. intel_modeset_setup_hw_state(dev, false);
  10444. drm_modeset_unlock_all(dev);
  10445. for_each_intel_crtc(dev, crtc) {
  10446. if (!crtc->active)
  10447. continue;
  10448. /*
  10449. * Note that reserving the BIOS fb up front prevents us
  10450. * from stuffing other stolen allocations like the ring
  10451. * on top. This prevents some ugliness at boot time, and
  10452. * can even allow for smooth boot transitions if the BIOS
  10453. * fb is large enough for the active pipe configuration.
  10454. */
  10455. if (dev_priv->display.get_plane_config) {
  10456. dev_priv->display.get_plane_config(crtc,
  10457. &crtc->plane_config);
  10458. /*
  10459. * If the fb is shared between multiple heads, we'll
  10460. * just get the first one.
  10461. */
  10462. intel_find_plane_obj(crtc, &crtc->plane_config);
  10463. }
  10464. }
  10465. }
  10466. static void intel_enable_pipe_a(struct drm_device *dev)
  10467. {
  10468. struct intel_connector *connector;
  10469. struct drm_connector *crt = NULL;
  10470. struct intel_load_detect_pipe load_detect_temp;
  10471. struct drm_modeset_acquire_ctx ctx;
  10472. /* We can't just switch on the pipe A, we need to set things up with a
  10473. * proper mode and output configuration. As a gross hack, enable pipe A
  10474. * by enabling the load detect pipe once. */
  10475. list_for_each_entry(connector,
  10476. &dev->mode_config.connector_list,
  10477. base.head) {
  10478. if (connector->encoder->type == INTEL_OUTPUT_ANALOG) {
  10479. crt = &connector->base;
  10480. break;
  10481. }
  10482. }
  10483. if (!crt)
  10484. return;
  10485. if (intel_get_load_detect_pipe(crt, NULL, &load_detect_temp, &ctx))
  10486. intel_release_load_detect_pipe(crt, &load_detect_temp, &ctx);
  10487. }
  10488. static bool
  10489. intel_check_plane_mapping(struct intel_crtc *crtc)
  10490. {
  10491. struct drm_device *dev = crtc->base.dev;
  10492. struct drm_i915_private *dev_priv = dev->dev_private;
  10493. u32 reg, val;
  10494. if (INTEL_INFO(dev)->num_pipes == 1)
  10495. return true;
  10496. reg = DSPCNTR(!crtc->plane);
  10497. val = I915_READ(reg);
  10498. if ((val & DISPLAY_PLANE_ENABLE) &&
  10499. (!!(val & DISPPLANE_SEL_PIPE_MASK) == crtc->pipe))
  10500. return false;
  10501. return true;
  10502. }
  10503. static void intel_sanitize_crtc(struct intel_crtc *crtc)
  10504. {
  10505. struct drm_device *dev = crtc->base.dev;
  10506. struct drm_i915_private *dev_priv = dev->dev_private;
  10507. u32 reg;
  10508. /* Clear any frame start delays used for debugging left by the BIOS */
  10509. reg = PIPECONF(crtc->config.cpu_transcoder);
  10510. I915_WRITE(reg, I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK);
  10511. /* restore vblank interrupts to correct state */
  10512. if (crtc->active)
  10513. drm_vblank_on(dev, crtc->pipe);
  10514. else
  10515. drm_vblank_off(dev, crtc->pipe);
  10516. /* We need to sanitize the plane -> pipe mapping first because this will
  10517. * disable the crtc (and hence change the state) if it is wrong. Note
  10518. * that gen4+ has a fixed plane -> pipe mapping. */
  10519. if (INTEL_INFO(dev)->gen < 4 && !intel_check_plane_mapping(crtc)) {
  10520. struct intel_connector *connector;
  10521. bool plane;
  10522. DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n",
  10523. crtc->base.base.id);
  10524. /* Pipe has the wrong plane attached and the plane is active.
  10525. * Temporarily change the plane mapping and disable everything
  10526. * ... */
  10527. plane = crtc->plane;
  10528. crtc->plane = !plane;
  10529. dev_priv->display.crtc_disable(&crtc->base);
  10530. crtc->plane = plane;
  10531. /* ... and break all links. */
  10532. list_for_each_entry(connector, &dev->mode_config.connector_list,
  10533. base.head) {
  10534. if (connector->encoder->base.crtc != &crtc->base)
  10535. continue;
  10536. connector->base.dpms = DRM_MODE_DPMS_OFF;
  10537. connector->base.encoder = NULL;
  10538. }
  10539. /* multiple connectors may have the same encoder:
  10540. * handle them and break crtc link separately */
  10541. list_for_each_entry(connector, &dev->mode_config.connector_list,
  10542. base.head)
  10543. if (connector->encoder->base.crtc == &crtc->base) {
  10544. connector->encoder->base.crtc = NULL;
  10545. connector->encoder->connectors_active = false;
  10546. }
  10547. WARN_ON(crtc->active);
  10548. crtc->base.enabled = false;
  10549. }
  10550. if (dev_priv->quirks & QUIRK_PIPEA_FORCE &&
  10551. crtc->pipe == PIPE_A && !crtc->active) {
  10552. /* BIOS forgot to enable pipe A, this mostly happens after
  10553. * resume. Force-enable the pipe to fix this, the update_dpms
  10554. * call below we restore the pipe to the right state, but leave
  10555. * the required bits on. */
  10556. intel_enable_pipe_a(dev);
  10557. }
  10558. /* Adjust the state of the output pipe according to whether we
  10559. * have active connectors/encoders. */
  10560. intel_crtc_update_dpms(&crtc->base);
  10561. if (crtc->active != crtc->base.enabled) {
  10562. struct intel_encoder *encoder;
  10563. /* This can happen either due to bugs in the get_hw_state
  10564. * functions or because the pipe is force-enabled due to the
  10565. * pipe A quirk. */
  10566. DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n",
  10567. crtc->base.base.id,
  10568. crtc->base.enabled ? "enabled" : "disabled",
  10569. crtc->active ? "enabled" : "disabled");
  10570. crtc->base.enabled = crtc->active;
  10571. /* Because we only establish the connector -> encoder ->
  10572. * crtc links if something is active, this means the
  10573. * crtc is now deactivated. Break the links. connector
  10574. * -> encoder links are only establish when things are
  10575. * actually up, hence no need to break them. */
  10576. WARN_ON(crtc->active);
  10577. for_each_encoder_on_crtc(dev, &crtc->base, encoder) {
  10578. WARN_ON(encoder->connectors_active);
  10579. encoder->base.crtc = NULL;
  10580. }
  10581. }
  10582. if (crtc->active || IS_VALLEYVIEW(dev) || INTEL_INFO(dev)->gen < 5) {
  10583. /*
  10584. * We start out with underrun reporting disabled to avoid races.
  10585. * For correct bookkeeping mark this on active crtcs.
  10586. *
  10587. * Also on gmch platforms we dont have any hardware bits to
  10588. * disable the underrun reporting. Which means we need to start
  10589. * out with underrun reporting disabled also on inactive pipes,
  10590. * since otherwise we'll complain about the garbage we read when
  10591. * e.g. coming up after runtime pm.
  10592. *
  10593. * No protection against concurrent access is required - at
  10594. * worst a fifo underrun happens which also sets this to false.
  10595. */
  10596. crtc->cpu_fifo_underrun_disabled = true;
  10597. crtc->pch_fifo_underrun_disabled = true;
  10598. update_scanline_offset(crtc);
  10599. }
  10600. }
  10601. static void intel_sanitize_encoder(struct intel_encoder *encoder)
  10602. {
  10603. struct intel_connector *connector;
  10604. struct drm_device *dev = encoder->base.dev;
  10605. /* We need to check both for a crtc link (meaning that the
  10606. * encoder is active and trying to read from a pipe) and the
  10607. * pipe itself being active. */
  10608. bool has_active_crtc = encoder->base.crtc &&
  10609. to_intel_crtc(encoder->base.crtc)->active;
  10610. if (encoder->connectors_active && !has_active_crtc) {
  10611. DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
  10612. encoder->base.base.id,
  10613. encoder->base.name);
  10614. /* Connector is active, but has no active pipe. This is
  10615. * fallout from our resume register restoring. Disable
  10616. * the encoder manually again. */
  10617. if (encoder->base.crtc) {
  10618. DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
  10619. encoder->base.base.id,
  10620. encoder->base.name);
  10621. encoder->disable(encoder);
  10622. }
  10623. encoder->base.crtc = NULL;
  10624. encoder->connectors_active = false;
  10625. /* Inconsistent output/port/pipe state happens presumably due to
  10626. * a bug in one of the get_hw_state functions. Or someplace else
  10627. * in our code, like the register restore mess on resume. Clamp
  10628. * things to off as a safer default. */
  10629. list_for_each_entry(connector,
  10630. &dev->mode_config.connector_list,
  10631. base.head) {
  10632. if (connector->encoder != encoder)
  10633. continue;
  10634. connector->base.dpms = DRM_MODE_DPMS_OFF;
  10635. connector->base.encoder = NULL;
  10636. }
  10637. }
  10638. /* Enabled encoders without active connectors will be fixed in
  10639. * the crtc fixup. */
  10640. }
  10641. void i915_redisable_vga_power_on(struct drm_device *dev)
  10642. {
  10643. struct drm_i915_private *dev_priv = dev->dev_private;
  10644. u32 vga_reg = i915_vgacntrl_reg(dev);
  10645. if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) {
  10646. DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
  10647. i915_disable_vga(dev);
  10648. }
  10649. }
  10650. void i915_redisable_vga(struct drm_device *dev)
  10651. {
  10652. struct drm_i915_private *dev_priv = dev->dev_private;
  10653. /* This function can be called both from intel_modeset_setup_hw_state or
  10654. * at a very early point in our resume sequence, where the power well
  10655. * structures are not yet restored. Since this function is at a very
  10656. * paranoid "someone might have enabled VGA while we were not looking"
  10657. * level, just check if the power well is enabled instead of trying to
  10658. * follow the "don't touch the power well if we don't need it" policy
  10659. * the rest of the driver uses. */
  10660. if (!intel_display_power_enabled(dev_priv, POWER_DOMAIN_VGA))
  10661. return;
  10662. i915_redisable_vga_power_on(dev);
  10663. }
  10664. static bool primary_get_hw_state(struct intel_crtc *crtc)
  10665. {
  10666. struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
  10667. if (!crtc->active)
  10668. return false;
  10669. return I915_READ(DSPCNTR(crtc->plane)) & DISPLAY_PLANE_ENABLE;
  10670. }
  10671. static void intel_modeset_readout_hw_state(struct drm_device *dev)
  10672. {
  10673. struct drm_i915_private *dev_priv = dev->dev_private;
  10674. enum pipe pipe;
  10675. struct intel_crtc *crtc;
  10676. struct intel_encoder *encoder;
  10677. struct intel_connector *connector;
  10678. int i;
  10679. for_each_intel_crtc(dev, crtc) {
  10680. memset(&crtc->config, 0, sizeof(crtc->config));
  10681. crtc->config.quirks |= PIPE_CONFIG_QUIRK_INHERITED_MODE;
  10682. crtc->active = dev_priv->display.get_pipe_config(crtc,
  10683. &crtc->config);
  10684. crtc->base.enabled = crtc->active;
  10685. crtc->primary_enabled = primary_get_hw_state(crtc);
  10686. DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n",
  10687. crtc->base.base.id,
  10688. crtc->active ? "enabled" : "disabled");
  10689. }
  10690. /* FIXME: Smash this into the new shared dpll infrastructure. */
  10691. if (HAS_DDI(dev))
  10692. intel_ddi_setup_hw_pll_state(dev);
  10693. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  10694. struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
  10695. pll->on = pll->get_hw_state(dev_priv, pll, &pll->hw_state);
  10696. pll->active = 0;
  10697. for_each_intel_crtc(dev, crtc) {
  10698. if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll)
  10699. pll->active++;
  10700. }
  10701. pll->refcount = pll->active;
  10702. DRM_DEBUG_KMS("%s hw state readout: refcount %i, on %i\n",
  10703. pll->name, pll->refcount, pll->on);
  10704. }
  10705. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  10706. base.head) {
  10707. pipe = 0;
  10708. if (encoder->get_hw_state(encoder, &pipe)) {
  10709. crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  10710. encoder->base.crtc = &crtc->base;
  10711. encoder->get_config(encoder, &crtc->config);
  10712. } else {
  10713. encoder->base.crtc = NULL;
  10714. }
  10715. encoder->connectors_active = false;
  10716. DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
  10717. encoder->base.base.id,
  10718. encoder->base.name,
  10719. encoder->base.crtc ? "enabled" : "disabled",
  10720. pipe_name(pipe));
  10721. }
  10722. list_for_each_entry(connector, &dev->mode_config.connector_list,
  10723. base.head) {
  10724. if (connector->get_hw_state(connector)) {
  10725. connector->base.dpms = DRM_MODE_DPMS_ON;
  10726. connector->encoder->connectors_active = true;
  10727. connector->base.encoder = &connector->encoder->base;
  10728. } else {
  10729. connector->base.dpms = DRM_MODE_DPMS_OFF;
  10730. connector->base.encoder = NULL;
  10731. }
  10732. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
  10733. connector->base.base.id,
  10734. connector->base.name,
  10735. connector->base.encoder ? "enabled" : "disabled");
  10736. }
  10737. }
  10738. /* Scan out the current hw modeset state, sanitizes it and maps it into the drm
  10739. * and i915 state tracking structures. */
  10740. void intel_modeset_setup_hw_state(struct drm_device *dev,
  10741. bool force_restore)
  10742. {
  10743. struct drm_i915_private *dev_priv = dev->dev_private;
  10744. enum pipe pipe;
  10745. struct intel_crtc *crtc;
  10746. struct intel_encoder *encoder;
  10747. int i;
  10748. intel_modeset_readout_hw_state(dev);
  10749. /*
  10750. * Now that we have the config, copy it to each CRTC struct
  10751. * Note that this could go away if we move to using crtc_config
  10752. * checking everywhere.
  10753. */
  10754. for_each_intel_crtc(dev, crtc) {
  10755. if (crtc->active && i915.fastboot) {
  10756. intel_mode_from_pipe_config(&crtc->base.mode, &crtc->config);
  10757. DRM_DEBUG_KMS("[CRTC:%d] found active mode: ",
  10758. crtc->base.base.id);
  10759. drm_mode_debug_printmodeline(&crtc->base.mode);
  10760. }
  10761. }
  10762. /* HW state is read out, now we need to sanitize this mess. */
  10763. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  10764. base.head) {
  10765. intel_sanitize_encoder(encoder);
  10766. }
  10767. for_each_pipe(pipe) {
  10768. crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  10769. intel_sanitize_crtc(crtc);
  10770. intel_dump_pipe_config(crtc, &crtc->config, "[setup_hw_state]");
  10771. }
  10772. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  10773. struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
  10774. if (!pll->on || pll->active)
  10775. continue;
  10776. DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll->name);
  10777. pll->disable(dev_priv, pll);
  10778. pll->on = false;
  10779. }
  10780. if (HAS_PCH_SPLIT(dev))
  10781. ilk_wm_get_hw_state(dev);
  10782. if (force_restore) {
  10783. i915_redisable_vga(dev);
  10784. /*
  10785. * We need to use raw interfaces for restoring state to avoid
  10786. * checking (bogus) intermediate states.
  10787. */
  10788. for_each_pipe(pipe) {
  10789. struct drm_crtc *crtc =
  10790. dev_priv->pipe_to_crtc_mapping[pipe];
  10791. __intel_set_mode(crtc, &crtc->mode, crtc->x, crtc->y,
  10792. crtc->primary->fb);
  10793. }
  10794. } else {
  10795. intel_modeset_update_staged_output_state(dev);
  10796. }
  10797. intel_modeset_check_state(dev);
  10798. }
  10799. void intel_modeset_gem_init(struct drm_device *dev)
  10800. {
  10801. struct drm_crtc *c;
  10802. struct intel_framebuffer *fb;
  10803. mutex_lock(&dev->struct_mutex);
  10804. intel_init_gt_powersave(dev);
  10805. mutex_unlock(&dev->struct_mutex);
  10806. intel_modeset_init_hw(dev);
  10807. intel_setup_overlay(dev);
  10808. /*
  10809. * Make sure any fbs we allocated at startup are properly
  10810. * pinned & fenced. When we do the allocation it's too early
  10811. * for this.
  10812. */
  10813. mutex_lock(&dev->struct_mutex);
  10814. for_each_crtc(dev, c) {
  10815. if (!c->primary->fb)
  10816. continue;
  10817. fb = to_intel_framebuffer(c->primary->fb);
  10818. if (intel_pin_and_fence_fb_obj(dev, fb->obj, NULL)) {
  10819. DRM_ERROR("failed to pin boot fb on pipe %d\n",
  10820. to_intel_crtc(c)->pipe);
  10821. drm_framebuffer_unreference(c->primary->fb);
  10822. c->primary->fb = NULL;
  10823. }
  10824. }
  10825. mutex_unlock(&dev->struct_mutex);
  10826. }
  10827. void intel_connector_unregister(struct intel_connector *intel_connector)
  10828. {
  10829. struct drm_connector *connector = &intel_connector->base;
  10830. intel_panel_destroy_backlight(connector);
  10831. drm_sysfs_connector_remove(connector);
  10832. }
  10833. void intel_modeset_cleanup(struct drm_device *dev)
  10834. {
  10835. struct drm_i915_private *dev_priv = dev->dev_private;
  10836. struct drm_connector *connector;
  10837. /*
  10838. * Interrupts and polling as the first thing to avoid creating havoc.
  10839. * Too much stuff here (turning of rps, connectors, ...) would
  10840. * experience fancy races otherwise.
  10841. */
  10842. drm_irq_uninstall(dev);
  10843. cancel_work_sync(&dev_priv->hotplug_work);
  10844. /*
  10845. * Due to the hpd irq storm handling the hotplug work can re-arm the
  10846. * poll handlers. Hence disable polling after hpd handling is shut down.
  10847. */
  10848. drm_kms_helper_poll_fini(dev);
  10849. mutex_lock(&dev->struct_mutex);
  10850. intel_unregister_dsm_handler();
  10851. intel_disable_fbc(dev);
  10852. intel_disable_gt_powersave(dev);
  10853. ironlake_teardown_rc6(dev);
  10854. mutex_unlock(&dev->struct_mutex);
  10855. /* flush any delayed tasks or pending work */
  10856. flush_scheduled_work();
  10857. /* destroy the backlight and sysfs files before encoders/connectors */
  10858. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  10859. struct intel_connector *intel_connector;
  10860. intel_connector = to_intel_connector(connector);
  10861. intel_connector->unregister(intel_connector);
  10862. }
  10863. drm_mode_config_cleanup(dev);
  10864. intel_cleanup_overlay(dev);
  10865. mutex_lock(&dev->struct_mutex);
  10866. intel_cleanup_gt_powersave(dev);
  10867. mutex_unlock(&dev->struct_mutex);
  10868. }
  10869. /*
  10870. * Return which encoder is currently attached for connector.
  10871. */
  10872. struct drm_encoder *intel_best_encoder(struct drm_connector *connector)
  10873. {
  10874. return &intel_attached_encoder(connector)->base;
  10875. }
  10876. void intel_connector_attach_encoder(struct intel_connector *connector,
  10877. struct intel_encoder *encoder)
  10878. {
  10879. connector->encoder = encoder;
  10880. drm_mode_connector_attach_encoder(&connector->base,
  10881. &encoder->base);
  10882. }
  10883. /*
  10884. * set vga decode state - true == enable VGA decode
  10885. */
  10886. int intel_modeset_vga_set_state(struct drm_device *dev, bool state)
  10887. {
  10888. struct drm_i915_private *dev_priv = dev->dev_private;
  10889. unsigned reg = INTEL_INFO(dev)->gen >= 6 ? SNB_GMCH_CTRL : INTEL_GMCH_CTRL;
  10890. u16 gmch_ctrl;
  10891. if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) {
  10892. DRM_ERROR("failed to read control word\n");
  10893. return -EIO;
  10894. }
  10895. if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state)
  10896. return 0;
  10897. if (state)
  10898. gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE;
  10899. else
  10900. gmch_ctrl |= INTEL_GMCH_VGA_DISABLE;
  10901. if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) {
  10902. DRM_ERROR("failed to write control word\n");
  10903. return -EIO;
  10904. }
  10905. return 0;
  10906. }
  10907. struct intel_display_error_state {
  10908. u32 power_well_driver;
  10909. int num_transcoders;
  10910. struct intel_cursor_error_state {
  10911. u32 control;
  10912. u32 position;
  10913. u32 base;
  10914. u32 size;
  10915. } cursor[I915_MAX_PIPES];
  10916. struct intel_pipe_error_state {
  10917. bool power_domain_on;
  10918. u32 source;
  10919. u32 stat;
  10920. } pipe[I915_MAX_PIPES];
  10921. struct intel_plane_error_state {
  10922. u32 control;
  10923. u32 stride;
  10924. u32 size;
  10925. u32 pos;
  10926. u32 addr;
  10927. u32 surface;
  10928. u32 tile_offset;
  10929. } plane[I915_MAX_PIPES];
  10930. struct intel_transcoder_error_state {
  10931. bool power_domain_on;
  10932. enum transcoder cpu_transcoder;
  10933. u32 conf;
  10934. u32 htotal;
  10935. u32 hblank;
  10936. u32 hsync;
  10937. u32 vtotal;
  10938. u32 vblank;
  10939. u32 vsync;
  10940. } transcoder[4];
  10941. };
  10942. struct intel_display_error_state *
  10943. intel_display_capture_error_state(struct drm_device *dev)
  10944. {
  10945. struct drm_i915_private *dev_priv = dev->dev_private;
  10946. struct intel_display_error_state *error;
  10947. int transcoders[] = {
  10948. TRANSCODER_A,
  10949. TRANSCODER_B,
  10950. TRANSCODER_C,
  10951. TRANSCODER_EDP,
  10952. };
  10953. int i;
  10954. if (INTEL_INFO(dev)->num_pipes == 0)
  10955. return NULL;
  10956. error = kzalloc(sizeof(*error), GFP_ATOMIC);
  10957. if (error == NULL)
  10958. return NULL;
  10959. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  10960. error->power_well_driver = I915_READ(HSW_PWR_WELL_DRIVER);
  10961. for_each_pipe(i) {
  10962. error->pipe[i].power_domain_on =
  10963. intel_display_power_enabled_sw(dev_priv,
  10964. POWER_DOMAIN_PIPE(i));
  10965. if (!error->pipe[i].power_domain_on)
  10966. continue;
  10967. error->cursor[i].control = I915_READ(CURCNTR(i));
  10968. error->cursor[i].position = I915_READ(CURPOS(i));
  10969. error->cursor[i].base = I915_READ(CURBASE(i));
  10970. error->plane[i].control = I915_READ(DSPCNTR(i));
  10971. error->plane[i].stride = I915_READ(DSPSTRIDE(i));
  10972. if (INTEL_INFO(dev)->gen <= 3) {
  10973. error->plane[i].size = I915_READ(DSPSIZE(i));
  10974. error->plane[i].pos = I915_READ(DSPPOS(i));
  10975. }
  10976. if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev))
  10977. error->plane[i].addr = I915_READ(DSPADDR(i));
  10978. if (INTEL_INFO(dev)->gen >= 4) {
  10979. error->plane[i].surface = I915_READ(DSPSURF(i));
  10980. error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i));
  10981. }
  10982. error->pipe[i].source = I915_READ(PIPESRC(i));
  10983. if (!HAS_PCH_SPLIT(dev))
  10984. error->pipe[i].stat = I915_READ(PIPESTAT(i));
  10985. }
  10986. error->num_transcoders = INTEL_INFO(dev)->num_pipes;
  10987. if (HAS_DDI(dev_priv->dev))
  10988. error->num_transcoders++; /* Account for eDP. */
  10989. for (i = 0; i < error->num_transcoders; i++) {
  10990. enum transcoder cpu_transcoder = transcoders[i];
  10991. error->transcoder[i].power_domain_on =
  10992. intel_display_power_enabled_sw(dev_priv,
  10993. POWER_DOMAIN_TRANSCODER(cpu_transcoder));
  10994. if (!error->transcoder[i].power_domain_on)
  10995. continue;
  10996. error->transcoder[i].cpu_transcoder = cpu_transcoder;
  10997. error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder));
  10998. error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder));
  10999. error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder));
  11000. error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder));
  11001. error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder));
  11002. error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder));
  11003. error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder));
  11004. }
  11005. return error;
  11006. }
  11007. #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
  11008. void
  11009. intel_display_print_error_state(struct drm_i915_error_state_buf *m,
  11010. struct drm_device *dev,
  11011. struct intel_display_error_state *error)
  11012. {
  11013. int i;
  11014. if (!error)
  11015. return;
  11016. err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev)->num_pipes);
  11017. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  11018. err_printf(m, "PWR_WELL_CTL2: %08x\n",
  11019. error->power_well_driver);
  11020. for_each_pipe(i) {
  11021. err_printf(m, "Pipe [%d]:\n", i);
  11022. err_printf(m, " Power: %s\n",
  11023. error->pipe[i].power_domain_on ? "on" : "off");
  11024. err_printf(m, " SRC: %08x\n", error->pipe[i].source);
  11025. err_printf(m, " STAT: %08x\n", error->pipe[i].stat);
  11026. err_printf(m, "Plane [%d]:\n", i);
  11027. err_printf(m, " CNTR: %08x\n", error->plane[i].control);
  11028. err_printf(m, " STRIDE: %08x\n", error->plane[i].stride);
  11029. if (INTEL_INFO(dev)->gen <= 3) {
  11030. err_printf(m, " SIZE: %08x\n", error->plane[i].size);
  11031. err_printf(m, " POS: %08x\n", error->plane[i].pos);
  11032. }
  11033. if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev))
  11034. err_printf(m, " ADDR: %08x\n", error->plane[i].addr);
  11035. if (INTEL_INFO(dev)->gen >= 4) {
  11036. err_printf(m, " SURF: %08x\n", error->plane[i].surface);
  11037. err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset);
  11038. }
  11039. err_printf(m, "Cursor [%d]:\n", i);
  11040. err_printf(m, " CNTR: %08x\n", error->cursor[i].control);
  11041. err_printf(m, " POS: %08x\n", error->cursor[i].position);
  11042. err_printf(m, " BASE: %08x\n", error->cursor[i].base);
  11043. }
  11044. for (i = 0; i < error->num_transcoders; i++) {
  11045. err_printf(m, "CPU transcoder: %c\n",
  11046. transcoder_name(error->transcoder[i].cpu_transcoder));
  11047. err_printf(m, " Power: %s\n",
  11048. error->transcoder[i].power_domain_on ? "on" : "off");
  11049. err_printf(m, " CONF: %08x\n", error->transcoder[i].conf);
  11050. err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal);
  11051. err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank);
  11052. err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync);
  11053. err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal);
  11054. err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank);
  11055. err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync);
  11056. }
  11057. }