intel_display.c 381 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810
  1. /*
  2. * Copyright © 2006-2007 Intel Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  21. * DEALINGS IN THE SOFTWARE.
  22. *
  23. * Authors:
  24. * Eric Anholt <eric@anholt.net>
  25. */
  26. #include <linux/dmi.h>
  27. #include <linux/module.h>
  28. #include <linux/input.h>
  29. #include <linux/i2c.h>
  30. #include <linux/kernel.h>
  31. #include <linux/slab.h>
  32. #include <linux/vgaarb.h>
  33. #include <drm/drm_edid.h>
  34. #include <drm/drmP.h>
  35. #include "intel_drv.h"
  36. #include <drm/i915_drm.h>
  37. #include "i915_drv.h"
  38. #include "i915_trace.h"
  39. #include <drm/drm_dp_helper.h>
  40. #include <drm/drm_crtc_helper.h>
  41. #include <drm/drm_plane_helper.h>
  42. #include <drm/drm_rect.h>
  43. #include <linux/dma_remapping.h>
  44. /* Primary plane formats supported by all gen */
  45. #define COMMON_PRIMARY_FORMATS \
  46. DRM_FORMAT_C8, \
  47. DRM_FORMAT_RGB565, \
  48. DRM_FORMAT_XRGB8888, \
  49. DRM_FORMAT_ARGB8888
  50. /* Primary plane formats for gen <= 3 */
  51. static const uint32_t intel_primary_formats_gen2[] = {
  52. COMMON_PRIMARY_FORMATS,
  53. DRM_FORMAT_XRGB1555,
  54. DRM_FORMAT_ARGB1555,
  55. };
  56. /* Primary plane formats for gen >= 4 */
  57. static const uint32_t intel_primary_formats_gen4[] = {
  58. COMMON_PRIMARY_FORMATS, \
  59. DRM_FORMAT_XBGR8888,
  60. DRM_FORMAT_ABGR8888,
  61. DRM_FORMAT_XRGB2101010,
  62. DRM_FORMAT_ARGB2101010,
  63. DRM_FORMAT_XBGR2101010,
  64. DRM_FORMAT_ABGR2101010,
  65. };
  66. /* Cursor formats */
  67. static const uint32_t intel_cursor_formats[] = {
  68. DRM_FORMAT_ARGB8888,
  69. };
  70. static void intel_increase_pllclock(struct drm_device *dev,
  71. enum pipe pipe);
  72. static void intel_crtc_update_cursor(struct drm_crtc *crtc, bool on);
  73. static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
  74. struct intel_crtc_config *pipe_config);
  75. static void ironlake_pch_clock_get(struct intel_crtc *crtc,
  76. struct intel_crtc_config *pipe_config);
  77. static int intel_set_mode(struct drm_crtc *crtc, struct drm_display_mode *mode,
  78. int x, int y, struct drm_framebuffer *old_fb);
  79. static int intel_framebuffer_init(struct drm_device *dev,
  80. struct intel_framebuffer *ifb,
  81. struct drm_mode_fb_cmd2 *mode_cmd,
  82. struct drm_i915_gem_object *obj);
  83. static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc);
  84. static void intel_set_pipe_timings(struct intel_crtc *intel_crtc);
  85. static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc,
  86. struct intel_link_m_n *m_n,
  87. struct intel_link_m_n *m2_n2);
  88. static void ironlake_set_pipeconf(struct drm_crtc *crtc);
  89. static void haswell_set_pipeconf(struct drm_crtc *crtc);
  90. static void intel_set_pipe_csc(struct drm_crtc *crtc);
  91. static void vlv_prepare_pll(struct intel_crtc *crtc);
  92. static void chv_prepare_pll(struct intel_crtc *crtc);
  93. static struct intel_encoder *intel_find_encoder(struct intel_connector *connector, int pipe)
  94. {
  95. if (!connector->mst_port)
  96. return connector->encoder;
  97. else
  98. return &connector->mst_port->mst_encoders[pipe]->base;
  99. }
  100. typedef struct {
  101. int min, max;
  102. } intel_range_t;
  103. typedef struct {
  104. int dot_limit;
  105. int p2_slow, p2_fast;
  106. } intel_p2_t;
  107. typedef struct intel_limit intel_limit_t;
  108. struct intel_limit {
  109. intel_range_t dot, vco, n, m, m1, m2, p, p1;
  110. intel_p2_t p2;
  111. };
  112. int
  113. intel_pch_rawclk(struct drm_device *dev)
  114. {
  115. struct drm_i915_private *dev_priv = dev->dev_private;
  116. WARN_ON(!HAS_PCH_SPLIT(dev));
  117. return I915_READ(PCH_RAWCLK_FREQ) & RAWCLK_FREQ_MASK;
  118. }
  119. static inline u32 /* units of 100MHz */
  120. intel_fdi_link_freq(struct drm_device *dev)
  121. {
  122. if (IS_GEN5(dev)) {
  123. struct drm_i915_private *dev_priv = dev->dev_private;
  124. return (I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK) + 2;
  125. } else
  126. return 27;
  127. }
  128. static const intel_limit_t intel_limits_i8xx_dac = {
  129. .dot = { .min = 25000, .max = 350000 },
  130. .vco = { .min = 908000, .max = 1512000 },
  131. .n = { .min = 2, .max = 16 },
  132. .m = { .min = 96, .max = 140 },
  133. .m1 = { .min = 18, .max = 26 },
  134. .m2 = { .min = 6, .max = 16 },
  135. .p = { .min = 4, .max = 128 },
  136. .p1 = { .min = 2, .max = 33 },
  137. .p2 = { .dot_limit = 165000,
  138. .p2_slow = 4, .p2_fast = 2 },
  139. };
  140. static const intel_limit_t intel_limits_i8xx_dvo = {
  141. .dot = { .min = 25000, .max = 350000 },
  142. .vco = { .min = 908000, .max = 1512000 },
  143. .n = { .min = 2, .max = 16 },
  144. .m = { .min = 96, .max = 140 },
  145. .m1 = { .min = 18, .max = 26 },
  146. .m2 = { .min = 6, .max = 16 },
  147. .p = { .min = 4, .max = 128 },
  148. .p1 = { .min = 2, .max = 33 },
  149. .p2 = { .dot_limit = 165000,
  150. .p2_slow = 4, .p2_fast = 4 },
  151. };
  152. static const intel_limit_t intel_limits_i8xx_lvds = {
  153. .dot = { .min = 25000, .max = 350000 },
  154. .vco = { .min = 908000, .max = 1512000 },
  155. .n = { .min = 2, .max = 16 },
  156. .m = { .min = 96, .max = 140 },
  157. .m1 = { .min = 18, .max = 26 },
  158. .m2 = { .min = 6, .max = 16 },
  159. .p = { .min = 4, .max = 128 },
  160. .p1 = { .min = 1, .max = 6 },
  161. .p2 = { .dot_limit = 165000,
  162. .p2_slow = 14, .p2_fast = 7 },
  163. };
  164. static const intel_limit_t intel_limits_i9xx_sdvo = {
  165. .dot = { .min = 20000, .max = 400000 },
  166. .vco = { .min = 1400000, .max = 2800000 },
  167. .n = { .min = 1, .max = 6 },
  168. .m = { .min = 70, .max = 120 },
  169. .m1 = { .min = 8, .max = 18 },
  170. .m2 = { .min = 3, .max = 7 },
  171. .p = { .min = 5, .max = 80 },
  172. .p1 = { .min = 1, .max = 8 },
  173. .p2 = { .dot_limit = 200000,
  174. .p2_slow = 10, .p2_fast = 5 },
  175. };
  176. static const intel_limit_t intel_limits_i9xx_lvds = {
  177. .dot = { .min = 20000, .max = 400000 },
  178. .vco = { .min = 1400000, .max = 2800000 },
  179. .n = { .min = 1, .max = 6 },
  180. .m = { .min = 70, .max = 120 },
  181. .m1 = { .min = 8, .max = 18 },
  182. .m2 = { .min = 3, .max = 7 },
  183. .p = { .min = 7, .max = 98 },
  184. .p1 = { .min = 1, .max = 8 },
  185. .p2 = { .dot_limit = 112000,
  186. .p2_slow = 14, .p2_fast = 7 },
  187. };
  188. static const intel_limit_t intel_limits_g4x_sdvo = {
  189. .dot = { .min = 25000, .max = 270000 },
  190. .vco = { .min = 1750000, .max = 3500000},
  191. .n = { .min = 1, .max = 4 },
  192. .m = { .min = 104, .max = 138 },
  193. .m1 = { .min = 17, .max = 23 },
  194. .m2 = { .min = 5, .max = 11 },
  195. .p = { .min = 10, .max = 30 },
  196. .p1 = { .min = 1, .max = 3},
  197. .p2 = { .dot_limit = 270000,
  198. .p2_slow = 10,
  199. .p2_fast = 10
  200. },
  201. };
  202. static const intel_limit_t intel_limits_g4x_hdmi = {
  203. .dot = { .min = 22000, .max = 400000 },
  204. .vco = { .min = 1750000, .max = 3500000},
  205. .n = { .min = 1, .max = 4 },
  206. .m = { .min = 104, .max = 138 },
  207. .m1 = { .min = 16, .max = 23 },
  208. .m2 = { .min = 5, .max = 11 },
  209. .p = { .min = 5, .max = 80 },
  210. .p1 = { .min = 1, .max = 8},
  211. .p2 = { .dot_limit = 165000,
  212. .p2_slow = 10, .p2_fast = 5 },
  213. };
  214. static const intel_limit_t intel_limits_g4x_single_channel_lvds = {
  215. .dot = { .min = 20000, .max = 115000 },
  216. .vco = { .min = 1750000, .max = 3500000 },
  217. .n = { .min = 1, .max = 3 },
  218. .m = { .min = 104, .max = 138 },
  219. .m1 = { .min = 17, .max = 23 },
  220. .m2 = { .min = 5, .max = 11 },
  221. .p = { .min = 28, .max = 112 },
  222. .p1 = { .min = 2, .max = 8 },
  223. .p2 = { .dot_limit = 0,
  224. .p2_slow = 14, .p2_fast = 14
  225. },
  226. };
  227. static const intel_limit_t intel_limits_g4x_dual_channel_lvds = {
  228. .dot = { .min = 80000, .max = 224000 },
  229. .vco = { .min = 1750000, .max = 3500000 },
  230. .n = { .min = 1, .max = 3 },
  231. .m = { .min = 104, .max = 138 },
  232. .m1 = { .min = 17, .max = 23 },
  233. .m2 = { .min = 5, .max = 11 },
  234. .p = { .min = 14, .max = 42 },
  235. .p1 = { .min = 2, .max = 6 },
  236. .p2 = { .dot_limit = 0,
  237. .p2_slow = 7, .p2_fast = 7
  238. },
  239. };
  240. static const intel_limit_t intel_limits_pineview_sdvo = {
  241. .dot = { .min = 20000, .max = 400000},
  242. .vco = { .min = 1700000, .max = 3500000 },
  243. /* Pineview's Ncounter is a ring counter */
  244. .n = { .min = 3, .max = 6 },
  245. .m = { .min = 2, .max = 256 },
  246. /* Pineview only has one combined m divider, which we treat as m2. */
  247. .m1 = { .min = 0, .max = 0 },
  248. .m2 = { .min = 0, .max = 254 },
  249. .p = { .min = 5, .max = 80 },
  250. .p1 = { .min = 1, .max = 8 },
  251. .p2 = { .dot_limit = 200000,
  252. .p2_slow = 10, .p2_fast = 5 },
  253. };
  254. static const intel_limit_t intel_limits_pineview_lvds = {
  255. .dot = { .min = 20000, .max = 400000 },
  256. .vco = { .min = 1700000, .max = 3500000 },
  257. .n = { .min = 3, .max = 6 },
  258. .m = { .min = 2, .max = 256 },
  259. .m1 = { .min = 0, .max = 0 },
  260. .m2 = { .min = 0, .max = 254 },
  261. .p = { .min = 7, .max = 112 },
  262. .p1 = { .min = 1, .max = 8 },
  263. .p2 = { .dot_limit = 112000,
  264. .p2_slow = 14, .p2_fast = 14 },
  265. };
  266. /* Ironlake / Sandybridge
  267. *
  268. * We calculate clock using (register_value + 2) for N/M1/M2, so here
  269. * the range value for them is (actual_value - 2).
  270. */
  271. static const intel_limit_t intel_limits_ironlake_dac = {
  272. .dot = { .min = 25000, .max = 350000 },
  273. .vco = { .min = 1760000, .max = 3510000 },
  274. .n = { .min = 1, .max = 5 },
  275. .m = { .min = 79, .max = 127 },
  276. .m1 = { .min = 12, .max = 22 },
  277. .m2 = { .min = 5, .max = 9 },
  278. .p = { .min = 5, .max = 80 },
  279. .p1 = { .min = 1, .max = 8 },
  280. .p2 = { .dot_limit = 225000,
  281. .p2_slow = 10, .p2_fast = 5 },
  282. };
  283. static const intel_limit_t intel_limits_ironlake_single_lvds = {
  284. .dot = { .min = 25000, .max = 350000 },
  285. .vco = { .min = 1760000, .max = 3510000 },
  286. .n = { .min = 1, .max = 3 },
  287. .m = { .min = 79, .max = 118 },
  288. .m1 = { .min = 12, .max = 22 },
  289. .m2 = { .min = 5, .max = 9 },
  290. .p = { .min = 28, .max = 112 },
  291. .p1 = { .min = 2, .max = 8 },
  292. .p2 = { .dot_limit = 225000,
  293. .p2_slow = 14, .p2_fast = 14 },
  294. };
  295. static const intel_limit_t intel_limits_ironlake_dual_lvds = {
  296. .dot = { .min = 25000, .max = 350000 },
  297. .vco = { .min = 1760000, .max = 3510000 },
  298. .n = { .min = 1, .max = 3 },
  299. .m = { .min = 79, .max = 127 },
  300. .m1 = { .min = 12, .max = 22 },
  301. .m2 = { .min = 5, .max = 9 },
  302. .p = { .min = 14, .max = 56 },
  303. .p1 = { .min = 2, .max = 8 },
  304. .p2 = { .dot_limit = 225000,
  305. .p2_slow = 7, .p2_fast = 7 },
  306. };
  307. /* LVDS 100mhz refclk limits. */
  308. static const intel_limit_t intel_limits_ironlake_single_lvds_100m = {
  309. .dot = { .min = 25000, .max = 350000 },
  310. .vco = { .min = 1760000, .max = 3510000 },
  311. .n = { .min = 1, .max = 2 },
  312. .m = { .min = 79, .max = 126 },
  313. .m1 = { .min = 12, .max = 22 },
  314. .m2 = { .min = 5, .max = 9 },
  315. .p = { .min = 28, .max = 112 },
  316. .p1 = { .min = 2, .max = 8 },
  317. .p2 = { .dot_limit = 225000,
  318. .p2_slow = 14, .p2_fast = 14 },
  319. };
  320. static const intel_limit_t intel_limits_ironlake_dual_lvds_100m = {
  321. .dot = { .min = 25000, .max = 350000 },
  322. .vco = { .min = 1760000, .max = 3510000 },
  323. .n = { .min = 1, .max = 3 },
  324. .m = { .min = 79, .max = 126 },
  325. .m1 = { .min = 12, .max = 22 },
  326. .m2 = { .min = 5, .max = 9 },
  327. .p = { .min = 14, .max = 42 },
  328. .p1 = { .min = 2, .max = 6 },
  329. .p2 = { .dot_limit = 225000,
  330. .p2_slow = 7, .p2_fast = 7 },
  331. };
  332. static const intel_limit_t intel_limits_vlv = {
  333. /*
  334. * These are the data rate limits (measured in fast clocks)
  335. * since those are the strictest limits we have. The fast
  336. * clock and actual rate limits are more relaxed, so checking
  337. * them would make no difference.
  338. */
  339. .dot = { .min = 25000 * 5, .max = 270000 * 5 },
  340. .vco = { .min = 4000000, .max = 6000000 },
  341. .n = { .min = 1, .max = 7 },
  342. .m1 = { .min = 2, .max = 3 },
  343. .m2 = { .min = 11, .max = 156 },
  344. .p1 = { .min = 2, .max = 3 },
  345. .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */
  346. };
  347. static const intel_limit_t intel_limits_chv = {
  348. /*
  349. * These are the data rate limits (measured in fast clocks)
  350. * since those are the strictest limits we have. The fast
  351. * clock and actual rate limits are more relaxed, so checking
  352. * them would make no difference.
  353. */
  354. .dot = { .min = 25000 * 5, .max = 540000 * 5},
  355. .vco = { .min = 4860000, .max = 6700000 },
  356. .n = { .min = 1, .max = 1 },
  357. .m1 = { .min = 2, .max = 2 },
  358. .m2 = { .min = 24 << 22, .max = 175 << 22 },
  359. .p1 = { .min = 2, .max = 4 },
  360. .p2 = { .p2_slow = 1, .p2_fast = 14 },
  361. };
  362. static void vlv_clock(int refclk, intel_clock_t *clock)
  363. {
  364. clock->m = clock->m1 * clock->m2;
  365. clock->p = clock->p1 * clock->p2;
  366. if (WARN_ON(clock->n == 0 || clock->p == 0))
  367. return;
  368. clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
  369. clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
  370. }
  371. /**
  372. * Returns whether any output on the specified pipe is of the specified type
  373. */
  374. static bool intel_pipe_has_type(struct drm_crtc *crtc, int type)
  375. {
  376. struct drm_device *dev = crtc->dev;
  377. struct intel_encoder *encoder;
  378. for_each_encoder_on_crtc(dev, crtc, encoder)
  379. if (encoder->type == type)
  380. return true;
  381. return false;
  382. }
  383. static const intel_limit_t *intel_ironlake_limit(struct drm_crtc *crtc,
  384. int refclk)
  385. {
  386. struct drm_device *dev = crtc->dev;
  387. const intel_limit_t *limit;
  388. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  389. if (intel_is_dual_link_lvds(dev)) {
  390. if (refclk == 100000)
  391. limit = &intel_limits_ironlake_dual_lvds_100m;
  392. else
  393. limit = &intel_limits_ironlake_dual_lvds;
  394. } else {
  395. if (refclk == 100000)
  396. limit = &intel_limits_ironlake_single_lvds_100m;
  397. else
  398. limit = &intel_limits_ironlake_single_lvds;
  399. }
  400. } else
  401. limit = &intel_limits_ironlake_dac;
  402. return limit;
  403. }
  404. static const intel_limit_t *intel_g4x_limit(struct drm_crtc *crtc)
  405. {
  406. struct drm_device *dev = crtc->dev;
  407. const intel_limit_t *limit;
  408. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  409. if (intel_is_dual_link_lvds(dev))
  410. limit = &intel_limits_g4x_dual_channel_lvds;
  411. else
  412. limit = &intel_limits_g4x_single_channel_lvds;
  413. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI) ||
  414. intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG)) {
  415. limit = &intel_limits_g4x_hdmi;
  416. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO)) {
  417. limit = &intel_limits_g4x_sdvo;
  418. } else /* The option is for other outputs */
  419. limit = &intel_limits_i9xx_sdvo;
  420. return limit;
  421. }
  422. static const intel_limit_t *intel_limit(struct drm_crtc *crtc, int refclk)
  423. {
  424. struct drm_device *dev = crtc->dev;
  425. const intel_limit_t *limit;
  426. if (HAS_PCH_SPLIT(dev))
  427. limit = intel_ironlake_limit(crtc, refclk);
  428. else if (IS_G4X(dev)) {
  429. limit = intel_g4x_limit(crtc);
  430. } else if (IS_PINEVIEW(dev)) {
  431. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  432. limit = &intel_limits_pineview_lvds;
  433. else
  434. limit = &intel_limits_pineview_sdvo;
  435. } else if (IS_CHERRYVIEW(dev)) {
  436. limit = &intel_limits_chv;
  437. } else if (IS_VALLEYVIEW(dev)) {
  438. limit = &intel_limits_vlv;
  439. } else if (!IS_GEN2(dev)) {
  440. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  441. limit = &intel_limits_i9xx_lvds;
  442. else
  443. limit = &intel_limits_i9xx_sdvo;
  444. } else {
  445. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  446. limit = &intel_limits_i8xx_lvds;
  447. else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO))
  448. limit = &intel_limits_i8xx_dvo;
  449. else
  450. limit = &intel_limits_i8xx_dac;
  451. }
  452. return limit;
  453. }
  454. /* m1 is reserved as 0 in Pineview, n is a ring counter */
  455. static void pineview_clock(int refclk, intel_clock_t *clock)
  456. {
  457. clock->m = clock->m2 + 2;
  458. clock->p = clock->p1 * clock->p2;
  459. if (WARN_ON(clock->n == 0 || clock->p == 0))
  460. return;
  461. clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
  462. clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
  463. }
  464. static uint32_t i9xx_dpll_compute_m(struct dpll *dpll)
  465. {
  466. return 5 * (dpll->m1 + 2) + (dpll->m2 + 2);
  467. }
  468. static void i9xx_clock(int refclk, intel_clock_t *clock)
  469. {
  470. clock->m = i9xx_dpll_compute_m(clock);
  471. clock->p = clock->p1 * clock->p2;
  472. if (WARN_ON(clock->n + 2 == 0 || clock->p == 0))
  473. return;
  474. clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2);
  475. clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
  476. }
  477. static void chv_clock(int refclk, intel_clock_t *clock)
  478. {
  479. clock->m = clock->m1 * clock->m2;
  480. clock->p = clock->p1 * clock->p2;
  481. if (WARN_ON(clock->n == 0 || clock->p == 0))
  482. return;
  483. clock->vco = DIV_ROUND_CLOSEST_ULL((uint64_t)refclk * clock->m,
  484. clock->n << 22);
  485. clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
  486. }
  487. #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
  488. /**
  489. * Returns whether the given set of divisors are valid for a given refclk with
  490. * the given connectors.
  491. */
  492. static bool intel_PLL_is_valid(struct drm_device *dev,
  493. const intel_limit_t *limit,
  494. const intel_clock_t *clock)
  495. {
  496. if (clock->n < limit->n.min || limit->n.max < clock->n)
  497. INTELPllInvalid("n out of range\n");
  498. if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1)
  499. INTELPllInvalid("p1 out of range\n");
  500. if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2)
  501. INTELPllInvalid("m2 out of range\n");
  502. if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1)
  503. INTELPllInvalid("m1 out of range\n");
  504. if (!IS_PINEVIEW(dev) && !IS_VALLEYVIEW(dev))
  505. if (clock->m1 <= clock->m2)
  506. INTELPllInvalid("m1 <= m2\n");
  507. if (!IS_VALLEYVIEW(dev)) {
  508. if (clock->p < limit->p.min || limit->p.max < clock->p)
  509. INTELPllInvalid("p out of range\n");
  510. if (clock->m < limit->m.min || limit->m.max < clock->m)
  511. INTELPllInvalid("m out of range\n");
  512. }
  513. if (clock->vco < limit->vco.min || limit->vco.max < clock->vco)
  514. INTELPllInvalid("vco out of range\n");
  515. /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
  516. * connector, etc., rather than just a single range.
  517. */
  518. if (clock->dot < limit->dot.min || limit->dot.max < clock->dot)
  519. INTELPllInvalid("dot out of range\n");
  520. return true;
  521. }
  522. static bool
  523. i9xx_find_best_dpll(const intel_limit_t *limit, struct drm_crtc *crtc,
  524. int target, int refclk, intel_clock_t *match_clock,
  525. intel_clock_t *best_clock)
  526. {
  527. struct drm_device *dev = crtc->dev;
  528. intel_clock_t clock;
  529. int err = target;
  530. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  531. /*
  532. * For LVDS just rely on its current settings for dual-channel.
  533. * We haven't figured out how to reliably set up different
  534. * single/dual channel state, if we even can.
  535. */
  536. if (intel_is_dual_link_lvds(dev))
  537. clock.p2 = limit->p2.p2_fast;
  538. else
  539. clock.p2 = limit->p2.p2_slow;
  540. } else {
  541. if (target < limit->p2.dot_limit)
  542. clock.p2 = limit->p2.p2_slow;
  543. else
  544. clock.p2 = limit->p2.p2_fast;
  545. }
  546. memset(best_clock, 0, sizeof(*best_clock));
  547. for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
  548. clock.m1++) {
  549. for (clock.m2 = limit->m2.min;
  550. clock.m2 <= limit->m2.max; clock.m2++) {
  551. if (clock.m2 >= clock.m1)
  552. break;
  553. for (clock.n = limit->n.min;
  554. clock.n <= limit->n.max; clock.n++) {
  555. for (clock.p1 = limit->p1.min;
  556. clock.p1 <= limit->p1.max; clock.p1++) {
  557. int this_err;
  558. i9xx_clock(refclk, &clock);
  559. if (!intel_PLL_is_valid(dev, limit,
  560. &clock))
  561. continue;
  562. if (match_clock &&
  563. clock.p != match_clock->p)
  564. continue;
  565. this_err = abs(clock.dot - target);
  566. if (this_err < err) {
  567. *best_clock = clock;
  568. err = this_err;
  569. }
  570. }
  571. }
  572. }
  573. }
  574. return (err != target);
  575. }
  576. static bool
  577. pnv_find_best_dpll(const intel_limit_t *limit, struct drm_crtc *crtc,
  578. int target, int refclk, intel_clock_t *match_clock,
  579. intel_clock_t *best_clock)
  580. {
  581. struct drm_device *dev = crtc->dev;
  582. intel_clock_t clock;
  583. int err = target;
  584. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  585. /*
  586. * For LVDS just rely on its current settings for dual-channel.
  587. * We haven't figured out how to reliably set up different
  588. * single/dual channel state, if we even can.
  589. */
  590. if (intel_is_dual_link_lvds(dev))
  591. clock.p2 = limit->p2.p2_fast;
  592. else
  593. clock.p2 = limit->p2.p2_slow;
  594. } else {
  595. if (target < limit->p2.dot_limit)
  596. clock.p2 = limit->p2.p2_slow;
  597. else
  598. clock.p2 = limit->p2.p2_fast;
  599. }
  600. memset(best_clock, 0, sizeof(*best_clock));
  601. for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
  602. clock.m1++) {
  603. for (clock.m2 = limit->m2.min;
  604. clock.m2 <= limit->m2.max; clock.m2++) {
  605. for (clock.n = limit->n.min;
  606. clock.n <= limit->n.max; clock.n++) {
  607. for (clock.p1 = limit->p1.min;
  608. clock.p1 <= limit->p1.max; clock.p1++) {
  609. int this_err;
  610. pineview_clock(refclk, &clock);
  611. if (!intel_PLL_is_valid(dev, limit,
  612. &clock))
  613. continue;
  614. if (match_clock &&
  615. clock.p != match_clock->p)
  616. continue;
  617. this_err = abs(clock.dot - target);
  618. if (this_err < err) {
  619. *best_clock = clock;
  620. err = this_err;
  621. }
  622. }
  623. }
  624. }
  625. }
  626. return (err != target);
  627. }
  628. static bool
  629. g4x_find_best_dpll(const intel_limit_t *limit, struct drm_crtc *crtc,
  630. int target, int refclk, intel_clock_t *match_clock,
  631. intel_clock_t *best_clock)
  632. {
  633. struct drm_device *dev = crtc->dev;
  634. intel_clock_t clock;
  635. int max_n;
  636. bool found;
  637. /* approximately equals target * 0.00585 */
  638. int err_most = (target >> 8) + (target >> 9);
  639. found = false;
  640. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  641. if (intel_is_dual_link_lvds(dev))
  642. clock.p2 = limit->p2.p2_fast;
  643. else
  644. clock.p2 = limit->p2.p2_slow;
  645. } else {
  646. if (target < limit->p2.dot_limit)
  647. clock.p2 = limit->p2.p2_slow;
  648. else
  649. clock.p2 = limit->p2.p2_fast;
  650. }
  651. memset(best_clock, 0, sizeof(*best_clock));
  652. max_n = limit->n.max;
  653. /* based on hardware requirement, prefer smaller n to precision */
  654. for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
  655. /* based on hardware requirement, prefere larger m1,m2 */
  656. for (clock.m1 = limit->m1.max;
  657. clock.m1 >= limit->m1.min; clock.m1--) {
  658. for (clock.m2 = limit->m2.max;
  659. clock.m2 >= limit->m2.min; clock.m2--) {
  660. for (clock.p1 = limit->p1.max;
  661. clock.p1 >= limit->p1.min; clock.p1--) {
  662. int this_err;
  663. i9xx_clock(refclk, &clock);
  664. if (!intel_PLL_is_valid(dev, limit,
  665. &clock))
  666. continue;
  667. this_err = abs(clock.dot - target);
  668. if (this_err < err_most) {
  669. *best_clock = clock;
  670. err_most = this_err;
  671. max_n = clock.n;
  672. found = true;
  673. }
  674. }
  675. }
  676. }
  677. }
  678. return found;
  679. }
  680. static bool
  681. vlv_find_best_dpll(const intel_limit_t *limit, struct drm_crtc *crtc,
  682. int target, int refclk, intel_clock_t *match_clock,
  683. intel_clock_t *best_clock)
  684. {
  685. struct drm_device *dev = crtc->dev;
  686. intel_clock_t clock;
  687. unsigned int bestppm = 1000000;
  688. /* min update 19.2 MHz */
  689. int max_n = min(limit->n.max, refclk / 19200);
  690. bool found = false;
  691. target *= 5; /* fast clock */
  692. memset(best_clock, 0, sizeof(*best_clock));
  693. /* based on hardware requirement, prefer smaller n to precision */
  694. for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
  695. for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
  696. for (clock.p2 = limit->p2.p2_fast; clock.p2 >= limit->p2.p2_slow;
  697. clock.p2 -= clock.p2 > 10 ? 2 : 1) {
  698. clock.p = clock.p1 * clock.p2;
  699. /* based on hardware requirement, prefer bigger m1,m2 values */
  700. for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) {
  701. unsigned int ppm, diff;
  702. clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n,
  703. refclk * clock.m1);
  704. vlv_clock(refclk, &clock);
  705. if (!intel_PLL_is_valid(dev, limit,
  706. &clock))
  707. continue;
  708. diff = abs(clock.dot - target);
  709. ppm = div_u64(1000000ULL * diff, target);
  710. if (ppm < 100 && clock.p > best_clock->p) {
  711. bestppm = 0;
  712. *best_clock = clock;
  713. found = true;
  714. }
  715. if (bestppm >= 10 && ppm < bestppm - 10) {
  716. bestppm = ppm;
  717. *best_clock = clock;
  718. found = true;
  719. }
  720. }
  721. }
  722. }
  723. }
  724. return found;
  725. }
  726. static bool
  727. chv_find_best_dpll(const intel_limit_t *limit, struct drm_crtc *crtc,
  728. int target, int refclk, intel_clock_t *match_clock,
  729. intel_clock_t *best_clock)
  730. {
  731. struct drm_device *dev = crtc->dev;
  732. intel_clock_t clock;
  733. uint64_t m2;
  734. int found = false;
  735. memset(best_clock, 0, sizeof(*best_clock));
  736. /*
  737. * Based on hardware doc, the n always set to 1, and m1 always
  738. * set to 2. If requires to support 200Mhz refclk, we need to
  739. * revisit this because n may not 1 anymore.
  740. */
  741. clock.n = 1, clock.m1 = 2;
  742. target *= 5; /* fast clock */
  743. for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
  744. for (clock.p2 = limit->p2.p2_fast;
  745. clock.p2 >= limit->p2.p2_slow;
  746. clock.p2 -= clock.p2 > 10 ? 2 : 1) {
  747. clock.p = clock.p1 * clock.p2;
  748. m2 = DIV_ROUND_CLOSEST_ULL(((uint64_t)target * clock.p *
  749. clock.n) << 22, refclk * clock.m1);
  750. if (m2 > INT_MAX/clock.m1)
  751. continue;
  752. clock.m2 = m2;
  753. chv_clock(refclk, &clock);
  754. if (!intel_PLL_is_valid(dev, limit, &clock))
  755. continue;
  756. /* based on hardware requirement, prefer bigger p
  757. */
  758. if (clock.p > best_clock->p) {
  759. *best_clock = clock;
  760. found = true;
  761. }
  762. }
  763. }
  764. return found;
  765. }
  766. bool intel_crtc_active(struct drm_crtc *crtc)
  767. {
  768. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  769. /* Be paranoid as we can arrive here with only partial
  770. * state retrieved from the hardware during setup.
  771. *
  772. * We can ditch the adjusted_mode.crtc_clock check as soon
  773. * as Haswell has gained clock readout/fastboot support.
  774. *
  775. * We can ditch the crtc->primary->fb check as soon as we can
  776. * properly reconstruct framebuffers.
  777. */
  778. return intel_crtc->active && crtc->primary->fb &&
  779. intel_crtc->config.adjusted_mode.crtc_clock;
  780. }
  781. enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv,
  782. enum pipe pipe)
  783. {
  784. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  785. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  786. return intel_crtc->config.cpu_transcoder;
  787. }
  788. static void g4x_wait_for_vblank(struct drm_device *dev, int pipe)
  789. {
  790. struct drm_i915_private *dev_priv = dev->dev_private;
  791. u32 frame, frame_reg = PIPE_FRMCOUNT_GM45(pipe);
  792. frame = I915_READ(frame_reg);
  793. if (wait_for(I915_READ_NOTRACE(frame_reg) != frame, 50))
  794. WARN(1, "vblank wait on pipe %c timed out\n",
  795. pipe_name(pipe));
  796. }
  797. /**
  798. * intel_wait_for_vblank - wait for vblank on a given pipe
  799. * @dev: drm device
  800. * @pipe: pipe to wait for
  801. *
  802. * Wait for vblank to occur on a given pipe. Needed for various bits of
  803. * mode setting code.
  804. */
  805. void intel_wait_for_vblank(struct drm_device *dev, int pipe)
  806. {
  807. struct drm_i915_private *dev_priv = dev->dev_private;
  808. int pipestat_reg = PIPESTAT(pipe);
  809. if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
  810. g4x_wait_for_vblank(dev, pipe);
  811. return;
  812. }
  813. /* Clear existing vblank status. Note this will clear any other
  814. * sticky status fields as well.
  815. *
  816. * This races with i915_driver_irq_handler() with the result
  817. * that either function could miss a vblank event. Here it is not
  818. * fatal, as we will either wait upon the next vblank interrupt or
  819. * timeout. Generally speaking intel_wait_for_vblank() is only
  820. * called during modeset at which time the GPU should be idle and
  821. * should *not* be performing page flips and thus not waiting on
  822. * vblanks...
  823. * Currently, the result of us stealing a vblank from the irq
  824. * handler is that a single frame will be skipped during swapbuffers.
  825. */
  826. I915_WRITE(pipestat_reg,
  827. I915_READ(pipestat_reg) | PIPE_VBLANK_INTERRUPT_STATUS);
  828. /* Wait for vblank interrupt bit to set */
  829. if (wait_for(I915_READ(pipestat_reg) &
  830. PIPE_VBLANK_INTERRUPT_STATUS,
  831. 50))
  832. DRM_DEBUG_KMS("vblank wait on pipe %c timed out\n",
  833. pipe_name(pipe));
  834. }
  835. static bool pipe_dsl_stopped(struct drm_device *dev, enum pipe pipe)
  836. {
  837. struct drm_i915_private *dev_priv = dev->dev_private;
  838. u32 reg = PIPEDSL(pipe);
  839. u32 line1, line2;
  840. u32 line_mask;
  841. if (IS_GEN2(dev))
  842. line_mask = DSL_LINEMASK_GEN2;
  843. else
  844. line_mask = DSL_LINEMASK_GEN3;
  845. line1 = I915_READ(reg) & line_mask;
  846. mdelay(5);
  847. line2 = I915_READ(reg) & line_mask;
  848. return line1 == line2;
  849. }
  850. /*
  851. * intel_wait_for_pipe_off - wait for pipe to turn off
  852. * @crtc: crtc whose pipe to wait for
  853. *
  854. * After disabling a pipe, we can't wait for vblank in the usual way,
  855. * spinning on the vblank interrupt status bit, since we won't actually
  856. * see an interrupt when the pipe is disabled.
  857. *
  858. * On Gen4 and above:
  859. * wait for the pipe register state bit to turn off
  860. *
  861. * Otherwise:
  862. * wait for the display line value to settle (it usually
  863. * ends up stopping at the start of the next frame).
  864. *
  865. */
  866. static void intel_wait_for_pipe_off(struct intel_crtc *crtc)
  867. {
  868. struct drm_device *dev = crtc->base.dev;
  869. struct drm_i915_private *dev_priv = dev->dev_private;
  870. enum transcoder cpu_transcoder = crtc->config.cpu_transcoder;
  871. enum pipe pipe = crtc->pipe;
  872. if (INTEL_INFO(dev)->gen >= 4) {
  873. int reg = PIPECONF(cpu_transcoder);
  874. /* Wait for the Pipe State to go off */
  875. if (wait_for((I915_READ(reg) & I965_PIPECONF_ACTIVE) == 0,
  876. 100))
  877. WARN(1, "pipe_off wait timed out\n");
  878. } else {
  879. /* Wait for the display line to settle */
  880. if (wait_for(pipe_dsl_stopped(dev, pipe), 100))
  881. WARN(1, "pipe_off wait timed out\n");
  882. }
  883. }
  884. /*
  885. * ibx_digital_port_connected - is the specified port connected?
  886. * @dev_priv: i915 private structure
  887. * @port: the port to test
  888. *
  889. * Returns true if @port is connected, false otherwise.
  890. */
  891. bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
  892. struct intel_digital_port *port)
  893. {
  894. u32 bit;
  895. if (HAS_PCH_IBX(dev_priv->dev)) {
  896. switch (port->port) {
  897. case PORT_B:
  898. bit = SDE_PORTB_HOTPLUG;
  899. break;
  900. case PORT_C:
  901. bit = SDE_PORTC_HOTPLUG;
  902. break;
  903. case PORT_D:
  904. bit = SDE_PORTD_HOTPLUG;
  905. break;
  906. default:
  907. return true;
  908. }
  909. } else {
  910. switch (port->port) {
  911. case PORT_B:
  912. bit = SDE_PORTB_HOTPLUG_CPT;
  913. break;
  914. case PORT_C:
  915. bit = SDE_PORTC_HOTPLUG_CPT;
  916. break;
  917. case PORT_D:
  918. bit = SDE_PORTD_HOTPLUG_CPT;
  919. break;
  920. default:
  921. return true;
  922. }
  923. }
  924. return I915_READ(SDEISR) & bit;
  925. }
  926. static const char *state_string(bool enabled)
  927. {
  928. return enabled ? "on" : "off";
  929. }
  930. /* Only for pre-ILK configs */
  931. void assert_pll(struct drm_i915_private *dev_priv,
  932. enum pipe pipe, bool state)
  933. {
  934. int reg;
  935. u32 val;
  936. bool cur_state;
  937. reg = DPLL(pipe);
  938. val = I915_READ(reg);
  939. cur_state = !!(val & DPLL_VCO_ENABLE);
  940. WARN(cur_state != state,
  941. "PLL state assertion failure (expected %s, current %s)\n",
  942. state_string(state), state_string(cur_state));
  943. }
  944. /* XXX: the dsi pll is shared between MIPI DSI ports */
  945. static void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state)
  946. {
  947. u32 val;
  948. bool cur_state;
  949. mutex_lock(&dev_priv->dpio_lock);
  950. val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL);
  951. mutex_unlock(&dev_priv->dpio_lock);
  952. cur_state = val & DSI_PLL_VCO_EN;
  953. WARN(cur_state != state,
  954. "DSI PLL state assertion failure (expected %s, current %s)\n",
  955. state_string(state), state_string(cur_state));
  956. }
  957. #define assert_dsi_pll_enabled(d) assert_dsi_pll(d, true)
  958. #define assert_dsi_pll_disabled(d) assert_dsi_pll(d, false)
  959. struct intel_shared_dpll *
  960. intel_crtc_to_shared_dpll(struct intel_crtc *crtc)
  961. {
  962. struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
  963. if (crtc->config.shared_dpll < 0)
  964. return NULL;
  965. return &dev_priv->shared_dplls[crtc->config.shared_dpll];
  966. }
  967. /* For ILK+ */
  968. void assert_shared_dpll(struct drm_i915_private *dev_priv,
  969. struct intel_shared_dpll *pll,
  970. bool state)
  971. {
  972. bool cur_state;
  973. struct intel_dpll_hw_state hw_state;
  974. if (WARN (!pll,
  975. "asserting DPLL %s with no DPLL\n", state_string(state)))
  976. return;
  977. cur_state = pll->get_hw_state(dev_priv, pll, &hw_state);
  978. WARN(cur_state != state,
  979. "%s assertion failure (expected %s, current %s)\n",
  980. pll->name, state_string(state), state_string(cur_state));
  981. }
  982. static void assert_fdi_tx(struct drm_i915_private *dev_priv,
  983. enum pipe pipe, bool state)
  984. {
  985. int reg;
  986. u32 val;
  987. bool cur_state;
  988. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  989. pipe);
  990. if (HAS_DDI(dev_priv->dev)) {
  991. /* DDI does not have a specific FDI_TX register */
  992. reg = TRANS_DDI_FUNC_CTL(cpu_transcoder);
  993. val = I915_READ(reg);
  994. cur_state = !!(val & TRANS_DDI_FUNC_ENABLE);
  995. } else {
  996. reg = FDI_TX_CTL(pipe);
  997. val = I915_READ(reg);
  998. cur_state = !!(val & FDI_TX_ENABLE);
  999. }
  1000. WARN(cur_state != state,
  1001. "FDI TX state assertion failure (expected %s, current %s)\n",
  1002. state_string(state), state_string(cur_state));
  1003. }
  1004. #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
  1005. #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
  1006. static void assert_fdi_rx(struct drm_i915_private *dev_priv,
  1007. enum pipe pipe, bool state)
  1008. {
  1009. int reg;
  1010. u32 val;
  1011. bool cur_state;
  1012. reg = FDI_RX_CTL(pipe);
  1013. val = I915_READ(reg);
  1014. cur_state = !!(val & FDI_RX_ENABLE);
  1015. WARN(cur_state != state,
  1016. "FDI RX state assertion failure (expected %s, current %s)\n",
  1017. state_string(state), state_string(cur_state));
  1018. }
  1019. #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
  1020. #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
  1021. static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv,
  1022. enum pipe pipe)
  1023. {
  1024. int reg;
  1025. u32 val;
  1026. /* ILK FDI PLL is always enabled */
  1027. if (INTEL_INFO(dev_priv->dev)->gen == 5)
  1028. return;
  1029. /* On Haswell, DDI ports are responsible for the FDI PLL setup */
  1030. if (HAS_DDI(dev_priv->dev))
  1031. return;
  1032. reg = FDI_TX_CTL(pipe);
  1033. val = I915_READ(reg);
  1034. WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n");
  1035. }
  1036. void assert_fdi_rx_pll(struct drm_i915_private *dev_priv,
  1037. enum pipe pipe, bool state)
  1038. {
  1039. int reg;
  1040. u32 val;
  1041. bool cur_state;
  1042. reg = FDI_RX_CTL(pipe);
  1043. val = I915_READ(reg);
  1044. cur_state = !!(val & FDI_RX_PLL_ENABLE);
  1045. WARN(cur_state != state,
  1046. "FDI RX PLL assertion failure (expected %s, current %s)\n",
  1047. state_string(state), state_string(cur_state));
  1048. }
  1049. static void assert_panel_unlocked(struct drm_i915_private *dev_priv,
  1050. enum pipe pipe)
  1051. {
  1052. struct drm_device *dev = dev_priv->dev;
  1053. int pp_reg;
  1054. u32 val;
  1055. enum pipe panel_pipe = PIPE_A;
  1056. bool locked = true;
  1057. if (WARN_ON(HAS_DDI(dev)))
  1058. return;
  1059. if (HAS_PCH_SPLIT(dev)) {
  1060. u32 port_sel;
  1061. pp_reg = PCH_PP_CONTROL;
  1062. port_sel = I915_READ(PCH_PP_ON_DELAYS) & PANEL_PORT_SELECT_MASK;
  1063. if (port_sel == PANEL_PORT_SELECT_LVDS &&
  1064. I915_READ(PCH_LVDS) & LVDS_PIPEB_SELECT)
  1065. panel_pipe = PIPE_B;
  1066. /* XXX: else fix for eDP */
  1067. } else if (IS_VALLEYVIEW(dev)) {
  1068. /* presumably write lock depends on pipe, not port select */
  1069. pp_reg = VLV_PIPE_PP_CONTROL(pipe);
  1070. panel_pipe = pipe;
  1071. } else {
  1072. pp_reg = PP_CONTROL;
  1073. if (I915_READ(LVDS) & LVDS_PIPEB_SELECT)
  1074. panel_pipe = PIPE_B;
  1075. }
  1076. val = I915_READ(pp_reg);
  1077. if (!(val & PANEL_POWER_ON) ||
  1078. ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS))
  1079. locked = false;
  1080. WARN(panel_pipe == pipe && locked,
  1081. "panel assertion failure, pipe %c regs locked\n",
  1082. pipe_name(pipe));
  1083. }
  1084. static void assert_cursor(struct drm_i915_private *dev_priv,
  1085. enum pipe pipe, bool state)
  1086. {
  1087. struct drm_device *dev = dev_priv->dev;
  1088. bool cur_state;
  1089. if (IS_845G(dev) || IS_I865G(dev))
  1090. cur_state = I915_READ(_CURACNTR) & CURSOR_ENABLE;
  1091. else
  1092. cur_state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
  1093. WARN(cur_state != state,
  1094. "cursor on pipe %c assertion failure (expected %s, current %s)\n",
  1095. pipe_name(pipe), state_string(state), state_string(cur_state));
  1096. }
  1097. #define assert_cursor_enabled(d, p) assert_cursor(d, p, true)
  1098. #define assert_cursor_disabled(d, p) assert_cursor(d, p, false)
  1099. void assert_pipe(struct drm_i915_private *dev_priv,
  1100. enum pipe pipe, bool state)
  1101. {
  1102. int reg;
  1103. u32 val;
  1104. bool cur_state;
  1105. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  1106. pipe);
  1107. /* if we need the pipe quirk it must be always on */
  1108. if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) ||
  1109. (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))
  1110. state = true;
  1111. if (!intel_display_power_enabled(dev_priv,
  1112. POWER_DOMAIN_TRANSCODER(cpu_transcoder))) {
  1113. cur_state = false;
  1114. } else {
  1115. reg = PIPECONF(cpu_transcoder);
  1116. val = I915_READ(reg);
  1117. cur_state = !!(val & PIPECONF_ENABLE);
  1118. }
  1119. WARN(cur_state != state,
  1120. "pipe %c assertion failure (expected %s, current %s)\n",
  1121. pipe_name(pipe), state_string(state), state_string(cur_state));
  1122. }
  1123. static void assert_plane(struct drm_i915_private *dev_priv,
  1124. enum plane plane, bool state)
  1125. {
  1126. int reg;
  1127. u32 val;
  1128. bool cur_state;
  1129. reg = DSPCNTR(plane);
  1130. val = I915_READ(reg);
  1131. cur_state = !!(val & DISPLAY_PLANE_ENABLE);
  1132. WARN(cur_state != state,
  1133. "plane %c assertion failure (expected %s, current %s)\n",
  1134. plane_name(plane), state_string(state), state_string(cur_state));
  1135. }
  1136. #define assert_plane_enabled(d, p) assert_plane(d, p, true)
  1137. #define assert_plane_disabled(d, p) assert_plane(d, p, false)
  1138. static void assert_planes_disabled(struct drm_i915_private *dev_priv,
  1139. enum pipe pipe)
  1140. {
  1141. struct drm_device *dev = dev_priv->dev;
  1142. int reg, i;
  1143. u32 val;
  1144. int cur_pipe;
  1145. /* Primary planes are fixed to pipes on gen4+ */
  1146. if (INTEL_INFO(dev)->gen >= 4) {
  1147. reg = DSPCNTR(pipe);
  1148. val = I915_READ(reg);
  1149. WARN(val & DISPLAY_PLANE_ENABLE,
  1150. "plane %c assertion failure, should be disabled but not\n",
  1151. plane_name(pipe));
  1152. return;
  1153. }
  1154. /* Need to check both planes against the pipe */
  1155. for_each_pipe(dev_priv, i) {
  1156. reg = DSPCNTR(i);
  1157. val = I915_READ(reg);
  1158. cur_pipe = (val & DISPPLANE_SEL_PIPE_MASK) >>
  1159. DISPPLANE_SEL_PIPE_SHIFT;
  1160. WARN((val & DISPLAY_PLANE_ENABLE) && pipe == cur_pipe,
  1161. "plane %c assertion failure, should be off on pipe %c but is still active\n",
  1162. plane_name(i), pipe_name(pipe));
  1163. }
  1164. }
  1165. static void assert_sprites_disabled(struct drm_i915_private *dev_priv,
  1166. enum pipe pipe)
  1167. {
  1168. struct drm_device *dev = dev_priv->dev;
  1169. int reg, sprite;
  1170. u32 val;
  1171. if (IS_VALLEYVIEW(dev)) {
  1172. for_each_sprite(pipe, sprite) {
  1173. reg = SPCNTR(pipe, sprite);
  1174. val = I915_READ(reg);
  1175. WARN(val & SP_ENABLE,
  1176. "sprite %c assertion failure, should be off on pipe %c but is still active\n",
  1177. sprite_name(pipe, sprite), pipe_name(pipe));
  1178. }
  1179. } else if (INTEL_INFO(dev)->gen >= 7) {
  1180. reg = SPRCTL(pipe);
  1181. val = I915_READ(reg);
  1182. WARN(val & SPRITE_ENABLE,
  1183. "sprite %c assertion failure, should be off on pipe %c but is still active\n",
  1184. plane_name(pipe), pipe_name(pipe));
  1185. } else if (INTEL_INFO(dev)->gen >= 5) {
  1186. reg = DVSCNTR(pipe);
  1187. val = I915_READ(reg);
  1188. WARN(val & DVS_ENABLE,
  1189. "sprite %c assertion failure, should be off on pipe %c but is still active\n",
  1190. plane_name(pipe), pipe_name(pipe));
  1191. }
  1192. }
  1193. static void assert_vblank_disabled(struct drm_crtc *crtc)
  1194. {
  1195. if (WARN_ON(drm_crtc_vblank_get(crtc) == 0))
  1196. drm_crtc_vblank_put(crtc);
  1197. }
  1198. static void ibx_assert_pch_refclk_enabled(struct drm_i915_private *dev_priv)
  1199. {
  1200. u32 val;
  1201. bool enabled;
  1202. WARN_ON(!(HAS_PCH_IBX(dev_priv->dev) || HAS_PCH_CPT(dev_priv->dev)));
  1203. val = I915_READ(PCH_DREF_CONTROL);
  1204. enabled = !!(val & (DREF_SSC_SOURCE_MASK | DREF_NONSPREAD_SOURCE_MASK |
  1205. DREF_SUPERSPREAD_SOURCE_MASK));
  1206. WARN(!enabled, "PCH refclk assertion failure, should be active but is disabled\n");
  1207. }
  1208. static void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv,
  1209. enum pipe pipe)
  1210. {
  1211. int reg;
  1212. u32 val;
  1213. bool enabled;
  1214. reg = PCH_TRANSCONF(pipe);
  1215. val = I915_READ(reg);
  1216. enabled = !!(val & TRANS_ENABLE);
  1217. WARN(enabled,
  1218. "transcoder assertion failed, should be off on pipe %c but is still active\n",
  1219. pipe_name(pipe));
  1220. }
  1221. static bool dp_pipe_enabled(struct drm_i915_private *dev_priv,
  1222. enum pipe pipe, u32 port_sel, u32 val)
  1223. {
  1224. if ((val & DP_PORT_EN) == 0)
  1225. return false;
  1226. if (HAS_PCH_CPT(dev_priv->dev)) {
  1227. u32 trans_dp_ctl_reg = TRANS_DP_CTL(pipe);
  1228. u32 trans_dp_ctl = I915_READ(trans_dp_ctl_reg);
  1229. if ((trans_dp_ctl & TRANS_DP_PORT_SEL_MASK) != port_sel)
  1230. return false;
  1231. } else if (IS_CHERRYVIEW(dev_priv->dev)) {
  1232. if ((val & DP_PIPE_MASK_CHV) != DP_PIPE_SELECT_CHV(pipe))
  1233. return false;
  1234. } else {
  1235. if ((val & DP_PIPE_MASK) != (pipe << 30))
  1236. return false;
  1237. }
  1238. return true;
  1239. }
  1240. static bool hdmi_pipe_enabled(struct drm_i915_private *dev_priv,
  1241. enum pipe pipe, u32 val)
  1242. {
  1243. if ((val & SDVO_ENABLE) == 0)
  1244. return false;
  1245. if (HAS_PCH_CPT(dev_priv->dev)) {
  1246. if ((val & SDVO_PIPE_SEL_MASK_CPT) != SDVO_PIPE_SEL_CPT(pipe))
  1247. return false;
  1248. } else if (IS_CHERRYVIEW(dev_priv->dev)) {
  1249. if ((val & SDVO_PIPE_SEL_MASK_CHV) != SDVO_PIPE_SEL_CHV(pipe))
  1250. return false;
  1251. } else {
  1252. if ((val & SDVO_PIPE_SEL_MASK) != SDVO_PIPE_SEL(pipe))
  1253. return false;
  1254. }
  1255. return true;
  1256. }
  1257. static bool lvds_pipe_enabled(struct drm_i915_private *dev_priv,
  1258. enum pipe pipe, u32 val)
  1259. {
  1260. if ((val & LVDS_PORT_EN) == 0)
  1261. return false;
  1262. if (HAS_PCH_CPT(dev_priv->dev)) {
  1263. if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe))
  1264. return false;
  1265. } else {
  1266. if ((val & LVDS_PIPE_MASK) != LVDS_PIPE(pipe))
  1267. return false;
  1268. }
  1269. return true;
  1270. }
  1271. static bool adpa_pipe_enabled(struct drm_i915_private *dev_priv,
  1272. enum pipe pipe, u32 val)
  1273. {
  1274. if ((val & ADPA_DAC_ENABLE) == 0)
  1275. return false;
  1276. if (HAS_PCH_CPT(dev_priv->dev)) {
  1277. if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe))
  1278. return false;
  1279. } else {
  1280. if ((val & ADPA_PIPE_SELECT_MASK) != ADPA_PIPE_SELECT(pipe))
  1281. return false;
  1282. }
  1283. return true;
  1284. }
  1285. static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv,
  1286. enum pipe pipe, int reg, u32 port_sel)
  1287. {
  1288. u32 val = I915_READ(reg);
  1289. WARN(dp_pipe_enabled(dev_priv, pipe, port_sel, val),
  1290. "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n",
  1291. reg, pipe_name(pipe));
  1292. WARN(HAS_PCH_IBX(dev_priv->dev) && (val & DP_PORT_EN) == 0
  1293. && (val & DP_PIPEB_SELECT),
  1294. "IBX PCH dp port still using transcoder B\n");
  1295. }
  1296. static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv,
  1297. enum pipe pipe, int reg)
  1298. {
  1299. u32 val = I915_READ(reg);
  1300. WARN(hdmi_pipe_enabled(dev_priv, pipe, val),
  1301. "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n",
  1302. reg, pipe_name(pipe));
  1303. WARN(HAS_PCH_IBX(dev_priv->dev) && (val & SDVO_ENABLE) == 0
  1304. && (val & SDVO_PIPE_B_SELECT),
  1305. "IBX PCH hdmi port still using transcoder B\n");
  1306. }
  1307. static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv,
  1308. enum pipe pipe)
  1309. {
  1310. int reg;
  1311. u32 val;
  1312. assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_B, TRANS_DP_PORT_SEL_B);
  1313. assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_C, TRANS_DP_PORT_SEL_C);
  1314. assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_D, TRANS_DP_PORT_SEL_D);
  1315. reg = PCH_ADPA;
  1316. val = I915_READ(reg);
  1317. WARN(adpa_pipe_enabled(dev_priv, pipe, val),
  1318. "PCH VGA enabled on transcoder %c, should be disabled\n",
  1319. pipe_name(pipe));
  1320. reg = PCH_LVDS;
  1321. val = I915_READ(reg);
  1322. WARN(lvds_pipe_enabled(dev_priv, pipe, val),
  1323. "PCH LVDS enabled on transcoder %c, should be disabled\n",
  1324. pipe_name(pipe));
  1325. assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIB);
  1326. assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIC);
  1327. assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMID);
  1328. }
  1329. static void intel_init_dpio(struct drm_device *dev)
  1330. {
  1331. struct drm_i915_private *dev_priv = dev->dev_private;
  1332. if (!IS_VALLEYVIEW(dev))
  1333. return;
  1334. /*
  1335. * IOSF_PORT_DPIO is used for VLV x2 PHY (DP/HDMI B and C),
  1336. * CHV x1 PHY (DP/HDMI D)
  1337. * IOSF_PORT_DPIO_2 is used for CHV x2 PHY (DP/HDMI B and C)
  1338. */
  1339. if (IS_CHERRYVIEW(dev)) {
  1340. DPIO_PHY_IOSF_PORT(DPIO_PHY0) = IOSF_PORT_DPIO_2;
  1341. DPIO_PHY_IOSF_PORT(DPIO_PHY1) = IOSF_PORT_DPIO;
  1342. } else {
  1343. DPIO_PHY_IOSF_PORT(DPIO_PHY0) = IOSF_PORT_DPIO;
  1344. }
  1345. }
  1346. static void vlv_enable_pll(struct intel_crtc *crtc)
  1347. {
  1348. struct drm_device *dev = crtc->base.dev;
  1349. struct drm_i915_private *dev_priv = dev->dev_private;
  1350. int reg = DPLL(crtc->pipe);
  1351. u32 dpll = crtc->config.dpll_hw_state.dpll;
  1352. assert_pipe_disabled(dev_priv, crtc->pipe);
  1353. /* No really, not for ILK+ */
  1354. BUG_ON(!IS_VALLEYVIEW(dev_priv->dev));
  1355. /* PLL is protected by panel, make sure we can write it */
  1356. if (IS_MOBILE(dev_priv->dev))
  1357. assert_panel_unlocked(dev_priv, crtc->pipe);
  1358. I915_WRITE(reg, dpll);
  1359. POSTING_READ(reg);
  1360. udelay(150);
  1361. if (wait_for(((I915_READ(reg) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1))
  1362. DRM_ERROR("DPLL %d failed to lock\n", crtc->pipe);
  1363. I915_WRITE(DPLL_MD(crtc->pipe), crtc->config.dpll_hw_state.dpll_md);
  1364. POSTING_READ(DPLL_MD(crtc->pipe));
  1365. /* We do this three times for luck */
  1366. I915_WRITE(reg, dpll);
  1367. POSTING_READ(reg);
  1368. udelay(150); /* wait for warmup */
  1369. I915_WRITE(reg, dpll);
  1370. POSTING_READ(reg);
  1371. udelay(150); /* wait for warmup */
  1372. I915_WRITE(reg, dpll);
  1373. POSTING_READ(reg);
  1374. udelay(150); /* wait for warmup */
  1375. }
  1376. static void chv_enable_pll(struct intel_crtc *crtc)
  1377. {
  1378. struct drm_device *dev = crtc->base.dev;
  1379. struct drm_i915_private *dev_priv = dev->dev_private;
  1380. int pipe = crtc->pipe;
  1381. enum dpio_channel port = vlv_pipe_to_channel(pipe);
  1382. u32 tmp;
  1383. assert_pipe_disabled(dev_priv, crtc->pipe);
  1384. BUG_ON(!IS_CHERRYVIEW(dev_priv->dev));
  1385. mutex_lock(&dev_priv->dpio_lock);
  1386. /* Enable back the 10bit clock to display controller */
  1387. tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
  1388. tmp |= DPIO_DCLKP_EN;
  1389. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp);
  1390. /*
  1391. * Need to wait > 100ns between dclkp clock enable bit and PLL enable.
  1392. */
  1393. udelay(1);
  1394. /* Enable PLL */
  1395. I915_WRITE(DPLL(pipe), crtc->config.dpll_hw_state.dpll);
  1396. /* Check PLL is locked */
  1397. if (wait_for(((I915_READ(DPLL(pipe)) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1))
  1398. DRM_ERROR("PLL %d failed to lock\n", pipe);
  1399. /* not sure when this should be written */
  1400. I915_WRITE(DPLL_MD(pipe), crtc->config.dpll_hw_state.dpll_md);
  1401. POSTING_READ(DPLL_MD(pipe));
  1402. mutex_unlock(&dev_priv->dpio_lock);
  1403. }
  1404. static int intel_num_dvo_pipes(struct drm_device *dev)
  1405. {
  1406. struct intel_crtc *crtc;
  1407. int count = 0;
  1408. for_each_intel_crtc(dev, crtc)
  1409. count += crtc->active &&
  1410. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DVO);
  1411. return count;
  1412. }
  1413. static void i9xx_enable_pll(struct intel_crtc *crtc)
  1414. {
  1415. struct drm_device *dev = crtc->base.dev;
  1416. struct drm_i915_private *dev_priv = dev->dev_private;
  1417. int reg = DPLL(crtc->pipe);
  1418. u32 dpll = crtc->config.dpll_hw_state.dpll;
  1419. assert_pipe_disabled(dev_priv, crtc->pipe);
  1420. /* No really, not for ILK+ */
  1421. BUG_ON(INTEL_INFO(dev)->gen >= 5);
  1422. /* PLL is protected by panel, make sure we can write it */
  1423. if (IS_MOBILE(dev) && !IS_I830(dev))
  1424. assert_panel_unlocked(dev_priv, crtc->pipe);
  1425. /* Enable DVO 2x clock on both PLLs if necessary */
  1426. if (IS_I830(dev) && intel_num_dvo_pipes(dev) > 0) {
  1427. /*
  1428. * It appears to be important that we don't enable this
  1429. * for the current pipe before otherwise configuring the
  1430. * PLL. No idea how this should be handled if multiple
  1431. * DVO outputs are enabled simultaneosly.
  1432. */
  1433. dpll |= DPLL_DVO_2X_MODE;
  1434. I915_WRITE(DPLL(!crtc->pipe),
  1435. I915_READ(DPLL(!crtc->pipe)) | DPLL_DVO_2X_MODE);
  1436. }
  1437. /* Wait for the clocks to stabilize. */
  1438. POSTING_READ(reg);
  1439. udelay(150);
  1440. if (INTEL_INFO(dev)->gen >= 4) {
  1441. I915_WRITE(DPLL_MD(crtc->pipe),
  1442. crtc->config.dpll_hw_state.dpll_md);
  1443. } else {
  1444. /* The pixel multiplier can only be updated once the
  1445. * DPLL is enabled and the clocks are stable.
  1446. *
  1447. * So write it again.
  1448. */
  1449. I915_WRITE(reg, dpll);
  1450. }
  1451. /* We do this three times for luck */
  1452. I915_WRITE(reg, dpll);
  1453. POSTING_READ(reg);
  1454. udelay(150); /* wait for warmup */
  1455. I915_WRITE(reg, dpll);
  1456. POSTING_READ(reg);
  1457. udelay(150); /* wait for warmup */
  1458. I915_WRITE(reg, dpll);
  1459. POSTING_READ(reg);
  1460. udelay(150); /* wait for warmup */
  1461. }
  1462. /**
  1463. * i9xx_disable_pll - disable a PLL
  1464. * @dev_priv: i915 private structure
  1465. * @pipe: pipe PLL to disable
  1466. *
  1467. * Disable the PLL for @pipe, making sure the pipe is off first.
  1468. *
  1469. * Note! This is for pre-ILK only.
  1470. */
  1471. static void i9xx_disable_pll(struct intel_crtc *crtc)
  1472. {
  1473. struct drm_device *dev = crtc->base.dev;
  1474. struct drm_i915_private *dev_priv = dev->dev_private;
  1475. enum pipe pipe = crtc->pipe;
  1476. /* Disable DVO 2x clock on both PLLs if necessary */
  1477. if (IS_I830(dev) &&
  1478. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DVO) &&
  1479. intel_num_dvo_pipes(dev) == 1) {
  1480. I915_WRITE(DPLL(PIPE_B),
  1481. I915_READ(DPLL(PIPE_B)) & ~DPLL_DVO_2X_MODE);
  1482. I915_WRITE(DPLL(PIPE_A),
  1483. I915_READ(DPLL(PIPE_A)) & ~DPLL_DVO_2X_MODE);
  1484. }
  1485. /* Don't disable pipe or pipe PLLs if needed */
  1486. if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) ||
  1487. (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))
  1488. return;
  1489. /* Make sure the pipe isn't still relying on us */
  1490. assert_pipe_disabled(dev_priv, pipe);
  1491. I915_WRITE(DPLL(pipe), 0);
  1492. POSTING_READ(DPLL(pipe));
  1493. }
  1494. static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
  1495. {
  1496. u32 val = 0;
  1497. /* Make sure the pipe isn't still relying on us */
  1498. assert_pipe_disabled(dev_priv, pipe);
  1499. /*
  1500. * Leave integrated clock source and reference clock enabled for pipe B.
  1501. * The latter is needed for VGA hotplug / manual detection.
  1502. */
  1503. if (pipe == PIPE_B)
  1504. val = DPLL_INTEGRATED_CRI_CLK_VLV | DPLL_REFA_CLK_ENABLE_VLV;
  1505. I915_WRITE(DPLL(pipe), val);
  1506. POSTING_READ(DPLL(pipe));
  1507. }
  1508. static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
  1509. {
  1510. enum dpio_channel port = vlv_pipe_to_channel(pipe);
  1511. u32 val;
  1512. /* Make sure the pipe isn't still relying on us */
  1513. assert_pipe_disabled(dev_priv, pipe);
  1514. /* Set PLL en = 0 */
  1515. val = DPLL_SSC_REF_CLOCK_CHV | DPLL_REFA_CLK_ENABLE_VLV;
  1516. if (pipe != PIPE_A)
  1517. val |= DPLL_INTEGRATED_CRI_CLK_VLV;
  1518. I915_WRITE(DPLL(pipe), val);
  1519. POSTING_READ(DPLL(pipe));
  1520. mutex_lock(&dev_priv->dpio_lock);
  1521. /* Disable 10bit clock to display controller */
  1522. val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
  1523. val &= ~DPIO_DCLKP_EN;
  1524. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val);
  1525. /* disable left/right clock distribution */
  1526. if (pipe != PIPE_B) {
  1527. val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW5_CH0);
  1528. val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK);
  1529. vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW5_CH0, val);
  1530. } else {
  1531. val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW1_CH1);
  1532. val &= ~(CHV_BUFLEFTENA2_MASK | CHV_BUFRIGHTENA2_MASK);
  1533. vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW1_CH1, val);
  1534. }
  1535. mutex_unlock(&dev_priv->dpio_lock);
  1536. }
  1537. void vlv_wait_port_ready(struct drm_i915_private *dev_priv,
  1538. struct intel_digital_port *dport)
  1539. {
  1540. u32 port_mask;
  1541. int dpll_reg;
  1542. switch (dport->port) {
  1543. case PORT_B:
  1544. port_mask = DPLL_PORTB_READY_MASK;
  1545. dpll_reg = DPLL(0);
  1546. break;
  1547. case PORT_C:
  1548. port_mask = DPLL_PORTC_READY_MASK;
  1549. dpll_reg = DPLL(0);
  1550. break;
  1551. case PORT_D:
  1552. port_mask = DPLL_PORTD_READY_MASK;
  1553. dpll_reg = DPIO_PHY_STATUS;
  1554. break;
  1555. default:
  1556. BUG();
  1557. }
  1558. if (wait_for((I915_READ(dpll_reg) & port_mask) == 0, 1000))
  1559. WARN(1, "timed out waiting for port %c ready: 0x%08x\n",
  1560. port_name(dport->port), I915_READ(dpll_reg));
  1561. }
  1562. static void intel_prepare_shared_dpll(struct intel_crtc *crtc)
  1563. {
  1564. struct drm_device *dev = crtc->base.dev;
  1565. struct drm_i915_private *dev_priv = dev->dev_private;
  1566. struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
  1567. if (WARN_ON(pll == NULL))
  1568. return;
  1569. WARN_ON(!pll->refcount);
  1570. if (pll->active == 0) {
  1571. DRM_DEBUG_DRIVER("setting up %s\n", pll->name);
  1572. WARN_ON(pll->on);
  1573. assert_shared_dpll_disabled(dev_priv, pll);
  1574. pll->mode_set(dev_priv, pll);
  1575. }
  1576. }
  1577. /**
  1578. * intel_enable_shared_dpll - enable PCH PLL
  1579. * @dev_priv: i915 private structure
  1580. * @pipe: pipe PLL to enable
  1581. *
  1582. * The PCH PLL needs to be enabled before the PCH transcoder, since it
  1583. * drives the transcoder clock.
  1584. */
  1585. static void intel_enable_shared_dpll(struct intel_crtc *crtc)
  1586. {
  1587. struct drm_device *dev = crtc->base.dev;
  1588. struct drm_i915_private *dev_priv = dev->dev_private;
  1589. struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
  1590. if (WARN_ON(pll == NULL))
  1591. return;
  1592. if (WARN_ON(pll->refcount == 0))
  1593. return;
  1594. DRM_DEBUG_KMS("enable %s (active %d, on? %d) for crtc %d\n",
  1595. pll->name, pll->active, pll->on,
  1596. crtc->base.base.id);
  1597. if (pll->active++) {
  1598. WARN_ON(!pll->on);
  1599. assert_shared_dpll_enabled(dev_priv, pll);
  1600. return;
  1601. }
  1602. WARN_ON(pll->on);
  1603. intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS);
  1604. DRM_DEBUG_KMS("enabling %s\n", pll->name);
  1605. pll->enable(dev_priv, pll);
  1606. pll->on = true;
  1607. }
  1608. static void intel_disable_shared_dpll(struct intel_crtc *crtc)
  1609. {
  1610. struct drm_device *dev = crtc->base.dev;
  1611. struct drm_i915_private *dev_priv = dev->dev_private;
  1612. struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
  1613. /* PCH only available on ILK+ */
  1614. BUG_ON(INTEL_INFO(dev)->gen < 5);
  1615. if (WARN_ON(pll == NULL))
  1616. return;
  1617. if (WARN_ON(pll->refcount == 0))
  1618. return;
  1619. DRM_DEBUG_KMS("disable %s (active %d, on? %d) for crtc %d\n",
  1620. pll->name, pll->active, pll->on,
  1621. crtc->base.base.id);
  1622. if (WARN_ON(pll->active == 0)) {
  1623. assert_shared_dpll_disabled(dev_priv, pll);
  1624. return;
  1625. }
  1626. assert_shared_dpll_enabled(dev_priv, pll);
  1627. WARN_ON(!pll->on);
  1628. if (--pll->active)
  1629. return;
  1630. DRM_DEBUG_KMS("disabling %s\n", pll->name);
  1631. pll->disable(dev_priv, pll);
  1632. pll->on = false;
  1633. intel_display_power_put(dev_priv, POWER_DOMAIN_PLLS);
  1634. }
  1635. static void ironlake_enable_pch_transcoder(struct drm_i915_private *dev_priv,
  1636. enum pipe pipe)
  1637. {
  1638. struct drm_device *dev = dev_priv->dev;
  1639. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  1640. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1641. uint32_t reg, val, pipeconf_val;
  1642. /* PCH only available on ILK+ */
  1643. BUG_ON(!HAS_PCH_SPLIT(dev));
  1644. /* Make sure PCH DPLL is enabled */
  1645. assert_shared_dpll_enabled(dev_priv,
  1646. intel_crtc_to_shared_dpll(intel_crtc));
  1647. /* FDI must be feeding us bits for PCH ports */
  1648. assert_fdi_tx_enabled(dev_priv, pipe);
  1649. assert_fdi_rx_enabled(dev_priv, pipe);
  1650. if (HAS_PCH_CPT(dev)) {
  1651. /* Workaround: Set the timing override bit before enabling the
  1652. * pch transcoder. */
  1653. reg = TRANS_CHICKEN2(pipe);
  1654. val = I915_READ(reg);
  1655. val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
  1656. I915_WRITE(reg, val);
  1657. }
  1658. reg = PCH_TRANSCONF(pipe);
  1659. val = I915_READ(reg);
  1660. pipeconf_val = I915_READ(PIPECONF(pipe));
  1661. if (HAS_PCH_IBX(dev_priv->dev)) {
  1662. /*
  1663. * make the BPC in transcoder be consistent with
  1664. * that in pipeconf reg.
  1665. */
  1666. val &= ~PIPECONF_BPC_MASK;
  1667. val |= pipeconf_val & PIPECONF_BPC_MASK;
  1668. }
  1669. val &= ~TRANS_INTERLACE_MASK;
  1670. if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK)
  1671. if (HAS_PCH_IBX(dev_priv->dev) &&
  1672. intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO))
  1673. val |= TRANS_LEGACY_INTERLACED_ILK;
  1674. else
  1675. val |= TRANS_INTERLACED;
  1676. else
  1677. val |= TRANS_PROGRESSIVE;
  1678. I915_WRITE(reg, val | TRANS_ENABLE);
  1679. if (wait_for(I915_READ(reg) & TRANS_STATE_ENABLE, 100))
  1680. DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe));
  1681. }
  1682. static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv,
  1683. enum transcoder cpu_transcoder)
  1684. {
  1685. u32 val, pipeconf_val;
  1686. /* PCH only available on ILK+ */
  1687. BUG_ON(!HAS_PCH_SPLIT(dev_priv->dev));
  1688. /* FDI must be feeding us bits for PCH ports */
  1689. assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder);
  1690. assert_fdi_rx_enabled(dev_priv, TRANSCODER_A);
  1691. /* Workaround: set timing override bit. */
  1692. val = I915_READ(_TRANSA_CHICKEN2);
  1693. val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
  1694. I915_WRITE(_TRANSA_CHICKEN2, val);
  1695. val = TRANS_ENABLE;
  1696. pipeconf_val = I915_READ(PIPECONF(cpu_transcoder));
  1697. if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) ==
  1698. PIPECONF_INTERLACED_ILK)
  1699. val |= TRANS_INTERLACED;
  1700. else
  1701. val |= TRANS_PROGRESSIVE;
  1702. I915_WRITE(LPT_TRANSCONF, val);
  1703. if (wait_for(I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE, 100))
  1704. DRM_ERROR("Failed to enable PCH transcoder\n");
  1705. }
  1706. static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv,
  1707. enum pipe pipe)
  1708. {
  1709. struct drm_device *dev = dev_priv->dev;
  1710. uint32_t reg, val;
  1711. /* FDI relies on the transcoder */
  1712. assert_fdi_tx_disabled(dev_priv, pipe);
  1713. assert_fdi_rx_disabled(dev_priv, pipe);
  1714. /* Ports must be off as well */
  1715. assert_pch_ports_disabled(dev_priv, pipe);
  1716. reg = PCH_TRANSCONF(pipe);
  1717. val = I915_READ(reg);
  1718. val &= ~TRANS_ENABLE;
  1719. I915_WRITE(reg, val);
  1720. /* wait for PCH transcoder off, transcoder state */
  1721. if (wait_for((I915_READ(reg) & TRANS_STATE_ENABLE) == 0, 50))
  1722. DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe));
  1723. if (!HAS_PCH_IBX(dev)) {
  1724. /* Workaround: Clear the timing override chicken bit again. */
  1725. reg = TRANS_CHICKEN2(pipe);
  1726. val = I915_READ(reg);
  1727. val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
  1728. I915_WRITE(reg, val);
  1729. }
  1730. }
  1731. static void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv)
  1732. {
  1733. u32 val;
  1734. val = I915_READ(LPT_TRANSCONF);
  1735. val &= ~TRANS_ENABLE;
  1736. I915_WRITE(LPT_TRANSCONF, val);
  1737. /* wait for PCH transcoder off, transcoder state */
  1738. if (wait_for((I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE) == 0, 50))
  1739. DRM_ERROR("Failed to disable PCH transcoder\n");
  1740. /* Workaround: clear timing override bit. */
  1741. val = I915_READ(_TRANSA_CHICKEN2);
  1742. val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
  1743. I915_WRITE(_TRANSA_CHICKEN2, val);
  1744. }
  1745. /**
  1746. * intel_enable_pipe - enable a pipe, asserting requirements
  1747. * @crtc: crtc responsible for the pipe
  1748. *
  1749. * Enable @crtc's pipe, making sure that various hardware specific requirements
  1750. * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc.
  1751. */
  1752. static void intel_enable_pipe(struct intel_crtc *crtc)
  1753. {
  1754. struct drm_device *dev = crtc->base.dev;
  1755. struct drm_i915_private *dev_priv = dev->dev_private;
  1756. enum pipe pipe = crtc->pipe;
  1757. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  1758. pipe);
  1759. enum pipe pch_transcoder;
  1760. int reg;
  1761. u32 val;
  1762. assert_planes_disabled(dev_priv, pipe);
  1763. assert_cursor_disabled(dev_priv, pipe);
  1764. assert_sprites_disabled(dev_priv, pipe);
  1765. if (HAS_PCH_LPT(dev_priv->dev))
  1766. pch_transcoder = TRANSCODER_A;
  1767. else
  1768. pch_transcoder = pipe;
  1769. /*
  1770. * A pipe without a PLL won't actually be able to drive bits from
  1771. * a plane. On ILK+ the pipe PLLs are integrated, so we don't
  1772. * need the check.
  1773. */
  1774. if (!HAS_PCH_SPLIT(dev_priv->dev))
  1775. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DSI))
  1776. assert_dsi_pll_enabled(dev_priv);
  1777. else
  1778. assert_pll_enabled(dev_priv, pipe);
  1779. else {
  1780. if (crtc->config.has_pch_encoder) {
  1781. /* if driving the PCH, we need FDI enabled */
  1782. assert_fdi_rx_pll_enabled(dev_priv, pch_transcoder);
  1783. assert_fdi_tx_pll_enabled(dev_priv,
  1784. (enum pipe) cpu_transcoder);
  1785. }
  1786. /* FIXME: assert CPU port conditions for SNB+ */
  1787. }
  1788. reg = PIPECONF(cpu_transcoder);
  1789. val = I915_READ(reg);
  1790. if (val & PIPECONF_ENABLE) {
  1791. WARN_ON(!((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) ||
  1792. (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)));
  1793. return;
  1794. }
  1795. I915_WRITE(reg, val | PIPECONF_ENABLE);
  1796. POSTING_READ(reg);
  1797. }
  1798. /**
  1799. * intel_disable_pipe - disable a pipe, asserting requirements
  1800. * @crtc: crtc whose pipes is to be disabled
  1801. *
  1802. * Disable the pipe of @crtc, making sure that various hardware
  1803. * specific requirements are met, if applicable, e.g. plane
  1804. * disabled, panel fitter off, etc.
  1805. *
  1806. * Will wait until the pipe has shut down before returning.
  1807. */
  1808. static void intel_disable_pipe(struct intel_crtc *crtc)
  1809. {
  1810. struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
  1811. enum transcoder cpu_transcoder = crtc->config.cpu_transcoder;
  1812. enum pipe pipe = crtc->pipe;
  1813. int reg;
  1814. u32 val;
  1815. /*
  1816. * Make sure planes won't keep trying to pump pixels to us,
  1817. * or we might hang the display.
  1818. */
  1819. assert_planes_disabled(dev_priv, pipe);
  1820. assert_cursor_disabled(dev_priv, pipe);
  1821. assert_sprites_disabled(dev_priv, pipe);
  1822. reg = PIPECONF(cpu_transcoder);
  1823. val = I915_READ(reg);
  1824. if ((val & PIPECONF_ENABLE) == 0)
  1825. return;
  1826. /*
  1827. * Double wide has implications for planes
  1828. * so best keep it disabled when not needed.
  1829. */
  1830. if (crtc->config.double_wide)
  1831. val &= ~PIPECONF_DOUBLE_WIDE;
  1832. /* Don't disable pipe or pipe PLLs if needed */
  1833. if (!(pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) &&
  1834. !(pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))
  1835. val &= ~PIPECONF_ENABLE;
  1836. I915_WRITE(reg, val);
  1837. if ((val & PIPECONF_ENABLE) == 0)
  1838. intel_wait_for_pipe_off(crtc);
  1839. }
  1840. /*
  1841. * Plane regs are double buffered, going from enabled->disabled needs a
  1842. * trigger in order to latch. The display address reg provides this.
  1843. */
  1844. void intel_flush_primary_plane(struct drm_i915_private *dev_priv,
  1845. enum plane plane)
  1846. {
  1847. struct drm_device *dev = dev_priv->dev;
  1848. u32 reg = INTEL_INFO(dev)->gen >= 4 ? DSPSURF(plane) : DSPADDR(plane);
  1849. I915_WRITE(reg, I915_READ(reg));
  1850. POSTING_READ(reg);
  1851. }
  1852. /**
  1853. * intel_enable_primary_hw_plane - enable the primary plane on a given pipe
  1854. * @plane: plane to be enabled
  1855. * @crtc: crtc for the plane
  1856. *
  1857. * Enable @plane on @crtc, making sure that the pipe is running first.
  1858. */
  1859. static void intel_enable_primary_hw_plane(struct drm_plane *plane,
  1860. struct drm_crtc *crtc)
  1861. {
  1862. struct drm_device *dev = plane->dev;
  1863. struct drm_i915_private *dev_priv = dev->dev_private;
  1864. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1865. /* If the pipe isn't enabled, we can't pump pixels and may hang */
  1866. assert_pipe_enabled(dev_priv, intel_crtc->pipe);
  1867. if (intel_crtc->primary_enabled)
  1868. return;
  1869. intel_crtc->primary_enabled = true;
  1870. dev_priv->display.update_primary_plane(crtc, plane->fb,
  1871. crtc->x, crtc->y);
  1872. /*
  1873. * BDW signals flip done immediately if the plane
  1874. * is disabled, even if the plane enable is already
  1875. * armed to occur at the next vblank :(
  1876. */
  1877. if (IS_BROADWELL(dev))
  1878. intel_wait_for_vblank(dev, intel_crtc->pipe);
  1879. }
  1880. /**
  1881. * intel_disable_primary_hw_plane - disable the primary hardware plane
  1882. * @plane: plane to be disabled
  1883. * @crtc: crtc for the plane
  1884. *
  1885. * Disable @plane on @crtc, making sure that the pipe is running first.
  1886. */
  1887. static void intel_disable_primary_hw_plane(struct drm_plane *plane,
  1888. struct drm_crtc *crtc)
  1889. {
  1890. struct drm_device *dev = plane->dev;
  1891. struct drm_i915_private *dev_priv = dev->dev_private;
  1892. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1893. assert_pipe_enabled(dev_priv, intel_crtc->pipe);
  1894. if (!intel_crtc->primary_enabled)
  1895. return;
  1896. intel_crtc->primary_enabled = false;
  1897. dev_priv->display.update_primary_plane(crtc, plane->fb,
  1898. crtc->x, crtc->y);
  1899. }
  1900. static bool need_vtd_wa(struct drm_device *dev)
  1901. {
  1902. #ifdef CONFIG_INTEL_IOMMU
  1903. if (INTEL_INFO(dev)->gen >= 6 && intel_iommu_gfx_mapped)
  1904. return true;
  1905. #endif
  1906. return false;
  1907. }
  1908. static int intel_align_height(struct drm_device *dev, int height, bool tiled)
  1909. {
  1910. int tile_height;
  1911. tile_height = tiled ? (IS_GEN2(dev) ? 16 : 8) : 1;
  1912. return ALIGN(height, tile_height);
  1913. }
  1914. int
  1915. intel_pin_and_fence_fb_obj(struct drm_device *dev,
  1916. struct drm_i915_gem_object *obj,
  1917. struct intel_engine_cs *pipelined)
  1918. {
  1919. struct drm_i915_private *dev_priv = dev->dev_private;
  1920. u32 alignment;
  1921. int ret;
  1922. WARN_ON(!mutex_is_locked(&dev->struct_mutex));
  1923. switch (obj->tiling_mode) {
  1924. case I915_TILING_NONE:
  1925. if (IS_BROADWATER(dev) || IS_CRESTLINE(dev))
  1926. alignment = 128 * 1024;
  1927. else if (INTEL_INFO(dev)->gen >= 4)
  1928. alignment = 4 * 1024;
  1929. else
  1930. alignment = 64 * 1024;
  1931. break;
  1932. case I915_TILING_X:
  1933. /* pin() will align the object as required by fence */
  1934. alignment = 0;
  1935. break;
  1936. case I915_TILING_Y:
  1937. WARN(1, "Y tiled bo slipped through, driver bug!\n");
  1938. return -EINVAL;
  1939. default:
  1940. BUG();
  1941. }
  1942. /* Note that the w/a also requires 64 PTE of padding following the
  1943. * bo. We currently fill all unused PTE with the shadow page and so
  1944. * we should always have valid PTE following the scanout preventing
  1945. * the VT-d warning.
  1946. */
  1947. if (need_vtd_wa(dev) && alignment < 256 * 1024)
  1948. alignment = 256 * 1024;
  1949. /*
  1950. * Global gtt pte registers are special registers which actually forward
  1951. * writes to a chunk of system memory. Which means that there is no risk
  1952. * that the register values disappear as soon as we call
  1953. * intel_runtime_pm_put(), so it is correct to wrap only the
  1954. * pin/unpin/fence and not more.
  1955. */
  1956. intel_runtime_pm_get(dev_priv);
  1957. dev_priv->mm.interruptible = false;
  1958. ret = i915_gem_object_pin_to_display_plane(obj, alignment, pipelined);
  1959. if (ret)
  1960. goto err_interruptible;
  1961. /* Install a fence for tiled scan-out. Pre-i965 always needs a
  1962. * fence, whereas 965+ only requires a fence if using
  1963. * framebuffer compression. For simplicity, we always install
  1964. * a fence as the cost is not that onerous.
  1965. */
  1966. ret = i915_gem_object_get_fence(obj);
  1967. if (ret)
  1968. goto err_unpin;
  1969. i915_gem_object_pin_fence(obj);
  1970. dev_priv->mm.interruptible = true;
  1971. intel_runtime_pm_put(dev_priv);
  1972. return 0;
  1973. err_unpin:
  1974. i915_gem_object_unpin_from_display_plane(obj);
  1975. err_interruptible:
  1976. dev_priv->mm.interruptible = true;
  1977. intel_runtime_pm_put(dev_priv);
  1978. return ret;
  1979. }
  1980. void intel_unpin_fb_obj(struct drm_i915_gem_object *obj)
  1981. {
  1982. WARN_ON(!mutex_is_locked(&obj->base.dev->struct_mutex));
  1983. i915_gem_object_unpin_fence(obj);
  1984. i915_gem_object_unpin_from_display_plane(obj);
  1985. }
  1986. /* Computes the linear offset to the base tile and adjusts x, y. bytes per pixel
  1987. * is assumed to be a power-of-two. */
  1988. unsigned long intel_gen4_compute_page_offset(int *x, int *y,
  1989. unsigned int tiling_mode,
  1990. unsigned int cpp,
  1991. unsigned int pitch)
  1992. {
  1993. if (tiling_mode != I915_TILING_NONE) {
  1994. unsigned int tile_rows, tiles;
  1995. tile_rows = *y / 8;
  1996. *y %= 8;
  1997. tiles = *x / (512/cpp);
  1998. *x %= 512/cpp;
  1999. return tile_rows * pitch * 8 + tiles * 4096;
  2000. } else {
  2001. unsigned int offset;
  2002. offset = *y * pitch + *x * cpp;
  2003. *y = 0;
  2004. *x = (offset & 4095) / cpp;
  2005. return offset & -4096;
  2006. }
  2007. }
  2008. int intel_format_to_fourcc(int format)
  2009. {
  2010. switch (format) {
  2011. case DISPPLANE_8BPP:
  2012. return DRM_FORMAT_C8;
  2013. case DISPPLANE_BGRX555:
  2014. return DRM_FORMAT_XRGB1555;
  2015. case DISPPLANE_BGRX565:
  2016. return DRM_FORMAT_RGB565;
  2017. default:
  2018. case DISPPLANE_BGRX888:
  2019. return DRM_FORMAT_XRGB8888;
  2020. case DISPPLANE_RGBX888:
  2021. return DRM_FORMAT_XBGR8888;
  2022. case DISPPLANE_BGRX101010:
  2023. return DRM_FORMAT_XRGB2101010;
  2024. case DISPPLANE_RGBX101010:
  2025. return DRM_FORMAT_XBGR2101010;
  2026. }
  2027. }
  2028. static bool intel_alloc_plane_obj(struct intel_crtc *crtc,
  2029. struct intel_plane_config *plane_config)
  2030. {
  2031. struct drm_device *dev = crtc->base.dev;
  2032. struct drm_i915_gem_object *obj = NULL;
  2033. struct drm_mode_fb_cmd2 mode_cmd = { 0 };
  2034. u32 base = plane_config->base;
  2035. if (plane_config->size == 0)
  2036. return false;
  2037. obj = i915_gem_object_create_stolen_for_preallocated(dev, base, base,
  2038. plane_config->size);
  2039. if (!obj)
  2040. return false;
  2041. if (plane_config->tiled) {
  2042. obj->tiling_mode = I915_TILING_X;
  2043. obj->stride = crtc->base.primary->fb->pitches[0];
  2044. }
  2045. mode_cmd.pixel_format = crtc->base.primary->fb->pixel_format;
  2046. mode_cmd.width = crtc->base.primary->fb->width;
  2047. mode_cmd.height = crtc->base.primary->fb->height;
  2048. mode_cmd.pitches[0] = crtc->base.primary->fb->pitches[0];
  2049. mutex_lock(&dev->struct_mutex);
  2050. if (intel_framebuffer_init(dev, to_intel_framebuffer(crtc->base.primary->fb),
  2051. &mode_cmd, obj)) {
  2052. DRM_DEBUG_KMS("intel fb init failed\n");
  2053. goto out_unref_obj;
  2054. }
  2055. obj->frontbuffer_bits = INTEL_FRONTBUFFER_PRIMARY(crtc->pipe);
  2056. mutex_unlock(&dev->struct_mutex);
  2057. DRM_DEBUG_KMS("plane fb obj %p\n", obj);
  2058. return true;
  2059. out_unref_obj:
  2060. drm_gem_object_unreference(&obj->base);
  2061. mutex_unlock(&dev->struct_mutex);
  2062. return false;
  2063. }
  2064. static void intel_find_plane_obj(struct intel_crtc *intel_crtc,
  2065. struct intel_plane_config *plane_config)
  2066. {
  2067. struct drm_device *dev = intel_crtc->base.dev;
  2068. struct drm_crtc *c;
  2069. struct intel_crtc *i;
  2070. struct drm_i915_gem_object *obj;
  2071. if (!intel_crtc->base.primary->fb)
  2072. return;
  2073. if (intel_alloc_plane_obj(intel_crtc, plane_config))
  2074. return;
  2075. kfree(intel_crtc->base.primary->fb);
  2076. intel_crtc->base.primary->fb = NULL;
  2077. /*
  2078. * Failed to alloc the obj, check to see if we should share
  2079. * an fb with another CRTC instead
  2080. */
  2081. for_each_crtc(dev, c) {
  2082. i = to_intel_crtc(c);
  2083. if (c == &intel_crtc->base)
  2084. continue;
  2085. if (!i->active)
  2086. continue;
  2087. obj = intel_fb_obj(c->primary->fb);
  2088. if (obj == NULL)
  2089. continue;
  2090. if (i915_gem_obj_ggtt_offset(obj) == plane_config->base) {
  2091. drm_framebuffer_reference(c->primary->fb);
  2092. intel_crtc->base.primary->fb = c->primary->fb;
  2093. obj->frontbuffer_bits |= INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe);
  2094. break;
  2095. }
  2096. }
  2097. }
  2098. static void i9xx_update_primary_plane(struct drm_crtc *crtc,
  2099. struct drm_framebuffer *fb,
  2100. int x, int y)
  2101. {
  2102. struct drm_device *dev = crtc->dev;
  2103. struct drm_i915_private *dev_priv = dev->dev_private;
  2104. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2105. struct drm_i915_gem_object *obj;
  2106. int plane = intel_crtc->plane;
  2107. unsigned long linear_offset;
  2108. u32 dspcntr;
  2109. u32 reg = DSPCNTR(plane);
  2110. int pixel_size;
  2111. if (!intel_crtc->primary_enabled) {
  2112. I915_WRITE(reg, 0);
  2113. if (INTEL_INFO(dev)->gen >= 4)
  2114. I915_WRITE(DSPSURF(plane), 0);
  2115. else
  2116. I915_WRITE(DSPADDR(plane), 0);
  2117. POSTING_READ(reg);
  2118. return;
  2119. }
  2120. obj = intel_fb_obj(fb);
  2121. if (WARN_ON(obj == NULL))
  2122. return;
  2123. pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
  2124. dspcntr = DISPPLANE_GAMMA_ENABLE;
  2125. dspcntr |= DISPLAY_PLANE_ENABLE;
  2126. if (INTEL_INFO(dev)->gen < 4) {
  2127. if (intel_crtc->pipe == PIPE_B)
  2128. dspcntr |= DISPPLANE_SEL_PIPE_B;
  2129. /* pipesrc and dspsize control the size that is scaled from,
  2130. * which should always be the user's requested size.
  2131. */
  2132. I915_WRITE(DSPSIZE(plane),
  2133. ((intel_crtc->config.pipe_src_h - 1) << 16) |
  2134. (intel_crtc->config.pipe_src_w - 1));
  2135. I915_WRITE(DSPPOS(plane), 0);
  2136. }
  2137. switch (fb->pixel_format) {
  2138. case DRM_FORMAT_C8:
  2139. dspcntr |= DISPPLANE_8BPP;
  2140. break;
  2141. case DRM_FORMAT_XRGB1555:
  2142. case DRM_FORMAT_ARGB1555:
  2143. dspcntr |= DISPPLANE_BGRX555;
  2144. break;
  2145. case DRM_FORMAT_RGB565:
  2146. dspcntr |= DISPPLANE_BGRX565;
  2147. break;
  2148. case DRM_FORMAT_XRGB8888:
  2149. case DRM_FORMAT_ARGB8888:
  2150. dspcntr |= DISPPLANE_BGRX888;
  2151. break;
  2152. case DRM_FORMAT_XBGR8888:
  2153. case DRM_FORMAT_ABGR8888:
  2154. dspcntr |= DISPPLANE_RGBX888;
  2155. break;
  2156. case DRM_FORMAT_XRGB2101010:
  2157. case DRM_FORMAT_ARGB2101010:
  2158. dspcntr |= DISPPLANE_BGRX101010;
  2159. break;
  2160. case DRM_FORMAT_XBGR2101010:
  2161. case DRM_FORMAT_ABGR2101010:
  2162. dspcntr |= DISPPLANE_RGBX101010;
  2163. break;
  2164. default:
  2165. BUG();
  2166. }
  2167. if (INTEL_INFO(dev)->gen >= 4 &&
  2168. obj->tiling_mode != I915_TILING_NONE)
  2169. dspcntr |= DISPPLANE_TILED;
  2170. if (IS_G4X(dev))
  2171. dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
  2172. linear_offset = y * fb->pitches[0] + x * pixel_size;
  2173. if (INTEL_INFO(dev)->gen >= 4) {
  2174. intel_crtc->dspaddr_offset =
  2175. intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
  2176. pixel_size,
  2177. fb->pitches[0]);
  2178. linear_offset -= intel_crtc->dspaddr_offset;
  2179. } else {
  2180. intel_crtc->dspaddr_offset = linear_offset;
  2181. }
  2182. if (to_intel_plane(crtc->primary)->rotation == BIT(DRM_ROTATE_180)) {
  2183. dspcntr |= DISPPLANE_ROTATE_180;
  2184. x += (intel_crtc->config.pipe_src_w - 1);
  2185. y += (intel_crtc->config.pipe_src_h - 1);
  2186. /* Finding the last pixel of the last line of the display
  2187. data and adding to linear_offset*/
  2188. linear_offset +=
  2189. (intel_crtc->config.pipe_src_h - 1) * fb->pitches[0] +
  2190. (intel_crtc->config.pipe_src_w - 1) * pixel_size;
  2191. }
  2192. I915_WRITE(reg, dspcntr);
  2193. DRM_DEBUG_KMS("Writing base %08lX %08lX %d %d %d\n",
  2194. i915_gem_obj_ggtt_offset(obj), linear_offset, x, y,
  2195. fb->pitches[0]);
  2196. I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]);
  2197. if (INTEL_INFO(dev)->gen >= 4) {
  2198. I915_WRITE(DSPSURF(plane),
  2199. i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset);
  2200. I915_WRITE(DSPTILEOFF(plane), (y << 16) | x);
  2201. I915_WRITE(DSPLINOFF(plane), linear_offset);
  2202. } else
  2203. I915_WRITE(DSPADDR(plane), i915_gem_obj_ggtt_offset(obj) + linear_offset);
  2204. POSTING_READ(reg);
  2205. }
  2206. static void ironlake_update_primary_plane(struct drm_crtc *crtc,
  2207. struct drm_framebuffer *fb,
  2208. int x, int y)
  2209. {
  2210. struct drm_device *dev = crtc->dev;
  2211. struct drm_i915_private *dev_priv = dev->dev_private;
  2212. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2213. struct drm_i915_gem_object *obj;
  2214. int plane = intel_crtc->plane;
  2215. unsigned long linear_offset;
  2216. u32 dspcntr;
  2217. u32 reg = DSPCNTR(plane);
  2218. int pixel_size;
  2219. if (!intel_crtc->primary_enabled) {
  2220. I915_WRITE(reg, 0);
  2221. I915_WRITE(DSPSURF(plane), 0);
  2222. POSTING_READ(reg);
  2223. return;
  2224. }
  2225. obj = intel_fb_obj(fb);
  2226. if (WARN_ON(obj == NULL))
  2227. return;
  2228. pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
  2229. dspcntr = DISPPLANE_GAMMA_ENABLE;
  2230. dspcntr |= DISPLAY_PLANE_ENABLE;
  2231. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  2232. dspcntr |= DISPPLANE_PIPE_CSC_ENABLE;
  2233. switch (fb->pixel_format) {
  2234. case DRM_FORMAT_C8:
  2235. dspcntr |= DISPPLANE_8BPP;
  2236. break;
  2237. case DRM_FORMAT_RGB565:
  2238. dspcntr |= DISPPLANE_BGRX565;
  2239. break;
  2240. case DRM_FORMAT_XRGB8888:
  2241. case DRM_FORMAT_ARGB8888:
  2242. dspcntr |= DISPPLANE_BGRX888;
  2243. break;
  2244. case DRM_FORMAT_XBGR8888:
  2245. case DRM_FORMAT_ABGR8888:
  2246. dspcntr |= DISPPLANE_RGBX888;
  2247. break;
  2248. case DRM_FORMAT_XRGB2101010:
  2249. case DRM_FORMAT_ARGB2101010:
  2250. dspcntr |= DISPPLANE_BGRX101010;
  2251. break;
  2252. case DRM_FORMAT_XBGR2101010:
  2253. case DRM_FORMAT_ABGR2101010:
  2254. dspcntr |= DISPPLANE_RGBX101010;
  2255. break;
  2256. default:
  2257. BUG();
  2258. }
  2259. if (obj->tiling_mode != I915_TILING_NONE)
  2260. dspcntr |= DISPPLANE_TILED;
  2261. if (!IS_HASWELL(dev) && !IS_BROADWELL(dev))
  2262. dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
  2263. linear_offset = y * fb->pitches[0] + x * pixel_size;
  2264. intel_crtc->dspaddr_offset =
  2265. intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
  2266. pixel_size,
  2267. fb->pitches[0]);
  2268. linear_offset -= intel_crtc->dspaddr_offset;
  2269. if (to_intel_plane(crtc->primary)->rotation == BIT(DRM_ROTATE_180)) {
  2270. dspcntr |= DISPPLANE_ROTATE_180;
  2271. if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) {
  2272. x += (intel_crtc->config.pipe_src_w - 1);
  2273. y += (intel_crtc->config.pipe_src_h - 1);
  2274. /* Finding the last pixel of the last line of the display
  2275. data and adding to linear_offset*/
  2276. linear_offset +=
  2277. (intel_crtc->config.pipe_src_h - 1) * fb->pitches[0] +
  2278. (intel_crtc->config.pipe_src_w - 1) * pixel_size;
  2279. }
  2280. }
  2281. I915_WRITE(reg, dspcntr);
  2282. DRM_DEBUG_KMS("Writing base %08lX %08lX %d %d %d\n",
  2283. i915_gem_obj_ggtt_offset(obj), linear_offset, x, y,
  2284. fb->pitches[0]);
  2285. I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]);
  2286. I915_WRITE(DSPSURF(plane),
  2287. i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset);
  2288. if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
  2289. I915_WRITE(DSPOFFSET(plane), (y << 16) | x);
  2290. } else {
  2291. I915_WRITE(DSPTILEOFF(plane), (y << 16) | x);
  2292. I915_WRITE(DSPLINOFF(plane), linear_offset);
  2293. }
  2294. POSTING_READ(reg);
  2295. }
  2296. /* Assume fb object is pinned & idle & fenced and just update base pointers */
  2297. static int
  2298. intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb,
  2299. int x, int y, enum mode_set_atomic state)
  2300. {
  2301. struct drm_device *dev = crtc->dev;
  2302. struct drm_i915_private *dev_priv = dev->dev_private;
  2303. if (dev_priv->display.disable_fbc)
  2304. dev_priv->display.disable_fbc(dev);
  2305. intel_increase_pllclock(dev, to_intel_crtc(crtc)->pipe);
  2306. dev_priv->display.update_primary_plane(crtc, fb, x, y);
  2307. return 0;
  2308. }
  2309. void intel_display_handle_reset(struct drm_device *dev)
  2310. {
  2311. struct drm_i915_private *dev_priv = dev->dev_private;
  2312. struct drm_crtc *crtc;
  2313. /*
  2314. * Flips in the rings have been nuked by the reset,
  2315. * so complete all pending flips so that user space
  2316. * will get its events and not get stuck.
  2317. *
  2318. * Also update the base address of all primary
  2319. * planes to the the last fb to make sure we're
  2320. * showing the correct fb after a reset.
  2321. *
  2322. * Need to make two loops over the crtcs so that we
  2323. * don't try to grab a crtc mutex before the
  2324. * pending_flip_queue really got woken up.
  2325. */
  2326. for_each_crtc(dev, crtc) {
  2327. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2328. enum plane plane = intel_crtc->plane;
  2329. intel_prepare_page_flip(dev, plane);
  2330. intel_finish_page_flip_plane(dev, plane);
  2331. }
  2332. for_each_crtc(dev, crtc) {
  2333. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2334. drm_modeset_lock(&crtc->mutex, NULL);
  2335. /*
  2336. * FIXME: Once we have proper support for primary planes (and
  2337. * disabling them without disabling the entire crtc) allow again
  2338. * a NULL crtc->primary->fb.
  2339. */
  2340. if (intel_crtc->active && crtc->primary->fb)
  2341. dev_priv->display.update_primary_plane(crtc,
  2342. crtc->primary->fb,
  2343. crtc->x,
  2344. crtc->y);
  2345. drm_modeset_unlock(&crtc->mutex);
  2346. }
  2347. }
  2348. static int
  2349. intel_finish_fb(struct drm_framebuffer *old_fb)
  2350. {
  2351. struct drm_i915_gem_object *obj = intel_fb_obj(old_fb);
  2352. struct drm_i915_private *dev_priv = obj->base.dev->dev_private;
  2353. bool was_interruptible = dev_priv->mm.interruptible;
  2354. int ret;
  2355. /* Big Hammer, we also need to ensure that any pending
  2356. * MI_WAIT_FOR_EVENT inside a user batch buffer on the
  2357. * current scanout is retired before unpinning the old
  2358. * framebuffer.
  2359. *
  2360. * This should only fail upon a hung GPU, in which case we
  2361. * can safely continue.
  2362. */
  2363. dev_priv->mm.interruptible = false;
  2364. ret = i915_gem_object_finish_gpu(obj);
  2365. dev_priv->mm.interruptible = was_interruptible;
  2366. return ret;
  2367. }
  2368. static bool intel_crtc_has_pending_flip(struct drm_crtc *crtc)
  2369. {
  2370. struct drm_device *dev = crtc->dev;
  2371. struct drm_i915_private *dev_priv = dev->dev_private;
  2372. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2373. unsigned long flags;
  2374. bool pending;
  2375. if (i915_reset_in_progress(&dev_priv->gpu_error) ||
  2376. intel_crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter))
  2377. return false;
  2378. spin_lock_irqsave(&dev->event_lock, flags);
  2379. pending = to_intel_crtc(crtc)->unpin_work != NULL;
  2380. spin_unlock_irqrestore(&dev->event_lock, flags);
  2381. return pending;
  2382. }
  2383. static int
  2384. intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
  2385. struct drm_framebuffer *fb)
  2386. {
  2387. struct drm_device *dev = crtc->dev;
  2388. struct drm_i915_private *dev_priv = dev->dev_private;
  2389. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2390. enum pipe pipe = intel_crtc->pipe;
  2391. struct drm_framebuffer *old_fb = crtc->primary->fb;
  2392. struct drm_i915_gem_object *obj = intel_fb_obj(fb);
  2393. struct drm_i915_gem_object *old_obj = intel_fb_obj(old_fb);
  2394. int ret;
  2395. if (intel_crtc_has_pending_flip(crtc)) {
  2396. DRM_ERROR("pipe is still busy with an old pageflip\n");
  2397. return -EBUSY;
  2398. }
  2399. /* no fb bound */
  2400. if (!fb) {
  2401. DRM_ERROR("No FB bound\n");
  2402. return 0;
  2403. }
  2404. if (intel_crtc->plane > INTEL_INFO(dev)->num_pipes) {
  2405. DRM_ERROR("no plane for crtc: plane %c, num_pipes %d\n",
  2406. plane_name(intel_crtc->plane),
  2407. INTEL_INFO(dev)->num_pipes);
  2408. return -EINVAL;
  2409. }
  2410. mutex_lock(&dev->struct_mutex);
  2411. ret = intel_pin_and_fence_fb_obj(dev, obj, NULL);
  2412. if (ret == 0)
  2413. i915_gem_track_fb(old_obj, obj,
  2414. INTEL_FRONTBUFFER_PRIMARY(pipe));
  2415. mutex_unlock(&dev->struct_mutex);
  2416. if (ret != 0) {
  2417. DRM_ERROR("pin & fence failed\n");
  2418. return ret;
  2419. }
  2420. /*
  2421. * Update pipe size and adjust fitter if needed: the reason for this is
  2422. * that in compute_mode_changes we check the native mode (not the pfit
  2423. * mode) to see if we can flip rather than do a full mode set. In the
  2424. * fastboot case, we'll flip, but if we don't update the pipesrc and
  2425. * pfit state, we'll end up with a big fb scanned out into the wrong
  2426. * sized surface.
  2427. *
  2428. * To fix this properly, we need to hoist the checks up into
  2429. * compute_mode_changes (or above), check the actual pfit state and
  2430. * whether the platform allows pfit disable with pipe active, and only
  2431. * then update the pipesrc and pfit state, even on the flip path.
  2432. */
  2433. if (i915.fastboot) {
  2434. const struct drm_display_mode *adjusted_mode =
  2435. &intel_crtc->config.adjusted_mode;
  2436. I915_WRITE(PIPESRC(intel_crtc->pipe),
  2437. ((adjusted_mode->crtc_hdisplay - 1) << 16) |
  2438. (adjusted_mode->crtc_vdisplay - 1));
  2439. if (!intel_crtc->config.pch_pfit.enabled &&
  2440. (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) ||
  2441. intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) {
  2442. I915_WRITE(PF_CTL(intel_crtc->pipe), 0);
  2443. I915_WRITE(PF_WIN_POS(intel_crtc->pipe), 0);
  2444. I915_WRITE(PF_WIN_SZ(intel_crtc->pipe), 0);
  2445. }
  2446. intel_crtc->config.pipe_src_w = adjusted_mode->crtc_hdisplay;
  2447. intel_crtc->config.pipe_src_h = adjusted_mode->crtc_vdisplay;
  2448. }
  2449. dev_priv->display.update_primary_plane(crtc, fb, x, y);
  2450. if (intel_crtc->active)
  2451. intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_PRIMARY(pipe));
  2452. crtc->primary->fb = fb;
  2453. crtc->x = x;
  2454. crtc->y = y;
  2455. if (old_fb) {
  2456. if (intel_crtc->active && old_fb != fb)
  2457. intel_wait_for_vblank(dev, intel_crtc->pipe);
  2458. mutex_lock(&dev->struct_mutex);
  2459. intel_unpin_fb_obj(old_obj);
  2460. mutex_unlock(&dev->struct_mutex);
  2461. }
  2462. mutex_lock(&dev->struct_mutex);
  2463. intel_update_fbc(dev);
  2464. mutex_unlock(&dev->struct_mutex);
  2465. return 0;
  2466. }
  2467. static void intel_fdi_normal_train(struct drm_crtc *crtc)
  2468. {
  2469. struct drm_device *dev = crtc->dev;
  2470. struct drm_i915_private *dev_priv = dev->dev_private;
  2471. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2472. int pipe = intel_crtc->pipe;
  2473. u32 reg, temp;
  2474. /* enable normal train */
  2475. reg = FDI_TX_CTL(pipe);
  2476. temp = I915_READ(reg);
  2477. if (IS_IVYBRIDGE(dev)) {
  2478. temp &= ~FDI_LINK_TRAIN_NONE_IVB;
  2479. temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE;
  2480. } else {
  2481. temp &= ~FDI_LINK_TRAIN_NONE;
  2482. temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
  2483. }
  2484. I915_WRITE(reg, temp);
  2485. reg = FDI_RX_CTL(pipe);
  2486. temp = I915_READ(reg);
  2487. if (HAS_PCH_CPT(dev)) {
  2488. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2489. temp |= FDI_LINK_TRAIN_NORMAL_CPT;
  2490. } else {
  2491. temp &= ~FDI_LINK_TRAIN_NONE;
  2492. temp |= FDI_LINK_TRAIN_NONE;
  2493. }
  2494. I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
  2495. /* wait one idle pattern time */
  2496. POSTING_READ(reg);
  2497. udelay(1000);
  2498. /* IVB wants error correction enabled */
  2499. if (IS_IVYBRIDGE(dev))
  2500. I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE |
  2501. FDI_FE_ERRC_ENABLE);
  2502. }
  2503. static bool pipe_has_enabled_pch(struct intel_crtc *crtc)
  2504. {
  2505. return crtc->base.enabled && crtc->active &&
  2506. crtc->config.has_pch_encoder;
  2507. }
  2508. static void ivb_modeset_global_resources(struct drm_device *dev)
  2509. {
  2510. struct drm_i915_private *dev_priv = dev->dev_private;
  2511. struct intel_crtc *pipe_B_crtc =
  2512. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_B]);
  2513. struct intel_crtc *pipe_C_crtc =
  2514. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_C]);
  2515. uint32_t temp;
  2516. /*
  2517. * When everything is off disable fdi C so that we could enable fdi B
  2518. * with all lanes. Note that we don't care about enabled pipes without
  2519. * an enabled pch encoder.
  2520. */
  2521. if (!pipe_has_enabled_pch(pipe_B_crtc) &&
  2522. !pipe_has_enabled_pch(pipe_C_crtc)) {
  2523. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
  2524. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
  2525. temp = I915_READ(SOUTH_CHICKEN1);
  2526. temp &= ~FDI_BC_BIFURCATION_SELECT;
  2527. DRM_DEBUG_KMS("disabling fdi C rx\n");
  2528. I915_WRITE(SOUTH_CHICKEN1, temp);
  2529. }
  2530. }
  2531. /* The FDI link training functions for ILK/Ibexpeak. */
  2532. static void ironlake_fdi_link_train(struct drm_crtc *crtc)
  2533. {
  2534. struct drm_device *dev = crtc->dev;
  2535. struct drm_i915_private *dev_priv = dev->dev_private;
  2536. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2537. int pipe = intel_crtc->pipe;
  2538. u32 reg, temp, tries;
  2539. /* FDI needs bits from pipe first */
  2540. assert_pipe_enabled(dev_priv, pipe);
  2541. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  2542. for train result */
  2543. reg = FDI_RX_IMR(pipe);
  2544. temp = I915_READ(reg);
  2545. temp &= ~FDI_RX_SYMBOL_LOCK;
  2546. temp &= ~FDI_RX_BIT_LOCK;
  2547. I915_WRITE(reg, temp);
  2548. I915_READ(reg);
  2549. udelay(150);
  2550. /* enable CPU FDI TX and PCH FDI RX */
  2551. reg = FDI_TX_CTL(pipe);
  2552. temp = I915_READ(reg);
  2553. temp &= ~FDI_DP_PORT_WIDTH_MASK;
  2554. temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes);
  2555. temp &= ~FDI_LINK_TRAIN_NONE;
  2556. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2557. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  2558. reg = FDI_RX_CTL(pipe);
  2559. temp = I915_READ(reg);
  2560. temp &= ~FDI_LINK_TRAIN_NONE;
  2561. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2562. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  2563. POSTING_READ(reg);
  2564. udelay(150);
  2565. /* Ironlake workaround, enable clock pointer after FDI enable*/
  2566. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
  2567. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR |
  2568. FDI_RX_PHASE_SYNC_POINTER_EN);
  2569. reg = FDI_RX_IIR(pipe);
  2570. for (tries = 0; tries < 5; tries++) {
  2571. temp = I915_READ(reg);
  2572. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2573. if ((temp & FDI_RX_BIT_LOCK)) {
  2574. DRM_DEBUG_KMS("FDI train 1 done.\n");
  2575. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  2576. break;
  2577. }
  2578. }
  2579. if (tries == 5)
  2580. DRM_ERROR("FDI train 1 fail!\n");
  2581. /* Train 2 */
  2582. reg = FDI_TX_CTL(pipe);
  2583. temp = I915_READ(reg);
  2584. temp &= ~FDI_LINK_TRAIN_NONE;
  2585. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2586. I915_WRITE(reg, temp);
  2587. reg = FDI_RX_CTL(pipe);
  2588. temp = I915_READ(reg);
  2589. temp &= ~FDI_LINK_TRAIN_NONE;
  2590. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2591. I915_WRITE(reg, temp);
  2592. POSTING_READ(reg);
  2593. udelay(150);
  2594. reg = FDI_RX_IIR(pipe);
  2595. for (tries = 0; tries < 5; tries++) {
  2596. temp = I915_READ(reg);
  2597. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2598. if (temp & FDI_RX_SYMBOL_LOCK) {
  2599. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  2600. DRM_DEBUG_KMS("FDI train 2 done.\n");
  2601. break;
  2602. }
  2603. }
  2604. if (tries == 5)
  2605. DRM_ERROR("FDI train 2 fail!\n");
  2606. DRM_DEBUG_KMS("FDI train done\n");
  2607. }
  2608. static const int snb_b_fdi_train_param[] = {
  2609. FDI_LINK_TRAIN_400MV_0DB_SNB_B,
  2610. FDI_LINK_TRAIN_400MV_6DB_SNB_B,
  2611. FDI_LINK_TRAIN_600MV_3_5DB_SNB_B,
  2612. FDI_LINK_TRAIN_800MV_0DB_SNB_B,
  2613. };
  2614. /* The FDI link training functions for SNB/Cougarpoint. */
  2615. static void gen6_fdi_link_train(struct drm_crtc *crtc)
  2616. {
  2617. struct drm_device *dev = crtc->dev;
  2618. struct drm_i915_private *dev_priv = dev->dev_private;
  2619. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2620. int pipe = intel_crtc->pipe;
  2621. u32 reg, temp, i, retry;
  2622. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  2623. for train result */
  2624. reg = FDI_RX_IMR(pipe);
  2625. temp = I915_READ(reg);
  2626. temp &= ~FDI_RX_SYMBOL_LOCK;
  2627. temp &= ~FDI_RX_BIT_LOCK;
  2628. I915_WRITE(reg, temp);
  2629. POSTING_READ(reg);
  2630. udelay(150);
  2631. /* enable CPU FDI TX and PCH FDI RX */
  2632. reg = FDI_TX_CTL(pipe);
  2633. temp = I915_READ(reg);
  2634. temp &= ~FDI_DP_PORT_WIDTH_MASK;
  2635. temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes);
  2636. temp &= ~FDI_LINK_TRAIN_NONE;
  2637. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2638. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2639. /* SNB-B */
  2640. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  2641. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  2642. I915_WRITE(FDI_RX_MISC(pipe),
  2643. FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
  2644. reg = FDI_RX_CTL(pipe);
  2645. temp = I915_READ(reg);
  2646. if (HAS_PCH_CPT(dev)) {
  2647. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2648. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2649. } else {
  2650. temp &= ~FDI_LINK_TRAIN_NONE;
  2651. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2652. }
  2653. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  2654. POSTING_READ(reg);
  2655. udelay(150);
  2656. for (i = 0; i < 4; i++) {
  2657. reg = FDI_TX_CTL(pipe);
  2658. temp = I915_READ(reg);
  2659. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2660. temp |= snb_b_fdi_train_param[i];
  2661. I915_WRITE(reg, temp);
  2662. POSTING_READ(reg);
  2663. udelay(500);
  2664. for (retry = 0; retry < 5; retry++) {
  2665. reg = FDI_RX_IIR(pipe);
  2666. temp = I915_READ(reg);
  2667. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2668. if (temp & FDI_RX_BIT_LOCK) {
  2669. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  2670. DRM_DEBUG_KMS("FDI train 1 done.\n");
  2671. break;
  2672. }
  2673. udelay(50);
  2674. }
  2675. if (retry < 5)
  2676. break;
  2677. }
  2678. if (i == 4)
  2679. DRM_ERROR("FDI train 1 fail!\n");
  2680. /* Train 2 */
  2681. reg = FDI_TX_CTL(pipe);
  2682. temp = I915_READ(reg);
  2683. temp &= ~FDI_LINK_TRAIN_NONE;
  2684. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2685. if (IS_GEN6(dev)) {
  2686. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2687. /* SNB-B */
  2688. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  2689. }
  2690. I915_WRITE(reg, temp);
  2691. reg = FDI_RX_CTL(pipe);
  2692. temp = I915_READ(reg);
  2693. if (HAS_PCH_CPT(dev)) {
  2694. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2695. temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
  2696. } else {
  2697. temp &= ~FDI_LINK_TRAIN_NONE;
  2698. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2699. }
  2700. I915_WRITE(reg, temp);
  2701. POSTING_READ(reg);
  2702. udelay(150);
  2703. for (i = 0; i < 4; i++) {
  2704. reg = FDI_TX_CTL(pipe);
  2705. temp = I915_READ(reg);
  2706. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2707. temp |= snb_b_fdi_train_param[i];
  2708. I915_WRITE(reg, temp);
  2709. POSTING_READ(reg);
  2710. udelay(500);
  2711. for (retry = 0; retry < 5; retry++) {
  2712. reg = FDI_RX_IIR(pipe);
  2713. temp = I915_READ(reg);
  2714. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2715. if (temp & FDI_RX_SYMBOL_LOCK) {
  2716. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  2717. DRM_DEBUG_KMS("FDI train 2 done.\n");
  2718. break;
  2719. }
  2720. udelay(50);
  2721. }
  2722. if (retry < 5)
  2723. break;
  2724. }
  2725. if (i == 4)
  2726. DRM_ERROR("FDI train 2 fail!\n");
  2727. DRM_DEBUG_KMS("FDI train done.\n");
  2728. }
  2729. /* Manual link training for Ivy Bridge A0 parts */
  2730. static void ivb_manual_fdi_link_train(struct drm_crtc *crtc)
  2731. {
  2732. struct drm_device *dev = crtc->dev;
  2733. struct drm_i915_private *dev_priv = dev->dev_private;
  2734. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2735. int pipe = intel_crtc->pipe;
  2736. u32 reg, temp, i, j;
  2737. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  2738. for train result */
  2739. reg = FDI_RX_IMR(pipe);
  2740. temp = I915_READ(reg);
  2741. temp &= ~FDI_RX_SYMBOL_LOCK;
  2742. temp &= ~FDI_RX_BIT_LOCK;
  2743. I915_WRITE(reg, temp);
  2744. POSTING_READ(reg);
  2745. udelay(150);
  2746. DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
  2747. I915_READ(FDI_RX_IIR(pipe)));
  2748. /* Try each vswing and preemphasis setting twice before moving on */
  2749. for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) {
  2750. /* disable first in case we need to retry */
  2751. reg = FDI_TX_CTL(pipe);
  2752. temp = I915_READ(reg);
  2753. temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB);
  2754. temp &= ~FDI_TX_ENABLE;
  2755. I915_WRITE(reg, temp);
  2756. reg = FDI_RX_CTL(pipe);
  2757. temp = I915_READ(reg);
  2758. temp &= ~FDI_LINK_TRAIN_AUTO;
  2759. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2760. temp &= ~FDI_RX_ENABLE;
  2761. I915_WRITE(reg, temp);
  2762. /* enable CPU FDI TX and PCH FDI RX */
  2763. reg = FDI_TX_CTL(pipe);
  2764. temp = I915_READ(reg);
  2765. temp &= ~FDI_DP_PORT_WIDTH_MASK;
  2766. temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes);
  2767. temp |= FDI_LINK_TRAIN_PATTERN_1_IVB;
  2768. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2769. temp |= snb_b_fdi_train_param[j/2];
  2770. temp |= FDI_COMPOSITE_SYNC;
  2771. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  2772. I915_WRITE(FDI_RX_MISC(pipe),
  2773. FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
  2774. reg = FDI_RX_CTL(pipe);
  2775. temp = I915_READ(reg);
  2776. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2777. temp |= FDI_COMPOSITE_SYNC;
  2778. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  2779. POSTING_READ(reg);
  2780. udelay(1); /* should be 0.5us */
  2781. for (i = 0; i < 4; i++) {
  2782. reg = FDI_RX_IIR(pipe);
  2783. temp = I915_READ(reg);
  2784. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2785. if (temp & FDI_RX_BIT_LOCK ||
  2786. (I915_READ(reg) & FDI_RX_BIT_LOCK)) {
  2787. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  2788. DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
  2789. i);
  2790. break;
  2791. }
  2792. udelay(1); /* should be 0.5us */
  2793. }
  2794. if (i == 4) {
  2795. DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2);
  2796. continue;
  2797. }
  2798. /* Train 2 */
  2799. reg = FDI_TX_CTL(pipe);
  2800. temp = I915_READ(reg);
  2801. temp &= ~FDI_LINK_TRAIN_NONE_IVB;
  2802. temp |= FDI_LINK_TRAIN_PATTERN_2_IVB;
  2803. I915_WRITE(reg, temp);
  2804. reg = FDI_RX_CTL(pipe);
  2805. temp = I915_READ(reg);
  2806. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2807. temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
  2808. I915_WRITE(reg, temp);
  2809. POSTING_READ(reg);
  2810. udelay(2); /* should be 1.5us */
  2811. for (i = 0; i < 4; i++) {
  2812. reg = FDI_RX_IIR(pipe);
  2813. temp = I915_READ(reg);
  2814. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2815. if (temp & FDI_RX_SYMBOL_LOCK ||
  2816. (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) {
  2817. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  2818. DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
  2819. i);
  2820. goto train_done;
  2821. }
  2822. udelay(2); /* should be 1.5us */
  2823. }
  2824. if (i == 4)
  2825. DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j / 2);
  2826. }
  2827. train_done:
  2828. DRM_DEBUG_KMS("FDI train done.\n");
  2829. }
  2830. static void ironlake_fdi_pll_enable(struct intel_crtc *intel_crtc)
  2831. {
  2832. struct drm_device *dev = intel_crtc->base.dev;
  2833. struct drm_i915_private *dev_priv = dev->dev_private;
  2834. int pipe = intel_crtc->pipe;
  2835. u32 reg, temp;
  2836. /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
  2837. reg = FDI_RX_CTL(pipe);
  2838. temp = I915_READ(reg);
  2839. temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16));
  2840. temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes);
  2841. temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
  2842. I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE);
  2843. POSTING_READ(reg);
  2844. udelay(200);
  2845. /* Switch from Rawclk to PCDclk */
  2846. temp = I915_READ(reg);
  2847. I915_WRITE(reg, temp | FDI_PCDCLK);
  2848. POSTING_READ(reg);
  2849. udelay(200);
  2850. /* Enable CPU FDI TX PLL, always on for Ironlake */
  2851. reg = FDI_TX_CTL(pipe);
  2852. temp = I915_READ(reg);
  2853. if ((temp & FDI_TX_PLL_ENABLE) == 0) {
  2854. I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE);
  2855. POSTING_READ(reg);
  2856. udelay(100);
  2857. }
  2858. }
  2859. static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc)
  2860. {
  2861. struct drm_device *dev = intel_crtc->base.dev;
  2862. struct drm_i915_private *dev_priv = dev->dev_private;
  2863. int pipe = intel_crtc->pipe;
  2864. u32 reg, temp;
  2865. /* Switch from PCDclk to Rawclk */
  2866. reg = FDI_RX_CTL(pipe);
  2867. temp = I915_READ(reg);
  2868. I915_WRITE(reg, temp & ~FDI_PCDCLK);
  2869. /* Disable CPU FDI TX PLL */
  2870. reg = FDI_TX_CTL(pipe);
  2871. temp = I915_READ(reg);
  2872. I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE);
  2873. POSTING_READ(reg);
  2874. udelay(100);
  2875. reg = FDI_RX_CTL(pipe);
  2876. temp = I915_READ(reg);
  2877. I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE);
  2878. /* Wait for the clocks to turn off. */
  2879. POSTING_READ(reg);
  2880. udelay(100);
  2881. }
  2882. static void ironlake_fdi_disable(struct drm_crtc *crtc)
  2883. {
  2884. struct drm_device *dev = crtc->dev;
  2885. struct drm_i915_private *dev_priv = dev->dev_private;
  2886. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2887. int pipe = intel_crtc->pipe;
  2888. u32 reg, temp;
  2889. /* disable CPU FDI tx and PCH FDI rx */
  2890. reg = FDI_TX_CTL(pipe);
  2891. temp = I915_READ(reg);
  2892. I915_WRITE(reg, temp & ~FDI_TX_ENABLE);
  2893. POSTING_READ(reg);
  2894. reg = FDI_RX_CTL(pipe);
  2895. temp = I915_READ(reg);
  2896. temp &= ~(0x7 << 16);
  2897. temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
  2898. I915_WRITE(reg, temp & ~FDI_RX_ENABLE);
  2899. POSTING_READ(reg);
  2900. udelay(100);
  2901. /* Ironlake workaround, disable clock pointer after downing FDI */
  2902. if (HAS_PCH_IBX(dev))
  2903. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
  2904. /* still set train pattern 1 */
  2905. reg = FDI_TX_CTL(pipe);
  2906. temp = I915_READ(reg);
  2907. temp &= ~FDI_LINK_TRAIN_NONE;
  2908. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2909. I915_WRITE(reg, temp);
  2910. reg = FDI_RX_CTL(pipe);
  2911. temp = I915_READ(reg);
  2912. if (HAS_PCH_CPT(dev)) {
  2913. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2914. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2915. } else {
  2916. temp &= ~FDI_LINK_TRAIN_NONE;
  2917. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2918. }
  2919. /* BPC in FDI rx is consistent with that in PIPECONF */
  2920. temp &= ~(0x07 << 16);
  2921. temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
  2922. I915_WRITE(reg, temp);
  2923. POSTING_READ(reg);
  2924. udelay(100);
  2925. }
  2926. bool intel_has_pending_fb_unpin(struct drm_device *dev)
  2927. {
  2928. struct intel_crtc *crtc;
  2929. /* Note that we don't need to be called with mode_config.lock here
  2930. * as our list of CRTC objects is static for the lifetime of the
  2931. * device and so cannot disappear as we iterate. Similarly, we can
  2932. * happily treat the predicates as racy, atomic checks as userspace
  2933. * cannot claim and pin a new fb without at least acquring the
  2934. * struct_mutex and so serialising with us.
  2935. */
  2936. for_each_intel_crtc(dev, crtc) {
  2937. if (atomic_read(&crtc->unpin_work_count) == 0)
  2938. continue;
  2939. if (crtc->unpin_work)
  2940. intel_wait_for_vblank(dev, crtc->pipe);
  2941. return true;
  2942. }
  2943. return false;
  2944. }
  2945. static void page_flip_completed(struct intel_crtc *intel_crtc)
  2946. {
  2947. struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
  2948. struct intel_unpin_work *work = intel_crtc->unpin_work;
  2949. /* ensure that the unpin work is consistent wrt ->pending. */
  2950. smp_rmb();
  2951. intel_crtc->unpin_work = NULL;
  2952. if (work->event)
  2953. drm_send_vblank_event(intel_crtc->base.dev,
  2954. intel_crtc->pipe,
  2955. work->event);
  2956. drm_crtc_vblank_put(&intel_crtc->base);
  2957. wake_up_all(&dev_priv->pending_flip_queue);
  2958. queue_work(dev_priv->wq, &work->work);
  2959. trace_i915_flip_complete(intel_crtc->plane,
  2960. work->pending_flip_obj);
  2961. }
  2962. void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
  2963. {
  2964. struct drm_device *dev = crtc->dev;
  2965. struct drm_i915_private *dev_priv = dev->dev_private;
  2966. WARN_ON(waitqueue_active(&dev_priv->pending_flip_queue));
  2967. if (WARN_ON(wait_event_timeout(dev_priv->pending_flip_queue,
  2968. !intel_crtc_has_pending_flip(crtc),
  2969. 60*HZ) == 0)) {
  2970. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2971. unsigned long flags;
  2972. spin_lock_irqsave(&dev->event_lock, flags);
  2973. if (intel_crtc->unpin_work) {
  2974. WARN_ONCE(1, "Removing stuck page flip\n");
  2975. page_flip_completed(intel_crtc);
  2976. }
  2977. spin_unlock_irqrestore(&dev->event_lock, flags);
  2978. }
  2979. if (crtc->primary->fb) {
  2980. mutex_lock(&dev->struct_mutex);
  2981. intel_finish_fb(crtc->primary->fb);
  2982. mutex_unlock(&dev->struct_mutex);
  2983. }
  2984. }
  2985. /* Program iCLKIP clock to the desired frequency */
  2986. static void lpt_program_iclkip(struct drm_crtc *crtc)
  2987. {
  2988. struct drm_device *dev = crtc->dev;
  2989. struct drm_i915_private *dev_priv = dev->dev_private;
  2990. int clock = to_intel_crtc(crtc)->config.adjusted_mode.crtc_clock;
  2991. u32 divsel, phaseinc, auxdiv, phasedir = 0;
  2992. u32 temp;
  2993. mutex_lock(&dev_priv->dpio_lock);
  2994. /* It is necessary to ungate the pixclk gate prior to programming
  2995. * the divisors, and gate it back when it is done.
  2996. */
  2997. I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE);
  2998. /* Disable SSCCTL */
  2999. intel_sbi_write(dev_priv, SBI_SSCCTL6,
  3000. intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK) |
  3001. SBI_SSCCTL_DISABLE,
  3002. SBI_ICLK);
  3003. /* 20MHz is a corner case which is out of range for the 7-bit divisor */
  3004. if (clock == 20000) {
  3005. auxdiv = 1;
  3006. divsel = 0x41;
  3007. phaseinc = 0x20;
  3008. } else {
  3009. /* The iCLK virtual clock root frequency is in MHz,
  3010. * but the adjusted_mode->crtc_clock in in KHz. To get the
  3011. * divisors, it is necessary to divide one by another, so we
  3012. * convert the virtual clock precision to KHz here for higher
  3013. * precision.
  3014. */
  3015. u32 iclk_virtual_root_freq = 172800 * 1000;
  3016. u32 iclk_pi_range = 64;
  3017. u32 desired_divisor, msb_divisor_value, pi_value;
  3018. desired_divisor = (iclk_virtual_root_freq / clock);
  3019. msb_divisor_value = desired_divisor / iclk_pi_range;
  3020. pi_value = desired_divisor % iclk_pi_range;
  3021. auxdiv = 0;
  3022. divsel = msb_divisor_value - 2;
  3023. phaseinc = pi_value;
  3024. }
  3025. /* This should not happen with any sane values */
  3026. WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) &
  3027. ~SBI_SSCDIVINTPHASE_DIVSEL_MASK);
  3028. WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) &
  3029. ~SBI_SSCDIVINTPHASE_INCVAL_MASK);
  3030. DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
  3031. clock,
  3032. auxdiv,
  3033. divsel,
  3034. phasedir,
  3035. phaseinc);
  3036. /* Program SSCDIVINTPHASE6 */
  3037. temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
  3038. temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK;
  3039. temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel);
  3040. temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK;
  3041. temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc);
  3042. temp |= SBI_SSCDIVINTPHASE_DIR(phasedir);
  3043. temp |= SBI_SSCDIVINTPHASE_PROPAGATE;
  3044. intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK);
  3045. /* Program SSCAUXDIV */
  3046. temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
  3047. temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
  3048. temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv);
  3049. intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK);
  3050. /* Enable modulator and associated divider */
  3051. temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
  3052. temp &= ~SBI_SSCCTL_DISABLE;
  3053. intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
  3054. /* Wait for initialization time */
  3055. udelay(24);
  3056. I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE);
  3057. mutex_unlock(&dev_priv->dpio_lock);
  3058. }
  3059. static void ironlake_pch_transcoder_set_timings(struct intel_crtc *crtc,
  3060. enum pipe pch_transcoder)
  3061. {
  3062. struct drm_device *dev = crtc->base.dev;
  3063. struct drm_i915_private *dev_priv = dev->dev_private;
  3064. enum transcoder cpu_transcoder = crtc->config.cpu_transcoder;
  3065. I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder),
  3066. I915_READ(HTOTAL(cpu_transcoder)));
  3067. I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder),
  3068. I915_READ(HBLANK(cpu_transcoder)));
  3069. I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder),
  3070. I915_READ(HSYNC(cpu_transcoder)));
  3071. I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder),
  3072. I915_READ(VTOTAL(cpu_transcoder)));
  3073. I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder),
  3074. I915_READ(VBLANK(cpu_transcoder)));
  3075. I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder),
  3076. I915_READ(VSYNC(cpu_transcoder)));
  3077. I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder),
  3078. I915_READ(VSYNCSHIFT(cpu_transcoder)));
  3079. }
  3080. static void cpt_enable_fdi_bc_bifurcation(struct drm_device *dev)
  3081. {
  3082. struct drm_i915_private *dev_priv = dev->dev_private;
  3083. uint32_t temp;
  3084. temp = I915_READ(SOUTH_CHICKEN1);
  3085. if (temp & FDI_BC_BIFURCATION_SELECT)
  3086. return;
  3087. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
  3088. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
  3089. temp |= FDI_BC_BIFURCATION_SELECT;
  3090. DRM_DEBUG_KMS("enabling fdi C rx\n");
  3091. I915_WRITE(SOUTH_CHICKEN1, temp);
  3092. POSTING_READ(SOUTH_CHICKEN1);
  3093. }
  3094. static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc *intel_crtc)
  3095. {
  3096. struct drm_device *dev = intel_crtc->base.dev;
  3097. struct drm_i915_private *dev_priv = dev->dev_private;
  3098. switch (intel_crtc->pipe) {
  3099. case PIPE_A:
  3100. break;
  3101. case PIPE_B:
  3102. if (intel_crtc->config.fdi_lanes > 2)
  3103. WARN_ON(I915_READ(SOUTH_CHICKEN1) & FDI_BC_BIFURCATION_SELECT);
  3104. else
  3105. cpt_enable_fdi_bc_bifurcation(dev);
  3106. break;
  3107. case PIPE_C:
  3108. cpt_enable_fdi_bc_bifurcation(dev);
  3109. break;
  3110. default:
  3111. BUG();
  3112. }
  3113. }
  3114. /*
  3115. * Enable PCH resources required for PCH ports:
  3116. * - PCH PLLs
  3117. * - FDI training & RX/TX
  3118. * - update transcoder timings
  3119. * - DP transcoding bits
  3120. * - transcoder
  3121. */
  3122. static void ironlake_pch_enable(struct drm_crtc *crtc)
  3123. {
  3124. struct drm_device *dev = crtc->dev;
  3125. struct drm_i915_private *dev_priv = dev->dev_private;
  3126. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3127. int pipe = intel_crtc->pipe;
  3128. u32 reg, temp;
  3129. assert_pch_transcoder_disabled(dev_priv, pipe);
  3130. if (IS_IVYBRIDGE(dev))
  3131. ivybridge_update_fdi_bc_bifurcation(intel_crtc);
  3132. /* Write the TU size bits before fdi link training, so that error
  3133. * detection works. */
  3134. I915_WRITE(FDI_RX_TUSIZE1(pipe),
  3135. I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
  3136. /* For PCH output, training FDI link */
  3137. dev_priv->display.fdi_link_train(crtc);
  3138. /* We need to program the right clock selection before writing the pixel
  3139. * mutliplier into the DPLL. */
  3140. if (HAS_PCH_CPT(dev)) {
  3141. u32 sel;
  3142. temp = I915_READ(PCH_DPLL_SEL);
  3143. temp |= TRANS_DPLL_ENABLE(pipe);
  3144. sel = TRANS_DPLLB_SEL(pipe);
  3145. if (intel_crtc->config.shared_dpll == DPLL_ID_PCH_PLL_B)
  3146. temp |= sel;
  3147. else
  3148. temp &= ~sel;
  3149. I915_WRITE(PCH_DPLL_SEL, temp);
  3150. }
  3151. /* XXX: pch pll's can be enabled any time before we enable the PCH
  3152. * transcoder, and we actually should do this to not upset any PCH
  3153. * transcoder that already use the clock when we share it.
  3154. *
  3155. * Note that enable_shared_dpll tries to do the right thing, but
  3156. * get_shared_dpll unconditionally resets the pll - we need that to have
  3157. * the right LVDS enable sequence. */
  3158. intel_enable_shared_dpll(intel_crtc);
  3159. /* set transcoder timing, panel must allow it */
  3160. assert_panel_unlocked(dev_priv, pipe);
  3161. ironlake_pch_transcoder_set_timings(intel_crtc, pipe);
  3162. intel_fdi_normal_train(crtc);
  3163. /* For PCH DP, enable TRANS_DP_CTL */
  3164. if (HAS_PCH_CPT(dev) &&
  3165. (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) ||
  3166. intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) {
  3167. u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5;
  3168. reg = TRANS_DP_CTL(pipe);
  3169. temp = I915_READ(reg);
  3170. temp &= ~(TRANS_DP_PORT_SEL_MASK |
  3171. TRANS_DP_SYNC_MASK |
  3172. TRANS_DP_BPC_MASK);
  3173. temp |= (TRANS_DP_OUTPUT_ENABLE |
  3174. TRANS_DP_ENH_FRAMING);
  3175. temp |= bpc << 9; /* same format but at 11:9 */
  3176. if (crtc->mode.flags & DRM_MODE_FLAG_PHSYNC)
  3177. temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
  3178. if (crtc->mode.flags & DRM_MODE_FLAG_PVSYNC)
  3179. temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
  3180. switch (intel_trans_dp_port_sel(crtc)) {
  3181. case PCH_DP_B:
  3182. temp |= TRANS_DP_PORT_SEL_B;
  3183. break;
  3184. case PCH_DP_C:
  3185. temp |= TRANS_DP_PORT_SEL_C;
  3186. break;
  3187. case PCH_DP_D:
  3188. temp |= TRANS_DP_PORT_SEL_D;
  3189. break;
  3190. default:
  3191. BUG();
  3192. }
  3193. I915_WRITE(reg, temp);
  3194. }
  3195. ironlake_enable_pch_transcoder(dev_priv, pipe);
  3196. }
  3197. static void lpt_pch_enable(struct drm_crtc *crtc)
  3198. {
  3199. struct drm_device *dev = crtc->dev;
  3200. struct drm_i915_private *dev_priv = dev->dev_private;
  3201. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3202. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  3203. assert_pch_transcoder_disabled(dev_priv, TRANSCODER_A);
  3204. lpt_program_iclkip(crtc);
  3205. /* Set transcoder timing. */
  3206. ironlake_pch_transcoder_set_timings(intel_crtc, PIPE_A);
  3207. lpt_enable_pch_transcoder(dev_priv, cpu_transcoder);
  3208. }
  3209. void intel_put_shared_dpll(struct intel_crtc *crtc)
  3210. {
  3211. struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
  3212. if (pll == NULL)
  3213. return;
  3214. if (pll->refcount == 0) {
  3215. WARN(1, "bad %s refcount\n", pll->name);
  3216. return;
  3217. }
  3218. if (--pll->refcount == 0) {
  3219. WARN_ON(pll->on);
  3220. WARN_ON(pll->active);
  3221. }
  3222. crtc->config.shared_dpll = DPLL_ID_PRIVATE;
  3223. }
  3224. struct intel_shared_dpll *intel_get_shared_dpll(struct intel_crtc *crtc)
  3225. {
  3226. struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
  3227. struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
  3228. enum intel_dpll_id i;
  3229. if (pll) {
  3230. DRM_DEBUG_KMS("CRTC:%d dropping existing %s\n",
  3231. crtc->base.base.id, pll->name);
  3232. intel_put_shared_dpll(crtc);
  3233. }
  3234. if (HAS_PCH_IBX(dev_priv->dev)) {
  3235. /* Ironlake PCH has a fixed PLL->PCH pipe mapping. */
  3236. i = (enum intel_dpll_id) crtc->pipe;
  3237. pll = &dev_priv->shared_dplls[i];
  3238. DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n",
  3239. crtc->base.base.id, pll->name);
  3240. WARN_ON(pll->refcount);
  3241. goto found;
  3242. }
  3243. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  3244. pll = &dev_priv->shared_dplls[i];
  3245. /* Only want to check enabled timings first */
  3246. if (pll->refcount == 0)
  3247. continue;
  3248. if (memcmp(&crtc->config.dpll_hw_state, &pll->hw_state,
  3249. sizeof(pll->hw_state)) == 0) {
  3250. DRM_DEBUG_KMS("CRTC:%d sharing existing %s (refcount %d, ative %d)\n",
  3251. crtc->base.base.id,
  3252. pll->name, pll->refcount, pll->active);
  3253. goto found;
  3254. }
  3255. }
  3256. /* Ok no matching timings, maybe there's a free one? */
  3257. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  3258. pll = &dev_priv->shared_dplls[i];
  3259. if (pll->refcount == 0) {
  3260. DRM_DEBUG_KMS("CRTC:%d allocated %s\n",
  3261. crtc->base.base.id, pll->name);
  3262. goto found;
  3263. }
  3264. }
  3265. return NULL;
  3266. found:
  3267. if (pll->refcount == 0)
  3268. pll->hw_state = crtc->config.dpll_hw_state;
  3269. crtc->config.shared_dpll = i;
  3270. DRM_DEBUG_DRIVER("using %s for pipe %c\n", pll->name,
  3271. pipe_name(crtc->pipe));
  3272. pll->refcount++;
  3273. return pll;
  3274. }
  3275. static void cpt_verify_modeset(struct drm_device *dev, int pipe)
  3276. {
  3277. struct drm_i915_private *dev_priv = dev->dev_private;
  3278. int dslreg = PIPEDSL(pipe);
  3279. u32 temp;
  3280. temp = I915_READ(dslreg);
  3281. udelay(500);
  3282. if (wait_for(I915_READ(dslreg) != temp, 5)) {
  3283. if (wait_for(I915_READ(dslreg) != temp, 5))
  3284. DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe));
  3285. }
  3286. }
  3287. static void ironlake_pfit_enable(struct intel_crtc *crtc)
  3288. {
  3289. struct drm_device *dev = crtc->base.dev;
  3290. struct drm_i915_private *dev_priv = dev->dev_private;
  3291. int pipe = crtc->pipe;
  3292. if (crtc->config.pch_pfit.enabled) {
  3293. /* Force use of hard-coded filter coefficients
  3294. * as some pre-programmed values are broken,
  3295. * e.g. x201.
  3296. */
  3297. if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev))
  3298. I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 |
  3299. PF_PIPE_SEL_IVB(pipe));
  3300. else
  3301. I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3);
  3302. I915_WRITE(PF_WIN_POS(pipe), crtc->config.pch_pfit.pos);
  3303. I915_WRITE(PF_WIN_SZ(pipe), crtc->config.pch_pfit.size);
  3304. }
  3305. }
  3306. static void intel_enable_planes(struct drm_crtc *crtc)
  3307. {
  3308. struct drm_device *dev = crtc->dev;
  3309. enum pipe pipe = to_intel_crtc(crtc)->pipe;
  3310. struct drm_plane *plane;
  3311. struct intel_plane *intel_plane;
  3312. drm_for_each_legacy_plane(plane, &dev->mode_config.plane_list) {
  3313. intel_plane = to_intel_plane(plane);
  3314. if (intel_plane->pipe == pipe)
  3315. intel_plane_restore(&intel_plane->base);
  3316. }
  3317. }
  3318. static void intel_disable_planes(struct drm_crtc *crtc)
  3319. {
  3320. struct drm_device *dev = crtc->dev;
  3321. enum pipe pipe = to_intel_crtc(crtc)->pipe;
  3322. struct drm_plane *plane;
  3323. struct intel_plane *intel_plane;
  3324. drm_for_each_legacy_plane(plane, &dev->mode_config.plane_list) {
  3325. intel_plane = to_intel_plane(plane);
  3326. if (intel_plane->pipe == pipe)
  3327. intel_plane_disable(&intel_plane->base);
  3328. }
  3329. }
  3330. void hsw_enable_ips(struct intel_crtc *crtc)
  3331. {
  3332. struct drm_device *dev = crtc->base.dev;
  3333. struct drm_i915_private *dev_priv = dev->dev_private;
  3334. if (!crtc->config.ips_enabled)
  3335. return;
  3336. /* We can only enable IPS after we enable a plane and wait for a vblank */
  3337. intel_wait_for_vblank(dev, crtc->pipe);
  3338. assert_plane_enabled(dev_priv, crtc->plane);
  3339. if (IS_BROADWELL(dev)) {
  3340. mutex_lock(&dev_priv->rps.hw_lock);
  3341. WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0xc0000000));
  3342. mutex_unlock(&dev_priv->rps.hw_lock);
  3343. /* Quoting Art Runyan: "its not safe to expect any particular
  3344. * value in IPS_CTL bit 31 after enabling IPS through the
  3345. * mailbox." Moreover, the mailbox may return a bogus state,
  3346. * so we need to just enable it and continue on.
  3347. */
  3348. } else {
  3349. I915_WRITE(IPS_CTL, IPS_ENABLE);
  3350. /* The bit only becomes 1 in the next vblank, so this wait here
  3351. * is essentially intel_wait_for_vblank. If we don't have this
  3352. * and don't wait for vblanks until the end of crtc_enable, then
  3353. * the HW state readout code will complain that the expected
  3354. * IPS_CTL value is not the one we read. */
  3355. if (wait_for(I915_READ_NOTRACE(IPS_CTL) & IPS_ENABLE, 50))
  3356. DRM_ERROR("Timed out waiting for IPS enable\n");
  3357. }
  3358. }
  3359. void hsw_disable_ips(struct intel_crtc *crtc)
  3360. {
  3361. struct drm_device *dev = crtc->base.dev;
  3362. struct drm_i915_private *dev_priv = dev->dev_private;
  3363. if (!crtc->config.ips_enabled)
  3364. return;
  3365. assert_plane_enabled(dev_priv, crtc->plane);
  3366. if (IS_BROADWELL(dev)) {
  3367. mutex_lock(&dev_priv->rps.hw_lock);
  3368. WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0));
  3369. mutex_unlock(&dev_priv->rps.hw_lock);
  3370. /* wait for pcode to finish disabling IPS, which may take up to 42ms */
  3371. if (wait_for((I915_READ(IPS_CTL) & IPS_ENABLE) == 0, 42))
  3372. DRM_ERROR("Timed out waiting for IPS disable\n");
  3373. } else {
  3374. I915_WRITE(IPS_CTL, 0);
  3375. POSTING_READ(IPS_CTL);
  3376. }
  3377. /* We need to wait for a vblank before we can disable the plane. */
  3378. intel_wait_for_vblank(dev, crtc->pipe);
  3379. }
  3380. /** Loads the palette/gamma unit for the CRTC with the prepared values */
  3381. static void intel_crtc_load_lut(struct drm_crtc *crtc)
  3382. {
  3383. struct drm_device *dev = crtc->dev;
  3384. struct drm_i915_private *dev_priv = dev->dev_private;
  3385. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3386. enum pipe pipe = intel_crtc->pipe;
  3387. int palreg = PALETTE(pipe);
  3388. int i;
  3389. bool reenable_ips = false;
  3390. /* The clocks have to be on to load the palette. */
  3391. if (!crtc->enabled || !intel_crtc->active)
  3392. return;
  3393. if (!HAS_PCH_SPLIT(dev_priv->dev)) {
  3394. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DSI))
  3395. assert_dsi_pll_enabled(dev_priv);
  3396. else
  3397. assert_pll_enabled(dev_priv, pipe);
  3398. }
  3399. /* use legacy palette for Ironlake */
  3400. if (!HAS_GMCH_DISPLAY(dev))
  3401. palreg = LGC_PALETTE(pipe);
  3402. /* Workaround : Do not read or write the pipe palette/gamma data while
  3403. * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
  3404. */
  3405. if (IS_HASWELL(dev) && intel_crtc->config.ips_enabled &&
  3406. ((I915_READ(GAMMA_MODE(pipe)) & GAMMA_MODE_MODE_MASK) ==
  3407. GAMMA_MODE_MODE_SPLIT)) {
  3408. hsw_disable_ips(intel_crtc);
  3409. reenable_ips = true;
  3410. }
  3411. for (i = 0; i < 256; i++) {
  3412. I915_WRITE(palreg + 4 * i,
  3413. (intel_crtc->lut_r[i] << 16) |
  3414. (intel_crtc->lut_g[i] << 8) |
  3415. intel_crtc->lut_b[i]);
  3416. }
  3417. if (reenable_ips)
  3418. hsw_enable_ips(intel_crtc);
  3419. }
  3420. static void intel_crtc_dpms_overlay(struct intel_crtc *intel_crtc, bool enable)
  3421. {
  3422. if (!enable && intel_crtc->overlay) {
  3423. struct drm_device *dev = intel_crtc->base.dev;
  3424. struct drm_i915_private *dev_priv = dev->dev_private;
  3425. mutex_lock(&dev->struct_mutex);
  3426. dev_priv->mm.interruptible = false;
  3427. (void) intel_overlay_switch_off(intel_crtc->overlay);
  3428. dev_priv->mm.interruptible = true;
  3429. mutex_unlock(&dev->struct_mutex);
  3430. }
  3431. /* Let userspace switch the overlay on again. In most cases userspace
  3432. * has to recompute where to put it anyway.
  3433. */
  3434. }
  3435. static void intel_crtc_enable_planes(struct drm_crtc *crtc)
  3436. {
  3437. struct drm_device *dev = crtc->dev;
  3438. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3439. int pipe = intel_crtc->pipe;
  3440. assert_vblank_disabled(crtc);
  3441. drm_vblank_on(dev, pipe);
  3442. intel_enable_primary_hw_plane(crtc->primary, crtc);
  3443. intel_enable_planes(crtc);
  3444. intel_crtc_update_cursor(crtc, true);
  3445. intel_crtc_dpms_overlay(intel_crtc, true);
  3446. hsw_enable_ips(intel_crtc);
  3447. mutex_lock(&dev->struct_mutex);
  3448. intel_update_fbc(dev);
  3449. mutex_unlock(&dev->struct_mutex);
  3450. /*
  3451. * FIXME: Once we grow proper nuclear flip support out of this we need
  3452. * to compute the mask of flip planes precisely. For the time being
  3453. * consider this a flip from a NULL plane.
  3454. */
  3455. intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_ALL_MASK(pipe));
  3456. }
  3457. static void intel_crtc_disable_planes(struct drm_crtc *crtc)
  3458. {
  3459. struct drm_device *dev = crtc->dev;
  3460. struct drm_i915_private *dev_priv = dev->dev_private;
  3461. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3462. int pipe = intel_crtc->pipe;
  3463. int plane = intel_crtc->plane;
  3464. intel_crtc_wait_for_pending_flips(crtc);
  3465. if (dev_priv->fbc.plane == plane)
  3466. intel_disable_fbc(dev);
  3467. hsw_disable_ips(intel_crtc);
  3468. intel_crtc_dpms_overlay(intel_crtc, false);
  3469. intel_crtc_update_cursor(crtc, false);
  3470. intel_disable_planes(crtc);
  3471. intel_disable_primary_hw_plane(crtc->primary, crtc);
  3472. /*
  3473. * FIXME: Once we grow proper nuclear flip support out of this we need
  3474. * to compute the mask of flip planes precisely. For the time being
  3475. * consider this a flip to a NULL plane.
  3476. */
  3477. intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_ALL_MASK(pipe));
  3478. drm_vblank_off(dev, pipe);
  3479. assert_vblank_disabled(crtc);
  3480. }
  3481. static void ironlake_crtc_enable(struct drm_crtc *crtc)
  3482. {
  3483. struct drm_device *dev = crtc->dev;
  3484. struct drm_i915_private *dev_priv = dev->dev_private;
  3485. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3486. struct intel_encoder *encoder;
  3487. int pipe = intel_crtc->pipe;
  3488. WARN_ON(!crtc->enabled);
  3489. if (intel_crtc->active)
  3490. return;
  3491. if (intel_crtc->config.has_pch_encoder)
  3492. intel_prepare_shared_dpll(intel_crtc);
  3493. if (intel_crtc->config.has_dp_encoder)
  3494. intel_dp_set_m_n(intel_crtc);
  3495. intel_set_pipe_timings(intel_crtc);
  3496. if (intel_crtc->config.has_pch_encoder) {
  3497. intel_cpu_transcoder_set_m_n(intel_crtc,
  3498. &intel_crtc->config.fdi_m_n, NULL);
  3499. }
  3500. ironlake_set_pipeconf(crtc);
  3501. intel_crtc->active = true;
  3502. intel_set_cpu_fifo_underrun_reporting(dev, pipe, true);
  3503. intel_set_pch_fifo_underrun_reporting(dev, pipe, true);
  3504. for_each_encoder_on_crtc(dev, crtc, encoder)
  3505. if (encoder->pre_enable)
  3506. encoder->pre_enable(encoder);
  3507. if (intel_crtc->config.has_pch_encoder) {
  3508. /* Note: FDI PLL enabling _must_ be done before we enable the
  3509. * cpu pipes, hence this is separate from all the other fdi/pch
  3510. * enabling. */
  3511. ironlake_fdi_pll_enable(intel_crtc);
  3512. } else {
  3513. assert_fdi_tx_disabled(dev_priv, pipe);
  3514. assert_fdi_rx_disabled(dev_priv, pipe);
  3515. }
  3516. ironlake_pfit_enable(intel_crtc);
  3517. /*
  3518. * On ILK+ LUT must be loaded before the pipe is running but with
  3519. * clocks enabled
  3520. */
  3521. intel_crtc_load_lut(crtc);
  3522. intel_update_watermarks(crtc);
  3523. intel_enable_pipe(intel_crtc);
  3524. if (intel_crtc->config.has_pch_encoder)
  3525. ironlake_pch_enable(crtc);
  3526. for_each_encoder_on_crtc(dev, crtc, encoder)
  3527. encoder->enable(encoder);
  3528. if (HAS_PCH_CPT(dev))
  3529. cpt_verify_modeset(dev, intel_crtc->pipe);
  3530. intel_crtc_enable_planes(crtc);
  3531. }
  3532. /* IPS only exists on ULT machines and is tied to pipe A. */
  3533. static bool hsw_crtc_supports_ips(struct intel_crtc *crtc)
  3534. {
  3535. return HAS_IPS(crtc->base.dev) && crtc->pipe == PIPE_A;
  3536. }
  3537. /*
  3538. * This implements the workaround described in the "notes" section of the mode
  3539. * set sequence documentation. When going from no pipes or single pipe to
  3540. * multiple pipes, and planes are enabled after the pipe, we need to wait at
  3541. * least 2 vblanks on the first pipe before enabling planes on the second pipe.
  3542. */
  3543. static void haswell_mode_set_planes_workaround(struct intel_crtc *crtc)
  3544. {
  3545. struct drm_device *dev = crtc->base.dev;
  3546. struct intel_crtc *crtc_it, *other_active_crtc = NULL;
  3547. /* We want to get the other_active_crtc only if there's only 1 other
  3548. * active crtc. */
  3549. for_each_intel_crtc(dev, crtc_it) {
  3550. if (!crtc_it->active || crtc_it == crtc)
  3551. continue;
  3552. if (other_active_crtc)
  3553. return;
  3554. other_active_crtc = crtc_it;
  3555. }
  3556. if (!other_active_crtc)
  3557. return;
  3558. intel_wait_for_vblank(dev, other_active_crtc->pipe);
  3559. intel_wait_for_vblank(dev, other_active_crtc->pipe);
  3560. }
  3561. static void haswell_crtc_enable(struct drm_crtc *crtc)
  3562. {
  3563. struct drm_device *dev = crtc->dev;
  3564. struct drm_i915_private *dev_priv = dev->dev_private;
  3565. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3566. struct intel_encoder *encoder;
  3567. int pipe = intel_crtc->pipe;
  3568. WARN_ON(!crtc->enabled);
  3569. if (intel_crtc->active)
  3570. return;
  3571. if (intel_crtc_to_shared_dpll(intel_crtc))
  3572. intel_enable_shared_dpll(intel_crtc);
  3573. if (intel_crtc->config.has_dp_encoder)
  3574. intel_dp_set_m_n(intel_crtc);
  3575. intel_set_pipe_timings(intel_crtc);
  3576. if (intel_crtc->config.cpu_transcoder != TRANSCODER_EDP) {
  3577. I915_WRITE(PIPE_MULT(intel_crtc->config.cpu_transcoder),
  3578. intel_crtc->config.pixel_multiplier - 1);
  3579. }
  3580. if (intel_crtc->config.has_pch_encoder) {
  3581. intel_cpu_transcoder_set_m_n(intel_crtc,
  3582. &intel_crtc->config.fdi_m_n, NULL);
  3583. }
  3584. haswell_set_pipeconf(crtc);
  3585. intel_set_pipe_csc(crtc);
  3586. intel_crtc->active = true;
  3587. intel_set_cpu_fifo_underrun_reporting(dev, pipe, true);
  3588. for_each_encoder_on_crtc(dev, crtc, encoder)
  3589. if (encoder->pre_enable)
  3590. encoder->pre_enable(encoder);
  3591. if (intel_crtc->config.has_pch_encoder) {
  3592. intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, true);
  3593. dev_priv->display.fdi_link_train(crtc);
  3594. }
  3595. intel_ddi_enable_pipe_clock(intel_crtc);
  3596. ironlake_pfit_enable(intel_crtc);
  3597. /*
  3598. * On ILK+ LUT must be loaded before the pipe is running but with
  3599. * clocks enabled
  3600. */
  3601. intel_crtc_load_lut(crtc);
  3602. intel_ddi_set_pipe_settings(crtc);
  3603. intel_ddi_enable_transcoder_func(crtc);
  3604. intel_update_watermarks(crtc);
  3605. intel_enable_pipe(intel_crtc);
  3606. if (intel_crtc->config.has_pch_encoder)
  3607. lpt_pch_enable(crtc);
  3608. if (intel_crtc->config.dp_encoder_is_mst)
  3609. intel_ddi_set_vc_payload_alloc(crtc, true);
  3610. for_each_encoder_on_crtc(dev, crtc, encoder) {
  3611. encoder->enable(encoder);
  3612. intel_opregion_notify_encoder(encoder, true);
  3613. }
  3614. /* If we change the relative order between pipe/planes enabling, we need
  3615. * to change the workaround. */
  3616. haswell_mode_set_planes_workaround(intel_crtc);
  3617. intel_crtc_enable_planes(crtc);
  3618. }
  3619. static void ironlake_pfit_disable(struct intel_crtc *crtc)
  3620. {
  3621. struct drm_device *dev = crtc->base.dev;
  3622. struct drm_i915_private *dev_priv = dev->dev_private;
  3623. int pipe = crtc->pipe;
  3624. /* To avoid upsetting the power well on haswell only disable the pfit if
  3625. * it's in use. The hw state code will make sure we get this right. */
  3626. if (crtc->config.pch_pfit.enabled) {
  3627. I915_WRITE(PF_CTL(pipe), 0);
  3628. I915_WRITE(PF_WIN_POS(pipe), 0);
  3629. I915_WRITE(PF_WIN_SZ(pipe), 0);
  3630. }
  3631. }
  3632. static void ironlake_crtc_disable(struct drm_crtc *crtc)
  3633. {
  3634. struct drm_device *dev = crtc->dev;
  3635. struct drm_i915_private *dev_priv = dev->dev_private;
  3636. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3637. struct intel_encoder *encoder;
  3638. int pipe = intel_crtc->pipe;
  3639. u32 reg, temp;
  3640. if (!intel_crtc->active)
  3641. return;
  3642. intel_crtc_disable_planes(crtc);
  3643. for_each_encoder_on_crtc(dev, crtc, encoder)
  3644. encoder->disable(encoder);
  3645. if (intel_crtc->config.has_pch_encoder)
  3646. intel_set_pch_fifo_underrun_reporting(dev, pipe, false);
  3647. intel_disable_pipe(intel_crtc);
  3648. ironlake_pfit_disable(intel_crtc);
  3649. for_each_encoder_on_crtc(dev, crtc, encoder)
  3650. if (encoder->post_disable)
  3651. encoder->post_disable(encoder);
  3652. if (intel_crtc->config.has_pch_encoder) {
  3653. ironlake_fdi_disable(crtc);
  3654. ironlake_disable_pch_transcoder(dev_priv, pipe);
  3655. intel_set_pch_fifo_underrun_reporting(dev, pipe, true);
  3656. if (HAS_PCH_CPT(dev)) {
  3657. /* disable TRANS_DP_CTL */
  3658. reg = TRANS_DP_CTL(pipe);
  3659. temp = I915_READ(reg);
  3660. temp &= ~(TRANS_DP_OUTPUT_ENABLE |
  3661. TRANS_DP_PORT_SEL_MASK);
  3662. temp |= TRANS_DP_PORT_SEL_NONE;
  3663. I915_WRITE(reg, temp);
  3664. /* disable DPLL_SEL */
  3665. temp = I915_READ(PCH_DPLL_SEL);
  3666. temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe));
  3667. I915_WRITE(PCH_DPLL_SEL, temp);
  3668. }
  3669. /* disable PCH DPLL */
  3670. intel_disable_shared_dpll(intel_crtc);
  3671. ironlake_fdi_pll_disable(intel_crtc);
  3672. }
  3673. intel_crtc->active = false;
  3674. intel_update_watermarks(crtc);
  3675. mutex_lock(&dev->struct_mutex);
  3676. intel_update_fbc(dev);
  3677. mutex_unlock(&dev->struct_mutex);
  3678. }
  3679. static void haswell_crtc_disable(struct drm_crtc *crtc)
  3680. {
  3681. struct drm_device *dev = crtc->dev;
  3682. struct drm_i915_private *dev_priv = dev->dev_private;
  3683. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3684. struct intel_encoder *encoder;
  3685. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  3686. if (!intel_crtc->active)
  3687. return;
  3688. intel_crtc_disable_planes(crtc);
  3689. for_each_encoder_on_crtc(dev, crtc, encoder) {
  3690. intel_opregion_notify_encoder(encoder, false);
  3691. encoder->disable(encoder);
  3692. }
  3693. if (intel_crtc->config.has_pch_encoder)
  3694. intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, false);
  3695. intel_disable_pipe(intel_crtc);
  3696. if (intel_crtc->config.dp_encoder_is_mst)
  3697. intel_ddi_set_vc_payload_alloc(crtc, false);
  3698. intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder);
  3699. ironlake_pfit_disable(intel_crtc);
  3700. intel_ddi_disable_pipe_clock(intel_crtc);
  3701. if (intel_crtc->config.has_pch_encoder) {
  3702. lpt_disable_pch_transcoder(dev_priv);
  3703. intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, true);
  3704. intel_ddi_fdi_disable(crtc);
  3705. }
  3706. for_each_encoder_on_crtc(dev, crtc, encoder)
  3707. if (encoder->post_disable)
  3708. encoder->post_disable(encoder);
  3709. intel_crtc->active = false;
  3710. intel_update_watermarks(crtc);
  3711. mutex_lock(&dev->struct_mutex);
  3712. intel_update_fbc(dev);
  3713. mutex_unlock(&dev->struct_mutex);
  3714. if (intel_crtc_to_shared_dpll(intel_crtc))
  3715. intel_disable_shared_dpll(intel_crtc);
  3716. }
  3717. static void ironlake_crtc_off(struct drm_crtc *crtc)
  3718. {
  3719. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3720. intel_put_shared_dpll(intel_crtc);
  3721. }
  3722. static void i9xx_pfit_enable(struct intel_crtc *crtc)
  3723. {
  3724. struct drm_device *dev = crtc->base.dev;
  3725. struct drm_i915_private *dev_priv = dev->dev_private;
  3726. struct intel_crtc_config *pipe_config = &crtc->config;
  3727. if (!crtc->config.gmch_pfit.control)
  3728. return;
  3729. /*
  3730. * The panel fitter should only be adjusted whilst the pipe is disabled,
  3731. * according to register description and PRM.
  3732. */
  3733. WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE);
  3734. assert_pipe_disabled(dev_priv, crtc->pipe);
  3735. I915_WRITE(PFIT_PGM_RATIOS, pipe_config->gmch_pfit.pgm_ratios);
  3736. I915_WRITE(PFIT_CONTROL, pipe_config->gmch_pfit.control);
  3737. /* Border color in case we don't scale up to the full screen. Black by
  3738. * default, change to something else for debugging. */
  3739. I915_WRITE(BCLRPAT(crtc->pipe), 0);
  3740. }
  3741. static enum intel_display_power_domain port_to_power_domain(enum port port)
  3742. {
  3743. switch (port) {
  3744. case PORT_A:
  3745. return POWER_DOMAIN_PORT_DDI_A_4_LANES;
  3746. case PORT_B:
  3747. return POWER_DOMAIN_PORT_DDI_B_4_LANES;
  3748. case PORT_C:
  3749. return POWER_DOMAIN_PORT_DDI_C_4_LANES;
  3750. case PORT_D:
  3751. return POWER_DOMAIN_PORT_DDI_D_4_LANES;
  3752. default:
  3753. WARN_ON_ONCE(1);
  3754. return POWER_DOMAIN_PORT_OTHER;
  3755. }
  3756. }
  3757. #define for_each_power_domain(domain, mask) \
  3758. for ((domain) = 0; (domain) < POWER_DOMAIN_NUM; (domain)++) \
  3759. if ((1 << (domain)) & (mask))
  3760. enum intel_display_power_domain
  3761. intel_display_port_power_domain(struct intel_encoder *intel_encoder)
  3762. {
  3763. struct drm_device *dev = intel_encoder->base.dev;
  3764. struct intel_digital_port *intel_dig_port;
  3765. switch (intel_encoder->type) {
  3766. case INTEL_OUTPUT_UNKNOWN:
  3767. /* Only DDI platforms should ever use this output type */
  3768. WARN_ON_ONCE(!HAS_DDI(dev));
  3769. case INTEL_OUTPUT_DISPLAYPORT:
  3770. case INTEL_OUTPUT_HDMI:
  3771. case INTEL_OUTPUT_EDP:
  3772. intel_dig_port = enc_to_dig_port(&intel_encoder->base);
  3773. return port_to_power_domain(intel_dig_port->port);
  3774. case INTEL_OUTPUT_DP_MST:
  3775. intel_dig_port = enc_to_mst(&intel_encoder->base)->primary;
  3776. return port_to_power_domain(intel_dig_port->port);
  3777. case INTEL_OUTPUT_ANALOG:
  3778. return POWER_DOMAIN_PORT_CRT;
  3779. case INTEL_OUTPUT_DSI:
  3780. return POWER_DOMAIN_PORT_DSI;
  3781. default:
  3782. return POWER_DOMAIN_PORT_OTHER;
  3783. }
  3784. }
  3785. static unsigned long get_crtc_power_domains(struct drm_crtc *crtc)
  3786. {
  3787. struct drm_device *dev = crtc->dev;
  3788. struct intel_encoder *intel_encoder;
  3789. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3790. enum pipe pipe = intel_crtc->pipe;
  3791. unsigned long mask;
  3792. enum transcoder transcoder;
  3793. transcoder = intel_pipe_to_cpu_transcoder(dev->dev_private, pipe);
  3794. mask = BIT(POWER_DOMAIN_PIPE(pipe));
  3795. mask |= BIT(POWER_DOMAIN_TRANSCODER(transcoder));
  3796. if (intel_crtc->config.pch_pfit.enabled ||
  3797. intel_crtc->config.pch_pfit.force_thru)
  3798. mask |= BIT(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe));
  3799. for_each_encoder_on_crtc(dev, crtc, intel_encoder)
  3800. mask |= BIT(intel_display_port_power_domain(intel_encoder));
  3801. return mask;
  3802. }
  3803. void intel_display_set_init_power(struct drm_i915_private *dev_priv,
  3804. bool enable)
  3805. {
  3806. if (dev_priv->power_domains.init_power_on == enable)
  3807. return;
  3808. if (enable)
  3809. intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
  3810. else
  3811. intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
  3812. dev_priv->power_domains.init_power_on = enable;
  3813. }
  3814. static void modeset_update_crtc_power_domains(struct drm_device *dev)
  3815. {
  3816. struct drm_i915_private *dev_priv = dev->dev_private;
  3817. unsigned long pipe_domains[I915_MAX_PIPES] = { 0, };
  3818. struct intel_crtc *crtc;
  3819. /*
  3820. * First get all needed power domains, then put all unneeded, to avoid
  3821. * any unnecessary toggling of the power wells.
  3822. */
  3823. for_each_intel_crtc(dev, crtc) {
  3824. enum intel_display_power_domain domain;
  3825. if (!crtc->base.enabled)
  3826. continue;
  3827. pipe_domains[crtc->pipe] = get_crtc_power_domains(&crtc->base);
  3828. for_each_power_domain(domain, pipe_domains[crtc->pipe])
  3829. intel_display_power_get(dev_priv, domain);
  3830. }
  3831. for_each_intel_crtc(dev, crtc) {
  3832. enum intel_display_power_domain domain;
  3833. for_each_power_domain(domain, crtc->enabled_power_domains)
  3834. intel_display_power_put(dev_priv, domain);
  3835. crtc->enabled_power_domains = pipe_domains[crtc->pipe];
  3836. }
  3837. intel_display_set_init_power(dev_priv, false);
  3838. }
  3839. /* returns HPLL frequency in kHz */
  3840. static int valleyview_get_vco(struct drm_i915_private *dev_priv)
  3841. {
  3842. int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 };
  3843. /* Obtain SKU information */
  3844. mutex_lock(&dev_priv->dpio_lock);
  3845. hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) &
  3846. CCK_FUSE_HPLL_FREQ_MASK;
  3847. mutex_unlock(&dev_priv->dpio_lock);
  3848. return vco_freq[hpll_freq] * 1000;
  3849. }
  3850. static void vlv_update_cdclk(struct drm_device *dev)
  3851. {
  3852. struct drm_i915_private *dev_priv = dev->dev_private;
  3853. dev_priv->vlv_cdclk_freq = dev_priv->display.get_display_clock_speed(dev);
  3854. DRM_DEBUG_DRIVER("Current CD clock rate: %d kHz",
  3855. dev_priv->vlv_cdclk_freq);
  3856. /*
  3857. * Program the gmbus_freq based on the cdclk frequency.
  3858. * BSpec erroneously claims we should aim for 4MHz, but
  3859. * in fact 1MHz is the correct frequency.
  3860. */
  3861. I915_WRITE(GMBUSFREQ_VLV, DIV_ROUND_UP(dev_priv->vlv_cdclk_freq, 1000));
  3862. }
  3863. /* Adjust CDclk dividers to allow high res or save power if possible */
  3864. static void valleyview_set_cdclk(struct drm_device *dev, int cdclk)
  3865. {
  3866. struct drm_i915_private *dev_priv = dev->dev_private;
  3867. u32 val, cmd;
  3868. WARN_ON(dev_priv->display.get_display_clock_speed(dev) != dev_priv->vlv_cdclk_freq);
  3869. if (cdclk >= 320000) /* jump to highest voltage for 400MHz too */
  3870. cmd = 2;
  3871. else if (cdclk == 266667)
  3872. cmd = 1;
  3873. else
  3874. cmd = 0;
  3875. mutex_lock(&dev_priv->rps.hw_lock);
  3876. val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
  3877. val &= ~DSPFREQGUAR_MASK;
  3878. val |= (cmd << DSPFREQGUAR_SHIFT);
  3879. vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val);
  3880. if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) &
  3881. DSPFREQSTAT_MASK) == (cmd << DSPFREQSTAT_SHIFT),
  3882. 50)) {
  3883. DRM_ERROR("timed out waiting for CDclk change\n");
  3884. }
  3885. mutex_unlock(&dev_priv->rps.hw_lock);
  3886. if (cdclk == 400000) {
  3887. u32 divider, vco;
  3888. vco = valleyview_get_vco(dev_priv);
  3889. divider = DIV_ROUND_CLOSEST(vco << 1, cdclk) - 1;
  3890. mutex_lock(&dev_priv->dpio_lock);
  3891. /* adjust cdclk divider */
  3892. val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL);
  3893. val &= ~DISPLAY_FREQUENCY_VALUES;
  3894. val |= divider;
  3895. vlv_cck_write(dev_priv, CCK_DISPLAY_CLOCK_CONTROL, val);
  3896. if (wait_for((vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL) &
  3897. DISPLAY_FREQUENCY_STATUS) == (divider << DISPLAY_FREQUENCY_STATUS_SHIFT),
  3898. 50))
  3899. DRM_ERROR("timed out waiting for CDclk change\n");
  3900. mutex_unlock(&dev_priv->dpio_lock);
  3901. }
  3902. mutex_lock(&dev_priv->dpio_lock);
  3903. /* adjust self-refresh exit latency value */
  3904. val = vlv_bunit_read(dev_priv, BUNIT_REG_BISOC);
  3905. val &= ~0x7f;
  3906. /*
  3907. * For high bandwidth configs, we set a higher latency in the bunit
  3908. * so that the core display fetch happens in time to avoid underruns.
  3909. */
  3910. if (cdclk == 400000)
  3911. val |= 4500 / 250; /* 4.5 usec */
  3912. else
  3913. val |= 3000 / 250; /* 3.0 usec */
  3914. vlv_bunit_write(dev_priv, BUNIT_REG_BISOC, val);
  3915. mutex_unlock(&dev_priv->dpio_lock);
  3916. vlv_update_cdclk(dev);
  3917. }
  3918. static void cherryview_set_cdclk(struct drm_device *dev, int cdclk)
  3919. {
  3920. struct drm_i915_private *dev_priv = dev->dev_private;
  3921. u32 val, cmd;
  3922. WARN_ON(dev_priv->display.get_display_clock_speed(dev) != dev_priv->vlv_cdclk_freq);
  3923. switch (cdclk) {
  3924. case 400000:
  3925. cmd = 3;
  3926. break;
  3927. case 333333:
  3928. case 320000:
  3929. cmd = 2;
  3930. break;
  3931. case 266667:
  3932. cmd = 1;
  3933. break;
  3934. case 200000:
  3935. cmd = 0;
  3936. break;
  3937. default:
  3938. WARN_ON(1);
  3939. return;
  3940. }
  3941. mutex_lock(&dev_priv->rps.hw_lock);
  3942. val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
  3943. val &= ~DSPFREQGUAR_MASK_CHV;
  3944. val |= (cmd << DSPFREQGUAR_SHIFT_CHV);
  3945. vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val);
  3946. if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) &
  3947. DSPFREQSTAT_MASK_CHV) == (cmd << DSPFREQSTAT_SHIFT_CHV),
  3948. 50)) {
  3949. DRM_ERROR("timed out waiting for CDclk change\n");
  3950. }
  3951. mutex_unlock(&dev_priv->rps.hw_lock);
  3952. vlv_update_cdclk(dev);
  3953. }
  3954. static int valleyview_calc_cdclk(struct drm_i915_private *dev_priv,
  3955. int max_pixclk)
  3956. {
  3957. int vco = valleyview_get_vco(dev_priv);
  3958. int freq_320 = (vco << 1) % 320000 != 0 ? 333333 : 320000;
  3959. /* FIXME: Punit isn't quite ready yet */
  3960. if (IS_CHERRYVIEW(dev_priv->dev))
  3961. return 400000;
  3962. /*
  3963. * Really only a few cases to deal with, as only 4 CDclks are supported:
  3964. * 200MHz
  3965. * 267MHz
  3966. * 320/333MHz (depends on HPLL freq)
  3967. * 400MHz
  3968. * So we check to see whether we're above 90% of the lower bin and
  3969. * adjust if needed.
  3970. *
  3971. * We seem to get an unstable or solid color picture at 200MHz.
  3972. * Not sure what's wrong. For now use 200MHz only when all pipes
  3973. * are off.
  3974. */
  3975. if (max_pixclk > freq_320*9/10)
  3976. return 400000;
  3977. else if (max_pixclk > 266667*9/10)
  3978. return freq_320;
  3979. else if (max_pixclk > 0)
  3980. return 266667;
  3981. else
  3982. return 200000;
  3983. }
  3984. /* compute the max pixel clock for new configuration */
  3985. static int intel_mode_max_pixclk(struct drm_i915_private *dev_priv)
  3986. {
  3987. struct drm_device *dev = dev_priv->dev;
  3988. struct intel_crtc *intel_crtc;
  3989. int max_pixclk = 0;
  3990. for_each_intel_crtc(dev, intel_crtc) {
  3991. if (intel_crtc->new_enabled)
  3992. max_pixclk = max(max_pixclk,
  3993. intel_crtc->new_config->adjusted_mode.crtc_clock);
  3994. }
  3995. return max_pixclk;
  3996. }
  3997. static void valleyview_modeset_global_pipes(struct drm_device *dev,
  3998. unsigned *prepare_pipes)
  3999. {
  4000. struct drm_i915_private *dev_priv = dev->dev_private;
  4001. struct intel_crtc *intel_crtc;
  4002. int max_pixclk = intel_mode_max_pixclk(dev_priv);
  4003. if (valleyview_calc_cdclk(dev_priv, max_pixclk) ==
  4004. dev_priv->vlv_cdclk_freq)
  4005. return;
  4006. /* disable/enable all currently active pipes while we change cdclk */
  4007. for_each_intel_crtc(dev, intel_crtc)
  4008. if (intel_crtc->base.enabled)
  4009. *prepare_pipes |= (1 << intel_crtc->pipe);
  4010. }
  4011. static void valleyview_modeset_global_resources(struct drm_device *dev)
  4012. {
  4013. struct drm_i915_private *dev_priv = dev->dev_private;
  4014. int max_pixclk = intel_mode_max_pixclk(dev_priv);
  4015. int req_cdclk = valleyview_calc_cdclk(dev_priv, max_pixclk);
  4016. if (req_cdclk != dev_priv->vlv_cdclk_freq) {
  4017. if (IS_CHERRYVIEW(dev))
  4018. cherryview_set_cdclk(dev, req_cdclk);
  4019. else
  4020. valleyview_set_cdclk(dev, req_cdclk);
  4021. }
  4022. modeset_update_crtc_power_domains(dev);
  4023. }
  4024. static void valleyview_crtc_enable(struct drm_crtc *crtc)
  4025. {
  4026. struct drm_device *dev = crtc->dev;
  4027. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4028. struct intel_encoder *encoder;
  4029. int pipe = intel_crtc->pipe;
  4030. bool is_dsi;
  4031. WARN_ON(!crtc->enabled);
  4032. if (intel_crtc->active)
  4033. return;
  4034. is_dsi = intel_pipe_has_type(crtc, INTEL_OUTPUT_DSI);
  4035. if (!is_dsi) {
  4036. if (IS_CHERRYVIEW(dev))
  4037. chv_prepare_pll(intel_crtc);
  4038. else
  4039. vlv_prepare_pll(intel_crtc);
  4040. }
  4041. if (intel_crtc->config.has_dp_encoder)
  4042. intel_dp_set_m_n(intel_crtc);
  4043. intel_set_pipe_timings(intel_crtc);
  4044. i9xx_set_pipeconf(intel_crtc);
  4045. intel_crtc->active = true;
  4046. intel_set_cpu_fifo_underrun_reporting(dev, pipe, true);
  4047. for_each_encoder_on_crtc(dev, crtc, encoder)
  4048. if (encoder->pre_pll_enable)
  4049. encoder->pre_pll_enable(encoder);
  4050. if (!is_dsi) {
  4051. if (IS_CHERRYVIEW(dev))
  4052. chv_enable_pll(intel_crtc);
  4053. else
  4054. vlv_enable_pll(intel_crtc);
  4055. }
  4056. for_each_encoder_on_crtc(dev, crtc, encoder)
  4057. if (encoder->pre_enable)
  4058. encoder->pre_enable(encoder);
  4059. i9xx_pfit_enable(intel_crtc);
  4060. intel_crtc_load_lut(crtc);
  4061. intel_update_watermarks(crtc);
  4062. intel_enable_pipe(intel_crtc);
  4063. for_each_encoder_on_crtc(dev, crtc, encoder)
  4064. encoder->enable(encoder);
  4065. intel_crtc_enable_planes(crtc);
  4066. /* Underruns don't raise interrupts, so check manually. */
  4067. i9xx_check_fifo_underruns(dev);
  4068. }
  4069. static void i9xx_set_pll_dividers(struct intel_crtc *crtc)
  4070. {
  4071. struct drm_device *dev = crtc->base.dev;
  4072. struct drm_i915_private *dev_priv = dev->dev_private;
  4073. I915_WRITE(FP0(crtc->pipe), crtc->config.dpll_hw_state.fp0);
  4074. I915_WRITE(FP1(crtc->pipe), crtc->config.dpll_hw_state.fp1);
  4075. }
  4076. static void i9xx_crtc_enable(struct drm_crtc *crtc)
  4077. {
  4078. struct drm_device *dev = crtc->dev;
  4079. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4080. struct intel_encoder *encoder;
  4081. int pipe = intel_crtc->pipe;
  4082. WARN_ON(!crtc->enabled);
  4083. if (intel_crtc->active)
  4084. return;
  4085. i9xx_set_pll_dividers(intel_crtc);
  4086. if (intel_crtc->config.has_dp_encoder)
  4087. intel_dp_set_m_n(intel_crtc);
  4088. intel_set_pipe_timings(intel_crtc);
  4089. i9xx_set_pipeconf(intel_crtc);
  4090. intel_crtc->active = true;
  4091. if (!IS_GEN2(dev))
  4092. intel_set_cpu_fifo_underrun_reporting(dev, pipe, true);
  4093. for_each_encoder_on_crtc(dev, crtc, encoder)
  4094. if (encoder->pre_enable)
  4095. encoder->pre_enable(encoder);
  4096. i9xx_enable_pll(intel_crtc);
  4097. i9xx_pfit_enable(intel_crtc);
  4098. intel_crtc_load_lut(crtc);
  4099. intel_update_watermarks(crtc);
  4100. intel_enable_pipe(intel_crtc);
  4101. for_each_encoder_on_crtc(dev, crtc, encoder)
  4102. encoder->enable(encoder);
  4103. intel_crtc_enable_planes(crtc);
  4104. /*
  4105. * Gen2 reports pipe underruns whenever all planes are disabled.
  4106. * So don't enable underrun reporting before at least some planes
  4107. * are enabled.
  4108. * FIXME: Need to fix the logic to work when we turn off all planes
  4109. * but leave the pipe running.
  4110. */
  4111. if (IS_GEN2(dev))
  4112. intel_set_cpu_fifo_underrun_reporting(dev, pipe, true);
  4113. /* Underruns don't raise interrupts, so check manually. */
  4114. i9xx_check_fifo_underruns(dev);
  4115. }
  4116. static void i9xx_pfit_disable(struct intel_crtc *crtc)
  4117. {
  4118. struct drm_device *dev = crtc->base.dev;
  4119. struct drm_i915_private *dev_priv = dev->dev_private;
  4120. if (!crtc->config.gmch_pfit.control)
  4121. return;
  4122. assert_pipe_disabled(dev_priv, crtc->pipe);
  4123. DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n",
  4124. I915_READ(PFIT_CONTROL));
  4125. I915_WRITE(PFIT_CONTROL, 0);
  4126. }
  4127. static void i9xx_crtc_disable(struct drm_crtc *crtc)
  4128. {
  4129. struct drm_device *dev = crtc->dev;
  4130. struct drm_i915_private *dev_priv = dev->dev_private;
  4131. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4132. struct intel_encoder *encoder;
  4133. int pipe = intel_crtc->pipe;
  4134. if (!intel_crtc->active)
  4135. return;
  4136. /*
  4137. * Gen2 reports pipe underruns whenever all planes are disabled.
  4138. * So diasble underrun reporting before all the planes get disabled.
  4139. * FIXME: Need to fix the logic to work when we turn off all planes
  4140. * but leave the pipe running.
  4141. */
  4142. if (IS_GEN2(dev))
  4143. intel_set_cpu_fifo_underrun_reporting(dev, pipe, false);
  4144. /*
  4145. * Vblank time updates from the shadow to live plane control register
  4146. * are blocked if the memory self-refresh mode is active at that
  4147. * moment. So to make sure the plane gets truly disabled, disable
  4148. * first the self-refresh mode. The self-refresh enable bit in turn
  4149. * will be checked/applied by the HW only at the next frame start
  4150. * event which is after the vblank start event, so we need to have a
  4151. * wait-for-vblank between disabling the plane and the pipe.
  4152. */
  4153. intel_set_memory_cxsr(dev_priv, false);
  4154. intel_crtc_disable_planes(crtc);
  4155. for_each_encoder_on_crtc(dev, crtc, encoder)
  4156. encoder->disable(encoder);
  4157. /*
  4158. * On gen2 planes are double buffered but the pipe isn't, so we must
  4159. * wait for planes to fully turn off before disabling the pipe.
  4160. * We also need to wait on all gmch platforms because of the
  4161. * self-refresh mode constraint explained above.
  4162. */
  4163. intel_wait_for_vblank(dev, pipe);
  4164. intel_disable_pipe(intel_crtc);
  4165. i9xx_pfit_disable(intel_crtc);
  4166. for_each_encoder_on_crtc(dev, crtc, encoder)
  4167. if (encoder->post_disable)
  4168. encoder->post_disable(encoder);
  4169. if (!intel_pipe_has_type(crtc, INTEL_OUTPUT_DSI)) {
  4170. if (IS_CHERRYVIEW(dev))
  4171. chv_disable_pll(dev_priv, pipe);
  4172. else if (IS_VALLEYVIEW(dev))
  4173. vlv_disable_pll(dev_priv, pipe);
  4174. else
  4175. i9xx_disable_pll(intel_crtc);
  4176. }
  4177. if (!IS_GEN2(dev))
  4178. intel_set_cpu_fifo_underrun_reporting(dev, pipe, false);
  4179. intel_crtc->active = false;
  4180. intel_update_watermarks(crtc);
  4181. mutex_lock(&dev->struct_mutex);
  4182. intel_update_fbc(dev);
  4183. mutex_unlock(&dev->struct_mutex);
  4184. }
  4185. static void i9xx_crtc_off(struct drm_crtc *crtc)
  4186. {
  4187. }
  4188. static void intel_crtc_update_sarea(struct drm_crtc *crtc,
  4189. bool enabled)
  4190. {
  4191. struct drm_device *dev = crtc->dev;
  4192. struct drm_i915_master_private *master_priv;
  4193. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4194. int pipe = intel_crtc->pipe;
  4195. if (!dev->primary->master)
  4196. return;
  4197. master_priv = dev->primary->master->driver_priv;
  4198. if (!master_priv->sarea_priv)
  4199. return;
  4200. switch (pipe) {
  4201. case 0:
  4202. master_priv->sarea_priv->pipeA_w = enabled ? crtc->mode.hdisplay : 0;
  4203. master_priv->sarea_priv->pipeA_h = enabled ? crtc->mode.vdisplay : 0;
  4204. break;
  4205. case 1:
  4206. master_priv->sarea_priv->pipeB_w = enabled ? crtc->mode.hdisplay : 0;
  4207. master_priv->sarea_priv->pipeB_h = enabled ? crtc->mode.vdisplay : 0;
  4208. break;
  4209. default:
  4210. DRM_ERROR("Can't update pipe %c in SAREA\n", pipe_name(pipe));
  4211. break;
  4212. }
  4213. }
  4214. /* Master function to enable/disable CRTC and corresponding power wells */
  4215. void intel_crtc_control(struct drm_crtc *crtc, bool enable)
  4216. {
  4217. struct drm_device *dev = crtc->dev;
  4218. struct drm_i915_private *dev_priv = dev->dev_private;
  4219. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4220. enum intel_display_power_domain domain;
  4221. unsigned long domains;
  4222. if (enable) {
  4223. if (!intel_crtc->active) {
  4224. domains = get_crtc_power_domains(crtc);
  4225. for_each_power_domain(domain, domains)
  4226. intel_display_power_get(dev_priv, domain);
  4227. intel_crtc->enabled_power_domains = domains;
  4228. dev_priv->display.crtc_enable(crtc);
  4229. }
  4230. } else {
  4231. if (intel_crtc->active) {
  4232. dev_priv->display.crtc_disable(crtc);
  4233. domains = intel_crtc->enabled_power_domains;
  4234. for_each_power_domain(domain, domains)
  4235. intel_display_power_put(dev_priv, domain);
  4236. intel_crtc->enabled_power_domains = 0;
  4237. }
  4238. }
  4239. }
  4240. /**
  4241. * Sets the power management mode of the pipe and plane.
  4242. */
  4243. void intel_crtc_update_dpms(struct drm_crtc *crtc)
  4244. {
  4245. struct drm_device *dev = crtc->dev;
  4246. struct intel_encoder *intel_encoder;
  4247. bool enable = false;
  4248. for_each_encoder_on_crtc(dev, crtc, intel_encoder)
  4249. enable |= intel_encoder->connectors_active;
  4250. intel_crtc_control(crtc, enable);
  4251. intel_crtc_update_sarea(crtc, enable);
  4252. }
  4253. static void intel_crtc_disable(struct drm_crtc *crtc)
  4254. {
  4255. struct drm_device *dev = crtc->dev;
  4256. struct drm_connector *connector;
  4257. struct drm_i915_private *dev_priv = dev->dev_private;
  4258. struct drm_i915_gem_object *old_obj = intel_fb_obj(crtc->primary->fb);
  4259. enum pipe pipe = to_intel_crtc(crtc)->pipe;
  4260. /* crtc should still be enabled when we disable it. */
  4261. WARN_ON(!crtc->enabled);
  4262. dev_priv->display.crtc_disable(crtc);
  4263. intel_crtc_update_sarea(crtc, false);
  4264. dev_priv->display.off(crtc);
  4265. if (crtc->primary->fb) {
  4266. mutex_lock(&dev->struct_mutex);
  4267. intel_unpin_fb_obj(old_obj);
  4268. i915_gem_track_fb(old_obj, NULL,
  4269. INTEL_FRONTBUFFER_PRIMARY(pipe));
  4270. mutex_unlock(&dev->struct_mutex);
  4271. crtc->primary->fb = NULL;
  4272. }
  4273. /* Update computed state. */
  4274. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  4275. if (!connector->encoder || !connector->encoder->crtc)
  4276. continue;
  4277. if (connector->encoder->crtc != crtc)
  4278. continue;
  4279. connector->dpms = DRM_MODE_DPMS_OFF;
  4280. to_intel_encoder(connector->encoder)->connectors_active = false;
  4281. }
  4282. }
  4283. void intel_encoder_destroy(struct drm_encoder *encoder)
  4284. {
  4285. struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
  4286. drm_encoder_cleanup(encoder);
  4287. kfree(intel_encoder);
  4288. }
  4289. /* Simple dpms helper for encoders with just one connector, no cloning and only
  4290. * one kind of off state. It clamps all !ON modes to fully OFF and changes the
  4291. * state of the entire output pipe. */
  4292. static void intel_encoder_dpms(struct intel_encoder *encoder, int mode)
  4293. {
  4294. if (mode == DRM_MODE_DPMS_ON) {
  4295. encoder->connectors_active = true;
  4296. intel_crtc_update_dpms(encoder->base.crtc);
  4297. } else {
  4298. encoder->connectors_active = false;
  4299. intel_crtc_update_dpms(encoder->base.crtc);
  4300. }
  4301. }
  4302. /* Cross check the actual hw state with our own modeset state tracking (and it's
  4303. * internal consistency). */
  4304. static void intel_connector_check_state(struct intel_connector *connector)
  4305. {
  4306. if (connector->get_hw_state(connector)) {
  4307. struct intel_encoder *encoder = connector->encoder;
  4308. struct drm_crtc *crtc;
  4309. bool encoder_enabled;
  4310. enum pipe pipe;
  4311. DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
  4312. connector->base.base.id,
  4313. connector->base.name);
  4314. /* there is no real hw state for MST connectors */
  4315. if (connector->mst_port)
  4316. return;
  4317. WARN(connector->base.dpms == DRM_MODE_DPMS_OFF,
  4318. "wrong connector dpms state\n");
  4319. WARN(connector->base.encoder != &encoder->base,
  4320. "active connector not linked to encoder\n");
  4321. if (encoder) {
  4322. WARN(!encoder->connectors_active,
  4323. "encoder->connectors_active not set\n");
  4324. encoder_enabled = encoder->get_hw_state(encoder, &pipe);
  4325. WARN(!encoder_enabled, "encoder not enabled\n");
  4326. if (WARN_ON(!encoder->base.crtc))
  4327. return;
  4328. crtc = encoder->base.crtc;
  4329. WARN(!crtc->enabled, "crtc not enabled\n");
  4330. WARN(!to_intel_crtc(crtc)->active, "crtc not active\n");
  4331. WARN(pipe != to_intel_crtc(crtc)->pipe,
  4332. "encoder active on the wrong pipe\n");
  4333. }
  4334. }
  4335. }
  4336. /* Even simpler default implementation, if there's really no special case to
  4337. * consider. */
  4338. void intel_connector_dpms(struct drm_connector *connector, int mode)
  4339. {
  4340. /* All the simple cases only support two dpms states. */
  4341. if (mode != DRM_MODE_DPMS_ON)
  4342. mode = DRM_MODE_DPMS_OFF;
  4343. if (mode == connector->dpms)
  4344. return;
  4345. connector->dpms = mode;
  4346. /* Only need to change hw state when actually enabled */
  4347. if (connector->encoder)
  4348. intel_encoder_dpms(to_intel_encoder(connector->encoder), mode);
  4349. intel_modeset_check_state(connector->dev);
  4350. }
  4351. /* Simple connector->get_hw_state implementation for encoders that support only
  4352. * one connector and no cloning and hence the encoder state determines the state
  4353. * of the connector. */
  4354. bool intel_connector_get_hw_state(struct intel_connector *connector)
  4355. {
  4356. enum pipe pipe = 0;
  4357. struct intel_encoder *encoder = connector->encoder;
  4358. return encoder->get_hw_state(encoder, &pipe);
  4359. }
  4360. static bool ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe,
  4361. struct intel_crtc_config *pipe_config)
  4362. {
  4363. struct drm_i915_private *dev_priv = dev->dev_private;
  4364. struct intel_crtc *pipe_B_crtc =
  4365. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_B]);
  4366. DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
  4367. pipe_name(pipe), pipe_config->fdi_lanes);
  4368. if (pipe_config->fdi_lanes > 4) {
  4369. DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
  4370. pipe_name(pipe), pipe_config->fdi_lanes);
  4371. return false;
  4372. }
  4373. if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
  4374. if (pipe_config->fdi_lanes > 2) {
  4375. DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
  4376. pipe_config->fdi_lanes);
  4377. return false;
  4378. } else {
  4379. return true;
  4380. }
  4381. }
  4382. if (INTEL_INFO(dev)->num_pipes == 2)
  4383. return true;
  4384. /* Ivybridge 3 pipe is really complicated */
  4385. switch (pipe) {
  4386. case PIPE_A:
  4387. return true;
  4388. case PIPE_B:
  4389. if (dev_priv->pipe_to_crtc_mapping[PIPE_C]->enabled &&
  4390. pipe_config->fdi_lanes > 2) {
  4391. DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
  4392. pipe_name(pipe), pipe_config->fdi_lanes);
  4393. return false;
  4394. }
  4395. return true;
  4396. case PIPE_C:
  4397. if (!pipe_has_enabled_pch(pipe_B_crtc) ||
  4398. pipe_B_crtc->config.fdi_lanes <= 2) {
  4399. if (pipe_config->fdi_lanes > 2) {
  4400. DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
  4401. pipe_name(pipe), pipe_config->fdi_lanes);
  4402. return false;
  4403. }
  4404. } else {
  4405. DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
  4406. return false;
  4407. }
  4408. return true;
  4409. default:
  4410. BUG();
  4411. }
  4412. }
  4413. #define RETRY 1
  4414. static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc,
  4415. struct intel_crtc_config *pipe_config)
  4416. {
  4417. struct drm_device *dev = intel_crtc->base.dev;
  4418. struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
  4419. int lane, link_bw, fdi_dotclock;
  4420. bool setup_ok, needs_recompute = false;
  4421. retry:
  4422. /* FDI is a binary signal running at ~2.7GHz, encoding
  4423. * each output octet as 10 bits. The actual frequency
  4424. * is stored as a divider into a 100MHz clock, and the
  4425. * mode pixel clock is stored in units of 1KHz.
  4426. * Hence the bw of each lane in terms of the mode signal
  4427. * is:
  4428. */
  4429. link_bw = intel_fdi_link_freq(dev) * MHz(100)/KHz(1)/10;
  4430. fdi_dotclock = adjusted_mode->crtc_clock;
  4431. lane = ironlake_get_lanes_required(fdi_dotclock, link_bw,
  4432. pipe_config->pipe_bpp);
  4433. pipe_config->fdi_lanes = lane;
  4434. intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock,
  4435. link_bw, &pipe_config->fdi_m_n);
  4436. setup_ok = ironlake_check_fdi_lanes(intel_crtc->base.dev,
  4437. intel_crtc->pipe, pipe_config);
  4438. if (!setup_ok && pipe_config->pipe_bpp > 6*3) {
  4439. pipe_config->pipe_bpp -= 2*3;
  4440. DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
  4441. pipe_config->pipe_bpp);
  4442. needs_recompute = true;
  4443. pipe_config->bw_constrained = true;
  4444. goto retry;
  4445. }
  4446. if (needs_recompute)
  4447. return RETRY;
  4448. return setup_ok ? 0 : -EINVAL;
  4449. }
  4450. static void hsw_compute_ips_config(struct intel_crtc *crtc,
  4451. struct intel_crtc_config *pipe_config)
  4452. {
  4453. pipe_config->ips_enabled = i915.enable_ips &&
  4454. hsw_crtc_supports_ips(crtc) &&
  4455. pipe_config->pipe_bpp <= 24;
  4456. }
  4457. static int intel_crtc_compute_config(struct intel_crtc *crtc,
  4458. struct intel_crtc_config *pipe_config)
  4459. {
  4460. struct drm_device *dev = crtc->base.dev;
  4461. struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
  4462. /* FIXME should check pixel clock limits on all platforms */
  4463. if (INTEL_INFO(dev)->gen < 4) {
  4464. struct drm_i915_private *dev_priv = dev->dev_private;
  4465. int clock_limit =
  4466. dev_priv->display.get_display_clock_speed(dev);
  4467. /*
  4468. * Enable pixel doubling when the dot clock
  4469. * is > 90% of the (display) core speed.
  4470. *
  4471. * GDG double wide on either pipe,
  4472. * otherwise pipe A only.
  4473. */
  4474. if ((crtc->pipe == PIPE_A || IS_I915G(dev)) &&
  4475. adjusted_mode->crtc_clock > clock_limit * 9 / 10) {
  4476. clock_limit *= 2;
  4477. pipe_config->double_wide = true;
  4478. }
  4479. if (adjusted_mode->crtc_clock > clock_limit * 9 / 10)
  4480. return -EINVAL;
  4481. }
  4482. /*
  4483. * Pipe horizontal size must be even in:
  4484. * - DVO ganged mode
  4485. * - LVDS dual channel mode
  4486. * - Double wide pipe
  4487. */
  4488. if ((intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) &&
  4489. intel_is_dual_link_lvds(dev)) || pipe_config->double_wide)
  4490. pipe_config->pipe_src_w &= ~1;
  4491. /* Cantiga+ cannot handle modes with a hsync front porch of 0.
  4492. * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
  4493. */
  4494. if ((INTEL_INFO(dev)->gen > 4 || IS_G4X(dev)) &&
  4495. adjusted_mode->hsync_start == adjusted_mode->hdisplay)
  4496. return -EINVAL;
  4497. if ((IS_G4X(dev) || IS_VALLEYVIEW(dev)) && pipe_config->pipe_bpp > 10*3) {
  4498. pipe_config->pipe_bpp = 10*3; /* 12bpc is gen5+ */
  4499. } else if (INTEL_INFO(dev)->gen <= 4 && pipe_config->pipe_bpp > 8*3) {
  4500. /* only a 8bpc pipe, with 6bpc dither through the panel fitter
  4501. * for lvds. */
  4502. pipe_config->pipe_bpp = 8*3;
  4503. }
  4504. if (HAS_IPS(dev))
  4505. hsw_compute_ips_config(crtc, pipe_config);
  4506. /*
  4507. * XXX: PCH/WRPLL clock sharing is done in ->mode_set, so make sure the
  4508. * old clock survives for now.
  4509. */
  4510. if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev) || HAS_DDI(dev))
  4511. pipe_config->shared_dpll = crtc->config.shared_dpll;
  4512. if (pipe_config->has_pch_encoder)
  4513. return ironlake_fdi_compute_config(crtc, pipe_config);
  4514. return 0;
  4515. }
  4516. static int valleyview_get_display_clock_speed(struct drm_device *dev)
  4517. {
  4518. struct drm_i915_private *dev_priv = dev->dev_private;
  4519. int vco = valleyview_get_vco(dev_priv);
  4520. u32 val;
  4521. int divider;
  4522. /* FIXME: Punit isn't quite ready yet */
  4523. if (IS_CHERRYVIEW(dev))
  4524. return 400000;
  4525. mutex_lock(&dev_priv->dpio_lock);
  4526. val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL);
  4527. mutex_unlock(&dev_priv->dpio_lock);
  4528. divider = val & DISPLAY_FREQUENCY_VALUES;
  4529. WARN((val & DISPLAY_FREQUENCY_STATUS) !=
  4530. (divider << DISPLAY_FREQUENCY_STATUS_SHIFT),
  4531. "cdclk change in progress\n");
  4532. return DIV_ROUND_CLOSEST(vco << 1, divider + 1);
  4533. }
  4534. static int i945_get_display_clock_speed(struct drm_device *dev)
  4535. {
  4536. return 400000;
  4537. }
  4538. static int i915_get_display_clock_speed(struct drm_device *dev)
  4539. {
  4540. return 333000;
  4541. }
  4542. static int i9xx_misc_get_display_clock_speed(struct drm_device *dev)
  4543. {
  4544. return 200000;
  4545. }
  4546. static int pnv_get_display_clock_speed(struct drm_device *dev)
  4547. {
  4548. u16 gcfgc = 0;
  4549. pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
  4550. switch (gcfgc & GC_DISPLAY_CLOCK_MASK) {
  4551. case GC_DISPLAY_CLOCK_267_MHZ_PNV:
  4552. return 267000;
  4553. case GC_DISPLAY_CLOCK_333_MHZ_PNV:
  4554. return 333000;
  4555. case GC_DISPLAY_CLOCK_444_MHZ_PNV:
  4556. return 444000;
  4557. case GC_DISPLAY_CLOCK_200_MHZ_PNV:
  4558. return 200000;
  4559. default:
  4560. DRM_ERROR("Unknown pnv display core clock 0x%04x\n", gcfgc);
  4561. case GC_DISPLAY_CLOCK_133_MHZ_PNV:
  4562. return 133000;
  4563. case GC_DISPLAY_CLOCK_167_MHZ_PNV:
  4564. return 167000;
  4565. }
  4566. }
  4567. static int i915gm_get_display_clock_speed(struct drm_device *dev)
  4568. {
  4569. u16 gcfgc = 0;
  4570. pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
  4571. if (gcfgc & GC_LOW_FREQUENCY_ENABLE)
  4572. return 133000;
  4573. else {
  4574. switch (gcfgc & GC_DISPLAY_CLOCK_MASK) {
  4575. case GC_DISPLAY_CLOCK_333_MHZ:
  4576. return 333000;
  4577. default:
  4578. case GC_DISPLAY_CLOCK_190_200_MHZ:
  4579. return 190000;
  4580. }
  4581. }
  4582. }
  4583. static int i865_get_display_clock_speed(struct drm_device *dev)
  4584. {
  4585. return 266000;
  4586. }
  4587. static int i855_get_display_clock_speed(struct drm_device *dev)
  4588. {
  4589. u16 hpllcc = 0;
  4590. /* Assume that the hardware is in the high speed state. This
  4591. * should be the default.
  4592. */
  4593. switch (hpllcc & GC_CLOCK_CONTROL_MASK) {
  4594. case GC_CLOCK_133_200:
  4595. case GC_CLOCK_100_200:
  4596. return 200000;
  4597. case GC_CLOCK_166_250:
  4598. return 250000;
  4599. case GC_CLOCK_100_133:
  4600. return 133000;
  4601. }
  4602. /* Shouldn't happen */
  4603. return 0;
  4604. }
  4605. static int i830_get_display_clock_speed(struct drm_device *dev)
  4606. {
  4607. return 133000;
  4608. }
  4609. static void
  4610. intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den)
  4611. {
  4612. while (*num > DATA_LINK_M_N_MASK ||
  4613. *den > DATA_LINK_M_N_MASK) {
  4614. *num >>= 1;
  4615. *den >>= 1;
  4616. }
  4617. }
  4618. static void compute_m_n(unsigned int m, unsigned int n,
  4619. uint32_t *ret_m, uint32_t *ret_n)
  4620. {
  4621. *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
  4622. *ret_m = div_u64((uint64_t) m * *ret_n, n);
  4623. intel_reduce_m_n_ratio(ret_m, ret_n);
  4624. }
  4625. void
  4626. intel_link_compute_m_n(int bits_per_pixel, int nlanes,
  4627. int pixel_clock, int link_clock,
  4628. struct intel_link_m_n *m_n)
  4629. {
  4630. m_n->tu = 64;
  4631. compute_m_n(bits_per_pixel * pixel_clock,
  4632. link_clock * nlanes * 8,
  4633. &m_n->gmch_m, &m_n->gmch_n);
  4634. compute_m_n(pixel_clock, link_clock,
  4635. &m_n->link_m, &m_n->link_n);
  4636. }
  4637. static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
  4638. {
  4639. if (i915.panel_use_ssc >= 0)
  4640. return i915.panel_use_ssc != 0;
  4641. return dev_priv->vbt.lvds_use_ssc
  4642. && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE);
  4643. }
  4644. static int i9xx_get_refclk(struct drm_crtc *crtc, int num_connectors)
  4645. {
  4646. struct drm_device *dev = crtc->dev;
  4647. struct drm_i915_private *dev_priv = dev->dev_private;
  4648. int refclk;
  4649. if (IS_VALLEYVIEW(dev)) {
  4650. refclk = 100000;
  4651. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
  4652. intel_panel_use_ssc(dev_priv) && num_connectors < 2) {
  4653. refclk = dev_priv->vbt.lvds_ssc_freq;
  4654. DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
  4655. } else if (!IS_GEN2(dev)) {
  4656. refclk = 96000;
  4657. } else {
  4658. refclk = 48000;
  4659. }
  4660. return refclk;
  4661. }
  4662. static uint32_t pnv_dpll_compute_fp(struct dpll *dpll)
  4663. {
  4664. return (1 << dpll->n) << 16 | dpll->m2;
  4665. }
  4666. static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll)
  4667. {
  4668. return dpll->n << 16 | dpll->m1 << 8 | dpll->m2;
  4669. }
  4670. static void i9xx_update_pll_dividers(struct intel_crtc *crtc,
  4671. intel_clock_t *reduced_clock)
  4672. {
  4673. struct drm_device *dev = crtc->base.dev;
  4674. u32 fp, fp2 = 0;
  4675. if (IS_PINEVIEW(dev)) {
  4676. fp = pnv_dpll_compute_fp(&crtc->config.dpll);
  4677. if (reduced_clock)
  4678. fp2 = pnv_dpll_compute_fp(reduced_clock);
  4679. } else {
  4680. fp = i9xx_dpll_compute_fp(&crtc->config.dpll);
  4681. if (reduced_clock)
  4682. fp2 = i9xx_dpll_compute_fp(reduced_clock);
  4683. }
  4684. crtc->config.dpll_hw_state.fp0 = fp;
  4685. crtc->lowfreq_avail = false;
  4686. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) &&
  4687. reduced_clock && i915.powersave) {
  4688. crtc->config.dpll_hw_state.fp1 = fp2;
  4689. crtc->lowfreq_avail = true;
  4690. } else {
  4691. crtc->config.dpll_hw_state.fp1 = fp;
  4692. }
  4693. }
  4694. static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe
  4695. pipe)
  4696. {
  4697. u32 reg_val;
  4698. /*
  4699. * PLLB opamp always calibrates to max value of 0x3f, force enable it
  4700. * and set it to a reasonable value instead.
  4701. */
  4702. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
  4703. reg_val &= 0xffffff00;
  4704. reg_val |= 0x00000030;
  4705. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
  4706. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
  4707. reg_val &= 0x8cffffff;
  4708. reg_val = 0x8c000000;
  4709. vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
  4710. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
  4711. reg_val &= 0xffffff00;
  4712. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
  4713. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
  4714. reg_val &= 0x00ffffff;
  4715. reg_val |= 0xb0000000;
  4716. vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
  4717. }
  4718. static void intel_pch_transcoder_set_m_n(struct intel_crtc *crtc,
  4719. struct intel_link_m_n *m_n)
  4720. {
  4721. struct drm_device *dev = crtc->base.dev;
  4722. struct drm_i915_private *dev_priv = dev->dev_private;
  4723. int pipe = crtc->pipe;
  4724. I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
  4725. I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n);
  4726. I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m);
  4727. I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n);
  4728. }
  4729. static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc,
  4730. struct intel_link_m_n *m_n,
  4731. struct intel_link_m_n *m2_n2)
  4732. {
  4733. struct drm_device *dev = crtc->base.dev;
  4734. struct drm_i915_private *dev_priv = dev->dev_private;
  4735. int pipe = crtc->pipe;
  4736. enum transcoder transcoder = crtc->config.cpu_transcoder;
  4737. if (INTEL_INFO(dev)->gen >= 5) {
  4738. I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m);
  4739. I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n);
  4740. I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m);
  4741. I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n);
  4742. /* M2_N2 registers to be set only for gen < 8 (M2_N2 available
  4743. * for gen < 8) and if DRRS is supported (to make sure the
  4744. * registers are not unnecessarily accessed).
  4745. */
  4746. if (m2_n2 && INTEL_INFO(dev)->gen < 8 &&
  4747. crtc->config.has_drrs) {
  4748. I915_WRITE(PIPE_DATA_M2(transcoder),
  4749. TU_SIZE(m2_n2->tu) | m2_n2->gmch_m);
  4750. I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n);
  4751. I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m);
  4752. I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n);
  4753. }
  4754. } else {
  4755. I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
  4756. I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n);
  4757. I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m);
  4758. I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n);
  4759. }
  4760. }
  4761. void intel_dp_set_m_n(struct intel_crtc *crtc)
  4762. {
  4763. if (crtc->config.has_pch_encoder)
  4764. intel_pch_transcoder_set_m_n(crtc, &crtc->config.dp_m_n);
  4765. else
  4766. intel_cpu_transcoder_set_m_n(crtc, &crtc->config.dp_m_n,
  4767. &crtc->config.dp_m2_n2);
  4768. }
  4769. static void vlv_update_pll(struct intel_crtc *crtc)
  4770. {
  4771. u32 dpll, dpll_md;
  4772. /*
  4773. * Enable DPIO clock input. We should never disable the reference
  4774. * clock for pipe B, since VGA hotplug / manual detection depends
  4775. * on it.
  4776. */
  4777. dpll = DPLL_EXT_BUFFER_ENABLE_VLV | DPLL_REFA_CLK_ENABLE_VLV |
  4778. DPLL_VGA_MODE_DIS | DPLL_INTEGRATED_CLOCK_VLV;
  4779. /* We should never disable this, set it here for state tracking */
  4780. if (crtc->pipe == PIPE_B)
  4781. dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
  4782. dpll |= DPLL_VCO_ENABLE;
  4783. crtc->config.dpll_hw_state.dpll = dpll;
  4784. dpll_md = (crtc->config.pixel_multiplier - 1)
  4785. << DPLL_MD_UDI_MULTIPLIER_SHIFT;
  4786. crtc->config.dpll_hw_state.dpll_md = dpll_md;
  4787. }
  4788. static void vlv_prepare_pll(struct intel_crtc *crtc)
  4789. {
  4790. struct drm_device *dev = crtc->base.dev;
  4791. struct drm_i915_private *dev_priv = dev->dev_private;
  4792. int pipe = crtc->pipe;
  4793. u32 mdiv;
  4794. u32 bestn, bestm1, bestm2, bestp1, bestp2;
  4795. u32 coreclk, reg_val;
  4796. mutex_lock(&dev_priv->dpio_lock);
  4797. bestn = crtc->config.dpll.n;
  4798. bestm1 = crtc->config.dpll.m1;
  4799. bestm2 = crtc->config.dpll.m2;
  4800. bestp1 = crtc->config.dpll.p1;
  4801. bestp2 = crtc->config.dpll.p2;
  4802. /* See eDP HDMI DPIO driver vbios notes doc */
  4803. /* PLL B needs special handling */
  4804. if (pipe == PIPE_B)
  4805. vlv_pllb_recal_opamp(dev_priv, pipe);
  4806. /* Set up Tx target for periodic Rcomp update */
  4807. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f);
  4808. /* Disable target IRef on PLL */
  4809. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe));
  4810. reg_val &= 0x00ffffff;
  4811. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val);
  4812. /* Disable fast lock */
  4813. vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610);
  4814. /* Set idtafcrecal before PLL is enabled */
  4815. mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK));
  4816. mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT));
  4817. mdiv |= ((bestn << DPIO_N_SHIFT));
  4818. mdiv |= (1 << DPIO_K_SHIFT);
  4819. /*
  4820. * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
  4821. * but we don't support that).
  4822. * Note: don't use the DAC post divider as it seems unstable.
  4823. */
  4824. mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT);
  4825. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
  4826. mdiv |= DPIO_ENABLE_CALIBRATION;
  4827. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
  4828. /* Set HBR and RBR LPF coefficients */
  4829. if (crtc->config.port_clock == 162000 ||
  4830. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_ANALOG) ||
  4831. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_HDMI))
  4832. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
  4833. 0x009f0003);
  4834. else
  4835. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
  4836. 0x00d0000f);
  4837. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_EDP) ||
  4838. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DISPLAYPORT)) {
  4839. /* Use SSC source */
  4840. if (pipe == PIPE_A)
  4841. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
  4842. 0x0df40000);
  4843. else
  4844. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
  4845. 0x0df70000);
  4846. } else { /* HDMI or VGA */
  4847. /* Use bend source */
  4848. if (pipe == PIPE_A)
  4849. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
  4850. 0x0df70000);
  4851. else
  4852. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
  4853. 0x0df40000);
  4854. }
  4855. coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe));
  4856. coreclk = (coreclk & 0x0000ff00) | 0x01c00000;
  4857. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DISPLAYPORT) ||
  4858. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_EDP))
  4859. coreclk |= 0x01000000;
  4860. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk);
  4861. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000);
  4862. mutex_unlock(&dev_priv->dpio_lock);
  4863. }
  4864. static void chv_update_pll(struct intel_crtc *crtc)
  4865. {
  4866. crtc->config.dpll_hw_state.dpll = DPLL_SSC_REF_CLOCK_CHV |
  4867. DPLL_REFA_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS |
  4868. DPLL_VCO_ENABLE;
  4869. if (crtc->pipe != PIPE_A)
  4870. crtc->config.dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
  4871. crtc->config.dpll_hw_state.dpll_md =
  4872. (crtc->config.pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
  4873. }
  4874. static void chv_prepare_pll(struct intel_crtc *crtc)
  4875. {
  4876. struct drm_device *dev = crtc->base.dev;
  4877. struct drm_i915_private *dev_priv = dev->dev_private;
  4878. int pipe = crtc->pipe;
  4879. int dpll_reg = DPLL(crtc->pipe);
  4880. enum dpio_channel port = vlv_pipe_to_channel(pipe);
  4881. u32 loopfilter, intcoeff;
  4882. u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac;
  4883. int refclk;
  4884. bestn = crtc->config.dpll.n;
  4885. bestm2_frac = crtc->config.dpll.m2 & 0x3fffff;
  4886. bestm1 = crtc->config.dpll.m1;
  4887. bestm2 = crtc->config.dpll.m2 >> 22;
  4888. bestp1 = crtc->config.dpll.p1;
  4889. bestp2 = crtc->config.dpll.p2;
  4890. /*
  4891. * Enable Refclk and SSC
  4892. */
  4893. I915_WRITE(dpll_reg,
  4894. crtc->config.dpll_hw_state.dpll & ~DPLL_VCO_ENABLE);
  4895. mutex_lock(&dev_priv->dpio_lock);
  4896. /* p1 and p2 divider */
  4897. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port),
  4898. 5 << DPIO_CHV_S1_DIV_SHIFT |
  4899. bestp1 << DPIO_CHV_P1_DIV_SHIFT |
  4900. bestp2 << DPIO_CHV_P2_DIV_SHIFT |
  4901. 1 << DPIO_CHV_K_DIV_SHIFT);
  4902. /* Feedback post-divider - m2 */
  4903. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2);
  4904. /* Feedback refclk divider - n and m1 */
  4905. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port),
  4906. DPIO_CHV_M1_DIV_BY_2 |
  4907. 1 << DPIO_CHV_N_DIV_SHIFT);
  4908. /* M2 fraction division */
  4909. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac);
  4910. /* M2 fraction division enable */
  4911. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port),
  4912. DPIO_CHV_FRAC_DIV_EN |
  4913. (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT));
  4914. /* Loop filter */
  4915. refclk = i9xx_get_refclk(&crtc->base, 0);
  4916. loopfilter = 5 << DPIO_CHV_PROP_COEFF_SHIFT |
  4917. 2 << DPIO_CHV_GAIN_CTRL_SHIFT;
  4918. if (refclk == 100000)
  4919. intcoeff = 11;
  4920. else if (refclk == 38400)
  4921. intcoeff = 10;
  4922. else
  4923. intcoeff = 9;
  4924. loopfilter |= intcoeff << DPIO_CHV_INT_COEFF_SHIFT;
  4925. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter);
  4926. /* AFC Recal */
  4927. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port),
  4928. vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) |
  4929. DPIO_AFC_RECAL);
  4930. mutex_unlock(&dev_priv->dpio_lock);
  4931. }
  4932. static void i9xx_update_pll(struct intel_crtc *crtc,
  4933. intel_clock_t *reduced_clock,
  4934. int num_connectors)
  4935. {
  4936. struct drm_device *dev = crtc->base.dev;
  4937. struct drm_i915_private *dev_priv = dev->dev_private;
  4938. u32 dpll;
  4939. bool is_sdvo;
  4940. struct dpll *clock = &crtc->config.dpll;
  4941. i9xx_update_pll_dividers(crtc, reduced_clock);
  4942. is_sdvo = intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_SDVO) ||
  4943. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_HDMI);
  4944. dpll = DPLL_VGA_MODE_DIS;
  4945. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS))
  4946. dpll |= DPLLB_MODE_LVDS;
  4947. else
  4948. dpll |= DPLLB_MODE_DAC_SERIAL;
  4949. if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) {
  4950. dpll |= (crtc->config.pixel_multiplier - 1)
  4951. << SDVO_MULTIPLIER_SHIFT_HIRES;
  4952. }
  4953. if (is_sdvo)
  4954. dpll |= DPLL_SDVO_HIGH_SPEED;
  4955. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DISPLAYPORT))
  4956. dpll |= DPLL_SDVO_HIGH_SPEED;
  4957. /* compute bitmask from p1 value */
  4958. if (IS_PINEVIEW(dev))
  4959. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
  4960. else {
  4961. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  4962. if (IS_G4X(dev) && reduced_clock)
  4963. dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
  4964. }
  4965. switch (clock->p2) {
  4966. case 5:
  4967. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
  4968. break;
  4969. case 7:
  4970. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
  4971. break;
  4972. case 10:
  4973. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
  4974. break;
  4975. case 14:
  4976. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
  4977. break;
  4978. }
  4979. if (INTEL_INFO(dev)->gen >= 4)
  4980. dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
  4981. if (crtc->config.sdvo_tv_clock)
  4982. dpll |= PLL_REF_INPUT_TVCLKINBC;
  4983. else if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) &&
  4984. intel_panel_use_ssc(dev_priv) && num_connectors < 2)
  4985. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  4986. else
  4987. dpll |= PLL_REF_INPUT_DREFCLK;
  4988. dpll |= DPLL_VCO_ENABLE;
  4989. crtc->config.dpll_hw_state.dpll = dpll;
  4990. if (INTEL_INFO(dev)->gen >= 4) {
  4991. u32 dpll_md = (crtc->config.pixel_multiplier - 1)
  4992. << DPLL_MD_UDI_MULTIPLIER_SHIFT;
  4993. crtc->config.dpll_hw_state.dpll_md = dpll_md;
  4994. }
  4995. }
  4996. static void i8xx_update_pll(struct intel_crtc *crtc,
  4997. intel_clock_t *reduced_clock,
  4998. int num_connectors)
  4999. {
  5000. struct drm_device *dev = crtc->base.dev;
  5001. struct drm_i915_private *dev_priv = dev->dev_private;
  5002. u32 dpll;
  5003. struct dpll *clock = &crtc->config.dpll;
  5004. i9xx_update_pll_dividers(crtc, reduced_clock);
  5005. dpll = DPLL_VGA_MODE_DIS;
  5006. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS)) {
  5007. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  5008. } else {
  5009. if (clock->p1 == 2)
  5010. dpll |= PLL_P1_DIVIDE_BY_TWO;
  5011. else
  5012. dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  5013. if (clock->p2 == 4)
  5014. dpll |= PLL_P2_DIVIDE_BY_4;
  5015. }
  5016. if (!IS_I830(dev) && intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DVO))
  5017. dpll |= DPLL_DVO_2X_MODE;
  5018. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) &&
  5019. intel_panel_use_ssc(dev_priv) && num_connectors < 2)
  5020. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  5021. else
  5022. dpll |= PLL_REF_INPUT_DREFCLK;
  5023. dpll |= DPLL_VCO_ENABLE;
  5024. crtc->config.dpll_hw_state.dpll = dpll;
  5025. }
  5026. static void intel_set_pipe_timings(struct intel_crtc *intel_crtc)
  5027. {
  5028. struct drm_device *dev = intel_crtc->base.dev;
  5029. struct drm_i915_private *dev_priv = dev->dev_private;
  5030. enum pipe pipe = intel_crtc->pipe;
  5031. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  5032. struct drm_display_mode *adjusted_mode =
  5033. &intel_crtc->config.adjusted_mode;
  5034. uint32_t crtc_vtotal, crtc_vblank_end;
  5035. int vsyncshift = 0;
  5036. /* We need to be careful not to changed the adjusted mode, for otherwise
  5037. * the hw state checker will get angry at the mismatch. */
  5038. crtc_vtotal = adjusted_mode->crtc_vtotal;
  5039. crtc_vblank_end = adjusted_mode->crtc_vblank_end;
  5040. if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
  5041. /* the chip adds 2 halflines automatically */
  5042. crtc_vtotal -= 1;
  5043. crtc_vblank_end -= 1;
  5044. if (intel_pipe_has_type(&intel_crtc->base, INTEL_OUTPUT_SDVO))
  5045. vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2;
  5046. else
  5047. vsyncshift = adjusted_mode->crtc_hsync_start -
  5048. adjusted_mode->crtc_htotal / 2;
  5049. if (vsyncshift < 0)
  5050. vsyncshift += adjusted_mode->crtc_htotal;
  5051. }
  5052. if (INTEL_INFO(dev)->gen > 3)
  5053. I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift);
  5054. I915_WRITE(HTOTAL(cpu_transcoder),
  5055. (adjusted_mode->crtc_hdisplay - 1) |
  5056. ((adjusted_mode->crtc_htotal - 1) << 16));
  5057. I915_WRITE(HBLANK(cpu_transcoder),
  5058. (adjusted_mode->crtc_hblank_start - 1) |
  5059. ((adjusted_mode->crtc_hblank_end - 1) << 16));
  5060. I915_WRITE(HSYNC(cpu_transcoder),
  5061. (adjusted_mode->crtc_hsync_start - 1) |
  5062. ((adjusted_mode->crtc_hsync_end - 1) << 16));
  5063. I915_WRITE(VTOTAL(cpu_transcoder),
  5064. (adjusted_mode->crtc_vdisplay - 1) |
  5065. ((crtc_vtotal - 1) << 16));
  5066. I915_WRITE(VBLANK(cpu_transcoder),
  5067. (adjusted_mode->crtc_vblank_start - 1) |
  5068. ((crtc_vblank_end - 1) << 16));
  5069. I915_WRITE(VSYNC(cpu_transcoder),
  5070. (adjusted_mode->crtc_vsync_start - 1) |
  5071. ((adjusted_mode->crtc_vsync_end - 1) << 16));
  5072. /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
  5073. * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
  5074. * documented on the DDI_FUNC_CTL register description, EDP Input Select
  5075. * bits. */
  5076. if (IS_HASWELL(dev) && cpu_transcoder == TRANSCODER_EDP &&
  5077. (pipe == PIPE_B || pipe == PIPE_C))
  5078. I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder)));
  5079. /* pipesrc controls the size that is scaled from, which should
  5080. * always be the user's requested size.
  5081. */
  5082. I915_WRITE(PIPESRC(pipe),
  5083. ((intel_crtc->config.pipe_src_w - 1) << 16) |
  5084. (intel_crtc->config.pipe_src_h - 1));
  5085. }
  5086. static void intel_get_pipe_timings(struct intel_crtc *crtc,
  5087. struct intel_crtc_config *pipe_config)
  5088. {
  5089. struct drm_device *dev = crtc->base.dev;
  5090. struct drm_i915_private *dev_priv = dev->dev_private;
  5091. enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
  5092. uint32_t tmp;
  5093. tmp = I915_READ(HTOTAL(cpu_transcoder));
  5094. pipe_config->adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1;
  5095. pipe_config->adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1;
  5096. tmp = I915_READ(HBLANK(cpu_transcoder));
  5097. pipe_config->adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1;
  5098. pipe_config->adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1;
  5099. tmp = I915_READ(HSYNC(cpu_transcoder));
  5100. pipe_config->adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1;
  5101. pipe_config->adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1;
  5102. tmp = I915_READ(VTOTAL(cpu_transcoder));
  5103. pipe_config->adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1;
  5104. pipe_config->adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1;
  5105. tmp = I915_READ(VBLANK(cpu_transcoder));
  5106. pipe_config->adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1;
  5107. pipe_config->adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1;
  5108. tmp = I915_READ(VSYNC(cpu_transcoder));
  5109. pipe_config->adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1;
  5110. pipe_config->adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1;
  5111. if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) {
  5112. pipe_config->adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE;
  5113. pipe_config->adjusted_mode.crtc_vtotal += 1;
  5114. pipe_config->adjusted_mode.crtc_vblank_end += 1;
  5115. }
  5116. tmp = I915_READ(PIPESRC(crtc->pipe));
  5117. pipe_config->pipe_src_h = (tmp & 0xffff) + 1;
  5118. pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1;
  5119. pipe_config->requested_mode.vdisplay = pipe_config->pipe_src_h;
  5120. pipe_config->requested_mode.hdisplay = pipe_config->pipe_src_w;
  5121. }
  5122. void intel_mode_from_pipe_config(struct drm_display_mode *mode,
  5123. struct intel_crtc_config *pipe_config)
  5124. {
  5125. mode->hdisplay = pipe_config->adjusted_mode.crtc_hdisplay;
  5126. mode->htotal = pipe_config->adjusted_mode.crtc_htotal;
  5127. mode->hsync_start = pipe_config->adjusted_mode.crtc_hsync_start;
  5128. mode->hsync_end = pipe_config->adjusted_mode.crtc_hsync_end;
  5129. mode->vdisplay = pipe_config->adjusted_mode.crtc_vdisplay;
  5130. mode->vtotal = pipe_config->adjusted_mode.crtc_vtotal;
  5131. mode->vsync_start = pipe_config->adjusted_mode.crtc_vsync_start;
  5132. mode->vsync_end = pipe_config->adjusted_mode.crtc_vsync_end;
  5133. mode->flags = pipe_config->adjusted_mode.flags;
  5134. mode->clock = pipe_config->adjusted_mode.crtc_clock;
  5135. mode->flags |= pipe_config->adjusted_mode.flags;
  5136. }
  5137. static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc)
  5138. {
  5139. struct drm_device *dev = intel_crtc->base.dev;
  5140. struct drm_i915_private *dev_priv = dev->dev_private;
  5141. uint32_t pipeconf;
  5142. pipeconf = 0;
  5143. if ((intel_crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) ||
  5144. (intel_crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))
  5145. pipeconf |= I915_READ(PIPECONF(intel_crtc->pipe)) & PIPECONF_ENABLE;
  5146. if (intel_crtc->config.double_wide)
  5147. pipeconf |= PIPECONF_DOUBLE_WIDE;
  5148. /* only g4x and later have fancy bpc/dither controls */
  5149. if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) {
  5150. /* Bspec claims that we can't use dithering for 30bpp pipes. */
  5151. if (intel_crtc->config.dither && intel_crtc->config.pipe_bpp != 30)
  5152. pipeconf |= PIPECONF_DITHER_EN |
  5153. PIPECONF_DITHER_TYPE_SP;
  5154. switch (intel_crtc->config.pipe_bpp) {
  5155. case 18:
  5156. pipeconf |= PIPECONF_6BPC;
  5157. break;
  5158. case 24:
  5159. pipeconf |= PIPECONF_8BPC;
  5160. break;
  5161. case 30:
  5162. pipeconf |= PIPECONF_10BPC;
  5163. break;
  5164. default:
  5165. /* Case prevented by intel_choose_pipe_bpp_dither. */
  5166. BUG();
  5167. }
  5168. }
  5169. if (HAS_PIPE_CXSR(dev)) {
  5170. if (intel_crtc->lowfreq_avail) {
  5171. DRM_DEBUG_KMS("enabling CxSR downclocking\n");
  5172. pipeconf |= PIPECONF_CXSR_DOWNCLOCK;
  5173. } else {
  5174. DRM_DEBUG_KMS("disabling CxSR downclocking\n");
  5175. }
  5176. }
  5177. if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
  5178. if (INTEL_INFO(dev)->gen < 4 ||
  5179. intel_pipe_has_type(&intel_crtc->base, INTEL_OUTPUT_SDVO))
  5180. pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
  5181. else
  5182. pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT;
  5183. } else
  5184. pipeconf |= PIPECONF_PROGRESSIVE;
  5185. if (IS_VALLEYVIEW(dev) && intel_crtc->config.limited_color_range)
  5186. pipeconf |= PIPECONF_COLOR_RANGE_SELECT;
  5187. I915_WRITE(PIPECONF(intel_crtc->pipe), pipeconf);
  5188. POSTING_READ(PIPECONF(intel_crtc->pipe));
  5189. }
  5190. static int i9xx_crtc_mode_set(struct drm_crtc *crtc,
  5191. int x, int y,
  5192. struct drm_framebuffer *fb)
  5193. {
  5194. struct drm_device *dev = crtc->dev;
  5195. struct drm_i915_private *dev_priv = dev->dev_private;
  5196. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5197. int refclk, num_connectors = 0;
  5198. intel_clock_t clock, reduced_clock;
  5199. bool ok, has_reduced_clock = false;
  5200. bool is_lvds = false, is_dsi = false;
  5201. struct intel_encoder *encoder;
  5202. const intel_limit_t *limit;
  5203. for_each_encoder_on_crtc(dev, crtc, encoder) {
  5204. switch (encoder->type) {
  5205. case INTEL_OUTPUT_LVDS:
  5206. is_lvds = true;
  5207. break;
  5208. case INTEL_OUTPUT_DSI:
  5209. is_dsi = true;
  5210. break;
  5211. }
  5212. num_connectors++;
  5213. }
  5214. if (is_dsi)
  5215. return 0;
  5216. if (!intel_crtc->config.clock_set) {
  5217. refclk = i9xx_get_refclk(crtc, num_connectors);
  5218. /*
  5219. * Returns a set of divisors for the desired target clock with
  5220. * the given refclk, or FALSE. The returned values represent
  5221. * the clock equation: reflck * (5 * (m1 + 2) + (m2 + 2)) / (n +
  5222. * 2) / p1 / p2.
  5223. */
  5224. limit = intel_limit(crtc, refclk);
  5225. ok = dev_priv->display.find_dpll(limit, crtc,
  5226. intel_crtc->config.port_clock,
  5227. refclk, NULL, &clock);
  5228. if (!ok) {
  5229. DRM_ERROR("Couldn't find PLL settings for mode!\n");
  5230. return -EINVAL;
  5231. }
  5232. if (is_lvds && dev_priv->lvds_downclock_avail) {
  5233. /*
  5234. * Ensure we match the reduced clock's P to the target
  5235. * clock. If the clocks don't match, we can't switch
  5236. * the display clock by using the FP0/FP1. In such case
  5237. * we will disable the LVDS downclock feature.
  5238. */
  5239. has_reduced_clock =
  5240. dev_priv->display.find_dpll(limit, crtc,
  5241. dev_priv->lvds_downclock,
  5242. refclk, &clock,
  5243. &reduced_clock);
  5244. }
  5245. /* Compat-code for transition, will disappear. */
  5246. intel_crtc->config.dpll.n = clock.n;
  5247. intel_crtc->config.dpll.m1 = clock.m1;
  5248. intel_crtc->config.dpll.m2 = clock.m2;
  5249. intel_crtc->config.dpll.p1 = clock.p1;
  5250. intel_crtc->config.dpll.p2 = clock.p2;
  5251. }
  5252. if (IS_GEN2(dev)) {
  5253. i8xx_update_pll(intel_crtc,
  5254. has_reduced_clock ? &reduced_clock : NULL,
  5255. num_connectors);
  5256. } else if (IS_CHERRYVIEW(dev)) {
  5257. chv_update_pll(intel_crtc);
  5258. } else if (IS_VALLEYVIEW(dev)) {
  5259. vlv_update_pll(intel_crtc);
  5260. } else {
  5261. i9xx_update_pll(intel_crtc,
  5262. has_reduced_clock ? &reduced_clock : NULL,
  5263. num_connectors);
  5264. }
  5265. return 0;
  5266. }
  5267. static void i9xx_get_pfit_config(struct intel_crtc *crtc,
  5268. struct intel_crtc_config *pipe_config)
  5269. {
  5270. struct drm_device *dev = crtc->base.dev;
  5271. struct drm_i915_private *dev_priv = dev->dev_private;
  5272. uint32_t tmp;
  5273. if (INTEL_INFO(dev)->gen <= 3 && (IS_I830(dev) || !IS_MOBILE(dev)))
  5274. return;
  5275. tmp = I915_READ(PFIT_CONTROL);
  5276. if (!(tmp & PFIT_ENABLE))
  5277. return;
  5278. /* Check whether the pfit is attached to our pipe. */
  5279. if (INTEL_INFO(dev)->gen < 4) {
  5280. if (crtc->pipe != PIPE_B)
  5281. return;
  5282. } else {
  5283. if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT))
  5284. return;
  5285. }
  5286. pipe_config->gmch_pfit.control = tmp;
  5287. pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS);
  5288. if (INTEL_INFO(dev)->gen < 5)
  5289. pipe_config->gmch_pfit.lvds_border_bits =
  5290. I915_READ(LVDS) & LVDS_BORDER_ENABLE;
  5291. }
  5292. static void vlv_crtc_clock_get(struct intel_crtc *crtc,
  5293. struct intel_crtc_config *pipe_config)
  5294. {
  5295. struct drm_device *dev = crtc->base.dev;
  5296. struct drm_i915_private *dev_priv = dev->dev_private;
  5297. int pipe = pipe_config->cpu_transcoder;
  5298. intel_clock_t clock;
  5299. u32 mdiv;
  5300. int refclk = 100000;
  5301. /* In case of MIPI DPLL will not even be used */
  5302. if (!(pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE))
  5303. return;
  5304. mutex_lock(&dev_priv->dpio_lock);
  5305. mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe));
  5306. mutex_unlock(&dev_priv->dpio_lock);
  5307. clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7;
  5308. clock.m2 = mdiv & DPIO_M2DIV_MASK;
  5309. clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf;
  5310. clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7;
  5311. clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f;
  5312. vlv_clock(refclk, &clock);
  5313. /* clock.dot is the fast clock */
  5314. pipe_config->port_clock = clock.dot / 5;
  5315. }
  5316. static void i9xx_get_plane_config(struct intel_crtc *crtc,
  5317. struct intel_plane_config *plane_config)
  5318. {
  5319. struct drm_device *dev = crtc->base.dev;
  5320. struct drm_i915_private *dev_priv = dev->dev_private;
  5321. u32 val, base, offset;
  5322. int pipe = crtc->pipe, plane = crtc->plane;
  5323. int fourcc, pixel_format;
  5324. int aligned_height;
  5325. crtc->base.primary->fb = kzalloc(sizeof(struct intel_framebuffer), GFP_KERNEL);
  5326. if (!crtc->base.primary->fb) {
  5327. DRM_DEBUG_KMS("failed to alloc fb\n");
  5328. return;
  5329. }
  5330. val = I915_READ(DSPCNTR(plane));
  5331. if (INTEL_INFO(dev)->gen >= 4)
  5332. if (val & DISPPLANE_TILED)
  5333. plane_config->tiled = true;
  5334. pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
  5335. fourcc = intel_format_to_fourcc(pixel_format);
  5336. crtc->base.primary->fb->pixel_format = fourcc;
  5337. crtc->base.primary->fb->bits_per_pixel =
  5338. drm_format_plane_cpp(fourcc, 0) * 8;
  5339. if (INTEL_INFO(dev)->gen >= 4) {
  5340. if (plane_config->tiled)
  5341. offset = I915_READ(DSPTILEOFF(plane));
  5342. else
  5343. offset = I915_READ(DSPLINOFF(plane));
  5344. base = I915_READ(DSPSURF(plane)) & 0xfffff000;
  5345. } else {
  5346. base = I915_READ(DSPADDR(plane));
  5347. }
  5348. plane_config->base = base;
  5349. val = I915_READ(PIPESRC(pipe));
  5350. crtc->base.primary->fb->width = ((val >> 16) & 0xfff) + 1;
  5351. crtc->base.primary->fb->height = ((val >> 0) & 0xfff) + 1;
  5352. val = I915_READ(DSPSTRIDE(pipe));
  5353. crtc->base.primary->fb->pitches[0] = val & 0xffffffc0;
  5354. aligned_height = intel_align_height(dev, crtc->base.primary->fb->height,
  5355. plane_config->tiled);
  5356. plane_config->size = PAGE_ALIGN(crtc->base.primary->fb->pitches[0] *
  5357. aligned_height);
  5358. DRM_DEBUG_KMS("pipe/plane %d/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
  5359. pipe, plane, crtc->base.primary->fb->width,
  5360. crtc->base.primary->fb->height,
  5361. crtc->base.primary->fb->bits_per_pixel, base,
  5362. crtc->base.primary->fb->pitches[0],
  5363. plane_config->size);
  5364. }
  5365. static void chv_crtc_clock_get(struct intel_crtc *crtc,
  5366. struct intel_crtc_config *pipe_config)
  5367. {
  5368. struct drm_device *dev = crtc->base.dev;
  5369. struct drm_i915_private *dev_priv = dev->dev_private;
  5370. int pipe = pipe_config->cpu_transcoder;
  5371. enum dpio_channel port = vlv_pipe_to_channel(pipe);
  5372. intel_clock_t clock;
  5373. u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2;
  5374. int refclk = 100000;
  5375. mutex_lock(&dev_priv->dpio_lock);
  5376. cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port));
  5377. pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port));
  5378. pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port));
  5379. pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port));
  5380. mutex_unlock(&dev_priv->dpio_lock);
  5381. clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0;
  5382. clock.m2 = ((pll_dw0 & 0xff) << 22) | (pll_dw2 & 0x3fffff);
  5383. clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf;
  5384. clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7;
  5385. clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f;
  5386. chv_clock(refclk, &clock);
  5387. /* clock.dot is the fast clock */
  5388. pipe_config->port_clock = clock.dot / 5;
  5389. }
  5390. static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
  5391. struct intel_crtc_config *pipe_config)
  5392. {
  5393. struct drm_device *dev = crtc->base.dev;
  5394. struct drm_i915_private *dev_priv = dev->dev_private;
  5395. uint32_t tmp;
  5396. if (!intel_display_power_enabled(dev_priv,
  5397. POWER_DOMAIN_PIPE(crtc->pipe)))
  5398. return false;
  5399. pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
  5400. pipe_config->shared_dpll = DPLL_ID_PRIVATE;
  5401. tmp = I915_READ(PIPECONF(crtc->pipe));
  5402. if (!(tmp & PIPECONF_ENABLE))
  5403. return false;
  5404. if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) {
  5405. switch (tmp & PIPECONF_BPC_MASK) {
  5406. case PIPECONF_6BPC:
  5407. pipe_config->pipe_bpp = 18;
  5408. break;
  5409. case PIPECONF_8BPC:
  5410. pipe_config->pipe_bpp = 24;
  5411. break;
  5412. case PIPECONF_10BPC:
  5413. pipe_config->pipe_bpp = 30;
  5414. break;
  5415. default:
  5416. break;
  5417. }
  5418. }
  5419. if (IS_VALLEYVIEW(dev) && (tmp & PIPECONF_COLOR_RANGE_SELECT))
  5420. pipe_config->limited_color_range = true;
  5421. if (INTEL_INFO(dev)->gen < 4)
  5422. pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE;
  5423. intel_get_pipe_timings(crtc, pipe_config);
  5424. i9xx_get_pfit_config(crtc, pipe_config);
  5425. if (INTEL_INFO(dev)->gen >= 4) {
  5426. tmp = I915_READ(DPLL_MD(crtc->pipe));
  5427. pipe_config->pixel_multiplier =
  5428. ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK)
  5429. >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1;
  5430. pipe_config->dpll_hw_state.dpll_md = tmp;
  5431. } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) {
  5432. tmp = I915_READ(DPLL(crtc->pipe));
  5433. pipe_config->pixel_multiplier =
  5434. ((tmp & SDVO_MULTIPLIER_MASK)
  5435. >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1;
  5436. } else {
  5437. /* Note that on i915G/GM the pixel multiplier is in the sdvo
  5438. * port and will be fixed up in the encoder->get_config
  5439. * function. */
  5440. pipe_config->pixel_multiplier = 1;
  5441. }
  5442. pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe));
  5443. if (!IS_VALLEYVIEW(dev)) {
  5444. /*
  5445. * DPLL_DVO_2X_MODE must be enabled for both DPLLs
  5446. * on 830. Filter it out here so that we don't
  5447. * report errors due to that.
  5448. */
  5449. if (IS_I830(dev))
  5450. pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE;
  5451. pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe));
  5452. pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe));
  5453. } else {
  5454. /* Mask out read-only status bits. */
  5455. pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV |
  5456. DPLL_PORTC_READY_MASK |
  5457. DPLL_PORTB_READY_MASK);
  5458. }
  5459. if (IS_CHERRYVIEW(dev))
  5460. chv_crtc_clock_get(crtc, pipe_config);
  5461. else if (IS_VALLEYVIEW(dev))
  5462. vlv_crtc_clock_get(crtc, pipe_config);
  5463. else
  5464. i9xx_crtc_clock_get(crtc, pipe_config);
  5465. return true;
  5466. }
  5467. static void ironlake_init_pch_refclk(struct drm_device *dev)
  5468. {
  5469. struct drm_i915_private *dev_priv = dev->dev_private;
  5470. struct intel_encoder *encoder;
  5471. u32 val, final;
  5472. bool has_lvds = false;
  5473. bool has_cpu_edp = false;
  5474. bool has_panel = false;
  5475. bool has_ck505 = false;
  5476. bool can_ssc = false;
  5477. /* We need to take the global config into account */
  5478. for_each_intel_encoder(dev, encoder) {
  5479. switch (encoder->type) {
  5480. case INTEL_OUTPUT_LVDS:
  5481. has_panel = true;
  5482. has_lvds = true;
  5483. break;
  5484. case INTEL_OUTPUT_EDP:
  5485. has_panel = true;
  5486. if (enc_to_dig_port(&encoder->base)->port == PORT_A)
  5487. has_cpu_edp = true;
  5488. break;
  5489. }
  5490. }
  5491. if (HAS_PCH_IBX(dev)) {
  5492. has_ck505 = dev_priv->vbt.display_clock_mode;
  5493. can_ssc = has_ck505;
  5494. } else {
  5495. has_ck505 = false;
  5496. can_ssc = true;
  5497. }
  5498. DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d\n",
  5499. has_panel, has_lvds, has_ck505);
  5500. /* Ironlake: try to setup display ref clock before DPLL
  5501. * enabling. This is only under driver's control after
  5502. * PCH B stepping, previous chipset stepping should be
  5503. * ignoring this setting.
  5504. */
  5505. val = I915_READ(PCH_DREF_CONTROL);
  5506. /* As we must carefully and slowly disable/enable each source in turn,
  5507. * compute the final state we want first and check if we need to
  5508. * make any changes at all.
  5509. */
  5510. final = val;
  5511. final &= ~DREF_NONSPREAD_SOURCE_MASK;
  5512. if (has_ck505)
  5513. final |= DREF_NONSPREAD_CK505_ENABLE;
  5514. else
  5515. final |= DREF_NONSPREAD_SOURCE_ENABLE;
  5516. final &= ~DREF_SSC_SOURCE_MASK;
  5517. final &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
  5518. final &= ~DREF_SSC1_ENABLE;
  5519. if (has_panel) {
  5520. final |= DREF_SSC_SOURCE_ENABLE;
  5521. if (intel_panel_use_ssc(dev_priv) && can_ssc)
  5522. final |= DREF_SSC1_ENABLE;
  5523. if (has_cpu_edp) {
  5524. if (intel_panel_use_ssc(dev_priv) && can_ssc)
  5525. final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
  5526. else
  5527. final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
  5528. } else
  5529. final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  5530. } else {
  5531. final |= DREF_SSC_SOURCE_DISABLE;
  5532. final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  5533. }
  5534. if (final == val)
  5535. return;
  5536. /* Always enable nonspread source */
  5537. val &= ~DREF_NONSPREAD_SOURCE_MASK;
  5538. if (has_ck505)
  5539. val |= DREF_NONSPREAD_CK505_ENABLE;
  5540. else
  5541. val |= DREF_NONSPREAD_SOURCE_ENABLE;
  5542. if (has_panel) {
  5543. val &= ~DREF_SSC_SOURCE_MASK;
  5544. val |= DREF_SSC_SOURCE_ENABLE;
  5545. /* SSC must be turned on before enabling the CPU output */
  5546. if (intel_panel_use_ssc(dev_priv) && can_ssc) {
  5547. DRM_DEBUG_KMS("Using SSC on panel\n");
  5548. val |= DREF_SSC1_ENABLE;
  5549. } else
  5550. val &= ~DREF_SSC1_ENABLE;
  5551. /* Get SSC going before enabling the outputs */
  5552. I915_WRITE(PCH_DREF_CONTROL, val);
  5553. POSTING_READ(PCH_DREF_CONTROL);
  5554. udelay(200);
  5555. val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
  5556. /* Enable CPU source on CPU attached eDP */
  5557. if (has_cpu_edp) {
  5558. if (intel_panel_use_ssc(dev_priv) && can_ssc) {
  5559. DRM_DEBUG_KMS("Using SSC on eDP\n");
  5560. val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
  5561. } else
  5562. val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
  5563. } else
  5564. val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  5565. I915_WRITE(PCH_DREF_CONTROL, val);
  5566. POSTING_READ(PCH_DREF_CONTROL);
  5567. udelay(200);
  5568. } else {
  5569. DRM_DEBUG_KMS("Disabling SSC entirely\n");
  5570. val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
  5571. /* Turn off CPU output */
  5572. val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  5573. I915_WRITE(PCH_DREF_CONTROL, val);
  5574. POSTING_READ(PCH_DREF_CONTROL);
  5575. udelay(200);
  5576. /* Turn off the SSC source */
  5577. val &= ~DREF_SSC_SOURCE_MASK;
  5578. val |= DREF_SSC_SOURCE_DISABLE;
  5579. /* Turn off SSC1 */
  5580. val &= ~DREF_SSC1_ENABLE;
  5581. I915_WRITE(PCH_DREF_CONTROL, val);
  5582. POSTING_READ(PCH_DREF_CONTROL);
  5583. udelay(200);
  5584. }
  5585. BUG_ON(val != final);
  5586. }
  5587. static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv)
  5588. {
  5589. uint32_t tmp;
  5590. tmp = I915_READ(SOUTH_CHICKEN2);
  5591. tmp |= FDI_MPHY_IOSFSB_RESET_CTL;
  5592. I915_WRITE(SOUTH_CHICKEN2, tmp);
  5593. if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2) &
  5594. FDI_MPHY_IOSFSB_RESET_STATUS, 100))
  5595. DRM_ERROR("FDI mPHY reset assert timeout\n");
  5596. tmp = I915_READ(SOUTH_CHICKEN2);
  5597. tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL;
  5598. I915_WRITE(SOUTH_CHICKEN2, tmp);
  5599. if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2) &
  5600. FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100))
  5601. DRM_ERROR("FDI mPHY reset de-assert timeout\n");
  5602. }
  5603. /* WaMPhyProgramming:hsw */
  5604. static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv)
  5605. {
  5606. uint32_t tmp;
  5607. tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY);
  5608. tmp &= ~(0xFF << 24);
  5609. tmp |= (0x12 << 24);
  5610. intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY);
  5611. tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY);
  5612. tmp |= (1 << 11);
  5613. intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY);
  5614. tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY);
  5615. tmp |= (1 << 11);
  5616. intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY);
  5617. tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY);
  5618. tmp |= (1 << 24) | (1 << 21) | (1 << 18);
  5619. intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY);
  5620. tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY);
  5621. tmp |= (1 << 24) | (1 << 21) | (1 << 18);
  5622. intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY);
  5623. tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY);
  5624. tmp &= ~(7 << 13);
  5625. tmp |= (5 << 13);
  5626. intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY);
  5627. tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY);
  5628. tmp &= ~(7 << 13);
  5629. tmp |= (5 << 13);
  5630. intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY);
  5631. tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY);
  5632. tmp &= ~0xFF;
  5633. tmp |= 0x1C;
  5634. intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY);
  5635. tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY);
  5636. tmp &= ~0xFF;
  5637. tmp |= 0x1C;
  5638. intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY);
  5639. tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY);
  5640. tmp &= ~(0xFF << 16);
  5641. tmp |= (0x1C << 16);
  5642. intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY);
  5643. tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY);
  5644. tmp &= ~(0xFF << 16);
  5645. tmp |= (0x1C << 16);
  5646. intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY);
  5647. tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY);
  5648. tmp |= (1 << 27);
  5649. intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY);
  5650. tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY);
  5651. tmp |= (1 << 27);
  5652. intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY);
  5653. tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY);
  5654. tmp &= ~(0xF << 28);
  5655. tmp |= (4 << 28);
  5656. intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY);
  5657. tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY);
  5658. tmp &= ~(0xF << 28);
  5659. tmp |= (4 << 28);
  5660. intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY);
  5661. }
  5662. /* Implements 3 different sequences from BSpec chapter "Display iCLK
  5663. * Programming" based on the parameters passed:
  5664. * - Sequence to enable CLKOUT_DP
  5665. * - Sequence to enable CLKOUT_DP without spread
  5666. * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
  5667. */
  5668. static void lpt_enable_clkout_dp(struct drm_device *dev, bool with_spread,
  5669. bool with_fdi)
  5670. {
  5671. struct drm_i915_private *dev_priv = dev->dev_private;
  5672. uint32_t reg, tmp;
  5673. if (WARN(with_fdi && !with_spread, "FDI requires downspread\n"))
  5674. with_spread = true;
  5675. if (WARN(dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE &&
  5676. with_fdi, "LP PCH doesn't have FDI\n"))
  5677. with_fdi = false;
  5678. mutex_lock(&dev_priv->dpio_lock);
  5679. tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
  5680. tmp &= ~SBI_SSCCTL_DISABLE;
  5681. tmp |= SBI_SSCCTL_PATHALT;
  5682. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  5683. udelay(24);
  5684. if (with_spread) {
  5685. tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
  5686. tmp &= ~SBI_SSCCTL_PATHALT;
  5687. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  5688. if (with_fdi) {
  5689. lpt_reset_fdi_mphy(dev_priv);
  5690. lpt_program_fdi_mphy(dev_priv);
  5691. }
  5692. }
  5693. reg = (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) ?
  5694. SBI_GEN0 : SBI_DBUFF0;
  5695. tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
  5696. tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE;
  5697. intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
  5698. mutex_unlock(&dev_priv->dpio_lock);
  5699. }
  5700. /* Sequence to disable CLKOUT_DP */
  5701. static void lpt_disable_clkout_dp(struct drm_device *dev)
  5702. {
  5703. struct drm_i915_private *dev_priv = dev->dev_private;
  5704. uint32_t reg, tmp;
  5705. mutex_lock(&dev_priv->dpio_lock);
  5706. reg = (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) ?
  5707. SBI_GEN0 : SBI_DBUFF0;
  5708. tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
  5709. tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE;
  5710. intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
  5711. tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
  5712. if (!(tmp & SBI_SSCCTL_DISABLE)) {
  5713. if (!(tmp & SBI_SSCCTL_PATHALT)) {
  5714. tmp |= SBI_SSCCTL_PATHALT;
  5715. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  5716. udelay(32);
  5717. }
  5718. tmp |= SBI_SSCCTL_DISABLE;
  5719. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  5720. }
  5721. mutex_unlock(&dev_priv->dpio_lock);
  5722. }
  5723. static void lpt_init_pch_refclk(struct drm_device *dev)
  5724. {
  5725. struct intel_encoder *encoder;
  5726. bool has_vga = false;
  5727. for_each_intel_encoder(dev, encoder) {
  5728. switch (encoder->type) {
  5729. case INTEL_OUTPUT_ANALOG:
  5730. has_vga = true;
  5731. break;
  5732. }
  5733. }
  5734. if (has_vga)
  5735. lpt_enable_clkout_dp(dev, true, true);
  5736. else
  5737. lpt_disable_clkout_dp(dev);
  5738. }
  5739. /*
  5740. * Initialize reference clocks when the driver loads
  5741. */
  5742. void intel_init_pch_refclk(struct drm_device *dev)
  5743. {
  5744. if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
  5745. ironlake_init_pch_refclk(dev);
  5746. else if (HAS_PCH_LPT(dev))
  5747. lpt_init_pch_refclk(dev);
  5748. }
  5749. static int ironlake_get_refclk(struct drm_crtc *crtc)
  5750. {
  5751. struct drm_device *dev = crtc->dev;
  5752. struct drm_i915_private *dev_priv = dev->dev_private;
  5753. struct intel_encoder *encoder;
  5754. int num_connectors = 0;
  5755. bool is_lvds = false;
  5756. for_each_encoder_on_crtc(dev, crtc, encoder) {
  5757. switch (encoder->type) {
  5758. case INTEL_OUTPUT_LVDS:
  5759. is_lvds = true;
  5760. break;
  5761. }
  5762. num_connectors++;
  5763. }
  5764. if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) {
  5765. DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
  5766. dev_priv->vbt.lvds_ssc_freq);
  5767. return dev_priv->vbt.lvds_ssc_freq;
  5768. }
  5769. return 120000;
  5770. }
  5771. static void ironlake_set_pipeconf(struct drm_crtc *crtc)
  5772. {
  5773. struct drm_i915_private *dev_priv = crtc->dev->dev_private;
  5774. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5775. int pipe = intel_crtc->pipe;
  5776. uint32_t val;
  5777. val = 0;
  5778. switch (intel_crtc->config.pipe_bpp) {
  5779. case 18:
  5780. val |= PIPECONF_6BPC;
  5781. break;
  5782. case 24:
  5783. val |= PIPECONF_8BPC;
  5784. break;
  5785. case 30:
  5786. val |= PIPECONF_10BPC;
  5787. break;
  5788. case 36:
  5789. val |= PIPECONF_12BPC;
  5790. break;
  5791. default:
  5792. /* Case prevented by intel_choose_pipe_bpp_dither. */
  5793. BUG();
  5794. }
  5795. if (intel_crtc->config.dither)
  5796. val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
  5797. if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
  5798. val |= PIPECONF_INTERLACED_ILK;
  5799. else
  5800. val |= PIPECONF_PROGRESSIVE;
  5801. if (intel_crtc->config.limited_color_range)
  5802. val |= PIPECONF_COLOR_RANGE_SELECT;
  5803. I915_WRITE(PIPECONF(pipe), val);
  5804. POSTING_READ(PIPECONF(pipe));
  5805. }
  5806. /*
  5807. * Set up the pipe CSC unit.
  5808. *
  5809. * Currently only full range RGB to limited range RGB conversion
  5810. * is supported, but eventually this should handle various
  5811. * RGB<->YCbCr scenarios as well.
  5812. */
  5813. static void intel_set_pipe_csc(struct drm_crtc *crtc)
  5814. {
  5815. struct drm_device *dev = crtc->dev;
  5816. struct drm_i915_private *dev_priv = dev->dev_private;
  5817. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5818. int pipe = intel_crtc->pipe;
  5819. uint16_t coeff = 0x7800; /* 1.0 */
  5820. /*
  5821. * TODO: Check what kind of values actually come out of the pipe
  5822. * with these coeff/postoff values and adjust to get the best
  5823. * accuracy. Perhaps we even need to take the bpc value into
  5824. * consideration.
  5825. */
  5826. if (intel_crtc->config.limited_color_range)
  5827. coeff = ((235 - 16) * (1 << 12) / 255) & 0xff8; /* 0.xxx... */
  5828. /*
  5829. * GY/GU and RY/RU should be the other way around according
  5830. * to BSpec, but reality doesn't agree. Just set them up in
  5831. * a way that results in the correct picture.
  5832. */
  5833. I915_WRITE(PIPE_CSC_COEFF_RY_GY(pipe), coeff << 16);
  5834. I915_WRITE(PIPE_CSC_COEFF_BY(pipe), 0);
  5835. I915_WRITE(PIPE_CSC_COEFF_RU_GU(pipe), coeff);
  5836. I915_WRITE(PIPE_CSC_COEFF_BU(pipe), 0);
  5837. I915_WRITE(PIPE_CSC_COEFF_RV_GV(pipe), 0);
  5838. I915_WRITE(PIPE_CSC_COEFF_BV(pipe), coeff << 16);
  5839. I915_WRITE(PIPE_CSC_PREOFF_HI(pipe), 0);
  5840. I915_WRITE(PIPE_CSC_PREOFF_ME(pipe), 0);
  5841. I915_WRITE(PIPE_CSC_PREOFF_LO(pipe), 0);
  5842. if (INTEL_INFO(dev)->gen > 6) {
  5843. uint16_t postoff = 0;
  5844. if (intel_crtc->config.limited_color_range)
  5845. postoff = (16 * (1 << 12) / 255) & 0x1fff;
  5846. I915_WRITE(PIPE_CSC_POSTOFF_HI(pipe), postoff);
  5847. I915_WRITE(PIPE_CSC_POSTOFF_ME(pipe), postoff);
  5848. I915_WRITE(PIPE_CSC_POSTOFF_LO(pipe), postoff);
  5849. I915_WRITE(PIPE_CSC_MODE(pipe), 0);
  5850. } else {
  5851. uint32_t mode = CSC_MODE_YUV_TO_RGB;
  5852. if (intel_crtc->config.limited_color_range)
  5853. mode |= CSC_BLACK_SCREEN_OFFSET;
  5854. I915_WRITE(PIPE_CSC_MODE(pipe), mode);
  5855. }
  5856. }
  5857. static void haswell_set_pipeconf(struct drm_crtc *crtc)
  5858. {
  5859. struct drm_device *dev = crtc->dev;
  5860. struct drm_i915_private *dev_priv = dev->dev_private;
  5861. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5862. enum pipe pipe = intel_crtc->pipe;
  5863. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  5864. uint32_t val;
  5865. val = 0;
  5866. if (IS_HASWELL(dev) && intel_crtc->config.dither)
  5867. val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
  5868. if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
  5869. val |= PIPECONF_INTERLACED_ILK;
  5870. else
  5871. val |= PIPECONF_PROGRESSIVE;
  5872. I915_WRITE(PIPECONF(cpu_transcoder), val);
  5873. POSTING_READ(PIPECONF(cpu_transcoder));
  5874. I915_WRITE(GAMMA_MODE(intel_crtc->pipe), GAMMA_MODE_MODE_8BIT);
  5875. POSTING_READ(GAMMA_MODE(intel_crtc->pipe));
  5876. if (IS_BROADWELL(dev)) {
  5877. val = 0;
  5878. switch (intel_crtc->config.pipe_bpp) {
  5879. case 18:
  5880. val |= PIPEMISC_DITHER_6_BPC;
  5881. break;
  5882. case 24:
  5883. val |= PIPEMISC_DITHER_8_BPC;
  5884. break;
  5885. case 30:
  5886. val |= PIPEMISC_DITHER_10_BPC;
  5887. break;
  5888. case 36:
  5889. val |= PIPEMISC_DITHER_12_BPC;
  5890. break;
  5891. default:
  5892. /* Case prevented by pipe_config_set_bpp. */
  5893. BUG();
  5894. }
  5895. if (intel_crtc->config.dither)
  5896. val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP;
  5897. I915_WRITE(PIPEMISC(pipe), val);
  5898. }
  5899. }
  5900. static bool ironlake_compute_clocks(struct drm_crtc *crtc,
  5901. intel_clock_t *clock,
  5902. bool *has_reduced_clock,
  5903. intel_clock_t *reduced_clock)
  5904. {
  5905. struct drm_device *dev = crtc->dev;
  5906. struct drm_i915_private *dev_priv = dev->dev_private;
  5907. struct intel_encoder *intel_encoder;
  5908. int refclk;
  5909. const intel_limit_t *limit;
  5910. bool ret, is_lvds = false;
  5911. for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
  5912. switch (intel_encoder->type) {
  5913. case INTEL_OUTPUT_LVDS:
  5914. is_lvds = true;
  5915. break;
  5916. }
  5917. }
  5918. refclk = ironlake_get_refclk(crtc);
  5919. /*
  5920. * Returns a set of divisors for the desired target clock with the given
  5921. * refclk, or FALSE. The returned values represent the clock equation:
  5922. * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
  5923. */
  5924. limit = intel_limit(crtc, refclk);
  5925. ret = dev_priv->display.find_dpll(limit, crtc,
  5926. to_intel_crtc(crtc)->config.port_clock,
  5927. refclk, NULL, clock);
  5928. if (!ret)
  5929. return false;
  5930. if (is_lvds && dev_priv->lvds_downclock_avail) {
  5931. /*
  5932. * Ensure we match the reduced clock's P to the target clock.
  5933. * If the clocks don't match, we can't switch the display clock
  5934. * by using the FP0/FP1. In such case we will disable the LVDS
  5935. * downclock feature.
  5936. */
  5937. *has_reduced_clock =
  5938. dev_priv->display.find_dpll(limit, crtc,
  5939. dev_priv->lvds_downclock,
  5940. refclk, clock,
  5941. reduced_clock);
  5942. }
  5943. return true;
  5944. }
  5945. int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp)
  5946. {
  5947. /*
  5948. * Account for spread spectrum to avoid
  5949. * oversubscribing the link. Max center spread
  5950. * is 2.5%; use 5% for safety's sake.
  5951. */
  5952. u32 bps = target_clock * bpp * 21 / 20;
  5953. return DIV_ROUND_UP(bps, link_bw * 8);
  5954. }
  5955. static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor)
  5956. {
  5957. return i9xx_dpll_compute_m(dpll) < factor * dpll->n;
  5958. }
  5959. static uint32_t ironlake_compute_dpll(struct intel_crtc *intel_crtc,
  5960. u32 *fp,
  5961. intel_clock_t *reduced_clock, u32 *fp2)
  5962. {
  5963. struct drm_crtc *crtc = &intel_crtc->base;
  5964. struct drm_device *dev = crtc->dev;
  5965. struct drm_i915_private *dev_priv = dev->dev_private;
  5966. struct intel_encoder *intel_encoder;
  5967. uint32_t dpll;
  5968. int factor, num_connectors = 0;
  5969. bool is_lvds = false, is_sdvo = false;
  5970. for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
  5971. switch (intel_encoder->type) {
  5972. case INTEL_OUTPUT_LVDS:
  5973. is_lvds = true;
  5974. break;
  5975. case INTEL_OUTPUT_SDVO:
  5976. case INTEL_OUTPUT_HDMI:
  5977. is_sdvo = true;
  5978. break;
  5979. }
  5980. num_connectors++;
  5981. }
  5982. /* Enable autotuning of the PLL clock (if permissible) */
  5983. factor = 21;
  5984. if (is_lvds) {
  5985. if ((intel_panel_use_ssc(dev_priv) &&
  5986. dev_priv->vbt.lvds_ssc_freq == 100000) ||
  5987. (HAS_PCH_IBX(dev) && intel_is_dual_link_lvds(dev)))
  5988. factor = 25;
  5989. } else if (intel_crtc->config.sdvo_tv_clock)
  5990. factor = 20;
  5991. if (ironlake_needs_fb_cb_tune(&intel_crtc->config.dpll, factor))
  5992. *fp |= FP_CB_TUNE;
  5993. if (fp2 && (reduced_clock->m < factor * reduced_clock->n))
  5994. *fp2 |= FP_CB_TUNE;
  5995. dpll = 0;
  5996. if (is_lvds)
  5997. dpll |= DPLLB_MODE_LVDS;
  5998. else
  5999. dpll |= DPLLB_MODE_DAC_SERIAL;
  6000. dpll |= (intel_crtc->config.pixel_multiplier - 1)
  6001. << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
  6002. if (is_sdvo)
  6003. dpll |= DPLL_SDVO_HIGH_SPEED;
  6004. if (intel_crtc->config.has_dp_encoder)
  6005. dpll |= DPLL_SDVO_HIGH_SPEED;
  6006. /* compute bitmask from p1 value */
  6007. dpll |= (1 << (intel_crtc->config.dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  6008. /* also FPA1 */
  6009. dpll |= (1 << (intel_crtc->config.dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
  6010. switch (intel_crtc->config.dpll.p2) {
  6011. case 5:
  6012. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
  6013. break;
  6014. case 7:
  6015. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
  6016. break;
  6017. case 10:
  6018. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
  6019. break;
  6020. case 14:
  6021. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
  6022. break;
  6023. }
  6024. if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2)
  6025. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  6026. else
  6027. dpll |= PLL_REF_INPUT_DREFCLK;
  6028. return dpll | DPLL_VCO_ENABLE;
  6029. }
  6030. static int ironlake_crtc_mode_set(struct drm_crtc *crtc,
  6031. int x, int y,
  6032. struct drm_framebuffer *fb)
  6033. {
  6034. struct drm_device *dev = crtc->dev;
  6035. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6036. int num_connectors = 0;
  6037. intel_clock_t clock, reduced_clock;
  6038. u32 dpll = 0, fp = 0, fp2 = 0;
  6039. bool ok, has_reduced_clock = false;
  6040. bool is_lvds = false;
  6041. struct intel_encoder *encoder;
  6042. struct intel_shared_dpll *pll;
  6043. for_each_encoder_on_crtc(dev, crtc, encoder) {
  6044. switch (encoder->type) {
  6045. case INTEL_OUTPUT_LVDS:
  6046. is_lvds = true;
  6047. break;
  6048. }
  6049. num_connectors++;
  6050. }
  6051. WARN(!(HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)),
  6052. "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev));
  6053. ok = ironlake_compute_clocks(crtc, &clock,
  6054. &has_reduced_clock, &reduced_clock);
  6055. if (!ok && !intel_crtc->config.clock_set) {
  6056. DRM_ERROR("Couldn't find PLL settings for mode!\n");
  6057. return -EINVAL;
  6058. }
  6059. /* Compat-code for transition, will disappear. */
  6060. if (!intel_crtc->config.clock_set) {
  6061. intel_crtc->config.dpll.n = clock.n;
  6062. intel_crtc->config.dpll.m1 = clock.m1;
  6063. intel_crtc->config.dpll.m2 = clock.m2;
  6064. intel_crtc->config.dpll.p1 = clock.p1;
  6065. intel_crtc->config.dpll.p2 = clock.p2;
  6066. }
  6067. /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
  6068. if (intel_crtc->config.has_pch_encoder) {
  6069. fp = i9xx_dpll_compute_fp(&intel_crtc->config.dpll);
  6070. if (has_reduced_clock)
  6071. fp2 = i9xx_dpll_compute_fp(&reduced_clock);
  6072. dpll = ironlake_compute_dpll(intel_crtc,
  6073. &fp, &reduced_clock,
  6074. has_reduced_clock ? &fp2 : NULL);
  6075. intel_crtc->config.dpll_hw_state.dpll = dpll;
  6076. intel_crtc->config.dpll_hw_state.fp0 = fp;
  6077. if (has_reduced_clock)
  6078. intel_crtc->config.dpll_hw_state.fp1 = fp2;
  6079. else
  6080. intel_crtc->config.dpll_hw_state.fp1 = fp;
  6081. pll = intel_get_shared_dpll(intel_crtc);
  6082. if (pll == NULL) {
  6083. DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
  6084. pipe_name(intel_crtc->pipe));
  6085. return -EINVAL;
  6086. }
  6087. } else
  6088. intel_put_shared_dpll(intel_crtc);
  6089. if (is_lvds && has_reduced_clock && i915.powersave)
  6090. intel_crtc->lowfreq_avail = true;
  6091. else
  6092. intel_crtc->lowfreq_avail = false;
  6093. return 0;
  6094. }
  6095. static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc,
  6096. struct intel_link_m_n *m_n)
  6097. {
  6098. struct drm_device *dev = crtc->base.dev;
  6099. struct drm_i915_private *dev_priv = dev->dev_private;
  6100. enum pipe pipe = crtc->pipe;
  6101. m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe));
  6102. m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe));
  6103. m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe))
  6104. & ~TU_SIZE_MASK;
  6105. m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe));
  6106. m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe))
  6107. & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
  6108. }
  6109. static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc,
  6110. enum transcoder transcoder,
  6111. struct intel_link_m_n *m_n,
  6112. struct intel_link_m_n *m2_n2)
  6113. {
  6114. struct drm_device *dev = crtc->base.dev;
  6115. struct drm_i915_private *dev_priv = dev->dev_private;
  6116. enum pipe pipe = crtc->pipe;
  6117. if (INTEL_INFO(dev)->gen >= 5) {
  6118. m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder));
  6119. m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder));
  6120. m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder))
  6121. & ~TU_SIZE_MASK;
  6122. m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder));
  6123. m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder))
  6124. & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
  6125. /* Read M2_N2 registers only for gen < 8 (M2_N2 available for
  6126. * gen < 8) and if DRRS is supported (to make sure the
  6127. * registers are not unnecessarily read).
  6128. */
  6129. if (m2_n2 && INTEL_INFO(dev)->gen < 8 &&
  6130. crtc->config.has_drrs) {
  6131. m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder));
  6132. m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder));
  6133. m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder))
  6134. & ~TU_SIZE_MASK;
  6135. m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder));
  6136. m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder))
  6137. & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
  6138. }
  6139. } else {
  6140. m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe));
  6141. m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe));
  6142. m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe))
  6143. & ~TU_SIZE_MASK;
  6144. m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe));
  6145. m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe))
  6146. & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
  6147. }
  6148. }
  6149. void intel_dp_get_m_n(struct intel_crtc *crtc,
  6150. struct intel_crtc_config *pipe_config)
  6151. {
  6152. if (crtc->config.has_pch_encoder)
  6153. intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n);
  6154. else
  6155. intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
  6156. &pipe_config->dp_m_n,
  6157. &pipe_config->dp_m2_n2);
  6158. }
  6159. static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc,
  6160. struct intel_crtc_config *pipe_config)
  6161. {
  6162. intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
  6163. &pipe_config->fdi_m_n, NULL);
  6164. }
  6165. static void ironlake_get_pfit_config(struct intel_crtc *crtc,
  6166. struct intel_crtc_config *pipe_config)
  6167. {
  6168. struct drm_device *dev = crtc->base.dev;
  6169. struct drm_i915_private *dev_priv = dev->dev_private;
  6170. uint32_t tmp;
  6171. tmp = I915_READ(PF_CTL(crtc->pipe));
  6172. if (tmp & PF_ENABLE) {
  6173. pipe_config->pch_pfit.enabled = true;
  6174. pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe));
  6175. pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe));
  6176. /* We currently do not free assignements of panel fitters on
  6177. * ivb/hsw (since we don't use the higher upscaling modes which
  6178. * differentiates them) so just WARN about this case for now. */
  6179. if (IS_GEN7(dev)) {
  6180. WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) !=
  6181. PF_PIPE_SEL_IVB(crtc->pipe));
  6182. }
  6183. }
  6184. }
  6185. static void ironlake_get_plane_config(struct intel_crtc *crtc,
  6186. struct intel_plane_config *plane_config)
  6187. {
  6188. struct drm_device *dev = crtc->base.dev;
  6189. struct drm_i915_private *dev_priv = dev->dev_private;
  6190. u32 val, base, offset;
  6191. int pipe = crtc->pipe, plane = crtc->plane;
  6192. int fourcc, pixel_format;
  6193. int aligned_height;
  6194. crtc->base.primary->fb = kzalloc(sizeof(struct intel_framebuffer), GFP_KERNEL);
  6195. if (!crtc->base.primary->fb) {
  6196. DRM_DEBUG_KMS("failed to alloc fb\n");
  6197. return;
  6198. }
  6199. val = I915_READ(DSPCNTR(plane));
  6200. if (INTEL_INFO(dev)->gen >= 4)
  6201. if (val & DISPPLANE_TILED)
  6202. plane_config->tiled = true;
  6203. pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
  6204. fourcc = intel_format_to_fourcc(pixel_format);
  6205. crtc->base.primary->fb->pixel_format = fourcc;
  6206. crtc->base.primary->fb->bits_per_pixel =
  6207. drm_format_plane_cpp(fourcc, 0) * 8;
  6208. base = I915_READ(DSPSURF(plane)) & 0xfffff000;
  6209. if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
  6210. offset = I915_READ(DSPOFFSET(plane));
  6211. } else {
  6212. if (plane_config->tiled)
  6213. offset = I915_READ(DSPTILEOFF(plane));
  6214. else
  6215. offset = I915_READ(DSPLINOFF(plane));
  6216. }
  6217. plane_config->base = base;
  6218. val = I915_READ(PIPESRC(pipe));
  6219. crtc->base.primary->fb->width = ((val >> 16) & 0xfff) + 1;
  6220. crtc->base.primary->fb->height = ((val >> 0) & 0xfff) + 1;
  6221. val = I915_READ(DSPSTRIDE(pipe));
  6222. crtc->base.primary->fb->pitches[0] = val & 0xffffffc0;
  6223. aligned_height = intel_align_height(dev, crtc->base.primary->fb->height,
  6224. plane_config->tiled);
  6225. plane_config->size = PAGE_ALIGN(crtc->base.primary->fb->pitches[0] *
  6226. aligned_height);
  6227. DRM_DEBUG_KMS("pipe/plane %d/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
  6228. pipe, plane, crtc->base.primary->fb->width,
  6229. crtc->base.primary->fb->height,
  6230. crtc->base.primary->fb->bits_per_pixel, base,
  6231. crtc->base.primary->fb->pitches[0],
  6232. plane_config->size);
  6233. }
  6234. static bool ironlake_get_pipe_config(struct intel_crtc *crtc,
  6235. struct intel_crtc_config *pipe_config)
  6236. {
  6237. struct drm_device *dev = crtc->base.dev;
  6238. struct drm_i915_private *dev_priv = dev->dev_private;
  6239. uint32_t tmp;
  6240. if (!intel_display_power_enabled(dev_priv,
  6241. POWER_DOMAIN_PIPE(crtc->pipe)))
  6242. return false;
  6243. pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
  6244. pipe_config->shared_dpll = DPLL_ID_PRIVATE;
  6245. tmp = I915_READ(PIPECONF(crtc->pipe));
  6246. if (!(tmp & PIPECONF_ENABLE))
  6247. return false;
  6248. switch (tmp & PIPECONF_BPC_MASK) {
  6249. case PIPECONF_6BPC:
  6250. pipe_config->pipe_bpp = 18;
  6251. break;
  6252. case PIPECONF_8BPC:
  6253. pipe_config->pipe_bpp = 24;
  6254. break;
  6255. case PIPECONF_10BPC:
  6256. pipe_config->pipe_bpp = 30;
  6257. break;
  6258. case PIPECONF_12BPC:
  6259. pipe_config->pipe_bpp = 36;
  6260. break;
  6261. default:
  6262. break;
  6263. }
  6264. if (tmp & PIPECONF_COLOR_RANGE_SELECT)
  6265. pipe_config->limited_color_range = true;
  6266. if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) {
  6267. struct intel_shared_dpll *pll;
  6268. pipe_config->has_pch_encoder = true;
  6269. tmp = I915_READ(FDI_RX_CTL(crtc->pipe));
  6270. pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
  6271. FDI_DP_PORT_WIDTH_SHIFT) + 1;
  6272. ironlake_get_fdi_m_n_config(crtc, pipe_config);
  6273. if (HAS_PCH_IBX(dev_priv->dev)) {
  6274. pipe_config->shared_dpll =
  6275. (enum intel_dpll_id) crtc->pipe;
  6276. } else {
  6277. tmp = I915_READ(PCH_DPLL_SEL);
  6278. if (tmp & TRANS_DPLLB_SEL(crtc->pipe))
  6279. pipe_config->shared_dpll = DPLL_ID_PCH_PLL_B;
  6280. else
  6281. pipe_config->shared_dpll = DPLL_ID_PCH_PLL_A;
  6282. }
  6283. pll = &dev_priv->shared_dplls[pipe_config->shared_dpll];
  6284. WARN_ON(!pll->get_hw_state(dev_priv, pll,
  6285. &pipe_config->dpll_hw_state));
  6286. tmp = pipe_config->dpll_hw_state.dpll;
  6287. pipe_config->pixel_multiplier =
  6288. ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK)
  6289. >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1;
  6290. ironlake_pch_clock_get(crtc, pipe_config);
  6291. } else {
  6292. pipe_config->pixel_multiplier = 1;
  6293. }
  6294. intel_get_pipe_timings(crtc, pipe_config);
  6295. ironlake_get_pfit_config(crtc, pipe_config);
  6296. return true;
  6297. }
  6298. static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv)
  6299. {
  6300. struct drm_device *dev = dev_priv->dev;
  6301. struct intel_crtc *crtc;
  6302. for_each_intel_crtc(dev, crtc)
  6303. WARN(crtc->active, "CRTC for pipe %c enabled\n",
  6304. pipe_name(crtc->pipe));
  6305. WARN(I915_READ(HSW_PWR_WELL_DRIVER), "Power well on\n");
  6306. WARN(I915_READ(SPLL_CTL) & SPLL_PLL_ENABLE, "SPLL enabled\n");
  6307. WARN(I915_READ(WRPLL_CTL1) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n");
  6308. WARN(I915_READ(WRPLL_CTL2) & WRPLL_PLL_ENABLE, "WRPLL2 enabled\n");
  6309. WARN(I915_READ(PCH_PP_STATUS) & PP_ON, "Panel power on\n");
  6310. WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE,
  6311. "CPU PWM1 enabled\n");
  6312. if (IS_HASWELL(dev))
  6313. WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE,
  6314. "CPU PWM2 enabled\n");
  6315. WARN(I915_READ(BLC_PWM_PCH_CTL1) & BLM_PCH_PWM_ENABLE,
  6316. "PCH PWM1 enabled\n");
  6317. WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
  6318. "Utility pin enabled\n");
  6319. WARN(I915_READ(PCH_GTC_CTL) & PCH_GTC_ENABLE, "PCH GTC enabled\n");
  6320. /*
  6321. * In theory we can still leave IRQs enabled, as long as only the HPD
  6322. * interrupts remain enabled. We used to check for that, but since it's
  6323. * gen-specific and since we only disable LCPLL after we fully disable
  6324. * the interrupts, the check below should be enough.
  6325. */
  6326. WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n");
  6327. }
  6328. static uint32_t hsw_read_dcomp(struct drm_i915_private *dev_priv)
  6329. {
  6330. struct drm_device *dev = dev_priv->dev;
  6331. if (IS_HASWELL(dev))
  6332. return I915_READ(D_COMP_HSW);
  6333. else
  6334. return I915_READ(D_COMP_BDW);
  6335. }
  6336. static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val)
  6337. {
  6338. struct drm_device *dev = dev_priv->dev;
  6339. if (IS_HASWELL(dev)) {
  6340. mutex_lock(&dev_priv->rps.hw_lock);
  6341. if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP,
  6342. val))
  6343. DRM_ERROR("Failed to write to D_COMP\n");
  6344. mutex_unlock(&dev_priv->rps.hw_lock);
  6345. } else {
  6346. I915_WRITE(D_COMP_BDW, val);
  6347. POSTING_READ(D_COMP_BDW);
  6348. }
  6349. }
  6350. /*
  6351. * This function implements pieces of two sequences from BSpec:
  6352. * - Sequence for display software to disable LCPLL
  6353. * - Sequence for display software to allow package C8+
  6354. * The steps implemented here are just the steps that actually touch the LCPLL
  6355. * register. Callers should take care of disabling all the display engine
  6356. * functions, doing the mode unset, fixing interrupts, etc.
  6357. */
  6358. static void hsw_disable_lcpll(struct drm_i915_private *dev_priv,
  6359. bool switch_to_fclk, bool allow_power_down)
  6360. {
  6361. uint32_t val;
  6362. assert_can_disable_lcpll(dev_priv);
  6363. val = I915_READ(LCPLL_CTL);
  6364. if (switch_to_fclk) {
  6365. val |= LCPLL_CD_SOURCE_FCLK;
  6366. I915_WRITE(LCPLL_CTL, val);
  6367. if (wait_for_atomic_us(I915_READ(LCPLL_CTL) &
  6368. LCPLL_CD_SOURCE_FCLK_DONE, 1))
  6369. DRM_ERROR("Switching to FCLK failed\n");
  6370. val = I915_READ(LCPLL_CTL);
  6371. }
  6372. val |= LCPLL_PLL_DISABLE;
  6373. I915_WRITE(LCPLL_CTL, val);
  6374. POSTING_READ(LCPLL_CTL);
  6375. if (wait_for((I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK) == 0, 1))
  6376. DRM_ERROR("LCPLL still locked\n");
  6377. val = hsw_read_dcomp(dev_priv);
  6378. val |= D_COMP_COMP_DISABLE;
  6379. hsw_write_dcomp(dev_priv, val);
  6380. ndelay(100);
  6381. if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0,
  6382. 1))
  6383. DRM_ERROR("D_COMP RCOMP still in progress\n");
  6384. if (allow_power_down) {
  6385. val = I915_READ(LCPLL_CTL);
  6386. val |= LCPLL_POWER_DOWN_ALLOW;
  6387. I915_WRITE(LCPLL_CTL, val);
  6388. POSTING_READ(LCPLL_CTL);
  6389. }
  6390. }
  6391. /*
  6392. * Fully restores LCPLL, disallowing power down and switching back to LCPLL
  6393. * source.
  6394. */
  6395. static void hsw_restore_lcpll(struct drm_i915_private *dev_priv)
  6396. {
  6397. uint32_t val;
  6398. unsigned long irqflags;
  6399. val = I915_READ(LCPLL_CTL);
  6400. if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK |
  6401. LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK)
  6402. return;
  6403. /*
  6404. * Make sure we're not on PC8 state before disabling PC8, otherwise
  6405. * we'll hang the machine. To prevent PC8 state, just enable force_wake.
  6406. *
  6407. * The other problem is that hsw_restore_lcpll() is called as part of
  6408. * the runtime PM resume sequence, so we can't just call
  6409. * gen6_gt_force_wake_get() because that function calls
  6410. * intel_runtime_pm_get(), and we can't change the runtime PM refcount
  6411. * while we are on the resume sequence. So to solve this problem we have
  6412. * to call special forcewake code that doesn't touch runtime PM and
  6413. * doesn't enable the forcewake delayed work.
  6414. */
  6415. spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
  6416. if (dev_priv->uncore.forcewake_count++ == 0)
  6417. dev_priv->uncore.funcs.force_wake_get(dev_priv, FORCEWAKE_ALL);
  6418. spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
  6419. if (val & LCPLL_POWER_DOWN_ALLOW) {
  6420. val &= ~LCPLL_POWER_DOWN_ALLOW;
  6421. I915_WRITE(LCPLL_CTL, val);
  6422. POSTING_READ(LCPLL_CTL);
  6423. }
  6424. val = hsw_read_dcomp(dev_priv);
  6425. val |= D_COMP_COMP_FORCE;
  6426. val &= ~D_COMP_COMP_DISABLE;
  6427. hsw_write_dcomp(dev_priv, val);
  6428. val = I915_READ(LCPLL_CTL);
  6429. val &= ~LCPLL_PLL_DISABLE;
  6430. I915_WRITE(LCPLL_CTL, val);
  6431. if (wait_for(I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK, 5))
  6432. DRM_ERROR("LCPLL not locked yet\n");
  6433. if (val & LCPLL_CD_SOURCE_FCLK) {
  6434. val = I915_READ(LCPLL_CTL);
  6435. val &= ~LCPLL_CD_SOURCE_FCLK;
  6436. I915_WRITE(LCPLL_CTL, val);
  6437. if (wait_for_atomic_us((I915_READ(LCPLL_CTL) &
  6438. LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1))
  6439. DRM_ERROR("Switching back to LCPLL failed\n");
  6440. }
  6441. /* See the big comment above. */
  6442. spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
  6443. if (--dev_priv->uncore.forcewake_count == 0)
  6444. dev_priv->uncore.funcs.force_wake_put(dev_priv, FORCEWAKE_ALL);
  6445. spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
  6446. }
  6447. /*
  6448. * Package states C8 and deeper are really deep PC states that can only be
  6449. * reached when all the devices on the system allow it, so even if the graphics
  6450. * device allows PC8+, it doesn't mean the system will actually get to these
  6451. * states. Our driver only allows PC8+ when going into runtime PM.
  6452. *
  6453. * The requirements for PC8+ are that all the outputs are disabled, the power
  6454. * well is disabled and most interrupts are disabled, and these are also
  6455. * requirements for runtime PM. When these conditions are met, we manually do
  6456. * the other conditions: disable the interrupts, clocks and switch LCPLL refclk
  6457. * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard
  6458. * hang the machine.
  6459. *
  6460. * When we really reach PC8 or deeper states (not just when we allow it) we lose
  6461. * the state of some registers, so when we come back from PC8+ we need to
  6462. * restore this state. We don't get into PC8+ if we're not in RC6, so we don't
  6463. * need to take care of the registers kept by RC6. Notice that this happens even
  6464. * if we don't put the device in PCI D3 state (which is what currently happens
  6465. * because of the runtime PM support).
  6466. *
  6467. * For more, read "Display Sequences for Package C8" on the hardware
  6468. * documentation.
  6469. */
  6470. void hsw_enable_pc8(struct drm_i915_private *dev_priv)
  6471. {
  6472. struct drm_device *dev = dev_priv->dev;
  6473. uint32_t val;
  6474. DRM_DEBUG_KMS("Enabling package C8+\n");
  6475. if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) {
  6476. val = I915_READ(SOUTH_DSPCLK_GATE_D);
  6477. val &= ~PCH_LP_PARTITION_LEVEL_DISABLE;
  6478. I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
  6479. }
  6480. lpt_disable_clkout_dp(dev);
  6481. hsw_disable_lcpll(dev_priv, true, true);
  6482. }
  6483. void hsw_disable_pc8(struct drm_i915_private *dev_priv)
  6484. {
  6485. struct drm_device *dev = dev_priv->dev;
  6486. uint32_t val;
  6487. DRM_DEBUG_KMS("Disabling package C8+\n");
  6488. hsw_restore_lcpll(dev_priv);
  6489. lpt_init_pch_refclk(dev);
  6490. if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) {
  6491. val = I915_READ(SOUTH_DSPCLK_GATE_D);
  6492. val |= PCH_LP_PARTITION_LEVEL_DISABLE;
  6493. I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
  6494. }
  6495. intel_prepare_ddi(dev);
  6496. }
  6497. static void snb_modeset_global_resources(struct drm_device *dev)
  6498. {
  6499. modeset_update_crtc_power_domains(dev);
  6500. }
  6501. static void haswell_modeset_global_resources(struct drm_device *dev)
  6502. {
  6503. modeset_update_crtc_power_domains(dev);
  6504. }
  6505. static int haswell_crtc_mode_set(struct drm_crtc *crtc,
  6506. int x, int y,
  6507. struct drm_framebuffer *fb)
  6508. {
  6509. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6510. if (!intel_ddi_pll_select(intel_crtc))
  6511. return -EINVAL;
  6512. intel_crtc->lowfreq_avail = false;
  6513. return 0;
  6514. }
  6515. static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv,
  6516. enum port port,
  6517. struct intel_crtc_config *pipe_config)
  6518. {
  6519. pipe_config->ddi_pll_sel = I915_READ(PORT_CLK_SEL(port));
  6520. switch (pipe_config->ddi_pll_sel) {
  6521. case PORT_CLK_SEL_WRPLL1:
  6522. pipe_config->shared_dpll = DPLL_ID_WRPLL1;
  6523. break;
  6524. case PORT_CLK_SEL_WRPLL2:
  6525. pipe_config->shared_dpll = DPLL_ID_WRPLL2;
  6526. break;
  6527. }
  6528. }
  6529. static void haswell_get_ddi_port_state(struct intel_crtc *crtc,
  6530. struct intel_crtc_config *pipe_config)
  6531. {
  6532. struct drm_device *dev = crtc->base.dev;
  6533. struct drm_i915_private *dev_priv = dev->dev_private;
  6534. struct intel_shared_dpll *pll;
  6535. enum port port;
  6536. uint32_t tmp;
  6537. tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder));
  6538. port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT;
  6539. haswell_get_ddi_pll(dev_priv, port, pipe_config);
  6540. if (pipe_config->shared_dpll >= 0) {
  6541. pll = &dev_priv->shared_dplls[pipe_config->shared_dpll];
  6542. WARN_ON(!pll->get_hw_state(dev_priv, pll,
  6543. &pipe_config->dpll_hw_state));
  6544. }
  6545. /*
  6546. * Haswell has only FDI/PCH transcoder A. It is which is connected to
  6547. * DDI E. So just check whether this pipe is wired to DDI E and whether
  6548. * the PCH transcoder is on.
  6549. */
  6550. if ((port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) {
  6551. pipe_config->has_pch_encoder = true;
  6552. tmp = I915_READ(FDI_RX_CTL(PIPE_A));
  6553. pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
  6554. FDI_DP_PORT_WIDTH_SHIFT) + 1;
  6555. ironlake_get_fdi_m_n_config(crtc, pipe_config);
  6556. }
  6557. }
  6558. static bool haswell_get_pipe_config(struct intel_crtc *crtc,
  6559. struct intel_crtc_config *pipe_config)
  6560. {
  6561. struct drm_device *dev = crtc->base.dev;
  6562. struct drm_i915_private *dev_priv = dev->dev_private;
  6563. enum intel_display_power_domain pfit_domain;
  6564. uint32_t tmp;
  6565. if (!intel_display_power_enabled(dev_priv,
  6566. POWER_DOMAIN_PIPE(crtc->pipe)))
  6567. return false;
  6568. pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
  6569. pipe_config->shared_dpll = DPLL_ID_PRIVATE;
  6570. tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
  6571. if (tmp & TRANS_DDI_FUNC_ENABLE) {
  6572. enum pipe trans_edp_pipe;
  6573. switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
  6574. default:
  6575. WARN(1, "unknown pipe linked to edp transcoder\n");
  6576. case TRANS_DDI_EDP_INPUT_A_ONOFF:
  6577. case TRANS_DDI_EDP_INPUT_A_ON:
  6578. trans_edp_pipe = PIPE_A;
  6579. break;
  6580. case TRANS_DDI_EDP_INPUT_B_ONOFF:
  6581. trans_edp_pipe = PIPE_B;
  6582. break;
  6583. case TRANS_DDI_EDP_INPUT_C_ONOFF:
  6584. trans_edp_pipe = PIPE_C;
  6585. break;
  6586. }
  6587. if (trans_edp_pipe == crtc->pipe)
  6588. pipe_config->cpu_transcoder = TRANSCODER_EDP;
  6589. }
  6590. if (!intel_display_power_enabled(dev_priv,
  6591. POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder)))
  6592. return false;
  6593. tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder));
  6594. if (!(tmp & PIPECONF_ENABLE))
  6595. return false;
  6596. haswell_get_ddi_port_state(crtc, pipe_config);
  6597. intel_get_pipe_timings(crtc, pipe_config);
  6598. pfit_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe);
  6599. if (intel_display_power_enabled(dev_priv, pfit_domain))
  6600. ironlake_get_pfit_config(crtc, pipe_config);
  6601. if (IS_HASWELL(dev))
  6602. pipe_config->ips_enabled = hsw_crtc_supports_ips(crtc) &&
  6603. (I915_READ(IPS_CTL) & IPS_ENABLE);
  6604. if (pipe_config->cpu_transcoder != TRANSCODER_EDP) {
  6605. pipe_config->pixel_multiplier =
  6606. I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1;
  6607. } else {
  6608. pipe_config->pixel_multiplier = 1;
  6609. }
  6610. return true;
  6611. }
  6612. static struct {
  6613. int clock;
  6614. u32 config;
  6615. } hdmi_audio_clock[] = {
  6616. { DIV_ROUND_UP(25200 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_25175 },
  6617. { 25200, AUD_CONFIG_PIXEL_CLOCK_HDMI_25200 }, /* default per bspec */
  6618. { 27000, AUD_CONFIG_PIXEL_CLOCK_HDMI_27000 },
  6619. { 27000 * 1001 / 1000, AUD_CONFIG_PIXEL_CLOCK_HDMI_27027 },
  6620. { 54000, AUD_CONFIG_PIXEL_CLOCK_HDMI_54000 },
  6621. { 54000 * 1001 / 1000, AUD_CONFIG_PIXEL_CLOCK_HDMI_54054 },
  6622. { DIV_ROUND_UP(74250 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_74176 },
  6623. { 74250, AUD_CONFIG_PIXEL_CLOCK_HDMI_74250 },
  6624. { DIV_ROUND_UP(148500 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_148352 },
  6625. { 148500, AUD_CONFIG_PIXEL_CLOCK_HDMI_148500 },
  6626. };
  6627. /* get AUD_CONFIG_PIXEL_CLOCK_HDMI_* value for mode */
  6628. static u32 audio_config_hdmi_pixel_clock(struct drm_display_mode *mode)
  6629. {
  6630. int i;
  6631. for (i = 0; i < ARRAY_SIZE(hdmi_audio_clock); i++) {
  6632. if (mode->clock == hdmi_audio_clock[i].clock)
  6633. break;
  6634. }
  6635. if (i == ARRAY_SIZE(hdmi_audio_clock)) {
  6636. DRM_DEBUG_KMS("HDMI audio pixel clock setting for %d not found, falling back to defaults\n", mode->clock);
  6637. i = 1;
  6638. }
  6639. DRM_DEBUG_KMS("Configuring HDMI audio for pixel clock %d (0x%08x)\n",
  6640. hdmi_audio_clock[i].clock,
  6641. hdmi_audio_clock[i].config);
  6642. return hdmi_audio_clock[i].config;
  6643. }
  6644. static bool intel_eld_uptodate(struct drm_connector *connector,
  6645. int reg_eldv, uint32_t bits_eldv,
  6646. int reg_elda, uint32_t bits_elda,
  6647. int reg_edid)
  6648. {
  6649. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  6650. uint8_t *eld = connector->eld;
  6651. uint32_t i;
  6652. i = I915_READ(reg_eldv);
  6653. i &= bits_eldv;
  6654. if (!eld[0])
  6655. return !i;
  6656. if (!i)
  6657. return false;
  6658. i = I915_READ(reg_elda);
  6659. i &= ~bits_elda;
  6660. I915_WRITE(reg_elda, i);
  6661. for (i = 0; i < eld[2]; i++)
  6662. if (I915_READ(reg_edid) != *((uint32_t *)eld + i))
  6663. return false;
  6664. return true;
  6665. }
  6666. static void g4x_write_eld(struct drm_connector *connector,
  6667. struct drm_crtc *crtc,
  6668. struct drm_display_mode *mode)
  6669. {
  6670. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  6671. uint8_t *eld = connector->eld;
  6672. uint32_t eldv;
  6673. uint32_t len;
  6674. uint32_t i;
  6675. i = I915_READ(G4X_AUD_VID_DID);
  6676. if (i == INTEL_AUDIO_DEVBLC || i == INTEL_AUDIO_DEVCL)
  6677. eldv = G4X_ELDV_DEVCL_DEVBLC;
  6678. else
  6679. eldv = G4X_ELDV_DEVCTG;
  6680. if (intel_eld_uptodate(connector,
  6681. G4X_AUD_CNTL_ST, eldv,
  6682. G4X_AUD_CNTL_ST, G4X_ELD_ADDR,
  6683. G4X_HDMIW_HDMIEDID))
  6684. return;
  6685. i = I915_READ(G4X_AUD_CNTL_ST);
  6686. i &= ~(eldv | G4X_ELD_ADDR);
  6687. len = (i >> 9) & 0x1f; /* ELD buffer size */
  6688. I915_WRITE(G4X_AUD_CNTL_ST, i);
  6689. if (!eld[0])
  6690. return;
  6691. len = min_t(uint8_t, eld[2], len);
  6692. DRM_DEBUG_DRIVER("ELD size %d\n", len);
  6693. for (i = 0; i < len; i++)
  6694. I915_WRITE(G4X_HDMIW_HDMIEDID, *((uint32_t *)eld + i));
  6695. i = I915_READ(G4X_AUD_CNTL_ST);
  6696. i |= eldv;
  6697. I915_WRITE(G4X_AUD_CNTL_ST, i);
  6698. }
  6699. static void haswell_write_eld(struct drm_connector *connector,
  6700. struct drm_crtc *crtc,
  6701. struct drm_display_mode *mode)
  6702. {
  6703. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  6704. uint8_t *eld = connector->eld;
  6705. uint32_t eldv;
  6706. uint32_t i;
  6707. int len;
  6708. int pipe = to_intel_crtc(crtc)->pipe;
  6709. int tmp;
  6710. int hdmiw_hdmiedid = HSW_AUD_EDID_DATA(pipe);
  6711. int aud_cntl_st = HSW_AUD_DIP_ELD_CTRL(pipe);
  6712. int aud_config = HSW_AUD_CFG(pipe);
  6713. int aud_cntrl_st2 = HSW_AUD_PIN_ELD_CP_VLD;
  6714. /* Audio output enable */
  6715. DRM_DEBUG_DRIVER("HDMI audio: enable codec\n");
  6716. tmp = I915_READ(aud_cntrl_st2);
  6717. tmp |= (AUDIO_OUTPUT_ENABLE_A << (pipe * 4));
  6718. I915_WRITE(aud_cntrl_st2, tmp);
  6719. POSTING_READ(aud_cntrl_st2);
  6720. assert_pipe_disabled(dev_priv, to_intel_crtc(crtc)->pipe);
  6721. /* Set ELD valid state */
  6722. tmp = I915_READ(aud_cntrl_st2);
  6723. DRM_DEBUG_DRIVER("HDMI audio: pin eld vld status=0x%08x\n", tmp);
  6724. tmp |= (AUDIO_ELD_VALID_A << (pipe * 4));
  6725. I915_WRITE(aud_cntrl_st2, tmp);
  6726. tmp = I915_READ(aud_cntrl_st2);
  6727. DRM_DEBUG_DRIVER("HDMI audio: eld vld status=0x%08x\n", tmp);
  6728. /* Enable HDMI mode */
  6729. tmp = I915_READ(aud_config);
  6730. DRM_DEBUG_DRIVER("HDMI audio: audio conf: 0x%08x\n", tmp);
  6731. /* clear N_programing_enable and N_value_index */
  6732. tmp &= ~(AUD_CONFIG_N_VALUE_INDEX | AUD_CONFIG_N_PROG_ENABLE);
  6733. I915_WRITE(aud_config, tmp);
  6734. DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe));
  6735. eldv = AUDIO_ELD_VALID_A << (pipe * 4);
  6736. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) {
  6737. DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
  6738. eld[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
  6739. I915_WRITE(aud_config, AUD_CONFIG_N_VALUE_INDEX); /* 0x1 = DP */
  6740. } else {
  6741. I915_WRITE(aud_config, audio_config_hdmi_pixel_clock(mode));
  6742. }
  6743. if (intel_eld_uptodate(connector,
  6744. aud_cntrl_st2, eldv,
  6745. aud_cntl_st, IBX_ELD_ADDRESS,
  6746. hdmiw_hdmiedid))
  6747. return;
  6748. i = I915_READ(aud_cntrl_st2);
  6749. i &= ~eldv;
  6750. I915_WRITE(aud_cntrl_st2, i);
  6751. if (!eld[0])
  6752. return;
  6753. i = I915_READ(aud_cntl_st);
  6754. i &= ~IBX_ELD_ADDRESS;
  6755. I915_WRITE(aud_cntl_st, i);
  6756. i = (i >> 29) & DIP_PORT_SEL_MASK; /* DIP_Port_Select, 0x1 = PortB */
  6757. DRM_DEBUG_DRIVER("port num:%d\n", i);
  6758. len = min_t(uint8_t, eld[2], 21); /* 84 bytes of hw ELD buffer */
  6759. DRM_DEBUG_DRIVER("ELD size %d\n", len);
  6760. for (i = 0; i < len; i++)
  6761. I915_WRITE(hdmiw_hdmiedid, *((uint32_t *)eld + i));
  6762. i = I915_READ(aud_cntrl_st2);
  6763. i |= eldv;
  6764. I915_WRITE(aud_cntrl_st2, i);
  6765. }
  6766. static void ironlake_write_eld(struct drm_connector *connector,
  6767. struct drm_crtc *crtc,
  6768. struct drm_display_mode *mode)
  6769. {
  6770. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  6771. uint8_t *eld = connector->eld;
  6772. uint32_t eldv;
  6773. uint32_t i;
  6774. int len;
  6775. int hdmiw_hdmiedid;
  6776. int aud_config;
  6777. int aud_cntl_st;
  6778. int aud_cntrl_st2;
  6779. int pipe = to_intel_crtc(crtc)->pipe;
  6780. if (HAS_PCH_IBX(connector->dev)) {
  6781. hdmiw_hdmiedid = IBX_HDMIW_HDMIEDID(pipe);
  6782. aud_config = IBX_AUD_CFG(pipe);
  6783. aud_cntl_st = IBX_AUD_CNTL_ST(pipe);
  6784. aud_cntrl_st2 = IBX_AUD_CNTL_ST2;
  6785. } else if (IS_VALLEYVIEW(connector->dev)) {
  6786. hdmiw_hdmiedid = VLV_HDMIW_HDMIEDID(pipe);
  6787. aud_config = VLV_AUD_CFG(pipe);
  6788. aud_cntl_st = VLV_AUD_CNTL_ST(pipe);
  6789. aud_cntrl_st2 = VLV_AUD_CNTL_ST2;
  6790. } else {
  6791. hdmiw_hdmiedid = CPT_HDMIW_HDMIEDID(pipe);
  6792. aud_config = CPT_AUD_CFG(pipe);
  6793. aud_cntl_st = CPT_AUD_CNTL_ST(pipe);
  6794. aud_cntrl_st2 = CPT_AUD_CNTRL_ST2;
  6795. }
  6796. DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe));
  6797. if (IS_VALLEYVIEW(connector->dev)) {
  6798. struct intel_encoder *intel_encoder;
  6799. struct intel_digital_port *intel_dig_port;
  6800. intel_encoder = intel_attached_encoder(connector);
  6801. intel_dig_port = enc_to_dig_port(&intel_encoder->base);
  6802. i = intel_dig_port->port;
  6803. } else {
  6804. i = I915_READ(aud_cntl_st);
  6805. i = (i >> 29) & DIP_PORT_SEL_MASK;
  6806. /* DIP_Port_Select, 0x1 = PortB */
  6807. }
  6808. if (!i) {
  6809. DRM_DEBUG_DRIVER("Audio directed to unknown port\n");
  6810. /* operate blindly on all ports */
  6811. eldv = IBX_ELD_VALIDB;
  6812. eldv |= IBX_ELD_VALIDB << 4;
  6813. eldv |= IBX_ELD_VALIDB << 8;
  6814. } else {
  6815. DRM_DEBUG_DRIVER("ELD on port %c\n", port_name(i));
  6816. eldv = IBX_ELD_VALIDB << ((i - 1) * 4);
  6817. }
  6818. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) {
  6819. DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
  6820. eld[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
  6821. I915_WRITE(aud_config, AUD_CONFIG_N_VALUE_INDEX); /* 0x1 = DP */
  6822. } else {
  6823. I915_WRITE(aud_config, audio_config_hdmi_pixel_clock(mode));
  6824. }
  6825. if (intel_eld_uptodate(connector,
  6826. aud_cntrl_st2, eldv,
  6827. aud_cntl_st, IBX_ELD_ADDRESS,
  6828. hdmiw_hdmiedid))
  6829. return;
  6830. i = I915_READ(aud_cntrl_st2);
  6831. i &= ~eldv;
  6832. I915_WRITE(aud_cntrl_st2, i);
  6833. if (!eld[0])
  6834. return;
  6835. i = I915_READ(aud_cntl_st);
  6836. i &= ~IBX_ELD_ADDRESS;
  6837. I915_WRITE(aud_cntl_st, i);
  6838. len = min_t(uint8_t, eld[2], 21); /* 84 bytes of hw ELD buffer */
  6839. DRM_DEBUG_DRIVER("ELD size %d\n", len);
  6840. for (i = 0; i < len; i++)
  6841. I915_WRITE(hdmiw_hdmiedid, *((uint32_t *)eld + i));
  6842. i = I915_READ(aud_cntrl_st2);
  6843. i |= eldv;
  6844. I915_WRITE(aud_cntrl_st2, i);
  6845. }
  6846. void intel_write_eld(struct drm_encoder *encoder,
  6847. struct drm_display_mode *mode)
  6848. {
  6849. struct drm_crtc *crtc = encoder->crtc;
  6850. struct drm_connector *connector;
  6851. struct drm_device *dev = encoder->dev;
  6852. struct drm_i915_private *dev_priv = dev->dev_private;
  6853. connector = drm_select_eld(encoder, mode);
  6854. if (!connector)
  6855. return;
  6856. DRM_DEBUG_DRIVER("ELD on [CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
  6857. connector->base.id,
  6858. connector->name,
  6859. connector->encoder->base.id,
  6860. connector->encoder->name);
  6861. connector->eld[6] = drm_av_sync_delay(connector, mode) / 2;
  6862. if (dev_priv->display.write_eld)
  6863. dev_priv->display.write_eld(connector, crtc, mode);
  6864. }
  6865. static void i845_update_cursor(struct drm_crtc *crtc, u32 base)
  6866. {
  6867. struct drm_device *dev = crtc->dev;
  6868. struct drm_i915_private *dev_priv = dev->dev_private;
  6869. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6870. uint32_t cntl = 0, size = 0;
  6871. if (base) {
  6872. unsigned int width = intel_crtc->cursor_width;
  6873. unsigned int height = intel_crtc->cursor_height;
  6874. unsigned int stride = roundup_pow_of_two(width) * 4;
  6875. switch (stride) {
  6876. default:
  6877. WARN_ONCE(1, "Invalid cursor width/stride, width=%u, stride=%u\n",
  6878. width, stride);
  6879. stride = 256;
  6880. /* fallthrough */
  6881. case 256:
  6882. case 512:
  6883. case 1024:
  6884. case 2048:
  6885. break;
  6886. }
  6887. cntl |= CURSOR_ENABLE |
  6888. CURSOR_GAMMA_ENABLE |
  6889. CURSOR_FORMAT_ARGB |
  6890. CURSOR_STRIDE(stride);
  6891. size = (height << 12) | width;
  6892. }
  6893. if (intel_crtc->cursor_cntl != 0 &&
  6894. (intel_crtc->cursor_base != base ||
  6895. intel_crtc->cursor_size != size ||
  6896. intel_crtc->cursor_cntl != cntl)) {
  6897. /* On these chipsets we can only modify the base/size/stride
  6898. * whilst the cursor is disabled.
  6899. */
  6900. I915_WRITE(_CURACNTR, 0);
  6901. POSTING_READ(_CURACNTR);
  6902. intel_crtc->cursor_cntl = 0;
  6903. }
  6904. if (intel_crtc->cursor_base != base)
  6905. I915_WRITE(_CURABASE, base);
  6906. if (intel_crtc->cursor_size != size) {
  6907. I915_WRITE(CURSIZE, size);
  6908. intel_crtc->cursor_size = size;
  6909. }
  6910. if (intel_crtc->cursor_cntl != cntl) {
  6911. I915_WRITE(_CURACNTR, cntl);
  6912. POSTING_READ(_CURACNTR);
  6913. intel_crtc->cursor_cntl = cntl;
  6914. }
  6915. }
  6916. static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base)
  6917. {
  6918. struct drm_device *dev = crtc->dev;
  6919. struct drm_i915_private *dev_priv = dev->dev_private;
  6920. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6921. int pipe = intel_crtc->pipe;
  6922. uint32_t cntl;
  6923. cntl = 0;
  6924. if (base) {
  6925. cntl = MCURSOR_GAMMA_ENABLE;
  6926. switch (intel_crtc->cursor_width) {
  6927. case 64:
  6928. cntl |= CURSOR_MODE_64_ARGB_AX;
  6929. break;
  6930. case 128:
  6931. cntl |= CURSOR_MODE_128_ARGB_AX;
  6932. break;
  6933. case 256:
  6934. cntl |= CURSOR_MODE_256_ARGB_AX;
  6935. break;
  6936. default:
  6937. WARN_ON(1);
  6938. return;
  6939. }
  6940. cntl |= pipe << 28; /* Connect to correct pipe */
  6941. }
  6942. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  6943. cntl |= CURSOR_PIPE_CSC_ENABLE;
  6944. if (intel_crtc->cursor_cntl != cntl) {
  6945. I915_WRITE(CURCNTR(pipe), cntl);
  6946. POSTING_READ(CURCNTR(pipe));
  6947. intel_crtc->cursor_cntl = cntl;
  6948. }
  6949. /* and commit changes on next vblank */
  6950. I915_WRITE(CURBASE(pipe), base);
  6951. POSTING_READ(CURBASE(pipe));
  6952. }
  6953. /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */
  6954. static void intel_crtc_update_cursor(struct drm_crtc *crtc,
  6955. bool on)
  6956. {
  6957. struct drm_device *dev = crtc->dev;
  6958. struct drm_i915_private *dev_priv = dev->dev_private;
  6959. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6960. int pipe = intel_crtc->pipe;
  6961. int x = crtc->cursor_x;
  6962. int y = crtc->cursor_y;
  6963. u32 base = 0, pos = 0;
  6964. if (on)
  6965. base = intel_crtc->cursor_addr;
  6966. if (x >= intel_crtc->config.pipe_src_w)
  6967. base = 0;
  6968. if (y >= intel_crtc->config.pipe_src_h)
  6969. base = 0;
  6970. if (x < 0) {
  6971. if (x + intel_crtc->cursor_width <= 0)
  6972. base = 0;
  6973. pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
  6974. x = -x;
  6975. }
  6976. pos |= x << CURSOR_X_SHIFT;
  6977. if (y < 0) {
  6978. if (y + intel_crtc->cursor_height <= 0)
  6979. base = 0;
  6980. pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
  6981. y = -y;
  6982. }
  6983. pos |= y << CURSOR_Y_SHIFT;
  6984. if (base == 0 && intel_crtc->cursor_base == 0)
  6985. return;
  6986. I915_WRITE(CURPOS(pipe), pos);
  6987. if (IS_845G(dev) || IS_I865G(dev))
  6988. i845_update_cursor(crtc, base);
  6989. else
  6990. i9xx_update_cursor(crtc, base);
  6991. intel_crtc->cursor_base = base;
  6992. }
  6993. static bool cursor_size_ok(struct drm_device *dev,
  6994. uint32_t width, uint32_t height)
  6995. {
  6996. if (width == 0 || height == 0)
  6997. return false;
  6998. /*
  6999. * 845g/865g are special in that they are only limited by
  7000. * the width of their cursors, the height is arbitrary up to
  7001. * the precision of the register. Everything else requires
  7002. * square cursors, limited to a few power-of-two sizes.
  7003. */
  7004. if (IS_845G(dev) || IS_I865G(dev)) {
  7005. if ((width & 63) != 0)
  7006. return false;
  7007. if (width > (IS_845G(dev) ? 64 : 512))
  7008. return false;
  7009. if (height > 1023)
  7010. return false;
  7011. } else {
  7012. switch (width | height) {
  7013. case 256:
  7014. case 128:
  7015. if (IS_GEN2(dev))
  7016. return false;
  7017. case 64:
  7018. break;
  7019. default:
  7020. return false;
  7021. }
  7022. }
  7023. return true;
  7024. }
  7025. /*
  7026. * intel_crtc_cursor_set_obj - Set cursor to specified GEM object
  7027. *
  7028. * Note that the object's reference will be consumed if the update fails. If
  7029. * the update succeeds, the reference of the old object (if any) will be
  7030. * consumed.
  7031. */
  7032. static int intel_crtc_cursor_set_obj(struct drm_crtc *crtc,
  7033. struct drm_i915_gem_object *obj,
  7034. uint32_t width, uint32_t height)
  7035. {
  7036. struct drm_device *dev = crtc->dev;
  7037. struct drm_i915_private *dev_priv = dev->dev_private;
  7038. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7039. enum pipe pipe = intel_crtc->pipe;
  7040. unsigned old_width, stride;
  7041. uint32_t addr;
  7042. int ret;
  7043. /* if we want to turn off the cursor ignore width and height */
  7044. if (!obj) {
  7045. DRM_DEBUG_KMS("cursor off\n");
  7046. addr = 0;
  7047. mutex_lock(&dev->struct_mutex);
  7048. goto finish;
  7049. }
  7050. /* Check for which cursor types we support */
  7051. if (!cursor_size_ok(dev, width, height)) {
  7052. DRM_DEBUG("Cursor dimension not supported\n");
  7053. return -EINVAL;
  7054. }
  7055. stride = roundup_pow_of_two(width) * 4;
  7056. if (obj->base.size < stride * height) {
  7057. DRM_DEBUG_KMS("buffer is too small\n");
  7058. ret = -ENOMEM;
  7059. goto fail;
  7060. }
  7061. /* we only need to pin inside GTT if cursor is non-phy */
  7062. mutex_lock(&dev->struct_mutex);
  7063. if (!INTEL_INFO(dev)->cursor_needs_physical) {
  7064. unsigned alignment;
  7065. if (obj->tiling_mode) {
  7066. DRM_DEBUG_KMS("cursor cannot be tiled\n");
  7067. ret = -EINVAL;
  7068. goto fail_locked;
  7069. }
  7070. /*
  7071. * Global gtt pte registers are special registers which actually
  7072. * forward writes to a chunk of system memory. Which means that
  7073. * there is no risk that the register values disappear as soon
  7074. * as we call intel_runtime_pm_put(), so it is correct to wrap
  7075. * only the pin/unpin/fence and not more.
  7076. */
  7077. intel_runtime_pm_get(dev_priv);
  7078. /* Note that the w/a also requires 2 PTE of padding following
  7079. * the bo. We currently fill all unused PTE with the shadow
  7080. * page and so we should always have valid PTE following the
  7081. * cursor preventing the VT-d warning.
  7082. */
  7083. alignment = 0;
  7084. if (need_vtd_wa(dev))
  7085. alignment = 64*1024;
  7086. ret = i915_gem_object_pin_to_display_plane(obj, alignment, NULL);
  7087. if (ret) {
  7088. DRM_DEBUG_KMS("failed to move cursor bo into the GTT\n");
  7089. intel_runtime_pm_put(dev_priv);
  7090. goto fail_locked;
  7091. }
  7092. ret = i915_gem_object_put_fence(obj);
  7093. if (ret) {
  7094. DRM_DEBUG_KMS("failed to release fence for cursor");
  7095. intel_runtime_pm_put(dev_priv);
  7096. goto fail_unpin;
  7097. }
  7098. addr = i915_gem_obj_ggtt_offset(obj);
  7099. intel_runtime_pm_put(dev_priv);
  7100. } else {
  7101. int align = IS_I830(dev) ? 16 * 1024 : 256;
  7102. ret = i915_gem_object_attach_phys(obj, align);
  7103. if (ret) {
  7104. DRM_DEBUG_KMS("failed to attach phys object\n");
  7105. goto fail_locked;
  7106. }
  7107. addr = obj->phys_handle->busaddr;
  7108. }
  7109. finish:
  7110. if (intel_crtc->cursor_bo) {
  7111. if (!INTEL_INFO(dev)->cursor_needs_physical)
  7112. i915_gem_object_unpin_from_display_plane(intel_crtc->cursor_bo);
  7113. }
  7114. i915_gem_track_fb(intel_crtc->cursor_bo, obj,
  7115. INTEL_FRONTBUFFER_CURSOR(pipe));
  7116. mutex_unlock(&dev->struct_mutex);
  7117. old_width = intel_crtc->cursor_width;
  7118. intel_crtc->cursor_addr = addr;
  7119. intel_crtc->cursor_bo = obj;
  7120. intel_crtc->cursor_width = width;
  7121. intel_crtc->cursor_height = height;
  7122. if (intel_crtc->active) {
  7123. if (old_width != width)
  7124. intel_update_watermarks(crtc);
  7125. intel_crtc_update_cursor(crtc, intel_crtc->cursor_bo != NULL);
  7126. }
  7127. intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_CURSOR(pipe));
  7128. return 0;
  7129. fail_unpin:
  7130. i915_gem_object_unpin_from_display_plane(obj);
  7131. fail_locked:
  7132. mutex_unlock(&dev->struct_mutex);
  7133. fail:
  7134. drm_gem_object_unreference_unlocked(&obj->base);
  7135. return ret;
  7136. }
  7137. static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
  7138. u16 *blue, uint32_t start, uint32_t size)
  7139. {
  7140. int end = (start + size > 256) ? 256 : start + size, i;
  7141. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7142. for (i = start; i < end; i++) {
  7143. intel_crtc->lut_r[i] = red[i] >> 8;
  7144. intel_crtc->lut_g[i] = green[i] >> 8;
  7145. intel_crtc->lut_b[i] = blue[i] >> 8;
  7146. }
  7147. intel_crtc_load_lut(crtc);
  7148. }
  7149. /* VESA 640x480x72Hz mode to set on the pipe */
  7150. static struct drm_display_mode load_detect_mode = {
  7151. DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
  7152. 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  7153. };
  7154. struct drm_framebuffer *
  7155. __intel_framebuffer_create(struct drm_device *dev,
  7156. struct drm_mode_fb_cmd2 *mode_cmd,
  7157. struct drm_i915_gem_object *obj)
  7158. {
  7159. struct intel_framebuffer *intel_fb;
  7160. int ret;
  7161. intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
  7162. if (!intel_fb) {
  7163. drm_gem_object_unreference_unlocked(&obj->base);
  7164. return ERR_PTR(-ENOMEM);
  7165. }
  7166. ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj);
  7167. if (ret)
  7168. goto err;
  7169. return &intel_fb->base;
  7170. err:
  7171. drm_gem_object_unreference_unlocked(&obj->base);
  7172. kfree(intel_fb);
  7173. return ERR_PTR(ret);
  7174. }
  7175. static struct drm_framebuffer *
  7176. intel_framebuffer_create(struct drm_device *dev,
  7177. struct drm_mode_fb_cmd2 *mode_cmd,
  7178. struct drm_i915_gem_object *obj)
  7179. {
  7180. struct drm_framebuffer *fb;
  7181. int ret;
  7182. ret = i915_mutex_lock_interruptible(dev);
  7183. if (ret)
  7184. return ERR_PTR(ret);
  7185. fb = __intel_framebuffer_create(dev, mode_cmd, obj);
  7186. mutex_unlock(&dev->struct_mutex);
  7187. return fb;
  7188. }
  7189. static u32
  7190. intel_framebuffer_pitch_for_width(int width, int bpp)
  7191. {
  7192. u32 pitch = DIV_ROUND_UP(width * bpp, 8);
  7193. return ALIGN(pitch, 64);
  7194. }
  7195. static u32
  7196. intel_framebuffer_size_for_mode(struct drm_display_mode *mode, int bpp)
  7197. {
  7198. u32 pitch = intel_framebuffer_pitch_for_width(mode->hdisplay, bpp);
  7199. return PAGE_ALIGN(pitch * mode->vdisplay);
  7200. }
  7201. static struct drm_framebuffer *
  7202. intel_framebuffer_create_for_mode(struct drm_device *dev,
  7203. struct drm_display_mode *mode,
  7204. int depth, int bpp)
  7205. {
  7206. struct drm_i915_gem_object *obj;
  7207. struct drm_mode_fb_cmd2 mode_cmd = { 0 };
  7208. obj = i915_gem_alloc_object(dev,
  7209. intel_framebuffer_size_for_mode(mode, bpp));
  7210. if (obj == NULL)
  7211. return ERR_PTR(-ENOMEM);
  7212. mode_cmd.width = mode->hdisplay;
  7213. mode_cmd.height = mode->vdisplay;
  7214. mode_cmd.pitches[0] = intel_framebuffer_pitch_for_width(mode_cmd.width,
  7215. bpp);
  7216. mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth);
  7217. return intel_framebuffer_create(dev, &mode_cmd, obj);
  7218. }
  7219. static struct drm_framebuffer *
  7220. mode_fits_in_fbdev(struct drm_device *dev,
  7221. struct drm_display_mode *mode)
  7222. {
  7223. #ifdef CONFIG_DRM_I915_FBDEV
  7224. struct drm_i915_private *dev_priv = dev->dev_private;
  7225. struct drm_i915_gem_object *obj;
  7226. struct drm_framebuffer *fb;
  7227. if (!dev_priv->fbdev)
  7228. return NULL;
  7229. if (!dev_priv->fbdev->fb)
  7230. return NULL;
  7231. obj = dev_priv->fbdev->fb->obj;
  7232. BUG_ON(!obj);
  7233. fb = &dev_priv->fbdev->fb->base;
  7234. if (fb->pitches[0] < intel_framebuffer_pitch_for_width(mode->hdisplay,
  7235. fb->bits_per_pixel))
  7236. return NULL;
  7237. if (obj->base.size < mode->vdisplay * fb->pitches[0])
  7238. return NULL;
  7239. return fb;
  7240. #else
  7241. return NULL;
  7242. #endif
  7243. }
  7244. bool intel_get_load_detect_pipe(struct drm_connector *connector,
  7245. struct drm_display_mode *mode,
  7246. struct intel_load_detect_pipe *old,
  7247. struct drm_modeset_acquire_ctx *ctx)
  7248. {
  7249. struct intel_crtc *intel_crtc;
  7250. struct intel_encoder *intel_encoder =
  7251. intel_attached_encoder(connector);
  7252. struct drm_crtc *possible_crtc;
  7253. struct drm_encoder *encoder = &intel_encoder->base;
  7254. struct drm_crtc *crtc = NULL;
  7255. struct drm_device *dev = encoder->dev;
  7256. struct drm_framebuffer *fb;
  7257. struct drm_mode_config *config = &dev->mode_config;
  7258. int ret, i = -1;
  7259. DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
  7260. connector->base.id, connector->name,
  7261. encoder->base.id, encoder->name);
  7262. retry:
  7263. ret = drm_modeset_lock(&config->connection_mutex, ctx);
  7264. if (ret)
  7265. goto fail_unlock;
  7266. /*
  7267. * Algorithm gets a little messy:
  7268. *
  7269. * - if the connector already has an assigned crtc, use it (but make
  7270. * sure it's on first)
  7271. *
  7272. * - try to find the first unused crtc that can drive this connector,
  7273. * and use that if we find one
  7274. */
  7275. /* See if we already have a CRTC for this connector */
  7276. if (encoder->crtc) {
  7277. crtc = encoder->crtc;
  7278. ret = drm_modeset_lock(&crtc->mutex, ctx);
  7279. if (ret)
  7280. goto fail_unlock;
  7281. old->dpms_mode = connector->dpms;
  7282. old->load_detect_temp = false;
  7283. /* Make sure the crtc and connector are running */
  7284. if (connector->dpms != DRM_MODE_DPMS_ON)
  7285. connector->funcs->dpms(connector, DRM_MODE_DPMS_ON);
  7286. return true;
  7287. }
  7288. /* Find an unused one (if possible) */
  7289. for_each_crtc(dev, possible_crtc) {
  7290. i++;
  7291. if (!(encoder->possible_crtcs & (1 << i)))
  7292. continue;
  7293. if (possible_crtc->enabled)
  7294. continue;
  7295. /* This can occur when applying the pipe A quirk on resume. */
  7296. if (to_intel_crtc(possible_crtc)->new_enabled)
  7297. continue;
  7298. crtc = possible_crtc;
  7299. break;
  7300. }
  7301. /*
  7302. * If we didn't find an unused CRTC, don't use any.
  7303. */
  7304. if (!crtc) {
  7305. DRM_DEBUG_KMS("no pipe available for load-detect\n");
  7306. goto fail_unlock;
  7307. }
  7308. ret = drm_modeset_lock(&crtc->mutex, ctx);
  7309. if (ret)
  7310. goto fail_unlock;
  7311. intel_encoder->new_crtc = to_intel_crtc(crtc);
  7312. to_intel_connector(connector)->new_encoder = intel_encoder;
  7313. intel_crtc = to_intel_crtc(crtc);
  7314. intel_crtc->new_enabled = true;
  7315. intel_crtc->new_config = &intel_crtc->config;
  7316. old->dpms_mode = connector->dpms;
  7317. old->load_detect_temp = true;
  7318. old->release_fb = NULL;
  7319. if (!mode)
  7320. mode = &load_detect_mode;
  7321. /* We need a framebuffer large enough to accommodate all accesses
  7322. * that the plane may generate whilst we perform load detection.
  7323. * We can not rely on the fbcon either being present (we get called
  7324. * during its initialisation to detect all boot displays, or it may
  7325. * not even exist) or that it is large enough to satisfy the
  7326. * requested mode.
  7327. */
  7328. fb = mode_fits_in_fbdev(dev, mode);
  7329. if (fb == NULL) {
  7330. DRM_DEBUG_KMS("creating tmp fb for load-detection\n");
  7331. fb = intel_framebuffer_create_for_mode(dev, mode, 24, 32);
  7332. old->release_fb = fb;
  7333. } else
  7334. DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n");
  7335. if (IS_ERR(fb)) {
  7336. DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n");
  7337. goto fail;
  7338. }
  7339. if (intel_set_mode(crtc, mode, 0, 0, fb)) {
  7340. DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
  7341. if (old->release_fb)
  7342. old->release_fb->funcs->destroy(old->release_fb);
  7343. goto fail;
  7344. }
  7345. /* let the connector get through one full cycle before testing */
  7346. intel_wait_for_vblank(dev, intel_crtc->pipe);
  7347. return true;
  7348. fail:
  7349. intel_crtc->new_enabled = crtc->enabled;
  7350. if (intel_crtc->new_enabled)
  7351. intel_crtc->new_config = &intel_crtc->config;
  7352. else
  7353. intel_crtc->new_config = NULL;
  7354. fail_unlock:
  7355. if (ret == -EDEADLK) {
  7356. drm_modeset_backoff(ctx);
  7357. goto retry;
  7358. }
  7359. return false;
  7360. }
  7361. void intel_release_load_detect_pipe(struct drm_connector *connector,
  7362. struct intel_load_detect_pipe *old)
  7363. {
  7364. struct intel_encoder *intel_encoder =
  7365. intel_attached_encoder(connector);
  7366. struct drm_encoder *encoder = &intel_encoder->base;
  7367. struct drm_crtc *crtc = encoder->crtc;
  7368. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7369. DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
  7370. connector->base.id, connector->name,
  7371. encoder->base.id, encoder->name);
  7372. if (old->load_detect_temp) {
  7373. to_intel_connector(connector)->new_encoder = NULL;
  7374. intel_encoder->new_crtc = NULL;
  7375. intel_crtc->new_enabled = false;
  7376. intel_crtc->new_config = NULL;
  7377. intel_set_mode(crtc, NULL, 0, 0, NULL);
  7378. if (old->release_fb) {
  7379. drm_framebuffer_unregister_private(old->release_fb);
  7380. drm_framebuffer_unreference(old->release_fb);
  7381. }
  7382. return;
  7383. }
  7384. /* Switch crtc and encoder back off if necessary */
  7385. if (old->dpms_mode != DRM_MODE_DPMS_ON)
  7386. connector->funcs->dpms(connector, old->dpms_mode);
  7387. }
  7388. static int i9xx_pll_refclk(struct drm_device *dev,
  7389. const struct intel_crtc_config *pipe_config)
  7390. {
  7391. struct drm_i915_private *dev_priv = dev->dev_private;
  7392. u32 dpll = pipe_config->dpll_hw_state.dpll;
  7393. if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN)
  7394. return dev_priv->vbt.lvds_ssc_freq;
  7395. else if (HAS_PCH_SPLIT(dev))
  7396. return 120000;
  7397. else if (!IS_GEN2(dev))
  7398. return 96000;
  7399. else
  7400. return 48000;
  7401. }
  7402. /* Returns the clock of the currently programmed mode of the given pipe. */
  7403. static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
  7404. struct intel_crtc_config *pipe_config)
  7405. {
  7406. struct drm_device *dev = crtc->base.dev;
  7407. struct drm_i915_private *dev_priv = dev->dev_private;
  7408. int pipe = pipe_config->cpu_transcoder;
  7409. u32 dpll = pipe_config->dpll_hw_state.dpll;
  7410. u32 fp;
  7411. intel_clock_t clock;
  7412. int refclk = i9xx_pll_refclk(dev, pipe_config);
  7413. if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
  7414. fp = pipe_config->dpll_hw_state.fp0;
  7415. else
  7416. fp = pipe_config->dpll_hw_state.fp1;
  7417. clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
  7418. if (IS_PINEVIEW(dev)) {
  7419. clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
  7420. clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
  7421. } else {
  7422. clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
  7423. clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
  7424. }
  7425. if (!IS_GEN2(dev)) {
  7426. if (IS_PINEVIEW(dev))
  7427. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
  7428. DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
  7429. else
  7430. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
  7431. DPLL_FPA01_P1_POST_DIV_SHIFT);
  7432. switch (dpll & DPLL_MODE_MASK) {
  7433. case DPLLB_MODE_DAC_SERIAL:
  7434. clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
  7435. 5 : 10;
  7436. break;
  7437. case DPLLB_MODE_LVDS:
  7438. clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
  7439. 7 : 14;
  7440. break;
  7441. default:
  7442. DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
  7443. "mode\n", (int)(dpll & DPLL_MODE_MASK));
  7444. return;
  7445. }
  7446. if (IS_PINEVIEW(dev))
  7447. pineview_clock(refclk, &clock);
  7448. else
  7449. i9xx_clock(refclk, &clock);
  7450. } else {
  7451. u32 lvds = IS_I830(dev) ? 0 : I915_READ(LVDS);
  7452. bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN);
  7453. if (is_lvds) {
  7454. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
  7455. DPLL_FPA01_P1_POST_DIV_SHIFT);
  7456. if (lvds & LVDS_CLKB_POWER_UP)
  7457. clock.p2 = 7;
  7458. else
  7459. clock.p2 = 14;
  7460. } else {
  7461. if (dpll & PLL_P1_DIVIDE_BY_TWO)
  7462. clock.p1 = 2;
  7463. else {
  7464. clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
  7465. DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
  7466. }
  7467. if (dpll & PLL_P2_DIVIDE_BY_4)
  7468. clock.p2 = 4;
  7469. else
  7470. clock.p2 = 2;
  7471. }
  7472. i9xx_clock(refclk, &clock);
  7473. }
  7474. /*
  7475. * This value includes pixel_multiplier. We will use
  7476. * port_clock to compute adjusted_mode.crtc_clock in the
  7477. * encoder's get_config() function.
  7478. */
  7479. pipe_config->port_clock = clock.dot;
  7480. }
  7481. int intel_dotclock_calculate(int link_freq,
  7482. const struct intel_link_m_n *m_n)
  7483. {
  7484. /*
  7485. * The calculation for the data clock is:
  7486. * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
  7487. * But we want to avoid losing precison if possible, so:
  7488. * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
  7489. *
  7490. * and the link clock is simpler:
  7491. * link_clock = (m * link_clock) / n
  7492. */
  7493. if (!m_n->link_n)
  7494. return 0;
  7495. return div_u64((u64)m_n->link_m * link_freq, m_n->link_n);
  7496. }
  7497. static void ironlake_pch_clock_get(struct intel_crtc *crtc,
  7498. struct intel_crtc_config *pipe_config)
  7499. {
  7500. struct drm_device *dev = crtc->base.dev;
  7501. /* read out port_clock from the DPLL */
  7502. i9xx_crtc_clock_get(crtc, pipe_config);
  7503. /*
  7504. * This value does not include pixel_multiplier.
  7505. * We will check that port_clock and adjusted_mode.crtc_clock
  7506. * agree once we know their relationship in the encoder's
  7507. * get_config() function.
  7508. */
  7509. pipe_config->adjusted_mode.crtc_clock =
  7510. intel_dotclock_calculate(intel_fdi_link_freq(dev) * 10000,
  7511. &pipe_config->fdi_m_n);
  7512. }
  7513. /** Returns the currently programmed mode of the given pipe. */
  7514. struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev,
  7515. struct drm_crtc *crtc)
  7516. {
  7517. struct drm_i915_private *dev_priv = dev->dev_private;
  7518. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7519. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  7520. struct drm_display_mode *mode;
  7521. struct intel_crtc_config pipe_config;
  7522. int htot = I915_READ(HTOTAL(cpu_transcoder));
  7523. int hsync = I915_READ(HSYNC(cpu_transcoder));
  7524. int vtot = I915_READ(VTOTAL(cpu_transcoder));
  7525. int vsync = I915_READ(VSYNC(cpu_transcoder));
  7526. enum pipe pipe = intel_crtc->pipe;
  7527. mode = kzalloc(sizeof(*mode), GFP_KERNEL);
  7528. if (!mode)
  7529. return NULL;
  7530. /*
  7531. * Construct a pipe_config sufficient for getting the clock info
  7532. * back out of crtc_clock_get.
  7533. *
  7534. * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need
  7535. * to use a real value here instead.
  7536. */
  7537. pipe_config.cpu_transcoder = (enum transcoder) pipe;
  7538. pipe_config.pixel_multiplier = 1;
  7539. pipe_config.dpll_hw_state.dpll = I915_READ(DPLL(pipe));
  7540. pipe_config.dpll_hw_state.fp0 = I915_READ(FP0(pipe));
  7541. pipe_config.dpll_hw_state.fp1 = I915_READ(FP1(pipe));
  7542. i9xx_crtc_clock_get(intel_crtc, &pipe_config);
  7543. mode->clock = pipe_config.port_clock / pipe_config.pixel_multiplier;
  7544. mode->hdisplay = (htot & 0xffff) + 1;
  7545. mode->htotal = ((htot & 0xffff0000) >> 16) + 1;
  7546. mode->hsync_start = (hsync & 0xffff) + 1;
  7547. mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1;
  7548. mode->vdisplay = (vtot & 0xffff) + 1;
  7549. mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1;
  7550. mode->vsync_start = (vsync & 0xffff) + 1;
  7551. mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1;
  7552. drm_mode_set_name(mode);
  7553. return mode;
  7554. }
  7555. static void intel_increase_pllclock(struct drm_device *dev,
  7556. enum pipe pipe)
  7557. {
  7558. struct drm_i915_private *dev_priv = dev->dev_private;
  7559. int dpll_reg = DPLL(pipe);
  7560. int dpll;
  7561. if (!HAS_GMCH_DISPLAY(dev))
  7562. return;
  7563. if (!dev_priv->lvds_downclock_avail)
  7564. return;
  7565. dpll = I915_READ(dpll_reg);
  7566. if (!HAS_PIPE_CXSR(dev) && (dpll & DISPLAY_RATE_SELECT_FPA1)) {
  7567. DRM_DEBUG_DRIVER("upclocking LVDS\n");
  7568. assert_panel_unlocked(dev_priv, pipe);
  7569. dpll &= ~DISPLAY_RATE_SELECT_FPA1;
  7570. I915_WRITE(dpll_reg, dpll);
  7571. intel_wait_for_vblank(dev, pipe);
  7572. dpll = I915_READ(dpll_reg);
  7573. if (dpll & DISPLAY_RATE_SELECT_FPA1)
  7574. DRM_DEBUG_DRIVER("failed to upclock LVDS!\n");
  7575. }
  7576. }
  7577. static void intel_decrease_pllclock(struct drm_crtc *crtc)
  7578. {
  7579. struct drm_device *dev = crtc->dev;
  7580. struct drm_i915_private *dev_priv = dev->dev_private;
  7581. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7582. if (!HAS_GMCH_DISPLAY(dev))
  7583. return;
  7584. if (!dev_priv->lvds_downclock_avail)
  7585. return;
  7586. /*
  7587. * Since this is called by a timer, we should never get here in
  7588. * the manual case.
  7589. */
  7590. if (!HAS_PIPE_CXSR(dev) && intel_crtc->lowfreq_avail) {
  7591. int pipe = intel_crtc->pipe;
  7592. int dpll_reg = DPLL(pipe);
  7593. int dpll;
  7594. DRM_DEBUG_DRIVER("downclocking LVDS\n");
  7595. assert_panel_unlocked(dev_priv, pipe);
  7596. dpll = I915_READ(dpll_reg);
  7597. dpll |= DISPLAY_RATE_SELECT_FPA1;
  7598. I915_WRITE(dpll_reg, dpll);
  7599. intel_wait_for_vblank(dev, pipe);
  7600. dpll = I915_READ(dpll_reg);
  7601. if (!(dpll & DISPLAY_RATE_SELECT_FPA1))
  7602. DRM_DEBUG_DRIVER("failed to downclock LVDS!\n");
  7603. }
  7604. }
  7605. void intel_mark_busy(struct drm_device *dev)
  7606. {
  7607. struct drm_i915_private *dev_priv = dev->dev_private;
  7608. if (dev_priv->mm.busy)
  7609. return;
  7610. intel_runtime_pm_get(dev_priv);
  7611. i915_update_gfx_val(dev_priv);
  7612. dev_priv->mm.busy = true;
  7613. }
  7614. void intel_mark_idle(struct drm_device *dev)
  7615. {
  7616. struct drm_i915_private *dev_priv = dev->dev_private;
  7617. struct drm_crtc *crtc;
  7618. if (!dev_priv->mm.busy)
  7619. return;
  7620. dev_priv->mm.busy = false;
  7621. if (!i915.powersave)
  7622. goto out;
  7623. for_each_crtc(dev, crtc) {
  7624. if (!crtc->primary->fb)
  7625. continue;
  7626. intel_decrease_pllclock(crtc);
  7627. }
  7628. if (INTEL_INFO(dev)->gen >= 6)
  7629. gen6_rps_idle(dev->dev_private);
  7630. out:
  7631. intel_runtime_pm_put(dev_priv);
  7632. }
  7633. /**
  7634. * intel_mark_fb_busy - mark given planes as busy
  7635. * @dev: DRM device
  7636. * @frontbuffer_bits: bits for the affected planes
  7637. * @ring: optional ring for asynchronous commands
  7638. *
  7639. * This function gets called every time the screen contents change. It can be
  7640. * used to keep e.g. the update rate at the nominal refresh rate with DRRS.
  7641. */
  7642. static void intel_mark_fb_busy(struct drm_device *dev,
  7643. unsigned frontbuffer_bits,
  7644. struct intel_engine_cs *ring)
  7645. {
  7646. struct drm_i915_private *dev_priv = dev->dev_private;
  7647. enum pipe pipe;
  7648. if (!i915.powersave)
  7649. return;
  7650. for_each_pipe(dev_priv, pipe) {
  7651. if (!(frontbuffer_bits & INTEL_FRONTBUFFER_ALL_MASK(pipe)))
  7652. continue;
  7653. intel_increase_pllclock(dev, pipe);
  7654. if (ring && intel_fbc_enabled(dev))
  7655. ring->fbc_dirty = true;
  7656. }
  7657. }
  7658. /**
  7659. * intel_fb_obj_invalidate - invalidate frontbuffer object
  7660. * @obj: GEM object to invalidate
  7661. * @ring: set for asynchronous rendering
  7662. *
  7663. * This function gets called every time rendering on the given object starts and
  7664. * frontbuffer caching (fbc, low refresh rate for DRRS, panel self refresh) must
  7665. * be invalidated. If @ring is non-NULL any subsequent invalidation will be delayed
  7666. * until the rendering completes or a flip on this frontbuffer plane is
  7667. * scheduled.
  7668. */
  7669. void intel_fb_obj_invalidate(struct drm_i915_gem_object *obj,
  7670. struct intel_engine_cs *ring)
  7671. {
  7672. struct drm_device *dev = obj->base.dev;
  7673. struct drm_i915_private *dev_priv = dev->dev_private;
  7674. WARN_ON(!mutex_is_locked(&dev->struct_mutex));
  7675. if (!obj->frontbuffer_bits)
  7676. return;
  7677. if (ring) {
  7678. mutex_lock(&dev_priv->fb_tracking.lock);
  7679. dev_priv->fb_tracking.busy_bits
  7680. |= obj->frontbuffer_bits;
  7681. dev_priv->fb_tracking.flip_bits
  7682. &= ~obj->frontbuffer_bits;
  7683. mutex_unlock(&dev_priv->fb_tracking.lock);
  7684. }
  7685. intel_mark_fb_busy(dev, obj->frontbuffer_bits, ring);
  7686. intel_edp_psr_invalidate(dev, obj->frontbuffer_bits);
  7687. }
  7688. /**
  7689. * intel_frontbuffer_flush - flush frontbuffer
  7690. * @dev: DRM device
  7691. * @frontbuffer_bits: frontbuffer plane tracking bits
  7692. *
  7693. * This function gets called every time rendering on the given planes has
  7694. * completed and frontbuffer caching can be started again. Flushes will get
  7695. * delayed if they're blocked by some oustanding asynchronous rendering.
  7696. *
  7697. * Can be called without any locks held.
  7698. */
  7699. void intel_frontbuffer_flush(struct drm_device *dev,
  7700. unsigned frontbuffer_bits)
  7701. {
  7702. struct drm_i915_private *dev_priv = dev->dev_private;
  7703. /* Delay flushing when rings are still busy.*/
  7704. mutex_lock(&dev_priv->fb_tracking.lock);
  7705. frontbuffer_bits &= ~dev_priv->fb_tracking.busy_bits;
  7706. mutex_unlock(&dev_priv->fb_tracking.lock);
  7707. intel_mark_fb_busy(dev, frontbuffer_bits, NULL);
  7708. intel_edp_psr_flush(dev, frontbuffer_bits);
  7709. /*
  7710. * FIXME: Unconditional fbc flushing here is a rather gross hack and
  7711. * needs to be reworked into a proper frontbuffer tracking scheme like
  7712. * psr employs.
  7713. */
  7714. if (IS_BROADWELL(dev))
  7715. gen8_fbc_sw_flush(dev, FBC_REND_CACHE_CLEAN);
  7716. }
  7717. /**
  7718. * intel_fb_obj_flush - flush frontbuffer object
  7719. * @obj: GEM object to flush
  7720. * @retire: set when retiring asynchronous rendering
  7721. *
  7722. * This function gets called every time rendering on the given object has
  7723. * completed and frontbuffer caching can be started again. If @retire is true
  7724. * then any delayed flushes will be unblocked.
  7725. */
  7726. void intel_fb_obj_flush(struct drm_i915_gem_object *obj,
  7727. bool retire)
  7728. {
  7729. struct drm_device *dev = obj->base.dev;
  7730. struct drm_i915_private *dev_priv = dev->dev_private;
  7731. unsigned frontbuffer_bits;
  7732. WARN_ON(!mutex_is_locked(&dev->struct_mutex));
  7733. if (!obj->frontbuffer_bits)
  7734. return;
  7735. frontbuffer_bits = obj->frontbuffer_bits;
  7736. if (retire) {
  7737. mutex_lock(&dev_priv->fb_tracking.lock);
  7738. /* Filter out new bits since rendering started. */
  7739. frontbuffer_bits &= dev_priv->fb_tracking.busy_bits;
  7740. dev_priv->fb_tracking.busy_bits &= ~frontbuffer_bits;
  7741. mutex_unlock(&dev_priv->fb_tracking.lock);
  7742. }
  7743. intel_frontbuffer_flush(dev, frontbuffer_bits);
  7744. }
  7745. /**
  7746. * intel_frontbuffer_flip_prepare - prepare asnychronous frontbuffer flip
  7747. * @dev: DRM device
  7748. * @frontbuffer_bits: frontbuffer plane tracking bits
  7749. *
  7750. * This function gets called after scheduling a flip on @obj. The actual
  7751. * frontbuffer flushing will be delayed until completion is signalled with
  7752. * intel_frontbuffer_flip_complete. If an invalidate happens in between this
  7753. * flush will be cancelled.
  7754. *
  7755. * Can be called without any locks held.
  7756. */
  7757. void intel_frontbuffer_flip_prepare(struct drm_device *dev,
  7758. unsigned frontbuffer_bits)
  7759. {
  7760. struct drm_i915_private *dev_priv = dev->dev_private;
  7761. mutex_lock(&dev_priv->fb_tracking.lock);
  7762. dev_priv->fb_tracking.flip_bits
  7763. |= frontbuffer_bits;
  7764. mutex_unlock(&dev_priv->fb_tracking.lock);
  7765. }
  7766. /**
  7767. * intel_frontbuffer_flip_complete - complete asynchronous frontbuffer flush
  7768. * @dev: DRM device
  7769. * @frontbuffer_bits: frontbuffer plane tracking bits
  7770. *
  7771. * This function gets called after the flip has been latched and will complete
  7772. * on the next vblank. It will execute the fush if it hasn't been cancalled yet.
  7773. *
  7774. * Can be called without any locks held.
  7775. */
  7776. void intel_frontbuffer_flip_complete(struct drm_device *dev,
  7777. unsigned frontbuffer_bits)
  7778. {
  7779. struct drm_i915_private *dev_priv = dev->dev_private;
  7780. mutex_lock(&dev_priv->fb_tracking.lock);
  7781. /* Mask any cancelled flips. */
  7782. frontbuffer_bits &= dev_priv->fb_tracking.flip_bits;
  7783. dev_priv->fb_tracking.flip_bits &= ~frontbuffer_bits;
  7784. mutex_unlock(&dev_priv->fb_tracking.lock);
  7785. intel_frontbuffer_flush(dev, frontbuffer_bits);
  7786. }
  7787. static void intel_crtc_destroy(struct drm_crtc *crtc)
  7788. {
  7789. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7790. struct drm_device *dev = crtc->dev;
  7791. struct intel_unpin_work *work;
  7792. unsigned long flags;
  7793. spin_lock_irqsave(&dev->event_lock, flags);
  7794. work = intel_crtc->unpin_work;
  7795. intel_crtc->unpin_work = NULL;
  7796. spin_unlock_irqrestore(&dev->event_lock, flags);
  7797. if (work) {
  7798. cancel_work_sync(&work->work);
  7799. kfree(work);
  7800. }
  7801. drm_crtc_cleanup(crtc);
  7802. kfree(intel_crtc);
  7803. }
  7804. static void intel_unpin_work_fn(struct work_struct *__work)
  7805. {
  7806. struct intel_unpin_work *work =
  7807. container_of(__work, struct intel_unpin_work, work);
  7808. struct drm_device *dev = work->crtc->dev;
  7809. enum pipe pipe = to_intel_crtc(work->crtc)->pipe;
  7810. mutex_lock(&dev->struct_mutex);
  7811. intel_unpin_fb_obj(work->old_fb_obj);
  7812. drm_gem_object_unreference(&work->pending_flip_obj->base);
  7813. drm_gem_object_unreference(&work->old_fb_obj->base);
  7814. intel_update_fbc(dev);
  7815. mutex_unlock(&dev->struct_mutex);
  7816. intel_frontbuffer_flip_complete(dev, INTEL_FRONTBUFFER_PRIMARY(pipe));
  7817. BUG_ON(atomic_read(&to_intel_crtc(work->crtc)->unpin_work_count) == 0);
  7818. atomic_dec(&to_intel_crtc(work->crtc)->unpin_work_count);
  7819. kfree(work);
  7820. }
  7821. static void do_intel_finish_page_flip(struct drm_device *dev,
  7822. struct drm_crtc *crtc)
  7823. {
  7824. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7825. struct intel_unpin_work *work;
  7826. unsigned long flags;
  7827. /* Ignore early vblank irqs */
  7828. if (intel_crtc == NULL)
  7829. return;
  7830. spin_lock_irqsave(&dev->event_lock, flags);
  7831. work = intel_crtc->unpin_work;
  7832. /* Ensure we don't miss a work->pending update ... */
  7833. smp_rmb();
  7834. if (work == NULL || atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) {
  7835. spin_unlock_irqrestore(&dev->event_lock, flags);
  7836. return;
  7837. }
  7838. page_flip_completed(intel_crtc);
  7839. spin_unlock_irqrestore(&dev->event_lock, flags);
  7840. }
  7841. void intel_finish_page_flip(struct drm_device *dev, int pipe)
  7842. {
  7843. struct drm_i915_private *dev_priv = dev->dev_private;
  7844. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  7845. do_intel_finish_page_flip(dev, crtc);
  7846. }
  7847. void intel_finish_page_flip_plane(struct drm_device *dev, int plane)
  7848. {
  7849. struct drm_i915_private *dev_priv = dev->dev_private;
  7850. struct drm_crtc *crtc = dev_priv->plane_to_crtc_mapping[plane];
  7851. do_intel_finish_page_flip(dev, crtc);
  7852. }
  7853. /* Is 'a' after or equal to 'b'? */
  7854. static bool g4x_flip_count_after_eq(u32 a, u32 b)
  7855. {
  7856. return !((a - b) & 0x80000000);
  7857. }
  7858. static bool page_flip_finished(struct intel_crtc *crtc)
  7859. {
  7860. struct drm_device *dev = crtc->base.dev;
  7861. struct drm_i915_private *dev_priv = dev->dev_private;
  7862. if (i915_reset_in_progress(&dev_priv->gpu_error) ||
  7863. crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter))
  7864. return true;
  7865. /*
  7866. * The relevant registers doen't exist on pre-ctg.
  7867. * As the flip done interrupt doesn't trigger for mmio
  7868. * flips on gmch platforms, a flip count check isn't
  7869. * really needed there. But since ctg has the registers,
  7870. * include it in the check anyway.
  7871. */
  7872. if (INTEL_INFO(dev)->gen < 5 && !IS_G4X(dev))
  7873. return true;
  7874. /*
  7875. * A DSPSURFLIVE check isn't enough in case the mmio and CS flips
  7876. * used the same base address. In that case the mmio flip might
  7877. * have completed, but the CS hasn't even executed the flip yet.
  7878. *
  7879. * A flip count check isn't enough as the CS might have updated
  7880. * the base address just after start of vblank, but before we
  7881. * managed to process the interrupt. This means we'd complete the
  7882. * CS flip too soon.
  7883. *
  7884. * Combining both checks should get us a good enough result. It may
  7885. * still happen that the CS flip has been executed, but has not
  7886. * yet actually completed. But in case the base address is the same
  7887. * anyway, we don't really care.
  7888. */
  7889. return (I915_READ(DSPSURFLIVE(crtc->plane)) & ~0xfff) ==
  7890. crtc->unpin_work->gtt_offset &&
  7891. g4x_flip_count_after_eq(I915_READ(PIPE_FLIPCOUNT_GM45(crtc->pipe)),
  7892. crtc->unpin_work->flip_count);
  7893. }
  7894. void intel_prepare_page_flip(struct drm_device *dev, int plane)
  7895. {
  7896. struct drm_i915_private *dev_priv = dev->dev_private;
  7897. struct intel_crtc *intel_crtc =
  7898. to_intel_crtc(dev_priv->plane_to_crtc_mapping[plane]);
  7899. unsigned long flags;
  7900. /* NB: An MMIO update of the plane base pointer will also
  7901. * generate a page-flip completion irq, i.e. every modeset
  7902. * is also accompanied by a spurious intel_prepare_page_flip().
  7903. */
  7904. spin_lock_irqsave(&dev->event_lock, flags);
  7905. if (intel_crtc->unpin_work && page_flip_finished(intel_crtc))
  7906. atomic_inc_not_zero(&intel_crtc->unpin_work->pending);
  7907. spin_unlock_irqrestore(&dev->event_lock, flags);
  7908. }
  7909. static inline void intel_mark_page_flip_active(struct intel_crtc *intel_crtc)
  7910. {
  7911. /* Ensure that the work item is consistent when activating it ... */
  7912. smp_wmb();
  7913. atomic_set(&intel_crtc->unpin_work->pending, INTEL_FLIP_PENDING);
  7914. /* and that it is marked active as soon as the irq could fire. */
  7915. smp_wmb();
  7916. }
  7917. static int intel_gen2_queue_flip(struct drm_device *dev,
  7918. struct drm_crtc *crtc,
  7919. struct drm_framebuffer *fb,
  7920. struct drm_i915_gem_object *obj,
  7921. struct intel_engine_cs *ring,
  7922. uint32_t flags)
  7923. {
  7924. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7925. u32 flip_mask;
  7926. int ret;
  7927. ret = intel_ring_begin(ring, 6);
  7928. if (ret)
  7929. return ret;
  7930. /* Can't queue multiple flips, so wait for the previous
  7931. * one to finish before executing the next.
  7932. */
  7933. if (intel_crtc->plane)
  7934. flip_mask = MI_WAIT_FOR_PLANE_B_FLIP;
  7935. else
  7936. flip_mask = MI_WAIT_FOR_PLANE_A_FLIP;
  7937. intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask);
  7938. intel_ring_emit(ring, MI_NOOP);
  7939. intel_ring_emit(ring, MI_DISPLAY_FLIP |
  7940. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  7941. intel_ring_emit(ring, fb->pitches[0]);
  7942. intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset);
  7943. intel_ring_emit(ring, 0); /* aux display base address, unused */
  7944. intel_mark_page_flip_active(intel_crtc);
  7945. __intel_ring_advance(ring);
  7946. return 0;
  7947. }
  7948. static int intel_gen3_queue_flip(struct drm_device *dev,
  7949. struct drm_crtc *crtc,
  7950. struct drm_framebuffer *fb,
  7951. struct drm_i915_gem_object *obj,
  7952. struct intel_engine_cs *ring,
  7953. uint32_t flags)
  7954. {
  7955. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7956. u32 flip_mask;
  7957. int ret;
  7958. ret = intel_ring_begin(ring, 6);
  7959. if (ret)
  7960. return ret;
  7961. if (intel_crtc->plane)
  7962. flip_mask = MI_WAIT_FOR_PLANE_B_FLIP;
  7963. else
  7964. flip_mask = MI_WAIT_FOR_PLANE_A_FLIP;
  7965. intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask);
  7966. intel_ring_emit(ring, MI_NOOP);
  7967. intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 |
  7968. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  7969. intel_ring_emit(ring, fb->pitches[0]);
  7970. intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset);
  7971. intel_ring_emit(ring, MI_NOOP);
  7972. intel_mark_page_flip_active(intel_crtc);
  7973. __intel_ring_advance(ring);
  7974. return 0;
  7975. }
  7976. static int intel_gen4_queue_flip(struct drm_device *dev,
  7977. struct drm_crtc *crtc,
  7978. struct drm_framebuffer *fb,
  7979. struct drm_i915_gem_object *obj,
  7980. struct intel_engine_cs *ring,
  7981. uint32_t flags)
  7982. {
  7983. struct drm_i915_private *dev_priv = dev->dev_private;
  7984. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7985. uint32_t pf, pipesrc;
  7986. int ret;
  7987. ret = intel_ring_begin(ring, 4);
  7988. if (ret)
  7989. return ret;
  7990. /* i965+ uses the linear or tiled offsets from the
  7991. * Display Registers (which do not change across a page-flip)
  7992. * so we need only reprogram the base address.
  7993. */
  7994. intel_ring_emit(ring, MI_DISPLAY_FLIP |
  7995. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  7996. intel_ring_emit(ring, fb->pitches[0]);
  7997. intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset |
  7998. obj->tiling_mode);
  7999. /* XXX Enabling the panel-fitter across page-flip is so far
  8000. * untested on non-native modes, so ignore it for now.
  8001. * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE;
  8002. */
  8003. pf = 0;
  8004. pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
  8005. intel_ring_emit(ring, pf | pipesrc);
  8006. intel_mark_page_flip_active(intel_crtc);
  8007. __intel_ring_advance(ring);
  8008. return 0;
  8009. }
  8010. static int intel_gen6_queue_flip(struct drm_device *dev,
  8011. struct drm_crtc *crtc,
  8012. struct drm_framebuffer *fb,
  8013. struct drm_i915_gem_object *obj,
  8014. struct intel_engine_cs *ring,
  8015. uint32_t flags)
  8016. {
  8017. struct drm_i915_private *dev_priv = dev->dev_private;
  8018. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  8019. uint32_t pf, pipesrc;
  8020. int ret;
  8021. ret = intel_ring_begin(ring, 4);
  8022. if (ret)
  8023. return ret;
  8024. intel_ring_emit(ring, MI_DISPLAY_FLIP |
  8025. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  8026. intel_ring_emit(ring, fb->pitches[0] | obj->tiling_mode);
  8027. intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset);
  8028. /* Contrary to the suggestions in the documentation,
  8029. * "Enable Panel Fitter" does not seem to be required when page
  8030. * flipping with a non-native mode, and worse causes a normal
  8031. * modeset to fail.
  8032. * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE;
  8033. */
  8034. pf = 0;
  8035. pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
  8036. intel_ring_emit(ring, pf | pipesrc);
  8037. intel_mark_page_flip_active(intel_crtc);
  8038. __intel_ring_advance(ring);
  8039. return 0;
  8040. }
  8041. static int intel_gen7_queue_flip(struct drm_device *dev,
  8042. struct drm_crtc *crtc,
  8043. struct drm_framebuffer *fb,
  8044. struct drm_i915_gem_object *obj,
  8045. struct intel_engine_cs *ring,
  8046. uint32_t flags)
  8047. {
  8048. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  8049. uint32_t plane_bit = 0;
  8050. int len, ret;
  8051. switch (intel_crtc->plane) {
  8052. case PLANE_A:
  8053. plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_A;
  8054. break;
  8055. case PLANE_B:
  8056. plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_B;
  8057. break;
  8058. case PLANE_C:
  8059. plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_C;
  8060. break;
  8061. default:
  8062. WARN_ONCE(1, "unknown plane in flip command\n");
  8063. return -ENODEV;
  8064. }
  8065. len = 4;
  8066. if (ring->id == RCS) {
  8067. len += 6;
  8068. /*
  8069. * On Gen 8, SRM is now taking an extra dword to accommodate
  8070. * 48bits addresses, and we need a NOOP for the batch size to
  8071. * stay even.
  8072. */
  8073. if (IS_GEN8(dev))
  8074. len += 2;
  8075. }
  8076. /*
  8077. * BSpec MI_DISPLAY_FLIP for IVB:
  8078. * "The full packet must be contained within the same cache line."
  8079. *
  8080. * Currently the LRI+SRM+MI_DISPLAY_FLIP all fit within the same
  8081. * cacheline, if we ever start emitting more commands before
  8082. * the MI_DISPLAY_FLIP we may need to first emit everything else,
  8083. * then do the cacheline alignment, and finally emit the
  8084. * MI_DISPLAY_FLIP.
  8085. */
  8086. ret = intel_ring_cacheline_align(ring);
  8087. if (ret)
  8088. return ret;
  8089. ret = intel_ring_begin(ring, len);
  8090. if (ret)
  8091. return ret;
  8092. /* Unmask the flip-done completion message. Note that the bspec says that
  8093. * we should do this for both the BCS and RCS, and that we must not unmask
  8094. * more than one flip event at any time (or ensure that one flip message
  8095. * can be sent by waiting for flip-done prior to queueing new flips).
  8096. * Experimentation says that BCS works despite DERRMR masking all
  8097. * flip-done completion events and that unmasking all planes at once
  8098. * for the RCS also doesn't appear to drop events. Setting the DERRMR
  8099. * to zero does lead to lockups within MI_DISPLAY_FLIP.
  8100. */
  8101. if (ring->id == RCS) {
  8102. intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1));
  8103. intel_ring_emit(ring, DERRMR);
  8104. intel_ring_emit(ring, ~(DERRMR_PIPEA_PRI_FLIP_DONE |
  8105. DERRMR_PIPEB_PRI_FLIP_DONE |
  8106. DERRMR_PIPEC_PRI_FLIP_DONE));
  8107. if (IS_GEN8(dev))
  8108. intel_ring_emit(ring, MI_STORE_REGISTER_MEM_GEN8(1) |
  8109. MI_SRM_LRM_GLOBAL_GTT);
  8110. else
  8111. intel_ring_emit(ring, MI_STORE_REGISTER_MEM(1) |
  8112. MI_SRM_LRM_GLOBAL_GTT);
  8113. intel_ring_emit(ring, DERRMR);
  8114. intel_ring_emit(ring, ring->scratch.gtt_offset + 256);
  8115. if (IS_GEN8(dev)) {
  8116. intel_ring_emit(ring, 0);
  8117. intel_ring_emit(ring, MI_NOOP);
  8118. }
  8119. }
  8120. intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | plane_bit);
  8121. intel_ring_emit(ring, (fb->pitches[0] | obj->tiling_mode));
  8122. intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset);
  8123. intel_ring_emit(ring, (MI_NOOP));
  8124. intel_mark_page_flip_active(intel_crtc);
  8125. __intel_ring_advance(ring);
  8126. return 0;
  8127. }
  8128. static bool use_mmio_flip(struct intel_engine_cs *ring,
  8129. struct drm_i915_gem_object *obj)
  8130. {
  8131. /*
  8132. * This is not being used for older platforms, because
  8133. * non-availability of flip done interrupt forces us to use
  8134. * CS flips. Older platforms derive flip done using some clever
  8135. * tricks involving the flip_pending status bits and vblank irqs.
  8136. * So using MMIO flips there would disrupt this mechanism.
  8137. */
  8138. if (ring == NULL)
  8139. return true;
  8140. if (INTEL_INFO(ring->dev)->gen < 5)
  8141. return false;
  8142. if (i915.use_mmio_flip < 0)
  8143. return false;
  8144. else if (i915.use_mmio_flip > 0)
  8145. return true;
  8146. else if (i915.enable_execlists)
  8147. return true;
  8148. else
  8149. return ring != obj->ring;
  8150. }
  8151. static void intel_do_mmio_flip(struct intel_crtc *intel_crtc)
  8152. {
  8153. struct drm_device *dev = intel_crtc->base.dev;
  8154. struct drm_i915_private *dev_priv = dev->dev_private;
  8155. struct intel_framebuffer *intel_fb =
  8156. to_intel_framebuffer(intel_crtc->base.primary->fb);
  8157. struct drm_i915_gem_object *obj = intel_fb->obj;
  8158. u32 dspcntr;
  8159. u32 reg;
  8160. intel_mark_page_flip_active(intel_crtc);
  8161. reg = DSPCNTR(intel_crtc->plane);
  8162. dspcntr = I915_READ(reg);
  8163. if (INTEL_INFO(dev)->gen >= 4) {
  8164. if (obj->tiling_mode != I915_TILING_NONE)
  8165. dspcntr |= DISPPLANE_TILED;
  8166. else
  8167. dspcntr &= ~DISPPLANE_TILED;
  8168. }
  8169. I915_WRITE(reg, dspcntr);
  8170. I915_WRITE(DSPSURF(intel_crtc->plane),
  8171. intel_crtc->unpin_work->gtt_offset);
  8172. POSTING_READ(DSPSURF(intel_crtc->plane));
  8173. }
  8174. static int intel_postpone_flip(struct drm_i915_gem_object *obj)
  8175. {
  8176. struct intel_engine_cs *ring;
  8177. int ret;
  8178. lockdep_assert_held(&obj->base.dev->struct_mutex);
  8179. if (!obj->last_write_seqno)
  8180. return 0;
  8181. ring = obj->ring;
  8182. if (i915_seqno_passed(ring->get_seqno(ring, true),
  8183. obj->last_write_seqno))
  8184. return 0;
  8185. ret = i915_gem_check_olr(ring, obj->last_write_seqno);
  8186. if (ret)
  8187. return ret;
  8188. if (WARN_ON(!ring->irq_get(ring)))
  8189. return 0;
  8190. return 1;
  8191. }
  8192. void intel_notify_mmio_flip(struct intel_engine_cs *ring)
  8193. {
  8194. struct drm_i915_private *dev_priv = to_i915(ring->dev);
  8195. struct intel_crtc *intel_crtc;
  8196. unsigned long irq_flags;
  8197. u32 seqno;
  8198. seqno = ring->get_seqno(ring, false);
  8199. spin_lock_irqsave(&dev_priv->mmio_flip_lock, irq_flags);
  8200. for_each_intel_crtc(ring->dev, intel_crtc) {
  8201. struct intel_mmio_flip *mmio_flip;
  8202. mmio_flip = &intel_crtc->mmio_flip;
  8203. if (mmio_flip->seqno == 0)
  8204. continue;
  8205. if (ring->id != mmio_flip->ring_id)
  8206. continue;
  8207. if (i915_seqno_passed(seqno, mmio_flip->seqno)) {
  8208. intel_do_mmio_flip(intel_crtc);
  8209. mmio_flip->seqno = 0;
  8210. ring->irq_put(ring);
  8211. }
  8212. }
  8213. spin_unlock_irqrestore(&dev_priv->mmio_flip_lock, irq_flags);
  8214. }
  8215. static int intel_queue_mmio_flip(struct drm_device *dev,
  8216. struct drm_crtc *crtc,
  8217. struct drm_framebuffer *fb,
  8218. struct drm_i915_gem_object *obj,
  8219. struct intel_engine_cs *ring,
  8220. uint32_t flags)
  8221. {
  8222. struct drm_i915_private *dev_priv = dev->dev_private;
  8223. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  8224. unsigned long irq_flags;
  8225. int ret;
  8226. if (WARN_ON(intel_crtc->mmio_flip.seqno))
  8227. return -EBUSY;
  8228. ret = intel_postpone_flip(obj);
  8229. if (ret < 0)
  8230. return ret;
  8231. if (ret == 0) {
  8232. intel_do_mmio_flip(intel_crtc);
  8233. return 0;
  8234. }
  8235. spin_lock_irqsave(&dev_priv->mmio_flip_lock, irq_flags);
  8236. intel_crtc->mmio_flip.seqno = obj->last_write_seqno;
  8237. intel_crtc->mmio_flip.ring_id = obj->ring->id;
  8238. spin_unlock_irqrestore(&dev_priv->mmio_flip_lock, irq_flags);
  8239. /*
  8240. * Double check to catch cases where irq fired before
  8241. * mmio flip data was ready
  8242. */
  8243. intel_notify_mmio_flip(obj->ring);
  8244. return 0;
  8245. }
  8246. static int intel_default_queue_flip(struct drm_device *dev,
  8247. struct drm_crtc *crtc,
  8248. struct drm_framebuffer *fb,
  8249. struct drm_i915_gem_object *obj,
  8250. struct intel_engine_cs *ring,
  8251. uint32_t flags)
  8252. {
  8253. return -ENODEV;
  8254. }
  8255. static bool __intel_pageflip_stall_check(struct drm_device *dev,
  8256. struct drm_crtc *crtc)
  8257. {
  8258. struct drm_i915_private *dev_priv = dev->dev_private;
  8259. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  8260. struct intel_unpin_work *work = intel_crtc->unpin_work;
  8261. u32 addr;
  8262. if (atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE)
  8263. return true;
  8264. if (!work->enable_stall_check)
  8265. return false;
  8266. if (work->flip_ready_vblank == 0) {
  8267. if (work->flip_queued_ring &&
  8268. !i915_seqno_passed(work->flip_queued_ring->get_seqno(work->flip_queued_ring, true),
  8269. work->flip_queued_seqno))
  8270. return false;
  8271. work->flip_ready_vblank = drm_vblank_count(dev, intel_crtc->pipe);
  8272. }
  8273. if (drm_vblank_count(dev, intel_crtc->pipe) - work->flip_ready_vblank < 3)
  8274. return false;
  8275. /* Potential stall - if we see that the flip has happened,
  8276. * assume a missed interrupt. */
  8277. if (INTEL_INFO(dev)->gen >= 4)
  8278. addr = I915_HI_DISPBASE(I915_READ(DSPSURF(intel_crtc->plane)));
  8279. else
  8280. addr = I915_READ(DSPADDR(intel_crtc->plane));
  8281. /* There is a potential issue here with a false positive after a flip
  8282. * to the same address. We could address this by checking for a
  8283. * non-incrementing frame counter.
  8284. */
  8285. return addr == work->gtt_offset;
  8286. }
  8287. void intel_check_page_flip(struct drm_device *dev, int pipe)
  8288. {
  8289. struct drm_i915_private *dev_priv = dev->dev_private;
  8290. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  8291. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  8292. unsigned long flags;
  8293. if (crtc == NULL)
  8294. return;
  8295. spin_lock_irqsave(&dev->event_lock, flags);
  8296. if (intel_crtc->unpin_work && __intel_pageflip_stall_check(dev, crtc)) {
  8297. WARN_ONCE(1, "Kicking stuck page flip: queued at %d, now %d\n",
  8298. intel_crtc->unpin_work->flip_queued_vblank, drm_vblank_count(dev, pipe));
  8299. page_flip_completed(intel_crtc);
  8300. }
  8301. spin_unlock_irqrestore(&dev->event_lock, flags);
  8302. }
  8303. static int intel_crtc_page_flip(struct drm_crtc *crtc,
  8304. struct drm_framebuffer *fb,
  8305. struct drm_pending_vblank_event *event,
  8306. uint32_t page_flip_flags)
  8307. {
  8308. struct drm_device *dev = crtc->dev;
  8309. struct drm_i915_private *dev_priv = dev->dev_private;
  8310. struct drm_framebuffer *old_fb = crtc->primary->fb;
  8311. struct drm_i915_gem_object *obj = intel_fb_obj(fb);
  8312. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  8313. enum pipe pipe = intel_crtc->pipe;
  8314. struct intel_unpin_work *work;
  8315. struct intel_engine_cs *ring;
  8316. unsigned long flags;
  8317. int ret;
  8318. /*
  8319. * drm_mode_page_flip_ioctl() should already catch this, but double
  8320. * check to be safe. In the future we may enable pageflipping from
  8321. * a disabled primary plane.
  8322. */
  8323. if (WARN_ON(intel_fb_obj(old_fb) == NULL))
  8324. return -EBUSY;
  8325. /* Can't change pixel format via MI display flips. */
  8326. if (fb->pixel_format != crtc->primary->fb->pixel_format)
  8327. return -EINVAL;
  8328. /*
  8329. * TILEOFF/LINOFF registers can't be changed via MI display flips.
  8330. * Note that pitch changes could also affect these register.
  8331. */
  8332. if (INTEL_INFO(dev)->gen > 3 &&
  8333. (fb->offsets[0] != crtc->primary->fb->offsets[0] ||
  8334. fb->pitches[0] != crtc->primary->fb->pitches[0]))
  8335. return -EINVAL;
  8336. if (i915_terminally_wedged(&dev_priv->gpu_error))
  8337. goto out_hang;
  8338. work = kzalloc(sizeof(*work), GFP_KERNEL);
  8339. if (work == NULL)
  8340. return -ENOMEM;
  8341. work->event = event;
  8342. work->crtc = crtc;
  8343. work->old_fb_obj = intel_fb_obj(old_fb);
  8344. INIT_WORK(&work->work, intel_unpin_work_fn);
  8345. ret = drm_crtc_vblank_get(crtc);
  8346. if (ret)
  8347. goto free_work;
  8348. /* We borrow the event spin lock for protecting unpin_work */
  8349. spin_lock_irqsave(&dev->event_lock, flags);
  8350. if (intel_crtc->unpin_work) {
  8351. /* Before declaring the flip queue wedged, check if
  8352. * the hardware completed the operation behind our backs.
  8353. */
  8354. if (__intel_pageflip_stall_check(dev, crtc)) {
  8355. DRM_DEBUG_DRIVER("flip queue: previous flip completed, continuing\n");
  8356. page_flip_completed(intel_crtc);
  8357. } else {
  8358. DRM_DEBUG_DRIVER("flip queue: crtc already busy\n");
  8359. spin_unlock_irqrestore(&dev->event_lock, flags);
  8360. drm_crtc_vblank_put(crtc);
  8361. kfree(work);
  8362. return -EBUSY;
  8363. }
  8364. }
  8365. intel_crtc->unpin_work = work;
  8366. spin_unlock_irqrestore(&dev->event_lock, flags);
  8367. if (atomic_read(&intel_crtc->unpin_work_count) >= 2)
  8368. flush_workqueue(dev_priv->wq);
  8369. ret = i915_mutex_lock_interruptible(dev);
  8370. if (ret)
  8371. goto cleanup;
  8372. /* Reference the objects for the scheduled work. */
  8373. drm_gem_object_reference(&work->old_fb_obj->base);
  8374. drm_gem_object_reference(&obj->base);
  8375. crtc->primary->fb = fb;
  8376. work->pending_flip_obj = obj;
  8377. atomic_inc(&intel_crtc->unpin_work_count);
  8378. intel_crtc->reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter);
  8379. if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev))
  8380. work->flip_count = I915_READ(PIPE_FLIPCOUNT_GM45(pipe)) + 1;
  8381. if (IS_VALLEYVIEW(dev)) {
  8382. ring = &dev_priv->ring[BCS];
  8383. if (obj->tiling_mode != work->old_fb_obj->tiling_mode)
  8384. /* vlv: DISPLAY_FLIP fails to change tiling */
  8385. ring = NULL;
  8386. } else if (IS_IVYBRIDGE(dev)) {
  8387. ring = &dev_priv->ring[BCS];
  8388. } else if (INTEL_INFO(dev)->gen >= 7) {
  8389. ring = obj->ring;
  8390. if (ring == NULL || ring->id != RCS)
  8391. ring = &dev_priv->ring[BCS];
  8392. } else {
  8393. ring = &dev_priv->ring[RCS];
  8394. }
  8395. ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
  8396. if (ret)
  8397. goto cleanup_pending;
  8398. work->gtt_offset =
  8399. i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset;
  8400. if (use_mmio_flip(ring, obj)) {
  8401. ret = intel_queue_mmio_flip(dev, crtc, fb, obj, ring,
  8402. page_flip_flags);
  8403. if (ret)
  8404. goto cleanup_unpin;
  8405. work->flip_queued_seqno = obj->last_write_seqno;
  8406. work->flip_queued_ring = obj->ring;
  8407. } else {
  8408. ret = dev_priv->display.queue_flip(dev, crtc, fb, obj, ring,
  8409. page_flip_flags);
  8410. if (ret)
  8411. goto cleanup_unpin;
  8412. work->flip_queued_seqno = intel_ring_get_seqno(ring);
  8413. work->flip_queued_ring = ring;
  8414. }
  8415. work->flip_queued_vblank = drm_vblank_count(dev, intel_crtc->pipe);
  8416. work->enable_stall_check = true;
  8417. i915_gem_track_fb(work->old_fb_obj, obj,
  8418. INTEL_FRONTBUFFER_PRIMARY(pipe));
  8419. intel_disable_fbc(dev);
  8420. intel_frontbuffer_flip_prepare(dev, INTEL_FRONTBUFFER_PRIMARY(pipe));
  8421. mutex_unlock(&dev->struct_mutex);
  8422. trace_i915_flip_request(intel_crtc->plane, obj);
  8423. return 0;
  8424. cleanup_unpin:
  8425. intel_unpin_fb_obj(obj);
  8426. cleanup_pending:
  8427. atomic_dec(&intel_crtc->unpin_work_count);
  8428. crtc->primary->fb = old_fb;
  8429. drm_gem_object_unreference(&work->old_fb_obj->base);
  8430. drm_gem_object_unreference(&obj->base);
  8431. mutex_unlock(&dev->struct_mutex);
  8432. cleanup:
  8433. spin_lock_irqsave(&dev->event_lock, flags);
  8434. intel_crtc->unpin_work = NULL;
  8435. spin_unlock_irqrestore(&dev->event_lock, flags);
  8436. drm_crtc_vblank_put(crtc);
  8437. free_work:
  8438. kfree(work);
  8439. if (ret == -EIO) {
  8440. out_hang:
  8441. intel_crtc_wait_for_pending_flips(crtc);
  8442. ret = intel_pipe_set_base(crtc, crtc->x, crtc->y, fb);
  8443. if (ret == 0 && event) {
  8444. spin_lock_irqsave(&dev->event_lock, flags);
  8445. drm_send_vblank_event(dev, pipe, event);
  8446. spin_unlock_irqrestore(&dev->event_lock, flags);
  8447. }
  8448. }
  8449. return ret;
  8450. }
  8451. static struct drm_crtc_helper_funcs intel_helper_funcs = {
  8452. .mode_set_base_atomic = intel_pipe_set_base_atomic,
  8453. .load_lut = intel_crtc_load_lut,
  8454. };
  8455. /**
  8456. * intel_modeset_update_staged_output_state
  8457. *
  8458. * Updates the staged output configuration state, e.g. after we've read out the
  8459. * current hw state.
  8460. */
  8461. static void intel_modeset_update_staged_output_state(struct drm_device *dev)
  8462. {
  8463. struct intel_crtc *crtc;
  8464. struct intel_encoder *encoder;
  8465. struct intel_connector *connector;
  8466. list_for_each_entry(connector, &dev->mode_config.connector_list,
  8467. base.head) {
  8468. connector->new_encoder =
  8469. to_intel_encoder(connector->base.encoder);
  8470. }
  8471. for_each_intel_encoder(dev, encoder) {
  8472. encoder->new_crtc =
  8473. to_intel_crtc(encoder->base.crtc);
  8474. }
  8475. for_each_intel_crtc(dev, crtc) {
  8476. crtc->new_enabled = crtc->base.enabled;
  8477. if (crtc->new_enabled)
  8478. crtc->new_config = &crtc->config;
  8479. else
  8480. crtc->new_config = NULL;
  8481. }
  8482. }
  8483. /**
  8484. * intel_modeset_commit_output_state
  8485. *
  8486. * This function copies the stage display pipe configuration to the real one.
  8487. */
  8488. static void intel_modeset_commit_output_state(struct drm_device *dev)
  8489. {
  8490. struct intel_crtc *crtc;
  8491. struct intel_encoder *encoder;
  8492. struct intel_connector *connector;
  8493. list_for_each_entry(connector, &dev->mode_config.connector_list,
  8494. base.head) {
  8495. connector->base.encoder = &connector->new_encoder->base;
  8496. }
  8497. for_each_intel_encoder(dev, encoder) {
  8498. encoder->base.crtc = &encoder->new_crtc->base;
  8499. }
  8500. for_each_intel_crtc(dev, crtc) {
  8501. crtc->base.enabled = crtc->new_enabled;
  8502. }
  8503. }
  8504. static void
  8505. connected_sink_compute_bpp(struct intel_connector *connector,
  8506. struct intel_crtc_config *pipe_config)
  8507. {
  8508. int bpp = pipe_config->pipe_bpp;
  8509. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n",
  8510. connector->base.base.id,
  8511. connector->base.name);
  8512. /* Don't use an invalid EDID bpc value */
  8513. if (connector->base.display_info.bpc &&
  8514. connector->base.display_info.bpc * 3 < bpp) {
  8515. DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n",
  8516. bpp, connector->base.display_info.bpc*3);
  8517. pipe_config->pipe_bpp = connector->base.display_info.bpc*3;
  8518. }
  8519. /* Clamp bpp to 8 on screens without EDID 1.4 */
  8520. if (connector->base.display_info.bpc == 0 && bpp > 24) {
  8521. DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n",
  8522. bpp);
  8523. pipe_config->pipe_bpp = 24;
  8524. }
  8525. }
  8526. static int
  8527. compute_baseline_pipe_bpp(struct intel_crtc *crtc,
  8528. struct drm_framebuffer *fb,
  8529. struct intel_crtc_config *pipe_config)
  8530. {
  8531. struct drm_device *dev = crtc->base.dev;
  8532. struct intel_connector *connector;
  8533. int bpp;
  8534. switch (fb->pixel_format) {
  8535. case DRM_FORMAT_C8:
  8536. bpp = 8*3; /* since we go through a colormap */
  8537. break;
  8538. case DRM_FORMAT_XRGB1555:
  8539. case DRM_FORMAT_ARGB1555:
  8540. /* checked in intel_framebuffer_init already */
  8541. if (WARN_ON(INTEL_INFO(dev)->gen > 3))
  8542. return -EINVAL;
  8543. case DRM_FORMAT_RGB565:
  8544. bpp = 6*3; /* min is 18bpp */
  8545. break;
  8546. case DRM_FORMAT_XBGR8888:
  8547. case DRM_FORMAT_ABGR8888:
  8548. /* checked in intel_framebuffer_init already */
  8549. if (WARN_ON(INTEL_INFO(dev)->gen < 4))
  8550. return -EINVAL;
  8551. case DRM_FORMAT_XRGB8888:
  8552. case DRM_FORMAT_ARGB8888:
  8553. bpp = 8*3;
  8554. break;
  8555. case DRM_FORMAT_XRGB2101010:
  8556. case DRM_FORMAT_ARGB2101010:
  8557. case DRM_FORMAT_XBGR2101010:
  8558. case DRM_FORMAT_ABGR2101010:
  8559. /* checked in intel_framebuffer_init already */
  8560. if (WARN_ON(INTEL_INFO(dev)->gen < 4))
  8561. return -EINVAL;
  8562. bpp = 10*3;
  8563. break;
  8564. /* TODO: gen4+ supports 16 bpc floating point, too. */
  8565. default:
  8566. DRM_DEBUG_KMS("unsupported depth\n");
  8567. return -EINVAL;
  8568. }
  8569. pipe_config->pipe_bpp = bpp;
  8570. /* Clamp display bpp to EDID value */
  8571. list_for_each_entry(connector, &dev->mode_config.connector_list,
  8572. base.head) {
  8573. if (!connector->new_encoder ||
  8574. connector->new_encoder->new_crtc != crtc)
  8575. continue;
  8576. connected_sink_compute_bpp(connector, pipe_config);
  8577. }
  8578. return bpp;
  8579. }
  8580. static void intel_dump_crtc_timings(const struct drm_display_mode *mode)
  8581. {
  8582. DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
  8583. "type: 0x%x flags: 0x%x\n",
  8584. mode->crtc_clock,
  8585. mode->crtc_hdisplay, mode->crtc_hsync_start,
  8586. mode->crtc_hsync_end, mode->crtc_htotal,
  8587. mode->crtc_vdisplay, mode->crtc_vsync_start,
  8588. mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags);
  8589. }
  8590. static void intel_dump_pipe_config(struct intel_crtc *crtc,
  8591. struct intel_crtc_config *pipe_config,
  8592. const char *context)
  8593. {
  8594. DRM_DEBUG_KMS("[CRTC:%d]%s config for pipe %c\n", crtc->base.base.id,
  8595. context, pipe_name(crtc->pipe));
  8596. DRM_DEBUG_KMS("cpu_transcoder: %c\n", transcoder_name(pipe_config->cpu_transcoder));
  8597. DRM_DEBUG_KMS("pipe bpp: %i, dithering: %i\n",
  8598. pipe_config->pipe_bpp, pipe_config->dither);
  8599. DRM_DEBUG_KMS("fdi/pch: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
  8600. pipe_config->has_pch_encoder,
  8601. pipe_config->fdi_lanes,
  8602. pipe_config->fdi_m_n.gmch_m, pipe_config->fdi_m_n.gmch_n,
  8603. pipe_config->fdi_m_n.link_m, pipe_config->fdi_m_n.link_n,
  8604. pipe_config->fdi_m_n.tu);
  8605. DRM_DEBUG_KMS("dp: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
  8606. pipe_config->has_dp_encoder,
  8607. pipe_config->dp_m_n.gmch_m, pipe_config->dp_m_n.gmch_n,
  8608. pipe_config->dp_m_n.link_m, pipe_config->dp_m_n.link_n,
  8609. pipe_config->dp_m_n.tu);
  8610. DRM_DEBUG_KMS("dp: %i, gmch_m2: %u, gmch_n2: %u, link_m2: %u, link_n2: %u, tu2: %u\n",
  8611. pipe_config->has_dp_encoder,
  8612. pipe_config->dp_m2_n2.gmch_m,
  8613. pipe_config->dp_m2_n2.gmch_n,
  8614. pipe_config->dp_m2_n2.link_m,
  8615. pipe_config->dp_m2_n2.link_n,
  8616. pipe_config->dp_m2_n2.tu);
  8617. DRM_DEBUG_KMS("requested mode:\n");
  8618. drm_mode_debug_printmodeline(&pipe_config->requested_mode);
  8619. DRM_DEBUG_KMS("adjusted mode:\n");
  8620. drm_mode_debug_printmodeline(&pipe_config->adjusted_mode);
  8621. intel_dump_crtc_timings(&pipe_config->adjusted_mode);
  8622. DRM_DEBUG_KMS("port clock: %d\n", pipe_config->port_clock);
  8623. DRM_DEBUG_KMS("pipe src size: %dx%d\n",
  8624. pipe_config->pipe_src_w, pipe_config->pipe_src_h);
  8625. DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
  8626. pipe_config->gmch_pfit.control,
  8627. pipe_config->gmch_pfit.pgm_ratios,
  8628. pipe_config->gmch_pfit.lvds_border_bits);
  8629. DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n",
  8630. pipe_config->pch_pfit.pos,
  8631. pipe_config->pch_pfit.size,
  8632. pipe_config->pch_pfit.enabled ? "enabled" : "disabled");
  8633. DRM_DEBUG_KMS("ips: %i\n", pipe_config->ips_enabled);
  8634. DRM_DEBUG_KMS("double wide: %i\n", pipe_config->double_wide);
  8635. }
  8636. static bool encoders_cloneable(const struct intel_encoder *a,
  8637. const struct intel_encoder *b)
  8638. {
  8639. /* masks could be asymmetric, so check both ways */
  8640. return a == b || (a->cloneable & (1 << b->type) &&
  8641. b->cloneable & (1 << a->type));
  8642. }
  8643. static bool check_single_encoder_cloning(struct intel_crtc *crtc,
  8644. struct intel_encoder *encoder)
  8645. {
  8646. struct drm_device *dev = crtc->base.dev;
  8647. struct intel_encoder *source_encoder;
  8648. for_each_intel_encoder(dev, source_encoder) {
  8649. if (source_encoder->new_crtc != crtc)
  8650. continue;
  8651. if (!encoders_cloneable(encoder, source_encoder))
  8652. return false;
  8653. }
  8654. return true;
  8655. }
  8656. static bool check_encoder_cloning(struct intel_crtc *crtc)
  8657. {
  8658. struct drm_device *dev = crtc->base.dev;
  8659. struct intel_encoder *encoder;
  8660. for_each_intel_encoder(dev, encoder) {
  8661. if (encoder->new_crtc != crtc)
  8662. continue;
  8663. if (!check_single_encoder_cloning(crtc, encoder))
  8664. return false;
  8665. }
  8666. return true;
  8667. }
  8668. static struct intel_crtc_config *
  8669. intel_modeset_pipe_config(struct drm_crtc *crtc,
  8670. struct drm_framebuffer *fb,
  8671. struct drm_display_mode *mode)
  8672. {
  8673. struct drm_device *dev = crtc->dev;
  8674. struct intel_encoder *encoder;
  8675. struct intel_crtc_config *pipe_config;
  8676. int plane_bpp, ret = -EINVAL;
  8677. bool retry = true;
  8678. if (!check_encoder_cloning(to_intel_crtc(crtc))) {
  8679. DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
  8680. return ERR_PTR(-EINVAL);
  8681. }
  8682. pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL);
  8683. if (!pipe_config)
  8684. return ERR_PTR(-ENOMEM);
  8685. drm_mode_copy(&pipe_config->adjusted_mode, mode);
  8686. drm_mode_copy(&pipe_config->requested_mode, mode);
  8687. pipe_config->cpu_transcoder =
  8688. (enum transcoder) to_intel_crtc(crtc)->pipe;
  8689. pipe_config->shared_dpll = DPLL_ID_PRIVATE;
  8690. /*
  8691. * Sanitize sync polarity flags based on requested ones. If neither
  8692. * positive or negative polarity is requested, treat this as meaning
  8693. * negative polarity.
  8694. */
  8695. if (!(pipe_config->adjusted_mode.flags &
  8696. (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC)))
  8697. pipe_config->adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC;
  8698. if (!(pipe_config->adjusted_mode.flags &
  8699. (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC)))
  8700. pipe_config->adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC;
  8701. /* Compute a starting value for pipe_config->pipe_bpp taking the source
  8702. * plane pixel format and any sink constraints into account. Returns the
  8703. * source plane bpp so that dithering can be selected on mismatches
  8704. * after encoders and crtc also have had their say. */
  8705. plane_bpp = compute_baseline_pipe_bpp(to_intel_crtc(crtc),
  8706. fb, pipe_config);
  8707. if (plane_bpp < 0)
  8708. goto fail;
  8709. /*
  8710. * Determine the real pipe dimensions. Note that stereo modes can
  8711. * increase the actual pipe size due to the frame doubling and
  8712. * insertion of additional space for blanks between the frame. This
  8713. * is stored in the crtc timings. We use the requested mode to do this
  8714. * computation to clearly distinguish it from the adjusted mode, which
  8715. * can be changed by the connectors in the below retry loop.
  8716. */
  8717. drm_mode_set_crtcinfo(&pipe_config->requested_mode, CRTC_STEREO_DOUBLE);
  8718. pipe_config->pipe_src_w = pipe_config->requested_mode.crtc_hdisplay;
  8719. pipe_config->pipe_src_h = pipe_config->requested_mode.crtc_vdisplay;
  8720. encoder_retry:
  8721. /* Ensure the port clock defaults are reset when retrying. */
  8722. pipe_config->port_clock = 0;
  8723. pipe_config->pixel_multiplier = 1;
  8724. /* Fill in default crtc timings, allow encoders to overwrite them. */
  8725. drm_mode_set_crtcinfo(&pipe_config->adjusted_mode, CRTC_STEREO_DOUBLE);
  8726. /* Pass our mode to the connectors and the CRTC to give them a chance to
  8727. * adjust it according to limitations or connector properties, and also
  8728. * a chance to reject the mode entirely.
  8729. */
  8730. for_each_intel_encoder(dev, encoder) {
  8731. if (&encoder->new_crtc->base != crtc)
  8732. continue;
  8733. if (!(encoder->compute_config(encoder, pipe_config))) {
  8734. DRM_DEBUG_KMS("Encoder config failure\n");
  8735. goto fail;
  8736. }
  8737. }
  8738. /* Set default port clock if not overwritten by the encoder. Needs to be
  8739. * done afterwards in case the encoder adjusts the mode. */
  8740. if (!pipe_config->port_clock)
  8741. pipe_config->port_clock = pipe_config->adjusted_mode.crtc_clock
  8742. * pipe_config->pixel_multiplier;
  8743. ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config);
  8744. if (ret < 0) {
  8745. DRM_DEBUG_KMS("CRTC fixup failed\n");
  8746. goto fail;
  8747. }
  8748. if (ret == RETRY) {
  8749. if (WARN(!retry, "loop in pipe configuration computation\n")) {
  8750. ret = -EINVAL;
  8751. goto fail;
  8752. }
  8753. DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
  8754. retry = false;
  8755. goto encoder_retry;
  8756. }
  8757. pipe_config->dither = pipe_config->pipe_bpp != plane_bpp;
  8758. DRM_DEBUG_KMS("plane bpp: %i, pipe bpp: %i, dithering: %i\n",
  8759. plane_bpp, pipe_config->pipe_bpp, pipe_config->dither);
  8760. return pipe_config;
  8761. fail:
  8762. kfree(pipe_config);
  8763. return ERR_PTR(ret);
  8764. }
  8765. /* Computes which crtcs are affected and sets the relevant bits in the mask. For
  8766. * simplicity we use the crtc's pipe number (because it's easier to obtain). */
  8767. static void
  8768. intel_modeset_affected_pipes(struct drm_crtc *crtc, unsigned *modeset_pipes,
  8769. unsigned *prepare_pipes, unsigned *disable_pipes)
  8770. {
  8771. struct intel_crtc *intel_crtc;
  8772. struct drm_device *dev = crtc->dev;
  8773. struct intel_encoder *encoder;
  8774. struct intel_connector *connector;
  8775. struct drm_crtc *tmp_crtc;
  8776. *disable_pipes = *modeset_pipes = *prepare_pipes = 0;
  8777. /* Check which crtcs have changed outputs connected to them, these need
  8778. * to be part of the prepare_pipes mask. We don't (yet) support global
  8779. * modeset across multiple crtcs, so modeset_pipes will only have one
  8780. * bit set at most. */
  8781. list_for_each_entry(connector, &dev->mode_config.connector_list,
  8782. base.head) {
  8783. if (connector->base.encoder == &connector->new_encoder->base)
  8784. continue;
  8785. if (connector->base.encoder) {
  8786. tmp_crtc = connector->base.encoder->crtc;
  8787. *prepare_pipes |= 1 << to_intel_crtc(tmp_crtc)->pipe;
  8788. }
  8789. if (connector->new_encoder)
  8790. *prepare_pipes |=
  8791. 1 << connector->new_encoder->new_crtc->pipe;
  8792. }
  8793. for_each_intel_encoder(dev, encoder) {
  8794. if (encoder->base.crtc == &encoder->new_crtc->base)
  8795. continue;
  8796. if (encoder->base.crtc) {
  8797. tmp_crtc = encoder->base.crtc;
  8798. *prepare_pipes |= 1 << to_intel_crtc(tmp_crtc)->pipe;
  8799. }
  8800. if (encoder->new_crtc)
  8801. *prepare_pipes |= 1 << encoder->new_crtc->pipe;
  8802. }
  8803. /* Check for pipes that will be enabled/disabled ... */
  8804. for_each_intel_crtc(dev, intel_crtc) {
  8805. if (intel_crtc->base.enabled == intel_crtc->new_enabled)
  8806. continue;
  8807. if (!intel_crtc->new_enabled)
  8808. *disable_pipes |= 1 << intel_crtc->pipe;
  8809. else
  8810. *prepare_pipes |= 1 << intel_crtc->pipe;
  8811. }
  8812. /* set_mode is also used to update properties on life display pipes. */
  8813. intel_crtc = to_intel_crtc(crtc);
  8814. if (intel_crtc->new_enabled)
  8815. *prepare_pipes |= 1 << intel_crtc->pipe;
  8816. /*
  8817. * For simplicity do a full modeset on any pipe where the output routing
  8818. * changed. We could be more clever, but that would require us to be
  8819. * more careful with calling the relevant encoder->mode_set functions.
  8820. */
  8821. if (*prepare_pipes)
  8822. *modeset_pipes = *prepare_pipes;
  8823. /* ... and mask these out. */
  8824. *modeset_pipes &= ~(*disable_pipes);
  8825. *prepare_pipes &= ~(*disable_pipes);
  8826. /*
  8827. * HACK: We don't (yet) fully support global modesets. intel_set_config
  8828. * obies this rule, but the modeset restore mode of
  8829. * intel_modeset_setup_hw_state does not.
  8830. */
  8831. *modeset_pipes &= 1 << intel_crtc->pipe;
  8832. *prepare_pipes &= 1 << intel_crtc->pipe;
  8833. DRM_DEBUG_KMS("set mode pipe masks: modeset: %x, prepare: %x, disable: %x\n",
  8834. *modeset_pipes, *prepare_pipes, *disable_pipes);
  8835. }
  8836. static bool intel_crtc_in_use(struct drm_crtc *crtc)
  8837. {
  8838. struct drm_encoder *encoder;
  8839. struct drm_device *dev = crtc->dev;
  8840. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head)
  8841. if (encoder->crtc == crtc)
  8842. return true;
  8843. return false;
  8844. }
  8845. static void
  8846. intel_modeset_update_state(struct drm_device *dev, unsigned prepare_pipes)
  8847. {
  8848. struct intel_encoder *intel_encoder;
  8849. struct intel_crtc *intel_crtc;
  8850. struct drm_connector *connector;
  8851. for_each_intel_encoder(dev, intel_encoder) {
  8852. if (!intel_encoder->base.crtc)
  8853. continue;
  8854. intel_crtc = to_intel_crtc(intel_encoder->base.crtc);
  8855. if (prepare_pipes & (1 << intel_crtc->pipe))
  8856. intel_encoder->connectors_active = false;
  8857. }
  8858. intel_modeset_commit_output_state(dev);
  8859. /* Double check state. */
  8860. for_each_intel_crtc(dev, intel_crtc) {
  8861. WARN_ON(intel_crtc->base.enabled != intel_crtc_in_use(&intel_crtc->base));
  8862. WARN_ON(intel_crtc->new_config &&
  8863. intel_crtc->new_config != &intel_crtc->config);
  8864. WARN_ON(intel_crtc->base.enabled != !!intel_crtc->new_config);
  8865. }
  8866. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  8867. if (!connector->encoder || !connector->encoder->crtc)
  8868. continue;
  8869. intel_crtc = to_intel_crtc(connector->encoder->crtc);
  8870. if (prepare_pipes & (1 << intel_crtc->pipe)) {
  8871. struct drm_property *dpms_property =
  8872. dev->mode_config.dpms_property;
  8873. connector->dpms = DRM_MODE_DPMS_ON;
  8874. drm_object_property_set_value(&connector->base,
  8875. dpms_property,
  8876. DRM_MODE_DPMS_ON);
  8877. intel_encoder = to_intel_encoder(connector->encoder);
  8878. intel_encoder->connectors_active = true;
  8879. }
  8880. }
  8881. }
  8882. static bool intel_fuzzy_clock_check(int clock1, int clock2)
  8883. {
  8884. int diff;
  8885. if (clock1 == clock2)
  8886. return true;
  8887. if (!clock1 || !clock2)
  8888. return false;
  8889. diff = abs(clock1 - clock2);
  8890. if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105)
  8891. return true;
  8892. return false;
  8893. }
  8894. #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \
  8895. list_for_each_entry((intel_crtc), \
  8896. &(dev)->mode_config.crtc_list, \
  8897. base.head) \
  8898. if (mask & (1 <<(intel_crtc)->pipe))
  8899. static bool
  8900. intel_pipe_config_compare(struct drm_device *dev,
  8901. struct intel_crtc_config *current_config,
  8902. struct intel_crtc_config *pipe_config)
  8903. {
  8904. #define PIPE_CONF_CHECK_X(name) \
  8905. if (current_config->name != pipe_config->name) { \
  8906. DRM_ERROR("mismatch in " #name " " \
  8907. "(expected 0x%08x, found 0x%08x)\n", \
  8908. current_config->name, \
  8909. pipe_config->name); \
  8910. return false; \
  8911. }
  8912. #define PIPE_CONF_CHECK_I(name) \
  8913. if (current_config->name != pipe_config->name) { \
  8914. DRM_ERROR("mismatch in " #name " " \
  8915. "(expected %i, found %i)\n", \
  8916. current_config->name, \
  8917. pipe_config->name); \
  8918. return false; \
  8919. }
  8920. /* This is required for BDW+ where there is only one set of registers for
  8921. * switching between high and low RR.
  8922. * This macro can be used whenever a comparison has to be made between one
  8923. * hw state and multiple sw state variables.
  8924. */
  8925. #define PIPE_CONF_CHECK_I_ALT(name, alt_name) \
  8926. if ((current_config->name != pipe_config->name) && \
  8927. (current_config->alt_name != pipe_config->name)) { \
  8928. DRM_ERROR("mismatch in " #name " " \
  8929. "(expected %i or %i, found %i)\n", \
  8930. current_config->name, \
  8931. current_config->alt_name, \
  8932. pipe_config->name); \
  8933. return false; \
  8934. }
  8935. #define PIPE_CONF_CHECK_FLAGS(name, mask) \
  8936. if ((current_config->name ^ pipe_config->name) & (mask)) { \
  8937. DRM_ERROR("mismatch in " #name "(" #mask ") " \
  8938. "(expected %i, found %i)\n", \
  8939. current_config->name & (mask), \
  8940. pipe_config->name & (mask)); \
  8941. return false; \
  8942. }
  8943. #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \
  8944. if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
  8945. DRM_ERROR("mismatch in " #name " " \
  8946. "(expected %i, found %i)\n", \
  8947. current_config->name, \
  8948. pipe_config->name); \
  8949. return false; \
  8950. }
  8951. #define PIPE_CONF_QUIRK(quirk) \
  8952. ((current_config->quirks | pipe_config->quirks) & (quirk))
  8953. PIPE_CONF_CHECK_I(cpu_transcoder);
  8954. PIPE_CONF_CHECK_I(has_pch_encoder);
  8955. PIPE_CONF_CHECK_I(fdi_lanes);
  8956. PIPE_CONF_CHECK_I(fdi_m_n.gmch_m);
  8957. PIPE_CONF_CHECK_I(fdi_m_n.gmch_n);
  8958. PIPE_CONF_CHECK_I(fdi_m_n.link_m);
  8959. PIPE_CONF_CHECK_I(fdi_m_n.link_n);
  8960. PIPE_CONF_CHECK_I(fdi_m_n.tu);
  8961. PIPE_CONF_CHECK_I(has_dp_encoder);
  8962. if (INTEL_INFO(dev)->gen < 8) {
  8963. PIPE_CONF_CHECK_I(dp_m_n.gmch_m);
  8964. PIPE_CONF_CHECK_I(dp_m_n.gmch_n);
  8965. PIPE_CONF_CHECK_I(dp_m_n.link_m);
  8966. PIPE_CONF_CHECK_I(dp_m_n.link_n);
  8967. PIPE_CONF_CHECK_I(dp_m_n.tu);
  8968. if (current_config->has_drrs) {
  8969. PIPE_CONF_CHECK_I(dp_m2_n2.gmch_m);
  8970. PIPE_CONF_CHECK_I(dp_m2_n2.gmch_n);
  8971. PIPE_CONF_CHECK_I(dp_m2_n2.link_m);
  8972. PIPE_CONF_CHECK_I(dp_m2_n2.link_n);
  8973. PIPE_CONF_CHECK_I(dp_m2_n2.tu);
  8974. }
  8975. } else {
  8976. PIPE_CONF_CHECK_I_ALT(dp_m_n.gmch_m, dp_m2_n2.gmch_m);
  8977. PIPE_CONF_CHECK_I_ALT(dp_m_n.gmch_n, dp_m2_n2.gmch_n);
  8978. PIPE_CONF_CHECK_I_ALT(dp_m_n.link_m, dp_m2_n2.link_m);
  8979. PIPE_CONF_CHECK_I_ALT(dp_m_n.link_n, dp_m2_n2.link_n);
  8980. PIPE_CONF_CHECK_I_ALT(dp_m_n.tu, dp_m2_n2.tu);
  8981. }
  8982. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hdisplay);
  8983. PIPE_CONF_CHECK_I(adjusted_mode.crtc_htotal);
  8984. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hblank_start);
  8985. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hblank_end);
  8986. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hsync_start);
  8987. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hsync_end);
  8988. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vdisplay);
  8989. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vtotal);
  8990. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vblank_start);
  8991. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vblank_end);
  8992. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vsync_start);
  8993. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vsync_end);
  8994. PIPE_CONF_CHECK_I(pixel_multiplier);
  8995. PIPE_CONF_CHECK_I(has_hdmi_sink);
  8996. if ((INTEL_INFO(dev)->gen < 8 && !IS_HASWELL(dev)) ||
  8997. IS_VALLEYVIEW(dev))
  8998. PIPE_CONF_CHECK_I(limited_color_range);
  8999. PIPE_CONF_CHECK_I(has_audio);
  9000. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  9001. DRM_MODE_FLAG_INTERLACE);
  9002. if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) {
  9003. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  9004. DRM_MODE_FLAG_PHSYNC);
  9005. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  9006. DRM_MODE_FLAG_NHSYNC);
  9007. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  9008. DRM_MODE_FLAG_PVSYNC);
  9009. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  9010. DRM_MODE_FLAG_NVSYNC);
  9011. }
  9012. PIPE_CONF_CHECK_I(pipe_src_w);
  9013. PIPE_CONF_CHECK_I(pipe_src_h);
  9014. /*
  9015. * FIXME: BIOS likes to set up a cloned config with lvds+external
  9016. * screen. Since we don't yet re-compute the pipe config when moving
  9017. * just the lvds port away to another pipe the sw tracking won't match.
  9018. *
  9019. * Proper atomic modesets with recomputed global state will fix this.
  9020. * Until then just don't check gmch state for inherited modes.
  9021. */
  9022. if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_INHERITED_MODE)) {
  9023. PIPE_CONF_CHECK_I(gmch_pfit.control);
  9024. /* pfit ratios are autocomputed by the hw on gen4+ */
  9025. if (INTEL_INFO(dev)->gen < 4)
  9026. PIPE_CONF_CHECK_I(gmch_pfit.pgm_ratios);
  9027. PIPE_CONF_CHECK_I(gmch_pfit.lvds_border_bits);
  9028. }
  9029. PIPE_CONF_CHECK_I(pch_pfit.enabled);
  9030. if (current_config->pch_pfit.enabled) {
  9031. PIPE_CONF_CHECK_I(pch_pfit.pos);
  9032. PIPE_CONF_CHECK_I(pch_pfit.size);
  9033. }
  9034. /* BDW+ don't expose a synchronous way to read the state */
  9035. if (IS_HASWELL(dev))
  9036. PIPE_CONF_CHECK_I(ips_enabled);
  9037. PIPE_CONF_CHECK_I(double_wide);
  9038. PIPE_CONF_CHECK_X(ddi_pll_sel);
  9039. PIPE_CONF_CHECK_I(shared_dpll);
  9040. PIPE_CONF_CHECK_X(dpll_hw_state.dpll);
  9041. PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md);
  9042. PIPE_CONF_CHECK_X(dpll_hw_state.fp0);
  9043. PIPE_CONF_CHECK_X(dpll_hw_state.fp1);
  9044. PIPE_CONF_CHECK_X(dpll_hw_state.wrpll);
  9045. if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5)
  9046. PIPE_CONF_CHECK_I(pipe_bpp);
  9047. PIPE_CONF_CHECK_CLOCK_FUZZY(adjusted_mode.crtc_clock);
  9048. PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock);
  9049. #undef PIPE_CONF_CHECK_X
  9050. #undef PIPE_CONF_CHECK_I
  9051. #undef PIPE_CONF_CHECK_I_ALT
  9052. #undef PIPE_CONF_CHECK_FLAGS
  9053. #undef PIPE_CONF_CHECK_CLOCK_FUZZY
  9054. #undef PIPE_CONF_QUIRK
  9055. return true;
  9056. }
  9057. static void
  9058. check_connector_state(struct drm_device *dev)
  9059. {
  9060. struct intel_connector *connector;
  9061. list_for_each_entry(connector, &dev->mode_config.connector_list,
  9062. base.head) {
  9063. /* This also checks the encoder/connector hw state with the
  9064. * ->get_hw_state callbacks. */
  9065. intel_connector_check_state(connector);
  9066. WARN(&connector->new_encoder->base != connector->base.encoder,
  9067. "connector's staged encoder doesn't match current encoder\n");
  9068. }
  9069. }
  9070. static void
  9071. check_encoder_state(struct drm_device *dev)
  9072. {
  9073. struct intel_encoder *encoder;
  9074. struct intel_connector *connector;
  9075. for_each_intel_encoder(dev, encoder) {
  9076. bool enabled = false;
  9077. bool active = false;
  9078. enum pipe pipe, tracked_pipe;
  9079. DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
  9080. encoder->base.base.id,
  9081. encoder->base.name);
  9082. WARN(&encoder->new_crtc->base != encoder->base.crtc,
  9083. "encoder's stage crtc doesn't match current crtc\n");
  9084. WARN(encoder->connectors_active && !encoder->base.crtc,
  9085. "encoder's active_connectors set, but no crtc\n");
  9086. list_for_each_entry(connector, &dev->mode_config.connector_list,
  9087. base.head) {
  9088. if (connector->base.encoder != &encoder->base)
  9089. continue;
  9090. enabled = true;
  9091. if (connector->base.dpms != DRM_MODE_DPMS_OFF)
  9092. active = true;
  9093. }
  9094. /*
  9095. * for MST connectors if we unplug the connector is gone
  9096. * away but the encoder is still connected to a crtc
  9097. * until a modeset happens in response to the hotplug.
  9098. */
  9099. if (!enabled && encoder->base.encoder_type == DRM_MODE_ENCODER_DPMST)
  9100. continue;
  9101. WARN(!!encoder->base.crtc != enabled,
  9102. "encoder's enabled state mismatch "
  9103. "(expected %i, found %i)\n",
  9104. !!encoder->base.crtc, enabled);
  9105. WARN(active && !encoder->base.crtc,
  9106. "active encoder with no crtc\n");
  9107. WARN(encoder->connectors_active != active,
  9108. "encoder's computed active state doesn't match tracked active state "
  9109. "(expected %i, found %i)\n", active, encoder->connectors_active);
  9110. active = encoder->get_hw_state(encoder, &pipe);
  9111. WARN(active != encoder->connectors_active,
  9112. "encoder's hw state doesn't match sw tracking "
  9113. "(expected %i, found %i)\n",
  9114. encoder->connectors_active, active);
  9115. if (!encoder->base.crtc)
  9116. continue;
  9117. tracked_pipe = to_intel_crtc(encoder->base.crtc)->pipe;
  9118. WARN(active && pipe != tracked_pipe,
  9119. "active encoder's pipe doesn't match"
  9120. "(expected %i, found %i)\n",
  9121. tracked_pipe, pipe);
  9122. }
  9123. }
  9124. static void
  9125. check_crtc_state(struct drm_device *dev)
  9126. {
  9127. struct drm_i915_private *dev_priv = dev->dev_private;
  9128. struct intel_crtc *crtc;
  9129. struct intel_encoder *encoder;
  9130. struct intel_crtc_config pipe_config;
  9131. for_each_intel_crtc(dev, crtc) {
  9132. bool enabled = false;
  9133. bool active = false;
  9134. memset(&pipe_config, 0, sizeof(pipe_config));
  9135. DRM_DEBUG_KMS("[CRTC:%d]\n",
  9136. crtc->base.base.id);
  9137. WARN(crtc->active && !crtc->base.enabled,
  9138. "active crtc, but not enabled in sw tracking\n");
  9139. for_each_intel_encoder(dev, encoder) {
  9140. if (encoder->base.crtc != &crtc->base)
  9141. continue;
  9142. enabled = true;
  9143. if (encoder->connectors_active)
  9144. active = true;
  9145. }
  9146. WARN(active != crtc->active,
  9147. "crtc's computed active state doesn't match tracked active state "
  9148. "(expected %i, found %i)\n", active, crtc->active);
  9149. WARN(enabled != crtc->base.enabled,
  9150. "crtc's computed enabled state doesn't match tracked enabled state "
  9151. "(expected %i, found %i)\n", enabled, crtc->base.enabled);
  9152. active = dev_priv->display.get_pipe_config(crtc,
  9153. &pipe_config);
  9154. /* hw state is inconsistent with the pipe quirk */
  9155. if ((crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) ||
  9156. (crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))
  9157. active = crtc->active;
  9158. for_each_intel_encoder(dev, encoder) {
  9159. enum pipe pipe;
  9160. if (encoder->base.crtc != &crtc->base)
  9161. continue;
  9162. if (encoder->get_hw_state(encoder, &pipe))
  9163. encoder->get_config(encoder, &pipe_config);
  9164. }
  9165. WARN(crtc->active != active,
  9166. "crtc active state doesn't match with hw state "
  9167. "(expected %i, found %i)\n", crtc->active, active);
  9168. if (active &&
  9169. !intel_pipe_config_compare(dev, &crtc->config, &pipe_config)) {
  9170. WARN(1, "pipe state doesn't match!\n");
  9171. intel_dump_pipe_config(crtc, &pipe_config,
  9172. "[hw state]");
  9173. intel_dump_pipe_config(crtc, &crtc->config,
  9174. "[sw state]");
  9175. }
  9176. }
  9177. }
  9178. static void
  9179. check_shared_dpll_state(struct drm_device *dev)
  9180. {
  9181. struct drm_i915_private *dev_priv = dev->dev_private;
  9182. struct intel_crtc *crtc;
  9183. struct intel_dpll_hw_state dpll_hw_state;
  9184. int i;
  9185. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  9186. struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
  9187. int enabled_crtcs = 0, active_crtcs = 0;
  9188. bool active;
  9189. memset(&dpll_hw_state, 0, sizeof(dpll_hw_state));
  9190. DRM_DEBUG_KMS("%s\n", pll->name);
  9191. active = pll->get_hw_state(dev_priv, pll, &dpll_hw_state);
  9192. WARN(pll->active > pll->refcount,
  9193. "more active pll users than references: %i vs %i\n",
  9194. pll->active, pll->refcount);
  9195. WARN(pll->active && !pll->on,
  9196. "pll in active use but not on in sw tracking\n");
  9197. WARN(pll->on && !pll->active,
  9198. "pll in on but not on in use in sw tracking\n");
  9199. WARN(pll->on != active,
  9200. "pll on state mismatch (expected %i, found %i)\n",
  9201. pll->on, active);
  9202. for_each_intel_crtc(dev, crtc) {
  9203. if (crtc->base.enabled && intel_crtc_to_shared_dpll(crtc) == pll)
  9204. enabled_crtcs++;
  9205. if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll)
  9206. active_crtcs++;
  9207. }
  9208. WARN(pll->active != active_crtcs,
  9209. "pll active crtcs mismatch (expected %i, found %i)\n",
  9210. pll->active, active_crtcs);
  9211. WARN(pll->refcount != enabled_crtcs,
  9212. "pll enabled crtcs mismatch (expected %i, found %i)\n",
  9213. pll->refcount, enabled_crtcs);
  9214. WARN(pll->on && memcmp(&pll->hw_state, &dpll_hw_state,
  9215. sizeof(dpll_hw_state)),
  9216. "pll hw state mismatch\n");
  9217. }
  9218. }
  9219. void
  9220. intel_modeset_check_state(struct drm_device *dev)
  9221. {
  9222. check_connector_state(dev);
  9223. check_encoder_state(dev);
  9224. check_crtc_state(dev);
  9225. check_shared_dpll_state(dev);
  9226. }
  9227. void ironlake_check_encoder_dotclock(const struct intel_crtc_config *pipe_config,
  9228. int dotclock)
  9229. {
  9230. /*
  9231. * FDI already provided one idea for the dotclock.
  9232. * Yell if the encoder disagrees.
  9233. */
  9234. WARN(!intel_fuzzy_clock_check(pipe_config->adjusted_mode.crtc_clock, dotclock),
  9235. "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
  9236. pipe_config->adjusted_mode.crtc_clock, dotclock);
  9237. }
  9238. static void update_scanline_offset(struct intel_crtc *crtc)
  9239. {
  9240. struct drm_device *dev = crtc->base.dev;
  9241. /*
  9242. * The scanline counter increments at the leading edge of hsync.
  9243. *
  9244. * On most platforms it starts counting from vtotal-1 on the
  9245. * first active line. That means the scanline counter value is
  9246. * always one less than what we would expect. Ie. just after
  9247. * start of vblank, which also occurs at start of hsync (on the
  9248. * last active line), the scanline counter will read vblank_start-1.
  9249. *
  9250. * On gen2 the scanline counter starts counting from 1 instead
  9251. * of vtotal-1, so we have to subtract one (or rather add vtotal-1
  9252. * to keep the value positive), instead of adding one.
  9253. *
  9254. * On HSW+ the behaviour of the scanline counter depends on the output
  9255. * type. For DP ports it behaves like most other platforms, but on HDMI
  9256. * there's an extra 1 line difference. So we need to add two instead of
  9257. * one to the value.
  9258. */
  9259. if (IS_GEN2(dev)) {
  9260. const struct drm_display_mode *mode = &crtc->config.adjusted_mode;
  9261. int vtotal;
  9262. vtotal = mode->crtc_vtotal;
  9263. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  9264. vtotal /= 2;
  9265. crtc->scanline_offset = vtotal - 1;
  9266. } else if (HAS_DDI(dev) &&
  9267. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_HDMI)) {
  9268. crtc->scanline_offset = 2;
  9269. } else
  9270. crtc->scanline_offset = 1;
  9271. }
  9272. static int __intel_set_mode(struct drm_crtc *crtc,
  9273. struct drm_display_mode *mode,
  9274. int x, int y, struct drm_framebuffer *fb)
  9275. {
  9276. struct drm_device *dev = crtc->dev;
  9277. struct drm_i915_private *dev_priv = dev->dev_private;
  9278. struct drm_display_mode *saved_mode;
  9279. struct intel_crtc_config *pipe_config = NULL;
  9280. struct intel_crtc *intel_crtc;
  9281. unsigned disable_pipes, prepare_pipes, modeset_pipes;
  9282. int ret = 0;
  9283. saved_mode = kmalloc(sizeof(*saved_mode), GFP_KERNEL);
  9284. if (!saved_mode)
  9285. return -ENOMEM;
  9286. intel_modeset_affected_pipes(crtc, &modeset_pipes,
  9287. &prepare_pipes, &disable_pipes);
  9288. *saved_mode = crtc->mode;
  9289. /* Hack: Because we don't (yet) support global modeset on multiple
  9290. * crtcs, we don't keep track of the new mode for more than one crtc.
  9291. * Hence simply check whether any bit is set in modeset_pipes in all the
  9292. * pieces of code that are not yet converted to deal with mutliple crtcs
  9293. * changing their mode at the same time. */
  9294. if (modeset_pipes) {
  9295. pipe_config = intel_modeset_pipe_config(crtc, fb, mode);
  9296. if (IS_ERR(pipe_config)) {
  9297. ret = PTR_ERR(pipe_config);
  9298. pipe_config = NULL;
  9299. goto out;
  9300. }
  9301. intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config,
  9302. "[modeset]");
  9303. to_intel_crtc(crtc)->new_config = pipe_config;
  9304. }
  9305. /*
  9306. * See if the config requires any additional preparation, e.g.
  9307. * to adjust global state with pipes off. We need to do this
  9308. * here so we can get the modeset_pipe updated config for the new
  9309. * mode set on this crtc. For other crtcs we need to use the
  9310. * adjusted_mode bits in the crtc directly.
  9311. */
  9312. if (IS_VALLEYVIEW(dev)) {
  9313. valleyview_modeset_global_pipes(dev, &prepare_pipes);
  9314. /* may have added more to prepare_pipes than we should */
  9315. prepare_pipes &= ~disable_pipes;
  9316. }
  9317. for_each_intel_crtc_masked(dev, disable_pipes, intel_crtc)
  9318. intel_crtc_disable(&intel_crtc->base);
  9319. for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc) {
  9320. if (intel_crtc->base.enabled)
  9321. dev_priv->display.crtc_disable(&intel_crtc->base);
  9322. }
  9323. /* crtc->mode is already used by the ->mode_set callbacks, hence we need
  9324. * to set it here already despite that we pass it down the callchain.
  9325. */
  9326. if (modeset_pipes) {
  9327. crtc->mode = *mode;
  9328. /* mode_set/enable/disable functions rely on a correct pipe
  9329. * config. */
  9330. to_intel_crtc(crtc)->config = *pipe_config;
  9331. to_intel_crtc(crtc)->new_config = &to_intel_crtc(crtc)->config;
  9332. /*
  9333. * Calculate and store various constants which
  9334. * are later needed by vblank and swap-completion
  9335. * timestamping. They are derived from true hwmode.
  9336. */
  9337. drm_calc_timestamping_constants(crtc,
  9338. &pipe_config->adjusted_mode);
  9339. }
  9340. /* Only after disabling all output pipelines that will be changed can we
  9341. * update the the output configuration. */
  9342. intel_modeset_update_state(dev, prepare_pipes);
  9343. if (dev_priv->display.modeset_global_resources)
  9344. dev_priv->display.modeset_global_resources(dev);
  9345. /* Set up the DPLL and any encoders state that needs to adjust or depend
  9346. * on the DPLL.
  9347. */
  9348. for_each_intel_crtc_masked(dev, modeset_pipes, intel_crtc) {
  9349. struct drm_framebuffer *old_fb = crtc->primary->fb;
  9350. struct drm_i915_gem_object *old_obj = intel_fb_obj(old_fb);
  9351. struct drm_i915_gem_object *obj = intel_fb_obj(fb);
  9352. mutex_lock(&dev->struct_mutex);
  9353. ret = intel_pin_and_fence_fb_obj(dev,
  9354. obj,
  9355. NULL);
  9356. if (ret != 0) {
  9357. DRM_ERROR("pin & fence failed\n");
  9358. mutex_unlock(&dev->struct_mutex);
  9359. goto done;
  9360. }
  9361. if (old_fb)
  9362. intel_unpin_fb_obj(old_obj);
  9363. i915_gem_track_fb(old_obj, obj,
  9364. INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe));
  9365. mutex_unlock(&dev->struct_mutex);
  9366. crtc->primary->fb = fb;
  9367. crtc->x = x;
  9368. crtc->y = y;
  9369. ret = dev_priv->display.crtc_mode_set(&intel_crtc->base,
  9370. x, y, fb);
  9371. if (ret)
  9372. goto done;
  9373. }
  9374. /* Now enable the clocks, plane, pipe, and connectors that we set up. */
  9375. for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc) {
  9376. update_scanline_offset(intel_crtc);
  9377. dev_priv->display.crtc_enable(&intel_crtc->base);
  9378. }
  9379. /* FIXME: add subpixel order */
  9380. done:
  9381. if (ret && crtc->enabled)
  9382. crtc->mode = *saved_mode;
  9383. out:
  9384. kfree(pipe_config);
  9385. kfree(saved_mode);
  9386. return ret;
  9387. }
  9388. static int intel_set_mode(struct drm_crtc *crtc,
  9389. struct drm_display_mode *mode,
  9390. int x, int y, struct drm_framebuffer *fb)
  9391. {
  9392. int ret;
  9393. ret = __intel_set_mode(crtc, mode, x, y, fb);
  9394. if (ret == 0)
  9395. intel_modeset_check_state(crtc->dev);
  9396. return ret;
  9397. }
  9398. void intel_crtc_restore_mode(struct drm_crtc *crtc)
  9399. {
  9400. intel_set_mode(crtc, &crtc->mode, crtc->x, crtc->y, crtc->primary->fb);
  9401. }
  9402. #undef for_each_intel_crtc_masked
  9403. static void intel_set_config_free(struct intel_set_config *config)
  9404. {
  9405. if (!config)
  9406. return;
  9407. kfree(config->save_connector_encoders);
  9408. kfree(config->save_encoder_crtcs);
  9409. kfree(config->save_crtc_enabled);
  9410. kfree(config);
  9411. }
  9412. static int intel_set_config_save_state(struct drm_device *dev,
  9413. struct intel_set_config *config)
  9414. {
  9415. struct drm_crtc *crtc;
  9416. struct drm_encoder *encoder;
  9417. struct drm_connector *connector;
  9418. int count;
  9419. config->save_crtc_enabled =
  9420. kcalloc(dev->mode_config.num_crtc,
  9421. sizeof(bool), GFP_KERNEL);
  9422. if (!config->save_crtc_enabled)
  9423. return -ENOMEM;
  9424. config->save_encoder_crtcs =
  9425. kcalloc(dev->mode_config.num_encoder,
  9426. sizeof(struct drm_crtc *), GFP_KERNEL);
  9427. if (!config->save_encoder_crtcs)
  9428. return -ENOMEM;
  9429. config->save_connector_encoders =
  9430. kcalloc(dev->mode_config.num_connector,
  9431. sizeof(struct drm_encoder *), GFP_KERNEL);
  9432. if (!config->save_connector_encoders)
  9433. return -ENOMEM;
  9434. /* Copy data. Note that driver private data is not affected.
  9435. * Should anything bad happen only the expected state is
  9436. * restored, not the drivers personal bookkeeping.
  9437. */
  9438. count = 0;
  9439. for_each_crtc(dev, crtc) {
  9440. config->save_crtc_enabled[count++] = crtc->enabled;
  9441. }
  9442. count = 0;
  9443. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  9444. config->save_encoder_crtcs[count++] = encoder->crtc;
  9445. }
  9446. count = 0;
  9447. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  9448. config->save_connector_encoders[count++] = connector->encoder;
  9449. }
  9450. return 0;
  9451. }
  9452. static void intel_set_config_restore_state(struct drm_device *dev,
  9453. struct intel_set_config *config)
  9454. {
  9455. struct intel_crtc *crtc;
  9456. struct intel_encoder *encoder;
  9457. struct intel_connector *connector;
  9458. int count;
  9459. count = 0;
  9460. for_each_intel_crtc(dev, crtc) {
  9461. crtc->new_enabled = config->save_crtc_enabled[count++];
  9462. if (crtc->new_enabled)
  9463. crtc->new_config = &crtc->config;
  9464. else
  9465. crtc->new_config = NULL;
  9466. }
  9467. count = 0;
  9468. for_each_intel_encoder(dev, encoder) {
  9469. encoder->new_crtc =
  9470. to_intel_crtc(config->save_encoder_crtcs[count++]);
  9471. }
  9472. count = 0;
  9473. list_for_each_entry(connector, &dev->mode_config.connector_list, base.head) {
  9474. connector->new_encoder =
  9475. to_intel_encoder(config->save_connector_encoders[count++]);
  9476. }
  9477. }
  9478. static bool
  9479. is_crtc_connector_off(struct drm_mode_set *set)
  9480. {
  9481. int i;
  9482. if (set->num_connectors == 0)
  9483. return false;
  9484. if (WARN_ON(set->connectors == NULL))
  9485. return false;
  9486. for (i = 0; i < set->num_connectors; i++)
  9487. if (set->connectors[i]->encoder &&
  9488. set->connectors[i]->encoder->crtc == set->crtc &&
  9489. set->connectors[i]->dpms != DRM_MODE_DPMS_ON)
  9490. return true;
  9491. return false;
  9492. }
  9493. static void
  9494. intel_set_config_compute_mode_changes(struct drm_mode_set *set,
  9495. struct intel_set_config *config)
  9496. {
  9497. /* We should be able to check here if the fb has the same properties
  9498. * and then just flip_or_move it */
  9499. if (is_crtc_connector_off(set)) {
  9500. config->mode_changed = true;
  9501. } else if (set->crtc->primary->fb != set->fb) {
  9502. /*
  9503. * If we have no fb, we can only flip as long as the crtc is
  9504. * active, otherwise we need a full mode set. The crtc may
  9505. * be active if we've only disabled the primary plane, or
  9506. * in fastboot situations.
  9507. */
  9508. if (set->crtc->primary->fb == NULL) {
  9509. struct intel_crtc *intel_crtc =
  9510. to_intel_crtc(set->crtc);
  9511. if (intel_crtc->active) {
  9512. DRM_DEBUG_KMS("crtc has no fb, will flip\n");
  9513. config->fb_changed = true;
  9514. } else {
  9515. DRM_DEBUG_KMS("inactive crtc, full mode set\n");
  9516. config->mode_changed = true;
  9517. }
  9518. } else if (set->fb == NULL) {
  9519. config->mode_changed = true;
  9520. } else if (set->fb->pixel_format !=
  9521. set->crtc->primary->fb->pixel_format) {
  9522. config->mode_changed = true;
  9523. } else {
  9524. config->fb_changed = true;
  9525. }
  9526. }
  9527. if (set->fb && (set->x != set->crtc->x || set->y != set->crtc->y))
  9528. config->fb_changed = true;
  9529. if (set->mode && !drm_mode_equal(set->mode, &set->crtc->mode)) {
  9530. DRM_DEBUG_KMS("modes are different, full mode set\n");
  9531. drm_mode_debug_printmodeline(&set->crtc->mode);
  9532. drm_mode_debug_printmodeline(set->mode);
  9533. config->mode_changed = true;
  9534. }
  9535. DRM_DEBUG_KMS("computed changes for [CRTC:%d], mode_changed=%d, fb_changed=%d\n",
  9536. set->crtc->base.id, config->mode_changed, config->fb_changed);
  9537. }
  9538. static int
  9539. intel_modeset_stage_output_state(struct drm_device *dev,
  9540. struct drm_mode_set *set,
  9541. struct intel_set_config *config)
  9542. {
  9543. struct intel_connector *connector;
  9544. struct intel_encoder *encoder;
  9545. struct intel_crtc *crtc;
  9546. int ro;
  9547. /* The upper layers ensure that we either disable a crtc or have a list
  9548. * of connectors. For paranoia, double-check this. */
  9549. WARN_ON(!set->fb && (set->num_connectors != 0));
  9550. WARN_ON(set->fb && (set->num_connectors == 0));
  9551. list_for_each_entry(connector, &dev->mode_config.connector_list,
  9552. base.head) {
  9553. /* Otherwise traverse passed in connector list and get encoders
  9554. * for them. */
  9555. for (ro = 0; ro < set->num_connectors; ro++) {
  9556. if (set->connectors[ro] == &connector->base) {
  9557. connector->new_encoder = intel_find_encoder(connector, to_intel_crtc(set->crtc)->pipe);
  9558. break;
  9559. }
  9560. }
  9561. /* If we disable the crtc, disable all its connectors. Also, if
  9562. * the connector is on the changing crtc but not on the new
  9563. * connector list, disable it. */
  9564. if ((!set->fb || ro == set->num_connectors) &&
  9565. connector->base.encoder &&
  9566. connector->base.encoder->crtc == set->crtc) {
  9567. connector->new_encoder = NULL;
  9568. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n",
  9569. connector->base.base.id,
  9570. connector->base.name);
  9571. }
  9572. if (&connector->new_encoder->base != connector->base.encoder) {
  9573. DRM_DEBUG_KMS("encoder changed, full mode switch\n");
  9574. config->mode_changed = true;
  9575. }
  9576. }
  9577. /* connector->new_encoder is now updated for all connectors. */
  9578. /* Update crtc of enabled connectors. */
  9579. list_for_each_entry(connector, &dev->mode_config.connector_list,
  9580. base.head) {
  9581. struct drm_crtc *new_crtc;
  9582. if (!connector->new_encoder)
  9583. continue;
  9584. new_crtc = connector->new_encoder->base.crtc;
  9585. for (ro = 0; ro < set->num_connectors; ro++) {
  9586. if (set->connectors[ro] == &connector->base)
  9587. new_crtc = set->crtc;
  9588. }
  9589. /* Make sure the new CRTC will work with the encoder */
  9590. if (!drm_encoder_crtc_ok(&connector->new_encoder->base,
  9591. new_crtc)) {
  9592. return -EINVAL;
  9593. }
  9594. connector->new_encoder->new_crtc = to_intel_crtc(new_crtc);
  9595. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n",
  9596. connector->base.base.id,
  9597. connector->base.name,
  9598. new_crtc->base.id);
  9599. }
  9600. /* Check for any encoders that needs to be disabled. */
  9601. for_each_intel_encoder(dev, encoder) {
  9602. int num_connectors = 0;
  9603. list_for_each_entry(connector,
  9604. &dev->mode_config.connector_list,
  9605. base.head) {
  9606. if (connector->new_encoder == encoder) {
  9607. WARN_ON(!connector->new_encoder->new_crtc);
  9608. num_connectors++;
  9609. }
  9610. }
  9611. if (num_connectors == 0)
  9612. encoder->new_crtc = NULL;
  9613. else if (num_connectors > 1)
  9614. return -EINVAL;
  9615. /* Only now check for crtc changes so we don't miss encoders
  9616. * that will be disabled. */
  9617. if (&encoder->new_crtc->base != encoder->base.crtc) {
  9618. DRM_DEBUG_KMS("crtc changed, full mode switch\n");
  9619. config->mode_changed = true;
  9620. }
  9621. }
  9622. /* Now we've also updated encoder->new_crtc for all encoders. */
  9623. list_for_each_entry(connector, &dev->mode_config.connector_list,
  9624. base.head) {
  9625. if (connector->new_encoder)
  9626. if (connector->new_encoder != connector->encoder)
  9627. connector->encoder = connector->new_encoder;
  9628. }
  9629. for_each_intel_crtc(dev, crtc) {
  9630. crtc->new_enabled = false;
  9631. for_each_intel_encoder(dev, encoder) {
  9632. if (encoder->new_crtc == crtc) {
  9633. crtc->new_enabled = true;
  9634. break;
  9635. }
  9636. }
  9637. if (crtc->new_enabled != crtc->base.enabled) {
  9638. DRM_DEBUG_KMS("crtc %sabled, full mode switch\n",
  9639. crtc->new_enabled ? "en" : "dis");
  9640. config->mode_changed = true;
  9641. }
  9642. if (crtc->new_enabled)
  9643. crtc->new_config = &crtc->config;
  9644. else
  9645. crtc->new_config = NULL;
  9646. }
  9647. return 0;
  9648. }
  9649. static void disable_crtc_nofb(struct intel_crtc *crtc)
  9650. {
  9651. struct drm_device *dev = crtc->base.dev;
  9652. struct intel_encoder *encoder;
  9653. struct intel_connector *connector;
  9654. DRM_DEBUG_KMS("Trying to restore without FB -> disabling pipe %c\n",
  9655. pipe_name(crtc->pipe));
  9656. list_for_each_entry(connector, &dev->mode_config.connector_list, base.head) {
  9657. if (connector->new_encoder &&
  9658. connector->new_encoder->new_crtc == crtc)
  9659. connector->new_encoder = NULL;
  9660. }
  9661. for_each_intel_encoder(dev, encoder) {
  9662. if (encoder->new_crtc == crtc)
  9663. encoder->new_crtc = NULL;
  9664. }
  9665. crtc->new_enabled = false;
  9666. crtc->new_config = NULL;
  9667. }
  9668. static int intel_crtc_set_config(struct drm_mode_set *set)
  9669. {
  9670. struct drm_device *dev;
  9671. struct drm_mode_set save_set;
  9672. struct intel_set_config *config;
  9673. int ret;
  9674. BUG_ON(!set);
  9675. BUG_ON(!set->crtc);
  9676. BUG_ON(!set->crtc->helper_private);
  9677. /* Enforce sane interface api - has been abused by the fb helper. */
  9678. BUG_ON(!set->mode && set->fb);
  9679. BUG_ON(set->fb && set->num_connectors == 0);
  9680. if (set->fb) {
  9681. DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n",
  9682. set->crtc->base.id, set->fb->base.id,
  9683. (int)set->num_connectors, set->x, set->y);
  9684. } else {
  9685. DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set->crtc->base.id);
  9686. }
  9687. dev = set->crtc->dev;
  9688. ret = -ENOMEM;
  9689. config = kzalloc(sizeof(*config), GFP_KERNEL);
  9690. if (!config)
  9691. goto out_config;
  9692. ret = intel_set_config_save_state(dev, config);
  9693. if (ret)
  9694. goto out_config;
  9695. save_set.crtc = set->crtc;
  9696. save_set.mode = &set->crtc->mode;
  9697. save_set.x = set->crtc->x;
  9698. save_set.y = set->crtc->y;
  9699. save_set.fb = set->crtc->primary->fb;
  9700. /* Compute whether we need a full modeset, only an fb base update or no
  9701. * change at all. In the future we might also check whether only the
  9702. * mode changed, e.g. for LVDS where we only change the panel fitter in
  9703. * such cases. */
  9704. intel_set_config_compute_mode_changes(set, config);
  9705. ret = intel_modeset_stage_output_state(dev, set, config);
  9706. if (ret)
  9707. goto fail;
  9708. if (config->mode_changed) {
  9709. ret = intel_set_mode(set->crtc, set->mode,
  9710. set->x, set->y, set->fb);
  9711. } else if (config->fb_changed) {
  9712. struct intel_crtc *intel_crtc = to_intel_crtc(set->crtc);
  9713. intel_crtc_wait_for_pending_flips(set->crtc);
  9714. ret = intel_pipe_set_base(set->crtc,
  9715. set->x, set->y, set->fb);
  9716. /*
  9717. * We need to make sure the primary plane is re-enabled if it
  9718. * has previously been turned off.
  9719. */
  9720. if (!intel_crtc->primary_enabled && ret == 0) {
  9721. WARN_ON(!intel_crtc->active);
  9722. intel_enable_primary_hw_plane(set->crtc->primary, set->crtc);
  9723. }
  9724. /*
  9725. * In the fastboot case this may be our only check of the
  9726. * state after boot. It would be better to only do it on
  9727. * the first update, but we don't have a nice way of doing that
  9728. * (and really, set_config isn't used much for high freq page
  9729. * flipping, so increasing its cost here shouldn't be a big
  9730. * deal).
  9731. */
  9732. if (i915.fastboot && ret == 0)
  9733. intel_modeset_check_state(set->crtc->dev);
  9734. }
  9735. if (ret) {
  9736. DRM_DEBUG_KMS("failed to set mode on [CRTC:%d], err = %d\n",
  9737. set->crtc->base.id, ret);
  9738. fail:
  9739. intel_set_config_restore_state(dev, config);
  9740. /*
  9741. * HACK: if the pipe was on, but we didn't have a framebuffer,
  9742. * force the pipe off to avoid oopsing in the modeset code
  9743. * due to fb==NULL. This should only happen during boot since
  9744. * we don't yet reconstruct the FB from the hardware state.
  9745. */
  9746. if (to_intel_crtc(save_set.crtc)->new_enabled && !save_set.fb)
  9747. disable_crtc_nofb(to_intel_crtc(save_set.crtc));
  9748. /* Try to restore the config */
  9749. if (config->mode_changed &&
  9750. intel_set_mode(save_set.crtc, save_set.mode,
  9751. save_set.x, save_set.y, save_set.fb))
  9752. DRM_ERROR("failed to restore config after modeset failure\n");
  9753. }
  9754. out_config:
  9755. intel_set_config_free(config);
  9756. return ret;
  9757. }
  9758. static const struct drm_crtc_funcs intel_crtc_funcs = {
  9759. .gamma_set = intel_crtc_gamma_set,
  9760. .set_config = intel_crtc_set_config,
  9761. .destroy = intel_crtc_destroy,
  9762. .page_flip = intel_crtc_page_flip,
  9763. };
  9764. static bool ibx_pch_dpll_get_hw_state(struct drm_i915_private *dev_priv,
  9765. struct intel_shared_dpll *pll,
  9766. struct intel_dpll_hw_state *hw_state)
  9767. {
  9768. uint32_t val;
  9769. if (!intel_display_power_enabled(dev_priv, POWER_DOMAIN_PLLS))
  9770. return false;
  9771. val = I915_READ(PCH_DPLL(pll->id));
  9772. hw_state->dpll = val;
  9773. hw_state->fp0 = I915_READ(PCH_FP0(pll->id));
  9774. hw_state->fp1 = I915_READ(PCH_FP1(pll->id));
  9775. return val & DPLL_VCO_ENABLE;
  9776. }
  9777. static void ibx_pch_dpll_mode_set(struct drm_i915_private *dev_priv,
  9778. struct intel_shared_dpll *pll)
  9779. {
  9780. I915_WRITE(PCH_FP0(pll->id), pll->hw_state.fp0);
  9781. I915_WRITE(PCH_FP1(pll->id), pll->hw_state.fp1);
  9782. }
  9783. static void ibx_pch_dpll_enable(struct drm_i915_private *dev_priv,
  9784. struct intel_shared_dpll *pll)
  9785. {
  9786. /* PCH refclock must be enabled first */
  9787. ibx_assert_pch_refclk_enabled(dev_priv);
  9788. I915_WRITE(PCH_DPLL(pll->id), pll->hw_state.dpll);
  9789. /* Wait for the clocks to stabilize. */
  9790. POSTING_READ(PCH_DPLL(pll->id));
  9791. udelay(150);
  9792. /* The pixel multiplier can only be updated once the
  9793. * DPLL is enabled and the clocks are stable.
  9794. *
  9795. * So write it again.
  9796. */
  9797. I915_WRITE(PCH_DPLL(pll->id), pll->hw_state.dpll);
  9798. POSTING_READ(PCH_DPLL(pll->id));
  9799. udelay(200);
  9800. }
  9801. static void ibx_pch_dpll_disable(struct drm_i915_private *dev_priv,
  9802. struct intel_shared_dpll *pll)
  9803. {
  9804. struct drm_device *dev = dev_priv->dev;
  9805. struct intel_crtc *crtc;
  9806. /* Make sure no transcoder isn't still depending on us. */
  9807. for_each_intel_crtc(dev, crtc) {
  9808. if (intel_crtc_to_shared_dpll(crtc) == pll)
  9809. assert_pch_transcoder_disabled(dev_priv, crtc->pipe);
  9810. }
  9811. I915_WRITE(PCH_DPLL(pll->id), 0);
  9812. POSTING_READ(PCH_DPLL(pll->id));
  9813. udelay(200);
  9814. }
  9815. static char *ibx_pch_dpll_names[] = {
  9816. "PCH DPLL A",
  9817. "PCH DPLL B",
  9818. };
  9819. static void ibx_pch_dpll_init(struct drm_device *dev)
  9820. {
  9821. struct drm_i915_private *dev_priv = dev->dev_private;
  9822. int i;
  9823. dev_priv->num_shared_dpll = 2;
  9824. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  9825. dev_priv->shared_dplls[i].id = i;
  9826. dev_priv->shared_dplls[i].name = ibx_pch_dpll_names[i];
  9827. dev_priv->shared_dplls[i].mode_set = ibx_pch_dpll_mode_set;
  9828. dev_priv->shared_dplls[i].enable = ibx_pch_dpll_enable;
  9829. dev_priv->shared_dplls[i].disable = ibx_pch_dpll_disable;
  9830. dev_priv->shared_dplls[i].get_hw_state =
  9831. ibx_pch_dpll_get_hw_state;
  9832. }
  9833. }
  9834. static void intel_shared_dpll_init(struct drm_device *dev)
  9835. {
  9836. struct drm_i915_private *dev_priv = dev->dev_private;
  9837. if (HAS_DDI(dev))
  9838. intel_ddi_pll_init(dev);
  9839. else if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
  9840. ibx_pch_dpll_init(dev);
  9841. else
  9842. dev_priv->num_shared_dpll = 0;
  9843. BUG_ON(dev_priv->num_shared_dpll > I915_NUM_PLLS);
  9844. }
  9845. static int
  9846. intel_primary_plane_disable(struct drm_plane *plane)
  9847. {
  9848. struct drm_device *dev = plane->dev;
  9849. struct intel_crtc *intel_crtc;
  9850. if (!plane->fb)
  9851. return 0;
  9852. BUG_ON(!plane->crtc);
  9853. intel_crtc = to_intel_crtc(plane->crtc);
  9854. /*
  9855. * Even though we checked plane->fb above, it's still possible that
  9856. * the primary plane has been implicitly disabled because the crtc
  9857. * coordinates given weren't visible, or because we detected
  9858. * that it was 100% covered by a sprite plane. Or, the CRTC may be
  9859. * off and we've set a fb, but haven't actually turned on the CRTC yet.
  9860. * In either case, we need to unpin the FB and let the fb pointer get
  9861. * updated, but otherwise we don't need to touch the hardware.
  9862. */
  9863. if (!intel_crtc->primary_enabled)
  9864. goto disable_unpin;
  9865. intel_crtc_wait_for_pending_flips(plane->crtc);
  9866. intel_disable_primary_hw_plane(plane, plane->crtc);
  9867. disable_unpin:
  9868. mutex_lock(&dev->struct_mutex);
  9869. i915_gem_track_fb(intel_fb_obj(plane->fb), NULL,
  9870. INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe));
  9871. intel_unpin_fb_obj(intel_fb_obj(plane->fb));
  9872. mutex_unlock(&dev->struct_mutex);
  9873. plane->fb = NULL;
  9874. return 0;
  9875. }
  9876. static int
  9877. intel_primary_plane_setplane(struct drm_plane *plane, struct drm_crtc *crtc,
  9878. struct drm_framebuffer *fb, int crtc_x, int crtc_y,
  9879. unsigned int crtc_w, unsigned int crtc_h,
  9880. uint32_t src_x, uint32_t src_y,
  9881. uint32_t src_w, uint32_t src_h)
  9882. {
  9883. struct drm_device *dev = crtc->dev;
  9884. struct drm_i915_private *dev_priv = dev->dev_private;
  9885. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  9886. struct drm_i915_gem_object *obj = intel_fb_obj(fb);
  9887. struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->fb);
  9888. struct drm_rect dest = {
  9889. /* integer pixels */
  9890. .x1 = crtc_x,
  9891. .y1 = crtc_y,
  9892. .x2 = crtc_x + crtc_w,
  9893. .y2 = crtc_y + crtc_h,
  9894. };
  9895. struct drm_rect src = {
  9896. /* 16.16 fixed point */
  9897. .x1 = src_x,
  9898. .y1 = src_y,
  9899. .x2 = src_x + src_w,
  9900. .y2 = src_y + src_h,
  9901. };
  9902. const struct drm_rect clip = {
  9903. /* integer pixels */
  9904. .x2 = intel_crtc->active ? intel_crtc->config.pipe_src_w : 0,
  9905. .y2 = intel_crtc->active ? intel_crtc->config.pipe_src_h : 0,
  9906. };
  9907. const struct {
  9908. int crtc_x, crtc_y;
  9909. unsigned int crtc_w, crtc_h;
  9910. uint32_t src_x, src_y, src_w, src_h;
  9911. } orig = {
  9912. .crtc_x = crtc_x,
  9913. .crtc_y = crtc_y,
  9914. .crtc_w = crtc_w,
  9915. .crtc_h = crtc_h,
  9916. .src_x = src_x,
  9917. .src_y = src_y,
  9918. .src_w = src_w,
  9919. .src_h = src_h,
  9920. };
  9921. struct intel_plane *intel_plane = to_intel_plane(plane);
  9922. bool visible;
  9923. int ret;
  9924. ret = drm_plane_helper_check_update(plane, crtc, fb,
  9925. &src, &dest, &clip,
  9926. DRM_PLANE_HELPER_NO_SCALING,
  9927. DRM_PLANE_HELPER_NO_SCALING,
  9928. false, true, &visible);
  9929. if (ret)
  9930. return ret;
  9931. /*
  9932. * If the CRTC isn't enabled, we're just pinning the framebuffer,
  9933. * updating the fb pointer, and returning without touching the
  9934. * hardware. This allows us to later do a drmModeSetCrtc with fb=-1 to
  9935. * turn on the display with all planes setup as desired.
  9936. */
  9937. if (!crtc->enabled) {
  9938. mutex_lock(&dev->struct_mutex);
  9939. /*
  9940. * If we already called setplane while the crtc was disabled,
  9941. * we may have an fb pinned; unpin it.
  9942. */
  9943. if (plane->fb)
  9944. intel_unpin_fb_obj(old_obj);
  9945. i915_gem_track_fb(old_obj, obj,
  9946. INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe));
  9947. /* Pin and return without programming hardware */
  9948. ret = intel_pin_and_fence_fb_obj(dev, obj, NULL);
  9949. mutex_unlock(&dev->struct_mutex);
  9950. return ret;
  9951. }
  9952. intel_crtc_wait_for_pending_flips(crtc);
  9953. /*
  9954. * If clipping results in a non-visible primary plane, we'll disable
  9955. * the primary plane. Note that this is a bit different than what
  9956. * happens if userspace explicitly disables the plane by passing fb=0
  9957. * because plane->fb still gets set and pinned.
  9958. */
  9959. if (!visible) {
  9960. mutex_lock(&dev->struct_mutex);
  9961. /*
  9962. * Try to pin the new fb first so that we can bail out if we
  9963. * fail.
  9964. */
  9965. if (plane->fb != fb) {
  9966. ret = intel_pin_and_fence_fb_obj(dev, obj, NULL);
  9967. if (ret) {
  9968. mutex_unlock(&dev->struct_mutex);
  9969. return ret;
  9970. }
  9971. }
  9972. i915_gem_track_fb(old_obj, obj,
  9973. INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe));
  9974. if (intel_crtc->primary_enabled)
  9975. intel_disable_primary_hw_plane(plane, crtc);
  9976. if (plane->fb != fb)
  9977. if (plane->fb)
  9978. intel_unpin_fb_obj(old_obj);
  9979. mutex_unlock(&dev->struct_mutex);
  9980. } else {
  9981. if (intel_crtc && intel_crtc->active &&
  9982. intel_crtc->primary_enabled) {
  9983. /*
  9984. * FBC does not work on some platforms for rotated
  9985. * planes, so disable it when rotation is not 0 and
  9986. * update it when rotation is set back to 0.
  9987. *
  9988. * FIXME: This is redundant with the fbc update done in
  9989. * the primary plane enable function except that that
  9990. * one is done too late. We eventually need to unify
  9991. * this.
  9992. */
  9993. if (INTEL_INFO(dev)->gen <= 4 && !IS_G4X(dev) &&
  9994. dev_priv->fbc.plane == intel_crtc->plane &&
  9995. intel_plane->rotation != BIT(DRM_ROTATE_0)) {
  9996. intel_disable_fbc(dev);
  9997. }
  9998. }
  9999. ret = intel_pipe_set_base(crtc, src.x1, src.y1, fb);
  10000. if (ret)
  10001. return ret;
  10002. if (!intel_crtc->primary_enabled)
  10003. intel_enable_primary_hw_plane(plane, crtc);
  10004. }
  10005. intel_plane->crtc_x = orig.crtc_x;
  10006. intel_plane->crtc_y = orig.crtc_y;
  10007. intel_plane->crtc_w = orig.crtc_w;
  10008. intel_plane->crtc_h = orig.crtc_h;
  10009. intel_plane->src_x = orig.src_x;
  10010. intel_plane->src_y = orig.src_y;
  10011. intel_plane->src_w = orig.src_w;
  10012. intel_plane->src_h = orig.src_h;
  10013. intel_plane->obj = obj;
  10014. return 0;
  10015. }
  10016. /* Common destruction function for both primary and cursor planes */
  10017. static void intel_plane_destroy(struct drm_plane *plane)
  10018. {
  10019. struct intel_plane *intel_plane = to_intel_plane(plane);
  10020. drm_plane_cleanup(plane);
  10021. kfree(intel_plane);
  10022. }
  10023. static const struct drm_plane_funcs intel_primary_plane_funcs = {
  10024. .update_plane = intel_primary_plane_setplane,
  10025. .disable_plane = intel_primary_plane_disable,
  10026. .destroy = intel_plane_destroy,
  10027. .set_property = intel_plane_set_property
  10028. };
  10029. static struct drm_plane *intel_primary_plane_create(struct drm_device *dev,
  10030. int pipe)
  10031. {
  10032. struct intel_plane *primary;
  10033. const uint32_t *intel_primary_formats;
  10034. int num_formats;
  10035. primary = kzalloc(sizeof(*primary), GFP_KERNEL);
  10036. if (primary == NULL)
  10037. return NULL;
  10038. primary->can_scale = false;
  10039. primary->max_downscale = 1;
  10040. primary->pipe = pipe;
  10041. primary->plane = pipe;
  10042. primary->rotation = BIT(DRM_ROTATE_0);
  10043. if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4)
  10044. primary->plane = !pipe;
  10045. if (INTEL_INFO(dev)->gen <= 3) {
  10046. intel_primary_formats = intel_primary_formats_gen2;
  10047. num_formats = ARRAY_SIZE(intel_primary_formats_gen2);
  10048. } else {
  10049. intel_primary_formats = intel_primary_formats_gen4;
  10050. num_formats = ARRAY_SIZE(intel_primary_formats_gen4);
  10051. }
  10052. drm_universal_plane_init(dev, &primary->base, 0,
  10053. &intel_primary_plane_funcs,
  10054. intel_primary_formats, num_formats,
  10055. DRM_PLANE_TYPE_PRIMARY);
  10056. if (INTEL_INFO(dev)->gen >= 4) {
  10057. if (!dev->mode_config.rotation_property)
  10058. dev->mode_config.rotation_property =
  10059. drm_mode_create_rotation_property(dev,
  10060. BIT(DRM_ROTATE_0) |
  10061. BIT(DRM_ROTATE_180));
  10062. if (dev->mode_config.rotation_property)
  10063. drm_object_attach_property(&primary->base.base,
  10064. dev->mode_config.rotation_property,
  10065. primary->rotation);
  10066. }
  10067. return &primary->base;
  10068. }
  10069. static int
  10070. intel_cursor_plane_disable(struct drm_plane *plane)
  10071. {
  10072. if (!plane->fb)
  10073. return 0;
  10074. BUG_ON(!plane->crtc);
  10075. return intel_crtc_cursor_set_obj(plane->crtc, NULL, 0, 0);
  10076. }
  10077. static int
  10078. intel_cursor_plane_update(struct drm_plane *plane, struct drm_crtc *crtc,
  10079. struct drm_framebuffer *fb, int crtc_x, int crtc_y,
  10080. unsigned int crtc_w, unsigned int crtc_h,
  10081. uint32_t src_x, uint32_t src_y,
  10082. uint32_t src_w, uint32_t src_h)
  10083. {
  10084. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  10085. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  10086. struct drm_i915_gem_object *obj = intel_fb->obj;
  10087. struct drm_rect dest = {
  10088. /* integer pixels */
  10089. .x1 = crtc_x,
  10090. .y1 = crtc_y,
  10091. .x2 = crtc_x + crtc_w,
  10092. .y2 = crtc_y + crtc_h,
  10093. };
  10094. struct drm_rect src = {
  10095. /* 16.16 fixed point */
  10096. .x1 = src_x,
  10097. .y1 = src_y,
  10098. .x2 = src_x + src_w,
  10099. .y2 = src_y + src_h,
  10100. };
  10101. const struct drm_rect clip = {
  10102. /* integer pixels */
  10103. .x2 = intel_crtc->active ? intel_crtc->config.pipe_src_w : 0,
  10104. .y2 = intel_crtc->active ? intel_crtc->config.pipe_src_h : 0,
  10105. };
  10106. bool visible;
  10107. int ret;
  10108. ret = drm_plane_helper_check_update(plane, crtc, fb,
  10109. &src, &dest, &clip,
  10110. DRM_PLANE_HELPER_NO_SCALING,
  10111. DRM_PLANE_HELPER_NO_SCALING,
  10112. true, true, &visible);
  10113. if (ret)
  10114. return ret;
  10115. crtc->cursor_x = crtc_x;
  10116. crtc->cursor_y = crtc_y;
  10117. if (fb != crtc->cursor->fb) {
  10118. return intel_crtc_cursor_set_obj(crtc, obj, crtc_w, crtc_h);
  10119. } else {
  10120. intel_crtc_update_cursor(crtc, visible);
  10121. intel_frontbuffer_flip(crtc->dev,
  10122. INTEL_FRONTBUFFER_CURSOR(intel_crtc->pipe));
  10123. return 0;
  10124. }
  10125. }
  10126. static const struct drm_plane_funcs intel_cursor_plane_funcs = {
  10127. .update_plane = intel_cursor_plane_update,
  10128. .disable_plane = intel_cursor_plane_disable,
  10129. .destroy = intel_plane_destroy,
  10130. };
  10131. static struct drm_plane *intel_cursor_plane_create(struct drm_device *dev,
  10132. int pipe)
  10133. {
  10134. struct intel_plane *cursor;
  10135. cursor = kzalloc(sizeof(*cursor), GFP_KERNEL);
  10136. if (cursor == NULL)
  10137. return NULL;
  10138. cursor->can_scale = false;
  10139. cursor->max_downscale = 1;
  10140. cursor->pipe = pipe;
  10141. cursor->plane = pipe;
  10142. drm_universal_plane_init(dev, &cursor->base, 0,
  10143. &intel_cursor_plane_funcs,
  10144. intel_cursor_formats,
  10145. ARRAY_SIZE(intel_cursor_formats),
  10146. DRM_PLANE_TYPE_CURSOR);
  10147. return &cursor->base;
  10148. }
  10149. static void intel_crtc_init(struct drm_device *dev, int pipe)
  10150. {
  10151. struct drm_i915_private *dev_priv = dev->dev_private;
  10152. struct intel_crtc *intel_crtc;
  10153. struct drm_plane *primary = NULL;
  10154. struct drm_plane *cursor = NULL;
  10155. int i, ret;
  10156. intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL);
  10157. if (intel_crtc == NULL)
  10158. return;
  10159. primary = intel_primary_plane_create(dev, pipe);
  10160. if (!primary)
  10161. goto fail;
  10162. cursor = intel_cursor_plane_create(dev, pipe);
  10163. if (!cursor)
  10164. goto fail;
  10165. ret = drm_crtc_init_with_planes(dev, &intel_crtc->base, primary,
  10166. cursor, &intel_crtc_funcs);
  10167. if (ret)
  10168. goto fail;
  10169. drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256);
  10170. for (i = 0; i < 256; i++) {
  10171. intel_crtc->lut_r[i] = i;
  10172. intel_crtc->lut_g[i] = i;
  10173. intel_crtc->lut_b[i] = i;
  10174. }
  10175. /*
  10176. * On gen2/3 only plane A can do fbc, but the panel fitter and lvds port
  10177. * is hooked to pipe B. Hence we want plane A feeding pipe B.
  10178. */
  10179. intel_crtc->pipe = pipe;
  10180. intel_crtc->plane = pipe;
  10181. if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) {
  10182. DRM_DEBUG_KMS("swapping pipes & planes for FBC\n");
  10183. intel_crtc->plane = !pipe;
  10184. }
  10185. intel_crtc->cursor_base = ~0;
  10186. intel_crtc->cursor_cntl = ~0;
  10187. intel_crtc->cursor_size = ~0;
  10188. BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
  10189. dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL);
  10190. dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base;
  10191. dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base;
  10192. drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
  10193. WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe);
  10194. return;
  10195. fail:
  10196. if (primary)
  10197. drm_plane_cleanup(primary);
  10198. if (cursor)
  10199. drm_plane_cleanup(cursor);
  10200. kfree(intel_crtc);
  10201. }
  10202. enum pipe intel_get_pipe_from_connector(struct intel_connector *connector)
  10203. {
  10204. struct drm_encoder *encoder = connector->base.encoder;
  10205. struct drm_device *dev = connector->base.dev;
  10206. WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
  10207. if (!encoder)
  10208. return INVALID_PIPE;
  10209. return to_intel_crtc(encoder->crtc)->pipe;
  10210. }
  10211. int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data,
  10212. struct drm_file *file)
  10213. {
  10214. struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
  10215. struct drm_crtc *drmmode_crtc;
  10216. struct intel_crtc *crtc;
  10217. if (!drm_core_check_feature(dev, DRIVER_MODESET))
  10218. return -ENODEV;
  10219. drmmode_crtc = drm_crtc_find(dev, pipe_from_crtc_id->crtc_id);
  10220. if (!drmmode_crtc) {
  10221. DRM_ERROR("no such CRTC id\n");
  10222. return -ENOENT;
  10223. }
  10224. crtc = to_intel_crtc(drmmode_crtc);
  10225. pipe_from_crtc_id->pipe = crtc->pipe;
  10226. return 0;
  10227. }
  10228. static int intel_encoder_clones(struct intel_encoder *encoder)
  10229. {
  10230. struct drm_device *dev = encoder->base.dev;
  10231. struct intel_encoder *source_encoder;
  10232. int index_mask = 0;
  10233. int entry = 0;
  10234. for_each_intel_encoder(dev, source_encoder) {
  10235. if (encoders_cloneable(encoder, source_encoder))
  10236. index_mask |= (1 << entry);
  10237. entry++;
  10238. }
  10239. return index_mask;
  10240. }
  10241. static bool has_edp_a(struct drm_device *dev)
  10242. {
  10243. struct drm_i915_private *dev_priv = dev->dev_private;
  10244. if (!IS_MOBILE(dev))
  10245. return false;
  10246. if ((I915_READ(DP_A) & DP_DETECTED) == 0)
  10247. return false;
  10248. if (IS_GEN5(dev) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE))
  10249. return false;
  10250. return true;
  10251. }
  10252. const char *intel_output_name(int output)
  10253. {
  10254. static const char *names[] = {
  10255. [INTEL_OUTPUT_UNUSED] = "Unused",
  10256. [INTEL_OUTPUT_ANALOG] = "Analog",
  10257. [INTEL_OUTPUT_DVO] = "DVO",
  10258. [INTEL_OUTPUT_SDVO] = "SDVO",
  10259. [INTEL_OUTPUT_LVDS] = "LVDS",
  10260. [INTEL_OUTPUT_TVOUT] = "TV",
  10261. [INTEL_OUTPUT_HDMI] = "HDMI",
  10262. [INTEL_OUTPUT_DISPLAYPORT] = "DisplayPort",
  10263. [INTEL_OUTPUT_EDP] = "eDP",
  10264. [INTEL_OUTPUT_DSI] = "DSI",
  10265. [INTEL_OUTPUT_UNKNOWN] = "Unknown",
  10266. };
  10267. if (output < 0 || output >= ARRAY_SIZE(names) || !names[output])
  10268. return "Invalid";
  10269. return names[output];
  10270. }
  10271. static bool intel_crt_present(struct drm_device *dev)
  10272. {
  10273. struct drm_i915_private *dev_priv = dev->dev_private;
  10274. if (IS_ULT(dev))
  10275. return false;
  10276. if (IS_CHERRYVIEW(dev))
  10277. return false;
  10278. if (IS_VALLEYVIEW(dev) && !dev_priv->vbt.int_crt_support)
  10279. return false;
  10280. return true;
  10281. }
  10282. static void intel_setup_outputs(struct drm_device *dev)
  10283. {
  10284. struct drm_i915_private *dev_priv = dev->dev_private;
  10285. struct intel_encoder *encoder;
  10286. bool dpd_is_edp = false;
  10287. intel_lvds_init(dev);
  10288. if (intel_crt_present(dev))
  10289. intel_crt_init(dev);
  10290. if (HAS_DDI(dev)) {
  10291. int found;
  10292. /* Haswell uses DDI functions to detect digital outputs */
  10293. found = I915_READ(DDI_BUF_CTL_A) & DDI_INIT_DISPLAY_DETECTED;
  10294. /* DDI A only supports eDP */
  10295. if (found)
  10296. intel_ddi_init(dev, PORT_A);
  10297. /* DDI B, C and D detection is indicated by the SFUSE_STRAP
  10298. * register */
  10299. found = I915_READ(SFUSE_STRAP);
  10300. if (found & SFUSE_STRAP_DDIB_DETECTED)
  10301. intel_ddi_init(dev, PORT_B);
  10302. if (found & SFUSE_STRAP_DDIC_DETECTED)
  10303. intel_ddi_init(dev, PORT_C);
  10304. if (found & SFUSE_STRAP_DDID_DETECTED)
  10305. intel_ddi_init(dev, PORT_D);
  10306. } else if (HAS_PCH_SPLIT(dev)) {
  10307. int found;
  10308. dpd_is_edp = intel_dp_is_edp(dev, PORT_D);
  10309. if (has_edp_a(dev))
  10310. intel_dp_init(dev, DP_A, PORT_A);
  10311. if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) {
  10312. /* PCH SDVOB multiplex with HDMIB */
  10313. found = intel_sdvo_init(dev, PCH_SDVOB, true);
  10314. if (!found)
  10315. intel_hdmi_init(dev, PCH_HDMIB, PORT_B);
  10316. if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
  10317. intel_dp_init(dev, PCH_DP_B, PORT_B);
  10318. }
  10319. if (I915_READ(PCH_HDMIC) & SDVO_DETECTED)
  10320. intel_hdmi_init(dev, PCH_HDMIC, PORT_C);
  10321. if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED)
  10322. intel_hdmi_init(dev, PCH_HDMID, PORT_D);
  10323. if (I915_READ(PCH_DP_C) & DP_DETECTED)
  10324. intel_dp_init(dev, PCH_DP_C, PORT_C);
  10325. if (I915_READ(PCH_DP_D) & DP_DETECTED)
  10326. intel_dp_init(dev, PCH_DP_D, PORT_D);
  10327. } else if (IS_VALLEYVIEW(dev)) {
  10328. /*
  10329. * The DP_DETECTED bit is the latched state of the DDC
  10330. * SDA pin at boot. However since eDP doesn't require DDC
  10331. * (no way to plug in a DP->HDMI dongle) the DDC pins for
  10332. * eDP ports may have been muxed to an alternate function.
  10333. * Thus we can't rely on the DP_DETECTED bit alone to detect
  10334. * eDP ports. Consult the VBT as well as DP_DETECTED to
  10335. * detect eDP ports.
  10336. */
  10337. if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIB) & SDVO_DETECTED)
  10338. intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIB,
  10339. PORT_B);
  10340. if (I915_READ(VLV_DISPLAY_BASE + DP_B) & DP_DETECTED ||
  10341. intel_dp_is_edp(dev, PORT_B))
  10342. intel_dp_init(dev, VLV_DISPLAY_BASE + DP_B, PORT_B);
  10343. if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIC) & SDVO_DETECTED)
  10344. intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIC,
  10345. PORT_C);
  10346. if (I915_READ(VLV_DISPLAY_BASE + DP_C) & DP_DETECTED ||
  10347. intel_dp_is_edp(dev, PORT_C))
  10348. intel_dp_init(dev, VLV_DISPLAY_BASE + DP_C, PORT_C);
  10349. if (IS_CHERRYVIEW(dev)) {
  10350. if (I915_READ(VLV_DISPLAY_BASE + CHV_HDMID) & SDVO_DETECTED)
  10351. intel_hdmi_init(dev, VLV_DISPLAY_BASE + CHV_HDMID,
  10352. PORT_D);
  10353. /* eDP not supported on port D, so don't check VBT */
  10354. if (I915_READ(VLV_DISPLAY_BASE + DP_D) & DP_DETECTED)
  10355. intel_dp_init(dev, VLV_DISPLAY_BASE + DP_D, PORT_D);
  10356. }
  10357. intel_dsi_init(dev);
  10358. } else if (SUPPORTS_DIGITAL_OUTPUTS(dev)) {
  10359. bool found = false;
  10360. if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
  10361. DRM_DEBUG_KMS("probing SDVOB\n");
  10362. found = intel_sdvo_init(dev, GEN3_SDVOB, true);
  10363. if (!found && SUPPORTS_INTEGRATED_HDMI(dev)) {
  10364. DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
  10365. intel_hdmi_init(dev, GEN4_HDMIB, PORT_B);
  10366. }
  10367. if (!found && SUPPORTS_INTEGRATED_DP(dev))
  10368. intel_dp_init(dev, DP_B, PORT_B);
  10369. }
  10370. /* Before G4X SDVOC doesn't have its own detect register */
  10371. if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
  10372. DRM_DEBUG_KMS("probing SDVOC\n");
  10373. found = intel_sdvo_init(dev, GEN3_SDVOC, false);
  10374. }
  10375. if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) {
  10376. if (SUPPORTS_INTEGRATED_HDMI(dev)) {
  10377. DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
  10378. intel_hdmi_init(dev, GEN4_HDMIC, PORT_C);
  10379. }
  10380. if (SUPPORTS_INTEGRATED_DP(dev))
  10381. intel_dp_init(dev, DP_C, PORT_C);
  10382. }
  10383. if (SUPPORTS_INTEGRATED_DP(dev) &&
  10384. (I915_READ(DP_D) & DP_DETECTED))
  10385. intel_dp_init(dev, DP_D, PORT_D);
  10386. } else if (IS_GEN2(dev))
  10387. intel_dvo_init(dev);
  10388. if (SUPPORTS_TV(dev))
  10389. intel_tv_init(dev);
  10390. intel_edp_psr_init(dev);
  10391. for_each_intel_encoder(dev, encoder) {
  10392. encoder->base.possible_crtcs = encoder->crtc_mask;
  10393. encoder->base.possible_clones =
  10394. intel_encoder_clones(encoder);
  10395. }
  10396. intel_init_pch_refclk(dev);
  10397. drm_helper_move_panel_connectors_to_head(dev);
  10398. }
  10399. static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
  10400. {
  10401. struct drm_device *dev = fb->dev;
  10402. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  10403. drm_framebuffer_cleanup(fb);
  10404. mutex_lock(&dev->struct_mutex);
  10405. WARN_ON(!intel_fb->obj->framebuffer_references--);
  10406. drm_gem_object_unreference(&intel_fb->obj->base);
  10407. mutex_unlock(&dev->struct_mutex);
  10408. kfree(intel_fb);
  10409. }
  10410. static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
  10411. struct drm_file *file,
  10412. unsigned int *handle)
  10413. {
  10414. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  10415. struct drm_i915_gem_object *obj = intel_fb->obj;
  10416. return drm_gem_handle_create(file, &obj->base, handle);
  10417. }
  10418. static const struct drm_framebuffer_funcs intel_fb_funcs = {
  10419. .destroy = intel_user_framebuffer_destroy,
  10420. .create_handle = intel_user_framebuffer_create_handle,
  10421. };
  10422. static int intel_framebuffer_init(struct drm_device *dev,
  10423. struct intel_framebuffer *intel_fb,
  10424. struct drm_mode_fb_cmd2 *mode_cmd,
  10425. struct drm_i915_gem_object *obj)
  10426. {
  10427. int aligned_height;
  10428. int pitch_limit;
  10429. int ret;
  10430. WARN_ON(!mutex_is_locked(&dev->struct_mutex));
  10431. if (obj->tiling_mode == I915_TILING_Y) {
  10432. DRM_DEBUG("hardware does not support tiling Y\n");
  10433. return -EINVAL;
  10434. }
  10435. if (mode_cmd->pitches[0] & 63) {
  10436. DRM_DEBUG("pitch (%d) must be at least 64 byte aligned\n",
  10437. mode_cmd->pitches[0]);
  10438. return -EINVAL;
  10439. }
  10440. if (INTEL_INFO(dev)->gen >= 5 && !IS_VALLEYVIEW(dev)) {
  10441. pitch_limit = 32*1024;
  10442. } else if (INTEL_INFO(dev)->gen >= 4) {
  10443. if (obj->tiling_mode)
  10444. pitch_limit = 16*1024;
  10445. else
  10446. pitch_limit = 32*1024;
  10447. } else if (INTEL_INFO(dev)->gen >= 3) {
  10448. if (obj->tiling_mode)
  10449. pitch_limit = 8*1024;
  10450. else
  10451. pitch_limit = 16*1024;
  10452. } else
  10453. /* XXX DSPC is limited to 4k tiled */
  10454. pitch_limit = 8*1024;
  10455. if (mode_cmd->pitches[0] > pitch_limit) {
  10456. DRM_DEBUG("%s pitch (%d) must be at less than %d\n",
  10457. obj->tiling_mode ? "tiled" : "linear",
  10458. mode_cmd->pitches[0], pitch_limit);
  10459. return -EINVAL;
  10460. }
  10461. if (obj->tiling_mode != I915_TILING_NONE &&
  10462. mode_cmd->pitches[0] != obj->stride) {
  10463. DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n",
  10464. mode_cmd->pitches[0], obj->stride);
  10465. return -EINVAL;
  10466. }
  10467. /* Reject formats not supported by any plane early. */
  10468. switch (mode_cmd->pixel_format) {
  10469. case DRM_FORMAT_C8:
  10470. case DRM_FORMAT_RGB565:
  10471. case DRM_FORMAT_XRGB8888:
  10472. case DRM_FORMAT_ARGB8888:
  10473. break;
  10474. case DRM_FORMAT_XRGB1555:
  10475. case DRM_FORMAT_ARGB1555:
  10476. if (INTEL_INFO(dev)->gen > 3) {
  10477. DRM_DEBUG("unsupported pixel format: %s\n",
  10478. drm_get_format_name(mode_cmd->pixel_format));
  10479. return -EINVAL;
  10480. }
  10481. break;
  10482. case DRM_FORMAT_XBGR8888:
  10483. case DRM_FORMAT_ABGR8888:
  10484. case DRM_FORMAT_XRGB2101010:
  10485. case DRM_FORMAT_ARGB2101010:
  10486. case DRM_FORMAT_XBGR2101010:
  10487. case DRM_FORMAT_ABGR2101010:
  10488. if (INTEL_INFO(dev)->gen < 4) {
  10489. DRM_DEBUG("unsupported pixel format: %s\n",
  10490. drm_get_format_name(mode_cmd->pixel_format));
  10491. return -EINVAL;
  10492. }
  10493. break;
  10494. case DRM_FORMAT_YUYV:
  10495. case DRM_FORMAT_UYVY:
  10496. case DRM_FORMAT_YVYU:
  10497. case DRM_FORMAT_VYUY:
  10498. if (INTEL_INFO(dev)->gen < 5) {
  10499. DRM_DEBUG("unsupported pixel format: %s\n",
  10500. drm_get_format_name(mode_cmd->pixel_format));
  10501. return -EINVAL;
  10502. }
  10503. break;
  10504. default:
  10505. DRM_DEBUG("unsupported pixel format: %s\n",
  10506. drm_get_format_name(mode_cmd->pixel_format));
  10507. return -EINVAL;
  10508. }
  10509. /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
  10510. if (mode_cmd->offsets[0] != 0)
  10511. return -EINVAL;
  10512. aligned_height = intel_align_height(dev, mode_cmd->height,
  10513. obj->tiling_mode);
  10514. /* FIXME drm helper for size checks (especially planar formats)? */
  10515. if (obj->base.size < aligned_height * mode_cmd->pitches[0])
  10516. return -EINVAL;
  10517. drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd);
  10518. intel_fb->obj = obj;
  10519. intel_fb->obj->framebuffer_references++;
  10520. ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs);
  10521. if (ret) {
  10522. DRM_ERROR("framebuffer init failed %d\n", ret);
  10523. return ret;
  10524. }
  10525. return 0;
  10526. }
  10527. static struct drm_framebuffer *
  10528. intel_user_framebuffer_create(struct drm_device *dev,
  10529. struct drm_file *filp,
  10530. struct drm_mode_fb_cmd2 *mode_cmd)
  10531. {
  10532. struct drm_i915_gem_object *obj;
  10533. obj = to_intel_bo(drm_gem_object_lookup(dev, filp,
  10534. mode_cmd->handles[0]));
  10535. if (&obj->base == NULL)
  10536. return ERR_PTR(-ENOENT);
  10537. return intel_framebuffer_create(dev, mode_cmd, obj);
  10538. }
  10539. #ifndef CONFIG_DRM_I915_FBDEV
  10540. static inline void intel_fbdev_output_poll_changed(struct drm_device *dev)
  10541. {
  10542. }
  10543. #endif
  10544. static const struct drm_mode_config_funcs intel_mode_funcs = {
  10545. .fb_create = intel_user_framebuffer_create,
  10546. .output_poll_changed = intel_fbdev_output_poll_changed,
  10547. };
  10548. /* Set up chip specific display functions */
  10549. static void intel_init_display(struct drm_device *dev)
  10550. {
  10551. struct drm_i915_private *dev_priv = dev->dev_private;
  10552. if (HAS_PCH_SPLIT(dev) || IS_G4X(dev))
  10553. dev_priv->display.find_dpll = g4x_find_best_dpll;
  10554. else if (IS_CHERRYVIEW(dev))
  10555. dev_priv->display.find_dpll = chv_find_best_dpll;
  10556. else if (IS_VALLEYVIEW(dev))
  10557. dev_priv->display.find_dpll = vlv_find_best_dpll;
  10558. else if (IS_PINEVIEW(dev))
  10559. dev_priv->display.find_dpll = pnv_find_best_dpll;
  10560. else
  10561. dev_priv->display.find_dpll = i9xx_find_best_dpll;
  10562. if (HAS_DDI(dev)) {
  10563. dev_priv->display.get_pipe_config = haswell_get_pipe_config;
  10564. dev_priv->display.get_plane_config = ironlake_get_plane_config;
  10565. dev_priv->display.crtc_mode_set = haswell_crtc_mode_set;
  10566. dev_priv->display.crtc_enable = haswell_crtc_enable;
  10567. dev_priv->display.crtc_disable = haswell_crtc_disable;
  10568. dev_priv->display.off = ironlake_crtc_off;
  10569. dev_priv->display.update_primary_plane =
  10570. ironlake_update_primary_plane;
  10571. } else if (HAS_PCH_SPLIT(dev)) {
  10572. dev_priv->display.get_pipe_config = ironlake_get_pipe_config;
  10573. dev_priv->display.get_plane_config = ironlake_get_plane_config;
  10574. dev_priv->display.crtc_mode_set = ironlake_crtc_mode_set;
  10575. dev_priv->display.crtc_enable = ironlake_crtc_enable;
  10576. dev_priv->display.crtc_disable = ironlake_crtc_disable;
  10577. dev_priv->display.off = ironlake_crtc_off;
  10578. dev_priv->display.update_primary_plane =
  10579. ironlake_update_primary_plane;
  10580. } else if (IS_VALLEYVIEW(dev)) {
  10581. dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
  10582. dev_priv->display.get_plane_config = i9xx_get_plane_config;
  10583. dev_priv->display.crtc_mode_set = i9xx_crtc_mode_set;
  10584. dev_priv->display.crtc_enable = valleyview_crtc_enable;
  10585. dev_priv->display.crtc_disable = i9xx_crtc_disable;
  10586. dev_priv->display.off = i9xx_crtc_off;
  10587. dev_priv->display.update_primary_plane =
  10588. i9xx_update_primary_plane;
  10589. } else {
  10590. dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
  10591. dev_priv->display.get_plane_config = i9xx_get_plane_config;
  10592. dev_priv->display.crtc_mode_set = i9xx_crtc_mode_set;
  10593. dev_priv->display.crtc_enable = i9xx_crtc_enable;
  10594. dev_priv->display.crtc_disable = i9xx_crtc_disable;
  10595. dev_priv->display.off = i9xx_crtc_off;
  10596. dev_priv->display.update_primary_plane =
  10597. i9xx_update_primary_plane;
  10598. }
  10599. /* Returns the core display clock speed */
  10600. if (IS_VALLEYVIEW(dev))
  10601. dev_priv->display.get_display_clock_speed =
  10602. valleyview_get_display_clock_speed;
  10603. else if (IS_I945G(dev) || (IS_G33(dev) && !IS_PINEVIEW_M(dev)))
  10604. dev_priv->display.get_display_clock_speed =
  10605. i945_get_display_clock_speed;
  10606. else if (IS_I915G(dev))
  10607. dev_priv->display.get_display_clock_speed =
  10608. i915_get_display_clock_speed;
  10609. else if (IS_I945GM(dev) || IS_845G(dev))
  10610. dev_priv->display.get_display_clock_speed =
  10611. i9xx_misc_get_display_clock_speed;
  10612. else if (IS_PINEVIEW(dev))
  10613. dev_priv->display.get_display_clock_speed =
  10614. pnv_get_display_clock_speed;
  10615. else if (IS_I915GM(dev))
  10616. dev_priv->display.get_display_clock_speed =
  10617. i915gm_get_display_clock_speed;
  10618. else if (IS_I865G(dev))
  10619. dev_priv->display.get_display_clock_speed =
  10620. i865_get_display_clock_speed;
  10621. else if (IS_I85X(dev))
  10622. dev_priv->display.get_display_clock_speed =
  10623. i855_get_display_clock_speed;
  10624. else /* 852, 830 */
  10625. dev_priv->display.get_display_clock_speed =
  10626. i830_get_display_clock_speed;
  10627. if (IS_G4X(dev)) {
  10628. dev_priv->display.write_eld = g4x_write_eld;
  10629. } else if (IS_GEN5(dev)) {
  10630. dev_priv->display.fdi_link_train = ironlake_fdi_link_train;
  10631. dev_priv->display.write_eld = ironlake_write_eld;
  10632. } else if (IS_GEN6(dev)) {
  10633. dev_priv->display.fdi_link_train = gen6_fdi_link_train;
  10634. dev_priv->display.write_eld = ironlake_write_eld;
  10635. dev_priv->display.modeset_global_resources =
  10636. snb_modeset_global_resources;
  10637. } else if (IS_IVYBRIDGE(dev)) {
  10638. /* FIXME: detect B0+ stepping and use auto training */
  10639. dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train;
  10640. dev_priv->display.write_eld = ironlake_write_eld;
  10641. dev_priv->display.modeset_global_resources =
  10642. ivb_modeset_global_resources;
  10643. } else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
  10644. dev_priv->display.fdi_link_train = hsw_fdi_link_train;
  10645. dev_priv->display.write_eld = haswell_write_eld;
  10646. dev_priv->display.modeset_global_resources =
  10647. haswell_modeset_global_resources;
  10648. } else if (IS_VALLEYVIEW(dev)) {
  10649. dev_priv->display.modeset_global_resources =
  10650. valleyview_modeset_global_resources;
  10651. dev_priv->display.write_eld = ironlake_write_eld;
  10652. }
  10653. /* Default just returns -ENODEV to indicate unsupported */
  10654. dev_priv->display.queue_flip = intel_default_queue_flip;
  10655. switch (INTEL_INFO(dev)->gen) {
  10656. case 2:
  10657. dev_priv->display.queue_flip = intel_gen2_queue_flip;
  10658. break;
  10659. case 3:
  10660. dev_priv->display.queue_flip = intel_gen3_queue_flip;
  10661. break;
  10662. case 4:
  10663. case 5:
  10664. dev_priv->display.queue_flip = intel_gen4_queue_flip;
  10665. break;
  10666. case 6:
  10667. dev_priv->display.queue_flip = intel_gen6_queue_flip;
  10668. break;
  10669. case 7:
  10670. case 8: /* FIXME(BDW): Check that the gen8 RCS flip works. */
  10671. dev_priv->display.queue_flip = intel_gen7_queue_flip;
  10672. break;
  10673. }
  10674. intel_panel_init_backlight_funcs(dev);
  10675. mutex_init(&dev_priv->pps_mutex);
  10676. }
  10677. /*
  10678. * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend,
  10679. * resume, or other times. This quirk makes sure that's the case for
  10680. * affected systems.
  10681. */
  10682. static void quirk_pipea_force(struct drm_device *dev)
  10683. {
  10684. struct drm_i915_private *dev_priv = dev->dev_private;
  10685. dev_priv->quirks |= QUIRK_PIPEA_FORCE;
  10686. DRM_INFO("applying pipe a force quirk\n");
  10687. }
  10688. static void quirk_pipeb_force(struct drm_device *dev)
  10689. {
  10690. struct drm_i915_private *dev_priv = dev->dev_private;
  10691. dev_priv->quirks |= QUIRK_PIPEB_FORCE;
  10692. DRM_INFO("applying pipe b force quirk\n");
  10693. }
  10694. /*
  10695. * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason
  10696. */
  10697. static void quirk_ssc_force_disable(struct drm_device *dev)
  10698. {
  10699. struct drm_i915_private *dev_priv = dev->dev_private;
  10700. dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE;
  10701. DRM_INFO("applying lvds SSC disable quirk\n");
  10702. }
  10703. /*
  10704. * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight
  10705. * brightness value
  10706. */
  10707. static void quirk_invert_brightness(struct drm_device *dev)
  10708. {
  10709. struct drm_i915_private *dev_priv = dev->dev_private;
  10710. dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS;
  10711. DRM_INFO("applying inverted panel brightness quirk\n");
  10712. }
  10713. /* Some VBT's incorrectly indicate no backlight is present */
  10714. static void quirk_backlight_present(struct drm_device *dev)
  10715. {
  10716. struct drm_i915_private *dev_priv = dev->dev_private;
  10717. dev_priv->quirks |= QUIRK_BACKLIGHT_PRESENT;
  10718. DRM_INFO("applying backlight present quirk\n");
  10719. }
  10720. struct intel_quirk {
  10721. int device;
  10722. int subsystem_vendor;
  10723. int subsystem_device;
  10724. void (*hook)(struct drm_device *dev);
  10725. };
  10726. /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
  10727. struct intel_dmi_quirk {
  10728. void (*hook)(struct drm_device *dev);
  10729. const struct dmi_system_id (*dmi_id_list)[];
  10730. };
  10731. static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
  10732. {
  10733. DRM_INFO("Backlight polarity reversed on %s\n", id->ident);
  10734. return 1;
  10735. }
  10736. static const struct intel_dmi_quirk intel_dmi_quirks[] = {
  10737. {
  10738. .dmi_id_list = &(const struct dmi_system_id[]) {
  10739. {
  10740. .callback = intel_dmi_reverse_brightness,
  10741. .ident = "NCR Corporation",
  10742. .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
  10743. DMI_MATCH(DMI_PRODUCT_NAME, ""),
  10744. },
  10745. },
  10746. { } /* terminating entry */
  10747. },
  10748. .hook = quirk_invert_brightness,
  10749. },
  10750. };
  10751. static struct intel_quirk intel_quirks[] = {
  10752. /* HP Mini needs pipe A force quirk (LP: #322104) */
  10753. { 0x27ae, 0x103c, 0x361a, quirk_pipea_force },
  10754. /* Toshiba Protege R-205, S-209 needs pipe A force quirk */
  10755. { 0x2592, 0x1179, 0x0001, quirk_pipea_force },
  10756. /* ThinkPad T60 needs pipe A force quirk (bug #16494) */
  10757. { 0x2782, 0x17aa, 0x201a, quirk_pipea_force },
  10758. /* 830 needs to leave pipe A & dpll A up */
  10759. { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force },
  10760. /* 830 needs to leave pipe B & dpll B up */
  10761. { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipeb_force },
  10762. /* Lenovo U160 cannot use SSC on LVDS */
  10763. { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable },
  10764. /* Sony Vaio Y cannot use SSC on LVDS */
  10765. { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable },
  10766. /* Acer Aspire 5734Z must invert backlight brightness */
  10767. { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness },
  10768. /* Acer/eMachines G725 */
  10769. { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness },
  10770. /* Acer/eMachines e725 */
  10771. { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness },
  10772. /* Acer/Packard Bell NCL20 */
  10773. { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness },
  10774. /* Acer Aspire 4736Z */
  10775. { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness },
  10776. /* Acer Aspire 5336 */
  10777. { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness },
  10778. /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */
  10779. { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present },
  10780. /* Acer C720 Chromebook (Core i3 4005U) */
  10781. { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present },
  10782. /* Apple Macbook 2,1 (Core 2 T7400) */
  10783. { 0x27a2, 0x8086, 0x7270, quirk_backlight_present },
  10784. /* Toshiba CB35 Chromebook (Celeron 2955U) */
  10785. { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present },
  10786. /* HP Chromebook 14 (Celeron 2955U) */
  10787. { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present },
  10788. };
  10789. static void intel_init_quirks(struct drm_device *dev)
  10790. {
  10791. struct pci_dev *d = dev->pdev;
  10792. int i;
  10793. for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) {
  10794. struct intel_quirk *q = &intel_quirks[i];
  10795. if (d->device == q->device &&
  10796. (d->subsystem_vendor == q->subsystem_vendor ||
  10797. q->subsystem_vendor == PCI_ANY_ID) &&
  10798. (d->subsystem_device == q->subsystem_device ||
  10799. q->subsystem_device == PCI_ANY_ID))
  10800. q->hook(dev);
  10801. }
  10802. for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) {
  10803. if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0)
  10804. intel_dmi_quirks[i].hook(dev);
  10805. }
  10806. }
  10807. /* Disable the VGA plane that we never use */
  10808. static void i915_disable_vga(struct drm_device *dev)
  10809. {
  10810. struct drm_i915_private *dev_priv = dev->dev_private;
  10811. u8 sr1;
  10812. u32 vga_reg = i915_vgacntrl_reg(dev);
  10813. /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
  10814. vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO);
  10815. outb(SR01, VGA_SR_INDEX);
  10816. sr1 = inb(VGA_SR_DATA);
  10817. outb(sr1 | 1<<5, VGA_SR_DATA);
  10818. vga_put(dev->pdev, VGA_RSRC_LEGACY_IO);
  10819. udelay(300);
  10820. /*
  10821. * Fujitsu-Siemens Lifebook S6010 (830) has problems resuming
  10822. * from S3 without preserving (some of?) the other bits.
  10823. */
  10824. I915_WRITE(vga_reg, dev_priv->bios_vgacntr | VGA_DISP_DISABLE);
  10825. POSTING_READ(vga_reg);
  10826. }
  10827. void intel_modeset_init_hw(struct drm_device *dev)
  10828. {
  10829. intel_prepare_ddi(dev);
  10830. if (IS_VALLEYVIEW(dev))
  10831. vlv_update_cdclk(dev);
  10832. intel_init_clock_gating(dev);
  10833. intel_enable_gt_powersave(dev);
  10834. }
  10835. void intel_modeset_suspend_hw(struct drm_device *dev)
  10836. {
  10837. intel_suspend_hw(dev);
  10838. }
  10839. void intel_modeset_init(struct drm_device *dev)
  10840. {
  10841. struct drm_i915_private *dev_priv = dev->dev_private;
  10842. int sprite, ret;
  10843. enum pipe pipe;
  10844. struct intel_crtc *crtc;
  10845. drm_mode_config_init(dev);
  10846. dev->mode_config.min_width = 0;
  10847. dev->mode_config.min_height = 0;
  10848. dev->mode_config.preferred_depth = 24;
  10849. dev->mode_config.prefer_shadow = 1;
  10850. dev->mode_config.funcs = &intel_mode_funcs;
  10851. intel_init_quirks(dev);
  10852. intel_init_pm(dev);
  10853. if (INTEL_INFO(dev)->num_pipes == 0)
  10854. return;
  10855. intel_init_display(dev);
  10856. if (IS_GEN2(dev)) {
  10857. dev->mode_config.max_width = 2048;
  10858. dev->mode_config.max_height = 2048;
  10859. } else if (IS_GEN3(dev)) {
  10860. dev->mode_config.max_width = 4096;
  10861. dev->mode_config.max_height = 4096;
  10862. } else {
  10863. dev->mode_config.max_width = 8192;
  10864. dev->mode_config.max_height = 8192;
  10865. }
  10866. if (IS_845G(dev) || IS_I865G(dev)) {
  10867. dev->mode_config.cursor_width = IS_845G(dev) ? 64 : 512;
  10868. dev->mode_config.cursor_height = 1023;
  10869. } else if (IS_GEN2(dev)) {
  10870. dev->mode_config.cursor_width = GEN2_CURSOR_WIDTH;
  10871. dev->mode_config.cursor_height = GEN2_CURSOR_HEIGHT;
  10872. } else {
  10873. dev->mode_config.cursor_width = MAX_CURSOR_WIDTH;
  10874. dev->mode_config.cursor_height = MAX_CURSOR_HEIGHT;
  10875. }
  10876. dev->mode_config.fb_base = dev_priv->gtt.mappable_base;
  10877. DRM_DEBUG_KMS("%d display pipe%s available.\n",
  10878. INTEL_INFO(dev)->num_pipes,
  10879. INTEL_INFO(dev)->num_pipes > 1 ? "s" : "");
  10880. for_each_pipe(dev_priv, pipe) {
  10881. intel_crtc_init(dev, pipe);
  10882. for_each_sprite(pipe, sprite) {
  10883. ret = intel_plane_init(dev, pipe, sprite);
  10884. if (ret)
  10885. DRM_DEBUG_KMS("pipe %c sprite %c init failed: %d\n",
  10886. pipe_name(pipe), sprite_name(pipe, sprite), ret);
  10887. }
  10888. }
  10889. intel_init_dpio(dev);
  10890. intel_shared_dpll_init(dev);
  10891. /* save the BIOS value before clobbering it */
  10892. dev_priv->bios_vgacntr = I915_READ(i915_vgacntrl_reg(dev));
  10893. /* Just disable it once at startup */
  10894. i915_disable_vga(dev);
  10895. intel_setup_outputs(dev);
  10896. /* Just in case the BIOS is doing something questionable. */
  10897. intel_disable_fbc(dev);
  10898. drm_modeset_lock_all(dev);
  10899. intel_modeset_setup_hw_state(dev, false);
  10900. drm_modeset_unlock_all(dev);
  10901. for_each_intel_crtc(dev, crtc) {
  10902. if (!crtc->active)
  10903. continue;
  10904. /*
  10905. * Note that reserving the BIOS fb up front prevents us
  10906. * from stuffing other stolen allocations like the ring
  10907. * on top. This prevents some ugliness at boot time, and
  10908. * can even allow for smooth boot transitions if the BIOS
  10909. * fb is large enough for the active pipe configuration.
  10910. */
  10911. if (dev_priv->display.get_plane_config) {
  10912. dev_priv->display.get_plane_config(crtc,
  10913. &crtc->plane_config);
  10914. /*
  10915. * If the fb is shared between multiple heads, we'll
  10916. * just get the first one.
  10917. */
  10918. intel_find_plane_obj(crtc, &crtc->plane_config);
  10919. }
  10920. }
  10921. }
  10922. static void intel_enable_pipe_a(struct drm_device *dev)
  10923. {
  10924. struct intel_connector *connector;
  10925. struct drm_connector *crt = NULL;
  10926. struct intel_load_detect_pipe load_detect_temp;
  10927. struct drm_modeset_acquire_ctx *ctx = dev->mode_config.acquire_ctx;
  10928. /* We can't just switch on the pipe A, we need to set things up with a
  10929. * proper mode and output configuration. As a gross hack, enable pipe A
  10930. * by enabling the load detect pipe once. */
  10931. list_for_each_entry(connector,
  10932. &dev->mode_config.connector_list,
  10933. base.head) {
  10934. if (connector->encoder->type == INTEL_OUTPUT_ANALOG) {
  10935. crt = &connector->base;
  10936. break;
  10937. }
  10938. }
  10939. if (!crt)
  10940. return;
  10941. if (intel_get_load_detect_pipe(crt, NULL, &load_detect_temp, ctx))
  10942. intel_release_load_detect_pipe(crt, &load_detect_temp);
  10943. }
  10944. static bool
  10945. intel_check_plane_mapping(struct intel_crtc *crtc)
  10946. {
  10947. struct drm_device *dev = crtc->base.dev;
  10948. struct drm_i915_private *dev_priv = dev->dev_private;
  10949. u32 reg, val;
  10950. if (INTEL_INFO(dev)->num_pipes == 1)
  10951. return true;
  10952. reg = DSPCNTR(!crtc->plane);
  10953. val = I915_READ(reg);
  10954. if ((val & DISPLAY_PLANE_ENABLE) &&
  10955. (!!(val & DISPPLANE_SEL_PIPE_MASK) == crtc->pipe))
  10956. return false;
  10957. return true;
  10958. }
  10959. static void intel_sanitize_crtc(struct intel_crtc *crtc)
  10960. {
  10961. struct drm_device *dev = crtc->base.dev;
  10962. struct drm_i915_private *dev_priv = dev->dev_private;
  10963. u32 reg;
  10964. /* Clear any frame start delays used for debugging left by the BIOS */
  10965. reg = PIPECONF(crtc->config.cpu_transcoder);
  10966. I915_WRITE(reg, I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK);
  10967. /* restore vblank interrupts to correct state */
  10968. if (crtc->active) {
  10969. update_scanline_offset(crtc);
  10970. drm_vblank_on(dev, crtc->pipe);
  10971. } else
  10972. drm_vblank_off(dev, crtc->pipe);
  10973. /* We need to sanitize the plane -> pipe mapping first because this will
  10974. * disable the crtc (and hence change the state) if it is wrong. Note
  10975. * that gen4+ has a fixed plane -> pipe mapping. */
  10976. if (INTEL_INFO(dev)->gen < 4 && !intel_check_plane_mapping(crtc)) {
  10977. struct intel_connector *connector;
  10978. bool plane;
  10979. DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n",
  10980. crtc->base.base.id);
  10981. /* Pipe has the wrong plane attached and the plane is active.
  10982. * Temporarily change the plane mapping and disable everything
  10983. * ... */
  10984. plane = crtc->plane;
  10985. crtc->plane = !plane;
  10986. crtc->primary_enabled = true;
  10987. dev_priv->display.crtc_disable(&crtc->base);
  10988. crtc->plane = plane;
  10989. /* ... and break all links. */
  10990. list_for_each_entry(connector, &dev->mode_config.connector_list,
  10991. base.head) {
  10992. if (connector->encoder->base.crtc != &crtc->base)
  10993. continue;
  10994. connector->base.dpms = DRM_MODE_DPMS_OFF;
  10995. connector->base.encoder = NULL;
  10996. }
  10997. /* multiple connectors may have the same encoder:
  10998. * handle them and break crtc link separately */
  10999. list_for_each_entry(connector, &dev->mode_config.connector_list,
  11000. base.head)
  11001. if (connector->encoder->base.crtc == &crtc->base) {
  11002. connector->encoder->base.crtc = NULL;
  11003. connector->encoder->connectors_active = false;
  11004. }
  11005. WARN_ON(crtc->active);
  11006. crtc->base.enabled = false;
  11007. }
  11008. if (dev_priv->quirks & QUIRK_PIPEA_FORCE &&
  11009. crtc->pipe == PIPE_A && !crtc->active) {
  11010. /* BIOS forgot to enable pipe A, this mostly happens after
  11011. * resume. Force-enable the pipe to fix this, the update_dpms
  11012. * call below we restore the pipe to the right state, but leave
  11013. * the required bits on. */
  11014. intel_enable_pipe_a(dev);
  11015. }
  11016. /* Adjust the state of the output pipe according to whether we
  11017. * have active connectors/encoders. */
  11018. intel_crtc_update_dpms(&crtc->base);
  11019. if (crtc->active != crtc->base.enabled) {
  11020. struct intel_encoder *encoder;
  11021. /* This can happen either due to bugs in the get_hw_state
  11022. * functions or because the pipe is force-enabled due to the
  11023. * pipe A quirk. */
  11024. DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n",
  11025. crtc->base.base.id,
  11026. crtc->base.enabled ? "enabled" : "disabled",
  11027. crtc->active ? "enabled" : "disabled");
  11028. crtc->base.enabled = crtc->active;
  11029. /* Because we only establish the connector -> encoder ->
  11030. * crtc links if something is active, this means the
  11031. * crtc is now deactivated. Break the links. connector
  11032. * -> encoder links are only establish when things are
  11033. * actually up, hence no need to break them. */
  11034. WARN_ON(crtc->active);
  11035. for_each_encoder_on_crtc(dev, &crtc->base, encoder) {
  11036. WARN_ON(encoder->connectors_active);
  11037. encoder->base.crtc = NULL;
  11038. }
  11039. }
  11040. if (crtc->active || HAS_GMCH_DISPLAY(dev)) {
  11041. /*
  11042. * We start out with underrun reporting disabled to avoid races.
  11043. * For correct bookkeeping mark this on active crtcs.
  11044. *
  11045. * Also on gmch platforms we dont have any hardware bits to
  11046. * disable the underrun reporting. Which means we need to start
  11047. * out with underrun reporting disabled also on inactive pipes,
  11048. * since otherwise we'll complain about the garbage we read when
  11049. * e.g. coming up after runtime pm.
  11050. *
  11051. * No protection against concurrent access is required - at
  11052. * worst a fifo underrun happens which also sets this to false.
  11053. */
  11054. crtc->cpu_fifo_underrun_disabled = true;
  11055. crtc->pch_fifo_underrun_disabled = true;
  11056. }
  11057. }
  11058. static void intel_sanitize_encoder(struct intel_encoder *encoder)
  11059. {
  11060. struct intel_connector *connector;
  11061. struct drm_device *dev = encoder->base.dev;
  11062. /* We need to check both for a crtc link (meaning that the
  11063. * encoder is active and trying to read from a pipe) and the
  11064. * pipe itself being active. */
  11065. bool has_active_crtc = encoder->base.crtc &&
  11066. to_intel_crtc(encoder->base.crtc)->active;
  11067. if (encoder->connectors_active && !has_active_crtc) {
  11068. DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
  11069. encoder->base.base.id,
  11070. encoder->base.name);
  11071. /* Connector is active, but has no active pipe. This is
  11072. * fallout from our resume register restoring. Disable
  11073. * the encoder manually again. */
  11074. if (encoder->base.crtc) {
  11075. DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
  11076. encoder->base.base.id,
  11077. encoder->base.name);
  11078. encoder->disable(encoder);
  11079. if (encoder->post_disable)
  11080. encoder->post_disable(encoder);
  11081. }
  11082. encoder->base.crtc = NULL;
  11083. encoder->connectors_active = false;
  11084. /* Inconsistent output/port/pipe state happens presumably due to
  11085. * a bug in one of the get_hw_state functions. Or someplace else
  11086. * in our code, like the register restore mess on resume. Clamp
  11087. * things to off as a safer default. */
  11088. list_for_each_entry(connector,
  11089. &dev->mode_config.connector_list,
  11090. base.head) {
  11091. if (connector->encoder != encoder)
  11092. continue;
  11093. connector->base.dpms = DRM_MODE_DPMS_OFF;
  11094. connector->base.encoder = NULL;
  11095. }
  11096. }
  11097. /* Enabled encoders without active connectors will be fixed in
  11098. * the crtc fixup. */
  11099. }
  11100. void i915_redisable_vga_power_on(struct drm_device *dev)
  11101. {
  11102. struct drm_i915_private *dev_priv = dev->dev_private;
  11103. u32 vga_reg = i915_vgacntrl_reg(dev);
  11104. if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) {
  11105. DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
  11106. i915_disable_vga(dev);
  11107. }
  11108. }
  11109. void i915_redisable_vga(struct drm_device *dev)
  11110. {
  11111. struct drm_i915_private *dev_priv = dev->dev_private;
  11112. /* This function can be called both from intel_modeset_setup_hw_state or
  11113. * at a very early point in our resume sequence, where the power well
  11114. * structures are not yet restored. Since this function is at a very
  11115. * paranoid "someone might have enabled VGA while we were not looking"
  11116. * level, just check if the power well is enabled instead of trying to
  11117. * follow the "don't touch the power well if we don't need it" policy
  11118. * the rest of the driver uses. */
  11119. if (!intel_display_power_enabled(dev_priv, POWER_DOMAIN_VGA))
  11120. return;
  11121. i915_redisable_vga_power_on(dev);
  11122. }
  11123. static bool primary_get_hw_state(struct intel_crtc *crtc)
  11124. {
  11125. struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
  11126. if (!crtc->active)
  11127. return false;
  11128. return I915_READ(DSPCNTR(crtc->plane)) & DISPLAY_PLANE_ENABLE;
  11129. }
  11130. static void intel_modeset_readout_hw_state(struct drm_device *dev)
  11131. {
  11132. struct drm_i915_private *dev_priv = dev->dev_private;
  11133. enum pipe pipe;
  11134. struct intel_crtc *crtc;
  11135. struct intel_encoder *encoder;
  11136. struct intel_connector *connector;
  11137. int i;
  11138. for_each_intel_crtc(dev, crtc) {
  11139. memset(&crtc->config, 0, sizeof(crtc->config));
  11140. crtc->config.quirks |= PIPE_CONFIG_QUIRK_INHERITED_MODE;
  11141. crtc->active = dev_priv->display.get_pipe_config(crtc,
  11142. &crtc->config);
  11143. crtc->base.enabled = crtc->active;
  11144. crtc->primary_enabled = primary_get_hw_state(crtc);
  11145. DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n",
  11146. crtc->base.base.id,
  11147. crtc->active ? "enabled" : "disabled");
  11148. }
  11149. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  11150. struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
  11151. pll->on = pll->get_hw_state(dev_priv, pll, &pll->hw_state);
  11152. pll->active = 0;
  11153. for_each_intel_crtc(dev, crtc) {
  11154. if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll)
  11155. pll->active++;
  11156. }
  11157. pll->refcount = pll->active;
  11158. DRM_DEBUG_KMS("%s hw state readout: refcount %i, on %i\n",
  11159. pll->name, pll->refcount, pll->on);
  11160. if (pll->refcount)
  11161. intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS);
  11162. }
  11163. for_each_intel_encoder(dev, encoder) {
  11164. pipe = 0;
  11165. if (encoder->get_hw_state(encoder, &pipe)) {
  11166. crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  11167. encoder->base.crtc = &crtc->base;
  11168. encoder->get_config(encoder, &crtc->config);
  11169. } else {
  11170. encoder->base.crtc = NULL;
  11171. }
  11172. encoder->connectors_active = false;
  11173. DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
  11174. encoder->base.base.id,
  11175. encoder->base.name,
  11176. encoder->base.crtc ? "enabled" : "disabled",
  11177. pipe_name(pipe));
  11178. }
  11179. list_for_each_entry(connector, &dev->mode_config.connector_list,
  11180. base.head) {
  11181. if (connector->get_hw_state(connector)) {
  11182. connector->base.dpms = DRM_MODE_DPMS_ON;
  11183. connector->encoder->connectors_active = true;
  11184. connector->base.encoder = &connector->encoder->base;
  11185. } else {
  11186. connector->base.dpms = DRM_MODE_DPMS_OFF;
  11187. connector->base.encoder = NULL;
  11188. }
  11189. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
  11190. connector->base.base.id,
  11191. connector->base.name,
  11192. connector->base.encoder ? "enabled" : "disabled");
  11193. }
  11194. }
  11195. /* Scan out the current hw modeset state, sanitizes it and maps it into the drm
  11196. * and i915 state tracking structures. */
  11197. void intel_modeset_setup_hw_state(struct drm_device *dev,
  11198. bool force_restore)
  11199. {
  11200. struct drm_i915_private *dev_priv = dev->dev_private;
  11201. enum pipe pipe;
  11202. struct intel_crtc *crtc;
  11203. struct intel_encoder *encoder;
  11204. int i;
  11205. intel_modeset_readout_hw_state(dev);
  11206. /*
  11207. * Now that we have the config, copy it to each CRTC struct
  11208. * Note that this could go away if we move to using crtc_config
  11209. * checking everywhere.
  11210. */
  11211. for_each_intel_crtc(dev, crtc) {
  11212. if (crtc->active && i915.fastboot) {
  11213. intel_mode_from_pipe_config(&crtc->base.mode, &crtc->config);
  11214. DRM_DEBUG_KMS("[CRTC:%d] found active mode: ",
  11215. crtc->base.base.id);
  11216. drm_mode_debug_printmodeline(&crtc->base.mode);
  11217. }
  11218. }
  11219. /* HW state is read out, now we need to sanitize this mess. */
  11220. for_each_intel_encoder(dev, encoder) {
  11221. intel_sanitize_encoder(encoder);
  11222. }
  11223. for_each_pipe(dev_priv, pipe) {
  11224. crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  11225. intel_sanitize_crtc(crtc);
  11226. intel_dump_pipe_config(crtc, &crtc->config, "[setup_hw_state]");
  11227. }
  11228. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  11229. struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
  11230. if (!pll->on || pll->active)
  11231. continue;
  11232. DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll->name);
  11233. pll->disable(dev_priv, pll);
  11234. pll->on = false;
  11235. }
  11236. if (HAS_PCH_SPLIT(dev))
  11237. ilk_wm_get_hw_state(dev);
  11238. if (force_restore) {
  11239. i915_redisable_vga(dev);
  11240. /*
  11241. * We need to use raw interfaces for restoring state to avoid
  11242. * checking (bogus) intermediate states.
  11243. */
  11244. for_each_pipe(dev_priv, pipe) {
  11245. struct drm_crtc *crtc =
  11246. dev_priv->pipe_to_crtc_mapping[pipe];
  11247. __intel_set_mode(crtc, &crtc->mode, crtc->x, crtc->y,
  11248. crtc->primary->fb);
  11249. }
  11250. } else {
  11251. intel_modeset_update_staged_output_state(dev);
  11252. }
  11253. intel_modeset_check_state(dev);
  11254. }
  11255. void intel_modeset_gem_init(struct drm_device *dev)
  11256. {
  11257. struct drm_crtc *c;
  11258. struct drm_i915_gem_object *obj;
  11259. mutex_lock(&dev->struct_mutex);
  11260. intel_init_gt_powersave(dev);
  11261. mutex_unlock(&dev->struct_mutex);
  11262. intel_modeset_init_hw(dev);
  11263. intel_setup_overlay(dev);
  11264. /*
  11265. * Make sure any fbs we allocated at startup are properly
  11266. * pinned & fenced. When we do the allocation it's too early
  11267. * for this.
  11268. */
  11269. mutex_lock(&dev->struct_mutex);
  11270. for_each_crtc(dev, c) {
  11271. obj = intel_fb_obj(c->primary->fb);
  11272. if (obj == NULL)
  11273. continue;
  11274. if (intel_pin_and_fence_fb_obj(dev, obj, NULL)) {
  11275. DRM_ERROR("failed to pin boot fb on pipe %d\n",
  11276. to_intel_crtc(c)->pipe);
  11277. drm_framebuffer_unreference(c->primary->fb);
  11278. c->primary->fb = NULL;
  11279. }
  11280. }
  11281. mutex_unlock(&dev->struct_mutex);
  11282. }
  11283. void intel_connector_unregister(struct intel_connector *intel_connector)
  11284. {
  11285. struct drm_connector *connector = &intel_connector->base;
  11286. intel_panel_destroy_backlight(connector);
  11287. drm_connector_unregister(connector);
  11288. }
  11289. void intel_modeset_cleanup(struct drm_device *dev)
  11290. {
  11291. struct drm_i915_private *dev_priv = dev->dev_private;
  11292. struct drm_connector *connector;
  11293. /*
  11294. * Interrupts and polling as the first thing to avoid creating havoc.
  11295. * Too much stuff here (turning of rps, connectors, ...) would
  11296. * experience fancy races otherwise.
  11297. */
  11298. drm_irq_uninstall(dev);
  11299. intel_hpd_cancel_work(dev_priv);
  11300. dev_priv->pm._irqs_disabled = true;
  11301. /*
  11302. * Due to the hpd irq storm handling the hotplug work can re-arm the
  11303. * poll handlers. Hence disable polling after hpd handling is shut down.
  11304. */
  11305. drm_kms_helper_poll_fini(dev);
  11306. mutex_lock(&dev->struct_mutex);
  11307. intel_unregister_dsm_handler();
  11308. intel_disable_fbc(dev);
  11309. intel_disable_gt_powersave(dev);
  11310. ironlake_teardown_rc6(dev);
  11311. mutex_unlock(&dev->struct_mutex);
  11312. /* flush any delayed tasks or pending work */
  11313. flush_scheduled_work();
  11314. /* destroy the backlight and sysfs files before encoders/connectors */
  11315. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  11316. struct intel_connector *intel_connector;
  11317. intel_connector = to_intel_connector(connector);
  11318. intel_connector->unregister(intel_connector);
  11319. }
  11320. drm_mode_config_cleanup(dev);
  11321. intel_cleanup_overlay(dev);
  11322. mutex_lock(&dev->struct_mutex);
  11323. intel_cleanup_gt_powersave(dev);
  11324. mutex_unlock(&dev->struct_mutex);
  11325. }
  11326. /*
  11327. * Return which encoder is currently attached for connector.
  11328. */
  11329. struct drm_encoder *intel_best_encoder(struct drm_connector *connector)
  11330. {
  11331. return &intel_attached_encoder(connector)->base;
  11332. }
  11333. void intel_connector_attach_encoder(struct intel_connector *connector,
  11334. struct intel_encoder *encoder)
  11335. {
  11336. connector->encoder = encoder;
  11337. drm_mode_connector_attach_encoder(&connector->base,
  11338. &encoder->base);
  11339. }
  11340. /*
  11341. * set vga decode state - true == enable VGA decode
  11342. */
  11343. int intel_modeset_vga_set_state(struct drm_device *dev, bool state)
  11344. {
  11345. struct drm_i915_private *dev_priv = dev->dev_private;
  11346. unsigned reg = INTEL_INFO(dev)->gen >= 6 ? SNB_GMCH_CTRL : INTEL_GMCH_CTRL;
  11347. u16 gmch_ctrl;
  11348. if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) {
  11349. DRM_ERROR("failed to read control word\n");
  11350. return -EIO;
  11351. }
  11352. if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state)
  11353. return 0;
  11354. if (state)
  11355. gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE;
  11356. else
  11357. gmch_ctrl |= INTEL_GMCH_VGA_DISABLE;
  11358. if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) {
  11359. DRM_ERROR("failed to write control word\n");
  11360. return -EIO;
  11361. }
  11362. return 0;
  11363. }
  11364. struct intel_display_error_state {
  11365. u32 power_well_driver;
  11366. int num_transcoders;
  11367. struct intel_cursor_error_state {
  11368. u32 control;
  11369. u32 position;
  11370. u32 base;
  11371. u32 size;
  11372. } cursor[I915_MAX_PIPES];
  11373. struct intel_pipe_error_state {
  11374. bool power_domain_on;
  11375. u32 source;
  11376. u32 stat;
  11377. } pipe[I915_MAX_PIPES];
  11378. struct intel_plane_error_state {
  11379. u32 control;
  11380. u32 stride;
  11381. u32 size;
  11382. u32 pos;
  11383. u32 addr;
  11384. u32 surface;
  11385. u32 tile_offset;
  11386. } plane[I915_MAX_PIPES];
  11387. struct intel_transcoder_error_state {
  11388. bool power_domain_on;
  11389. enum transcoder cpu_transcoder;
  11390. u32 conf;
  11391. u32 htotal;
  11392. u32 hblank;
  11393. u32 hsync;
  11394. u32 vtotal;
  11395. u32 vblank;
  11396. u32 vsync;
  11397. } transcoder[4];
  11398. };
  11399. struct intel_display_error_state *
  11400. intel_display_capture_error_state(struct drm_device *dev)
  11401. {
  11402. struct drm_i915_private *dev_priv = dev->dev_private;
  11403. struct intel_display_error_state *error;
  11404. int transcoders[] = {
  11405. TRANSCODER_A,
  11406. TRANSCODER_B,
  11407. TRANSCODER_C,
  11408. TRANSCODER_EDP,
  11409. };
  11410. int i;
  11411. if (INTEL_INFO(dev)->num_pipes == 0)
  11412. return NULL;
  11413. error = kzalloc(sizeof(*error), GFP_ATOMIC);
  11414. if (error == NULL)
  11415. return NULL;
  11416. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  11417. error->power_well_driver = I915_READ(HSW_PWR_WELL_DRIVER);
  11418. for_each_pipe(dev_priv, i) {
  11419. error->pipe[i].power_domain_on =
  11420. intel_display_power_enabled_unlocked(dev_priv,
  11421. POWER_DOMAIN_PIPE(i));
  11422. if (!error->pipe[i].power_domain_on)
  11423. continue;
  11424. error->cursor[i].control = I915_READ(CURCNTR(i));
  11425. error->cursor[i].position = I915_READ(CURPOS(i));
  11426. error->cursor[i].base = I915_READ(CURBASE(i));
  11427. error->plane[i].control = I915_READ(DSPCNTR(i));
  11428. error->plane[i].stride = I915_READ(DSPSTRIDE(i));
  11429. if (INTEL_INFO(dev)->gen <= 3) {
  11430. error->plane[i].size = I915_READ(DSPSIZE(i));
  11431. error->plane[i].pos = I915_READ(DSPPOS(i));
  11432. }
  11433. if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev))
  11434. error->plane[i].addr = I915_READ(DSPADDR(i));
  11435. if (INTEL_INFO(dev)->gen >= 4) {
  11436. error->plane[i].surface = I915_READ(DSPSURF(i));
  11437. error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i));
  11438. }
  11439. error->pipe[i].source = I915_READ(PIPESRC(i));
  11440. if (HAS_GMCH_DISPLAY(dev))
  11441. error->pipe[i].stat = I915_READ(PIPESTAT(i));
  11442. }
  11443. error->num_transcoders = INTEL_INFO(dev)->num_pipes;
  11444. if (HAS_DDI(dev_priv->dev))
  11445. error->num_transcoders++; /* Account for eDP. */
  11446. for (i = 0; i < error->num_transcoders; i++) {
  11447. enum transcoder cpu_transcoder = transcoders[i];
  11448. error->transcoder[i].power_domain_on =
  11449. intel_display_power_enabled_unlocked(dev_priv,
  11450. POWER_DOMAIN_TRANSCODER(cpu_transcoder));
  11451. if (!error->transcoder[i].power_domain_on)
  11452. continue;
  11453. error->transcoder[i].cpu_transcoder = cpu_transcoder;
  11454. error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder));
  11455. error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder));
  11456. error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder));
  11457. error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder));
  11458. error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder));
  11459. error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder));
  11460. error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder));
  11461. }
  11462. return error;
  11463. }
  11464. #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
  11465. void
  11466. intel_display_print_error_state(struct drm_i915_error_state_buf *m,
  11467. struct drm_device *dev,
  11468. struct intel_display_error_state *error)
  11469. {
  11470. struct drm_i915_private *dev_priv = dev->dev_private;
  11471. int i;
  11472. if (!error)
  11473. return;
  11474. err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev)->num_pipes);
  11475. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  11476. err_printf(m, "PWR_WELL_CTL2: %08x\n",
  11477. error->power_well_driver);
  11478. for_each_pipe(dev_priv, i) {
  11479. err_printf(m, "Pipe [%d]:\n", i);
  11480. err_printf(m, " Power: %s\n",
  11481. error->pipe[i].power_domain_on ? "on" : "off");
  11482. err_printf(m, " SRC: %08x\n", error->pipe[i].source);
  11483. err_printf(m, " STAT: %08x\n", error->pipe[i].stat);
  11484. err_printf(m, "Plane [%d]:\n", i);
  11485. err_printf(m, " CNTR: %08x\n", error->plane[i].control);
  11486. err_printf(m, " STRIDE: %08x\n", error->plane[i].stride);
  11487. if (INTEL_INFO(dev)->gen <= 3) {
  11488. err_printf(m, " SIZE: %08x\n", error->plane[i].size);
  11489. err_printf(m, " POS: %08x\n", error->plane[i].pos);
  11490. }
  11491. if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev))
  11492. err_printf(m, " ADDR: %08x\n", error->plane[i].addr);
  11493. if (INTEL_INFO(dev)->gen >= 4) {
  11494. err_printf(m, " SURF: %08x\n", error->plane[i].surface);
  11495. err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset);
  11496. }
  11497. err_printf(m, "Cursor [%d]:\n", i);
  11498. err_printf(m, " CNTR: %08x\n", error->cursor[i].control);
  11499. err_printf(m, " POS: %08x\n", error->cursor[i].position);
  11500. err_printf(m, " BASE: %08x\n", error->cursor[i].base);
  11501. }
  11502. for (i = 0; i < error->num_transcoders; i++) {
  11503. err_printf(m, "CPU transcoder: %c\n",
  11504. transcoder_name(error->transcoder[i].cpu_transcoder));
  11505. err_printf(m, " Power: %s\n",
  11506. error->transcoder[i].power_domain_on ? "on" : "off");
  11507. err_printf(m, " CONF: %08x\n", error->transcoder[i].conf);
  11508. err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal);
  11509. err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank);
  11510. err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync);
  11511. err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal);
  11512. err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank);
  11513. err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync);
  11514. }
  11515. }
  11516. void intel_modeset_preclose(struct drm_device *dev, struct drm_file *file)
  11517. {
  11518. struct intel_crtc *crtc;
  11519. for_each_intel_crtc(dev, crtc) {
  11520. struct intel_unpin_work *work;
  11521. unsigned long irqflags;
  11522. spin_lock_irqsave(&dev->event_lock, irqflags);
  11523. work = crtc->unpin_work;
  11524. if (work && work->event &&
  11525. work->event->base.file_priv == file) {
  11526. kfree(work->event);
  11527. work->event = NULL;
  11528. }
  11529. spin_unlock_irqrestore(&dev->event_lock, irqflags);
  11530. }
  11531. }