intel_display.c 380 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786
  1. /*
  2. * Copyright © 2006-2007 Intel Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  21. * DEALINGS IN THE SOFTWARE.
  22. *
  23. * Authors:
  24. * Eric Anholt <eric@anholt.net>
  25. */
  26. #include <linux/dmi.h>
  27. #include <linux/module.h>
  28. #include <linux/input.h>
  29. #include <linux/i2c.h>
  30. #include <linux/kernel.h>
  31. #include <linux/slab.h>
  32. #include <linux/vgaarb.h>
  33. #include <drm/drm_edid.h>
  34. #include <drm/drmP.h>
  35. #include "intel_drv.h"
  36. #include <drm/i915_drm.h>
  37. #include "i915_drv.h"
  38. #include "i915_trace.h"
  39. #include <drm/drm_dp_helper.h>
  40. #include <drm/drm_crtc_helper.h>
  41. #include <drm/drm_plane_helper.h>
  42. #include <drm/drm_rect.h>
  43. #include <linux/dma_remapping.h>
  44. /* Primary plane formats supported by all gen */
  45. #define COMMON_PRIMARY_FORMATS \
  46. DRM_FORMAT_C8, \
  47. DRM_FORMAT_RGB565, \
  48. DRM_FORMAT_XRGB8888, \
  49. DRM_FORMAT_ARGB8888
  50. /* Primary plane formats for gen <= 3 */
  51. static const uint32_t intel_primary_formats_gen2[] = {
  52. COMMON_PRIMARY_FORMATS,
  53. DRM_FORMAT_XRGB1555,
  54. DRM_FORMAT_ARGB1555,
  55. };
  56. /* Primary plane formats for gen >= 4 */
  57. static const uint32_t intel_primary_formats_gen4[] = {
  58. COMMON_PRIMARY_FORMATS, \
  59. DRM_FORMAT_XBGR8888,
  60. DRM_FORMAT_ABGR8888,
  61. DRM_FORMAT_XRGB2101010,
  62. DRM_FORMAT_ARGB2101010,
  63. DRM_FORMAT_XBGR2101010,
  64. DRM_FORMAT_ABGR2101010,
  65. };
  66. /* Cursor formats */
  67. static const uint32_t intel_cursor_formats[] = {
  68. DRM_FORMAT_ARGB8888,
  69. };
  70. #define DIV_ROUND_CLOSEST_ULL(ll, d) \
  71. ({ unsigned long long _tmp = (ll)+(d)/2; do_div(_tmp, d); _tmp; })
  72. static void intel_increase_pllclock(struct drm_device *dev,
  73. enum pipe pipe);
  74. static void intel_crtc_update_cursor(struct drm_crtc *crtc, bool on);
  75. static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
  76. struct intel_crtc_config *pipe_config);
  77. static void ironlake_pch_clock_get(struct intel_crtc *crtc,
  78. struct intel_crtc_config *pipe_config);
  79. static int intel_set_mode(struct drm_crtc *crtc, struct drm_display_mode *mode,
  80. int x, int y, struct drm_framebuffer *old_fb);
  81. static int intel_framebuffer_init(struct drm_device *dev,
  82. struct intel_framebuffer *ifb,
  83. struct drm_mode_fb_cmd2 *mode_cmd,
  84. struct drm_i915_gem_object *obj);
  85. static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc);
  86. static void intel_set_pipe_timings(struct intel_crtc *intel_crtc);
  87. static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc,
  88. struct intel_link_m_n *m_n,
  89. struct intel_link_m_n *m2_n2);
  90. static void ironlake_set_pipeconf(struct drm_crtc *crtc);
  91. static void haswell_set_pipeconf(struct drm_crtc *crtc);
  92. static void intel_set_pipe_csc(struct drm_crtc *crtc);
  93. static void vlv_prepare_pll(struct intel_crtc *crtc);
  94. static void chv_prepare_pll(struct intel_crtc *crtc);
  95. static struct intel_encoder *intel_find_encoder(struct intel_connector *connector, int pipe)
  96. {
  97. if (!connector->mst_port)
  98. return connector->encoder;
  99. else
  100. return &connector->mst_port->mst_encoders[pipe]->base;
  101. }
  102. typedef struct {
  103. int min, max;
  104. } intel_range_t;
  105. typedef struct {
  106. int dot_limit;
  107. int p2_slow, p2_fast;
  108. } intel_p2_t;
  109. typedef struct intel_limit intel_limit_t;
  110. struct intel_limit {
  111. intel_range_t dot, vco, n, m, m1, m2, p, p1;
  112. intel_p2_t p2;
  113. };
  114. int
  115. intel_pch_rawclk(struct drm_device *dev)
  116. {
  117. struct drm_i915_private *dev_priv = dev->dev_private;
  118. WARN_ON(!HAS_PCH_SPLIT(dev));
  119. return I915_READ(PCH_RAWCLK_FREQ) & RAWCLK_FREQ_MASK;
  120. }
  121. static inline u32 /* units of 100MHz */
  122. intel_fdi_link_freq(struct drm_device *dev)
  123. {
  124. if (IS_GEN5(dev)) {
  125. struct drm_i915_private *dev_priv = dev->dev_private;
  126. return (I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK) + 2;
  127. } else
  128. return 27;
  129. }
  130. static const intel_limit_t intel_limits_i8xx_dac = {
  131. .dot = { .min = 25000, .max = 350000 },
  132. .vco = { .min = 908000, .max = 1512000 },
  133. .n = { .min = 2, .max = 16 },
  134. .m = { .min = 96, .max = 140 },
  135. .m1 = { .min = 18, .max = 26 },
  136. .m2 = { .min = 6, .max = 16 },
  137. .p = { .min = 4, .max = 128 },
  138. .p1 = { .min = 2, .max = 33 },
  139. .p2 = { .dot_limit = 165000,
  140. .p2_slow = 4, .p2_fast = 2 },
  141. };
  142. static const intel_limit_t intel_limits_i8xx_dvo = {
  143. .dot = { .min = 25000, .max = 350000 },
  144. .vco = { .min = 908000, .max = 1512000 },
  145. .n = { .min = 2, .max = 16 },
  146. .m = { .min = 96, .max = 140 },
  147. .m1 = { .min = 18, .max = 26 },
  148. .m2 = { .min = 6, .max = 16 },
  149. .p = { .min = 4, .max = 128 },
  150. .p1 = { .min = 2, .max = 33 },
  151. .p2 = { .dot_limit = 165000,
  152. .p2_slow = 4, .p2_fast = 4 },
  153. };
  154. static const intel_limit_t intel_limits_i8xx_lvds = {
  155. .dot = { .min = 25000, .max = 350000 },
  156. .vco = { .min = 908000, .max = 1512000 },
  157. .n = { .min = 2, .max = 16 },
  158. .m = { .min = 96, .max = 140 },
  159. .m1 = { .min = 18, .max = 26 },
  160. .m2 = { .min = 6, .max = 16 },
  161. .p = { .min = 4, .max = 128 },
  162. .p1 = { .min = 1, .max = 6 },
  163. .p2 = { .dot_limit = 165000,
  164. .p2_slow = 14, .p2_fast = 7 },
  165. };
  166. static const intel_limit_t intel_limits_i9xx_sdvo = {
  167. .dot = { .min = 20000, .max = 400000 },
  168. .vco = { .min = 1400000, .max = 2800000 },
  169. .n = { .min = 1, .max = 6 },
  170. .m = { .min = 70, .max = 120 },
  171. .m1 = { .min = 8, .max = 18 },
  172. .m2 = { .min = 3, .max = 7 },
  173. .p = { .min = 5, .max = 80 },
  174. .p1 = { .min = 1, .max = 8 },
  175. .p2 = { .dot_limit = 200000,
  176. .p2_slow = 10, .p2_fast = 5 },
  177. };
  178. static const intel_limit_t intel_limits_i9xx_lvds = {
  179. .dot = { .min = 20000, .max = 400000 },
  180. .vco = { .min = 1400000, .max = 2800000 },
  181. .n = { .min = 1, .max = 6 },
  182. .m = { .min = 70, .max = 120 },
  183. .m1 = { .min = 8, .max = 18 },
  184. .m2 = { .min = 3, .max = 7 },
  185. .p = { .min = 7, .max = 98 },
  186. .p1 = { .min = 1, .max = 8 },
  187. .p2 = { .dot_limit = 112000,
  188. .p2_slow = 14, .p2_fast = 7 },
  189. };
  190. static const intel_limit_t intel_limits_g4x_sdvo = {
  191. .dot = { .min = 25000, .max = 270000 },
  192. .vco = { .min = 1750000, .max = 3500000},
  193. .n = { .min = 1, .max = 4 },
  194. .m = { .min = 104, .max = 138 },
  195. .m1 = { .min = 17, .max = 23 },
  196. .m2 = { .min = 5, .max = 11 },
  197. .p = { .min = 10, .max = 30 },
  198. .p1 = { .min = 1, .max = 3},
  199. .p2 = { .dot_limit = 270000,
  200. .p2_slow = 10,
  201. .p2_fast = 10
  202. },
  203. };
  204. static const intel_limit_t intel_limits_g4x_hdmi = {
  205. .dot = { .min = 22000, .max = 400000 },
  206. .vco = { .min = 1750000, .max = 3500000},
  207. .n = { .min = 1, .max = 4 },
  208. .m = { .min = 104, .max = 138 },
  209. .m1 = { .min = 16, .max = 23 },
  210. .m2 = { .min = 5, .max = 11 },
  211. .p = { .min = 5, .max = 80 },
  212. .p1 = { .min = 1, .max = 8},
  213. .p2 = { .dot_limit = 165000,
  214. .p2_slow = 10, .p2_fast = 5 },
  215. };
  216. static const intel_limit_t intel_limits_g4x_single_channel_lvds = {
  217. .dot = { .min = 20000, .max = 115000 },
  218. .vco = { .min = 1750000, .max = 3500000 },
  219. .n = { .min = 1, .max = 3 },
  220. .m = { .min = 104, .max = 138 },
  221. .m1 = { .min = 17, .max = 23 },
  222. .m2 = { .min = 5, .max = 11 },
  223. .p = { .min = 28, .max = 112 },
  224. .p1 = { .min = 2, .max = 8 },
  225. .p2 = { .dot_limit = 0,
  226. .p2_slow = 14, .p2_fast = 14
  227. },
  228. };
  229. static const intel_limit_t intel_limits_g4x_dual_channel_lvds = {
  230. .dot = { .min = 80000, .max = 224000 },
  231. .vco = { .min = 1750000, .max = 3500000 },
  232. .n = { .min = 1, .max = 3 },
  233. .m = { .min = 104, .max = 138 },
  234. .m1 = { .min = 17, .max = 23 },
  235. .m2 = { .min = 5, .max = 11 },
  236. .p = { .min = 14, .max = 42 },
  237. .p1 = { .min = 2, .max = 6 },
  238. .p2 = { .dot_limit = 0,
  239. .p2_slow = 7, .p2_fast = 7
  240. },
  241. };
  242. static const intel_limit_t intel_limits_pineview_sdvo = {
  243. .dot = { .min = 20000, .max = 400000},
  244. .vco = { .min = 1700000, .max = 3500000 },
  245. /* Pineview's Ncounter is a ring counter */
  246. .n = { .min = 3, .max = 6 },
  247. .m = { .min = 2, .max = 256 },
  248. /* Pineview only has one combined m divider, which we treat as m2. */
  249. .m1 = { .min = 0, .max = 0 },
  250. .m2 = { .min = 0, .max = 254 },
  251. .p = { .min = 5, .max = 80 },
  252. .p1 = { .min = 1, .max = 8 },
  253. .p2 = { .dot_limit = 200000,
  254. .p2_slow = 10, .p2_fast = 5 },
  255. };
  256. static const intel_limit_t intel_limits_pineview_lvds = {
  257. .dot = { .min = 20000, .max = 400000 },
  258. .vco = { .min = 1700000, .max = 3500000 },
  259. .n = { .min = 3, .max = 6 },
  260. .m = { .min = 2, .max = 256 },
  261. .m1 = { .min = 0, .max = 0 },
  262. .m2 = { .min = 0, .max = 254 },
  263. .p = { .min = 7, .max = 112 },
  264. .p1 = { .min = 1, .max = 8 },
  265. .p2 = { .dot_limit = 112000,
  266. .p2_slow = 14, .p2_fast = 14 },
  267. };
  268. /* Ironlake / Sandybridge
  269. *
  270. * We calculate clock using (register_value + 2) for N/M1/M2, so here
  271. * the range value for them is (actual_value - 2).
  272. */
  273. static const intel_limit_t intel_limits_ironlake_dac = {
  274. .dot = { .min = 25000, .max = 350000 },
  275. .vco = { .min = 1760000, .max = 3510000 },
  276. .n = { .min = 1, .max = 5 },
  277. .m = { .min = 79, .max = 127 },
  278. .m1 = { .min = 12, .max = 22 },
  279. .m2 = { .min = 5, .max = 9 },
  280. .p = { .min = 5, .max = 80 },
  281. .p1 = { .min = 1, .max = 8 },
  282. .p2 = { .dot_limit = 225000,
  283. .p2_slow = 10, .p2_fast = 5 },
  284. };
  285. static const intel_limit_t intel_limits_ironlake_single_lvds = {
  286. .dot = { .min = 25000, .max = 350000 },
  287. .vco = { .min = 1760000, .max = 3510000 },
  288. .n = { .min = 1, .max = 3 },
  289. .m = { .min = 79, .max = 118 },
  290. .m1 = { .min = 12, .max = 22 },
  291. .m2 = { .min = 5, .max = 9 },
  292. .p = { .min = 28, .max = 112 },
  293. .p1 = { .min = 2, .max = 8 },
  294. .p2 = { .dot_limit = 225000,
  295. .p2_slow = 14, .p2_fast = 14 },
  296. };
  297. static const intel_limit_t intel_limits_ironlake_dual_lvds = {
  298. .dot = { .min = 25000, .max = 350000 },
  299. .vco = { .min = 1760000, .max = 3510000 },
  300. .n = { .min = 1, .max = 3 },
  301. .m = { .min = 79, .max = 127 },
  302. .m1 = { .min = 12, .max = 22 },
  303. .m2 = { .min = 5, .max = 9 },
  304. .p = { .min = 14, .max = 56 },
  305. .p1 = { .min = 2, .max = 8 },
  306. .p2 = { .dot_limit = 225000,
  307. .p2_slow = 7, .p2_fast = 7 },
  308. };
  309. /* LVDS 100mhz refclk limits. */
  310. static const intel_limit_t intel_limits_ironlake_single_lvds_100m = {
  311. .dot = { .min = 25000, .max = 350000 },
  312. .vco = { .min = 1760000, .max = 3510000 },
  313. .n = { .min = 1, .max = 2 },
  314. .m = { .min = 79, .max = 126 },
  315. .m1 = { .min = 12, .max = 22 },
  316. .m2 = { .min = 5, .max = 9 },
  317. .p = { .min = 28, .max = 112 },
  318. .p1 = { .min = 2, .max = 8 },
  319. .p2 = { .dot_limit = 225000,
  320. .p2_slow = 14, .p2_fast = 14 },
  321. };
  322. static const intel_limit_t intel_limits_ironlake_dual_lvds_100m = {
  323. .dot = { .min = 25000, .max = 350000 },
  324. .vco = { .min = 1760000, .max = 3510000 },
  325. .n = { .min = 1, .max = 3 },
  326. .m = { .min = 79, .max = 126 },
  327. .m1 = { .min = 12, .max = 22 },
  328. .m2 = { .min = 5, .max = 9 },
  329. .p = { .min = 14, .max = 42 },
  330. .p1 = { .min = 2, .max = 6 },
  331. .p2 = { .dot_limit = 225000,
  332. .p2_slow = 7, .p2_fast = 7 },
  333. };
  334. static const intel_limit_t intel_limits_vlv = {
  335. /*
  336. * These are the data rate limits (measured in fast clocks)
  337. * since those are the strictest limits we have. The fast
  338. * clock and actual rate limits are more relaxed, so checking
  339. * them would make no difference.
  340. */
  341. .dot = { .min = 25000 * 5, .max = 270000 * 5 },
  342. .vco = { .min = 4000000, .max = 6000000 },
  343. .n = { .min = 1, .max = 7 },
  344. .m1 = { .min = 2, .max = 3 },
  345. .m2 = { .min = 11, .max = 156 },
  346. .p1 = { .min = 2, .max = 3 },
  347. .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */
  348. };
  349. static const intel_limit_t intel_limits_chv = {
  350. /*
  351. * These are the data rate limits (measured in fast clocks)
  352. * since those are the strictest limits we have. The fast
  353. * clock and actual rate limits are more relaxed, so checking
  354. * them would make no difference.
  355. */
  356. .dot = { .min = 25000 * 5, .max = 540000 * 5},
  357. .vco = { .min = 4860000, .max = 6700000 },
  358. .n = { .min = 1, .max = 1 },
  359. .m1 = { .min = 2, .max = 2 },
  360. .m2 = { .min = 24 << 22, .max = 175 << 22 },
  361. .p1 = { .min = 2, .max = 4 },
  362. .p2 = { .p2_slow = 1, .p2_fast = 14 },
  363. };
  364. static void vlv_clock(int refclk, intel_clock_t *clock)
  365. {
  366. clock->m = clock->m1 * clock->m2;
  367. clock->p = clock->p1 * clock->p2;
  368. if (WARN_ON(clock->n == 0 || clock->p == 0))
  369. return;
  370. clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
  371. clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
  372. }
  373. /**
  374. * Returns whether any output on the specified pipe is of the specified type
  375. */
  376. static bool intel_pipe_has_type(struct drm_crtc *crtc, int type)
  377. {
  378. struct drm_device *dev = crtc->dev;
  379. struct intel_encoder *encoder;
  380. for_each_encoder_on_crtc(dev, crtc, encoder)
  381. if (encoder->type == type)
  382. return true;
  383. return false;
  384. }
  385. static const intel_limit_t *intel_ironlake_limit(struct drm_crtc *crtc,
  386. int refclk)
  387. {
  388. struct drm_device *dev = crtc->dev;
  389. const intel_limit_t *limit;
  390. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  391. if (intel_is_dual_link_lvds(dev)) {
  392. if (refclk == 100000)
  393. limit = &intel_limits_ironlake_dual_lvds_100m;
  394. else
  395. limit = &intel_limits_ironlake_dual_lvds;
  396. } else {
  397. if (refclk == 100000)
  398. limit = &intel_limits_ironlake_single_lvds_100m;
  399. else
  400. limit = &intel_limits_ironlake_single_lvds;
  401. }
  402. } else
  403. limit = &intel_limits_ironlake_dac;
  404. return limit;
  405. }
  406. static const intel_limit_t *intel_g4x_limit(struct drm_crtc *crtc)
  407. {
  408. struct drm_device *dev = crtc->dev;
  409. const intel_limit_t *limit;
  410. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  411. if (intel_is_dual_link_lvds(dev))
  412. limit = &intel_limits_g4x_dual_channel_lvds;
  413. else
  414. limit = &intel_limits_g4x_single_channel_lvds;
  415. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI) ||
  416. intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG)) {
  417. limit = &intel_limits_g4x_hdmi;
  418. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO)) {
  419. limit = &intel_limits_g4x_sdvo;
  420. } else /* The option is for other outputs */
  421. limit = &intel_limits_i9xx_sdvo;
  422. return limit;
  423. }
  424. static const intel_limit_t *intel_limit(struct drm_crtc *crtc, int refclk)
  425. {
  426. struct drm_device *dev = crtc->dev;
  427. const intel_limit_t *limit;
  428. if (HAS_PCH_SPLIT(dev))
  429. limit = intel_ironlake_limit(crtc, refclk);
  430. else if (IS_G4X(dev)) {
  431. limit = intel_g4x_limit(crtc);
  432. } else if (IS_PINEVIEW(dev)) {
  433. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  434. limit = &intel_limits_pineview_lvds;
  435. else
  436. limit = &intel_limits_pineview_sdvo;
  437. } else if (IS_CHERRYVIEW(dev)) {
  438. limit = &intel_limits_chv;
  439. } else if (IS_VALLEYVIEW(dev)) {
  440. limit = &intel_limits_vlv;
  441. } else if (!IS_GEN2(dev)) {
  442. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  443. limit = &intel_limits_i9xx_lvds;
  444. else
  445. limit = &intel_limits_i9xx_sdvo;
  446. } else {
  447. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  448. limit = &intel_limits_i8xx_lvds;
  449. else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO))
  450. limit = &intel_limits_i8xx_dvo;
  451. else
  452. limit = &intel_limits_i8xx_dac;
  453. }
  454. return limit;
  455. }
  456. /* m1 is reserved as 0 in Pineview, n is a ring counter */
  457. static void pineview_clock(int refclk, intel_clock_t *clock)
  458. {
  459. clock->m = clock->m2 + 2;
  460. clock->p = clock->p1 * clock->p2;
  461. if (WARN_ON(clock->n == 0 || clock->p == 0))
  462. return;
  463. clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
  464. clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
  465. }
  466. static uint32_t i9xx_dpll_compute_m(struct dpll *dpll)
  467. {
  468. return 5 * (dpll->m1 + 2) + (dpll->m2 + 2);
  469. }
  470. static void i9xx_clock(int refclk, intel_clock_t *clock)
  471. {
  472. clock->m = i9xx_dpll_compute_m(clock);
  473. clock->p = clock->p1 * clock->p2;
  474. if (WARN_ON(clock->n + 2 == 0 || clock->p == 0))
  475. return;
  476. clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2);
  477. clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
  478. }
  479. static void chv_clock(int refclk, intel_clock_t *clock)
  480. {
  481. clock->m = clock->m1 * clock->m2;
  482. clock->p = clock->p1 * clock->p2;
  483. if (WARN_ON(clock->n == 0 || clock->p == 0))
  484. return;
  485. clock->vco = DIV_ROUND_CLOSEST_ULL((uint64_t)refclk * clock->m,
  486. clock->n << 22);
  487. clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
  488. }
  489. #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
  490. /**
  491. * Returns whether the given set of divisors are valid for a given refclk with
  492. * the given connectors.
  493. */
  494. static bool intel_PLL_is_valid(struct drm_device *dev,
  495. const intel_limit_t *limit,
  496. const intel_clock_t *clock)
  497. {
  498. if (clock->n < limit->n.min || limit->n.max < clock->n)
  499. INTELPllInvalid("n out of range\n");
  500. if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1)
  501. INTELPllInvalid("p1 out of range\n");
  502. if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2)
  503. INTELPllInvalid("m2 out of range\n");
  504. if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1)
  505. INTELPllInvalid("m1 out of range\n");
  506. if (!IS_PINEVIEW(dev) && !IS_VALLEYVIEW(dev))
  507. if (clock->m1 <= clock->m2)
  508. INTELPllInvalid("m1 <= m2\n");
  509. if (!IS_VALLEYVIEW(dev)) {
  510. if (clock->p < limit->p.min || limit->p.max < clock->p)
  511. INTELPllInvalid("p out of range\n");
  512. if (clock->m < limit->m.min || limit->m.max < clock->m)
  513. INTELPllInvalid("m out of range\n");
  514. }
  515. if (clock->vco < limit->vco.min || limit->vco.max < clock->vco)
  516. INTELPllInvalid("vco out of range\n");
  517. /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
  518. * connector, etc., rather than just a single range.
  519. */
  520. if (clock->dot < limit->dot.min || limit->dot.max < clock->dot)
  521. INTELPllInvalid("dot out of range\n");
  522. return true;
  523. }
  524. static bool
  525. i9xx_find_best_dpll(const intel_limit_t *limit, struct drm_crtc *crtc,
  526. int target, int refclk, intel_clock_t *match_clock,
  527. intel_clock_t *best_clock)
  528. {
  529. struct drm_device *dev = crtc->dev;
  530. intel_clock_t clock;
  531. int err = target;
  532. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  533. /*
  534. * For LVDS just rely on its current settings for dual-channel.
  535. * We haven't figured out how to reliably set up different
  536. * single/dual channel state, if we even can.
  537. */
  538. if (intel_is_dual_link_lvds(dev))
  539. clock.p2 = limit->p2.p2_fast;
  540. else
  541. clock.p2 = limit->p2.p2_slow;
  542. } else {
  543. if (target < limit->p2.dot_limit)
  544. clock.p2 = limit->p2.p2_slow;
  545. else
  546. clock.p2 = limit->p2.p2_fast;
  547. }
  548. memset(best_clock, 0, sizeof(*best_clock));
  549. for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
  550. clock.m1++) {
  551. for (clock.m2 = limit->m2.min;
  552. clock.m2 <= limit->m2.max; clock.m2++) {
  553. if (clock.m2 >= clock.m1)
  554. break;
  555. for (clock.n = limit->n.min;
  556. clock.n <= limit->n.max; clock.n++) {
  557. for (clock.p1 = limit->p1.min;
  558. clock.p1 <= limit->p1.max; clock.p1++) {
  559. int this_err;
  560. i9xx_clock(refclk, &clock);
  561. if (!intel_PLL_is_valid(dev, limit,
  562. &clock))
  563. continue;
  564. if (match_clock &&
  565. clock.p != match_clock->p)
  566. continue;
  567. this_err = abs(clock.dot - target);
  568. if (this_err < err) {
  569. *best_clock = clock;
  570. err = this_err;
  571. }
  572. }
  573. }
  574. }
  575. }
  576. return (err != target);
  577. }
  578. static bool
  579. pnv_find_best_dpll(const intel_limit_t *limit, struct drm_crtc *crtc,
  580. int target, int refclk, intel_clock_t *match_clock,
  581. intel_clock_t *best_clock)
  582. {
  583. struct drm_device *dev = crtc->dev;
  584. intel_clock_t clock;
  585. int err = target;
  586. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  587. /*
  588. * For LVDS just rely on its current settings for dual-channel.
  589. * We haven't figured out how to reliably set up different
  590. * single/dual channel state, if we even can.
  591. */
  592. if (intel_is_dual_link_lvds(dev))
  593. clock.p2 = limit->p2.p2_fast;
  594. else
  595. clock.p2 = limit->p2.p2_slow;
  596. } else {
  597. if (target < limit->p2.dot_limit)
  598. clock.p2 = limit->p2.p2_slow;
  599. else
  600. clock.p2 = limit->p2.p2_fast;
  601. }
  602. memset(best_clock, 0, sizeof(*best_clock));
  603. for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
  604. clock.m1++) {
  605. for (clock.m2 = limit->m2.min;
  606. clock.m2 <= limit->m2.max; clock.m2++) {
  607. for (clock.n = limit->n.min;
  608. clock.n <= limit->n.max; clock.n++) {
  609. for (clock.p1 = limit->p1.min;
  610. clock.p1 <= limit->p1.max; clock.p1++) {
  611. int this_err;
  612. pineview_clock(refclk, &clock);
  613. if (!intel_PLL_is_valid(dev, limit,
  614. &clock))
  615. continue;
  616. if (match_clock &&
  617. clock.p != match_clock->p)
  618. continue;
  619. this_err = abs(clock.dot - target);
  620. if (this_err < err) {
  621. *best_clock = clock;
  622. err = this_err;
  623. }
  624. }
  625. }
  626. }
  627. }
  628. return (err != target);
  629. }
  630. static bool
  631. g4x_find_best_dpll(const intel_limit_t *limit, struct drm_crtc *crtc,
  632. int target, int refclk, intel_clock_t *match_clock,
  633. intel_clock_t *best_clock)
  634. {
  635. struct drm_device *dev = crtc->dev;
  636. intel_clock_t clock;
  637. int max_n;
  638. bool found;
  639. /* approximately equals target * 0.00585 */
  640. int err_most = (target >> 8) + (target >> 9);
  641. found = false;
  642. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  643. if (intel_is_dual_link_lvds(dev))
  644. clock.p2 = limit->p2.p2_fast;
  645. else
  646. clock.p2 = limit->p2.p2_slow;
  647. } else {
  648. if (target < limit->p2.dot_limit)
  649. clock.p2 = limit->p2.p2_slow;
  650. else
  651. clock.p2 = limit->p2.p2_fast;
  652. }
  653. memset(best_clock, 0, sizeof(*best_clock));
  654. max_n = limit->n.max;
  655. /* based on hardware requirement, prefer smaller n to precision */
  656. for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
  657. /* based on hardware requirement, prefere larger m1,m2 */
  658. for (clock.m1 = limit->m1.max;
  659. clock.m1 >= limit->m1.min; clock.m1--) {
  660. for (clock.m2 = limit->m2.max;
  661. clock.m2 >= limit->m2.min; clock.m2--) {
  662. for (clock.p1 = limit->p1.max;
  663. clock.p1 >= limit->p1.min; clock.p1--) {
  664. int this_err;
  665. i9xx_clock(refclk, &clock);
  666. if (!intel_PLL_is_valid(dev, limit,
  667. &clock))
  668. continue;
  669. this_err = abs(clock.dot - target);
  670. if (this_err < err_most) {
  671. *best_clock = clock;
  672. err_most = this_err;
  673. max_n = clock.n;
  674. found = true;
  675. }
  676. }
  677. }
  678. }
  679. }
  680. return found;
  681. }
  682. static bool
  683. vlv_find_best_dpll(const intel_limit_t *limit, struct drm_crtc *crtc,
  684. int target, int refclk, intel_clock_t *match_clock,
  685. intel_clock_t *best_clock)
  686. {
  687. struct drm_device *dev = crtc->dev;
  688. intel_clock_t clock;
  689. unsigned int bestppm = 1000000;
  690. /* min update 19.2 MHz */
  691. int max_n = min(limit->n.max, refclk / 19200);
  692. bool found = false;
  693. target *= 5; /* fast clock */
  694. memset(best_clock, 0, sizeof(*best_clock));
  695. /* based on hardware requirement, prefer smaller n to precision */
  696. for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
  697. for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
  698. for (clock.p2 = limit->p2.p2_fast; clock.p2 >= limit->p2.p2_slow;
  699. clock.p2 -= clock.p2 > 10 ? 2 : 1) {
  700. clock.p = clock.p1 * clock.p2;
  701. /* based on hardware requirement, prefer bigger m1,m2 values */
  702. for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) {
  703. unsigned int ppm, diff;
  704. clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n,
  705. refclk * clock.m1);
  706. vlv_clock(refclk, &clock);
  707. if (!intel_PLL_is_valid(dev, limit,
  708. &clock))
  709. continue;
  710. diff = abs(clock.dot - target);
  711. ppm = div_u64(1000000ULL * diff, target);
  712. if (ppm < 100 && clock.p > best_clock->p) {
  713. bestppm = 0;
  714. *best_clock = clock;
  715. found = true;
  716. }
  717. if (bestppm >= 10 && ppm < bestppm - 10) {
  718. bestppm = ppm;
  719. *best_clock = clock;
  720. found = true;
  721. }
  722. }
  723. }
  724. }
  725. }
  726. return found;
  727. }
  728. static bool
  729. chv_find_best_dpll(const intel_limit_t *limit, struct drm_crtc *crtc,
  730. int target, int refclk, intel_clock_t *match_clock,
  731. intel_clock_t *best_clock)
  732. {
  733. struct drm_device *dev = crtc->dev;
  734. intel_clock_t clock;
  735. uint64_t m2;
  736. int found = false;
  737. memset(best_clock, 0, sizeof(*best_clock));
  738. /*
  739. * Based on hardware doc, the n always set to 1, and m1 always
  740. * set to 2. If requires to support 200Mhz refclk, we need to
  741. * revisit this because n may not 1 anymore.
  742. */
  743. clock.n = 1, clock.m1 = 2;
  744. target *= 5; /* fast clock */
  745. for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
  746. for (clock.p2 = limit->p2.p2_fast;
  747. clock.p2 >= limit->p2.p2_slow;
  748. clock.p2 -= clock.p2 > 10 ? 2 : 1) {
  749. clock.p = clock.p1 * clock.p2;
  750. m2 = DIV_ROUND_CLOSEST_ULL(((uint64_t)target * clock.p *
  751. clock.n) << 22, refclk * clock.m1);
  752. if (m2 > INT_MAX/clock.m1)
  753. continue;
  754. clock.m2 = m2;
  755. chv_clock(refclk, &clock);
  756. if (!intel_PLL_is_valid(dev, limit, &clock))
  757. continue;
  758. /* based on hardware requirement, prefer bigger p
  759. */
  760. if (clock.p > best_clock->p) {
  761. *best_clock = clock;
  762. found = true;
  763. }
  764. }
  765. }
  766. return found;
  767. }
  768. bool intel_crtc_active(struct drm_crtc *crtc)
  769. {
  770. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  771. /* Be paranoid as we can arrive here with only partial
  772. * state retrieved from the hardware during setup.
  773. *
  774. * We can ditch the adjusted_mode.crtc_clock check as soon
  775. * as Haswell has gained clock readout/fastboot support.
  776. *
  777. * We can ditch the crtc->primary->fb check as soon as we can
  778. * properly reconstruct framebuffers.
  779. */
  780. return intel_crtc->active && crtc->primary->fb &&
  781. intel_crtc->config.adjusted_mode.crtc_clock;
  782. }
  783. enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv,
  784. enum pipe pipe)
  785. {
  786. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  787. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  788. return intel_crtc->config.cpu_transcoder;
  789. }
  790. /**
  791. * intel_wait_for_vblank - wait for vblank on a given pipe
  792. * @dev: drm device
  793. * @pipe: pipe to wait for
  794. *
  795. * Wait for vblank to occur on a given pipe. Needed for various bits of
  796. * mode setting code.
  797. */
  798. void intel_wait_for_vblank(struct drm_device *dev, int pipe)
  799. {
  800. drm_wait_one_vblank(dev, pipe);
  801. }
  802. static bool pipe_dsl_stopped(struct drm_device *dev, enum pipe pipe)
  803. {
  804. struct drm_i915_private *dev_priv = dev->dev_private;
  805. u32 reg = PIPEDSL(pipe);
  806. u32 line1, line2;
  807. u32 line_mask;
  808. if (IS_GEN2(dev))
  809. line_mask = DSL_LINEMASK_GEN2;
  810. else
  811. line_mask = DSL_LINEMASK_GEN3;
  812. line1 = I915_READ(reg) & line_mask;
  813. mdelay(5);
  814. line2 = I915_READ(reg) & line_mask;
  815. return line1 == line2;
  816. }
  817. /*
  818. * intel_wait_for_pipe_off - wait for pipe to turn off
  819. * @crtc: crtc whose pipe to wait for
  820. *
  821. * After disabling a pipe, we can't wait for vblank in the usual way,
  822. * spinning on the vblank interrupt status bit, since we won't actually
  823. * see an interrupt when the pipe is disabled.
  824. *
  825. * On Gen4 and above:
  826. * wait for the pipe register state bit to turn off
  827. *
  828. * Otherwise:
  829. * wait for the display line value to settle (it usually
  830. * ends up stopping at the start of the next frame).
  831. *
  832. */
  833. static void intel_wait_for_pipe_off(struct intel_crtc *crtc)
  834. {
  835. struct drm_device *dev = crtc->base.dev;
  836. struct drm_i915_private *dev_priv = dev->dev_private;
  837. enum transcoder cpu_transcoder = crtc->config.cpu_transcoder;
  838. enum pipe pipe = crtc->pipe;
  839. if (INTEL_INFO(dev)->gen >= 4) {
  840. int reg = PIPECONF(cpu_transcoder);
  841. /* Wait for the Pipe State to go off */
  842. if (wait_for((I915_READ(reg) & I965_PIPECONF_ACTIVE) == 0,
  843. 100))
  844. WARN(1, "pipe_off wait timed out\n");
  845. } else {
  846. /* Wait for the display line to settle */
  847. if (wait_for(pipe_dsl_stopped(dev, pipe), 100))
  848. WARN(1, "pipe_off wait timed out\n");
  849. }
  850. }
  851. /*
  852. * ibx_digital_port_connected - is the specified port connected?
  853. * @dev_priv: i915 private structure
  854. * @port: the port to test
  855. *
  856. * Returns true if @port is connected, false otherwise.
  857. */
  858. bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
  859. struct intel_digital_port *port)
  860. {
  861. u32 bit;
  862. if (HAS_PCH_IBX(dev_priv->dev)) {
  863. switch (port->port) {
  864. case PORT_B:
  865. bit = SDE_PORTB_HOTPLUG;
  866. break;
  867. case PORT_C:
  868. bit = SDE_PORTC_HOTPLUG;
  869. break;
  870. case PORT_D:
  871. bit = SDE_PORTD_HOTPLUG;
  872. break;
  873. default:
  874. return true;
  875. }
  876. } else {
  877. switch (port->port) {
  878. case PORT_B:
  879. bit = SDE_PORTB_HOTPLUG_CPT;
  880. break;
  881. case PORT_C:
  882. bit = SDE_PORTC_HOTPLUG_CPT;
  883. break;
  884. case PORT_D:
  885. bit = SDE_PORTD_HOTPLUG_CPT;
  886. break;
  887. default:
  888. return true;
  889. }
  890. }
  891. return I915_READ(SDEISR) & bit;
  892. }
  893. static const char *state_string(bool enabled)
  894. {
  895. return enabled ? "on" : "off";
  896. }
  897. /* Only for pre-ILK configs */
  898. void assert_pll(struct drm_i915_private *dev_priv,
  899. enum pipe pipe, bool state)
  900. {
  901. int reg;
  902. u32 val;
  903. bool cur_state;
  904. reg = DPLL(pipe);
  905. val = I915_READ(reg);
  906. cur_state = !!(val & DPLL_VCO_ENABLE);
  907. WARN(cur_state != state,
  908. "PLL state assertion failure (expected %s, current %s)\n",
  909. state_string(state), state_string(cur_state));
  910. }
  911. /* XXX: the dsi pll is shared between MIPI DSI ports */
  912. static void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state)
  913. {
  914. u32 val;
  915. bool cur_state;
  916. mutex_lock(&dev_priv->dpio_lock);
  917. val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL);
  918. mutex_unlock(&dev_priv->dpio_lock);
  919. cur_state = val & DSI_PLL_VCO_EN;
  920. WARN(cur_state != state,
  921. "DSI PLL state assertion failure (expected %s, current %s)\n",
  922. state_string(state), state_string(cur_state));
  923. }
  924. #define assert_dsi_pll_enabled(d) assert_dsi_pll(d, true)
  925. #define assert_dsi_pll_disabled(d) assert_dsi_pll(d, false)
  926. struct intel_shared_dpll *
  927. intel_crtc_to_shared_dpll(struct intel_crtc *crtc)
  928. {
  929. struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
  930. if (crtc->config.shared_dpll < 0)
  931. return NULL;
  932. return &dev_priv->shared_dplls[crtc->config.shared_dpll];
  933. }
  934. /* For ILK+ */
  935. void assert_shared_dpll(struct drm_i915_private *dev_priv,
  936. struct intel_shared_dpll *pll,
  937. bool state)
  938. {
  939. bool cur_state;
  940. struct intel_dpll_hw_state hw_state;
  941. if (WARN (!pll,
  942. "asserting DPLL %s with no DPLL\n", state_string(state)))
  943. return;
  944. cur_state = pll->get_hw_state(dev_priv, pll, &hw_state);
  945. WARN(cur_state != state,
  946. "%s assertion failure (expected %s, current %s)\n",
  947. pll->name, state_string(state), state_string(cur_state));
  948. }
  949. static void assert_fdi_tx(struct drm_i915_private *dev_priv,
  950. enum pipe pipe, bool state)
  951. {
  952. int reg;
  953. u32 val;
  954. bool cur_state;
  955. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  956. pipe);
  957. if (HAS_DDI(dev_priv->dev)) {
  958. /* DDI does not have a specific FDI_TX register */
  959. reg = TRANS_DDI_FUNC_CTL(cpu_transcoder);
  960. val = I915_READ(reg);
  961. cur_state = !!(val & TRANS_DDI_FUNC_ENABLE);
  962. } else {
  963. reg = FDI_TX_CTL(pipe);
  964. val = I915_READ(reg);
  965. cur_state = !!(val & FDI_TX_ENABLE);
  966. }
  967. WARN(cur_state != state,
  968. "FDI TX state assertion failure (expected %s, current %s)\n",
  969. state_string(state), state_string(cur_state));
  970. }
  971. #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
  972. #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
  973. static void assert_fdi_rx(struct drm_i915_private *dev_priv,
  974. enum pipe pipe, bool state)
  975. {
  976. int reg;
  977. u32 val;
  978. bool cur_state;
  979. reg = FDI_RX_CTL(pipe);
  980. val = I915_READ(reg);
  981. cur_state = !!(val & FDI_RX_ENABLE);
  982. WARN(cur_state != state,
  983. "FDI RX state assertion failure (expected %s, current %s)\n",
  984. state_string(state), state_string(cur_state));
  985. }
  986. #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
  987. #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
  988. static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv,
  989. enum pipe pipe)
  990. {
  991. int reg;
  992. u32 val;
  993. /* ILK FDI PLL is always enabled */
  994. if (INTEL_INFO(dev_priv->dev)->gen == 5)
  995. return;
  996. /* On Haswell, DDI ports are responsible for the FDI PLL setup */
  997. if (HAS_DDI(dev_priv->dev))
  998. return;
  999. reg = FDI_TX_CTL(pipe);
  1000. val = I915_READ(reg);
  1001. WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n");
  1002. }
  1003. void assert_fdi_rx_pll(struct drm_i915_private *dev_priv,
  1004. enum pipe pipe, bool state)
  1005. {
  1006. int reg;
  1007. u32 val;
  1008. bool cur_state;
  1009. reg = FDI_RX_CTL(pipe);
  1010. val = I915_READ(reg);
  1011. cur_state = !!(val & FDI_RX_PLL_ENABLE);
  1012. WARN(cur_state != state,
  1013. "FDI RX PLL assertion failure (expected %s, current %s)\n",
  1014. state_string(state), state_string(cur_state));
  1015. }
  1016. static void assert_panel_unlocked(struct drm_i915_private *dev_priv,
  1017. enum pipe pipe)
  1018. {
  1019. struct drm_device *dev = dev_priv->dev;
  1020. int pp_reg;
  1021. u32 val;
  1022. enum pipe panel_pipe = PIPE_A;
  1023. bool locked = true;
  1024. if (WARN_ON(HAS_DDI(dev)))
  1025. return;
  1026. if (HAS_PCH_SPLIT(dev)) {
  1027. u32 port_sel;
  1028. pp_reg = PCH_PP_CONTROL;
  1029. port_sel = I915_READ(PCH_PP_ON_DELAYS) & PANEL_PORT_SELECT_MASK;
  1030. if (port_sel == PANEL_PORT_SELECT_LVDS &&
  1031. I915_READ(PCH_LVDS) & LVDS_PIPEB_SELECT)
  1032. panel_pipe = PIPE_B;
  1033. /* XXX: else fix for eDP */
  1034. } else if (IS_VALLEYVIEW(dev)) {
  1035. /* presumably write lock depends on pipe, not port select */
  1036. pp_reg = VLV_PIPE_PP_CONTROL(pipe);
  1037. panel_pipe = pipe;
  1038. } else {
  1039. pp_reg = PP_CONTROL;
  1040. if (I915_READ(LVDS) & LVDS_PIPEB_SELECT)
  1041. panel_pipe = PIPE_B;
  1042. }
  1043. val = I915_READ(pp_reg);
  1044. if (!(val & PANEL_POWER_ON) ||
  1045. ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS))
  1046. locked = false;
  1047. WARN(panel_pipe == pipe && locked,
  1048. "panel assertion failure, pipe %c regs locked\n",
  1049. pipe_name(pipe));
  1050. }
  1051. static void assert_cursor(struct drm_i915_private *dev_priv,
  1052. enum pipe pipe, bool state)
  1053. {
  1054. struct drm_device *dev = dev_priv->dev;
  1055. bool cur_state;
  1056. if (IS_845G(dev) || IS_I865G(dev))
  1057. cur_state = I915_READ(_CURACNTR) & CURSOR_ENABLE;
  1058. else
  1059. cur_state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
  1060. WARN(cur_state != state,
  1061. "cursor on pipe %c assertion failure (expected %s, current %s)\n",
  1062. pipe_name(pipe), state_string(state), state_string(cur_state));
  1063. }
  1064. #define assert_cursor_enabled(d, p) assert_cursor(d, p, true)
  1065. #define assert_cursor_disabled(d, p) assert_cursor(d, p, false)
  1066. void assert_pipe(struct drm_i915_private *dev_priv,
  1067. enum pipe pipe, bool state)
  1068. {
  1069. int reg;
  1070. u32 val;
  1071. bool cur_state;
  1072. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  1073. pipe);
  1074. /* if we need the pipe quirk it must be always on */
  1075. if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) ||
  1076. (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))
  1077. state = true;
  1078. if (!intel_display_power_enabled(dev_priv,
  1079. POWER_DOMAIN_TRANSCODER(cpu_transcoder))) {
  1080. cur_state = false;
  1081. } else {
  1082. reg = PIPECONF(cpu_transcoder);
  1083. val = I915_READ(reg);
  1084. cur_state = !!(val & PIPECONF_ENABLE);
  1085. }
  1086. WARN(cur_state != state,
  1087. "pipe %c assertion failure (expected %s, current %s)\n",
  1088. pipe_name(pipe), state_string(state), state_string(cur_state));
  1089. }
  1090. static void assert_plane(struct drm_i915_private *dev_priv,
  1091. enum plane plane, bool state)
  1092. {
  1093. int reg;
  1094. u32 val;
  1095. bool cur_state;
  1096. reg = DSPCNTR(plane);
  1097. val = I915_READ(reg);
  1098. cur_state = !!(val & DISPLAY_PLANE_ENABLE);
  1099. WARN(cur_state != state,
  1100. "plane %c assertion failure (expected %s, current %s)\n",
  1101. plane_name(plane), state_string(state), state_string(cur_state));
  1102. }
  1103. #define assert_plane_enabled(d, p) assert_plane(d, p, true)
  1104. #define assert_plane_disabled(d, p) assert_plane(d, p, false)
  1105. static void assert_planes_disabled(struct drm_i915_private *dev_priv,
  1106. enum pipe pipe)
  1107. {
  1108. struct drm_device *dev = dev_priv->dev;
  1109. int reg, i;
  1110. u32 val;
  1111. int cur_pipe;
  1112. /* Primary planes are fixed to pipes on gen4+ */
  1113. if (INTEL_INFO(dev)->gen >= 4) {
  1114. reg = DSPCNTR(pipe);
  1115. val = I915_READ(reg);
  1116. WARN(val & DISPLAY_PLANE_ENABLE,
  1117. "plane %c assertion failure, should be disabled but not\n",
  1118. plane_name(pipe));
  1119. return;
  1120. }
  1121. /* Need to check both planes against the pipe */
  1122. for_each_pipe(dev_priv, i) {
  1123. reg = DSPCNTR(i);
  1124. val = I915_READ(reg);
  1125. cur_pipe = (val & DISPPLANE_SEL_PIPE_MASK) >>
  1126. DISPPLANE_SEL_PIPE_SHIFT;
  1127. WARN((val & DISPLAY_PLANE_ENABLE) && pipe == cur_pipe,
  1128. "plane %c assertion failure, should be off on pipe %c but is still active\n",
  1129. plane_name(i), pipe_name(pipe));
  1130. }
  1131. }
  1132. static void assert_sprites_disabled(struct drm_i915_private *dev_priv,
  1133. enum pipe pipe)
  1134. {
  1135. struct drm_device *dev = dev_priv->dev;
  1136. int reg, sprite;
  1137. u32 val;
  1138. if (IS_VALLEYVIEW(dev)) {
  1139. for_each_sprite(pipe, sprite) {
  1140. reg = SPCNTR(pipe, sprite);
  1141. val = I915_READ(reg);
  1142. WARN(val & SP_ENABLE,
  1143. "sprite %c assertion failure, should be off on pipe %c but is still active\n",
  1144. sprite_name(pipe, sprite), pipe_name(pipe));
  1145. }
  1146. } else if (INTEL_INFO(dev)->gen >= 7) {
  1147. reg = SPRCTL(pipe);
  1148. val = I915_READ(reg);
  1149. WARN(val & SPRITE_ENABLE,
  1150. "sprite %c assertion failure, should be off on pipe %c but is still active\n",
  1151. plane_name(pipe), pipe_name(pipe));
  1152. } else if (INTEL_INFO(dev)->gen >= 5) {
  1153. reg = DVSCNTR(pipe);
  1154. val = I915_READ(reg);
  1155. WARN(val & DVS_ENABLE,
  1156. "sprite %c assertion failure, should be off on pipe %c but is still active\n",
  1157. plane_name(pipe), pipe_name(pipe));
  1158. }
  1159. }
  1160. static void assert_vblank_disabled(struct drm_crtc *crtc)
  1161. {
  1162. if (WARN_ON(drm_crtc_vblank_get(crtc) == 0))
  1163. drm_crtc_vblank_put(crtc);
  1164. }
  1165. static void ibx_assert_pch_refclk_enabled(struct drm_i915_private *dev_priv)
  1166. {
  1167. u32 val;
  1168. bool enabled;
  1169. WARN_ON(!(HAS_PCH_IBX(dev_priv->dev) || HAS_PCH_CPT(dev_priv->dev)));
  1170. val = I915_READ(PCH_DREF_CONTROL);
  1171. enabled = !!(val & (DREF_SSC_SOURCE_MASK | DREF_NONSPREAD_SOURCE_MASK |
  1172. DREF_SUPERSPREAD_SOURCE_MASK));
  1173. WARN(!enabled, "PCH refclk assertion failure, should be active but is disabled\n");
  1174. }
  1175. static void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv,
  1176. enum pipe pipe)
  1177. {
  1178. int reg;
  1179. u32 val;
  1180. bool enabled;
  1181. reg = PCH_TRANSCONF(pipe);
  1182. val = I915_READ(reg);
  1183. enabled = !!(val & TRANS_ENABLE);
  1184. WARN(enabled,
  1185. "transcoder assertion failed, should be off on pipe %c but is still active\n",
  1186. pipe_name(pipe));
  1187. }
  1188. static bool dp_pipe_enabled(struct drm_i915_private *dev_priv,
  1189. enum pipe pipe, u32 port_sel, u32 val)
  1190. {
  1191. if ((val & DP_PORT_EN) == 0)
  1192. return false;
  1193. if (HAS_PCH_CPT(dev_priv->dev)) {
  1194. u32 trans_dp_ctl_reg = TRANS_DP_CTL(pipe);
  1195. u32 trans_dp_ctl = I915_READ(trans_dp_ctl_reg);
  1196. if ((trans_dp_ctl & TRANS_DP_PORT_SEL_MASK) != port_sel)
  1197. return false;
  1198. } else if (IS_CHERRYVIEW(dev_priv->dev)) {
  1199. if ((val & DP_PIPE_MASK_CHV) != DP_PIPE_SELECT_CHV(pipe))
  1200. return false;
  1201. } else {
  1202. if ((val & DP_PIPE_MASK) != (pipe << 30))
  1203. return false;
  1204. }
  1205. return true;
  1206. }
  1207. static bool hdmi_pipe_enabled(struct drm_i915_private *dev_priv,
  1208. enum pipe pipe, u32 val)
  1209. {
  1210. if ((val & SDVO_ENABLE) == 0)
  1211. return false;
  1212. if (HAS_PCH_CPT(dev_priv->dev)) {
  1213. if ((val & SDVO_PIPE_SEL_MASK_CPT) != SDVO_PIPE_SEL_CPT(pipe))
  1214. return false;
  1215. } else if (IS_CHERRYVIEW(dev_priv->dev)) {
  1216. if ((val & SDVO_PIPE_SEL_MASK_CHV) != SDVO_PIPE_SEL_CHV(pipe))
  1217. return false;
  1218. } else {
  1219. if ((val & SDVO_PIPE_SEL_MASK) != SDVO_PIPE_SEL(pipe))
  1220. return false;
  1221. }
  1222. return true;
  1223. }
  1224. static bool lvds_pipe_enabled(struct drm_i915_private *dev_priv,
  1225. enum pipe pipe, u32 val)
  1226. {
  1227. if ((val & LVDS_PORT_EN) == 0)
  1228. return false;
  1229. if (HAS_PCH_CPT(dev_priv->dev)) {
  1230. if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe))
  1231. return false;
  1232. } else {
  1233. if ((val & LVDS_PIPE_MASK) != LVDS_PIPE(pipe))
  1234. return false;
  1235. }
  1236. return true;
  1237. }
  1238. static bool adpa_pipe_enabled(struct drm_i915_private *dev_priv,
  1239. enum pipe pipe, u32 val)
  1240. {
  1241. if ((val & ADPA_DAC_ENABLE) == 0)
  1242. return false;
  1243. if (HAS_PCH_CPT(dev_priv->dev)) {
  1244. if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe))
  1245. return false;
  1246. } else {
  1247. if ((val & ADPA_PIPE_SELECT_MASK) != ADPA_PIPE_SELECT(pipe))
  1248. return false;
  1249. }
  1250. return true;
  1251. }
  1252. static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv,
  1253. enum pipe pipe, int reg, u32 port_sel)
  1254. {
  1255. u32 val = I915_READ(reg);
  1256. WARN(dp_pipe_enabled(dev_priv, pipe, port_sel, val),
  1257. "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n",
  1258. reg, pipe_name(pipe));
  1259. WARN(HAS_PCH_IBX(dev_priv->dev) && (val & DP_PORT_EN) == 0
  1260. && (val & DP_PIPEB_SELECT),
  1261. "IBX PCH dp port still using transcoder B\n");
  1262. }
  1263. static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv,
  1264. enum pipe pipe, int reg)
  1265. {
  1266. u32 val = I915_READ(reg);
  1267. WARN(hdmi_pipe_enabled(dev_priv, pipe, val),
  1268. "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n",
  1269. reg, pipe_name(pipe));
  1270. WARN(HAS_PCH_IBX(dev_priv->dev) && (val & SDVO_ENABLE) == 0
  1271. && (val & SDVO_PIPE_B_SELECT),
  1272. "IBX PCH hdmi port still using transcoder B\n");
  1273. }
  1274. static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv,
  1275. enum pipe pipe)
  1276. {
  1277. int reg;
  1278. u32 val;
  1279. assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_B, TRANS_DP_PORT_SEL_B);
  1280. assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_C, TRANS_DP_PORT_SEL_C);
  1281. assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_D, TRANS_DP_PORT_SEL_D);
  1282. reg = PCH_ADPA;
  1283. val = I915_READ(reg);
  1284. WARN(adpa_pipe_enabled(dev_priv, pipe, val),
  1285. "PCH VGA enabled on transcoder %c, should be disabled\n",
  1286. pipe_name(pipe));
  1287. reg = PCH_LVDS;
  1288. val = I915_READ(reg);
  1289. WARN(lvds_pipe_enabled(dev_priv, pipe, val),
  1290. "PCH LVDS enabled on transcoder %c, should be disabled\n",
  1291. pipe_name(pipe));
  1292. assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIB);
  1293. assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIC);
  1294. assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMID);
  1295. }
  1296. static void intel_init_dpio(struct drm_device *dev)
  1297. {
  1298. struct drm_i915_private *dev_priv = dev->dev_private;
  1299. if (!IS_VALLEYVIEW(dev))
  1300. return;
  1301. /*
  1302. * IOSF_PORT_DPIO is used for VLV x2 PHY (DP/HDMI B and C),
  1303. * CHV x1 PHY (DP/HDMI D)
  1304. * IOSF_PORT_DPIO_2 is used for CHV x2 PHY (DP/HDMI B and C)
  1305. */
  1306. if (IS_CHERRYVIEW(dev)) {
  1307. DPIO_PHY_IOSF_PORT(DPIO_PHY0) = IOSF_PORT_DPIO_2;
  1308. DPIO_PHY_IOSF_PORT(DPIO_PHY1) = IOSF_PORT_DPIO;
  1309. } else {
  1310. DPIO_PHY_IOSF_PORT(DPIO_PHY0) = IOSF_PORT_DPIO;
  1311. }
  1312. }
  1313. static void vlv_enable_pll(struct intel_crtc *crtc)
  1314. {
  1315. struct drm_device *dev = crtc->base.dev;
  1316. struct drm_i915_private *dev_priv = dev->dev_private;
  1317. int reg = DPLL(crtc->pipe);
  1318. u32 dpll = crtc->config.dpll_hw_state.dpll;
  1319. assert_pipe_disabled(dev_priv, crtc->pipe);
  1320. /* No really, not for ILK+ */
  1321. BUG_ON(!IS_VALLEYVIEW(dev_priv->dev));
  1322. /* PLL is protected by panel, make sure we can write it */
  1323. if (IS_MOBILE(dev_priv->dev))
  1324. assert_panel_unlocked(dev_priv, crtc->pipe);
  1325. I915_WRITE(reg, dpll);
  1326. POSTING_READ(reg);
  1327. udelay(150);
  1328. if (wait_for(((I915_READ(reg) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1))
  1329. DRM_ERROR("DPLL %d failed to lock\n", crtc->pipe);
  1330. I915_WRITE(DPLL_MD(crtc->pipe), crtc->config.dpll_hw_state.dpll_md);
  1331. POSTING_READ(DPLL_MD(crtc->pipe));
  1332. /* We do this three times for luck */
  1333. I915_WRITE(reg, dpll);
  1334. POSTING_READ(reg);
  1335. udelay(150); /* wait for warmup */
  1336. I915_WRITE(reg, dpll);
  1337. POSTING_READ(reg);
  1338. udelay(150); /* wait for warmup */
  1339. I915_WRITE(reg, dpll);
  1340. POSTING_READ(reg);
  1341. udelay(150); /* wait for warmup */
  1342. }
  1343. static void chv_enable_pll(struct intel_crtc *crtc)
  1344. {
  1345. struct drm_device *dev = crtc->base.dev;
  1346. struct drm_i915_private *dev_priv = dev->dev_private;
  1347. int pipe = crtc->pipe;
  1348. enum dpio_channel port = vlv_pipe_to_channel(pipe);
  1349. u32 tmp;
  1350. assert_pipe_disabled(dev_priv, crtc->pipe);
  1351. BUG_ON(!IS_CHERRYVIEW(dev_priv->dev));
  1352. mutex_lock(&dev_priv->dpio_lock);
  1353. /* Enable back the 10bit clock to display controller */
  1354. tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
  1355. tmp |= DPIO_DCLKP_EN;
  1356. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp);
  1357. /*
  1358. * Need to wait > 100ns between dclkp clock enable bit and PLL enable.
  1359. */
  1360. udelay(1);
  1361. /* Enable PLL */
  1362. I915_WRITE(DPLL(pipe), crtc->config.dpll_hw_state.dpll);
  1363. /* Check PLL is locked */
  1364. if (wait_for(((I915_READ(DPLL(pipe)) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1))
  1365. DRM_ERROR("PLL %d failed to lock\n", pipe);
  1366. /* not sure when this should be written */
  1367. I915_WRITE(DPLL_MD(pipe), crtc->config.dpll_hw_state.dpll_md);
  1368. POSTING_READ(DPLL_MD(pipe));
  1369. mutex_unlock(&dev_priv->dpio_lock);
  1370. }
  1371. static int intel_num_dvo_pipes(struct drm_device *dev)
  1372. {
  1373. struct intel_crtc *crtc;
  1374. int count = 0;
  1375. for_each_intel_crtc(dev, crtc)
  1376. count += crtc->active &&
  1377. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DVO);
  1378. return count;
  1379. }
  1380. static void i9xx_enable_pll(struct intel_crtc *crtc)
  1381. {
  1382. struct drm_device *dev = crtc->base.dev;
  1383. struct drm_i915_private *dev_priv = dev->dev_private;
  1384. int reg = DPLL(crtc->pipe);
  1385. u32 dpll = crtc->config.dpll_hw_state.dpll;
  1386. assert_pipe_disabled(dev_priv, crtc->pipe);
  1387. /* No really, not for ILK+ */
  1388. BUG_ON(INTEL_INFO(dev)->gen >= 5);
  1389. /* PLL is protected by panel, make sure we can write it */
  1390. if (IS_MOBILE(dev) && !IS_I830(dev))
  1391. assert_panel_unlocked(dev_priv, crtc->pipe);
  1392. /* Enable DVO 2x clock on both PLLs if necessary */
  1393. if (IS_I830(dev) && intel_num_dvo_pipes(dev) > 0) {
  1394. /*
  1395. * It appears to be important that we don't enable this
  1396. * for the current pipe before otherwise configuring the
  1397. * PLL. No idea how this should be handled if multiple
  1398. * DVO outputs are enabled simultaneosly.
  1399. */
  1400. dpll |= DPLL_DVO_2X_MODE;
  1401. I915_WRITE(DPLL(!crtc->pipe),
  1402. I915_READ(DPLL(!crtc->pipe)) | DPLL_DVO_2X_MODE);
  1403. }
  1404. /* Wait for the clocks to stabilize. */
  1405. POSTING_READ(reg);
  1406. udelay(150);
  1407. if (INTEL_INFO(dev)->gen >= 4) {
  1408. I915_WRITE(DPLL_MD(crtc->pipe),
  1409. crtc->config.dpll_hw_state.dpll_md);
  1410. } else {
  1411. /* The pixel multiplier can only be updated once the
  1412. * DPLL is enabled and the clocks are stable.
  1413. *
  1414. * So write it again.
  1415. */
  1416. I915_WRITE(reg, dpll);
  1417. }
  1418. /* We do this three times for luck */
  1419. I915_WRITE(reg, dpll);
  1420. POSTING_READ(reg);
  1421. udelay(150); /* wait for warmup */
  1422. I915_WRITE(reg, dpll);
  1423. POSTING_READ(reg);
  1424. udelay(150); /* wait for warmup */
  1425. I915_WRITE(reg, dpll);
  1426. POSTING_READ(reg);
  1427. udelay(150); /* wait for warmup */
  1428. }
  1429. /**
  1430. * i9xx_disable_pll - disable a PLL
  1431. * @dev_priv: i915 private structure
  1432. * @pipe: pipe PLL to disable
  1433. *
  1434. * Disable the PLL for @pipe, making sure the pipe is off first.
  1435. *
  1436. * Note! This is for pre-ILK only.
  1437. */
  1438. static void i9xx_disable_pll(struct intel_crtc *crtc)
  1439. {
  1440. struct drm_device *dev = crtc->base.dev;
  1441. struct drm_i915_private *dev_priv = dev->dev_private;
  1442. enum pipe pipe = crtc->pipe;
  1443. /* Disable DVO 2x clock on both PLLs if necessary */
  1444. if (IS_I830(dev) &&
  1445. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DVO) &&
  1446. intel_num_dvo_pipes(dev) == 1) {
  1447. I915_WRITE(DPLL(PIPE_B),
  1448. I915_READ(DPLL(PIPE_B)) & ~DPLL_DVO_2X_MODE);
  1449. I915_WRITE(DPLL(PIPE_A),
  1450. I915_READ(DPLL(PIPE_A)) & ~DPLL_DVO_2X_MODE);
  1451. }
  1452. /* Don't disable pipe or pipe PLLs if needed */
  1453. if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) ||
  1454. (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))
  1455. return;
  1456. /* Make sure the pipe isn't still relying on us */
  1457. assert_pipe_disabled(dev_priv, pipe);
  1458. I915_WRITE(DPLL(pipe), 0);
  1459. POSTING_READ(DPLL(pipe));
  1460. }
  1461. static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
  1462. {
  1463. u32 val = 0;
  1464. /* Make sure the pipe isn't still relying on us */
  1465. assert_pipe_disabled(dev_priv, pipe);
  1466. /*
  1467. * Leave integrated clock source and reference clock enabled for pipe B.
  1468. * The latter is needed for VGA hotplug / manual detection.
  1469. */
  1470. if (pipe == PIPE_B)
  1471. val = DPLL_INTEGRATED_CRI_CLK_VLV | DPLL_REFA_CLK_ENABLE_VLV;
  1472. I915_WRITE(DPLL(pipe), val);
  1473. POSTING_READ(DPLL(pipe));
  1474. }
  1475. static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
  1476. {
  1477. enum dpio_channel port = vlv_pipe_to_channel(pipe);
  1478. u32 val;
  1479. /* Make sure the pipe isn't still relying on us */
  1480. assert_pipe_disabled(dev_priv, pipe);
  1481. /* Set PLL en = 0 */
  1482. val = DPLL_SSC_REF_CLOCK_CHV | DPLL_REFA_CLK_ENABLE_VLV;
  1483. if (pipe != PIPE_A)
  1484. val |= DPLL_INTEGRATED_CRI_CLK_VLV;
  1485. I915_WRITE(DPLL(pipe), val);
  1486. POSTING_READ(DPLL(pipe));
  1487. mutex_lock(&dev_priv->dpio_lock);
  1488. /* Disable 10bit clock to display controller */
  1489. val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
  1490. val &= ~DPIO_DCLKP_EN;
  1491. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val);
  1492. /* disable left/right clock distribution */
  1493. if (pipe != PIPE_B) {
  1494. val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW5_CH0);
  1495. val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK);
  1496. vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW5_CH0, val);
  1497. } else {
  1498. val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW1_CH1);
  1499. val &= ~(CHV_BUFLEFTENA2_MASK | CHV_BUFRIGHTENA2_MASK);
  1500. vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW1_CH1, val);
  1501. }
  1502. mutex_unlock(&dev_priv->dpio_lock);
  1503. }
  1504. void vlv_wait_port_ready(struct drm_i915_private *dev_priv,
  1505. struct intel_digital_port *dport)
  1506. {
  1507. u32 port_mask;
  1508. int dpll_reg;
  1509. switch (dport->port) {
  1510. case PORT_B:
  1511. port_mask = DPLL_PORTB_READY_MASK;
  1512. dpll_reg = DPLL(0);
  1513. break;
  1514. case PORT_C:
  1515. port_mask = DPLL_PORTC_READY_MASK;
  1516. dpll_reg = DPLL(0);
  1517. break;
  1518. case PORT_D:
  1519. port_mask = DPLL_PORTD_READY_MASK;
  1520. dpll_reg = DPIO_PHY_STATUS;
  1521. break;
  1522. default:
  1523. BUG();
  1524. }
  1525. if (wait_for((I915_READ(dpll_reg) & port_mask) == 0, 1000))
  1526. WARN(1, "timed out waiting for port %c ready: 0x%08x\n",
  1527. port_name(dport->port), I915_READ(dpll_reg));
  1528. }
  1529. static void intel_prepare_shared_dpll(struct intel_crtc *crtc)
  1530. {
  1531. struct drm_device *dev = crtc->base.dev;
  1532. struct drm_i915_private *dev_priv = dev->dev_private;
  1533. struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
  1534. if (WARN_ON(pll == NULL))
  1535. return;
  1536. WARN_ON(!pll->refcount);
  1537. if (pll->active == 0) {
  1538. DRM_DEBUG_DRIVER("setting up %s\n", pll->name);
  1539. WARN_ON(pll->on);
  1540. assert_shared_dpll_disabled(dev_priv, pll);
  1541. pll->mode_set(dev_priv, pll);
  1542. }
  1543. }
  1544. /**
  1545. * intel_enable_shared_dpll - enable PCH PLL
  1546. * @dev_priv: i915 private structure
  1547. * @pipe: pipe PLL to enable
  1548. *
  1549. * The PCH PLL needs to be enabled before the PCH transcoder, since it
  1550. * drives the transcoder clock.
  1551. */
  1552. static void intel_enable_shared_dpll(struct intel_crtc *crtc)
  1553. {
  1554. struct drm_device *dev = crtc->base.dev;
  1555. struct drm_i915_private *dev_priv = dev->dev_private;
  1556. struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
  1557. if (WARN_ON(pll == NULL))
  1558. return;
  1559. if (WARN_ON(pll->refcount == 0))
  1560. return;
  1561. DRM_DEBUG_KMS("enable %s (active %d, on? %d) for crtc %d\n",
  1562. pll->name, pll->active, pll->on,
  1563. crtc->base.base.id);
  1564. if (pll->active++) {
  1565. WARN_ON(!pll->on);
  1566. assert_shared_dpll_enabled(dev_priv, pll);
  1567. return;
  1568. }
  1569. WARN_ON(pll->on);
  1570. intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS);
  1571. DRM_DEBUG_KMS("enabling %s\n", pll->name);
  1572. pll->enable(dev_priv, pll);
  1573. pll->on = true;
  1574. }
  1575. static void intel_disable_shared_dpll(struct intel_crtc *crtc)
  1576. {
  1577. struct drm_device *dev = crtc->base.dev;
  1578. struct drm_i915_private *dev_priv = dev->dev_private;
  1579. struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
  1580. /* PCH only available on ILK+ */
  1581. BUG_ON(INTEL_INFO(dev)->gen < 5);
  1582. if (WARN_ON(pll == NULL))
  1583. return;
  1584. if (WARN_ON(pll->refcount == 0))
  1585. return;
  1586. DRM_DEBUG_KMS("disable %s (active %d, on? %d) for crtc %d\n",
  1587. pll->name, pll->active, pll->on,
  1588. crtc->base.base.id);
  1589. if (WARN_ON(pll->active == 0)) {
  1590. assert_shared_dpll_disabled(dev_priv, pll);
  1591. return;
  1592. }
  1593. assert_shared_dpll_enabled(dev_priv, pll);
  1594. WARN_ON(!pll->on);
  1595. if (--pll->active)
  1596. return;
  1597. DRM_DEBUG_KMS("disabling %s\n", pll->name);
  1598. pll->disable(dev_priv, pll);
  1599. pll->on = false;
  1600. intel_display_power_put(dev_priv, POWER_DOMAIN_PLLS);
  1601. }
  1602. static void ironlake_enable_pch_transcoder(struct drm_i915_private *dev_priv,
  1603. enum pipe pipe)
  1604. {
  1605. struct drm_device *dev = dev_priv->dev;
  1606. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  1607. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1608. uint32_t reg, val, pipeconf_val;
  1609. /* PCH only available on ILK+ */
  1610. BUG_ON(!HAS_PCH_SPLIT(dev));
  1611. /* Make sure PCH DPLL is enabled */
  1612. assert_shared_dpll_enabled(dev_priv,
  1613. intel_crtc_to_shared_dpll(intel_crtc));
  1614. /* FDI must be feeding us bits for PCH ports */
  1615. assert_fdi_tx_enabled(dev_priv, pipe);
  1616. assert_fdi_rx_enabled(dev_priv, pipe);
  1617. if (HAS_PCH_CPT(dev)) {
  1618. /* Workaround: Set the timing override bit before enabling the
  1619. * pch transcoder. */
  1620. reg = TRANS_CHICKEN2(pipe);
  1621. val = I915_READ(reg);
  1622. val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
  1623. I915_WRITE(reg, val);
  1624. }
  1625. reg = PCH_TRANSCONF(pipe);
  1626. val = I915_READ(reg);
  1627. pipeconf_val = I915_READ(PIPECONF(pipe));
  1628. if (HAS_PCH_IBX(dev_priv->dev)) {
  1629. /*
  1630. * make the BPC in transcoder be consistent with
  1631. * that in pipeconf reg.
  1632. */
  1633. val &= ~PIPECONF_BPC_MASK;
  1634. val |= pipeconf_val & PIPECONF_BPC_MASK;
  1635. }
  1636. val &= ~TRANS_INTERLACE_MASK;
  1637. if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK)
  1638. if (HAS_PCH_IBX(dev_priv->dev) &&
  1639. intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO))
  1640. val |= TRANS_LEGACY_INTERLACED_ILK;
  1641. else
  1642. val |= TRANS_INTERLACED;
  1643. else
  1644. val |= TRANS_PROGRESSIVE;
  1645. I915_WRITE(reg, val | TRANS_ENABLE);
  1646. if (wait_for(I915_READ(reg) & TRANS_STATE_ENABLE, 100))
  1647. DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe));
  1648. }
  1649. static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv,
  1650. enum transcoder cpu_transcoder)
  1651. {
  1652. u32 val, pipeconf_val;
  1653. /* PCH only available on ILK+ */
  1654. BUG_ON(!HAS_PCH_SPLIT(dev_priv->dev));
  1655. /* FDI must be feeding us bits for PCH ports */
  1656. assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder);
  1657. assert_fdi_rx_enabled(dev_priv, TRANSCODER_A);
  1658. /* Workaround: set timing override bit. */
  1659. val = I915_READ(_TRANSA_CHICKEN2);
  1660. val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
  1661. I915_WRITE(_TRANSA_CHICKEN2, val);
  1662. val = TRANS_ENABLE;
  1663. pipeconf_val = I915_READ(PIPECONF(cpu_transcoder));
  1664. if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) ==
  1665. PIPECONF_INTERLACED_ILK)
  1666. val |= TRANS_INTERLACED;
  1667. else
  1668. val |= TRANS_PROGRESSIVE;
  1669. I915_WRITE(LPT_TRANSCONF, val);
  1670. if (wait_for(I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE, 100))
  1671. DRM_ERROR("Failed to enable PCH transcoder\n");
  1672. }
  1673. static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv,
  1674. enum pipe pipe)
  1675. {
  1676. struct drm_device *dev = dev_priv->dev;
  1677. uint32_t reg, val;
  1678. /* FDI relies on the transcoder */
  1679. assert_fdi_tx_disabled(dev_priv, pipe);
  1680. assert_fdi_rx_disabled(dev_priv, pipe);
  1681. /* Ports must be off as well */
  1682. assert_pch_ports_disabled(dev_priv, pipe);
  1683. reg = PCH_TRANSCONF(pipe);
  1684. val = I915_READ(reg);
  1685. val &= ~TRANS_ENABLE;
  1686. I915_WRITE(reg, val);
  1687. /* wait for PCH transcoder off, transcoder state */
  1688. if (wait_for((I915_READ(reg) & TRANS_STATE_ENABLE) == 0, 50))
  1689. DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe));
  1690. if (!HAS_PCH_IBX(dev)) {
  1691. /* Workaround: Clear the timing override chicken bit again. */
  1692. reg = TRANS_CHICKEN2(pipe);
  1693. val = I915_READ(reg);
  1694. val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
  1695. I915_WRITE(reg, val);
  1696. }
  1697. }
  1698. static void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv)
  1699. {
  1700. u32 val;
  1701. val = I915_READ(LPT_TRANSCONF);
  1702. val &= ~TRANS_ENABLE;
  1703. I915_WRITE(LPT_TRANSCONF, val);
  1704. /* wait for PCH transcoder off, transcoder state */
  1705. if (wait_for((I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE) == 0, 50))
  1706. DRM_ERROR("Failed to disable PCH transcoder\n");
  1707. /* Workaround: clear timing override bit. */
  1708. val = I915_READ(_TRANSA_CHICKEN2);
  1709. val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
  1710. I915_WRITE(_TRANSA_CHICKEN2, val);
  1711. }
  1712. /**
  1713. * intel_enable_pipe - enable a pipe, asserting requirements
  1714. * @crtc: crtc responsible for the pipe
  1715. *
  1716. * Enable @crtc's pipe, making sure that various hardware specific requirements
  1717. * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc.
  1718. */
  1719. static void intel_enable_pipe(struct intel_crtc *crtc)
  1720. {
  1721. struct drm_device *dev = crtc->base.dev;
  1722. struct drm_i915_private *dev_priv = dev->dev_private;
  1723. enum pipe pipe = crtc->pipe;
  1724. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  1725. pipe);
  1726. enum pipe pch_transcoder;
  1727. int reg;
  1728. u32 val;
  1729. assert_planes_disabled(dev_priv, pipe);
  1730. assert_cursor_disabled(dev_priv, pipe);
  1731. assert_sprites_disabled(dev_priv, pipe);
  1732. if (HAS_PCH_LPT(dev_priv->dev))
  1733. pch_transcoder = TRANSCODER_A;
  1734. else
  1735. pch_transcoder = pipe;
  1736. /*
  1737. * A pipe without a PLL won't actually be able to drive bits from
  1738. * a plane. On ILK+ the pipe PLLs are integrated, so we don't
  1739. * need the check.
  1740. */
  1741. if (!HAS_PCH_SPLIT(dev_priv->dev))
  1742. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DSI))
  1743. assert_dsi_pll_enabled(dev_priv);
  1744. else
  1745. assert_pll_enabled(dev_priv, pipe);
  1746. else {
  1747. if (crtc->config.has_pch_encoder) {
  1748. /* if driving the PCH, we need FDI enabled */
  1749. assert_fdi_rx_pll_enabled(dev_priv, pch_transcoder);
  1750. assert_fdi_tx_pll_enabled(dev_priv,
  1751. (enum pipe) cpu_transcoder);
  1752. }
  1753. /* FIXME: assert CPU port conditions for SNB+ */
  1754. }
  1755. reg = PIPECONF(cpu_transcoder);
  1756. val = I915_READ(reg);
  1757. if (val & PIPECONF_ENABLE) {
  1758. WARN_ON(!((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) ||
  1759. (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)));
  1760. return;
  1761. }
  1762. I915_WRITE(reg, val | PIPECONF_ENABLE);
  1763. POSTING_READ(reg);
  1764. }
  1765. /**
  1766. * intel_disable_pipe - disable a pipe, asserting requirements
  1767. * @crtc: crtc whose pipes is to be disabled
  1768. *
  1769. * Disable the pipe of @crtc, making sure that various hardware
  1770. * specific requirements are met, if applicable, e.g. plane
  1771. * disabled, panel fitter off, etc.
  1772. *
  1773. * Will wait until the pipe has shut down before returning.
  1774. */
  1775. static void intel_disable_pipe(struct intel_crtc *crtc)
  1776. {
  1777. struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
  1778. enum transcoder cpu_transcoder = crtc->config.cpu_transcoder;
  1779. enum pipe pipe = crtc->pipe;
  1780. int reg;
  1781. u32 val;
  1782. /*
  1783. * Make sure planes won't keep trying to pump pixels to us,
  1784. * or we might hang the display.
  1785. */
  1786. assert_planes_disabled(dev_priv, pipe);
  1787. assert_cursor_disabled(dev_priv, pipe);
  1788. assert_sprites_disabled(dev_priv, pipe);
  1789. reg = PIPECONF(cpu_transcoder);
  1790. val = I915_READ(reg);
  1791. if ((val & PIPECONF_ENABLE) == 0)
  1792. return;
  1793. /*
  1794. * Double wide has implications for planes
  1795. * so best keep it disabled when not needed.
  1796. */
  1797. if (crtc->config.double_wide)
  1798. val &= ~PIPECONF_DOUBLE_WIDE;
  1799. /* Don't disable pipe or pipe PLLs if needed */
  1800. if (!(pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) &&
  1801. !(pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))
  1802. val &= ~PIPECONF_ENABLE;
  1803. I915_WRITE(reg, val);
  1804. if ((val & PIPECONF_ENABLE) == 0)
  1805. intel_wait_for_pipe_off(crtc);
  1806. }
  1807. /*
  1808. * Plane regs are double buffered, going from enabled->disabled needs a
  1809. * trigger in order to latch. The display address reg provides this.
  1810. */
  1811. void intel_flush_primary_plane(struct drm_i915_private *dev_priv,
  1812. enum plane plane)
  1813. {
  1814. struct drm_device *dev = dev_priv->dev;
  1815. u32 reg = INTEL_INFO(dev)->gen >= 4 ? DSPSURF(plane) : DSPADDR(plane);
  1816. I915_WRITE(reg, I915_READ(reg));
  1817. POSTING_READ(reg);
  1818. }
  1819. /**
  1820. * intel_enable_primary_hw_plane - enable the primary plane on a given pipe
  1821. * @plane: plane to be enabled
  1822. * @crtc: crtc for the plane
  1823. *
  1824. * Enable @plane on @crtc, making sure that the pipe is running first.
  1825. */
  1826. static void intel_enable_primary_hw_plane(struct drm_plane *plane,
  1827. struct drm_crtc *crtc)
  1828. {
  1829. struct drm_device *dev = plane->dev;
  1830. struct drm_i915_private *dev_priv = dev->dev_private;
  1831. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1832. /* If the pipe isn't enabled, we can't pump pixels and may hang */
  1833. assert_pipe_enabled(dev_priv, intel_crtc->pipe);
  1834. if (intel_crtc->primary_enabled)
  1835. return;
  1836. intel_crtc->primary_enabled = true;
  1837. dev_priv->display.update_primary_plane(crtc, plane->fb,
  1838. crtc->x, crtc->y);
  1839. /*
  1840. * BDW signals flip done immediately if the plane
  1841. * is disabled, even if the plane enable is already
  1842. * armed to occur at the next vblank :(
  1843. */
  1844. if (IS_BROADWELL(dev))
  1845. intel_wait_for_vblank(dev, intel_crtc->pipe);
  1846. }
  1847. /**
  1848. * intel_disable_primary_hw_plane - disable the primary hardware plane
  1849. * @plane: plane to be disabled
  1850. * @crtc: crtc for the plane
  1851. *
  1852. * Disable @plane on @crtc, making sure that the pipe is running first.
  1853. */
  1854. static void intel_disable_primary_hw_plane(struct drm_plane *plane,
  1855. struct drm_crtc *crtc)
  1856. {
  1857. struct drm_device *dev = plane->dev;
  1858. struct drm_i915_private *dev_priv = dev->dev_private;
  1859. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1860. assert_pipe_enabled(dev_priv, intel_crtc->pipe);
  1861. if (!intel_crtc->primary_enabled)
  1862. return;
  1863. intel_crtc->primary_enabled = false;
  1864. dev_priv->display.update_primary_plane(crtc, plane->fb,
  1865. crtc->x, crtc->y);
  1866. }
  1867. static bool need_vtd_wa(struct drm_device *dev)
  1868. {
  1869. #ifdef CONFIG_INTEL_IOMMU
  1870. if (INTEL_INFO(dev)->gen >= 6 && intel_iommu_gfx_mapped)
  1871. return true;
  1872. #endif
  1873. return false;
  1874. }
  1875. static int intel_align_height(struct drm_device *dev, int height, bool tiled)
  1876. {
  1877. int tile_height;
  1878. tile_height = tiled ? (IS_GEN2(dev) ? 16 : 8) : 1;
  1879. return ALIGN(height, tile_height);
  1880. }
  1881. int
  1882. intel_pin_and_fence_fb_obj(struct drm_device *dev,
  1883. struct drm_i915_gem_object *obj,
  1884. struct intel_engine_cs *pipelined)
  1885. {
  1886. struct drm_i915_private *dev_priv = dev->dev_private;
  1887. u32 alignment;
  1888. int ret;
  1889. WARN_ON(!mutex_is_locked(&dev->struct_mutex));
  1890. switch (obj->tiling_mode) {
  1891. case I915_TILING_NONE:
  1892. if (IS_BROADWATER(dev) || IS_CRESTLINE(dev))
  1893. alignment = 128 * 1024;
  1894. else if (INTEL_INFO(dev)->gen >= 4)
  1895. alignment = 4 * 1024;
  1896. else
  1897. alignment = 64 * 1024;
  1898. break;
  1899. case I915_TILING_X:
  1900. /* pin() will align the object as required by fence */
  1901. alignment = 0;
  1902. break;
  1903. case I915_TILING_Y:
  1904. WARN(1, "Y tiled bo slipped through, driver bug!\n");
  1905. return -EINVAL;
  1906. default:
  1907. BUG();
  1908. }
  1909. /* Note that the w/a also requires 64 PTE of padding following the
  1910. * bo. We currently fill all unused PTE with the shadow page and so
  1911. * we should always have valid PTE following the scanout preventing
  1912. * the VT-d warning.
  1913. */
  1914. if (need_vtd_wa(dev) && alignment < 256 * 1024)
  1915. alignment = 256 * 1024;
  1916. /*
  1917. * Global gtt pte registers are special registers which actually forward
  1918. * writes to a chunk of system memory. Which means that there is no risk
  1919. * that the register values disappear as soon as we call
  1920. * intel_runtime_pm_put(), so it is correct to wrap only the
  1921. * pin/unpin/fence and not more.
  1922. */
  1923. intel_runtime_pm_get(dev_priv);
  1924. dev_priv->mm.interruptible = false;
  1925. ret = i915_gem_object_pin_to_display_plane(obj, alignment, pipelined);
  1926. if (ret)
  1927. goto err_interruptible;
  1928. /* Install a fence for tiled scan-out. Pre-i965 always needs a
  1929. * fence, whereas 965+ only requires a fence if using
  1930. * framebuffer compression. For simplicity, we always install
  1931. * a fence as the cost is not that onerous.
  1932. */
  1933. ret = i915_gem_object_get_fence(obj);
  1934. if (ret)
  1935. goto err_unpin;
  1936. i915_gem_object_pin_fence(obj);
  1937. dev_priv->mm.interruptible = true;
  1938. intel_runtime_pm_put(dev_priv);
  1939. return 0;
  1940. err_unpin:
  1941. i915_gem_object_unpin_from_display_plane(obj);
  1942. err_interruptible:
  1943. dev_priv->mm.interruptible = true;
  1944. intel_runtime_pm_put(dev_priv);
  1945. return ret;
  1946. }
  1947. void intel_unpin_fb_obj(struct drm_i915_gem_object *obj)
  1948. {
  1949. WARN_ON(!mutex_is_locked(&obj->base.dev->struct_mutex));
  1950. i915_gem_object_unpin_fence(obj);
  1951. i915_gem_object_unpin_from_display_plane(obj);
  1952. }
  1953. /* Computes the linear offset to the base tile and adjusts x, y. bytes per pixel
  1954. * is assumed to be a power-of-two. */
  1955. unsigned long intel_gen4_compute_page_offset(int *x, int *y,
  1956. unsigned int tiling_mode,
  1957. unsigned int cpp,
  1958. unsigned int pitch)
  1959. {
  1960. if (tiling_mode != I915_TILING_NONE) {
  1961. unsigned int tile_rows, tiles;
  1962. tile_rows = *y / 8;
  1963. *y %= 8;
  1964. tiles = *x / (512/cpp);
  1965. *x %= 512/cpp;
  1966. return tile_rows * pitch * 8 + tiles * 4096;
  1967. } else {
  1968. unsigned int offset;
  1969. offset = *y * pitch + *x * cpp;
  1970. *y = 0;
  1971. *x = (offset & 4095) / cpp;
  1972. return offset & -4096;
  1973. }
  1974. }
  1975. int intel_format_to_fourcc(int format)
  1976. {
  1977. switch (format) {
  1978. case DISPPLANE_8BPP:
  1979. return DRM_FORMAT_C8;
  1980. case DISPPLANE_BGRX555:
  1981. return DRM_FORMAT_XRGB1555;
  1982. case DISPPLANE_BGRX565:
  1983. return DRM_FORMAT_RGB565;
  1984. default:
  1985. case DISPPLANE_BGRX888:
  1986. return DRM_FORMAT_XRGB8888;
  1987. case DISPPLANE_RGBX888:
  1988. return DRM_FORMAT_XBGR8888;
  1989. case DISPPLANE_BGRX101010:
  1990. return DRM_FORMAT_XRGB2101010;
  1991. case DISPPLANE_RGBX101010:
  1992. return DRM_FORMAT_XBGR2101010;
  1993. }
  1994. }
  1995. static bool intel_alloc_plane_obj(struct intel_crtc *crtc,
  1996. struct intel_plane_config *plane_config)
  1997. {
  1998. struct drm_device *dev = crtc->base.dev;
  1999. struct drm_i915_gem_object *obj = NULL;
  2000. struct drm_mode_fb_cmd2 mode_cmd = { 0 };
  2001. u32 base = plane_config->base;
  2002. if (plane_config->size == 0)
  2003. return false;
  2004. obj = i915_gem_object_create_stolen_for_preallocated(dev, base, base,
  2005. plane_config->size);
  2006. if (!obj)
  2007. return false;
  2008. if (plane_config->tiled) {
  2009. obj->tiling_mode = I915_TILING_X;
  2010. obj->stride = crtc->base.primary->fb->pitches[0];
  2011. }
  2012. mode_cmd.pixel_format = crtc->base.primary->fb->pixel_format;
  2013. mode_cmd.width = crtc->base.primary->fb->width;
  2014. mode_cmd.height = crtc->base.primary->fb->height;
  2015. mode_cmd.pitches[0] = crtc->base.primary->fb->pitches[0];
  2016. mutex_lock(&dev->struct_mutex);
  2017. if (intel_framebuffer_init(dev, to_intel_framebuffer(crtc->base.primary->fb),
  2018. &mode_cmd, obj)) {
  2019. DRM_DEBUG_KMS("intel fb init failed\n");
  2020. goto out_unref_obj;
  2021. }
  2022. obj->frontbuffer_bits = INTEL_FRONTBUFFER_PRIMARY(crtc->pipe);
  2023. mutex_unlock(&dev->struct_mutex);
  2024. DRM_DEBUG_KMS("plane fb obj %p\n", obj);
  2025. return true;
  2026. out_unref_obj:
  2027. drm_gem_object_unreference(&obj->base);
  2028. mutex_unlock(&dev->struct_mutex);
  2029. return false;
  2030. }
  2031. static void intel_find_plane_obj(struct intel_crtc *intel_crtc,
  2032. struct intel_plane_config *plane_config)
  2033. {
  2034. struct drm_device *dev = intel_crtc->base.dev;
  2035. struct drm_crtc *c;
  2036. struct intel_crtc *i;
  2037. struct drm_i915_gem_object *obj;
  2038. if (!intel_crtc->base.primary->fb)
  2039. return;
  2040. if (intel_alloc_plane_obj(intel_crtc, plane_config))
  2041. return;
  2042. kfree(intel_crtc->base.primary->fb);
  2043. intel_crtc->base.primary->fb = NULL;
  2044. /*
  2045. * Failed to alloc the obj, check to see if we should share
  2046. * an fb with another CRTC instead
  2047. */
  2048. for_each_crtc(dev, c) {
  2049. i = to_intel_crtc(c);
  2050. if (c == &intel_crtc->base)
  2051. continue;
  2052. if (!i->active)
  2053. continue;
  2054. obj = intel_fb_obj(c->primary->fb);
  2055. if (obj == NULL)
  2056. continue;
  2057. if (i915_gem_obj_ggtt_offset(obj) == plane_config->base) {
  2058. drm_framebuffer_reference(c->primary->fb);
  2059. intel_crtc->base.primary->fb = c->primary->fb;
  2060. obj->frontbuffer_bits |= INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe);
  2061. break;
  2062. }
  2063. }
  2064. }
  2065. static void i9xx_update_primary_plane(struct drm_crtc *crtc,
  2066. struct drm_framebuffer *fb,
  2067. int x, int y)
  2068. {
  2069. struct drm_device *dev = crtc->dev;
  2070. struct drm_i915_private *dev_priv = dev->dev_private;
  2071. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2072. struct drm_i915_gem_object *obj;
  2073. int plane = intel_crtc->plane;
  2074. unsigned long linear_offset;
  2075. u32 dspcntr;
  2076. u32 reg = DSPCNTR(plane);
  2077. int pixel_size;
  2078. if (!intel_crtc->primary_enabled) {
  2079. I915_WRITE(reg, 0);
  2080. if (INTEL_INFO(dev)->gen >= 4)
  2081. I915_WRITE(DSPSURF(plane), 0);
  2082. else
  2083. I915_WRITE(DSPADDR(plane), 0);
  2084. POSTING_READ(reg);
  2085. return;
  2086. }
  2087. obj = intel_fb_obj(fb);
  2088. if (WARN_ON(obj == NULL))
  2089. return;
  2090. pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
  2091. dspcntr = DISPPLANE_GAMMA_ENABLE;
  2092. dspcntr |= DISPLAY_PLANE_ENABLE;
  2093. if (INTEL_INFO(dev)->gen < 4) {
  2094. if (intel_crtc->pipe == PIPE_B)
  2095. dspcntr |= DISPPLANE_SEL_PIPE_B;
  2096. /* pipesrc and dspsize control the size that is scaled from,
  2097. * which should always be the user's requested size.
  2098. */
  2099. I915_WRITE(DSPSIZE(plane),
  2100. ((intel_crtc->config.pipe_src_h - 1) << 16) |
  2101. (intel_crtc->config.pipe_src_w - 1));
  2102. I915_WRITE(DSPPOS(plane), 0);
  2103. }
  2104. switch (fb->pixel_format) {
  2105. case DRM_FORMAT_C8:
  2106. dspcntr |= DISPPLANE_8BPP;
  2107. break;
  2108. case DRM_FORMAT_XRGB1555:
  2109. case DRM_FORMAT_ARGB1555:
  2110. dspcntr |= DISPPLANE_BGRX555;
  2111. break;
  2112. case DRM_FORMAT_RGB565:
  2113. dspcntr |= DISPPLANE_BGRX565;
  2114. break;
  2115. case DRM_FORMAT_XRGB8888:
  2116. case DRM_FORMAT_ARGB8888:
  2117. dspcntr |= DISPPLANE_BGRX888;
  2118. break;
  2119. case DRM_FORMAT_XBGR8888:
  2120. case DRM_FORMAT_ABGR8888:
  2121. dspcntr |= DISPPLANE_RGBX888;
  2122. break;
  2123. case DRM_FORMAT_XRGB2101010:
  2124. case DRM_FORMAT_ARGB2101010:
  2125. dspcntr |= DISPPLANE_BGRX101010;
  2126. break;
  2127. case DRM_FORMAT_XBGR2101010:
  2128. case DRM_FORMAT_ABGR2101010:
  2129. dspcntr |= DISPPLANE_RGBX101010;
  2130. break;
  2131. default:
  2132. BUG();
  2133. }
  2134. if (INTEL_INFO(dev)->gen >= 4 &&
  2135. obj->tiling_mode != I915_TILING_NONE)
  2136. dspcntr |= DISPPLANE_TILED;
  2137. if (IS_G4X(dev))
  2138. dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
  2139. linear_offset = y * fb->pitches[0] + x * pixel_size;
  2140. if (INTEL_INFO(dev)->gen >= 4) {
  2141. intel_crtc->dspaddr_offset =
  2142. intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
  2143. pixel_size,
  2144. fb->pitches[0]);
  2145. linear_offset -= intel_crtc->dspaddr_offset;
  2146. } else {
  2147. intel_crtc->dspaddr_offset = linear_offset;
  2148. }
  2149. if (to_intel_plane(crtc->primary)->rotation == BIT(DRM_ROTATE_180)) {
  2150. dspcntr |= DISPPLANE_ROTATE_180;
  2151. x += (intel_crtc->config.pipe_src_w - 1);
  2152. y += (intel_crtc->config.pipe_src_h - 1);
  2153. /* Finding the last pixel of the last line of the display
  2154. data and adding to linear_offset*/
  2155. linear_offset +=
  2156. (intel_crtc->config.pipe_src_h - 1) * fb->pitches[0] +
  2157. (intel_crtc->config.pipe_src_w - 1) * pixel_size;
  2158. }
  2159. I915_WRITE(reg, dspcntr);
  2160. DRM_DEBUG_KMS("Writing base %08lX %08lX %d %d %d\n",
  2161. i915_gem_obj_ggtt_offset(obj), linear_offset, x, y,
  2162. fb->pitches[0]);
  2163. I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]);
  2164. if (INTEL_INFO(dev)->gen >= 4) {
  2165. I915_WRITE(DSPSURF(plane),
  2166. i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset);
  2167. I915_WRITE(DSPTILEOFF(plane), (y << 16) | x);
  2168. I915_WRITE(DSPLINOFF(plane), linear_offset);
  2169. } else
  2170. I915_WRITE(DSPADDR(plane), i915_gem_obj_ggtt_offset(obj) + linear_offset);
  2171. POSTING_READ(reg);
  2172. }
  2173. static void ironlake_update_primary_plane(struct drm_crtc *crtc,
  2174. struct drm_framebuffer *fb,
  2175. int x, int y)
  2176. {
  2177. struct drm_device *dev = crtc->dev;
  2178. struct drm_i915_private *dev_priv = dev->dev_private;
  2179. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2180. struct drm_i915_gem_object *obj;
  2181. int plane = intel_crtc->plane;
  2182. unsigned long linear_offset;
  2183. u32 dspcntr;
  2184. u32 reg = DSPCNTR(plane);
  2185. int pixel_size;
  2186. if (!intel_crtc->primary_enabled) {
  2187. I915_WRITE(reg, 0);
  2188. I915_WRITE(DSPSURF(plane), 0);
  2189. POSTING_READ(reg);
  2190. return;
  2191. }
  2192. obj = intel_fb_obj(fb);
  2193. if (WARN_ON(obj == NULL))
  2194. return;
  2195. pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
  2196. dspcntr = DISPPLANE_GAMMA_ENABLE;
  2197. dspcntr |= DISPLAY_PLANE_ENABLE;
  2198. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  2199. dspcntr |= DISPPLANE_PIPE_CSC_ENABLE;
  2200. switch (fb->pixel_format) {
  2201. case DRM_FORMAT_C8:
  2202. dspcntr |= DISPPLANE_8BPP;
  2203. break;
  2204. case DRM_FORMAT_RGB565:
  2205. dspcntr |= DISPPLANE_BGRX565;
  2206. break;
  2207. case DRM_FORMAT_XRGB8888:
  2208. case DRM_FORMAT_ARGB8888:
  2209. dspcntr |= DISPPLANE_BGRX888;
  2210. break;
  2211. case DRM_FORMAT_XBGR8888:
  2212. case DRM_FORMAT_ABGR8888:
  2213. dspcntr |= DISPPLANE_RGBX888;
  2214. break;
  2215. case DRM_FORMAT_XRGB2101010:
  2216. case DRM_FORMAT_ARGB2101010:
  2217. dspcntr |= DISPPLANE_BGRX101010;
  2218. break;
  2219. case DRM_FORMAT_XBGR2101010:
  2220. case DRM_FORMAT_ABGR2101010:
  2221. dspcntr |= DISPPLANE_RGBX101010;
  2222. break;
  2223. default:
  2224. BUG();
  2225. }
  2226. if (obj->tiling_mode != I915_TILING_NONE)
  2227. dspcntr |= DISPPLANE_TILED;
  2228. if (!IS_HASWELL(dev) && !IS_BROADWELL(dev))
  2229. dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
  2230. linear_offset = y * fb->pitches[0] + x * pixel_size;
  2231. intel_crtc->dspaddr_offset =
  2232. intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
  2233. pixel_size,
  2234. fb->pitches[0]);
  2235. linear_offset -= intel_crtc->dspaddr_offset;
  2236. if (to_intel_plane(crtc->primary)->rotation == BIT(DRM_ROTATE_180)) {
  2237. dspcntr |= DISPPLANE_ROTATE_180;
  2238. if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) {
  2239. x += (intel_crtc->config.pipe_src_w - 1);
  2240. y += (intel_crtc->config.pipe_src_h - 1);
  2241. /* Finding the last pixel of the last line of the display
  2242. data and adding to linear_offset*/
  2243. linear_offset +=
  2244. (intel_crtc->config.pipe_src_h - 1) * fb->pitches[0] +
  2245. (intel_crtc->config.pipe_src_w - 1) * pixel_size;
  2246. }
  2247. }
  2248. I915_WRITE(reg, dspcntr);
  2249. DRM_DEBUG_KMS("Writing base %08lX %08lX %d %d %d\n",
  2250. i915_gem_obj_ggtt_offset(obj), linear_offset, x, y,
  2251. fb->pitches[0]);
  2252. I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]);
  2253. I915_WRITE(DSPSURF(plane),
  2254. i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset);
  2255. if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
  2256. I915_WRITE(DSPOFFSET(plane), (y << 16) | x);
  2257. } else {
  2258. I915_WRITE(DSPTILEOFF(plane), (y << 16) | x);
  2259. I915_WRITE(DSPLINOFF(plane), linear_offset);
  2260. }
  2261. POSTING_READ(reg);
  2262. }
  2263. /* Assume fb object is pinned & idle & fenced and just update base pointers */
  2264. static int
  2265. intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb,
  2266. int x, int y, enum mode_set_atomic state)
  2267. {
  2268. struct drm_device *dev = crtc->dev;
  2269. struct drm_i915_private *dev_priv = dev->dev_private;
  2270. if (dev_priv->display.disable_fbc)
  2271. dev_priv->display.disable_fbc(dev);
  2272. intel_increase_pllclock(dev, to_intel_crtc(crtc)->pipe);
  2273. dev_priv->display.update_primary_plane(crtc, fb, x, y);
  2274. return 0;
  2275. }
  2276. void intel_display_handle_reset(struct drm_device *dev)
  2277. {
  2278. struct drm_i915_private *dev_priv = dev->dev_private;
  2279. struct drm_crtc *crtc;
  2280. /*
  2281. * Flips in the rings have been nuked by the reset,
  2282. * so complete all pending flips so that user space
  2283. * will get its events and not get stuck.
  2284. *
  2285. * Also update the base address of all primary
  2286. * planes to the the last fb to make sure we're
  2287. * showing the correct fb after a reset.
  2288. *
  2289. * Need to make two loops over the crtcs so that we
  2290. * don't try to grab a crtc mutex before the
  2291. * pending_flip_queue really got woken up.
  2292. */
  2293. for_each_crtc(dev, crtc) {
  2294. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2295. enum plane plane = intel_crtc->plane;
  2296. intel_prepare_page_flip(dev, plane);
  2297. intel_finish_page_flip_plane(dev, plane);
  2298. }
  2299. for_each_crtc(dev, crtc) {
  2300. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2301. drm_modeset_lock(&crtc->mutex, NULL);
  2302. /*
  2303. * FIXME: Once we have proper support for primary planes (and
  2304. * disabling them without disabling the entire crtc) allow again
  2305. * a NULL crtc->primary->fb.
  2306. */
  2307. if (intel_crtc->active && crtc->primary->fb)
  2308. dev_priv->display.update_primary_plane(crtc,
  2309. crtc->primary->fb,
  2310. crtc->x,
  2311. crtc->y);
  2312. drm_modeset_unlock(&crtc->mutex);
  2313. }
  2314. }
  2315. static int
  2316. intel_finish_fb(struct drm_framebuffer *old_fb)
  2317. {
  2318. struct drm_i915_gem_object *obj = intel_fb_obj(old_fb);
  2319. struct drm_i915_private *dev_priv = obj->base.dev->dev_private;
  2320. bool was_interruptible = dev_priv->mm.interruptible;
  2321. int ret;
  2322. /* Big Hammer, we also need to ensure that any pending
  2323. * MI_WAIT_FOR_EVENT inside a user batch buffer on the
  2324. * current scanout is retired before unpinning the old
  2325. * framebuffer.
  2326. *
  2327. * This should only fail upon a hung GPU, in which case we
  2328. * can safely continue.
  2329. */
  2330. dev_priv->mm.interruptible = false;
  2331. ret = i915_gem_object_finish_gpu(obj);
  2332. dev_priv->mm.interruptible = was_interruptible;
  2333. return ret;
  2334. }
  2335. static bool intel_crtc_has_pending_flip(struct drm_crtc *crtc)
  2336. {
  2337. struct drm_device *dev = crtc->dev;
  2338. struct drm_i915_private *dev_priv = dev->dev_private;
  2339. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2340. unsigned long flags;
  2341. bool pending;
  2342. if (i915_reset_in_progress(&dev_priv->gpu_error) ||
  2343. intel_crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter))
  2344. return false;
  2345. spin_lock_irqsave(&dev->event_lock, flags);
  2346. pending = to_intel_crtc(crtc)->unpin_work != NULL;
  2347. spin_unlock_irqrestore(&dev->event_lock, flags);
  2348. return pending;
  2349. }
  2350. static void intel_update_pipe_size(struct intel_crtc *crtc)
  2351. {
  2352. struct drm_device *dev = crtc->base.dev;
  2353. struct drm_i915_private *dev_priv = dev->dev_private;
  2354. const struct drm_display_mode *adjusted_mode;
  2355. if (!i915.fastboot)
  2356. return;
  2357. /*
  2358. * Update pipe size and adjust fitter if needed: the reason for this is
  2359. * that in compute_mode_changes we check the native mode (not the pfit
  2360. * mode) to see if we can flip rather than do a full mode set. In the
  2361. * fastboot case, we'll flip, but if we don't update the pipesrc and
  2362. * pfit state, we'll end up with a big fb scanned out into the wrong
  2363. * sized surface.
  2364. *
  2365. * To fix this properly, we need to hoist the checks up into
  2366. * compute_mode_changes (or above), check the actual pfit state and
  2367. * whether the platform allows pfit disable with pipe active, and only
  2368. * then update the pipesrc and pfit state, even on the flip path.
  2369. */
  2370. adjusted_mode = &crtc->config.adjusted_mode;
  2371. I915_WRITE(PIPESRC(crtc->pipe),
  2372. ((adjusted_mode->crtc_hdisplay - 1) << 16) |
  2373. (adjusted_mode->crtc_vdisplay - 1));
  2374. if (!crtc->config.pch_pfit.enabled &&
  2375. (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) ||
  2376. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_EDP))) {
  2377. I915_WRITE(PF_CTL(crtc->pipe), 0);
  2378. I915_WRITE(PF_WIN_POS(crtc->pipe), 0);
  2379. I915_WRITE(PF_WIN_SZ(crtc->pipe), 0);
  2380. }
  2381. crtc->config.pipe_src_w = adjusted_mode->crtc_hdisplay;
  2382. crtc->config.pipe_src_h = adjusted_mode->crtc_vdisplay;
  2383. }
  2384. static int
  2385. intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
  2386. struct drm_framebuffer *fb)
  2387. {
  2388. struct drm_device *dev = crtc->dev;
  2389. struct drm_i915_private *dev_priv = dev->dev_private;
  2390. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2391. enum pipe pipe = intel_crtc->pipe;
  2392. struct drm_framebuffer *old_fb = crtc->primary->fb;
  2393. struct drm_i915_gem_object *obj = intel_fb_obj(fb);
  2394. struct drm_i915_gem_object *old_obj = intel_fb_obj(old_fb);
  2395. int ret;
  2396. if (intel_crtc_has_pending_flip(crtc)) {
  2397. DRM_ERROR("pipe is still busy with an old pageflip\n");
  2398. return -EBUSY;
  2399. }
  2400. /* no fb bound */
  2401. if (!fb) {
  2402. DRM_ERROR("No FB bound\n");
  2403. return 0;
  2404. }
  2405. if (intel_crtc->plane > INTEL_INFO(dev)->num_pipes) {
  2406. DRM_ERROR("no plane for crtc: plane %c, num_pipes %d\n",
  2407. plane_name(intel_crtc->plane),
  2408. INTEL_INFO(dev)->num_pipes);
  2409. return -EINVAL;
  2410. }
  2411. mutex_lock(&dev->struct_mutex);
  2412. ret = intel_pin_and_fence_fb_obj(dev, obj, NULL);
  2413. if (ret == 0)
  2414. i915_gem_track_fb(old_obj, obj,
  2415. INTEL_FRONTBUFFER_PRIMARY(pipe));
  2416. mutex_unlock(&dev->struct_mutex);
  2417. if (ret != 0) {
  2418. DRM_ERROR("pin & fence failed\n");
  2419. return ret;
  2420. }
  2421. intel_update_pipe_size(intel_crtc);
  2422. dev_priv->display.update_primary_plane(crtc, fb, x, y);
  2423. if (intel_crtc->active)
  2424. intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_PRIMARY(pipe));
  2425. crtc->primary->fb = fb;
  2426. crtc->x = x;
  2427. crtc->y = y;
  2428. if (old_fb) {
  2429. if (intel_crtc->active && old_fb != fb)
  2430. intel_wait_for_vblank(dev, intel_crtc->pipe);
  2431. mutex_lock(&dev->struct_mutex);
  2432. intel_unpin_fb_obj(old_obj);
  2433. mutex_unlock(&dev->struct_mutex);
  2434. }
  2435. mutex_lock(&dev->struct_mutex);
  2436. intel_update_fbc(dev);
  2437. mutex_unlock(&dev->struct_mutex);
  2438. return 0;
  2439. }
  2440. static void intel_fdi_normal_train(struct drm_crtc *crtc)
  2441. {
  2442. struct drm_device *dev = crtc->dev;
  2443. struct drm_i915_private *dev_priv = dev->dev_private;
  2444. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2445. int pipe = intel_crtc->pipe;
  2446. u32 reg, temp;
  2447. /* enable normal train */
  2448. reg = FDI_TX_CTL(pipe);
  2449. temp = I915_READ(reg);
  2450. if (IS_IVYBRIDGE(dev)) {
  2451. temp &= ~FDI_LINK_TRAIN_NONE_IVB;
  2452. temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE;
  2453. } else {
  2454. temp &= ~FDI_LINK_TRAIN_NONE;
  2455. temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
  2456. }
  2457. I915_WRITE(reg, temp);
  2458. reg = FDI_RX_CTL(pipe);
  2459. temp = I915_READ(reg);
  2460. if (HAS_PCH_CPT(dev)) {
  2461. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2462. temp |= FDI_LINK_TRAIN_NORMAL_CPT;
  2463. } else {
  2464. temp &= ~FDI_LINK_TRAIN_NONE;
  2465. temp |= FDI_LINK_TRAIN_NONE;
  2466. }
  2467. I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
  2468. /* wait one idle pattern time */
  2469. POSTING_READ(reg);
  2470. udelay(1000);
  2471. /* IVB wants error correction enabled */
  2472. if (IS_IVYBRIDGE(dev))
  2473. I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE |
  2474. FDI_FE_ERRC_ENABLE);
  2475. }
  2476. static bool pipe_has_enabled_pch(struct intel_crtc *crtc)
  2477. {
  2478. return crtc->base.enabled && crtc->active &&
  2479. crtc->config.has_pch_encoder;
  2480. }
  2481. static void ivb_modeset_global_resources(struct drm_device *dev)
  2482. {
  2483. struct drm_i915_private *dev_priv = dev->dev_private;
  2484. struct intel_crtc *pipe_B_crtc =
  2485. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_B]);
  2486. struct intel_crtc *pipe_C_crtc =
  2487. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_C]);
  2488. uint32_t temp;
  2489. /*
  2490. * When everything is off disable fdi C so that we could enable fdi B
  2491. * with all lanes. Note that we don't care about enabled pipes without
  2492. * an enabled pch encoder.
  2493. */
  2494. if (!pipe_has_enabled_pch(pipe_B_crtc) &&
  2495. !pipe_has_enabled_pch(pipe_C_crtc)) {
  2496. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
  2497. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
  2498. temp = I915_READ(SOUTH_CHICKEN1);
  2499. temp &= ~FDI_BC_BIFURCATION_SELECT;
  2500. DRM_DEBUG_KMS("disabling fdi C rx\n");
  2501. I915_WRITE(SOUTH_CHICKEN1, temp);
  2502. }
  2503. }
  2504. /* The FDI link training functions for ILK/Ibexpeak. */
  2505. static void ironlake_fdi_link_train(struct drm_crtc *crtc)
  2506. {
  2507. struct drm_device *dev = crtc->dev;
  2508. struct drm_i915_private *dev_priv = dev->dev_private;
  2509. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2510. int pipe = intel_crtc->pipe;
  2511. u32 reg, temp, tries;
  2512. /* FDI needs bits from pipe first */
  2513. assert_pipe_enabled(dev_priv, pipe);
  2514. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  2515. for train result */
  2516. reg = FDI_RX_IMR(pipe);
  2517. temp = I915_READ(reg);
  2518. temp &= ~FDI_RX_SYMBOL_LOCK;
  2519. temp &= ~FDI_RX_BIT_LOCK;
  2520. I915_WRITE(reg, temp);
  2521. I915_READ(reg);
  2522. udelay(150);
  2523. /* enable CPU FDI TX and PCH FDI RX */
  2524. reg = FDI_TX_CTL(pipe);
  2525. temp = I915_READ(reg);
  2526. temp &= ~FDI_DP_PORT_WIDTH_MASK;
  2527. temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes);
  2528. temp &= ~FDI_LINK_TRAIN_NONE;
  2529. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2530. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  2531. reg = FDI_RX_CTL(pipe);
  2532. temp = I915_READ(reg);
  2533. temp &= ~FDI_LINK_TRAIN_NONE;
  2534. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2535. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  2536. POSTING_READ(reg);
  2537. udelay(150);
  2538. /* Ironlake workaround, enable clock pointer after FDI enable*/
  2539. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
  2540. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR |
  2541. FDI_RX_PHASE_SYNC_POINTER_EN);
  2542. reg = FDI_RX_IIR(pipe);
  2543. for (tries = 0; tries < 5; tries++) {
  2544. temp = I915_READ(reg);
  2545. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2546. if ((temp & FDI_RX_BIT_LOCK)) {
  2547. DRM_DEBUG_KMS("FDI train 1 done.\n");
  2548. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  2549. break;
  2550. }
  2551. }
  2552. if (tries == 5)
  2553. DRM_ERROR("FDI train 1 fail!\n");
  2554. /* Train 2 */
  2555. reg = FDI_TX_CTL(pipe);
  2556. temp = I915_READ(reg);
  2557. temp &= ~FDI_LINK_TRAIN_NONE;
  2558. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2559. I915_WRITE(reg, temp);
  2560. reg = FDI_RX_CTL(pipe);
  2561. temp = I915_READ(reg);
  2562. temp &= ~FDI_LINK_TRAIN_NONE;
  2563. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2564. I915_WRITE(reg, temp);
  2565. POSTING_READ(reg);
  2566. udelay(150);
  2567. reg = FDI_RX_IIR(pipe);
  2568. for (tries = 0; tries < 5; tries++) {
  2569. temp = I915_READ(reg);
  2570. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2571. if (temp & FDI_RX_SYMBOL_LOCK) {
  2572. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  2573. DRM_DEBUG_KMS("FDI train 2 done.\n");
  2574. break;
  2575. }
  2576. }
  2577. if (tries == 5)
  2578. DRM_ERROR("FDI train 2 fail!\n");
  2579. DRM_DEBUG_KMS("FDI train done\n");
  2580. }
  2581. static const int snb_b_fdi_train_param[] = {
  2582. FDI_LINK_TRAIN_400MV_0DB_SNB_B,
  2583. FDI_LINK_TRAIN_400MV_6DB_SNB_B,
  2584. FDI_LINK_TRAIN_600MV_3_5DB_SNB_B,
  2585. FDI_LINK_TRAIN_800MV_0DB_SNB_B,
  2586. };
  2587. /* The FDI link training functions for SNB/Cougarpoint. */
  2588. static void gen6_fdi_link_train(struct drm_crtc *crtc)
  2589. {
  2590. struct drm_device *dev = crtc->dev;
  2591. struct drm_i915_private *dev_priv = dev->dev_private;
  2592. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2593. int pipe = intel_crtc->pipe;
  2594. u32 reg, temp, i, retry;
  2595. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  2596. for train result */
  2597. reg = FDI_RX_IMR(pipe);
  2598. temp = I915_READ(reg);
  2599. temp &= ~FDI_RX_SYMBOL_LOCK;
  2600. temp &= ~FDI_RX_BIT_LOCK;
  2601. I915_WRITE(reg, temp);
  2602. POSTING_READ(reg);
  2603. udelay(150);
  2604. /* enable CPU FDI TX and PCH FDI RX */
  2605. reg = FDI_TX_CTL(pipe);
  2606. temp = I915_READ(reg);
  2607. temp &= ~FDI_DP_PORT_WIDTH_MASK;
  2608. temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes);
  2609. temp &= ~FDI_LINK_TRAIN_NONE;
  2610. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2611. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2612. /* SNB-B */
  2613. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  2614. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  2615. I915_WRITE(FDI_RX_MISC(pipe),
  2616. FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
  2617. reg = FDI_RX_CTL(pipe);
  2618. temp = I915_READ(reg);
  2619. if (HAS_PCH_CPT(dev)) {
  2620. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2621. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2622. } else {
  2623. temp &= ~FDI_LINK_TRAIN_NONE;
  2624. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2625. }
  2626. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  2627. POSTING_READ(reg);
  2628. udelay(150);
  2629. for (i = 0; i < 4; i++) {
  2630. reg = FDI_TX_CTL(pipe);
  2631. temp = I915_READ(reg);
  2632. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2633. temp |= snb_b_fdi_train_param[i];
  2634. I915_WRITE(reg, temp);
  2635. POSTING_READ(reg);
  2636. udelay(500);
  2637. for (retry = 0; retry < 5; retry++) {
  2638. reg = FDI_RX_IIR(pipe);
  2639. temp = I915_READ(reg);
  2640. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2641. if (temp & FDI_RX_BIT_LOCK) {
  2642. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  2643. DRM_DEBUG_KMS("FDI train 1 done.\n");
  2644. break;
  2645. }
  2646. udelay(50);
  2647. }
  2648. if (retry < 5)
  2649. break;
  2650. }
  2651. if (i == 4)
  2652. DRM_ERROR("FDI train 1 fail!\n");
  2653. /* Train 2 */
  2654. reg = FDI_TX_CTL(pipe);
  2655. temp = I915_READ(reg);
  2656. temp &= ~FDI_LINK_TRAIN_NONE;
  2657. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2658. if (IS_GEN6(dev)) {
  2659. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2660. /* SNB-B */
  2661. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  2662. }
  2663. I915_WRITE(reg, temp);
  2664. reg = FDI_RX_CTL(pipe);
  2665. temp = I915_READ(reg);
  2666. if (HAS_PCH_CPT(dev)) {
  2667. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2668. temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
  2669. } else {
  2670. temp &= ~FDI_LINK_TRAIN_NONE;
  2671. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2672. }
  2673. I915_WRITE(reg, temp);
  2674. POSTING_READ(reg);
  2675. udelay(150);
  2676. for (i = 0; i < 4; i++) {
  2677. reg = FDI_TX_CTL(pipe);
  2678. temp = I915_READ(reg);
  2679. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2680. temp |= snb_b_fdi_train_param[i];
  2681. I915_WRITE(reg, temp);
  2682. POSTING_READ(reg);
  2683. udelay(500);
  2684. for (retry = 0; retry < 5; retry++) {
  2685. reg = FDI_RX_IIR(pipe);
  2686. temp = I915_READ(reg);
  2687. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2688. if (temp & FDI_RX_SYMBOL_LOCK) {
  2689. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  2690. DRM_DEBUG_KMS("FDI train 2 done.\n");
  2691. break;
  2692. }
  2693. udelay(50);
  2694. }
  2695. if (retry < 5)
  2696. break;
  2697. }
  2698. if (i == 4)
  2699. DRM_ERROR("FDI train 2 fail!\n");
  2700. DRM_DEBUG_KMS("FDI train done.\n");
  2701. }
  2702. /* Manual link training for Ivy Bridge A0 parts */
  2703. static void ivb_manual_fdi_link_train(struct drm_crtc *crtc)
  2704. {
  2705. struct drm_device *dev = crtc->dev;
  2706. struct drm_i915_private *dev_priv = dev->dev_private;
  2707. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2708. int pipe = intel_crtc->pipe;
  2709. u32 reg, temp, i, j;
  2710. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  2711. for train result */
  2712. reg = FDI_RX_IMR(pipe);
  2713. temp = I915_READ(reg);
  2714. temp &= ~FDI_RX_SYMBOL_LOCK;
  2715. temp &= ~FDI_RX_BIT_LOCK;
  2716. I915_WRITE(reg, temp);
  2717. POSTING_READ(reg);
  2718. udelay(150);
  2719. DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
  2720. I915_READ(FDI_RX_IIR(pipe)));
  2721. /* Try each vswing and preemphasis setting twice before moving on */
  2722. for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) {
  2723. /* disable first in case we need to retry */
  2724. reg = FDI_TX_CTL(pipe);
  2725. temp = I915_READ(reg);
  2726. temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB);
  2727. temp &= ~FDI_TX_ENABLE;
  2728. I915_WRITE(reg, temp);
  2729. reg = FDI_RX_CTL(pipe);
  2730. temp = I915_READ(reg);
  2731. temp &= ~FDI_LINK_TRAIN_AUTO;
  2732. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2733. temp &= ~FDI_RX_ENABLE;
  2734. I915_WRITE(reg, temp);
  2735. /* enable CPU FDI TX and PCH FDI RX */
  2736. reg = FDI_TX_CTL(pipe);
  2737. temp = I915_READ(reg);
  2738. temp &= ~FDI_DP_PORT_WIDTH_MASK;
  2739. temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes);
  2740. temp |= FDI_LINK_TRAIN_PATTERN_1_IVB;
  2741. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2742. temp |= snb_b_fdi_train_param[j/2];
  2743. temp |= FDI_COMPOSITE_SYNC;
  2744. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  2745. I915_WRITE(FDI_RX_MISC(pipe),
  2746. FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
  2747. reg = FDI_RX_CTL(pipe);
  2748. temp = I915_READ(reg);
  2749. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2750. temp |= FDI_COMPOSITE_SYNC;
  2751. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  2752. POSTING_READ(reg);
  2753. udelay(1); /* should be 0.5us */
  2754. for (i = 0; i < 4; i++) {
  2755. reg = FDI_RX_IIR(pipe);
  2756. temp = I915_READ(reg);
  2757. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2758. if (temp & FDI_RX_BIT_LOCK ||
  2759. (I915_READ(reg) & FDI_RX_BIT_LOCK)) {
  2760. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  2761. DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
  2762. i);
  2763. break;
  2764. }
  2765. udelay(1); /* should be 0.5us */
  2766. }
  2767. if (i == 4) {
  2768. DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2);
  2769. continue;
  2770. }
  2771. /* Train 2 */
  2772. reg = FDI_TX_CTL(pipe);
  2773. temp = I915_READ(reg);
  2774. temp &= ~FDI_LINK_TRAIN_NONE_IVB;
  2775. temp |= FDI_LINK_TRAIN_PATTERN_2_IVB;
  2776. I915_WRITE(reg, temp);
  2777. reg = FDI_RX_CTL(pipe);
  2778. temp = I915_READ(reg);
  2779. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2780. temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
  2781. I915_WRITE(reg, temp);
  2782. POSTING_READ(reg);
  2783. udelay(2); /* should be 1.5us */
  2784. for (i = 0; i < 4; i++) {
  2785. reg = FDI_RX_IIR(pipe);
  2786. temp = I915_READ(reg);
  2787. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2788. if (temp & FDI_RX_SYMBOL_LOCK ||
  2789. (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) {
  2790. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  2791. DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
  2792. i);
  2793. goto train_done;
  2794. }
  2795. udelay(2); /* should be 1.5us */
  2796. }
  2797. if (i == 4)
  2798. DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j / 2);
  2799. }
  2800. train_done:
  2801. DRM_DEBUG_KMS("FDI train done.\n");
  2802. }
  2803. static void ironlake_fdi_pll_enable(struct intel_crtc *intel_crtc)
  2804. {
  2805. struct drm_device *dev = intel_crtc->base.dev;
  2806. struct drm_i915_private *dev_priv = dev->dev_private;
  2807. int pipe = intel_crtc->pipe;
  2808. u32 reg, temp;
  2809. /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
  2810. reg = FDI_RX_CTL(pipe);
  2811. temp = I915_READ(reg);
  2812. temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16));
  2813. temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes);
  2814. temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
  2815. I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE);
  2816. POSTING_READ(reg);
  2817. udelay(200);
  2818. /* Switch from Rawclk to PCDclk */
  2819. temp = I915_READ(reg);
  2820. I915_WRITE(reg, temp | FDI_PCDCLK);
  2821. POSTING_READ(reg);
  2822. udelay(200);
  2823. /* Enable CPU FDI TX PLL, always on for Ironlake */
  2824. reg = FDI_TX_CTL(pipe);
  2825. temp = I915_READ(reg);
  2826. if ((temp & FDI_TX_PLL_ENABLE) == 0) {
  2827. I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE);
  2828. POSTING_READ(reg);
  2829. udelay(100);
  2830. }
  2831. }
  2832. static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc)
  2833. {
  2834. struct drm_device *dev = intel_crtc->base.dev;
  2835. struct drm_i915_private *dev_priv = dev->dev_private;
  2836. int pipe = intel_crtc->pipe;
  2837. u32 reg, temp;
  2838. /* Switch from PCDclk to Rawclk */
  2839. reg = FDI_RX_CTL(pipe);
  2840. temp = I915_READ(reg);
  2841. I915_WRITE(reg, temp & ~FDI_PCDCLK);
  2842. /* Disable CPU FDI TX PLL */
  2843. reg = FDI_TX_CTL(pipe);
  2844. temp = I915_READ(reg);
  2845. I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE);
  2846. POSTING_READ(reg);
  2847. udelay(100);
  2848. reg = FDI_RX_CTL(pipe);
  2849. temp = I915_READ(reg);
  2850. I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE);
  2851. /* Wait for the clocks to turn off. */
  2852. POSTING_READ(reg);
  2853. udelay(100);
  2854. }
  2855. static void ironlake_fdi_disable(struct drm_crtc *crtc)
  2856. {
  2857. struct drm_device *dev = crtc->dev;
  2858. struct drm_i915_private *dev_priv = dev->dev_private;
  2859. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2860. int pipe = intel_crtc->pipe;
  2861. u32 reg, temp;
  2862. /* disable CPU FDI tx and PCH FDI rx */
  2863. reg = FDI_TX_CTL(pipe);
  2864. temp = I915_READ(reg);
  2865. I915_WRITE(reg, temp & ~FDI_TX_ENABLE);
  2866. POSTING_READ(reg);
  2867. reg = FDI_RX_CTL(pipe);
  2868. temp = I915_READ(reg);
  2869. temp &= ~(0x7 << 16);
  2870. temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
  2871. I915_WRITE(reg, temp & ~FDI_RX_ENABLE);
  2872. POSTING_READ(reg);
  2873. udelay(100);
  2874. /* Ironlake workaround, disable clock pointer after downing FDI */
  2875. if (HAS_PCH_IBX(dev))
  2876. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
  2877. /* still set train pattern 1 */
  2878. reg = FDI_TX_CTL(pipe);
  2879. temp = I915_READ(reg);
  2880. temp &= ~FDI_LINK_TRAIN_NONE;
  2881. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2882. I915_WRITE(reg, temp);
  2883. reg = FDI_RX_CTL(pipe);
  2884. temp = I915_READ(reg);
  2885. if (HAS_PCH_CPT(dev)) {
  2886. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2887. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2888. } else {
  2889. temp &= ~FDI_LINK_TRAIN_NONE;
  2890. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2891. }
  2892. /* BPC in FDI rx is consistent with that in PIPECONF */
  2893. temp &= ~(0x07 << 16);
  2894. temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
  2895. I915_WRITE(reg, temp);
  2896. POSTING_READ(reg);
  2897. udelay(100);
  2898. }
  2899. bool intel_has_pending_fb_unpin(struct drm_device *dev)
  2900. {
  2901. struct intel_crtc *crtc;
  2902. /* Note that we don't need to be called with mode_config.lock here
  2903. * as our list of CRTC objects is static for the lifetime of the
  2904. * device and so cannot disappear as we iterate. Similarly, we can
  2905. * happily treat the predicates as racy, atomic checks as userspace
  2906. * cannot claim and pin a new fb without at least acquring the
  2907. * struct_mutex and so serialising with us.
  2908. */
  2909. for_each_intel_crtc(dev, crtc) {
  2910. if (atomic_read(&crtc->unpin_work_count) == 0)
  2911. continue;
  2912. if (crtc->unpin_work)
  2913. intel_wait_for_vblank(dev, crtc->pipe);
  2914. return true;
  2915. }
  2916. return false;
  2917. }
  2918. static void page_flip_completed(struct intel_crtc *intel_crtc)
  2919. {
  2920. struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
  2921. struct intel_unpin_work *work = intel_crtc->unpin_work;
  2922. /* ensure that the unpin work is consistent wrt ->pending. */
  2923. smp_rmb();
  2924. intel_crtc->unpin_work = NULL;
  2925. if (work->event)
  2926. drm_send_vblank_event(intel_crtc->base.dev,
  2927. intel_crtc->pipe,
  2928. work->event);
  2929. drm_crtc_vblank_put(&intel_crtc->base);
  2930. wake_up_all(&dev_priv->pending_flip_queue);
  2931. queue_work(dev_priv->wq, &work->work);
  2932. trace_i915_flip_complete(intel_crtc->plane,
  2933. work->pending_flip_obj);
  2934. }
  2935. void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
  2936. {
  2937. struct drm_device *dev = crtc->dev;
  2938. struct drm_i915_private *dev_priv = dev->dev_private;
  2939. WARN_ON(waitqueue_active(&dev_priv->pending_flip_queue));
  2940. if (WARN_ON(wait_event_timeout(dev_priv->pending_flip_queue,
  2941. !intel_crtc_has_pending_flip(crtc),
  2942. 60*HZ) == 0)) {
  2943. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2944. unsigned long flags;
  2945. spin_lock_irqsave(&dev->event_lock, flags);
  2946. if (intel_crtc->unpin_work) {
  2947. WARN_ONCE(1, "Removing stuck page flip\n");
  2948. page_flip_completed(intel_crtc);
  2949. }
  2950. spin_unlock_irqrestore(&dev->event_lock, flags);
  2951. }
  2952. if (crtc->primary->fb) {
  2953. mutex_lock(&dev->struct_mutex);
  2954. intel_finish_fb(crtc->primary->fb);
  2955. mutex_unlock(&dev->struct_mutex);
  2956. }
  2957. }
  2958. /* Program iCLKIP clock to the desired frequency */
  2959. static void lpt_program_iclkip(struct drm_crtc *crtc)
  2960. {
  2961. struct drm_device *dev = crtc->dev;
  2962. struct drm_i915_private *dev_priv = dev->dev_private;
  2963. int clock = to_intel_crtc(crtc)->config.adjusted_mode.crtc_clock;
  2964. u32 divsel, phaseinc, auxdiv, phasedir = 0;
  2965. u32 temp;
  2966. mutex_lock(&dev_priv->dpio_lock);
  2967. /* It is necessary to ungate the pixclk gate prior to programming
  2968. * the divisors, and gate it back when it is done.
  2969. */
  2970. I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE);
  2971. /* Disable SSCCTL */
  2972. intel_sbi_write(dev_priv, SBI_SSCCTL6,
  2973. intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK) |
  2974. SBI_SSCCTL_DISABLE,
  2975. SBI_ICLK);
  2976. /* 20MHz is a corner case which is out of range for the 7-bit divisor */
  2977. if (clock == 20000) {
  2978. auxdiv = 1;
  2979. divsel = 0x41;
  2980. phaseinc = 0x20;
  2981. } else {
  2982. /* The iCLK virtual clock root frequency is in MHz,
  2983. * but the adjusted_mode->crtc_clock in in KHz. To get the
  2984. * divisors, it is necessary to divide one by another, so we
  2985. * convert the virtual clock precision to KHz here for higher
  2986. * precision.
  2987. */
  2988. u32 iclk_virtual_root_freq = 172800 * 1000;
  2989. u32 iclk_pi_range = 64;
  2990. u32 desired_divisor, msb_divisor_value, pi_value;
  2991. desired_divisor = (iclk_virtual_root_freq / clock);
  2992. msb_divisor_value = desired_divisor / iclk_pi_range;
  2993. pi_value = desired_divisor % iclk_pi_range;
  2994. auxdiv = 0;
  2995. divsel = msb_divisor_value - 2;
  2996. phaseinc = pi_value;
  2997. }
  2998. /* This should not happen with any sane values */
  2999. WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) &
  3000. ~SBI_SSCDIVINTPHASE_DIVSEL_MASK);
  3001. WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) &
  3002. ~SBI_SSCDIVINTPHASE_INCVAL_MASK);
  3003. DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
  3004. clock,
  3005. auxdiv,
  3006. divsel,
  3007. phasedir,
  3008. phaseinc);
  3009. /* Program SSCDIVINTPHASE6 */
  3010. temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
  3011. temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK;
  3012. temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel);
  3013. temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK;
  3014. temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc);
  3015. temp |= SBI_SSCDIVINTPHASE_DIR(phasedir);
  3016. temp |= SBI_SSCDIVINTPHASE_PROPAGATE;
  3017. intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK);
  3018. /* Program SSCAUXDIV */
  3019. temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
  3020. temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
  3021. temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv);
  3022. intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK);
  3023. /* Enable modulator and associated divider */
  3024. temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
  3025. temp &= ~SBI_SSCCTL_DISABLE;
  3026. intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
  3027. /* Wait for initialization time */
  3028. udelay(24);
  3029. I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE);
  3030. mutex_unlock(&dev_priv->dpio_lock);
  3031. }
  3032. static void ironlake_pch_transcoder_set_timings(struct intel_crtc *crtc,
  3033. enum pipe pch_transcoder)
  3034. {
  3035. struct drm_device *dev = crtc->base.dev;
  3036. struct drm_i915_private *dev_priv = dev->dev_private;
  3037. enum transcoder cpu_transcoder = crtc->config.cpu_transcoder;
  3038. I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder),
  3039. I915_READ(HTOTAL(cpu_transcoder)));
  3040. I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder),
  3041. I915_READ(HBLANK(cpu_transcoder)));
  3042. I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder),
  3043. I915_READ(HSYNC(cpu_transcoder)));
  3044. I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder),
  3045. I915_READ(VTOTAL(cpu_transcoder)));
  3046. I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder),
  3047. I915_READ(VBLANK(cpu_transcoder)));
  3048. I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder),
  3049. I915_READ(VSYNC(cpu_transcoder)));
  3050. I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder),
  3051. I915_READ(VSYNCSHIFT(cpu_transcoder)));
  3052. }
  3053. static void cpt_enable_fdi_bc_bifurcation(struct drm_device *dev)
  3054. {
  3055. struct drm_i915_private *dev_priv = dev->dev_private;
  3056. uint32_t temp;
  3057. temp = I915_READ(SOUTH_CHICKEN1);
  3058. if (temp & FDI_BC_BIFURCATION_SELECT)
  3059. return;
  3060. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
  3061. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
  3062. temp |= FDI_BC_BIFURCATION_SELECT;
  3063. DRM_DEBUG_KMS("enabling fdi C rx\n");
  3064. I915_WRITE(SOUTH_CHICKEN1, temp);
  3065. POSTING_READ(SOUTH_CHICKEN1);
  3066. }
  3067. static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc *intel_crtc)
  3068. {
  3069. struct drm_device *dev = intel_crtc->base.dev;
  3070. struct drm_i915_private *dev_priv = dev->dev_private;
  3071. switch (intel_crtc->pipe) {
  3072. case PIPE_A:
  3073. break;
  3074. case PIPE_B:
  3075. if (intel_crtc->config.fdi_lanes > 2)
  3076. WARN_ON(I915_READ(SOUTH_CHICKEN1) & FDI_BC_BIFURCATION_SELECT);
  3077. else
  3078. cpt_enable_fdi_bc_bifurcation(dev);
  3079. break;
  3080. case PIPE_C:
  3081. cpt_enable_fdi_bc_bifurcation(dev);
  3082. break;
  3083. default:
  3084. BUG();
  3085. }
  3086. }
  3087. /*
  3088. * Enable PCH resources required for PCH ports:
  3089. * - PCH PLLs
  3090. * - FDI training & RX/TX
  3091. * - update transcoder timings
  3092. * - DP transcoding bits
  3093. * - transcoder
  3094. */
  3095. static void ironlake_pch_enable(struct drm_crtc *crtc)
  3096. {
  3097. struct drm_device *dev = crtc->dev;
  3098. struct drm_i915_private *dev_priv = dev->dev_private;
  3099. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3100. int pipe = intel_crtc->pipe;
  3101. u32 reg, temp;
  3102. assert_pch_transcoder_disabled(dev_priv, pipe);
  3103. if (IS_IVYBRIDGE(dev))
  3104. ivybridge_update_fdi_bc_bifurcation(intel_crtc);
  3105. /* Write the TU size bits before fdi link training, so that error
  3106. * detection works. */
  3107. I915_WRITE(FDI_RX_TUSIZE1(pipe),
  3108. I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
  3109. /* For PCH output, training FDI link */
  3110. dev_priv->display.fdi_link_train(crtc);
  3111. /* We need to program the right clock selection before writing the pixel
  3112. * mutliplier into the DPLL. */
  3113. if (HAS_PCH_CPT(dev)) {
  3114. u32 sel;
  3115. temp = I915_READ(PCH_DPLL_SEL);
  3116. temp |= TRANS_DPLL_ENABLE(pipe);
  3117. sel = TRANS_DPLLB_SEL(pipe);
  3118. if (intel_crtc->config.shared_dpll == DPLL_ID_PCH_PLL_B)
  3119. temp |= sel;
  3120. else
  3121. temp &= ~sel;
  3122. I915_WRITE(PCH_DPLL_SEL, temp);
  3123. }
  3124. /* XXX: pch pll's can be enabled any time before we enable the PCH
  3125. * transcoder, and we actually should do this to not upset any PCH
  3126. * transcoder that already use the clock when we share it.
  3127. *
  3128. * Note that enable_shared_dpll tries to do the right thing, but
  3129. * get_shared_dpll unconditionally resets the pll - we need that to have
  3130. * the right LVDS enable sequence. */
  3131. intel_enable_shared_dpll(intel_crtc);
  3132. /* set transcoder timing, panel must allow it */
  3133. assert_panel_unlocked(dev_priv, pipe);
  3134. ironlake_pch_transcoder_set_timings(intel_crtc, pipe);
  3135. intel_fdi_normal_train(crtc);
  3136. /* For PCH DP, enable TRANS_DP_CTL */
  3137. if (HAS_PCH_CPT(dev) &&
  3138. (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) ||
  3139. intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) {
  3140. u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5;
  3141. reg = TRANS_DP_CTL(pipe);
  3142. temp = I915_READ(reg);
  3143. temp &= ~(TRANS_DP_PORT_SEL_MASK |
  3144. TRANS_DP_SYNC_MASK |
  3145. TRANS_DP_BPC_MASK);
  3146. temp |= (TRANS_DP_OUTPUT_ENABLE |
  3147. TRANS_DP_ENH_FRAMING);
  3148. temp |= bpc << 9; /* same format but at 11:9 */
  3149. if (crtc->mode.flags & DRM_MODE_FLAG_PHSYNC)
  3150. temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
  3151. if (crtc->mode.flags & DRM_MODE_FLAG_PVSYNC)
  3152. temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
  3153. switch (intel_trans_dp_port_sel(crtc)) {
  3154. case PCH_DP_B:
  3155. temp |= TRANS_DP_PORT_SEL_B;
  3156. break;
  3157. case PCH_DP_C:
  3158. temp |= TRANS_DP_PORT_SEL_C;
  3159. break;
  3160. case PCH_DP_D:
  3161. temp |= TRANS_DP_PORT_SEL_D;
  3162. break;
  3163. default:
  3164. BUG();
  3165. }
  3166. I915_WRITE(reg, temp);
  3167. }
  3168. ironlake_enable_pch_transcoder(dev_priv, pipe);
  3169. }
  3170. static void lpt_pch_enable(struct drm_crtc *crtc)
  3171. {
  3172. struct drm_device *dev = crtc->dev;
  3173. struct drm_i915_private *dev_priv = dev->dev_private;
  3174. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3175. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  3176. assert_pch_transcoder_disabled(dev_priv, TRANSCODER_A);
  3177. lpt_program_iclkip(crtc);
  3178. /* Set transcoder timing. */
  3179. ironlake_pch_transcoder_set_timings(intel_crtc, PIPE_A);
  3180. lpt_enable_pch_transcoder(dev_priv, cpu_transcoder);
  3181. }
  3182. void intel_put_shared_dpll(struct intel_crtc *crtc)
  3183. {
  3184. struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
  3185. if (pll == NULL)
  3186. return;
  3187. if (pll->refcount == 0) {
  3188. WARN(1, "bad %s refcount\n", pll->name);
  3189. return;
  3190. }
  3191. if (--pll->refcount == 0) {
  3192. WARN_ON(pll->on);
  3193. WARN_ON(pll->active);
  3194. }
  3195. crtc->config.shared_dpll = DPLL_ID_PRIVATE;
  3196. }
  3197. struct intel_shared_dpll *intel_get_shared_dpll(struct intel_crtc *crtc)
  3198. {
  3199. struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
  3200. struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
  3201. enum intel_dpll_id i;
  3202. if (pll) {
  3203. DRM_DEBUG_KMS("CRTC:%d dropping existing %s\n",
  3204. crtc->base.base.id, pll->name);
  3205. intel_put_shared_dpll(crtc);
  3206. }
  3207. if (HAS_PCH_IBX(dev_priv->dev)) {
  3208. /* Ironlake PCH has a fixed PLL->PCH pipe mapping. */
  3209. i = (enum intel_dpll_id) crtc->pipe;
  3210. pll = &dev_priv->shared_dplls[i];
  3211. DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n",
  3212. crtc->base.base.id, pll->name);
  3213. WARN_ON(pll->refcount);
  3214. goto found;
  3215. }
  3216. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  3217. pll = &dev_priv->shared_dplls[i];
  3218. /* Only want to check enabled timings first */
  3219. if (pll->refcount == 0)
  3220. continue;
  3221. if (memcmp(&crtc->config.dpll_hw_state, &pll->hw_state,
  3222. sizeof(pll->hw_state)) == 0) {
  3223. DRM_DEBUG_KMS("CRTC:%d sharing existing %s (refcount %d, ative %d)\n",
  3224. crtc->base.base.id,
  3225. pll->name, pll->refcount, pll->active);
  3226. goto found;
  3227. }
  3228. }
  3229. /* Ok no matching timings, maybe there's a free one? */
  3230. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  3231. pll = &dev_priv->shared_dplls[i];
  3232. if (pll->refcount == 0) {
  3233. DRM_DEBUG_KMS("CRTC:%d allocated %s\n",
  3234. crtc->base.base.id, pll->name);
  3235. goto found;
  3236. }
  3237. }
  3238. return NULL;
  3239. found:
  3240. if (pll->refcount == 0)
  3241. pll->hw_state = crtc->config.dpll_hw_state;
  3242. crtc->config.shared_dpll = i;
  3243. DRM_DEBUG_DRIVER("using %s for pipe %c\n", pll->name,
  3244. pipe_name(crtc->pipe));
  3245. pll->refcount++;
  3246. return pll;
  3247. }
  3248. static void cpt_verify_modeset(struct drm_device *dev, int pipe)
  3249. {
  3250. struct drm_i915_private *dev_priv = dev->dev_private;
  3251. int dslreg = PIPEDSL(pipe);
  3252. u32 temp;
  3253. temp = I915_READ(dslreg);
  3254. udelay(500);
  3255. if (wait_for(I915_READ(dslreg) != temp, 5)) {
  3256. if (wait_for(I915_READ(dslreg) != temp, 5))
  3257. DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe));
  3258. }
  3259. }
  3260. static void ironlake_pfit_enable(struct intel_crtc *crtc)
  3261. {
  3262. struct drm_device *dev = crtc->base.dev;
  3263. struct drm_i915_private *dev_priv = dev->dev_private;
  3264. int pipe = crtc->pipe;
  3265. if (crtc->config.pch_pfit.enabled) {
  3266. /* Force use of hard-coded filter coefficients
  3267. * as some pre-programmed values are broken,
  3268. * e.g. x201.
  3269. */
  3270. if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev))
  3271. I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 |
  3272. PF_PIPE_SEL_IVB(pipe));
  3273. else
  3274. I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3);
  3275. I915_WRITE(PF_WIN_POS(pipe), crtc->config.pch_pfit.pos);
  3276. I915_WRITE(PF_WIN_SZ(pipe), crtc->config.pch_pfit.size);
  3277. }
  3278. }
  3279. static void intel_enable_planes(struct drm_crtc *crtc)
  3280. {
  3281. struct drm_device *dev = crtc->dev;
  3282. enum pipe pipe = to_intel_crtc(crtc)->pipe;
  3283. struct drm_plane *plane;
  3284. struct intel_plane *intel_plane;
  3285. drm_for_each_legacy_plane(plane, &dev->mode_config.plane_list) {
  3286. intel_plane = to_intel_plane(plane);
  3287. if (intel_plane->pipe == pipe)
  3288. intel_plane_restore(&intel_plane->base);
  3289. }
  3290. }
  3291. static void intel_disable_planes(struct drm_crtc *crtc)
  3292. {
  3293. struct drm_device *dev = crtc->dev;
  3294. enum pipe pipe = to_intel_crtc(crtc)->pipe;
  3295. struct drm_plane *plane;
  3296. struct intel_plane *intel_plane;
  3297. drm_for_each_legacy_plane(plane, &dev->mode_config.plane_list) {
  3298. intel_plane = to_intel_plane(plane);
  3299. if (intel_plane->pipe == pipe)
  3300. intel_plane_disable(&intel_plane->base);
  3301. }
  3302. }
  3303. void hsw_enable_ips(struct intel_crtc *crtc)
  3304. {
  3305. struct drm_device *dev = crtc->base.dev;
  3306. struct drm_i915_private *dev_priv = dev->dev_private;
  3307. if (!crtc->config.ips_enabled)
  3308. return;
  3309. /* We can only enable IPS after we enable a plane and wait for a vblank */
  3310. intel_wait_for_vblank(dev, crtc->pipe);
  3311. assert_plane_enabled(dev_priv, crtc->plane);
  3312. if (IS_BROADWELL(dev)) {
  3313. mutex_lock(&dev_priv->rps.hw_lock);
  3314. WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0xc0000000));
  3315. mutex_unlock(&dev_priv->rps.hw_lock);
  3316. /* Quoting Art Runyan: "its not safe to expect any particular
  3317. * value in IPS_CTL bit 31 after enabling IPS through the
  3318. * mailbox." Moreover, the mailbox may return a bogus state,
  3319. * so we need to just enable it and continue on.
  3320. */
  3321. } else {
  3322. I915_WRITE(IPS_CTL, IPS_ENABLE);
  3323. /* The bit only becomes 1 in the next vblank, so this wait here
  3324. * is essentially intel_wait_for_vblank. If we don't have this
  3325. * and don't wait for vblanks until the end of crtc_enable, then
  3326. * the HW state readout code will complain that the expected
  3327. * IPS_CTL value is not the one we read. */
  3328. if (wait_for(I915_READ_NOTRACE(IPS_CTL) & IPS_ENABLE, 50))
  3329. DRM_ERROR("Timed out waiting for IPS enable\n");
  3330. }
  3331. }
  3332. void hsw_disable_ips(struct intel_crtc *crtc)
  3333. {
  3334. struct drm_device *dev = crtc->base.dev;
  3335. struct drm_i915_private *dev_priv = dev->dev_private;
  3336. if (!crtc->config.ips_enabled)
  3337. return;
  3338. 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, 0));
  3342. mutex_unlock(&dev_priv->rps.hw_lock);
  3343. /* wait for pcode to finish disabling IPS, which may take up to 42ms */
  3344. if (wait_for((I915_READ(IPS_CTL) & IPS_ENABLE) == 0, 42))
  3345. DRM_ERROR("Timed out waiting for IPS disable\n");
  3346. } else {
  3347. I915_WRITE(IPS_CTL, 0);
  3348. POSTING_READ(IPS_CTL);
  3349. }
  3350. /* We need to wait for a vblank before we can disable the plane. */
  3351. intel_wait_for_vblank(dev, crtc->pipe);
  3352. }
  3353. /** Loads the palette/gamma unit for the CRTC with the prepared values */
  3354. static void intel_crtc_load_lut(struct drm_crtc *crtc)
  3355. {
  3356. struct drm_device *dev = crtc->dev;
  3357. struct drm_i915_private *dev_priv = dev->dev_private;
  3358. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3359. enum pipe pipe = intel_crtc->pipe;
  3360. int palreg = PALETTE(pipe);
  3361. int i;
  3362. bool reenable_ips = false;
  3363. /* The clocks have to be on to load the palette. */
  3364. if (!crtc->enabled || !intel_crtc->active)
  3365. return;
  3366. if (!HAS_PCH_SPLIT(dev_priv->dev)) {
  3367. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DSI))
  3368. assert_dsi_pll_enabled(dev_priv);
  3369. else
  3370. assert_pll_enabled(dev_priv, pipe);
  3371. }
  3372. /* use legacy palette for Ironlake */
  3373. if (!HAS_GMCH_DISPLAY(dev))
  3374. palreg = LGC_PALETTE(pipe);
  3375. /* Workaround : Do not read or write the pipe palette/gamma data while
  3376. * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
  3377. */
  3378. if (IS_HASWELL(dev) && intel_crtc->config.ips_enabled &&
  3379. ((I915_READ(GAMMA_MODE(pipe)) & GAMMA_MODE_MODE_MASK) ==
  3380. GAMMA_MODE_MODE_SPLIT)) {
  3381. hsw_disable_ips(intel_crtc);
  3382. reenable_ips = true;
  3383. }
  3384. for (i = 0; i < 256; i++) {
  3385. I915_WRITE(palreg + 4 * i,
  3386. (intel_crtc->lut_r[i] << 16) |
  3387. (intel_crtc->lut_g[i] << 8) |
  3388. intel_crtc->lut_b[i]);
  3389. }
  3390. if (reenable_ips)
  3391. hsw_enable_ips(intel_crtc);
  3392. }
  3393. static void intel_crtc_dpms_overlay(struct intel_crtc *intel_crtc, bool enable)
  3394. {
  3395. if (!enable && intel_crtc->overlay) {
  3396. struct drm_device *dev = intel_crtc->base.dev;
  3397. struct drm_i915_private *dev_priv = dev->dev_private;
  3398. mutex_lock(&dev->struct_mutex);
  3399. dev_priv->mm.interruptible = false;
  3400. (void) intel_overlay_switch_off(intel_crtc->overlay);
  3401. dev_priv->mm.interruptible = true;
  3402. mutex_unlock(&dev->struct_mutex);
  3403. }
  3404. /* Let userspace switch the overlay on again. In most cases userspace
  3405. * has to recompute where to put it anyway.
  3406. */
  3407. }
  3408. static void intel_crtc_enable_planes(struct drm_crtc *crtc)
  3409. {
  3410. struct drm_device *dev = crtc->dev;
  3411. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3412. int pipe = intel_crtc->pipe;
  3413. assert_vblank_disabled(crtc);
  3414. drm_vblank_on(dev, pipe);
  3415. intel_enable_primary_hw_plane(crtc->primary, crtc);
  3416. intel_enable_planes(crtc);
  3417. intel_crtc_update_cursor(crtc, true);
  3418. intel_crtc_dpms_overlay(intel_crtc, true);
  3419. hsw_enable_ips(intel_crtc);
  3420. mutex_lock(&dev->struct_mutex);
  3421. intel_update_fbc(dev);
  3422. mutex_unlock(&dev->struct_mutex);
  3423. /*
  3424. * FIXME: Once we grow proper nuclear flip support out of this we need
  3425. * to compute the mask of flip planes precisely. For the time being
  3426. * consider this a flip from a NULL plane.
  3427. */
  3428. intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_ALL_MASK(pipe));
  3429. }
  3430. static void intel_crtc_disable_planes(struct drm_crtc *crtc)
  3431. {
  3432. struct drm_device *dev = crtc->dev;
  3433. struct drm_i915_private *dev_priv = dev->dev_private;
  3434. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3435. int pipe = intel_crtc->pipe;
  3436. int plane = intel_crtc->plane;
  3437. intel_crtc_wait_for_pending_flips(crtc);
  3438. if (dev_priv->fbc.plane == plane)
  3439. intel_disable_fbc(dev);
  3440. hsw_disable_ips(intel_crtc);
  3441. intel_crtc_dpms_overlay(intel_crtc, false);
  3442. intel_crtc_update_cursor(crtc, false);
  3443. intel_disable_planes(crtc);
  3444. intel_disable_primary_hw_plane(crtc->primary, crtc);
  3445. /*
  3446. * FIXME: Once we grow proper nuclear flip support out of this we need
  3447. * to compute the mask of flip planes precisely. For the time being
  3448. * consider this a flip to a NULL plane.
  3449. */
  3450. intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_ALL_MASK(pipe));
  3451. drm_vblank_off(dev, pipe);
  3452. assert_vblank_disabled(crtc);
  3453. }
  3454. static void ironlake_crtc_enable(struct drm_crtc *crtc)
  3455. {
  3456. struct drm_device *dev = crtc->dev;
  3457. struct drm_i915_private *dev_priv = dev->dev_private;
  3458. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3459. struct intel_encoder *encoder;
  3460. int pipe = intel_crtc->pipe;
  3461. WARN_ON(!crtc->enabled);
  3462. if (intel_crtc->active)
  3463. return;
  3464. if (intel_crtc->config.has_pch_encoder)
  3465. intel_prepare_shared_dpll(intel_crtc);
  3466. if (intel_crtc->config.has_dp_encoder)
  3467. intel_dp_set_m_n(intel_crtc);
  3468. intel_set_pipe_timings(intel_crtc);
  3469. if (intel_crtc->config.has_pch_encoder) {
  3470. intel_cpu_transcoder_set_m_n(intel_crtc,
  3471. &intel_crtc->config.fdi_m_n, NULL);
  3472. }
  3473. ironlake_set_pipeconf(crtc);
  3474. intel_crtc->active = true;
  3475. intel_set_cpu_fifo_underrun_reporting(dev, pipe, true);
  3476. intel_set_pch_fifo_underrun_reporting(dev, pipe, true);
  3477. for_each_encoder_on_crtc(dev, crtc, encoder)
  3478. if (encoder->pre_enable)
  3479. encoder->pre_enable(encoder);
  3480. if (intel_crtc->config.has_pch_encoder) {
  3481. /* Note: FDI PLL enabling _must_ be done before we enable the
  3482. * cpu pipes, hence this is separate from all the other fdi/pch
  3483. * enabling. */
  3484. ironlake_fdi_pll_enable(intel_crtc);
  3485. } else {
  3486. assert_fdi_tx_disabled(dev_priv, pipe);
  3487. assert_fdi_rx_disabled(dev_priv, pipe);
  3488. }
  3489. ironlake_pfit_enable(intel_crtc);
  3490. /*
  3491. * On ILK+ LUT must be loaded before the pipe is running but with
  3492. * clocks enabled
  3493. */
  3494. intel_crtc_load_lut(crtc);
  3495. intel_update_watermarks(crtc);
  3496. intel_enable_pipe(intel_crtc);
  3497. if (intel_crtc->config.has_pch_encoder)
  3498. ironlake_pch_enable(crtc);
  3499. for_each_encoder_on_crtc(dev, crtc, encoder)
  3500. encoder->enable(encoder);
  3501. if (HAS_PCH_CPT(dev))
  3502. cpt_verify_modeset(dev, intel_crtc->pipe);
  3503. intel_crtc_enable_planes(crtc);
  3504. }
  3505. /* IPS only exists on ULT machines and is tied to pipe A. */
  3506. static bool hsw_crtc_supports_ips(struct intel_crtc *crtc)
  3507. {
  3508. return HAS_IPS(crtc->base.dev) && crtc->pipe == PIPE_A;
  3509. }
  3510. /*
  3511. * This implements the workaround described in the "notes" section of the mode
  3512. * set sequence documentation. When going from no pipes or single pipe to
  3513. * multiple pipes, and planes are enabled after the pipe, we need to wait at
  3514. * least 2 vblanks on the first pipe before enabling planes on the second pipe.
  3515. */
  3516. static void haswell_mode_set_planes_workaround(struct intel_crtc *crtc)
  3517. {
  3518. struct drm_device *dev = crtc->base.dev;
  3519. struct intel_crtc *crtc_it, *other_active_crtc = NULL;
  3520. /* We want to get the other_active_crtc only if there's only 1 other
  3521. * active crtc. */
  3522. for_each_intel_crtc(dev, crtc_it) {
  3523. if (!crtc_it->active || crtc_it == crtc)
  3524. continue;
  3525. if (other_active_crtc)
  3526. return;
  3527. other_active_crtc = crtc_it;
  3528. }
  3529. if (!other_active_crtc)
  3530. return;
  3531. intel_wait_for_vblank(dev, other_active_crtc->pipe);
  3532. intel_wait_for_vblank(dev, other_active_crtc->pipe);
  3533. }
  3534. static void haswell_crtc_enable(struct drm_crtc *crtc)
  3535. {
  3536. struct drm_device *dev = crtc->dev;
  3537. struct drm_i915_private *dev_priv = dev->dev_private;
  3538. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3539. struct intel_encoder *encoder;
  3540. int pipe = intel_crtc->pipe;
  3541. WARN_ON(!crtc->enabled);
  3542. if (intel_crtc->active)
  3543. return;
  3544. if (intel_crtc_to_shared_dpll(intel_crtc))
  3545. intel_enable_shared_dpll(intel_crtc);
  3546. if (intel_crtc->config.has_dp_encoder)
  3547. intel_dp_set_m_n(intel_crtc);
  3548. intel_set_pipe_timings(intel_crtc);
  3549. if (intel_crtc->config.has_pch_encoder) {
  3550. intel_cpu_transcoder_set_m_n(intel_crtc,
  3551. &intel_crtc->config.fdi_m_n, NULL);
  3552. }
  3553. haswell_set_pipeconf(crtc);
  3554. intel_set_pipe_csc(crtc);
  3555. intel_crtc->active = true;
  3556. intel_set_cpu_fifo_underrun_reporting(dev, pipe, true);
  3557. for_each_encoder_on_crtc(dev, crtc, encoder)
  3558. if (encoder->pre_enable)
  3559. encoder->pre_enable(encoder);
  3560. if (intel_crtc->config.has_pch_encoder) {
  3561. intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, true);
  3562. dev_priv->display.fdi_link_train(crtc);
  3563. }
  3564. intel_ddi_enable_pipe_clock(intel_crtc);
  3565. ironlake_pfit_enable(intel_crtc);
  3566. /*
  3567. * On ILK+ LUT must be loaded before the pipe is running but with
  3568. * clocks enabled
  3569. */
  3570. intel_crtc_load_lut(crtc);
  3571. intel_ddi_set_pipe_settings(crtc);
  3572. intel_ddi_enable_transcoder_func(crtc);
  3573. intel_update_watermarks(crtc);
  3574. intel_enable_pipe(intel_crtc);
  3575. if (intel_crtc->config.has_pch_encoder)
  3576. lpt_pch_enable(crtc);
  3577. if (intel_crtc->config.dp_encoder_is_mst)
  3578. intel_ddi_set_vc_payload_alloc(crtc, true);
  3579. for_each_encoder_on_crtc(dev, crtc, encoder) {
  3580. encoder->enable(encoder);
  3581. intel_opregion_notify_encoder(encoder, true);
  3582. }
  3583. /* If we change the relative order between pipe/planes enabling, we need
  3584. * to change the workaround. */
  3585. haswell_mode_set_planes_workaround(intel_crtc);
  3586. intel_crtc_enable_planes(crtc);
  3587. }
  3588. static void ironlake_pfit_disable(struct intel_crtc *crtc)
  3589. {
  3590. struct drm_device *dev = crtc->base.dev;
  3591. struct drm_i915_private *dev_priv = dev->dev_private;
  3592. int pipe = crtc->pipe;
  3593. /* To avoid upsetting the power well on haswell only disable the pfit if
  3594. * it's in use. The hw state code will make sure we get this right. */
  3595. if (crtc->config.pch_pfit.enabled) {
  3596. I915_WRITE(PF_CTL(pipe), 0);
  3597. I915_WRITE(PF_WIN_POS(pipe), 0);
  3598. I915_WRITE(PF_WIN_SZ(pipe), 0);
  3599. }
  3600. }
  3601. static void ironlake_crtc_disable(struct drm_crtc *crtc)
  3602. {
  3603. struct drm_device *dev = crtc->dev;
  3604. struct drm_i915_private *dev_priv = dev->dev_private;
  3605. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3606. struct intel_encoder *encoder;
  3607. int pipe = intel_crtc->pipe;
  3608. u32 reg, temp;
  3609. if (!intel_crtc->active)
  3610. return;
  3611. intel_crtc_disable_planes(crtc);
  3612. for_each_encoder_on_crtc(dev, crtc, encoder)
  3613. encoder->disable(encoder);
  3614. if (intel_crtc->config.has_pch_encoder)
  3615. intel_set_pch_fifo_underrun_reporting(dev, pipe, false);
  3616. intel_disable_pipe(intel_crtc);
  3617. ironlake_pfit_disable(intel_crtc);
  3618. for_each_encoder_on_crtc(dev, crtc, encoder)
  3619. if (encoder->post_disable)
  3620. encoder->post_disable(encoder);
  3621. if (intel_crtc->config.has_pch_encoder) {
  3622. ironlake_fdi_disable(crtc);
  3623. ironlake_disable_pch_transcoder(dev_priv, pipe);
  3624. intel_set_pch_fifo_underrun_reporting(dev, pipe, true);
  3625. if (HAS_PCH_CPT(dev)) {
  3626. /* disable TRANS_DP_CTL */
  3627. reg = TRANS_DP_CTL(pipe);
  3628. temp = I915_READ(reg);
  3629. temp &= ~(TRANS_DP_OUTPUT_ENABLE |
  3630. TRANS_DP_PORT_SEL_MASK);
  3631. temp |= TRANS_DP_PORT_SEL_NONE;
  3632. I915_WRITE(reg, temp);
  3633. /* disable DPLL_SEL */
  3634. temp = I915_READ(PCH_DPLL_SEL);
  3635. temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe));
  3636. I915_WRITE(PCH_DPLL_SEL, temp);
  3637. }
  3638. /* disable PCH DPLL */
  3639. intel_disable_shared_dpll(intel_crtc);
  3640. ironlake_fdi_pll_disable(intel_crtc);
  3641. }
  3642. intel_crtc->active = false;
  3643. intel_update_watermarks(crtc);
  3644. mutex_lock(&dev->struct_mutex);
  3645. intel_update_fbc(dev);
  3646. mutex_unlock(&dev->struct_mutex);
  3647. }
  3648. static void haswell_crtc_disable(struct drm_crtc *crtc)
  3649. {
  3650. struct drm_device *dev = crtc->dev;
  3651. struct drm_i915_private *dev_priv = dev->dev_private;
  3652. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3653. struct intel_encoder *encoder;
  3654. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  3655. if (!intel_crtc->active)
  3656. return;
  3657. intel_crtc_disable_planes(crtc);
  3658. for_each_encoder_on_crtc(dev, crtc, encoder) {
  3659. intel_opregion_notify_encoder(encoder, false);
  3660. encoder->disable(encoder);
  3661. }
  3662. if (intel_crtc->config.has_pch_encoder)
  3663. intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, false);
  3664. intel_disable_pipe(intel_crtc);
  3665. if (intel_crtc->config.dp_encoder_is_mst)
  3666. intel_ddi_set_vc_payload_alloc(crtc, false);
  3667. intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder);
  3668. ironlake_pfit_disable(intel_crtc);
  3669. intel_ddi_disable_pipe_clock(intel_crtc);
  3670. if (intel_crtc->config.has_pch_encoder) {
  3671. lpt_disable_pch_transcoder(dev_priv);
  3672. intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, true);
  3673. intel_ddi_fdi_disable(crtc);
  3674. }
  3675. for_each_encoder_on_crtc(dev, crtc, encoder)
  3676. if (encoder->post_disable)
  3677. encoder->post_disable(encoder);
  3678. intel_crtc->active = false;
  3679. intel_update_watermarks(crtc);
  3680. mutex_lock(&dev->struct_mutex);
  3681. intel_update_fbc(dev);
  3682. mutex_unlock(&dev->struct_mutex);
  3683. if (intel_crtc_to_shared_dpll(intel_crtc))
  3684. intel_disable_shared_dpll(intel_crtc);
  3685. }
  3686. static void ironlake_crtc_off(struct drm_crtc *crtc)
  3687. {
  3688. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3689. intel_put_shared_dpll(intel_crtc);
  3690. }
  3691. static void i9xx_pfit_enable(struct intel_crtc *crtc)
  3692. {
  3693. struct drm_device *dev = crtc->base.dev;
  3694. struct drm_i915_private *dev_priv = dev->dev_private;
  3695. struct intel_crtc_config *pipe_config = &crtc->config;
  3696. if (!crtc->config.gmch_pfit.control)
  3697. return;
  3698. /*
  3699. * The panel fitter should only be adjusted whilst the pipe is disabled,
  3700. * according to register description and PRM.
  3701. */
  3702. WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE);
  3703. assert_pipe_disabled(dev_priv, crtc->pipe);
  3704. I915_WRITE(PFIT_PGM_RATIOS, pipe_config->gmch_pfit.pgm_ratios);
  3705. I915_WRITE(PFIT_CONTROL, pipe_config->gmch_pfit.control);
  3706. /* Border color in case we don't scale up to the full screen. Black by
  3707. * default, change to something else for debugging. */
  3708. I915_WRITE(BCLRPAT(crtc->pipe), 0);
  3709. }
  3710. static enum intel_display_power_domain port_to_power_domain(enum port port)
  3711. {
  3712. switch (port) {
  3713. case PORT_A:
  3714. return POWER_DOMAIN_PORT_DDI_A_4_LANES;
  3715. case PORT_B:
  3716. return POWER_DOMAIN_PORT_DDI_B_4_LANES;
  3717. case PORT_C:
  3718. return POWER_DOMAIN_PORT_DDI_C_4_LANES;
  3719. case PORT_D:
  3720. return POWER_DOMAIN_PORT_DDI_D_4_LANES;
  3721. default:
  3722. WARN_ON_ONCE(1);
  3723. return POWER_DOMAIN_PORT_OTHER;
  3724. }
  3725. }
  3726. #define for_each_power_domain(domain, mask) \
  3727. for ((domain) = 0; (domain) < POWER_DOMAIN_NUM; (domain)++) \
  3728. if ((1 << (domain)) & (mask))
  3729. enum intel_display_power_domain
  3730. intel_display_port_power_domain(struct intel_encoder *intel_encoder)
  3731. {
  3732. struct drm_device *dev = intel_encoder->base.dev;
  3733. struct intel_digital_port *intel_dig_port;
  3734. switch (intel_encoder->type) {
  3735. case INTEL_OUTPUT_UNKNOWN:
  3736. /* Only DDI platforms should ever use this output type */
  3737. WARN_ON_ONCE(!HAS_DDI(dev));
  3738. case INTEL_OUTPUT_DISPLAYPORT:
  3739. case INTEL_OUTPUT_HDMI:
  3740. case INTEL_OUTPUT_EDP:
  3741. intel_dig_port = enc_to_dig_port(&intel_encoder->base);
  3742. return port_to_power_domain(intel_dig_port->port);
  3743. case INTEL_OUTPUT_DP_MST:
  3744. intel_dig_port = enc_to_mst(&intel_encoder->base)->primary;
  3745. return port_to_power_domain(intel_dig_port->port);
  3746. case INTEL_OUTPUT_ANALOG:
  3747. return POWER_DOMAIN_PORT_CRT;
  3748. case INTEL_OUTPUT_DSI:
  3749. return POWER_DOMAIN_PORT_DSI;
  3750. default:
  3751. return POWER_DOMAIN_PORT_OTHER;
  3752. }
  3753. }
  3754. static unsigned long get_crtc_power_domains(struct drm_crtc *crtc)
  3755. {
  3756. struct drm_device *dev = crtc->dev;
  3757. struct intel_encoder *intel_encoder;
  3758. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3759. enum pipe pipe = intel_crtc->pipe;
  3760. unsigned long mask;
  3761. enum transcoder transcoder;
  3762. transcoder = intel_pipe_to_cpu_transcoder(dev->dev_private, pipe);
  3763. mask = BIT(POWER_DOMAIN_PIPE(pipe));
  3764. mask |= BIT(POWER_DOMAIN_TRANSCODER(transcoder));
  3765. if (intel_crtc->config.pch_pfit.enabled ||
  3766. intel_crtc->config.pch_pfit.force_thru)
  3767. mask |= BIT(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe));
  3768. for_each_encoder_on_crtc(dev, crtc, intel_encoder)
  3769. mask |= BIT(intel_display_port_power_domain(intel_encoder));
  3770. return mask;
  3771. }
  3772. void intel_display_set_init_power(struct drm_i915_private *dev_priv,
  3773. bool enable)
  3774. {
  3775. if (dev_priv->power_domains.init_power_on == enable)
  3776. return;
  3777. if (enable)
  3778. intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
  3779. else
  3780. intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
  3781. dev_priv->power_domains.init_power_on = enable;
  3782. }
  3783. static void modeset_update_crtc_power_domains(struct drm_device *dev)
  3784. {
  3785. struct drm_i915_private *dev_priv = dev->dev_private;
  3786. unsigned long pipe_domains[I915_MAX_PIPES] = { 0, };
  3787. struct intel_crtc *crtc;
  3788. /*
  3789. * First get all needed power domains, then put all unneeded, to avoid
  3790. * any unnecessary toggling of the power wells.
  3791. */
  3792. for_each_intel_crtc(dev, crtc) {
  3793. enum intel_display_power_domain domain;
  3794. if (!crtc->base.enabled)
  3795. continue;
  3796. pipe_domains[crtc->pipe] = get_crtc_power_domains(&crtc->base);
  3797. for_each_power_domain(domain, pipe_domains[crtc->pipe])
  3798. intel_display_power_get(dev_priv, domain);
  3799. }
  3800. for_each_intel_crtc(dev, crtc) {
  3801. enum intel_display_power_domain domain;
  3802. for_each_power_domain(domain, crtc->enabled_power_domains)
  3803. intel_display_power_put(dev_priv, domain);
  3804. crtc->enabled_power_domains = pipe_domains[crtc->pipe];
  3805. }
  3806. intel_display_set_init_power(dev_priv, false);
  3807. }
  3808. /* returns HPLL frequency in kHz */
  3809. static int valleyview_get_vco(struct drm_i915_private *dev_priv)
  3810. {
  3811. int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 };
  3812. /* Obtain SKU information */
  3813. mutex_lock(&dev_priv->dpio_lock);
  3814. hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) &
  3815. CCK_FUSE_HPLL_FREQ_MASK;
  3816. mutex_unlock(&dev_priv->dpio_lock);
  3817. return vco_freq[hpll_freq] * 1000;
  3818. }
  3819. static void vlv_update_cdclk(struct drm_device *dev)
  3820. {
  3821. struct drm_i915_private *dev_priv = dev->dev_private;
  3822. dev_priv->vlv_cdclk_freq = dev_priv->display.get_display_clock_speed(dev);
  3823. DRM_DEBUG_DRIVER("Current CD clock rate: %d kHz",
  3824. dev_priv->vlv_cdclk_freq);
  3825. /*
  3826. * Program the gmbus_freq based on the cdclk frequency.
  3827. * BSpec erroneously claims we should aim for 4MHz, but
  3828. * in fact 1MHz is the correct frequency.
  3829. */
  3830. I915_WRITE(GMBUSFREQ_VLV, dev_priv->vlv_cdclk_freq);
  3831. }
  3832. /* Adjust CDclk dividers to allow high res or save power if possible */
  3833. static void valleyview_set_cdclk(struct drm_device *dev, int cdclk)
  3834. {
  3835. struct drm_i915_private *dev_priv = dev->dev_private;
  3836. u32 val, cmd;
  3837. WARN_ON(dev_priv->display.get_display_clock_speed(dev) != dev_priv->vlv_cdclk_freq);
  3838. if (cdclk >= 320000) /* jump to highest voltage for 400MHz too */
  3839. cmd = 2;
  3840. else if (cdclk == 266667)
  3841. cmd = 1;
  3842. else
  3843. cmd = 0;
  3844. mutex_lock(&dev_priv->rps.hw_lock);
  3845. val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
  3846. val &= ~DSPFREQGUAR_MASK;
  3847. val |= (cmd << DSPFREQGUAR_SHIFT);
  3848. vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val);
  3849. if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) &
  3850. DSPFREQSTAT_MASK) == (cmd << DSPFREQSTAT_SHIFT),
  3851. 50)) {
  3852. DRM_ERROR("timed out waiting for CDclk change\n");
  3853. }
  3854. mutex_unlock(&dev_priv->rps.hw_lock);
  3855. if (cdclk == 400000) {
  3856. u32 divider, vco;
  3857. vco = valleyview_get_vco(dev_priv);
  3858. divider = DIV_ROUND_CLOSEST(vco << 1, cdclk) - 1;
  3859. mutex_lock(&dev_priv->dpio_lock);
  3860. /* adjust cdclk divider */
  3861. val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL);
  3862. val &= ~DISPLAY_FREQUENCY_VALUES;
  3863. val |= divider;
  3864. vlv_cck_write(dev_priv, CCK_DISPLAY_CLOCK_CONTROL, val);
  3865. if (wait_for((vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL) &
  3866. DISPLAY_FREQUENCY_STATUS) == (divider << DISPLAY_FREQUENCY_STATUS_SHIFT),
  3867. 50))
  3868. DRM_ERROR("timed out waiting for CDclk change\n");
  3869. mutex_unlock(&dev_priv->dpio_lock);
  3870. }
  3871. mutex_lock(&dev_priv->dpio_lock);
  3872. /* adjust self-refresh exit latency value */
  3873. val = vlv_bunit_read(dev_priv, BUNIT_REG_BISOC);
  3874. val &= ~0x7f;
  3875. /*
  3876. * For high bandwidth configs, we set a higher latency in the bunit
  3877. * so that the core display fetch happens in time to avoid underruns.
  3878. */
  3879. if (cdclk == 400000)
  3880. val |= 4500 / 250; /* 4.5 usec */
  3881. else
  3882. val |= 3000 / 250; /* 3.0 usec */
  3883. vlv_bunit_write(dev_priv, BUNIT_REG_BISOC, val);
  3884. mutex_unlock(&dev_priv->dpio_lock);
  3885. vlv_update_cdclk(dev);
  3886. }
  3887. static void cherryview_set_cdclk(struct drm_device *dev, int cdclk)
  3888. {
  3889. struct drm_i915_private *dev_priv = dev->dev_private;
  3890. u32 val, cmd;
  3891. WARN_ON(dev_priv->display.get_display_clock_speed(dev) != dev_priv->vlv_cdclk_freq);
  3892. switch (cdclk) {
  3893. case 400000:
  3894. cmd = 3;
  3895. break;
  3896. case 333333:
  3897. case 320000:
  3898. cmd = 2;
  3899. break;
  3900. case 266667:
  3901. cmd = 1;
  3902. break;
  3903. case 200000:
  3904. cmd = 0;
  3905. break;
  3906. default:
  3907. WARN_ON(1);
  3908. return;
  3909. }
  3910. mutex_lock(&dev_priv->rps.hw_lock);
  3911. val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
  3912. val &= ~DSPFREQGUAR_MASK_CHV;
  3913. val |= (cmd << DSPFREQGUAR_SHIFT_CHV);
  3914. vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val);
  3915. if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) &
  3916. DSPFREQSTAT_MASK_CHV) == (cmd << DSPFREQSTAT_SHIFT_CHV),
  3917. 50)) {
  3918. DRM_ERROR("timed out waiting for CDclk change\n");
  3919. }
  3920. mutex_unlock(&dev_priv->rps.hw_lock);
  3921. vlv_update_cdclk(dev);
  3922. }
  3923. static int valleyview_calc_cdclk(struct drm_i915_private *dev_priv,
  3924. int max_pixclk)
  3925. {
  3926. int vco = valleyview_get_vco(dev_priv);
  3927. int freq_320 = (vco << 1) % 320000 != 0 ? 333333 : 320000;
  3928. /* FIXME: Punit isn't quite ready yet */
  3929. if (IS_CHERRYVIEW(dev_priv->dev))
  3930. return 400000;
  3931. /*
  3932. * Really only a few cases to deal with, as only 4 CDclks are supported:
  3933. * 200MHz
  3934. * 267MHz
  3935. * 320/333MHz (depends on HPLL freq)
  3936. * 400MHz
  3937. * So we check to see whether we're above 90% of the lower bin and
  3938. * adjust if needed.
  3939. *
  3940. * We seem to get an unstable or solid color picture at 200MHz.
  3941. * Not sure what's wrong. For now use 200MHz only when all pipes
  3942. * are off.
  3943. */
  3944. if (max_pixclk > freq_320*9/10)
  3945. return 400000;
  3946. else if (max_pixclk > 266667*9/10)
  3947. return freq_320;
  3948. else if (max_pixclk > 0)
  3949. return 266667;
  3950. else
  3951. return 200000;
  3952. }
  3953. /* compute the max pixel clock for new configuration */
  3954. static int intel_mode_max_pixclk(struct drm_i915_private *dev_priv)
  3955. {
  3956. struct drm_device *dev = dev_priv->dev;
  3957. struct intel_crtc *intel_crtc;
  3958. int max_pixclk = 0;
  3959. for_each_intel_crtc(dev, intel_crtc) {
  3960. if (intel_crtc->new_enabled)
  3961. max_pixclk = max(max_pixclk,
  3962. intel_crtc->new_config->adjusted_mode.crtc_clock);
  3963. }
  3964. return max_pixclk;
  3965. }
  3966. static void valleyview_modeset_global_pipes(struct drm_device *dev,
  3967. unsigned *prepare_pipes)
  3968. {
  3969. struct drm_i915_private *dev_priv = dev->dev_private;
  3970. struct intel_crtc *intel_crtc;
  3971. int max_pixclk = intel_mode_max_pixclk(dev_priv);
  3972. if (valleyview_calc_cdclk(dev_priv, max_pixclk) ==
  3973. dev_priv->vlv_cdclk_freq)
  3974. return;
  3975. /* disable/enable all currently active pipes while we change cdclk */
  3976. for_each_intel_crtc(dev, intel_crtc)
  3977. if (intel_crtc->base.enabled)
  3978. *prepare_pipes |= (1 << intel_crtc->pipe);
  3979. }
  3980. static void valleyview_modeset_global_resources(struct drm_device *dev)
  3981. {
  3982. struct drm_i915_private *dev_priv = dev->dev_private;
  3983. int max_pixclk = intel_mode_max_pixclk(dev_priv);
  3984. int req_cdclk = valleyview_calc_cdclk(dev_priv, max_pixclk);
  3985. if (req_cdclk != dev_priv->vlv_cdclk_freq) {
  3986. if (IS_CHERRYVIEW(dev))
  3987. cherryview_set_cdclk(dev, req_cdclk);
  3988. else
  3989. valleyview_set_cdclk(dev, req_cdclk);
  3990. }
  3991. modeset_update_crtc_power_domains(dev);
  3992. }
  3993. static void valleyview_crtc_enable(struct drm_crtc *crtc)
  3994. {
  3995. struct drm_device *dev = crtc->dev;
  3996. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3997. struct intel_encoder *encoder;
  3998. int pipe = intel_crtc->pipe;
  3999. bool is_dsi;
  4000. WARN_ON(!crtc->enabled);
  4001. if (intel_crtc->active)
  4002. return;
  4003. is_dsi = intel_pipe_has_type(crtc, INTEL_OUTPUT_DSI);
  4004. if (!is_dsi) {
  4005. if (IS_CHERRYVIEW(dev))
  4006. chv_prepare_pll(intel_crtc);
  4007. else
  4008. vlv_prepare_pll(intel_crtc);
  4009. }
  4010. if (intel_crtc->config.has_dp_encoder)
  4011. intel_dp_set_m_n(intel_crtc);
  4012. intel_set_pipe_timings(intel_crtc);
  4013. i9xx_set_pipeconf(intel_crtc);
  4014. intel_crtc->active = true;
  4015. intel_set_cpu_fifo_underrun_reporting(dev, pipe, true);
  4016. for_each_encoder_on_crtc(dev, crtc, encoder)
  4017. if (encoder->pre_pll_enable)
  4018. encoder->pre_pll_enable(encoder);
  4019. if (!is_dsi) {
  4020. if (IS_CHERRYVIEW(dev))
  4021. chv_enable_pll(intel_crtc);
  4022. else
  4023. vlv_enable_pll(intel_crtc);
  4024. }
  4025. for_each_encoder_on_crtc(dev, crtc, encoder)
  4026. if (encoder->pre_enable)
  4027. encoder->pre_enable(encoder);
  4028. i9xx_pfit_enable(intel_crtc);
  4029. intel_crtc_load_lut(crtc);
  4030. intel_update_watermarks(crtc);
  4031. intel_enable_pipe(intel_crtc);
  4032. for_each_encoder_on_crtc(dev, crtc, encoder)
  4033. encoder->enable(encoder);
  4034. intel_crtc_enable_planes(crtc);
  4035. /* Underruns don't raise interrupts, so check manually. */
  4036. i9xx_check_fifo_underruns(dev);
  4037. }
  4038. static void i9xx_set_pll_dividers(struct intel_crtc *crtc)
  4039. {
  4040. struct drm_device *dev = crtc->base.dev;
  4041. struct drm_i915_private *dev_priv = dev->dev_private;
  4042. I915_WRITE(FP0(crtc->pipe), crtc->config.dpll_hw_state.fp0);
  4043. I915_WRITE(FP1(crtc->pipe), crtc->config.dpll_hw_state.fp1);
  4044. }
  4045. static void i9xx_crtc_enable(struct drm_crtc *crtc)
  4046. {
  4047. struct drm_device *dev = crtc->dev;
  4048. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4049. struct intel_encoder *encoder;
  4050. int pipe = intel_crtc->pipe;
  4051. WARN_ON(!crtc->enabled);
  4052. if (intel_crtc->active)
  4053. return;
  4054. i9xx_set_pll_dividers(intel_crtc);
  4055. if (intel_crtc->config.has_dp_encoder)
  4056. intel_dp_set_m_n(intel_crtc);
  4057. intel_set_pipe_timings(intel_crtc);
  4058. i9xx_set_pipeconf(intel_crtc);
  4059. intel_crtc->active = true;
  4060. if (!IS_GEN2(dev))
  4061. intel_set_cpu_fifo_underrun_reporting(dev, pipe, true);
  4062. for_each_encoder_on_crtc(dev, crtc, encoder)
  4063. if (encoder->pre_enable)
  4064. encoder->pre_enable(encoder);
  4065. i9xx_enable_pll(intel_crtc);
  4066. i9xx_pfit_enable(intel_crtc);
  4067. intel_crtc_load_lut(crtc);
  4068. intel_update_watermarks(crtc);
  4069. intel_enable_pipe(intel_crtc);
  4070. for_each_encoder_on_crtc(dev, crtc, encoder)
  4071. encoder->enable(encoder);
  4072. intel_crtc_enable_planes(crtc);
  4073. /*
  4074. * Gen2 reports pipe underruns whenever all planes are disabled.
  4075. * So don't enable underrun reporting before at least some planes
  4076. * are enabled.
  4077. * FIXME: Need to fix the logic to work when we turn off all planes
  4078. * but leave the pipe running.
  4079. */
  4080. if (IS_GEN2(dev))
  4081. intel_set_cpu_fifo_underrun_reporting(dev, pipe, true);
  4082. /* Underruns don't raise interrupts, so check manually. */
  4083. i9xx_check_fifo_underruns(dev);
  4084. }
  4085. static void i9xx_pfit_disable(struct intel_crtc *crtc)
  4086. {
  4087. struct drm_device *dev = crtc->base.dev;
  4088. struct drm_i915_private *dev_priv = dev->dev_private;
  4089. if (!crtc->config.gmch_pfit.control)
  4090. return;
  4091. assert_pipe_disabled(dev_priv, crtc->pipe);
  4092. DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n",
  4093. I915_READ(PFIT_CONTROL));
  4094. I915_WRITE(PFIT_CONTROL, 0);
  4095. }
  4096. static void i9xx_crtc_disable(struct drm_crtc *crtc)
  4097. {
  4098. struct drm_device *dev = crtc->dev;
  4099. struct drm_i915_private *dev_priv = dev->dev_private;
  4100. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4101. struct intel_encoder *encoder;
  4102. int pipe = intel_crtc->pipe;
  4103. if (!intel_crtc->active)
  4104. return;
  4105. /*
  4106. * Gen2 reports pipe underruns whenever all planes are disabled.
  4107. * So diasble underrun reporting before all the planes get disabled.
  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, false);
  4113. /*
  4114. * Vblank time updates from the shadow to live plane control register
  4115. * are blocked if the memory self-refresh mode is active at that
  4116. * moment. So to make sure the plane gets truly disabled, disable
  4117. * first the self-refresh mode. The self-refresh enable bit in turn
  4118. * will be checked/applied by the HW only at the next frame start
  4119. * event which is after the vblank start event, so we need to have a
  4120. * wait-for-vblank between disabling the plane and the pipe.
  4121. */
  4122. intel_set_memory_cxsr(dev_priv, false);
  4123. intel_crtc_disable_planes(crtc);
  4124. for_each_encoder_on_crtc(dev, crtc, encoder)
  4125. encoder->disable(encoder);
  4126. /*
  4127. * On gen2 planes are double buffered but the pipe isn't, so we must
  4128. * wait for planes to fully turn off before disabling the pipe.
  4129. * We also need to wait on all gmch platforms because of the
  4130. * self-refresh mode constraint explained above.
  4131. */
  4132. intel_wait_for_vblank(dev, pipe);
  4133. intel_disable_pipe(intel_crtc);
  4134. i9xx_pfit_disable(intel_crtc);
  4135. for_each_encoder_on_crtc(dev, crtc, encoder)
  4136. if (encoder->post_disable)
  4137. encoder->post_disable(encoder);
  4138. if (!intel_pipe_has_type(crtc, INTEL_OUTPUT_DSI)) {
  4139. if (IS_CHERRYVIEW(dev))
  4140. chv_disable_pll(dev_priv, pipe);
  4141. else if (IS_VALLEYVIEW(dev))
  4142. vlv_disable_pll(dev_priv, pipe);
  4143. else
  4144. i9xx_disable_pll(intel_crtc);
  4145. }
  4146. if (!IS_GEN2(dev))
  4147. intel_set_cpu_fifo_underrun_reporting(dev, pipe, false);
  4148. intel_crtc->active = false;
  4149. intel_update_watermarks(crtc);
  4150. mutex_lock(&dev->struct_mutex);
  4151. intel_update_fbc(dev);
  4152. mutex_unlock(&dev->struct_mutex);
  4153. }
  4154. static void i9xx_crtc_off(struct drm_crtc *crtc)
  4155. {
  4156. }
  4157. static void intel_crtc_update_sarea(struct drm_crtc *crtc,
  4158. bool enabled)
  4159. {
  4160. struct drm_device *dev = crtc->dev;
  4161. struct drm_i915_master_private *master_priv;
  4162. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4163. int pipe = intel_crtc->pipe;
  4164. if (!dev->primary->master)
  4165. return;
  4166. master_priv = dev->primary->master->driver_priv;
  4167. if (!master_priv->sarea_priv)
  4168. return;
  4169. switch (pipe) {
  4170. case 0:
  4171. master_priv->sarea_priv->pipeA_w = enabled ? crtc->mode.hdisplay : 0;
  4172. master_priv->sarea_priv->pipeA_h = enabled ? crtc->mode.vdisplay : 0;
  4173. break;
  4174. case 1:
  4175. master_priv->sarea_priv->pipeB_w = enabled ? crtc->mode.hdisplay : 0;
  4176. master_priv->sarea_priv->pipeB_h = enabled ? crtc->mode.vdisplay : 0;
  4177. break;
  4178. default:
  4179. DRM_ERROR("Can't update pipe %c in SAREA\n", pipe_name(pipe));
  4180. break;
  4181. }
  4182. }
  4183. /* Master function to enable/disable CRTC and corresponding power wells */
  4184. void intel_crtc_control(struct drm_crtc *crtc, bool enable)
  4185. {
  4186. struct drm_device *dev = crtc->dev;
  4187. struct drm_i915_private *dev_priv = dev->dev_private;
  4188. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4189. enum intel_display_power_domain domain;
  4190. unsigned long domains;
  4191. if (enable) {
  4192. if (!intel_crtc->active) {
  4193. domains = get_crtc_power_domains(crtc);
  4194. for_each_power_domain(domain, domains)
  4195. intel_display_power_get(dev_priv, domain);
  4196. intel_crtc->enabled_power_domains = domains;
  4197. dev_priv->display.crtc_enable(crtc);
  4198. }
  4199. } else {
  4200. if (intel_crtc->active) {
  4201. dev_priv->display.crtc_disable(crtc);
  4202. domains = intel_crtc->enabled_power_domains;
  4203. for_each_power_domain(domain, domains)
  4204. intel_display_power_put(dev_priv, domain);
  4205. intel_crtc->enabled_power_domains = 0;
  4206. }
  4207. }
  4208. }
  4209. /**
  4210. * Sets the power management mode of the pipe and plane.
  4211. */
  4212. void intel_crtc_update_dpms(struct drm_crtc *crtc)
  4213. {
  4214. struct drm_device *dev = crtc->dev;
  4215. struct intel_encoder *intel_encoder;
  4216. bool enable = false;
  4217. for_each_encoder_on_crtc(dev, crtc, intel_encoder)
  4218. enable |= intel_encoder->connectors_active;
  4219. intel_crtc_control(crtc, enable);
  4220. intel_crtc_update_sarea(crtc, enable);
  4221. }
  4222. static void intel_crtc_disable(struct drm_crtc *crtc)
  4223. {
  4224. struct drm_device *dev = crtc->dev;
  4225. struct drm_connector *connector;
  4226. struct drm_i915_private *dev_priv = dev->dev_private;
  4227. struct drm_i915_gem_object *old_obj = intel_fb_obj(crtc->primary->fb);
  4228. enum pipe pipe = to_intel_crtc(crtc)->pipe;
  4229. /* crtc should still be enabled when we disable it. */
  4230. WARN_ON(!crtc->enabled);
  4231. dev_priv->display.crtc_disable(crtc);
  4232. intel_crtc_update_sarea(crtc, false);
  4233. dev_priv->display.off(crtc);
  4234. if (crtc->primary->fb) {
  4235. mutex_lock(&dev->struct_mutex);
  4236. intel_unpin_fb_obj(old_obj);
  4237. i915_gem_track_fb(old_obj, NULL,
  4238. INTEL_FRONTBUFFER_PRIMARY(pipe));
  4239. mutex_unlock(&dev->struct_mutex);
  4240. crtc->primary->fb = NULL;
  4241. }
  4242. /* Update computed state. */
  4243. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  4244. if (!connector->encoder || !connector->encoder->crtc)
  4245. continue;
  4246. if (connector->encoder->crtc != crtc)
  4247. continue;
  4248. connector->dpms = DRM_MODE_DPMS_OFF;
  4249. to_intel_encoder(connector->encoder)->connectors_active = false;
  4250. }
  4251. }
  4252. void intel_encoder_destroy(struct drm_encoder *encoder)
  4253. {
  4254. struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
  4255. drm_encoder_cleanup(encoder);
  4256. kfree(intel_encoder);
  4257. }
  4258. /* Simple dpms helper for encoders with just one connector, no cloning and only
  4259. * one kind of off state. It clamps all !ON modes to fully OFF and changes the
  4260. * state of the entire output pipe. */
  4261. static void intel_encoder_dpms(struct intel_encoder *encoder, int mode)
  4262. {
  4263. if (mode == DRM_MODE_DPMS_ON) {
  4264. encoder->connectors_active = true;
  4265. intel_crtc_update_dpms(encoder->base.crtc);
  4266. } else {
  4267. encoder->connectors_active = false;
  4268. intel_crtc_update_dpms(encoder->base.crtc);
  4269. }
  4270. }
  4271. /* Cross check the actual hw state with our own modeset state tracking (and it's
  4272. * internal consistency). */
  4273. static void intel_connector_check_state(struct intel_connector *connector)
  4274. {
  4275. if (connector->get_hw_state(connector)) {
  4276. struct intel_encoder *encoder = connector->encoder;
  4277. struct drm_crtc *crtc;
  4278. bool encoder_enabled;
  4279. enum pipe pipe;
  4280. DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
  4281. connector->base.base.id,
  4282. connector->base.name);
  4283. /* there is no real hw state for MST connectors */
  4284. if (connector->mst_port)
  4285. return;
  4286. WARN(connector->base.dpms == DRM_MODE_DPMS_OFF,
  4287. "wrong connector dpms state\n");
  4288. WARN(connector->base.encoder != &encoder->base,
  4289. "active connector not linked to encoder\n");
  4290. if (encoder) {
  4291. WARN(!encoder->connectors_active,
  4292. "encoder->connectors_active not set\n");
  4293. encoder_enabled = encoder->get_hw_state(encoder, &pipe);
  4294. WARN(!encoder_enabled, "encoder not enabled\n");
  4295. if (WARN_ON(!encoder->base.crtc))
  4296. return;
  4297. crtc = encoder->base.crtc;
  4298. WARN(!crtc->enabled, "crtc not enabled\n");
  4299. WARN(!to_intel_crtc(crtc)->active, "crtc not active\n");
  4300. WARN(pipe != to_intel_crtc(crtc)->pipe,
  4301. "encoder active on the wrong pipe\n");
  4302. }
  4303. }
  4304. }
  4305. /* Even simpler default implementation, if there's really no special case to
  4306. * consider. */
  4307. void intel_connector_dpms(struct drm_connector *connector, int mode)
  4308. {
  4309. /* All the simple cases only support two dpms states. */
  4310. if (mode != DRM_MODE_DPMS_ON)
  4311. mode = DRM_MODE_DPMS_OFF;
  4312. if (mode == connector->dpms)
  4313. return;
  4314. connector->dpms = mode;
  4315. /* Only need to change hw state when actually enabled */
  4316. if (connector->encoder)
  4317. intel_encoder_dpms(to_intel_encoder(connector->encoder), mode);
  4318. intel_modeset_check_state(connector->dev);
  4319. }
  4320. /* Simple connector->get_hw_state implementation for encoders that support only
  4321. * one connector and no cloning and hence the encoder state determines the state
  4322. * of the connector. */
  4323. bool intel_connector_get_hw_state(struct intel_connector *connector)
  4324. {
  4325. enum pipe pipe = 0;
  4326. struct intel_encoder *encoder = connector->encoder;
  4327. return encoder->get_hw_state(encoder, &pipe);
  4328. }
  4329. static bool ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe,
  4330. struct intel_crtc_config *pipe_config)
  4331. {
  4332. struct drm_i915_private *dev_priv = dev->dev_private;
  4333. struct intel_crtc *pipe_B_crtc =
  4334. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_B]);
  4335. DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
  4336. pipe_name(pipe), pipe_config->fdi_lanes);
  4337. if (pipe_config->fdi_lanes > 4) {
  4338. DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
  4339. pipe_name(pipe), pipe_config->fdi_lanes);
  4340. return false;
  4341. }
  4342. if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
  4343. if (pipe_config->fdi_lanes > 2) {
  4344. DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
  4345. pipe_config->fdi_lanes);
  4346. return false;
  4347. } else {
  4348. return true;
  4349. }
  4350. }
  4351. if (INTEL_INFO(dev)->num_pipes == 2)
  4352. return true;
  4353. /* Ivybridge 3 pipe is really complicated */
  4354. switch (pipe) {
  4355. case PIPE_A:
  4356. return true;
  4357. case PIPE_B:
  4358. if (dev_priv->pipe_to_crtc_mapping[PIPE_C]->enabled &&
  4359. pipe_config->fdi_lanes > 2) {
  4360. DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
  4361. pipe_name(pipe), pipe_config->fdi_lanes);
  4362. return false;
  4363. }
  4364. return true;
  4365. case PIPE_C:
  4366. if (!pipe_has_enabled_pch(pipe_B_crtc) ||
  4367. pipe_B_crtc->config.fdi_lanes <= 2) {
  4368. if (pipe_config->fdi_lanes > 2) {
  4369. DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
  4370. pipe_name(pipe), pipe_config->fdi_lanes);
  4371. return false;
  4372. }
  4373. } else {
  4374. DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
  4375. return false;
  4376. }
  4377. return true;
  4378. default:
  4379. BUG();
  4380. }
  4381. }
  4382. #define RETRY 1
  4383. static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc,
  4384. struct intel_crtc_config *pipe_config)
  4385. {
  4386. struct drm_device *dev = intel_crtc->base.dev;
  4387. struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
  4388. int lane, link_bw, fdi_dotclock;
  4389. bool setup_ok, needs_recompute = false;
  4390. retry:
  4391. /* FDI is a binary signal running at ~2.7GHz, encoding
  4392. * each output octet as 10 bits. The actual frequency
  4393. * is stored as a divider into a 100MHz clock, and the
  4394. * mode pixel clock is stored in units of 1KHz.
  4395. * Hence the bw of each lane in terms of the mode signal
  4396. * is:
  4397. */
  4398. link_bw = intel_fdi_link_freq(dev) * MHz(100)/KHz(1)/10;
  4399. fdi_dotclock = adjusted_mode->crtc_clock;
  4400. lane = ironlake_get_lanes_required(fdi_dotclock, link_bw,
  4401. pipe_config->pipe_bpp);
  4402. pipe_config->fdi_lanes = lane;
  4403. intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock,
  4404. link_bw, &pipe_config->fdi_m_n);
  4405. setup_ok = ironlake_check_fdi_lanes(intel_crtc->base.dev,
  4406. intel_crtc->pipe, pipe_config);
  4407. if (!setup_ok && pipe_config->pipe_bpp > 6*3) {
  4408. pipe_config->pipe_bpp -= 2*3;
  4409. DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
  4410. pipe_config->pipe_bpp);
  4411. needs_recompute = true;
  4412. pipe_config->bw_constrained = true;
  4413. goto retry;
  4414. }
  4415. if (needs_recompute)
  4416. return RETRY;
  4417. return setup_ok ? 0 : -EINVAL;
  4418. }
  4419. static void hsw_compute_ips_config(struct intel_crtc *crtc,
  4420. struct intel_crtc_config *pipe_config)
  4421. {
  4422. pipe_config->ips_enabled = i915.enable_ips &&
  4423. hsw_crtc_supports_ips(crtc) &&
  4424. pipe_config->pipe_bpp <= 24;
  4425. }
  4426. static int intel_crtc_compute_config(struct intel_crtc *crtc,
  4427. struct intel_crtc_config *pipe_config)
  4428. {
  4429. struct drm_device *dev = crtc->base.dev;
  4430. struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
  4431. /* FIXME should check pixel clock limits on all platforms */
  4432. if (INTEL_INFO(dev)->gen < 4) {
  4433. struct drm_i915_private *dev_priv = dev->dev_private;
  4434. int clock_limit =
  4435. dev_priv->display.get_display_clock_speed(dev);
  4436. /*
  4437. * Enable pixel doubling when the dot clock
  4438. * is > 90% of the (display) core speed.
  4439. *
  4440. * GDG double wide on either pipe,
  4441. * otherwise pipe A only.
  4442. */
  4443. if ((crtc->pipe == PIPE_A || IS_I915G(dev)) &&
  4444. adjusted_mode->crtc_clock > clock_limit * 9 / 10) {
  4445. clock_limit *= 2;
  4446. pipe_config->double_wide = true;
  4447. }
  4448. if (adjusted_mode->crtc_clock > clock_limit * 9 / 10)
  4449. return -EINVAL;
  4450. }
  4451. /*
  4452. * Pipe horizontal size must be even in:
  4453. * - DVO ganged mode
  4454. * - LVDS dual channel mode
  4455. * - Double wide pipe
  4456. */
  4457. if ((intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) &&
  4458. intel_is_dual_link_lvds(dev)) || pipe_config->double_wide)
  4459. pipe_config->pipe_src_w &= ~1;
  4460. /* Cantiga+ cannot handle modes with a hsync front porch of 0.
  4461. * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
  4462. */
  4463. if ((INTEL_INFO(dev)->gen > 4 || IS_G4X(dev)) &&
  4464. adjusted_mode->hsync_start == adjusted_mode->hdisplay)
  4465. return -EINVAL;
  4466. if ((IS_G4X(dev) || IS_VALLEYVIEW(dev)) && pipe_config->pipe_bpp > 10*3) {
  4467. pipe_config->pipe_bpp = 10*3; /* 12bpc is gen5+ */
  4468. } else if (INTEL_INFO(dev)->gen <= 4 && pipe_config->pipe_bpp > 8*3) {
  4469. /* only a 8bpc pipe, with 6bpc dither through the panel fitter
  4470. * for lvds. */
  4471. pipe_config->pipe_bpp = 8*3;
  4472. }
  4473. if (HAS_IPS(dev))
  4474. hsw_compute_ips_config(crtc, pipe_config);
  4475. /*
  4476. * XXX: PCH/WRPLL clock sharing is done in ->mode_set, so make sure the
  4477. * old clock survives for now.
  4478. */
  4479. if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev) || HAS_DDI(dev))
  4480. pipe_config->shared_dpll = crtc->config.shared_dpll;
  4481. if (pipe_config->has_pch_encoder)
  4482. return ironlake_fdi_compute_config(crtc, pipe_config);
  4483. return 0;
  4484. }
  4485. static int valleyview_get_display_clock_speed(struct drm_device *dev)
  4486. {
  4487. struct drm_i915_private *dev_priv = dev->dev_private;
  4488. int vco = valleyview_get_vco(dev_priv);
  4489. u32 val;
  4490. int divider;
  4491. /* FIXME: Punit isn't quite ready yet */
  4492. if (IS_CHERRYVIEW(dev))
  4493. return 400000;
  4494. mutex_lock(&dev_priv->dpio_lock);
  4495. val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL);
  4496. mutex_unlock(&dev_priv->dpio_lock);
  4497. divider = val & DISPLAY_FREQUENCY_VALUES;
  4498. WARN((val & DISPLAY_FREQUENCY_STATUS) !=
  4499. (divider << DISPLAY_FREQUENCY_STATUS_SHIFT),
  4500. "cdclk change in progress\n");
  4501. return DIV_ROUND_CLOSEST(vco << 1, divider + 1);
  4502. }
  4503. static int i945_get_display_clock_speed(struct drm_device *dev)
  4504. {
  4505. return 400000;
  4506. }
  4507. static int i915_get_display_clock_speed(struct drm_device *dev)
  4508. {
  4509. return 333000;
  4510. }
  4511. static int i9xx_misc_get_display_clock_speed(struct drm_device *dev)
  4512. {
  4513. return 200000;
  4514. }
  4515. static int pnv_get_display_clock_speed(struct drm_device *dev)
  4516. {
  4517. u16 gcfgc = 0;
  4518. pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
  4519. switch (gcfgc & GC_DISPLAY_CLOCK_MASK) {
  4520. case GC_DISPLAY_CLOCK_267_MHZ_PNV:
  4521. return 267000;
  4522. case GC_DISPLAY_CLOCK_333_MHZ_PNV:
  4523. return 333000;
  4524. case GC_DISPLAY_CLOCK_444_MHZ_PNV:
  4525. return 444000;
  4526. case GC_DISPLAY_CLOCK_200_MHZ_PNV:
  4527. return 200000;
  4528. default:
  4529. DRM_ERROR("Unknown pnv display core clock 0x%04x\n", gcfgc);
  4530. case GC_DISPLAY_CLOCK_133_MHZ_PNV:
  4531. return 133000;
  4532. case GC_DISPLAY_CLOCK_167_MHZ_PNV:
  4533. return 167000;
  4534. }
  4535. }
  4536. static int i915gm_get_display_clock_speed(struct drm_device *dev)
  4537. {
  4538. u16 gcfgc = 0;
  4539. pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
  4540. if (gcfgc & GC_LOW_FREQUENCY_ENABLE)
  4541. return 133000;
  4542. else {
  4543. switch (gcfgc & GC_DISPLAY_CLOCK_MASK) {
  4544. case GC_DISPLAY_CLOCK_333_MHZ:
  4545. return 333000;
  4546. default:
  4547. case GC_DISPLAY_CLOCK_190_200_MHZ:
  4548. return 190000;
  4549. }
  4550. }
  4551. }
  4552. static int i865_get_display_clock_speed(struct drm_device *dev)
  4553. {
  4554. return 266000;
  4555. }
  4556. static int i855_get_display_clock_speed(struct drm_device *dev)
  4557. {
  4558. u16 hpllcc = 0;
  4559. /* Assume that the hardware is in the high speed state. This
  4560. * should be the default.
  4561. */
  4562. switch (hpllcc & GC_CLOCK_CONTROL_MASK) {
  4563. case GC_CLOCK_133_200:
  4564. case GC_CLOCK_100_200:
  4565. return 200000;
  4566. case GC_CLOCK_166_250:
  4567. return 250000;
  4568. case GC_CLOCK_100_133:
  4569. return 133000;
  4570. }
  4571. /* Shouldn't happen */
  4572. return 0;
  4573. }
  4574. static int i830_get_display_clock_speed(struct drm_device *dev)
  4575. {
  4576. return 133000;
  4577. }
  4578. static void
  4579. intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den)
  4580. {
  4581. while (*num > DATA_LINK_M_N_MASK ||
  4582. *den > DATA_LINK_M_N_MASK) {
  4583. *num >>= 1;
  4584. *den >>= 1;
  4585. }
  4586. }
  4587. static void compute_m_n(unsigned int m, unsigned int n,
  4588. uint32_t *ret_m, uint32_t *ret_n)
  4589. {
  4590. *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
  4591. *ret_m = div_u64((uint64_t) m * *ret_n, n);
  4592. intel_reduce_m_n_ratio(ret_m, ret_n);
  4593. }
  4594. void
  4595. intel_link_compute_m_n(int bits_per_pixel, int nlanes,
  4596. int pixel_clock, int link_clock,
  4597. struct intel_link_m_n *m_n)
  4598. {
  4599. m_n->tu = 64;
  4600. compute_m_n(bits_per_pixel * pixel_clock,
  4601. link_clock * nlanes * 8,
  4602. &m_n->gmch_m, &m_n->gmch_n);
  4603. compute_m_n(pixel_clock, link_clock,
  4604. &m_n->link_m, &m_n->link_n);
  4605. }
  4606. static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
  4607. {
  4608. if (i915.panel_use_ssc >= 0)
  4609. return i915.panel_use_ssc != 0;
  4610. return dev_priv->vbt.lvds_use_ssc
  4611. && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE);
  4612. }
  4613. static int i9xx_get_refclk(struct drm_crtc *crtc, int num_connectors)
  4614. {
  4615. struct drm_device *dev = crtc->dev;
  4616. struct drm_i915_private *dev_priv = dev->dev_private;
  4617. int refclk;
  4618. if (IS_VALLEYVIEW(dev)) {
  4619. refclk = 100000;
  4620. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
  4621. intel_panel_use_ssc(dev_priv) && num_connectors < 2) {
  4622. refclk = dev_priv->vbt.lvds_ssc_freq;
  4623. DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
  4624. } else if (!IS_GEN2(dev)) {
  4625. refclk = 96000;
  4626. } else {
  4627. refclk = 48000;
  4628. }
  4629. return refclk;
  4630. }
  4631. static uint32_t pnv_dpll_compute_fp(struct dpll *dpll)
  4632. {
  4633. return (1 << dpll->n) << 16 | dpll->m2;
  4634. }
  4635. static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll)
  4636. {
  4637. return dpll->n << 16 | dpll->m1 << 8 | dpll->m2;
  4638. }
  4639. static void i9xx_update_pll_dividers(struct intel_crtc *crtc,
  4640. intel_clock_t *reduced_clock)
  4641. {
  4642. struct drm_device *dev = crtc->base.dev;
  4643. u32 fp, fp2 = 0;
  4644. if (IS_PINEVIEW(dev)) {
  4645. fp = pnv_dpll_compute_fp(&crtc->config.dpll);
  4646. if (reduced_clock)
  4647. fp2 = pnv_dpll_compute_fp(reduced_clock);
  4648. } else {
  4649. fp = i9xx_dpll_compute_fp(&crtc->config.dpll);
  4650. if (reduced_clock)
  4651. fp2 = i9xx_dpll_compute_fp(reduced_clock);
  4652. }
  4653. crtc->config.dpll_hw_state.fp0 = fp;
  4654. crtc->lowfreq_avail = false;
  4655. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) &&
  4656. reduced_clock && i915.powersave) {
  4657. crtc->config.dpll_hw_state.fp1 = fp2;
  4658. crtc->lowfreq_avail = true;
  4659. } else {
  4660. crtc->config.dpll_hw_state.fp1 = fp;
  4661. }
  4662. }
  4663. static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe
  4664. pipe)
  4665. {
  4666. u32 reg_val;
  4667. /*
  4668. * PLLB opamp always calibrates to max value of 0x3f, force enable it
  4669. * and set it to a reasonable value instead.
  4670. */
  4671. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
  4672. reg_val &= 0xffffff00;
  4673. reg_val |= 0x00000030;
  4674. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
  4675. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
  4676. reg_val &= 0x8cffffff;
  4677. reg_val = 0x8c000000;
  4678. vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
  4679. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
  4680. reg_val &= 0xffffff00;
  4681. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
  4682. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
  4683. reg_val &= 0x00ffffff;
  4684. reg_val |= 0xb0000000;
  4685. vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
  4686. }
  4687. static void intel_pch_transcoder_set_m_n(struct intel_crtc *crtc,
  4688. struct intel_link_m_n *m_n)
  4689. {
  4690. struct drm_device *dev = crtc->base.dev;
  4691. struct drm_i915_private *dev_priv = dev->dev_private;
  4692. int pipe = crtc->pipe;
  4693. I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
  4694. I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n);
  4695. I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m);
  4696. I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n);
  4697. }
  4698. static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc,
  4699. struct intel_link_m_n *m_n,
  4700. struct intel_link_m_n *m2_n2)
  4701. {
  4702. struct drm_device *dev = crtc->base.dev;
  4703. struct drm_i915_private *dev_priv = dev->dev_private;
  4704. int pipe = crtc->pipe;
  4705. enum transcoder transcoder = crtc->config.cpu_transcoder;
  4706. if (INTEL_INFO(dev)->gen >= 5) {
  4707. I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m);
  4708. I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n);
  4709. I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m);
  4710. I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n);
  4711. /* M2_N2 registers to be set only for gen < 8 (M2_N2 available
  4712. * for gen < 8) and if DRRS is supported (to make sure the
  4713. * registers are not unnecessarily accessed).
  4714. */
  4715. if (m2_n2 && INTEL_INFO(dev)->gen < 8 &&
  4716. crtc->config.has_drrs) {
  4717. I915_WRITE(PIPE_DATA_M2(transcoder),
  4718. TU_SIZE(m2_n2->tu) | m2_n2->gmch_m);
  4719. I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n);
  4720. I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m);
  4721. I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n);
  4722. }
  4723. } else {
  4724. I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
  4725. I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n);
  4726. I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m);
  4727. I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n);
  4728. }
  4729. }
  4730. void intel_dp_set_m_n(struct intel_crtc *crtc)
  4731. {
  4732. if (crtc->config.has_pch_encoder)
  4733. intel_pch_transcoder_set_m_n(crtc, &crtc->config.dp_m_n);
  4734. else
  4735. intel_cpu_transcoder_set_m_n(crtc, &crtc->config.dp_m_n,
  4736. &crtc->config.dp_m2_n2);
  4737. }
  4738. static void vlv_update_pll(struct intel_crtc *crtc)
  4739. {
  4740. u32 dpll, dpll_md;
  4741. /*
  4742. * Enable DPIO clock input. We should never disable the reference
  4743. * clock for pipe B, since VGA hotplug / manual detection depends
  4744. * on it.
  4745. */
  4746. dpll = DPLL_EXT_BUFFER_ENABLE_VLV | DPLL_REFA_CLK_ENABLE_VLV |
  4747. DPLL_VGA_MODE_DIS | DPLL_INTEGRATED_CLOCK_VLV;
  4748. /* We should never disable this, set it here for state tracking */
  4749. if (crtc->pipe == PIPE_B)
  4750. dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
  4751. dpll |= DPLL_VCO_ENABLE;
  4752. crtc->config.dpll_hw_state.dpll = dpll;
  4753. dpll_md = (crtc->config.pixel_multiplier - 1)
  4754. << DPLL_MD_UDI_MULTIPLIER_SHIFT;
  4755. crtc->config.dpll_hw_state.dpll_md = dpll_md;
  4756. }
  4757. static void vlv_prepare_pll(struct intel_crtc *crtc)
  4758. {
  4759. struct drm_device *dev = crtc->base.dev;
  4760. struct drm_i915_private *dev_priv = dev->dev_private;
  4761. int pipe = crtc->pipe;
  4762. u32 mdiv;
  4763. u32 bestn, bestm1, bestm2, bestp1, bestp2;
  4764. u32 coreclk, reg_val;
  4765. mutex_lock(&dev_priv->dpio_lock);
  4766. bestn = crtc->config.dpll.n;
  4767. bestm1 = crtc->config.dpll.m1;
  4768. bestm2 = crtc->config.dpll.m2;
  4769. bestp1 = crtc->config.dpll.p1;
  4770. bestp2 = crtc->config.dpll.p2;
  4771. /* See eDP HDMI DPIO driver vbios notes doc */
  4772. /* PLL B needs special handling */
  4773. if (pipe == PIPE_B)
  4774. vlv_pllb_recal_opamp(dev_priv, pipe);
  4775. /* Set up Tx target for periodic Rcomp update */
  4776. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f);
  4777. /* Disable target IRef on PLL */
  4778. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe));
  4779. reg_val &= 0x00ffffff;
  4780. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val);
  4781. /* Disable fast lock */
  4782. vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610);
  4783. /* Set idtafcrecal before PLL is enabled */
  4784. mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK));
  4785. mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT));
  4786. mdiv |= ((bestn << DPIO_N_SHIFT));
  4787. mdiv |= (1 << DPIO_K_SHIFT);
  4788. /*
  4789. * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
  4790. * but we don't support that).
  4791. * Note: don't use the DAC post divider as it seems unstable.
  4792. */
  4793. mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT);
  4794. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
  4795. mdiv |= DPIO_ENABLE_CALIBRATION;
  4796. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
  4797. /* Set HBR and RBR LPF coefficients */
  4798. if (crtc->config.port_clock == 162000 ||
  4799. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_ANALOG) ||
  4800. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_HDMI))
  4801. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
  4802. 0x009f0003);
  4803. else
  4804. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
  4805. 0x00d0000f);
  4806. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_EDP) ||
  4807. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DISPLAYPORT)) {
  4808. /* Use SSC source */
  4809. if (pipe == PIPE_A)
  4810. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
  4811. 0x0df40000);
  4812. else
  4813. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
  4814. 0x0df70000);
  4815. } else { /* HDMI or VGA */
  4816. /* Use bend source */
  4817. if (pipe == PIPE_A)
  4818. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
  4819. 0x0df70000);
  4820. else
  4821. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
  4822. 0x0df40000);
  4823. }
  4824. coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe));
  4825. coreclk = (coreclk & 0x0000ff00) | 0x01c00000;
  4826. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DISPLAYPORT) ||
  4827. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_EDP))
  4828. coreclk |= 0x01000000;
  4829. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk);
  4830. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000);
  4831. mutex_unlock(&dev_priv->dpio_lock);
  4832. }
  4833. static void chv_update_pll(struct intel_crtc *crtc)
  4834. {
  4835. crtc->config.dpll_hw_state.dpll = DPLL_SSC_REF_CLOCK_CHV |
  4836. DPLL_REFA_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS |
  4837. DPLL_VCO_ENABLE;
  4838. if (crtc->pipe != PIPE_A)
  4839. crtc->config.dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
  4840. crtc->config.dpll_hw_state.dpll_md =
  4841. (crtc->config.pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
  4842. }
  4843. static void chv_prepare_pll(struct intel_crtc *crtc)
  4844. {
  4845. struct drm_device *dev = crtc->base.dev;
  4846. struct drm_i915_private *dev_priv = dev->dev_private;
  4847. int pipe = crtc->pipe;
  4848. int dpll_reg = DPLL(crtc->pipe);
  4849. enum dpio_channel port = vlv_pipe_to_channel(pipe);
  4850. u32 loopfilter, intcoeff;
  4851. u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac;
  4852. int refclk;
  4853. bestn = crtc->config.dpll.n;
  4854. bestm2_frac = crtc->config.dpll.m2 & 0x3fffff;
  4855. bestm1 = crtc->config.dpll.m1;
  4856. bestm2 = crtc->config.dpll.m2 >> 22;
  4857. bestp1 = crtc->config.dpll.p1;
  4858. bestp2 = crtc->config.dpll.p2;
  4859. /*
  4860. * Enable Refclk and SSC
  4861. */
  4862. I915_WRITE(dpll_reg,
  4863. crtc->config.dpll_hw_state.dpll & ~DPLL_VCO_ENABLE);
  4864. mutex_lock(&dev_priv->dpio_lock);
  4865. /* p1 and p2 divider */
  4866. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port),
  4867. 5 << DPIO_CHV_S1_DIV_SHIFT |
  4868. bestp1 << DPIO_CHV_P1_DIV_SHIFT |
  4869. bestp2 << DPIO_CHV_P2_DIV_SHIFT |
  4870. 1 << DPIO_CHV_K_DIV_SHIFT);
  4871. /* Feedback post-divider - m2 */
  4872. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2);
  4873. /* Feedback refclk divider - n and m1 */
  4874. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port),
  4875. DPIO_CHV_M1_DIV_BY_2 |
  4876. 1 << DPIO_CHV_N_DIV_SHIFT);
  4877. /* M2 fraction division */
  4878. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac);
  4879. /* M2 fraction division enable */
  4880. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port),
  4881. DPIO_CHV_FRAC_DIV_EN |
  4882. (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT));
  4883. /* Loop filter */
  4884. refclk = i9xx_get_refclk(&crtc->base, 0);
  4885. loopfilter = 5 << DPIO_CHV_PROP_COEFF_SHIFT |
  4886. 2 << DPIO_CHV_GAIN_CTRL_SHIFT;
  4887. if (refclk == 100000)
  4888. intcoeff = 11;
  4889. else if (refclk == 38400)
  4890. intcoeff = 10;
  4891. else
  4892. intcoeff = 9;
  4893. loopfilter |= intcoeff << DPIO_CHV_INT_COEFF_SHIFT;
  4894. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter);
  4895. /* AFC Recal */
  4896. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port),
  4897. vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) |
  4898. DPIO_AFC_RECAL);
  4899. mutex_unlock(&dev_priv->dpio_lock);
  4900. }
  4901. static void i9xx_update_pll(struct intel_crtc *crtc,
  4902. intel_clock_t *reduced_clock,
  4903. int num_connectors)
  4904. {
  4905. struct drm_device *dev = crtc->base.dev;
  4906. struct drm_i915_private *dev_priv = dev->dev_private;
  4907. u32 dpll;
  4908. bool is_sdvo;
  4909. struct dpll *clock = &crtc->config.dpll;
  4910. i9xx_update_pll_dividers(crtc, reduced_clock);
  4911. is_sdvo = intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_SDVO) ||
  4912. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_HDMI);
  4913. dpll = DPLL_VGA_MODE_DIS;
  4914. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS))
  4915. dpll |= DPLLB_MODE_LVDS;
  4916. else
  4917. dpll |= DPLLB_MODE_DAC_SERIAL;
  4918. if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) {
  4919. dpll |= (crtc->config.pixel_multiplier - 1)
  4920. << SDVO_MULTIPLIER_SHIFT_HIRES;
  4921. }
  4922. if (is_sdvo)
  4923. dpll |= DPLL_SDVO_HIGH_SPEED;
  4924. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DISPLAYPORT))
  4925. dpll |= DPLL_SDVO_HIGH_SPEED;
  4926. /* compute bitmask from p1 value */
  4927. if (IS_PINEVIEW(dev))
  4928. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
  4929. else {
  4930. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  4931. if (IS_G4X(dev) && reduced_clock)
  4932. dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
  4933. }
  4934. switch (clock->p2) {
  4935. case 5:
  4936. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
  4937. break;
  4938. case 7:
  4939. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
  4940. break;
  4941. case 10:
  4942. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
  4943. break;
  4944. case 14:
  4945. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
  4946. break;
  4947. }
  4948. if (INTEL_INFO(dev)->gen >= 4)
  4949. dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
  4950. if (crtc->config.sdvo_tv_clock)
  4951. dpll |= PLL_REF_INPUT_TVCLKINBC;
  4952. else if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) &&
  4953. intel_panel_use_ssc(dev_priv) && num_connectors < 2)
  4954. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  4955. else
  4956. dpll |= PLL_REF_INPUT_DREFCLK;
  4957. dpll |= DPLL_VCO_ENABLE;
  4958. crtc->config.dpll_hw_state.dpll = dpll;
  4959. if (INTEL_INFO(dev)->gen >= 4) {
  4960. u32 dpll_md = (crtc->config.pixel_multiplier - 1)
  4961. << DPLL_MD_UDI_MULTIPLIER_SHIFT;
  4962. crtc->config.dpll_hw_state.dpll_md = dpll_md;
  4963. }
  4964. }
  4965. static void i8xx_update_pll(struct intel_crtc *crtc,
  4966. intel_clock_t *reduced_clock,
  4967. int num_connectors)
  4968. {
  4969. struct drm_device *dev = crtc->base.dev;
  4970. struct drm_i915_private *dev_priv = dev->dev_private;
  4971. u32 dpll;
  4972. struct dpll *clock = &crtc->config.dpll;
  4973. i9xx_update_pll_dividers(crtc, reduced_clock);
  4974. dpll = DPLL_VGA_MODE_DIS;
  4975. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS)) {
  4976. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  4977. } else {
  4978. if (clock->p1 == 2)
  4979. dpll |= PLL_P1_DIVIDE_BY_TWO;
  4980. else
  4981. dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  4982. if (clock->p2 == 4)
  4983. dpll |= PLL_P2_DIVIDE_BY_4;
  4984. }
  4985. if (!IS_I830(dev) && intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DVO))
  4986. dpll |= DPLL_DVO_2X_MODE;
  4987. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) &&
  4988. intel_panel_use_ssc(dev_priv) && num_connectors < 2)
  4989. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  4990. else
  4991. dpll |= PLL_REF_INPUT_DREFCLK;
  4992. dpll |= DPLL_VCO_ENABLE;
  4993. crtc->config.dpll_hw_state.dpll = dpll;
  4994. }
  4995. static void intel_set_pipe_timings(struct intel_crtc *intel_crtc)
  4996. {
  4997. struct drm_device *dev = intel_crtc->base.dev;
  4998. struct drm_i915_private *dev_priv = dev->dev_private;
  4999. enum pipe pipe = intel_crtc->pipe;
  5000. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  5001. struct drm_display_mode *adjusted_mode =
  5002. &intel_crtc->config.adjusted_mode;
  5003. uint32_t crtc_vtotal, crtc_vblank_end;
  5004. int vsyncshift = 0;
  5005. /* We need to be careful not to changed the adjusted mode, for otherwise
  5006. * the hw state checker will get angry at the mismatch. */
  5007. crtc_vtotal = adjusted_mode->crtc_vtotal;
  5008. crtc_vblank_end = adjusted_mode->crtc_vblank_end;
  5009. if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
  5010. /* the chip adds 2 halflines automatically */
  5011. crtc_vtotal -= 1;
  5012. crtc_vblank_end -= 1;
  5013. if (intel_pipe_has_type(&intel_crtc->base, INTEL_OUTPUT_SDVO))
  5014. vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2;
  5015. else
  5016. vsyncshift = adjusted_mode->crtc_hsync_start -
  5017. adjusted_mode->crtc_htotal / 2;
  5018. if (vsyncshift < 0)
  5019. vsyncshift += adjusted_mode->crtc_htotal;
  5020. }
  5021. if (INTEL_INFO(dev)->gen > 3)
  5022. I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift);
  5023. I915_WRITE(HTOTAL(cpu_transcoder),
  5024. (adjusted_mode->crtc_hdisplay - 1) |
  5025. ((adjusted_mode->crtc_htotal - 1) << 16));
  5026. I915_WRITE(HBLANK(cpu_transcoder),
  5027. (adjusted_mode->crtc_hblank_start - 1) |
  5028. ((adjusted_mode->crtc_hblank_end - 1) << 16));
  5029. I915_WRITE(HSYNC(cpu_transcoder),
  5030. (adjusted_mode->crtc_hsync_start - 1) |
  5031. ((adjusted_mode->crtc_hsync_end - 1) << 16));
  5032. I915_WRITE(VTOTAL(cpu_transcoder),
  5033. (adjusted_mode->crtc_vdisplay - 1) |
  5034. ((crtc_vtotal - 1) << 16));
  5035. I915_WRITE(VBLANK(cpu_transcoder),
  5036. (adjusted_mode->crtc_vblank_start - 1) |
  5037. ((crtc_vblank_end - 1) << 16));
  5038. I915_WRITE(VSYNC(cpu_transcoder),
  5039. (adjusted_mode->crtc_vsync_start - 1) |
  5040. ((adjusted_mode->crtc_vsync_end - 1) << 16));
  5041. /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
  5042. * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
  5043. * documented on the DDI_FUNC_CTL register description, EDP Input Select
  5044. * bits. */
  5045. if (IS_HASWELL(dev) && cpu_transcoder == TRANSCODER_EDP &&
  5046. (pipe == PIPE_B || pipe == PIPE_C))
  5047. I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder)));
  5048. /* pipesrc controls the size that is scaled from, which should
  5049. * always be the user's requested size.
  5050. */
  5051. I915_WRITE(PIPESRC(pipe),
  5052. ((intel_crtc->config.pipe_src_w - 1) << 16) |
  5053. (intel_crtc->config.pipe_src_h - 1));
  5054. }
  5055. static void intel_get_pipe_timings(struct intel_crtc *crtc,
  5056. struct intel_crtc_config *pipe_config)
  5057. {
  5058. struct drm_device *dev = crtc->base.dev;
  5059. struct drm_i915_private *dev_priv = dev->dev_private;
  5060. enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
  5061. uint32_t tmp;
  5062. tmp = I915_READ(HTOTAL(cpu_transcoder));
  5063. pipe_config->adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1;
  5064. pipe_config->adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1;
  5065. tmp = I915_READ(HBLANK(cpu_transcoder));
  5066. pipe_config->adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1;
  5067. pipe_config->adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1;
  5068. tmp = I915_READ(HSYNC(cpu_transcoder));
  5069. pipe_config->adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1;
  5070. pipe_config->adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1;
  5071. tmp = I915_READ(VTOTAL(cpu_transcoder));
  5072. pipe_config->adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1;
  5073. pipe_config->adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1;
  5074. tmp = I915_READ(VBLANK(cpu_transcoder));
  5075. pipe_config->adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1;
  5076. pipe_config->adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1;
  5077. tmp = I915_READ(VSYNC(cpu_transcoder));
  5078. pipe_config->adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1;
  5079. pipe_config->adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1;
  5080. if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) {
  5081. pipe_config->adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE;
  5082. pipe_config->adjusted_mode.crtc_vtotal += 1;
  5083. pipe_config->adjusted_mode.crtc_vblank_end += 1;
  5084. }
  5085. tmp = I915_READ(PIPESRC(crtc->pipe));
  5086. pipe_config->pipe_src_h = (tmp & 0xffff) + 1;
  5087. pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1;
  5088. pipe_config->requested_mode.vdisplay = pipe_config->pipe_src_h;
  5089. pipe_config->requested_mode.hdisplay = pipe_config->pipe_src_w;
  5090. }
  5091. void intel_mode_from_pipe_config(struct drm_display_mode *mode,
  5092. struct intel_crtc_config *pipe_config)
  5093. {
  5094. mode->hdisplay = pipe_config->adjusted_mode.crtc_hdisplay;
  5095. mode->htotal = pipe_config->adjusted_mode.crtc_htotal;
  5096. mode->hsync_start = pipe_config->adjusted_mode.crtc_hsync_start;
  5097. mode->hsync_end = pipe_config->adjusted_mode.crtc_hsync_end;
  5098. mode->vdisplay = pipe_config->adjusted_mode.crtc_vdisplay;
  5099. mode->vtotal = pipe_config->adjusted_mode.crtc_vtotal;
  5100. mode->vsync_start = pipe_config->adjusted_mode.crtc_vsync_start;
  5101. mode->vsync_end = pipe_config->adjusted_mode.crtc_vsync_end;
  5102. mode->flags = pipe_config->adjusted_mode.flags;
  5103. mode->clock = pipe_config->adjusted_mode.crtc_clock;
  5104. mode->flags |= pipe_config->adjusted_mode.flags;
  5105. }
  5106. static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc)
  5107. {
  5108. struct drm_device *dev = intel_crtc->base.dev;
  5109. struct drm_i915_private *dev_priv = dev->dev_private;
  5110. uint32_t pipeconf;
  5111. pipeconf = 0;
  5112. if ((intel_crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) ||
  5113. (intel_crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))
  5114. pipeconf |= I915_READ(PIPECONF(intel_crtc->pipe)) & PIPECONF_ENABLE;
  5115. if (intel_crtc->config.double_wide)
  5116. pipeconf |= PIPECONF_DOUBLE_WIDE;
  5117. /* only g4x and later have fancy bpc/dither controls */
  5118. if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) {
  5119. /* Bspec claims that we can't use dithering for 30bpp pipes. */
  5120. if (intel_crtc->config.dither && intel_crtc->config.pipe_bpp != 30)
  5121. pipeconf |= PIPECONF_DITHER_EN |
  5122. PIPECONF_DITHER_TYPE_SP;
  5123. switch (intel_crtc->config.pipe_bpp) {
  5124. case 18:
  5125. pipeconf |= PIPECONF_6BPC;
  5126. break;
  5127. case 24:
  5128. pipeconf |= PIPECONF_8BPC;
  5129. break;
  5130. case 30:
  5131. pipeconf |= PIPECONF_10BPC;
  5132. break;
  5133. default:
  5134. /* Case prevented by intel_choose_pipe_bpp_dither. */
  5135. BUG();
  5136. }
  5137. }
  5138. if (HAS_PIPE_CXSR(dev)) {
  5139. if (intel_crtc->lowfreq_avail) {
  5140. DRM_DEBUG_KMS("enabling CxSR downclocking\n");
  5141. pipeconf |= PIPECONF_CXSR_DOWNCLOCK;
  5142. } else {
  5143. DRM_DEBUG_KMS("disabling CxSR downclocking\n");
  5144. }
  5145. }
  5146. if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
  5147. if (INTEL_INFO(dev)->gen < 4 ||
  5148. intel_pipe_has_type(&intel_crtc->base, INTEL_OUTPUT_SDVO))
  5149. pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
  5150. else
  5151. pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT;
  5152. } else
  5153. pipeconf |= PIPECONF_PROGRESSIVE;
  5154. if (IS_VALLEYVIEW(dev) && intel_crtc->config.limited_color_range)
  5155. pipeconf |= PIPECONF_COLOR_RANGE_SELECT;
  5156. I915_WRITE(PIPECONF(intel_crtc->pipe), pipeconf);
  5157. POSTING_READ(PIPECONF(intel_crtc->pipe));
  5158. }
  5159. static int i9xx_crtc_mode_set(struct drm_crtc *crtc,
  5160. int x, int y,
  5161. struct drm_framebuffer *fb)
  5162. {
  5163. struct drm_device *dev = crtc->dev;
  5164. struct drm_i915_private *dev_priv = dev->dev_private;
  5165. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5166. int refclk, num_connectors = 0;
  5167. intel_clock_t clock, reduced_clock;
  5168. bool ok, has_reduced_clock = false;
  5169. bool is_lvds = false, is_dsi = false;
  5170. struct intel_encoder *encoder;
  5171. const intel_limit_t *limit;
  5172. for_each_encoder_on_crtc(dev, crtc, encoder) {
  5173. switch (encoder->type) {
  5174. case INTEL_OUTPUT_LVDS:
  5175. is_lvds = true;
  5176. break;
  5177. case INTEL_OUTPUT_DSI:
  5178. is_dsi = true;
  5179. break;
  5180. }
  5181. num_connectors++;
  5182. }
  5183. if (is_dsi)
  5184. return 0;
  5185. if (!intel_crtc->config.clock_set) {
  5186. refclk = i9xx_get_refclk(crtc, num_connectors);
  5187. /*
  5188. * Returns a set of divisors for the desired target clock with
  5189. * the given refclk, or FALSE. The returned values represent
  5190. * the clock equation: reflck * (5 * (m1 + 2) + (m2 + 2)) / (n +
  5191. * 2) / p1 / p2.
  5192. */
  5193. limit = intel_limit(crtc, refclk);
  5194. ok = dev_priv->display.find_dpll(limit, crtc,
  5195. intel_crtc->config.port_clock,
  5196. refclk, NULL, &clock);
  5197. if (!ok) {
  5198. DRM_ERROR("Couldn't find PLL settings for mode!\n");
  5199. return -EINVAL;
  5200. }
  5201. if (is_lvds && dev_priv->lvds_downclock_avail) {
  5202. /*
  5203. * Ensure we match the reduced clock's P to the target
  5204. * clock. If the clocks don't match, we can't switch
  5205. * the display clock by using the FP0/FP1. In such case
  5206. * we will disable the LVDS downclock feature.
  5207. */
  5208. has_reduced_clock =
  5209. dev_priv->display.find_dpll(limit, crtc,
  5210. dev_priv->lvds_downclock,
  5211. refclk, &clock,
  5212. &reduced_clock);
  5213. }
  5214. /* Compat-code for transition, will disappear. */
  5215. intel_crtc->config.dpll.n = clock.n;
  5216. intel_crtc->config.dpll.m1 = clock.m1;
  5217. intel_crtc->config.dpll.m2 = clock.m2;
  5218. intel_crtc->config.dpll.p1 = clock.p1;
  5219. intel_crtc->config.dpll.p2 = clock.p2;
  5220. }
  5221. if (IS_GEN2(dev)) {
  5222. i8xx_update_pll(intel_crtc,
  5223. has_reduced_clock ? &reduced_clock : NULL,
  5224. num_connectors);
  5225. } else if (IS_CHERRYVIEW(dev)) {
  5226. chv_update_pll(intel_crtc);
  5227. } else if (IS_VALLEYVIEW(dev)) {
  5228. vlv_update_pll(intel_crtc);
  5229. } else {
  5230. i9xx_update_pll(intel_crtc,
  5231. has_reduced_clock ? &reduced_clock : NULL,
  5232. num_connectors);
  5233. }
  5234. return 0;
  5235. }
  5236. static void i9xx_get_pfit_config(struct intel_crtc *crtc,
  5237. struct intel_crtc_config *pipe_config)
  5238. {
  5239. struct drm_device *dev = crtc->base.dev;
  5240. struct drm_i915_private *dev_priv = dev->dev_private;
  5241. uint32_t tmp;
  5242. if (INTEL_INFO(dev)->gen <= 3 && (IS_I830(dev) || !IS_MOBILE(dev)))
  5243. return;
  5244. tmp = I915_READ(PFIT_CONTROL);
  5245. if (!(tmp & PFIT_ENABLE))
  5246. return;
  5247. /* Check whether the pfit is attached to our pipe. */
  5248. if (INTEL_INFO(dev)->gen < 4) {
  5249. if (crtc->pipe != PIPE_B)
  5250. return;
  5251. } else {
  5252. if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT))
  5253. return;
  5254. }
  5255. pipe_config->gmch_pfit.control = tmp;
  5256. pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS);
  5257. if (INTEL_INFO(dev)->gen < 5)
  5258. pipe_config->gmch_pfit.lvds_border_bits =
  5259. I915_READ(LVDS) & LVDS_BORDER_ENABLE;
  5260. }
  5261. static void vlv_crtc_clock_get(struct intel_crtc *crtc,
  5262. struct intel_crtc_config *pipe_config)
  5263. {
  5264. struct drm_device *dev = crtc->base.dev;
  5265. struct drm_i915_private *dev_priv = dev->dev_private;
  5266. int pipe = pipe_config->cpu_transcoder;
  5267. intel_clock_t clock;
  5268. u32 mdiv;
  5269. int refclk = 100000;
  5270. /* In case of MIPI DPLL will not even be used */
  5271. if (!(pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE))
  5272. return;
  5273. mutex_lock(&dev_priv->dpio_lock);
  5274. mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe));
  5275. mutex_unlock(&dev_priv->dpio_lock);
  5276. clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7;
  5277. clock.m2 = mdiv & DPIO_M2DIV_MASK;
  5278. clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf;
  5279. clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7;
  5280. clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f;
  5281. vlv_clock(refclk, &clock);
  5282. /* clock.dot is the fast clock */
  5283. pipe_config->port_clock = clock.dot / 5;
  5284. }
  5285. static void i9xx_get_plane_config(struct intel_crtc *crtc,
  5286. struct intel_plane_config *plane_config)
  5287. {
  5288. struct drm_device *dev = crtc->base.dev;
  5289. struct drm_i915_private *dev_priv = dev->dev_private;
  5290. u32 val, base, offset;
  5291. int pipe = crtc->pipe, plane = crtc->plane;
  5292. int fourcc, pixel_format;
  5293. int aligned_height;
  5294. crtc->base.primary->fb = kzalloc(sizeof(struct intel_framebuffer), GFP_KERNEL);
  5295. if (!crtc->base.primary->fb) {
  5296. DRM_DEBUG_KMS("failed to alloc fb\n");
  5297. return;
  5298. }
  5299. val = I915_READ(DSPCNTR(plane));
  5300. if (INTEL_INFO(dev)->gen >= 4)
  5301. if (val & DISPPLANE_TILED)
  5302. plane_config->tiled = true;
  5303. pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
  5304. fourcc = intel_format_to_fourcc(pixel_format);
  5305. crtc->base.primary->fb->pixel_format = fourcc;
  5306. crtc->base.primary->fb->bits_per_pixel =
  5307. drm_format_plane_cpp(fourcc, 0) * 8;
  5308. if (INTEL_INFO(dev)->gen >= 4) {
  5309. if (plane_config->tiled)
  5310. offset = I915_READ(DSPTILEOFF(plane));
  5311. else
  5312. offset = I915_READ(DSPLINOFF(plane));
  5313. base = I915_READ(DSPSURF(plane)) & 0xfffff000;
  5314. } else {
  5315. base = I915_READ(DSPADDR(plane));
  5316. }
  5317. plane_config->base = base;
  5318. val = I915_READ(PIPESRC(pipe));
  5319. crtc->base.primary->fb->width = ((val >> 16) & 0xfff) + 1;
  5320. crtc->base.primary->fb->height = ((val >> 0) & 0xfff) + 1;
  5321. val = I915_READ(DSPSTRIDE(pipe));
  5322. crtc->base.primary->fb->pitches[0] = val & 0xffffffc0;
  5323. aligned_height = intel_align_height(dev, crtc->base.primary->fb->height,
  5324. plane_config->tiled);
  5325. plane_config->size = PAGE_ALIGN(crtc->base.primary->fb->pitches[0] *
  5326. aligned_height);
  5327. DRM_DEBUG_KMS("pipe/plane %d/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
  5328. pipe, plane, crtc->base.primary->fb->width,
  5329. crtc->base.primary->fb->height,
  5330. crtc->base.primary->fb->bits_per_pixel, base,
  5331. crtc->base.primary->fb->pitches[0],
  5332. plane_config->size);
  5333. }
  5334. static void chv_crtc_clock_get(struct intel_crtc *crtc,
  5335. struct intel_crtc_config *pipe_config)
  5336. {
  5337. struct drm_device *dev = crtc->base.dev;
  5338. struct drm_i915_private *dev_priv = dev->dev_private;
  5339. int pipe = pipe_config->cpu_transcoder;
  5340. enum dpio_channel port = vlv_pipe_to_channel(pipe);
  5341. intel_clock_t clock;
  5342. u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2;
  5343. int refclk = 100000;
  5344. mutex_lock(&dev_priv->dpio_lock);
  5345. cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port));
  5346. pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port));
  5347. pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port));
  5348. pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port));
  5349. mutex_unlock(&dev_priv->dpio_lock);
  5350. clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0;
  5351. clock.m2 = ((pll_dw0 & 0xff) << 22) | (pll_dw2 & 0x3fffff);
  5352. clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf;
  5353. clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7;
  5354. clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f;
  5355. chv_clock(refclk, &clock);
  5356. /* clock.dot is the fast clock */
  5357. pipe_config->port_clock = clock.dot / 5;
  5358. }
  5359. static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
  5360. struct intel_crtc_config *pipe_config)
  5361. {
  5362. struct drm_device *dev = crtc->base.dev;
  5363. struct drm_i915_private *dev_priv = dev->dev_private;
  5364. uint32_t tmp;
  5365. if (!intel_display_power_enabled(dev_priv,
  5366. POWER_DOMAIN_PIPE(crtc->pipe)))
  5367. return false;
  5368. pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
  5369. pipe_config->shared_dpll = DPLL_ID_PRIVATE;
  5370. tmp = I915_READ(PIPECONF(crtc->pipe));
  5371. if (!(tmp & PIPECONF_ENABLE))
  5372. return false;
  5373. if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) {
  5374. switch (tmp & PIPECONF_BPC_MASK) {
  5375. case PIPECONF_6BPC:
  5376. pipe_config->pipe_bpp = 18;
  5377. break;
  5378. case PIPECONF_8BPC:
  5379. pipe_config->pipe_bpp = 24;
  5380. break;
  5381. case PIPECONF_10BPC:
  5382. pipe_config->pipe_bpp = 30;
  5383. break;
  5384. default:
  5385. break;
  5386. }
  5387. }
  5388. if (IS_VALLEYVIEW(dev) && (tmp & PIPECONF_COLOR_RANGE_SELECT))
  5389. pipe_config->limited_color_range = true;
  5390. if (INTEL_INFO(dev)->gen < 4)
  5391. pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE;
  5392. intel_get_pipe_timings(crtc, pipe_config);
  5393. i9xx_get_pfit_config(crtc, pipe_config);
  5394. if (INTEL_INFO(dev)->gen >= 4) {
  5395. tmp = I915_READ(DPLL_MD(crtc->pipe));
  5396. pipe_config->pixel_multiplier =
  5397. ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK)
  5398. >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1;
  5399. pipe_config->dpll_hw_state.dpll_md = tmp;
  5400. } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) {
  5401. tmp = I915_READ(DPLL(crtc->pipe));
  5402. pipe_config->pixel_multiplier =
  5403. ((tmp & SDVO_MULTIPLIER_MASK)
  5404. >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1;
  5405. } else {
  5406. /* Note that on i915G/GM the pixel multiplier is in the sdvo
  5407. * port and will be fixed up in the encoder->get_config
  5408. * function. */
  5409. pipe_config->pixel_multiplier = 1;
  5410. }
  5411. pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe));
  5412. if (!IS_VALLEYVIEW(dev)) {
  5413. /*
  5414. * DPLL_DVO_2X_MODE must be enabled for both DPLLs
  5415. * on 830. Filter it out here so that we don't
  5416. * report errors due to that.
  5417. */
  5418. if (IS_I830(dev))
  5419. pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE;
  5420. pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe));
  5421. pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe));
  5422. } else {
  5423. /* Mask out read-only status bits. */
  5424. pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV |
  5425. DPLL_PORTC_READY_MASK |
  5426. DPLL_PORTB_READY_MASK);
  5427. }
  5428. if (IS_CHERRYVIEW(dev))
  5429. chv_crtc_clock_get(crtc, pipe_config);
  5430. else if (IS_VALLEYVIEW(dev))
  5431. vlv_crtc_clock_get(crtc, pipe_config);
  5432. else
  5433. i9xx_crtc_clock_get(crtc, pipe_config);
  5434. return true;
  5435. }
  5436. static void ironlake_init_pch_refclk(struct drm_device *dev)
  5437. {
  5438. struct drm_i915_private *dev_priv = dev->dev_private;
  5439. struct intel_encoder *encoder;
  5440. u32 val, final;
  5441. bool has_lvds = false;
  5442. bool has_cpu_edp = false;
  5443. bool has_panel = false;
  5444. bool has_ck505 = false;
  5445. bool can_ssc = false;
  5446. /* We need to take the global config into account */
  5447. for_each_intel_encoder(dev, encoder) {
  5448. switch (encoder->type) {
  5449. case INTEL_OUTPUT_LVDS:
  5450. has_panel = true;
  5451. has_lvds = true;
  5452. break;
  5453. case INTEL_OUTPUT_EDP:
  5454. has_panel = true;
  5455. if (enc_to_dig_port(&encoder->base)->port == PORT_A)
  5456. has_cpu_edp = true;
  5457. break;
  5458. }
  5459. }
  5460. if (HAS_PCH_IBX(dev)) {
  5461. has_ck505 = dev_priv->vbt.display_clock_mode;
  5462. can_ssc = has_ck505;
  5463. } else {
  5464. has_ck505 = false;
  5465. can_ssc = true;
  5466. }
  5467. DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d\n",
  5468. has_panel, has_lvds, has_ck505);
  5469. /* Ironlake: try to setup display ref clock before DPLL
  5470. * enabling. This is only under driver's control after
  5471. * PCH B stepping, previous chipset stepping should be
  5472. * ignoring this setting.
  5473. */
  5474. val = I915_READ(PCH_DREF_CONTROL);
  5475. /* As we must carefully and slowly disable/enable each source in turn,
  5476. * compute the final state we want first and check if we need to
  5477. * make any changes at all.
  5478. */
  5479. final = val;
  5480. final &= ~DREF_NONSPREAD_SOURCE_MASK;
  5481. if (has_ck505)
  5482. final |= DREF_NONSPREAD_CK505_ENABLE;
  5483. else
  5484. final |= DREF_NONSPREAD_SOURCE_ENABLE;
  5485. final &= ~DREF_SSC_SOURCE_MASK;
  5486. final &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
  5487. final &= ~DREF_SSC1_ENABLE;
  5488. if (has_panel) {
  5489. final |= DREF_SSC_SOURCE_ENABLE;
  5490. if (intel_panel_use_ssc(dev_priv) && can_ssc)
  5491. final |= DREF_SSC1_ENABLE;
  5492. if (has_cpu_edp) {
  5493. if (intel_panel_use_ssc(dev_priv) && can_ssc)
  5494. final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
  5495. else
  5496. final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
  5497. } else
  5498. final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  5499. } else {
  5500. final |= DREF_SSC_SOURCE_DISABLE;
  5501. final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  5502. }
  5503. if (final == val)
  5504. return;
  5505. /* Always enable nonspread source */
  5506. val &= ~DREF_NONSPREAD_SOURCE_MASK;
  5507. if (has_ck505)
  5508. val |= DREF_NONSPREAD_CK505_ENABLE;
  5509. else
  5510. val |= DREF_NONSPREAD_SOURCE_ENABLE;
  5511. if (has_panel) {
  5512. val &= ~DREF_SSC_SOURCE_MASK;
  5513. val |= DREF_SSC_SOURCE_ENABLE;
  5514. /* SSC must be turned on before enabling the CPU output */
  5515. if (intel_panel_use_ssc(dev_priv) && can_ssc) {
  5516. DRM_DEBUG_KMS("Using SSC on panel\n");
  5517. val |= DREF_SSC1_ENABLE;
  5518. } else
  5519. val &= ~DREF_SSC1_ENABLE;
  5520. /* Get SSC going before enabling the outputs */
  5521. I915_WRITE(PCH_DREF_CONTROL, val);
  5522. POSTING_READ(PCH_DREF_CONTROL);
  5523. udelay(200);
  5524. val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
  5525. /* Enable CPU source on CPU attached eDP */
  5526. if (has_cpu_edp) {
  5527. if (intel_panel_use_ssc(dev_priv) && can_ssc) {
  5528. DRM_DEBUG_KMS("Using SSC on eDP\n");
  5529. val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
  5530. } else
  5531. val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
  5532. } else
  5533. val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  5534. I915_WRITE(PCH_DREF_CONTROL, val);
  5535. POSTING_READ(PCH_DREF_CONTROL);
  5536. udelay(200);
  5537. } else {
  5538. DRM_DEBUG_KMS("Disabling SSC entirely\n");
  5539. val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
  5540. /* Turn off CPU output */
  5541. val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  5542. I915_WRITE(PCH_DREF_CONTROL, val);
  5543. POSTING_READ(PCH_DREF_CONTROL);
  5544. udelay(200);
  5545. /* Turn off the SSC source */
  5546. val &= ~DREF_SSC_SOURCE_MASK;
  5547. val |= DREF_SSC_SOURCE_DISABLE;
  5548. /* Turn off SSC1 */
  5549. val &= ~DREF_SSC1_ENABLE;
  5550. I915_WRITE(PCH_DREF_CONTROL, val);
  5551. POSTING_READ(PCH_DREF_CONTROL);
  5552. udelay(200);
  5553. }
  5554. BUG_ON(val != final);
  5555. }
  5556. static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv)
  5557. {
  5558. uint32_t tmp;
  5559. tmp = I915_READ(SOUTH_CHICKEN2);
  5560. tmp |= FDI_MPHY_IOSFSB_RESET_CTL;
  5561. I915_WRITE(SOUTH_CHICKEN2, tmp);
  5562. if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2) &
  5563. FDI_MPHY_IOSFSB_RESET_STATUS, 100))
  5564. DRM_ERROR("FDI mPHY reset assert timeout\n");
  5565. tmp = I915_READ(SOUTH_CHICKEN2);
  5566. tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL;
  5567. I915_WRITE(SOUTH_CHICKEN2, tmp);
  5568. if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2) &
  5569. FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100))
  5570. DRM_ERROR("FDI mPHY reset de-assert timeout\n");
  5571. }
  5572. /* WaMPhyProgramming:hsw */
  5573. static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv)
  5574. {
  5575. uint32_t tmp;
  5576. tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY);
  5577. tmp &= ~(0xFF << 24);
  5578. tmp |= (0x12 << 24);
  5579. intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY);
  5580. tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY);
  5581. tmp |= (1 << 11);
  5582. intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY);
  5583. tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY);
  5584. tmp |= (1 << 11);
  5585. intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY);
  5586. tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY);
  5587. tmp |= (1 << 24) | (1 << 21) | (1 << 18);
  5588. intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY);
  5589. tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY);
  5590. tmp |= (1 << 24) | (1 << 21) | (1 << 18);
  5591. intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY);
  5592. tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY);
  5593. tmp &= ~(7 << 13);
  5594. tmp |= (5 << 13);
  5595. intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY);
  5596. tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY);
  5597. tmp &= ~(7 << 13);
  5598. tmp |= (5 << 13);
  5599. intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY);
  5600. tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY);
  5601. tmp &= ~0xFF;
  5602. tmp |= 0x1C;
  5603. intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY);
  5604. tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY);
  5605. tmp &= ~0xFF;
  5606. tmp |= 0x1C;
  5607. intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY);
  5608. tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY);
  5609. tmp &= ~(0xFF << 16);
  5610. tmp |= (0x1C << 16);
  5611. intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY);
  5612. tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY);
  5613. tmp &= ~(0xFF << 16);
  5614. tmp |= (0x1C << 16);
  5615. intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY);
  5616. tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY);
  5617. tmp |= (1 << 27);
  5618. intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY);
  5619. tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY);
  5620. tmp |= (1 << 27);
  5621. intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY);
  5622. tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY);
  5623. tmp &= ~(0xF << 28);
  5624. tmp |= (4 << 28);
  5625. intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY);
  5626. tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY);
  5627. tmp &= ~(0xF << 28);
  5628. tmp |= (4 << 28);
  5629. intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY);
  5630. }
  5631. /* Implements 3 different sequences from BSpec chapter "Display iCLK
  5632. * Programming" based on the parameters passed:
  5633. * - Sequence to enable CLKOUT_DP
  5634. * - Sequence to enable CLKOUT_DP without spread
  5635. * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
  5636. */
  5637. static void lpt_enable_clkout_dp(struct drm_device *dev, bool with_spread,
  5638. bool with_fdi)
  5639. {
  5640. struct drm_i915_private *dev_priv = dev->dev_private;
  5641. uint32_t reg, tmp;
  5642. if (WARN(with_fdi && !with_spread, "FDI requires downspread\n"))
  5643. with_spread = true;
  5644. if (WARN(dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE &&
  5645. with_fdi, "LP PCH doesn't have FDI\n"))
  5646. with_fdi = false;
  5647. mutex_lock(&dev_priv->dpio_lock);
  5648. tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
  5649. tmp &= ~SBI_SSCCTL_DISABLE;
  5650. tmp |= SBI_SSCCTL_PATHALT;
  5651. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  5652. udelay(24);
  5653. if (with_spread) {
  5654. tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
  5655. tmp &= ~SBI_SSCCTL_PATHALT;
  5656. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  5657. if (with_fdi) {
  5658. lpt_reset_fdi_mphy(dev_priv);
  5659. lpt_program_fdi_mphy(dev_priv);
  5660. }
  5661. }
  5662. reg = (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) ?
  5663. SBI_GEN0 : SBI_DBUFF0;
  5664. tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
  5665. tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE;
  5666. intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
  5667. mutex_unlock(&dev_priv->dpio_lock);
  5668. }
  5669. /* Sequence to disable CLKOUT_DP */
  5670. static void lpt_disable_clkout_dp(struct drm_device *dev)
  5671. {
  5672. struct drm_i915_private *dev_priv = dev->dev_private;
  5673. uint32_t reg, tmp;
  5674. mutex_lock(&dev_priv->dpio_lock);
  5675. reg = (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) ?
  5676. SBI_GEN0 : SBI_DBUFF0;
  5677. tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
  5678. tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE;
  5679. intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
  5680. tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
  5681. if (!(tmp & SBI_SSCCTL_DISABLE)) {
  5682. if (!(tmp & SBI_SSCCTL_PATHALT)) {
  5683. tmp |= SBI_SSCCTL_PATHALT;
  5684. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  5685. udelay(32);
  5686. }
  5687. tmp |= SBI_SSCCTL_DISABLE;
  5688. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  5689. }
  5690. mutex_unlock(&dev_priv->dpio_lock);
  5691. }
  5692. static void lpt_init_pch_refclk(struct drm_device *dev)
  5693. {
  5694. struct intel_encoder *encoder;
  5695. bool has_vga = false;
  5696. for_each_intel_encoder(dev, encoder) {
  5697. switch (encoder->type) {
  5698. case INTEL_OUTPUT_ANALOG:
  5699. has_vga = true;
  5700. break;
  5701. }
  5702. }
  5703. if (has_vga)
  5704. lpt_enable_clkout_dp(dev, true, true);
  5705. else
  5706. lpt_disable_clkout_dp(dev);
  5707. }
  5708. /*
  5709. * Initialize reference clocks when the driver loads
  5710. */
  5711. void intel_init_pch_refclk(struct drm_device *dev)
  5712. {
  5713. if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
  5714. ironlake_init_pch_refclk(dev);
  5715. else if (HAS_PCH_LPT(dev))
  5716. lpt_init_pch_refclk(dev);
  5717. }
  5718. static int ironlake_get_refclk(struct drm_crtc *crtc)
  5719. {
  5720. struct drm_device *dev = crtc->dev;
  5721. struct drm_i915_private *dev_priv = dev->dev_private;
  5722. struct intel_encoder *encoder;
  5723. int num_connectors = 0;
  5724. bool is_lvds = false;
  5725. for_each_encoder_on_crtc(dev, crtc, encoder) {
  5726. switch (encoder->type) {
  5727. case INTEL_OUTPUT_LVDS:
  5728. is_lvds = true;
  5729. break;
  5730. }
  5731. num_connectors++;
  5732. }
  5733. if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) {
  5734. DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
  5735. dev_priv->vbt.lvds_ssc_freq);
  5736. return dev_priv->vbt.lvds_ssc_freq;
  5737. }
  5738. return 120000;
  5739. }
  5740. static void ironlake_set_pipeconf(struct drm_crtc *crtc)
  5741. {
  5742. struct drm_i915_private *dev_priv = crtc->dev->dev_private;
  5743. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5744. int pipe = intel_crtc->pipe;
  5745. uint32_t val;
  5746. val = 0;
  5747. switch (intel_crtc->config.pipe_bpp) {
  5748. case 18:
  5749. val |= PIPECONF_6BPC;
  5750. break;
  5751. case 24:
  5752. val |= PIPECONF_8BPC;
  5753. break;
  5754. case 30:
  5755. val |= PIPECONF_10BPC;
  5756. break;
  5757. case 36:
  5758. val |= PIPECONF_12BPC;
  5759. break;
  5760. default:
  5761. /* Case prevented by intel_choose_pipe_bpp_dither. */
  5762. BUG();
  5763. }
  5764. if (intel_crtc->config.dither)
  5765. val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
  5766. if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
  5767. val |= PIPECONF_INTERLACED_ILK;
  5768. else
  5769. val |= PIPECONF_PROGRESSIVE;
  5770. if (intel_crtc->config.limited_color_range)
  5771. val |= PIPECONF_COLOR_RANGE_SELECT;
  5772. I915_WRITE(PIPECONF(pipe), val);
  5773. POSTING_READ(PIPECONF(pipe));
  5774. }
  5775. /*
  5776. * Set up the pipe CSC unit.
  5777. *
  5778. * Currently only full range RGB to limited range RGB conversion
  5779. * is supported, but eventually this should handle various
  5780. * RGB<->YCbCr scenarios as well.
  5781. */
  5782. static void intel_set_pipe_csc(struct drm_crtc *crtc)
  5783. {
  5784. struct drm_device *dev = crtc->dev;
  5785. struct drm_i915_private *dev_priv = dev->dev_private;
  5786. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5787. int pipe = intel_crtc->pipe;
  5788. uint16_t coeff = 0x7800; /* 1.0 */
  5789. /*
  5790. * TODO: Check what kind of values actually come out of the pipe
  5791. * with these coeff/postoff values and adjust to get the best
  5792. * accuracy. Perhaps we even need to take the bpc value into
  5793. * consideration.
  5794. */
  5795. if (intel_crtc->config.limited_color_range)
  5796. coeff = ((235 - 16) * (1 << 12) / 255) & 0xff8; /* 0.xxx... */
  5797. /*
  5798. * GY/GU and RY/RU should be the other way around according
  5799. * to BSpec, but reality doesn't agree. Just set them up in
  5800. * a way that results in the correct picture.
  5801. */
  5802. I915_WRITE(PIPE_CSC_COEFF_RY_GY(pipe), coeff << 16);
  5803. I915_WRITE(PIPE_CSC_COEFF_BY(pipe), 0);
  5804. I915_WRITE(PIPE_CSC_COEFF_RU_GU(pipe), coeff);
  5805. I915_WRITE(PIPE_CSC_COEFF_BU(pipe), 0);
  5806. I915_WRITE(PIPE_CSC_COEFF_RV_GV(pipe), 0);
  5807. I915_WRITE(PIPE_CSC_COEFF_BV(pipe), coeff << 16);
  5808. I915_WRITE(PIPE_CSC_PREOFF_HI(pipe), 0);
  5809. I915_WRITE(PIPE_CSC_PREOFF_ME(pipe), 0);
  5810. I915_WRITE(PIPE_CSC_PREOFF_LO(pipe), 0);
  5811. if (INTEL_INFO(dev)->gen > 6) {
  5812. uint16_t postoff = 0;
  5813. if (intel_crtc->config.limited_color_range)
  5814. postoff = (16 * (1 << 12) / 255) & 0x1fff;
  5815. I915_WRITE(PIPE_CSC_POSTOFF_HI(pipe), postoff);
  5816. I915_WRITE(PIPE_CSC_POSTOFF_ME(pipe), postoff);
  5817. I915_WRITE(PIPE_CSC_POSTOFF_LO(pipe), postoff);
  5818. I915_WRITE(PIPE_CSC_MODE(pipe), 0);
  5819. } else {
  5820. uint32_t mode = CSC_MODE_YUV_TO_RGB;
  5821. if (intel_crtc->config.limited_color_range)
  5822. mode |= CSC_BLACK_SCREEN_OFFSET;
  5823. I915_WRITE(PIPE_CSC_MODE(pipe), mode);
  5824. }
  5825. }
  5826. static void haswell_set_pipeconf(struct drm_crtc *crtc)
  5827. {
  5828. struct drm_device *dev = crtc->dev;
  5829. struct drm_i915_private *dev_priv = dev->dev_private;
  5830. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5831. enum pipe pipe = intel_crtc->pipe;
  5832. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  5833. uint32_t val;
  5834. val = 0;
  5835. if (IS_HASWELL(dev) && intel_crtc->config.dither)
  5836. val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
  5837. if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
  5838. val |= PIPECONF_INTERLACED_ILK;
  5839. else
  5840. val |= PIPECONF_PROGRESSIVE;
  5841. I915_WRITE(PIPECONF(cpu_transcoder), val);
  5842. POSTING_READ(PIPECONF(cpu_transcoder));
  5843. I915_WRITE(GAMMA_MODE(intel_crtc->pipe), GAMMA_MODE_MODE_8BIT);
  5844. POSTING_READ(GAMMA_MODE(intel_crtc->pipe));
  5845. if (IS_BROADWELL(dev)) {
  5846. val = 0;
  5847. switch (intel_crtc->config.pipe_bpp) {
  5848. case 18:
  5849. val |= PIPEMISC_DITHER_6_BPC;
  5850. break;
  5851. case 24:
  5852. val |= PIPEMISC_DITHER_8_BPC;
  5853. break;
  5854. case 30:
  5855. val |= PIPEMISC_DITHER_10_BPC;
  5856. break;
  5857. case 36:
  5858. val |= PIPEMISC_DITHER_12_BPC;
  5859. break;
  5860. default:
  5861. /* Case prevented by pipe_config_set_bpp. */
  5862. BUG();
  5863. }
  5864. if (intel_crtc->config.dither)
  5865. val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP;
  5866. I915_WRITE(PIPEMISC(pipe), val);
  5867. }
  5868. }
  5869. static bool ironlake_compute_clocks(struct drm_crtc *crtc,
  5870. intel_clock_t *clock,
  5871. bool *has_reduced_clock,
  5872. intel_clock_t *reduced_clock)
  5873. {
  5874. struct drm_device *dev = crtc->dev;
  5875. struct drm_i915_private *dev_priv = dev->dev_private;
  5876. struct intel_encoder *intel_encoder;
  5877. int refclk;
  5878. const intel_limit_t *limit;
  5879. bool ret, is_lvds = false;
  5880. for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
  5881. switch (intel_encoder->type) {
  5882. case INTEL_OUTPUT_LVDS:
  5883. is_lvds = true;
  5884. break;
  5885. }
  5886. }
  5887. refclk = ironlake_get_refclk(crtc);
  5888. /*
  5889. * Returns a set of divisors for the desired target clock with the given
  5890. * refclk, or FALSE. The returned values represent the clock equation:
  5891. * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
  5892. */
  5893. limit = intel_limit(crtc, refclk);
  5894. ret = dev_priv->display.find_dpll(limit, crtc,
  5895. to_intel_crtc(crtc)->config.port_clock,
  5896. refclk, NULL, clock);
  5897. if (!ret)
  5898. return false;
  5899. if (is_lvds && dev_priv->lvds_downclock_avail) {
  5900. /*
  5901. * Ensure we match the reduced clock's P to the target clock.
  5902. * If the clocks don't match, we can't switch the display clock
  5903. * by using the FP0/FP1. In such case we will disable the LVDS
  5904. * downclock feature.
  5905. */
  5906. *has_reduced_clock =
  5907. dev_priv->display.find_dpll(limit, crtc,
  5908. dev_priv->lvds_downclock,
  5909. refclk, clock,
  5910. reduced_clock);
  5911. }
  5912. return true;
  5913. }
  5914. int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp)
  5915. {
  5916. /*
  5917. * Account for spread spectrum to avoid
  5918. * oversubscribing the link. Max center spread
  5919. * is 2.5%; use 5% for safety's sake.
  5920. */
  5921. u32 bps = target_clock * bpp * 21 / 20;
  5922. return DIV_ROUND_UP(bps, link_bw * 8);
  5923. }
  5924. static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor)
  5925. {
  5926. return i9xx_dpll_compute_m(dpll) < factor * dpll->n;
  5927. }
  5928. static uint32_t ironlake_compute_dpll(struct intel_crtc *intel_crtc,
  5929. u32 *fp,
  5930. intel_clock_t *reduced_clock, u32 *fp2)
  5931. {
  5932. struct drm_crtc *crtc = &intel_crtc->base;
  5933. struct drm_device *dev = crtc->dev;
  5934. struct drm_i915_private *dev_priv = dev->dev_private;
  5935. struct intel_encoder *intel_encoder;
  5936. uint32_t dpll;
  5937. int factor, num_connectors = 0;
  5938. bool is_lvds = false, is_sdvo = false;
  5939. for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
  5940. switch (intel_encoder->type) {
  5941. case INTEL_OUTPUT_LVDS:
  5942. is_lvds = true;
  5943. break;
  5944. case INTEL_OUTPUT_SDVO:
  5945. case INTEL_OUTPUT_HDMI:
  5946. is_sdvo = true;
  5947. break;
  5948. }
  5949. num_connectors++;
  5950. }
  5951. /* Enable autotuning of the PLL clock (if permissible) */
  5952. factor = 21;
  5953. if (is_lvds) {
  5954. if ((intel_panel_use_ssc(dev_priv) &&
  5955. dev_priv->vbt.lvds_ssc_freq == 100000) ||
  5956. (HAS_PCH_IBX(dev) && intel_is_dual_link_lvds(dev)))
  5957. factor = 25;
  5958. } else if (intel_crtc->config.sdvo_tv_clock)
  5959. factor = 20;
  5960. if (ironlake_needs_fb_cb_tune(&intel_crtc->config.dpll, factor))
  5961. *fp |= FP_CB_TUNE;
  5962. if (fp2 && (reduced_clock->m < factor * reduced_clock->n))
  5963. *fp2 |= FP_CB_TUNE;
  5964. dpll = 0;
  5965. if (is_lvds)
  5966. dpll |= DPLLB_MODE_LVDS;
  5967. else
  5968. dpll |= DPLLB_MODE_DAC_SERIAL;
  5969. dpll |= (intel_crtc->config.pixel_multiplier - 1)
  5970. << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
  5971. if (is_sdvo)
  5972. dpll |= DPLL_SDVO_HIGH_SPEED;
  5973. if (intel_crtc->config.has_dp_encoder)
  5974. dpll |= DPLL_SDVO_HIGH_SPEED;
  5975. /* compute bitmask from p1 value */
  5976. dpll |= (1 << (intel_crtc->config.dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  5977. /* also FPA1 */
  5978. dpll |= (1 << (intel_crtc->config.dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
  5979. switch (intel_crtc->config.dpll.p2) {
  5980. case 5:
  5981. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
  5982. break;
  5983. case 7:
  5984. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
  5985. break;
  5986. case 10:
  5987. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
  5988. break;
  5989. case 14:
  5990. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
  5991. break;
  5992. }
  5993. if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2)
  5994. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  5995. else
  5996. dpll |= PLL_REF_INPUT_DREFCLK;
  5997. return dpll | DPLL_VCO_ENABLE;
  5998. }
  5999. static int ironlake_crtc_mode_set(struct drm_crtc *crtc,
  6000. int x, int y,
  6001. struct drm_framebuffer *fb)
  6002. {
  6003. struct drm_device *dev = crtc->dev;
  6004. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6005. int num_connectors = 0;
  6006. intel_clock_t clock, reduced_clock;
  6007. u32 dpll = 0, fp = 0, fp2 = 0;
  6008. bool ok, has_reduced_clock = false;
  6009. bool is_lvds = false;
  6010. struct intel_encoder *encoder;
  6011. struct intel_shared_dpll *pll;
  6012. for_each_encoder_on_crtc(dev, crtc, encoder) {
  6013. switch (encoder->type) {
  6014. case INTEL_OUTPUT_LVDS:
  6015. is_lvds = true;
  6016. break;
  6017. }
  6018. num_connectors++;
  6019. }
  6020. WARN(!(HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)),
  6021. "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev));
  6022. ok = ironlake_compute_clocks(crtc, &clock,
  6023. &has_reduced_clock, &reduced_clock);
  6024. if (!ok && !intel_crtc->config.clock_set) {
  6025. DRM_ERROR("Couldn't find PLL settings for mode!\n");
  6026. return -EINVAL;
  6027. }
  6028. /* Compat-code for transition, will disappear. */
  6029. if (!intel_crtc->config.clock_set) {
  6030. intel_crtc->config.dpll.n = clock.n;
  6031. intel_crtc->config.dpll.m1 = clock.m1;
  6032. intel_crtc->config.dpll.m2 = clock.m2;
  6033. intel_crtc->config.dpll.p1 = clock.p1;
  6034. intel_crtc->config.dpll.p2 = clock.p2;
  6035. }
  6036. /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
  6037. if (intel_crtc->config.has_pch_encoder) {
  6038. fp = i9xx_dpll_compute_fp(&intel_crtc->config.dpll);
  6039. if (has_reduced_clock)
  6040. fp2 = i9xx_dpll_compute_fp(&reduced_clock);
  6041. dpll = ironlake_compute_dpll(intel_crtc,
  6042. &fp, &reduced_clock,
  6043. has_reduced_clock ? &fp2 : NULL);
  6044. intel_crtc->config.dpll_hw_state.dpll = dpll;
  6045. intel_crtc->config.dpll_hw_state.fp0 = fp;
  6046. if (has_reduced_clock)
  6047. intel_crtc->config.dpll_hw_state.fp1 = fp2;
  6048. else
  6049. intel_crtc->config.dpll_hw_state.fp1 = fp;
  6050. pll = intel_get_shared_dpll(intel_crtc);
  6051. if (pll == NULL) {
  6052. DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
  6053. pipe_name(intel_crtc->pipe));
  6054. return -EINVAL;
  6055. }
  6056. } else
  6057. intel_put_shared_dpll(intel_crtc);
  6058. if (is_lvds && has_reduced_clock && i915.powersave)
  6059. intel_crtc->lowfreq_avail = true;
  6060. else
  6061. intel_crtc->lowfreq_avail = false;
  6062. return 0;
  6063. }
  6064. static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc,
  6065. struct intel_link_m_n *m_n)
  6066. {
  6067. struct drm_device *dev = crtc->base.dev;
  6068. struct drm_i915_private *dev_priv = dev->dev_private;
  6069. enum pipe pipe = crtc->pipe;
  6070. m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe));
  6071. m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe));
  6072. m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe))
  6073. & ~TU_SIZE_MASK;
  6074. m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe));
  6075. m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe))
  6076. & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
  6077. }
  6078. static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc,
  6079. enum transcoder transcoder,
  6080. struct intel_link_m_n *m_n,
  6081. struct intel_link_m_n *m2_n2)
  6082. {
  6083. struct drm_device *dev = crtc->base.dev;
  6084. struct drm_i915_private *dev_priv = dev->dev_private;
  6085. enum pipe pipe = crtc->pipe;
  6086. if (INTEL_INFO(dev)->gen >= 5) {
  6087. m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder));
  6088. m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder));
  6089. m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder))
  6090. & ~TU_SIZE_MASK;
  6091. m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder));
  6092. m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder))
  6093. & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
  6094. /* Read M2_N2 registers only for gen < 8 (M2_N2 available for
  6095. * gen < 8) and if DRRS is supported (to make sure the
  6096. * registers are not unnecessarily read).
  6097. */
  6098. if (m2_n2 && INTEL_INFO(dev)->gen < 8 &&
  6099. crtc->config.has_drrs) {
  6100. m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder));
  6101. m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder));
  6102. m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder))
  6103. & ~TU_SIZE_MASK;
  6104. m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder));
  6105. m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder))
  6106. & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
  6107. }
  6108. } else {
  6109. m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe));
  6110. m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe));
  6111. m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe))
  6112. & ~TU_SIZE_MASK;
  6113. m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe));
  6114. m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe))
  6115. & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
  6116. }
  6117. }
  6118. void intel_dp_get_m_n(struct intel_crtc *crtc,
  6119. struct intel_crtc_config *pipe_config)
  6120. {
  6121. if (crtc->config.has_pch_encoder)
  6122. intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n);
  6123. else
  6124. intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
  6125. &pipe_config->dp_m_n,
  6126. &pipe_config->dp_m2_n2);
  6127. }
  6128. static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc,
  6129. struct intel_crtc_config *pipe_config)
  6130. {
  6131. intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
  6132. &pipe_config->fdi_m_n, NULL);
  6133. }
  6134. static void ironlake_get_pfit_config(struct intel_crtc *crtc,
  6135. struct intel_crtc_config *pipe_config)
  6136. {
  6137. struct drm_device *dev = crtc->base.dev;
  6138. struct drm_i915_private *dev_priv = dev->dev_private;
  6139. uint32_t tmp;
  6140. tmp = I915_READ(PF_CTL(crtc->pipe));
  6141. if (tmp & PF_ENABLE) {
  6142. pipe_config->pch_pfit.enabled = true;
  6143. pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe));
  6144. pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe));
  6145. /* We currently do not free assignements of panel fitters on
  6146. * ivb/hsw (since we don't use the higher upscaling modes which
  6147. * differentiates them) so just WARN about this case for now. */
  6148. if (IS_GEN7(dev)) {
  6149. WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) !=
  6150. PF_PIPE_SEL_IVB(crtc->pipe));
  6151. }
  6152. }
  6153. }
  6154. static void ironlake_get_plane_config(struct intel_crtc *crtc,
  6155. struct intel_plane_config *plane_config)
  6156. {
  6157. struct drm_device *dev = crtc->base.dev;
  6158. struct drm_i915_private *dev_priv = dev->dev_private;
  6159. u32 val, base, offset;
  6160. int pipe = crtc->pipe, plane = crtc->plane;
  6161. int fourcc, pixel_format;
  6162. int aligned_height;
  6163. crtc->base.primary->fb = kzalloc(sizeof(struct intel_framebuffer), GFP_KERNEL);
  6164. if (!crtc->base.primary->fb) {
  6165. DRM_DEBUG_KMS("failed to alloc fb\n");
  6166. return;
  6167. }
  6168. val = I915_READ(DSPCNTR(plane));
  6169. if (INTEL_INFO(dev)->gen >= 4)
  6170. if (val & DISPPLANE_TILED)
  6171. plane_config->tiled = true;
  6172. pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
  6173. fourcc = intel_format_to_fourcc(pixel_format);
  6174. crtc->base.primary->fb->pixel_format = fourcc;
  6175. crtc->base.primary->fb->bits_per_pixel =
  6176. drm_format_plane_cpp(fourcc, 0) * 8;
  6177. base = I915_READ(DSPSURF(plane)) & 0xfffff000;
  6178. if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
  6179. offset = I915_READ(DSPOFFSET(plane));
  6180. } else {
  6181. if (plane_config->tiled)
  6182. offset = I915_READ(DSPTILEOFF(plane));
  6183. else
  6184. offset = I915_READ(DSPLINOFF(plane));
  6185. }
  6186. plane_config->base = base;
  6187. val = I915_READ(PIPESRC(pipe));
  6188. crtc->base.primary->fb->width = ((val >> 16) & 0xfff) + 1;
  6189. crtc->base.primary->fb->height = ((val >> 0) & 0xfff) + 1;
  6190. val = I915_READ(DSPSTRIDE(pipe));
  6191. crtc->base.primary->fb->pitches[0] = val & 0xffffffc0;
  6192. aligned_height = intel_align_height(dev, crtc->base.primary->fb->height,
  6193. plane_config->tiled);
  6194. plane_config->size = PAGE_ALIGN(crtc->base.primary->fb->pitches[0] *
  6195. aligned_height);
  6196. DRM_DEBUG_KMS("pipe/plane %d/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
  6197. pipe, plane, crtc->base.primary->fb->width,
  6198. crtc->base.primary->fb->height,
  6199. crtc->base.primary->fb->bits_per_pixel, base,
  6200. crtc->base.primary->fb->pitches[0],
  6201. plane_config->size);
  6202. }
  6203. static bool ironlake_get_pipe_config(struct intel_crtc *crtc,
  6204. struct intel_crtc_config *pipe_config)
  6205. {
  6206. struct drm_device *dev = crtc->base.dev;
  6207. struct drm_i915_private *dev_priv = dev->dev_private;
  6208. uint32_t tmp;
  6209. if (!intel_display_power_enabled(dev_priv,
  6210. POWER_DOMAIN_PIPE(crtc->pipe)))
  6211. return false;
  6212. pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
  6213. pipe_config->shared_dpll = DPLL_ID_PRIVATE;
  6214. tmp = I915_READ(PIPECONF(crtc->pipe));
  6215. if (!(tmp & PIPECONF_ENABLE))
  6216. return false;
  6217. switch (tmp & PIPECONF_BPC_MASK) {
  6218. case PIPECONF_6BPC:
  6219. pipe_config->pipe_bpp = 18;
  6220. break;
  6221. case PIPECONF_8BPC:
  6222. pipe_config->pipe_bpp = 24;
  6223. break;
  6224. case PIPECONF_10BPC:
  6225. pipe_config->pipe_bpp = 30;
  6226. break;
  6227. case PIPECONF_12BPC:
  6228. pipe_config->pipe_bpp = 36;
  6229. break;
  6230. default:
  6231. break;
  6232. }
  6233. if (tmp & PIPECONF_COLOR_RANGE_SELECT)
  6234. pipe_config->limited_color_range = true;
  6235. if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) {
  6236. struct intel_shared_dpll *pll;
  6237. pipe_config->has_pch_encoder = true;
  6238. tmp = I915_READ(FDI_RX_CTL(crtc->pipe));
  6239. pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
  6240. FDI_DP_PORT_WIDTH_SHIFT) + 1;
  6241. ironlake_get_fdi_m_n_config(crtc, pipe_config);
  6242. if (HAS_PCH_IBX(dev_priv->dev)) {
  6243. pipe_config->shared_dpll =
  6244. (enum intel_dpll_id) crtc->pipe;
  6245. } else {
  6246. tmp = I915_READ(PCH_DPLL_SEL);
  6247. if (tmp & TRANS_DPLLB_SEL(crtc->pipe))
  6248. pipe_config->shared_dpll = DPLL_ID_PCH_PLL_B;
  6249. else
  6250. pipe_config->shared_dpll = DPLL_ID_PCH_PLL_A;
  6251. }
  6252. pll = &dev_priv->shared_dplls[pipe_config->shared_dpll];
  6253. WARN_ON(!pll->get_hw_state(dev_priv, pll,
  6254. &pipe_config->dpll_hw_state));
  6255. tmp = pipe_config->dpll_hw_state.dpll;
  6256. pipe_config->pixel_multiplier =
  6257. ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK)
  6258. >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1;
  6259. ironlake_pch_clock_get(crtc, pipe_config);
  6260. } else {
  6261. pipe_config->pixel_multiplier = 1;
  6262. }
  6263. intel_get_pipe_timings(crtc, pipe_config);
  6264. ironlake_get_pfit_config(crtc, pipe_config);
  6265. return true;
  6266. }
  6267. static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv)
  6268. {
  6269. struct drm_device *dev = dev_priv->dev;
  6270. struct intel_crtc *crtc;
  6271. for_each_intel_crtc(dev, crtc)
  6272. WARN(crtc->active, "CRTC for pipe %c enabled\n",
  6273. pipe_name(crtc->pipe));
  6274. WARN(I915_READ(HSW_PWR_WELL_DRIVER), "Power well on\n");
  6275. WARN(I915_READ(SPLL_CTL) & SPLL_PLL_ENABLE, "SPLL enabled\n");
  6276. WARN(I915_READ(WRPLL_CTL1) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n");
  6277. WARN(I915_READ(WRPLL_CTL2) & WRPLL_PLL_ENABLE, "WRPLL2 enabled\n");
  6278. WARN(I915_READ(PCH_PP_STATUS) & PP_ON, "Panel power on\n");
  6279. WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE,
  6280. "CPU PWM1 enabled\n");
  6281. if (IS_HASWELL(dev))
  6282. WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE,
  6283. "CPU PWM2 enabled\n");
  6284. WARN(I915_READ(BLC_PWM_PCH_CTL1) & BLM_PCH_PWM_ENABLE,
  6285. "PCH PWM1 enabled\n");
  6286. WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
  6287. "Utility pin enabled\n");
  6288. WARN(I915_READ(PCH_GTC_CTL) & PCH_GTC_ENABLE, "PCH GTC enabled\n");
  6289. /*
  6290. * In theory we can still leave IRQs enabled, as long as only the HPD
  6291. * interrupts remain enabled. We used to check for that, but since it's
  6292. * gen-specific and since we only disable LCPLL after we fully disable
  6293. * the interrupts, the check below should be enough.
  6294. */
  6295. WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n");
  6296. }
  6297. static uint32_t hsw_read_dcomp(struct drm_i915_private *dev_priv)
  6298. {
  6299. struct drm_device *dev = dev_priv->dev;
  6300. if (IS_HASWELL(dev))
  6301. return I915_READ(D_COMP_HSW);
  6302. else
  6303. return I915_READ(D_COMP_BDW);
  6304. }
  6305. static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val)
  6306. {
  6307. struct drm_device *dev = dev_priv->dev;
  6308. if (IS_HASWELL(dev)) {
  6309. mutex_lock(&dev_priv->rps.hw_lock);
  6310. if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP,
  6311. val))
  6312. DRM_ERROR("Failed to write to D_COMP\n");
  6313. mutex_unlock(&dev_priv->rps.hw_lock);
  6314. } else {
  6315. I915_WRITE(D_COMP_BDW, val);
  6316. POSTING_READ(D_COMP_BDW);
  6317. }
  6318. }
  6319. /*
  6320. * This function implements pieces of two sequences from BSpec:
  6321. * - Sequence for display software to disable LCPLL
  6322. * - Sequence for display software to allow package C8+
  6323. * The steps implemented here are just the steps that actually touch the LCPLL
  6324. * register. Callers should take care of disabling all the display engine
  6325. * functions, doing the mode unset, fixing interrupts, etc.
  6326. */
  6327. static void hsw_disable_lcpll(struct drm_i915_private *dev_priv,
  6328. bool switch_to_fclk, bool allow_power_down)
  6329. {
  6330. uint32_t val;
  6331. assert_can_disable_lcpll(dev_priv);
  6332. val = I915_READ(LCPLL_CTL);
  6333. if (switch_to_fclk) {
  6334. val |= LCPLL_CD_SOURCE_FCLK;
  6335. I915_WRITE(LCPLL_CTL, val);
  6336. if (wait_for_atomic_us(I915_READ(LCPLL_CTL) &
  6337. LCPLL_CD_SOURCE_FCLK_DONE, 1))
  6338. DRM_ERROR("Switching to FCLK failed\n");
  6339. val = I915_READ(LCPLL_CTL);
  6340. }
  6341. val |= LCPLL_PLL_DISABLE;
  6342. I915_WRITE(LCPLL_CTL, val);
  6343. POSTING_READ(LCPLL_CTL);
  6344. if (wait_for((I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK) == 0, 1))
  6345. DRM_ERROR("LCPLL still locked\n");
  6346. val = hsw_read_dcomp(dev_priv);
  6347. val |= D_COMP_COMP_DISABLE;
  6348. hsw_write_dcomp(dev_priv, val);
  6349. ndelay(100);
  6350. if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0,
  6351. 1))
  6352. DRM_ERROR("D_COMP RCOMP still in progress\n");
  6353. if (allow_power_down) {
  6354. val = I915_READ(LCPLL_CTL);
  6355. val |= LCPLL_POWER_DOWN_ALLOW;
  6356. I915_WRITE(LCPLL_CTL, val);
  6357. POSTING_READ(LCPLL_CTL);
  6358. }
  6359. }
  6360. /*
  6361. * Fully restores LCPLL, disallowing power down and switching back to LCPLL
  6362. * source.
  6363. */
  6364. static void hsw_restore_lcpll(struct drm_i915_private *dev_priv)
  6365. {
  6366. uint32_t val;
  6367. unsigned long irqflags;
  6368. val = I915_READ(LCPLL_CTL);
  6369. if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK |
  6370. LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK)
  6371. return;
  6372. /*
  6373. * Make sure we're not on PC8 state before disabling PC8, otherwise
  6374. * we'll hang the machine. To prevent PC8 state, just enable force_wake.
  6375. *
  6376. * The other problem is that hsw_restore_lcpll() is called as part of
  6377. * the runtime PM resume sequence, so we can't just call
  6378. * gen6_gt_force_wake_get() because that function calls
  6379. * intel_runtime_pm_get(), and we can't change the runtime PM refcount
  6380. * while we are on the resume sequence. So to solve this problem we have
  6381. * to call special forcewake code that doesn't touch runtime PM and
  6382. * doesn't enable the forcewake delayed work.
  6383. */
  6384. spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
  6385. if (dev_priv->uncore.forcewake_count++ == 0)
  6386. dev_priv->uncore.funcs.force_wake_get(dev_priv, FORCEWAKE_ALL);
  6387. spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
  6388. if (val & LCPLL_POWER_DOWN_ALLOW) {
  6389. val &= ~LCPLL_POWER_DOWN_ALLOW;
  6390. I915_WRITE(LCPLL_CTL, val);
  6391. POSTING_READ(LCPLL_CTL);
  6392. }
  6393. val = hsw_read_dcomp(dev_priv);
  6394. val |= D_COMP_COMP_FORCE;
  6395. val &= ~D_COMP_COMP_DISABLE;
  6396. hsw_write_dcomp(dev_priv, val);
  6397. val = I915_READ(LCPLL_CTL);
  6398. val &= ~LCPLL_PLL_DISABLE;
  6399. I915_WRITE(LCPLL_CTL, val);
  6400. if (wait_for(I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK, 5))
  6401. DRM_ERROR("LCPLL not locked yet\n");
  6402. if (val & LCPLL_CD_SOURCE_FCLK) {
  6403. val = I915_READ(LCPLL_CTL);
  6404. val &= ~LCPLL_CD_SOURCE_FCLK;
  6405. I915_WRITE(LCPLL_CTL, val);
  6406. if (wait_for_atomic_us((I915_READ(LCPLL_CTL) &
  6407. LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1))
  6408. DRM_ERROR("Switching back to LCPLL failed\n");
  6409. }
  6410. /* See the big comment above. */
  6411. spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
  6412. if (--dev_priv->uncore.forcewake_count == 0)
  6413. dev_priv->uncore.funcs.force_wake_put(dev_priv, FORCEWAKE_ALL);
  6414. spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
  6415. }
  6416. /*
  6417. * Package states C8 and deeper are really deep PC states that can only be
  6418. * reached when all the devices on the system allow it, so even if the graphics
  6419. * device allows PC8+, it doesn't mean the system will actually get to these
  6420. * states. Our driver only allows PC8+ when going into runtime PM.
  6421. *
  6422. * The requirements for PC8+ are that all the outputs are disabled, the power
  6423. * well is disabled and most interrupts are disabled, and these are also
  6424. * requirements for runtime PM. When these conditions are met, we manually do
  6425. * the other conditions: disable the interrupts, clocks and switch LCPLL refclk
  6426. * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard
  6427. * hang the machine.
  6428. *
  6429. * When we really reach PC8 or deeper states (not just when we allow it) we lose
  6430. * the state of some registers, so when we come back from PC8+ we need to
  6431. * restore this state. We don't get into PC8+ if we're not in RC6, so we don't
  6432. * need to take care of the registers kept by RC6. Notice that this happens even
  6433. * if we don't put the device in PCI D3 state (which is what currently happens
  6434. * because of the runtime PM support).
  6435. *
  6436. * For more, read "Display Sequences for Package C8" on the hardware
  6437. * documentation.
  6438. */
  6439. void hsw_enable_pc8(struct drm_i915_private *dev_priv)
  6440. {
  6441. struct drm_device *dev = dev_priv->dev;
  6442. uint32_t val;
  6443. DRM_DEBUG_KMS("Enabling package C8+\n");
  6444. if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) {
  6445. val = I915_READ(SOUTH_DSPCLK_GATE_D);
  6446. val &= ~PCH_LP_PARTITION_LEVEL_DISABLE;
  6447. I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
  6448. }
  6449. lpt_disable_clkout_dp(dev);
  6450. hsw_disable_lcpll(dev_priv, true, true);
  6451. }
  6452. void hsw_disable_pc8(struct drm_i915_private *dev_priv)
  6453. {
  6454. struct drm_device *dev = dev_priv->dev;
  6455. uint32_t val;
  6456. DRM_DEBUG_KMS("Disabling package C8+\n");
  6457. hsw_restore_lcpll(dev_priv);
  6458. lpt_init_pch_refclk(dev);
  6459. if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) {
  6460. val = I915_READ(SOUTH_DSPCLK_GATE_D);
  6461. val |= PCH_LP_PARTITION_LEVEL_DISABLE;
  6462. I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
  6463. }
  6464. intel_prepare_ddi(dev);
  6465. }
  6466. static void snb_modeset_global_resources(struct drm_device *dev)
  6467. {
  6468. modeset_update_crtc_power_domains(dev);
  6469. }
  6470. static void haswell_modeset_global_resources(struct drm_device *dev)
  6471. {
  6472. modeset_update_crtc_power_domains(dev);
  6473. }
  6474. static int haswell_crtc_mode_set(struct drm_crtc *crtc,
  6475. int x, int y,
  6476. struct drm_framebuffer *fb)
  6477. {
  6478. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6479. if (!intel_ddi_pll_select(intel_crtc))
  6480. return -EINVAL;
  6481. intel_crtc->lowfreq_avail = false;
  6482. return 0;
  6483. }
  6484. static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv,
  6485. enum port port,
  6486. struct intel_crtc_config *pipe_config)
  6487. {
  6488. pipe_config->ddi_pll_sel = I915_READ(PORT_CLK_SEL(port));
  6489. switch (pipe_config->ddi_pll_sel) {
  6490. case PORT_CLK_SEL_WRPLL1:
  6491. pipe_config->shared_dpll = DPLL_ID_WRPLL1;
  6492. break;
  6493. case PORT_CLK_SEL_WRPLL2:
  6494. pipe_config->shared_dpll = DPLL_ID_WRPLL2;
  6495. break;
  6496. }
  6497. }
  6498. static void haswell_get_ddi_port_state(struct intel_crtc *crtc,
  6499. struct intel_crtc_config *pipe_config)
  6500. {
  6501. struct drm_device *dev = crtc->base.dev;
  6502. struct drm_i915_private *dev_priv = dev->dev_private;
  6503. struct intel_shared_dpll *pll;
  6504. enum port port;
  6505. uint32_t tmp;
  6506. tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder));
  6507. port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT;
  6508. haswell_get_ddi_pll(dev_priv, port, pipe_config);
  6509. if (pipe_config->shared_dpll >= 0) {
  6510. pll = &dev_priv->shared_dplls[pipe_config->shared_dpll];
  6511. WARN_ON(!pll->get_hw_state(dev_priv, pll,
  6512. &pipe_config->dpll_hw_state));
  6513. }
  6514. /*
  6515. * Haswell has only FDI/PCH transcoder A. It is which is connected to
  6516. * DDI E. So just check whether this pipe is wired to DDI E and whether
  6517. * the PCH transcoder is on.
  6518. */
  6519. if ((port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) {
  6520. pipe_config->has_pch_encoder = true;
  6521. tmp = I915_READ(FDI_RX_CTL(PIPE_A));
  6522. pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
  6523. FDI_DP_PORT_WIDTH_SHIFT) + 1;
  6524. ironlake_get_fdi_m_n_config(crtc, pipe_config);
  6525. }
  6526. }
  6527. static bool haswell_get_pipe_config(struct intel_crtc *crtc,
  6528. struct intel_crtc_config *pipe_config)
  6529. {
  6530. struct drm_device *dev = crtc->base.dev;
  6531. struct drm_i915_private *dev_priv = dev->dev_private;
  6532. enum intel_display_power_domain pfit_domain;
  6533. uint32_t tmp;
  6534. if (!intel_display_power_enabled(dev_priv,
  6535. POWER_DOMAIN_PIPE(crtc->pipe)))
  6536. return false;
  6537. pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
  6538. pipe_config->shared_dpll = DPLL_ID_PRIVATE;
  6539. tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
  6540. if (tmp & TRANS_DDI_FUNC_ENABLE) {
  6541. enum pipe trans_edp_pipe;
  6542. switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
  6543. default:
  6544. WARN(1, "unknown pipe linked to edp transcoder\n");
  6545. case TRANS_DDI_EDP_INPUT_A_ONOFF:
  6546. case TRANS_DDI_EDP_INPUT_A_ON:
  6547. trans_edp_pipe = PIPE_A;
  6548. break;
  6549. case TRANS_DDI_EDP_INPUT_B_ONOFF:
  6550. trans_edp_pipe = PIPE_B;
  6551. break;
  6552. case TRANS_DDI_EDP_INPUT_C_ONOFF:
  6553. trans_edp_pipe = PIPE_C;
  6554. break;
  6555. }
  6556. if (trans_edp_pipe == crtc->pipe)
  6557. pipe_config->cpu_transcoder = TRANSCODER_EDP;
  6558. }
  6559. if (!intel_display_power_enabled(dev_priv,
  6560. POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder)))
  6561. return false;
  6562. tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder));
  6563. if (!(tmp & PIPECONF_ENABLE))
  6564. return false;
  6565. haswell_get_ddi_port_state(crtc, pipe_config);
  6566. intel_get_pipe_timings(crtc, pipe_config);
  6567. pfit_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe);
  6568. if (intel_display_power_enabled(dev_priv, pfit_domain))
  6569. ironlake_get_pfit_config(crtc, pipe_config);
  6570. if (IS_HASWELL(dev))
  6571. pipe_config->ips_enabled = hsw_crtc_supports_ips(crtc) &&
  6572. (I915_READ(IPS_CTL) & IPS_ENABLE);
  6573. pipe_config->pixel_multiplier = 1;
  6574. return true;
  6575. }
  6576. static struct {
  6577. int clock;
  6578. u32 config;
  6579. } hdmi_audio_clock[] = {
  6580. { DIV_ROUND_UP(25200 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_25175 },
  6581. { 25200, AUD_CONFIG_PIXEL_CLOCK_HDMI_25200 }, /* default per bspec */
  6582. { 27000, AUD_CONFIG_PIXEL_CLOCK_HDMI_27000 },
  6583. { 27000 * 1001 / 1000, AUD_CONFIG_PIXEL_CLOCK_HDMI_27027 },
  6584. { 54000, AUD_CONFIG_PIXEL_CLOCK_HDMI_54000 },
  6585. { 54000 * 1001 / 1000, AUD_CONFIG_PIXEL_CLOCK_HDMI_54054 },
  6586. { DIV_ROUND_UP(74250 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_74176 },
  6587. { 74250, AUD_CONFIG_PIXEL_CLOCK_HDMI_74250 },
  6588. { DIV_ROUND_UP(148500 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_148352 },
  6589. { 148500, AUD_CONFIG_PIXEL_CLOCK_HDMI_148500 },
  6590. };
  6591. /* get AUD_CONFIG_PIXEL_CLOCK_HDMI_* value for mode */
  6592. static u32 audio_config_hdmi_pixel_clock(struct drm_display_mode *mode)
  6593. {
  6594. int i;
  6595. for (i = 0; i < ARRAY_SIZE(hdmi_audio_clock); i++) {
  6596. if (mode->clock == hdmi_audio_clock[i].clock)
  6597. break;
  6598. }
  6599. if (i == ARRAY_SIZE(hdmi_audio_clock)) {
  6600. DRM_DEBUG_KMS("HDMI audio pixel clock setting for %d not found, falling back to defaults\n", mode->clock);
  6601. i = 1;
  6602. }
  6603. DRM_DEBUG_KMS("Configuring HDMI audio for pixel clock %d (0x%08x)\n",
  6604. hdmi_audio_clock[i].clock,
  6605. hdmi_audio_clock[i].config);
  6606. return hdmi_audio_clock[i].config;
  6607. }
  6608. static bool intel_eld_uptodate(struct drm_connector *connector,
  6609. int reg_eldv, uint32_t bits_eldv,
  6610. int reg_elda, uint32_t bits_elda,
  6611. int reg_edid)
  6612. {
  6613. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  6614. uint8_t *eld = connector->eld;
  6615. uint32_t i;
  6616. i = I915_READ(reg_eldv);
  6617. i &= bits_eldv;
  6618. if (!eld[0])
  6619. return !i;
  6620. if (!i)
  6621. return false;
  6622. i = I915_READ(reg_elda);
  6623. i &= ~bits_elda;
  6624. I915_WRITE(reg_elda, i);
  6625. for (i = 0; i < eld[2]; i++)
  6626. if (I915_READ(reg_edid) != *((uint32_t *)eld + i))
  6627. return false;
  6628. return true;
  6629. }
  6630. static void g4x_write_eld(struct drm_connector *connector,
  6631. struct drm_crtc *crtc,
  6632. struct drm_display_mode *mode)
  6633. {
  6634. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  6635. uint8_t *eld = connector->eld;
  6636. uint32_t eldv;
  6637. uint32_t len;
  6638. uint32_t i;
  6639. i = I915_READ(G4X_AUD_VID_DID);
  6640. if (i == INTEL_AUDIO_DEVBLC || i == INTEL_AUDIO_DEVCL)
  6641. eldv = G4X_ELDV_DEVCL_DEVBLC;
  6642. else
  6643. eldv = G4X_ELDV_DEVCTG;
  6644. if (intel_eld_uptodate(connector,
  6645. G4X_AUD_CNTL_ST, eldv,
  6646. G4X_AUD_CNTL_ST, G4X_ELD_ADDR,
  6647. G4X_HDMIW_HDMIEDID))
  6648. return;
  6649. i = I915_READ(G4X_AUD_CNTL_ST);
  6650. i &= ~(eldv | G4X_ELD_ADDR);
  6651. len = (i >> 9) & 0x1f; /* ELD buffer size */
  6652. I915_WRITE(G4X_AUD_CNTL_ST, i);
  6653. if (!eld[0])
  6654. return;
  6655. len = min_t(uint8_t, eld[2], len);
  6656. DRM_DEBUG_DRIVER("ELD size %d\n", len);
  6657. for (i = 0; i < len; i++)
  6658. I915_WRITE(G4X_HDMIW_HDMIEDID, *((uint32_t *)eld + i));
  6659. i = I915_READ(G4X_AUD_CNTL_ST);
  6660. i |= eldv;
  6661. I915_WRITE(G4X_AUD_CNTL_ST, i);
  6662. }
  6663. static void haswell_write_eld(struct drm_connector *connector,
  6664. struct drm_crtc *crtc,
  6665. struct drm_display_mode *mode)
  6666. {
  6667. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  6668. uint8_t *eld = connector->eld;
  6669. uint32_t eldv;
  6670. uint32_t i;
  6671. int len;
  6672. int pipe = to_intel_crtc(crtc)->pipe;
  6673. int tmp;
  6674. int hdmiw_hdmiedid = HSW_AUD_EDID_DATA(pipe);
  6675. int aud_cntl_st = HSW_AUD_DIP_ELD_CTRL(pipe);
  6676. int aud_config = HSW_AUD_CFG(pipe);
  6677. int aud_cntrl_st2 = HSW_AUD_PIN_ELD_CP_VLD;
  6678. /* Audio output enable */
  6679. DRM_DEBUG_DRIVER("HDMI audio: enable codec\n");
  6680. tmp = I915_READ(aud_cntrl_st2);
  6681. tmp |= (AUDIO_OUTPUT_ENABLE_A << (pipe * 4));
  6682. I915_WRITE(aud_cntrl_st2, tmp);
  6683. POSTING_READ(aud_cntrl_st2);
  6684. assert_pipe_disabled(dev_priv, to_intel_crtc(crtc)->pipe);
  6685. /* Set ELD valid state */
  6686. tmp = I915_READ(aud_cntrl_st2);
  6687. DRM_DEBUG_DRIVER("HDMI audio: pin eld vld status=0x%08x\n", tmp);
  6688. tmp |= (AUDIO_ELD_VALID_A << (pipe * 4));
  6689. I915_WRITE(aud_cntrl_st2, tmp);
  6690. tmp = I915_READ(aud_cntrl_st2);
  6691. DRM_DEBUG_DRIVER("HDMI audio: eld vld status=0x%08x\n", tmp);
  6692. /* Enable HDMI mode */
  6693. tmp = I915_READ(aud_config);
  6694. DRM_DEBUG_DRIVER("HDMI audio: audio conf: 0x%08x\n", tmp);
  6695. /* clear N_programing_enable and N_value_index */
  6696. tmp &= ~(AUD_CONFIG_N_VALUE_INDEX | AUD_CONFIG_N_PROG_ENABLE);
  6697. I915_WRITE(aud_config, tmp);
  6698. DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe));
  6699. eldv = AUDIO_ELD_VALID_A << (pipe * 4);
  6700. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) {
  6701. DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
  6702. eld[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
  6703. I915_WRITE(aud_config, AUD_CONFIG_N_VALUE_INDEX); /* 0x1 = DP */
  6704. } else {
  6705. I915_WRITE(aud_config, audio_config_hdmi_pixel_clock(mode));
  6706. }
  6707. if (intel_eld_uptodate(connector,
  6708. aud_cntrl_st2, eldv,
  6709. aud_cntl_st, IBX_ELD_ADDRESS,
  6710. hdmiw_hdmiedid))
  6711. return;
  6712. i = I915_READ(aud_cntrl_st2);
  6713. i &= ~eldv;
  6714. I915_WRITE(aud_cntrl_st2, i);
  6715. if (!eld[0])
  6716. return;
  6717. i = I915_READ(aud_cntl_st);
  6718. i &= ~IBX_ELD_ADDRESS;
  6719. I915_WRITE(aud_cntl_st, i);
  6720. i = (i >> 29) & DIP_PORT_SEL_MASK; /* DIP_Port_Select, 0x1 = PortB */
  6721. DRM_DEBUG_DRIVER("port num:%d\n", i);
  6722. len = min_t(uint8_t, eld[2], 21); /* 84 bytes of hw ELD buffer */
  6723. DRM_DEBUG_DRIVER("ELD size %d\n", len);
  6724. for (i = 0; i < len; i++)
  6725. I915_WRITE(hdmiw_hdmiedid, *((uint32_t *)eld + i));
  6726. i = I915_READ(aud_cntrl_st2);
  6727. i |= eldv;
  6728. I915_WRITE(aud_cntrl_st2, i);
  6729. }
  6730. static void ironlake_write_eld(struct drm_connector *connector,
  6731. struct drm_crtc *crtc,
  6732. struct drm_display_mode *mode)
  6733. {
  6734. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  6735. uint8_t *eld = connector->eld;
  6736. uint32_t eldv;
  6737. uint32_t i;
  6738. int len;
  6739. int hdmiw_hdmiedid;
  6740. int aud_config;
  6741. int aud_cntl_st;
  6742. int aud_cntrl_st2;
  6743. int pipe = to_intel_crtc(crtc)->pipe;
  6744. if (HAS_PCH_IBX(connector->dev)) {
  6745. hdmiw_hdmiedid = IBX_HDMIW_HDMIEDID(pipe);
  6746. aud_config = IBX_AUD_CFG(pipe);
  6747. aud_cntl_st = IBX_AUD_CNTL_ST(pipe);
  6748. aud_cntrl_st2 = IBX_AUD_CNTL_ST2;
  6749. } else if (IS_VALLEYVIEW(connector->dev)) {
  6750. hdmiw_hdmiedid = VLV_HDMIW_HDMIEDID(pipe);
  6751. aud_config = VLV_AUD_CFG(pipe);
  6752. aud_cntl_st = VLV_AUD_CNTL_ST(pipe);
  6753. aud_cntrl_st2 = VLV_AUD_CNTL_ST2;
  6754. } else {
  6755. hdmiw_hdmiedid = CPT_HDMIW_HDMIEDID(pipe);
  6756. aud_config = CPT_AUD_CFG(pipe);
  6757. aud_cntl_st = CPT_AUD_CNTL_ST(pipe);
  6758. aud_cntrl_st2 = CPT_AUD_CNTRL_ST2;
  6759. }
  6760. DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe));
  6761. if (IS_VALLEYVIEW(connector->dev)) {
  6762. struct intel_encoder *intel_encoder;
  6763. struct intel_digital_port *intel_dig_port;
  6764. intel_encoder = intel_attached_encoder(connector);
  6765. intel_dig_port = enc_to_dig_port(&intel_encoder->base);
  6766. i = intel_dig_port->port;
  6767. } else {
  6768. i = I915_READ(aud_cntl_st);
  6769. i = (i >> 29) & DIP_PORT_SEL_MASK;
  6770. /* DIP_Port_Select, 0x1 = PortB */
  6771. }
  6772. if (!i) {
  6773. DRM_DEBUG_DRIVER("Audio directed to unknown port\n");
  6774. /* operate blindly on all ports */
  6775. eldv = IBX_ELD_VALIDB;
  6776. eldv |= IBX_ELD_VALIDB << 4;
  6777. eldv |= IBX_ELD_VALIDB << 8;
  6778. } else {
  6779. DRM_DEBUG_DRIVER("ELD on port %c\n", port_name(i));
  6780. eldv = IBX_ELD_VALIDB << ((i - 1) * 4);
  6781. }
  6782. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) {
  6783. DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
  6784. eld[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
  6785. I915_WRITE(aud_config, AUD_CONFIG_N_VALUE_INDEX); /* 0x1 = DP */
  6786. } else {
  6787. I915_WRITE(aud_config, audio_config_hdmi_pixel_clock(mode));
  6788. }
  6789. if (intel_eld_uptodate(connector,
  6790. aud_cntrl_st2, eldv,
  6791. aud_cntl_st, IBX_ELD_ADDRESS,
  6792. hdmiw_hdmiedid))
  6793. return;
  6794. i = I915_READ(aud_cntrl_st2);
  6795. i &= ~eldv;
  6796. I915_WRITE(aud_cntrl_st2, i);
  6797. if (!eld[0])
  6798. return;
  6799. i = I915_READ(aud_cntl_st);
  6800. i &= ~IBX_ELD_ADDRESS;
  6801. I915_WRITE(aud_cntl_st, i);
  6802. len = min_t(uint8_t, eld[2], 21); /* 84 bytes of hw ELD buffer */
  6803. DRM_DEBUG_DRIVER("ELD size %d\n", len);
  6804. for (i = 0; i < len; i++)
  6805. I915_WRITE(hdmiw_hdmiedid, *((uint32_t *)eld + i));
  6806. i = I915_READ(aud_cntrl_st2);
  6807. i |= eldv;
  6808. I915_WRITE(aud_cntrl_st2, i);
  6809. }
  6810. void intel_write_eld(struct drm_encoder *encoder,
  6811. struct drm_display_mode *mode)
  6812. {
  6813. struct drm_crtc *crtc = encoder->crtc;
  6814. struct drm_connector *connector;
  6815. struct drm_device *dev = encoder->dev;
  6816. struct drm_i915_private *dev_priv = dev->dev_private;
  6817. connector = drm_select_eld(encoder, mode);
  6818. if (!connector)
  6819. return;
  6820. DRM_DEBUG_DRIVER("ELD on [CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
  6821. connector->base.id,
  6822. connector->name,
  6823. connector->encoder->base.id,
  6824. connector->encoder->name);
  6825. connector->eld[6] = drm_av_sync_delay(connector, mode) / 2;
  6826. if (dev_priv->display.write_eld)
  6827. dev_priv->display.write_eld(connector, crtc, mode);
  6828. }
  6829. static void i845_update_cursor(struct drm_crtc *crtc, u32 base)
  6830. {
  6831. struct drm_device *dev = crtc->dev;
  6832. struct drm_i915_private *dev_priv = dev->dev_private;
  6833. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6834. uint32_t cntl = 0, size = 0;
  6835. if (base) {
  6836. unsigned int width = intel_crtc->cursor_width;
  6837. unsigned int height = intel_crtc->cursor_height;
  6838. unsigned int stride = roundup_pow_of_two(width) * 4;
  6839. switch (stride) {
  6840. default:
  6841. WARN_ONCE(1, "Invalid cursor width/stride, width=%u, stride=%u\n",
  6842. width, stride);
  6843. stride = 256;
  6844. /* fallthrough */
  6845. case 256:
  6846. case 512:
  6847. case 1024:
  6848. case 2048:
  6849. break;
  6850. }
  6851. cntl |= CURSOR_ENABLE |
  6852. CURSOR_GAMMA_ENABLE |
  6853. CURSOR_FORMAT_ARGB |
  6854. CURSOR_STRIDE(stride);
  6855. size = (height << 12) | width;
  6856. }
  6857. if (intel_crtc->cursor_cntl != 0 &&
  6858. (intel_crtc->cursor_base != base ||
  6859. intel_crtc->cursor_size != size ||
  6860. intel_crtc->cursor_cntl != cntl)) {
  6861. /* On these chipsets we can only modify the base/size/stride
  6862. * whilst the cursor is disabled.
  6863. */
  6864. I915_WRITE(_CURACNTR, 0);
  6865. POSTING_READ(_CURACNTR);
  6866. intel_crtc->cursor_cntl = 0;
  6867. }
  6868. if (intel_crtc->cursor_base != base) {
  6869. I915_WRITE(_CURABASE, base);
  6870. intel_crtc->cursor_base = base;
  6871. }
  6872. if (intel_crtc->cursor_size != size) {
  6873. I915_WRITE(CURSIZE, size);
  6874. intel_crtc->cursor_size = size;
  6875. }
  6876. if (intel_crtc->cursor_cntl != cntl) {
  6877. I915_WRITE(_CURACNTR, cntl);
  6878. POSTING_READ(_CURACNTR);
  6879. intel_crtc->cursor_cntl = cntl;
  6880. }
  6881. }
  6882. static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base)
  6883. {
  6884. struct drm_device *dev = crtc->dev;
  6885. struct drm_i915_private *dev_priv = dev->dev_private;
  6886. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6887. int pipe = intel_crtc->pipe;
  6888. uint32_t cntl;
  6889. cntl = 0;
  6890. if (base) {
  6891. cntl = MCURSOR_GAMMA_ENABLE;
  6892. switch (intel_crtc->cursor_width) {
  6893. case 64:
  6894. cntl |= CURSOR_MODE_64_ARGB_AX;
  6895. break;
  6896. case 128:
  6897. cntl |= CURSOR_MODE_128_ARGB_AX;
  6898. break;
  6899. case 256:
  6900. cntl |= CURSOR_MODE_256_ARGB_AX;
  6901. break;
  6902. default:
  6903. WARN_ON(1);
  6904. return;
  6905. }
  6906. cntl |= pipe << 28; /* Connect to correct pipe */
  6907. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  6908. cntl |= CURSOR_PIPE_CSC_ENABLE;
  6909. }
  6910. if (intel_crtc->cursor_cntl != cntl) {
  6911. I915_WRITE(CURCNTR(pipe), cntl);
  6912. POSTING_READ(CURCNTR(pipe));
  6913. intel_crtc->cursor_cntl = cntl;
  6914. }
  6915. /* and commit changes on next vblank */
  6916. I915_WRITE(CURBASE(pipe), base);
  6917. POSTING_READ(CURBASE(pipe));
  6918. intel_crtc->cursor_base = base;
  6919. }
  6920. /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */
  6921. static void intel_crtc_update_cursor(struct drm_crtc *crtc,
  6922. bool on)
  6923. {
  6924. struct drm_device *dev = crtc->dev;
  6925. struct drm_i915_private *dev_priv = dev->dev_private;
  6926. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6927. int pipe = intel_crtc->pipe;
  6928. int x = crtc->cursor_x;
  6929. int y = crtc->cursor_y;
  6930. u32 base = 0, pos = 0;
  6931. if (on)
  6932. base = intel_crtc->cursor_addr;
  6933. if (x >= intel_crtc->config.pipe_src_w)
  6934. base = 0;
  6935. if (y >= intel_crtc->config.pipe_src_h)
  6936. base = 0;
  6937. if (x < 0) {
  6938. if (x + intel_crtc->cursor_width <= 0)
  6939. base = 0;
  6940. pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
  6941. x = -x;
  6942. }
  6943. pos |= x << CURSOR_X_SHIFT;
  6944. if (y < 0) {
  6945. if (y + intel_crtc->cursor_height <= 0)
  6946. base = 0;
  6947. pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
  6948. y = -y;
  6949. }
  6950. pos |= y << CURSOR_Y_SHIFT;
  6951. if (base == 0 && intel_crtc->cursor_base == 0)
  6952. return;
  6953. I915_WRITE(CURPOS(pipe), pos);
  6954. if (IS_845G(dev) || IS_I865G(dev))
  6955. i845_update_cursor(crtc, base);
  6956. else
  6957. i9xx_update_cursor(crtc, base);
  6958. }
  6959. static bool cursor_size_ok(struct drm_device *dev,
  6960. uint32_t width, uint32_t height)
  6961. {
  6962. if (width == 0 || height == 0)
  6963. return false;
  6964. /*
  6965. * 845g/865g are special in that they are only limited by
  6966. * the width of their cursors, the height is arbitrary up to
  6967. * the precision of the register. Everything else requires
  6968. * square cursors, limited to a few power-of-two sizes.
  6969. */
  6970. if (IS_845G(dev) || IS_I865G(dev)) {
  6971. if ((width & 63) != 0)
  6972. return false;
  6973. if (width > (IS_845G(dev) ? 64 : 512))
  6974. return false;
  6975. if (height > 1023)
  6976. return false;
  6977. } else {
  6978. switch (width | height) {
  6979. case 256:
  6980. case 128:
  6981. if (IS_GEN2(dev))
  6982. return false;
  6983. case 64:
  6984. break;
  6985. default:
  6986. return false;
  6987. }
  6988. }
  6989. return true;
  6990. }
  6991. /*
  6992. * intel_crtc_cursor_set_obj - Set cursor to specified GEM object
  6993. *
  6994. * Note that the object's reference will be consumed if the update fails. If
  6995. * the update succeeds, the reference of the old object (if any) will be
  6996. * consumed.
  6997. */
  6998. static int intel_crtc_cursor_set_obj(struct drm_crtc *crtc,
  6999. struct drm_i915_gem_object *obj,
  7000. uint32_t width, uint32_t height)
  7001. {
  7002. struct drm_device *dev = crtc->dev;
  7003. struct drm_i915_private *dev_priv = dev->dev_private;
  7004. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7005. enum pipe pipe = intel_crtc->pipe;
  7006. unsigned old_width, stride;
  7007. uint32_t addr;
  7008. int ret;
  7009. /* if we want to turn off the cursor ignore width and height */
  7010. if (!obj) {
  7011. DRM_DEBUG_KMS("cursor off\n");
  7012. addr = 0;
  7013. mutex_lock(&dev->struct_mutex);
  7014. goto finish;
  7015. }
  7016. /* Check for which cursor types we support */
  7017. if (!cursor_size_ok(dev, width, height)) {
  7018. DRM_DEBUG("Cursor dimension not supported\n");
  7019. return -EINVAL;
  7020. }
  7021. stride = roundup_pow_of_two(width) * 4;
  7022. if (obj->base.size < stride * height) {
  7023. DRM_DEBUG_KMS("buffer is too small\n");
  7024. ret = -ENOMEM;
  7025. goto fail;
  7026. }
  7027. /* we only need to pin inside GTT if cursor is non-phy */
  7028. mutex_lock(&dev->struct_mutex);
  7029. if (!INTEL_INFO(dev)->cursor_needs_physical) {
  7030. unsigned alignment;
  7031. if (obj->tiling_mode) {
  7032. DRM_DEBUG_KMS("cursor cannot be tiled\n");
  7033. ret = -EINVAL;
  7034. goto fail_locked;
  7035. }
  7036. /*
  7037. * Global gtt pte registers are special registers which actually
  7038. * forward writes to a chunk of system memory. Which means that
  7039. * there is no risk that the register values disappear as soon
  7040. * as we call intel_runtime_pm_put(), so it is correct to wrap
  7041. * only the pin/unpin/fence and not more.
  7042. */
  7043. intel_runtime_pm_get(dev_priv);
  7044. /* Note that the w/a also requires 2 PTE of padding following
  7045. * the bo. We currently fill all unused PTE with the shadow
  7046. * page and so we should always have valid PTE following the
  7047. * cursor preventing the VT-d warning.
  7048. */
  7049. alignment = 0;
  7050. if (need_vtd_wa(dev))
  7051. alignment = 64*1024;
  7052. ret = i915_gem_object_pin_to_display_plane(obj, alignment, NULL);
  7053. if (ret) {
  7054. DRM_DEBUG_KMS("failed to move cursor bo into the GTT\n");
  7055. intel_runtime_pm_put(dev_priv);
  7056. goto fail_locked;
  7057. }
  7058. ret = i915_gem_object_put_fence(obj);
  7059. if (ret) {
  7060. DRM_DEBUG_KMS("failed to release fence for cursor");
  7061. intel_runtime_pm_put(dev_priv);
  7062. goto fail_unpin;
  7063. }
  7064. addr = i915_gem_obj_ggtt_offset(obj);
  7065. intel_runtime_pm_put(dev_priv);
  7066. } else {
  7067. int align = IS_I830(dev) ? 16 * 1024 : 256;
  7068. ret = i915_gem_object_attach_phys(obj, align);
  7069. if (ret) {
  7070. DRM_DEBUG_KMS("failed to attach phys object\n");
  7071. goto fail_locked;
  7072. }
  7073. addr = obj->phys_handle->busaddr;
  7074. }
  7075. finish:
  7076. if (intel_crtc->cursor_bo) {
  7077. if (!INTEL_INFO(dev)->cursor_needs_physical)
  7078. i915_gem_object_unpin_from_display_plane(intel_crtc->cursor_bo);
  7079. }
  7080. i915_gem_track_fb(intel_crtc->cursor_bo, obj,
  7081. INTEL_FRONTBUFFER_CURSOR(pipe));
  7082. mutex_unlock(&dev->struct_mutex);
  7083. old_width = intel_crtc->cursor_width;
  7084. intel_crtc->cursor_addr = addr;
  7085. intel_crtc->cursor_bo = obj;
  7086. intel_crtc->cursor_width = width;
  7087. intel_crtc->cursor_height = height;
  7088. if (intel_crtc->active) {
  7089. if (old_width != width)
  7090. intel_update_watermarks(crtc);
  7091. intel_crtc_update_cursor(crtc, intel_crtc->cursor_bo != NULL);
  7092. }
  7093. intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_CURSOR(pipe));
  7094. return 0;
  7095. fail_unpin:
  7096. i915_gem_object_unpin_from_display_plane(obj);
  7097. fail_locked:
  7098. mutex_unlock(&dev->struct_mutex);
  7099. fail:
  7100. drm_gem_object_unreference_unlocked(&obj->base);
  7101. return ret;
  7102. }
  7103. static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
  7104. u16 *blue, uint32_t start, uint32_t size)
  7105. {
  7106. int end = (start + size > 256) ? 256 : start + size, i;
  7107. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7108. for (i = start; i < end; i++) {
  7109. intel_crtc->lut_r[i] = red[i] >> 8;
  7110. intel_crtc->lut_g[i] = green[i] >> 8;
  7111. intel_crtc->lut_b[i] = blue[i] >> 8;
  7112. }
  7113. intel_crtc_load_lut(crtc);
  7114. }
  7115. /* VESA 640x480x72Hz mode to set on the pipe */
  7116. static struct drm_display_mode load_detect_mode = {
  7117. DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
  7118. 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  7119. };
  7120. struct drm_framebuffer *
  7121. __intel_framebuffer_create(struct drm_device *dev,
  7122. struct drm_mode_fb_cmd2 *mode_cmd,
  7123. struct drm_i915_gem_object *obj)
  7124. {
  7125. struct intel_framebuffer *intel_fb;
  7126. int ret;
  7127. intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
  7128. if (!intel_fb) {
  7129. drm_gem_object_unreference_unlocked(&obj->base);
  7130. return ERR_PTR(-ENOMEM);
  7131. }
  7132. ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj);
  7133. if (ret)
  7134. goto err;
  7135. return &intel_fb->base;
  7136. err:
  7137. drm_gem_object_unreference_unlocked(&obj->base);
  7138. kfree(intel_fb);
  7139. return ERR_PTR(ret);
  7140. }
  7141. static struct drm_framebuffer *
  7142. intel_framebuffer_create(struct drm_device *dev,
  7143. struct drm_mode_fb_cmd2 *mode_cmd,
  7144. struct drm_i915_gem_object *obj)
  7145. {
  7146. struct drm_framebuffer *fb;
  7147. int ret;
  7148. ret = i915_mutex_lock_interruptible(dev);
  7149. if (ret)
  7150. return ERR_PTR(ret);
  7151. fb = __intel_framebuffer_create(dev, mode_cmd, obj);
  7152. mutex_unlock(&dev->struct_mutex);
  7153. return fb;
  7154. }
  7155. static u32
  7156. intel_framebuffer_pitch_for_width(int width, int bpp)
  7157. {
  7158. u32 pitch = DIV_ROUND_UP(width * bpp, 8);
  7159. return ALIGN(pitch, 64);
  7160. }
  7161. static u32
  7162. intel_framebuffer_size_for_mode(struct drm_display_mode *mode, int bpp)
  7163. {
  7164. u32 pitch = intel_framebuffer_pitch_for_width(mode->hdisplay, bpp);
  7165. return PAGE_ALIGN(pitch * mode->vdisplay);
  7166. }
  7167. static struct drm_framebuffer *
  7168. intel_framebuffer_create_for_mode(struct drm_device *dev,
  7169. struct drm_display_mode *mode,
  7170. int depth, int bpp)
  7171. {
  7172. struct drm_i915_gem_object *obj;
  7173. struct drm_mode_fb_cmd2 mode_cmd = { 0 };
  7174. obj = i915_gem_alloc_object(dev,
  7175. intel_framebuffer_size_for_mode(mode, bpp));
  7176. if (obj == NULL)
  7177. return ERR_PTR(-ENOMEM);
  7178. mode_cmd.width = mode->hdisplay;
  7179. mode_cmd.height = mode->vdisplay;
  7180. mode_cmd.pitches[0] = intel_framebuffer_pitch_for_width(mode_cmd.width,
  7181. bpp);
  7182. mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth);
  7183. return intel_framebuffer_create(dev, &mode_cmd, obj);
  7184. }
  7185. static struct drm_framebuffer *
  7186. mode_fits_in_fbdev(struct drm_device *dev,
  7187. struct drm_display_mode *mode)
  7188. {
  7189. #ifdef CONFIG_DRM_I915_FBDEV
  7190. struct drm_i915_private *dev_priv = dev->dev_private;
  7191. struct drm_i915_gem_object *obj;
  7192. struct drm_framebuffer *fb;
  7193. if (!dev_priv->fbdev)
  7194. return NULL;
  7195. if (!dev_priv->fbdev->fb)
  7196. return NULL;
  7197. obj = dev_priv->fbdev->fb->obj;
  7198. BUG_ON(!obj);
  7199. fb = &dev_priv->fbdev->fb->base;
  7200. if (fb->pitches[0] < intel_framebuffer_pitch_for_width(mode->hdisplay,
  7201. fb->bits_per_pixel))
  7202. return NULL;
  7203. if (obj->base.size < mode->vdisplay * fb->pitches[0])
  7204. return NULL;
  7205. return fb;
  7206. #else
  7207. return NULL;
  7208. #endif
  7209. }
  7210. bool intel_get_load_detect_pipe(struct drm_connector *connector,
  7211. struct drm_display_mode *mode,
  7212. struct intel_load_detect_pipe *old,
  7213. struct drm_modeset_acquire_ctx *ctx)
  7214. {
  7215. struct intel_crtc *intel_crtc;
  7216. struct intel_encoder *intel_encoder =
  7217. intel_attached_encoder(connector);
  7218. struct drm_crtc *possible_crtc;
  7219. struct drm_encoder *encoder = &intel_encoder->base;
  7220. struct drm_crtc *crtc = NULL;
  7221. struct drm_device *dev = encoder->dev;
  7222. struct drm_framebuffer *fb;
  7223. struct drm_mode_config *config = &dev->mode_config;
  7224. int ret, i = -1;
  7225. DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
  7226. connector->base.id, connector->name,
  7227. encoder->base.id, encoder->name);
  7228. retry:
  7229. ret = drm_modeset_lock(&config->connection_mutex, ctx);
  7230. if (ret)
  7231. goto fail_unlock;
  7232. /*
  7233. * Algorithm gets a little messy:
  7234. *
  7235. * - if the connector already has an assigned crtc, use it (but make
  7236. * sure it's on first)
  7237. *
  7238. * - try to find the first unused crtc that can drive this connector,
  7239. * and use that if we find one
  7240. */
  7241. /* See if we already have a CRTC for this connector */
  7242. if (encoder->crtc) {
  7243. crtc = encoder->crtc;
  7244. ret = drm_modeset_lock(&crtc->mutex, ctx);
  7245. if (ret)
  7246. goto fail_unlock;
  7247. old->dpms_mode = connector->dpms;
  7248. old->load_detect_temp = false;
  7249. /* Make sure the crtc and connector are running */
  7250. if (connector->dpms != DRM_MODE_DPMS_ON)
  7251. connector->funcs->dpms(connector, DRM_MODE_DPMS_ON);
  7252. return true;
  7253. }
  7254. /* Find an unused one (if possible) */
  7255. for_each_crtc(dev, possible_crtc) {
  7256. i++;
  7257. if (!(encoder->possible_crtcs & (1 << i)))
  7258. continue;
  7259. if (possible_crtc->enabled)
  7260. continue;
  7261. /* This can occur when applying the pipe A quirk on resume. */
  7262. if (to_intel_crtc(possible_crtc)->new_enabled)
  7263. continue;
  7264. crtc = possible_crtc;
  7265. break;
  7266. }
  7267. /*
  7268. * If we didn't find an unused CRTC, don't use any.
  7269. */
  7270. if (!crtc) {
  7271. DRM_DEBUG_KMS("no pipe available for load-detect\n");
  7272. goto fail_unlock;
  7273. }
  7274. ret = drm_modeset_lock(&crtc->mutex, ctx);
  7275. if (ret)
  7276. goto fail_unlock;
  7277. intel_encoder->new_crtc = to_intel_crtc(crtc);
  7278. to_intel_connector(connector)->new_encoder = intel_encoder;
  7279. intel_crtc = to_intel_crtc(crtc);
  7280. intel_crtc->new_enabled = true;
  7281. intel_crtc->new_config = &intel_crtc->config;
  7282. old->dpms_mode = connector->dpms;
  7283. old->load_detect_temp = true;
  7284. old->release_fb = NULL;
  7285. if (!mode)
  7286. mode = &load_detect_mode;
  7287. /* We need a framebuffer large enough to accommodate all accesses
  7288. * that the plane may generate whilst we perform load detection.
  7289. * We can not rely on the fbcon either being present (we get called
  7290. * during its initialisation to detect all boot displays, or it may
  7291. * not even exist) or that it is large enough to satisfy the
  7292. * requested mode.
  7293. */
  7294. fb = mode_fits_in_fbdev(dev, mode);
  7295. if (fb == NULL) {
  7296. DRM_DEBUG_KMS("creating tmp fb for load-detection\n");
  7297. fb = intel_framebuffer_create_for_mode(dev, mode, 24, 32);
  7298. old->release_fb = fb;
  7299. } else
  7300. DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n");
  7301. if (IS_ERR(fb)) {
  7302. DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n");
  7303. goto fail;
  7304. }
  7305. if (intel_set_mode(crtc, mode, 0, 0, fb)) {
  7306. DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
  7307. if (old->release_fb)
  7308. old->release_fb->funcs->destroy(old->release_fb);
  7309. goto fail;
  7310. }
  7311. /* let the connector get through one full cycle before testing */
  7312. intel_wait_for_vblank(dev, intel_crtc->pipe);
  7313. return true;
  7314. fail:
  7315. intel_crtc->new_enabled = crtc->enabled;
  7316. if (intel_crtc->new_enabled)
  7317. intel_crtc->new_config = &intel_crtc->config;
  7318. else
  7319. intel_crtc->new_config = NULL;
  7320. fail_unlock:
  7321. if (ret == -EDEADLK) {
  7322. drm_modeset_backoff(ctx);
  7323. goto retry;
  7324. }
  7325. return false;
  7326. }
  7327. void intel_release_load_detect_pipe(struct drm_connector *connector,
  7328. struct intel_load_detect_pipe *old)
  7329. {
  7330. struct intel_encoder *intel_encoder =
  7331. intel_attached_encoder(connector);
  7332. struct drm_encoder *encoder = &intel_encoder->base;
  7333. struct drm_crtc *crtc = encoder->crtc;
  7334. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7335. DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
  7336. connector->base.id, connector->name,
  7337. encoder->base.id, encoder->name);
  7338. if (old->load_detect_temp) {
  7339. to_intel_connector(connector)->new_encoder = NULL;
  7340. intel_encoder->new_crtc = NULL;
  7341. intel_crtc->new_enabled = false;
  7342. intel_crtc->new_config = NULL;
  7343. intel_set_mode(crtc, NULL, 0, 0, NULL);
  7344. if (old->release_fb) {
  7345. drm_framebuffer_unregister_private(old->release_fb);
  7346. drm_framebuffer_unreference(old->release_fb);
  7347. }
  7348. return;
  7349. }
  7350. /* Switch crtc and encoder back off if necessary */
  7351. if (old->dpms_mode != DRM_MODE_DPMS_ON)
  7352. connector->funcs->dpms(connector, old->dpms_mode);
  7353. }
  7354. static int i9xx_pll_refclk(struct drm_device *dev,
  7355. const struct intel_crtc_config *pipe_config)
  7356. {
  7357. struct drm_i915_private *dev_priv = dev->dev_private;
  7358. u32 dpll = pipe_config->dpll_hw_state.dpll;
  7359. if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN)
  7360. return dev_priv->vbt.lvds_ssc_freq;
  7361. else if (HAS_PCH_SPLIT(dev))
  7362. return 120000;
  7363. else if (!IS_GEN2(dev))
  7364. return 96000;
  7365. else
  7366. return 48000;
  7367. }
  7368. /* Returns the clock of the currently programmed mode of the given pipe. */
  7369. static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
  7370. struct intel_crtc_config *pipe_config)
  7371. {
  7372. struct drm_device *dev = crtc->base.dev;
  7373. struct drm_i915_private *dev_priv = dev->dev_private;
  7374. int pipe = pipe_config->cpu_transcoder;
  7375. u32 dpll = pipe_config->dpll_hw_state.dpll;
  7376. u32 fp;
  7377. intel_clock_t clock;
  7378. int refclk = i9xx_pll_refclk(dev, pipe_config);
  7379. if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
  7380. fp = pipe_config->dpll_hw_state.fp0;
  7381. else
  7382. fp = pipe_config->dpll_hw_state.fp1;
  7383. clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
  7384. if (IS_PINEVIEW(dev)) {
  7385. clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
  7386. clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
  7387. } else {
  7388. clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
  7389. clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
  7390. }
  7391. if (!IS_GEN2(dev)) {
  7392. if (IS_PINEVIEW(dev))
  7393. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
  7394. DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
  7395. else
  7396. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
  7397. DPLL_FPA01_P1_POST_DIV_SHIFT);
  7398. switch (dpll & DPLL_MODE_MASK) {
  7399. case DPLLB_MODE_DAC_SERIAL:
  7400. clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
  7401. 5 : 10;
  7402. break;
  7403. case DPLLB_MODE_LVDS:
  7404. clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
  7405. 7 : 14;
  7406. break;
  7407. default:
  7408. DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
  7409. "mode\n", (int)(dpll & DPLL_MODE_MASK));
  7410. return;
  7411. }
  7412. if (IS_PINEVIEW(dev))
  7413. pineview_clock(refclk, &clock);
  7414. else
  7415. i9xx_clock(refclk, &clock);
  7416. } else {
  7417. u32 lvds = IS_I830(dev) ? 0 : I915_READ(LVDS);
  7418. bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN);
  7419. if (is_lvds) {
  7420. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
  7421. DPLL_FPA01_P1_POST_DIV_SHIFT);
  7422. if (lvds & LVDS_CLKB_POWER_UP)
  7423. clock.p2 = 7;
  7424. else
  7425. clock.p2 = 14;
  7426. } else {
  7427. if (dpll & PLL_P1_DIVIDE_BY_TWO)
  7428. clock.p1 = 2;
  7429. else {
  7430. clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
  7431. DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
  7432. }
  7433. if (dpll & PLL_P2_DIVIDE_BY_4)
  7434. clock.p2 = 4;
  7435. else
  7436. clock.p2 = 2;
  7437. }
  7438. i9xx_clock(refclk, &clock);
  7439. }
  7440. /*
  7441. * This value includes pixel_multiplier. We will use
  7442. * port_clock to compute adjusted_mode.crtc_clock in the
  7443. * encoder's get_config() function.
  7444. */
  7445. pipe_config->port_clock = clock.dot;
  7446. }
  7447. int intel_dotclock_calculate(int link_freq,
  7448. const struct intel_link_m_n *m_n)
  7449. {
  7450. /*
  7451. * The calculation for the data clock is:
  7452. * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
  7453. * But we want to avoid losing precison if possible, so:
  7454. * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
  7455. *
  7456. * and the link clock is simpler:
  7457. * link_clock = (m * link_clock) / n
  7458. */
  7459. if (!m_n->link_n)
  7460. return 0;
  7461. return div_u64((u64)m_n->link_m * link_freq, m_n->link_n);
  7462. }
  7463. static void ironlake_pch_clock_get(struct intel_crtc *crtc,
  7464. struct intel_crtc_config *pipe_config)
  7465. {
  7466. struct drm_device *dev = crtc->base.dev;
  7467. /* read out port_clock from the DPLL */
  7468. i9xx_crtc_clock_get(crtc, pipe_config);
  7469. /*
  7470. * This value does not include pixel_multiplier.
  7471. * We will check that port_clock and adjusted_mode.crtc_clock
  7472. * agree once we know their relationship in the encoder's
  7473. * get_config() function.
  7474. */
  7475. pipe_config->adjusted_mode.crtc_clock =
  7476. intel_dotclock_calculate(intel_fdi_link_freq(dev) * 10000,
  7477. &pipe_config->fdi_m_n);
  7478. }
  7479. /** Returns the currently programmed mode of the given pipe. */
  7480. struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev,
  7481. struct drm_crtc *crtc)
  7482. {
  7483. struct drm_i915_private *dev_priv = dev->dev_private;
  7484. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7485. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  7486. struct drm_display_mode *mode;
  7487. struct intel_crtc_config pipe_config;
  7488. int htot = I915_READ(HTOTAL(cpu_transcoder));
  7489. int hsync = I915_READ(HSYNC(cpu_transcoder));
  7490. int vtot = I915_READ(VTOTAL(cpu_transcoder));
  7491. int vsync = I915_READ(VSYNC(cpu_transcoder));
  7492. enum pipe pipe = intel_crtc->pipe;
  7493. mode = kzalloc(sizeof(*mode), GFP_KERNEL);
  7494. if (!mode)
  7495. return NULL;
  7496. /*
  7497. * Construct a pipe_config sufficient for getting the clock info
  7498. * back out of crtc_clock_get.
  7499. *
  7500. * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need
  7501. * to use a real value here instead.
  7502. */
  7503. pipe_config.cpu_transcoder = (enum transcoder) pipe;
  7504. pipe_config.pixel_multiplier = 1;
  7505. pipe_config.dpll_hw_state.dpll = I915_READ(DPLL(pipe));
  7506. pipe_config.dpll_hw_state.fp0 = I915_READ(FP0(pipe));
  7507. pipe_config.dpll_hw_state.fp1 = I915_READ(FP1(pipe));
  7508. i9xx_crtc_clock_get(intel_crtc, &pipe_config);
  7509. mode->clock = pipe_config.port_clock / pipe_config.pixel_multiplier;
  7510. mode->hdisplay = (htot & 0xffff) + 1;
  7511. mode->htotal = ((htot & 0xffff0000) >> 16) + 1;
  7512. mode->hsync_start = (hsync & 0xffff) + 1;
  7513. mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1;
  7514. mode->vdisplay = (vtot & 0xffff) + 1;
  7515. mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1;
  7516. mode->vsync_start = (vsync & 0xffff) + 1;
  7517. mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1;
  7518. drm_mode_set_name(mode);
  7519. return mode;
  7520. }
  7521. static void intel_increase_pllclock(struct drm_device *dev,
  7522. enum pipe pipe)
  7523. {
  7524. struct drm_i915_private *dev_priv = dev->dev_private;
  7525. int dpll_reg = DPLL(pipe);
  7526. int dpll;
  7527. if (!HAS_GMCH_DISPLAY(dev))
  7528. return;
  7529. if (!dev_priv->lvds_downclock_avail)
  7530. return;
  7531. dpll = I915_READ(dpll_reg);
  7532. if (!HAS_PIPE_CXSR(dev) && (dpll & DISPLAY_RATE_SELECT_FPA1)) {
  7533. DRM_DEBUG_DRIVER("upclocking LVDS\n");
  7534. assert_panel_unlocked(dev_priv, pipe);
  7535. dpll &= ~DISPLAY_RATE_SELECT_FPA1;
  7536. I915_WRITE(dpll_reg, dpll);
  7537. intel_wait_for_vblank(dev, pipe);
  7538. dpll = I915_READ(dpll_reg);
  7539. if (dpll & DISPLAY_RATE_SELECT_FPA1)
  7540. DRM_DEBUG_DRIVER("failed to upclock LVDS!\n");
  7541. }
  7542. }
  7543. static void intel_decrease_pllclock(struct drm_crtc *crtc)
  7544. {
  7545. struct drm_device *dev = crtc->dev;
  7546. struct drm_i915_private *dev_priv = dev->dev_private;
  7547. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7548. if (!HAS_GMCH_DISPLAY(dev))
  7549. return;
  7550. if (!dev_priv->lvds_downclock_avail)
  7551. return;
  7552. /*
  7553. * Since this is called by a timer, we should never get here in
  7554. * the manual case.
  7555. */
  7556. if (!HAS_PIPE_CXSR(dev) && intel_crtc->lowfreq_avail) {
  7557. int pipe = intel_crtc->pipe;
  7558. int dpll_reg = DPLL(pipe);
  7559. int dpll;
  7560. DRM_DEBUG_DRIVER("downclocking LVDS\n");
  7561. assert_panel_unlocked(dev_priv, pipe);
  7562. dpll = I915_READ(dpll_reg);
  7563. dpll |= DISPLAY_RATE_SELECT_FPA1;
  7564. I915_WRITE(dpll_reg, dpll);
  7565. intel_wait_for_vblank(dev, pipe);
  7566. dpll = I915_READ(dpll_reg);
  7567. if (!(dpll & DISPLAY_RATE_SELECT_FPA1))
  7568. DRM_DEBUG_DRIVER("failed to downclock LVDS!\n");
  7569. }
  7570. }
  7571. void intel_mark_busy(struct drm_device *dev)
  7572. {
  7573. struct drm_i915_private *dev_priv = dev->dev_private;
  7574. if (dev_priv->mm.busy)
  7575. return;
  7576. intel_runtime_pm_get(dev_priv);
  7577. i915_update_gfx_val(dev_priv);
  7578. dev_priv->mm.busy = true;
  7579. }
  7580. void intel_mark_idle(struct drm_device *dev)
  7581. {
  7582. struct drm_i915_private *dev_priv = dev->dev_private;
  7583. struct drm_crtc *crtc;
  7584. if (!dev_priv->mm.busy)
  7585. return;
  7586. dev_priv->mm.busy = false;
  7587. if (!i915.powersave)
  7588. goto out;
  7589. for_each_crtc(dev, crtc) {
  7590. if (!crtc->primary->fb)
  7591. continue;
  7592. intel_decrease_pllclock(crtc);
  7593. }
  7594. if (INTEL_INFO(dev)->gen >= 6)
  7595. gen6_rps_idle(dev->dev_private);
  7596. out:
  7597. intel_runtime_pm_put(dev_priv);
  7598. }
  7599. /**
  7600. * intel_mark_fb_busy - mark given planes as busy
  7601. * @dev: DRM device
  7602. * @frontbuffer_bits: bits for the affected planes
  7603. * @ring: optional ring for asynchronous commands
  7604. *
  7605. * This function gets called every time the screen contents change. It can be
  7606. * used to keep e.g. the update rate at the nominal refresh rate with DRRS.
  7607. */
  7608. static void intel_mark_fb_busy(struct drm_device *dev,
  7609. unsigned frontbuffer_bits,
  7610. struct intel_engine_cs *ring)
  7611. {
  7612. struct drm_i915_private *dev_priv = dev->dev_private;
  7613. enum pipe pipe;
  7614. if (!i915.powersave)
  7615. return;
  7616. for_each_pipe(dev_priv, pipe) {
  7617. if (!(frontbuffer_bits & INTEL_FRONTBUFFER_ALL_MASK(pipe)))
  7618. continue;
  7619. intel_increase_pllclock(dev, pipe);
  7620. if (ring && intel_fbc_enabled(dev))
  7621. ring->fbc_dirty = true;
  7622. }
  7623. }
  7624. /**
  7625. * intel_fb_obj_invalidate - invalidate frontbuffer object
  7626. * @obj: GEM object to invalidate
  7627. * @ring: set for asynchronous rendering
  7628. *
  7629. * This function gets called every time rendering on the given object starts and
  7630. * frontbuffer caching (fbc, low refresh rate for DRRS, panel self refresh) must
  7631. * be invalidated. If @ring is non-NULL any subsequent invalidation will be delayed
  7632. * until the rendering completes or a flip on this frontbuffer plane is
  7633. * scheduled.
  7634. */
  7635. void intel_fb_obj_invalidate(struct drm_i915_gem_object *obj,
  7636. struct intel_engine_cs *ring)
  7637. {
  7638. struct drm_device *dev = obj->base.dev;
  7639. struct drm_i915_private *dev_priv = dev->dev_private;
  7640. WARN_ON(!mutex_is_locked(&dev->struct_mutex));
  7641. if (!obj->frontbuffer_bits)
  7642. return;
  7643. if (ring) {
  7644. mutex_lock(&dev_priv->fb_tracking.lock);
  7645. dev_priv->fb_tracking.busy_bits
  7646. |= obj->frontbuffer_bits;
  7647. dev_priv->fb_tracking.flip_bits
  7648. &= ~obj->frontbuffer_bits;
  7649. mutex_unlock(&dev_priv->fb_tracking.lock);
  7650. }
  7651. intel_mark_fb_busy(dev, obj->frontbuffer_bits, ring);
  7652. intel_edp_psr_invalidate(dev, obj->frontbuffer_bits);
  7653. }
  7654. /**
  7655. * intel_frontbuffer_flush - flush frontbuffer
  7656. * @dev: DRM device
  7657. * @frontbuffer_bits: frontbuffer plane tracking bits
  7658. *
  7659. * This function gets called every time rendering on the given planes has
  7660. * completed and frontbuffer caching can be started again. Flushes will get
  7661. * delayed if they're blocked by some oustanding asynchronous rendering.
  7662. *
  7663. * Can be called without any locks held.
  7664. */
  7665. void intel_frontbuffer_flush(struct drm_device *dev,
  7666. unsigned frontbuffer_bits)
  7667. {
  7668. struct drm_i915_private *dev_priv = dev->dev_private;
  7669. /* Delay flushing when rings are still busy.*/
  7670. mutex_lock(&dev_priv->fb_tracking.lock);
  7671. frontbuffer_bits &= ~dev_priv->fb_tracking.busy_bits;
  7672. mutex_unlock(&dev_priv->fb_tracking.lock);
  7673. intel_mark_fb_busy(dev, frontbuffer_bits, NULL);
  7674. intel_edp_psr_flush(dev, frontbuffer_bits);
  7675. /*
  7676. * FIXME: Unconditional fbc flushing here is a rather gross hack and
  7677. * needs to be reworked into a proper frontbuffer tracking scheme like
  7678. * psr employs.
  7679. */
  7680. if (IS_BROADWELL(dev))
  7681. gen8_fbc_sw_flush(dev, FBC_REND_CACHE_CLEAN);
  7682. }
  7683. /**
  7684. * intel_fb_obj_flush - flush frontbuffer object
  7685. * @obj: GEM object to flush
  7686. * @retire: set when retiring asynchronous rendering
  7687. *
  7688. * This function gets called every time rendering on the given object has
  7689. * completed and frontbuffer caching can be started again. If @retire is true
  7690. * then any delayed flushes will be unblocked.
  7691. */
  7692. void intel_fb_obj_flush(struct drm_i915_gem_object *obj,
  7693. bool retire)
  7694. {
  7695. struct drm_device *dev = obj->base.dev;
  7696. struct drm_i915_private *dev_priv = dev->dev_private;
  7697. unsigned frontbuffer_bits;
  7698. WARN_ON(!mutex_is_locked(&dev->struct_mutex));
  7699. if (!obj->frontbuffer_bits)
  7700. return;
  7701. frontbuffer_bits = obj->frontbuffer_bits;
  7702. if (retire) {
  7703. mutex_lock(&dev_priv->fb_tracking.lock);
  7704. /* Filter out new bits since rendering started. */
  7705. frontbuffer_bits &= dev_priv->fb_tracking.busy_bits;
  7706. dev_priv->fb_tracking.busy_bits &= ~frontbuffer_bits;
  7707. mutex_unlock(&dev_priv->fb_tracking.lock);
  7708. }
  7709. intel_frontbuffer_flush(dev, frontbuffer_bits);
  7710. }
  7711. /**
  7712. * intel_frontbuffer_flip_prepare - prepare asnychronous frontbuffer flip
  7713. * @dev: DRM device
  7714. * @frontbuffer_bits: frontbuffer plane tracking bits
  7715. *
  7716. * This function gets called after scheduling a flip on @obj. The actual
  7717. * frontbuffer flushing will be delayed until completion is signalled with
  7718. * intel_frontbuffer_flip_complete. If an invalidate happens in between this
  7719. * flush will be cancelled.
  7720. *
  7721. * Can be called without any locks held.
  7722. */
  7723. void intel_frontbuffer_flip_prepare(struct drm_device *dev,
  7724. unsigned frontbuffer_bits)
  7725. {
  7726. struct drm_i915_private *dev_priv = dev->dev_private;
  7727. mutex_lock(&dev_priv->fb_tracking.lock);
  7728. dev_priv->fb_tracking.flip_bits
  7729. |= frontbuffer_bits;
  7730. mutex_unlock(&dev_priv->fb_tracking.lock);
  7731. }
  7732. /**
  7733. * intel_frontbuffer_flip_complete - complete asynchronous frontbuffer flush
  7734. * @dev: DRM device
  7735. * @frontbuffer_bits: frontbuffer plane tracking bits
  7736. *
  7737. * This function gets called after the flip has been latched and will complete
  7738. * on the next vblank. It will execute the fush if it hasn't been cancalled yet.
  7739. *
  7740. * Can be called without any locks held.
  7741. */
  7742. void intel_frontbuffer_flip_complete(struct drm_device *dev,
  7743. unsigned frontbuffer_bits)
  7744. {
  7745. struct drm_i915_private *dev_priv = dev->dev_private;
  7746. mutex_lock(&dev_priv->fb_tracking.lock);
  7747. /* Mask any cancelled flips. */
  7748. frontbuffer_bits &= dev_priv->fb_tracking.flip_bits;
  7749. dev_priv->fb_tracking.flip_bits &= ~frontbuffer_bits;
  7750. mutex_unlock(&dev_priv->fb_tracking.lock);
  7751. intel_frontbuffer_flush(dev, frontbuffer_bits);
  7752. }
  7753. static void intel_crtc_destroy(struct drm_crtc *crtc)
  7754. {
  7755. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7756. struct drm_device *dev = crtc->dev;
  7757. struct intel_unpin_work *work;
  7758. unsigned long flags;
  7759. spin_lock_irqsave(&dev->event_lock, flags);
  7760. work = intel_crtc->unpin_work;
  7761. intel_crtc->unpin_work = NULL;
  7762. spin_unlock_irqrestore(&dev->event_lock, flags);
  7763. if (work) {
  7764. cancel_work_sync(&work->work);
  7765. kfree(work);
  7766. }
  7767. drm_crtc_cleanup(crtc);
  7768. kfree(intel_crtc);
  7769. }
  7770. static void intel_unpin_work_fn(struct work_struct *__work)
  7771. {
  7772. struct intel_unpin_work *work =
  7773. container_of(__work, struct intel_unpin_work, work);
  7774. struct drm_device *dev = work->crtc->dev;
  7775. enum pipe pipe = to_intel_crtc(work->crtc)->pipe;
  7776. mutex_lock(&dev->struct_mutex);
  7777. intel_unpin_fb_obj(work->old_fb_obj);
  7778. drm_gem_object_unreference(&work->pending_flip_obj->base);
  7779. drm_gem_object_unreference(&work->old_fb_obj->base);
  7780. intel_update_fbc(dev);
  7781. mutex_unlock(&dev->struct_mutex);
  7782. intel_frontbuffer_flip_complete(dev, INTEL_FRONTBUFFER_PRIMARY(pipe));
  7783. BUG_ON(atomic_read(&to_intel_crtc(work->crtc)->unpin_work_count) == 0);
  7784. atomic_dec(&to_intel_crtc(work->crtc)->unpin_work_count);
  7785. kfree(work);
  7786. }
  7787. static void do_intel_finish_page_flip(struct drm_device *dev,
  7788. struct drm_crtc *crtc)
  7789. {
  7790. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7791. struct intel_unpin_work *work;
  7792. unsigned long flags;
  7793. /* Ignore early vblank irqs */
  7794. if (intel_crtc == NULL)
  7795. return;
  7796. spin_lock_irqsave(&dev->event_lock, flags);
  7797. work = intel_crtc->unpin_work;
  7798. /* Ensure we don't miss a work->pending update ... */
  7799. smp_rmb();
  7800. if (work == NULL || atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) {
  7801. spin_unlock_irqrestore(&dev->event_lock, flags);
  7802. return;
  7803. }
  7804. page_flip_completed(intel_crtc);
  7805. spin_unlock_irqrestore(&dev->event_lock, flags);
  7806. }
  7807. void intel_finish_page_flip(struct drm_device *dev, int pipe)
  7808. {
  7809. struct drm_i915_private *dev_priv = dev->dev_private;
  7810. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  7811. do_intel_finish_page_flip(dev, crtc);
  7812. }
  7813. void intel_finish_page_flip_plane(struct drm_device *dev, int plane)
  7814. {
  7815. struct drm_i915_private *dev_priv = dev->dev_private;
  7816. struct drm_crtc *crtc = dev_priv->plane_to_crtc_mapping[plane];
  7817. do_intel_finish_page_flip(dev, crtc);
  7818. }
  7819. /* Is 'a' after or equal to 'b'? */
  7820. static bool g4x_flip_count_after_eq(u32 a, u32 b)
  7821. {
  7822. return !((a - b) & 0x80000000);
  7823. }
  7824. static bool page_flip_finished(struct intel_crtc *crtc)
  7825. {
  7826. struct drm_device *dev = crtc->base.dev;
  7827. struct drm_i915_private *dev_priv = dev->dev_private;
  7828. /*
  7829. * The relevant registers doen't exist on pre-ctg.
  7830. * As the flip done interrupt doesn't trigger for mmio
  7831. * flips on gmch platforms, a flip count check isn't
  7832. * really needed there. But since ctg has the registers,
  7833. * include it in the check anyway.
  7834. */
  7835. if (INTEL_INFO(dev)->gen < 5 && !IS_G4X(dev))
  7836. return true;
  7837. /*
  7838. * A DSPSURFLIVE check isn't enough in case the mmio and CS flips
  7839. * used the same base address. In that case the mmio flip might
  7840. * have completed, but the CS hasn't even executed the flip yet.
  7841. *
  7842. * A flip count check isn't enough as the CS might have updated
  7843. * the base address just after start of vblank, but before we
  7844. * managed to process the interrupt. This means we'd complete the
  7845. * CS flip too soon.
  7846. *
  7847. * Combining both checks should get us a good enough result. It may
  7848. * still happen that the CS flip has been executed, but has not
  7849. * yet actually completed. But in case the base address is the same
  7850. * anyway, we don't really care.
  7851. */
  7852. return (I915_READ(DSPSURFLIVE(crtc->plane)) & ~0xfff) ==
  7853. crtc->unpin_work->gtt_offset &&
  7854. g4x_flip_count_after_eq(I915_READ(PIPE_FLIPCOUNT_GM45(crtc->pipe)),
  7855. crtc->unpin_work->flip_count);
  7856. }
  7857. void intel_prepare_page_flip(struct drm_device *dev, int plane)
  7858. {
  7859. struct drm_i915_private *dev_priv = dev->dev_private;
  7860. struct intel_crtc *intel_crtc =
  7861. to_intel_crtc(dev_priv->plane_to_crtc_mapping[plane]);
  7862. unsigned long flags;
  7863. /* NB: An MMIO update of the plane base pointer will also
  7864. * generate a page-flip completion irq, i.e. every modeset
  7865. * is also accompanied by a spurious intel_prepare_page_flip().
  7866. */
  7867. spin_lock_irqsave(&dev->event_lock, flags);
  7868. if (intel_crtc->unpin_work && page_flip_finished(intel_crtc))
  7869. atomic_inc_not_zero(&intel_crtc->unpin_work->pending);
  7870. spin_unlock_irqrestore(&dev->event_lock, flags);
  7871. }
  7872. static inline void intel_mark_page_flip_active(struct intel_crtc *intel_crtc)
  7873. {
  7874. /* Ensure that the work item is consistent when activating it ... */
  7875. smp_wmb();
  7876. atomic_set(&intel_crtc->unpin_work->pending, INTEL_FLIP_PENDING);
  7877. /* and that it is marked active as soon as the irq could fire. */
  7878. smp_wmb();
  7879. }
  7880. static int intel_gen2_queue_flip(struct drm_device *dev,
  7881. struct drm_crtc *crtc,
  7882. struct drm_framebuffer *fb,
  7883. struct drm_i915_gem_object *obj,
  7884. struct intel_engine_cs *ring,
  7885. uint32_t flags)
  7886. {
  7887. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7888. u32 flip_mask;
  7889. int ret;
  7890. ret = intel_ring_begin(ring, 6);
  7891. if (ret)
  7892. return ret;
  7893. /* Can't queue multiple flips, so wait for the previous
  7894. * one to finish before executing the next.
  7895. */
  7896. if (intel_crtc->plane)
  7897. flip_mask = MI_WAIT_FOR_PLANE_B_FLIP;
  7898. else
  7899. flip_mask = MI_WAIT_FOR_PLANE_A_FLIP;
  7900. intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask);
  7901. intel_ring_emit(ring, MI_NOOP);
  7902. intel_ring_emit(ring, MI_DISPLAY_FLIP |
  7903. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  7904. intel_ring_emit(ring, fb->pitches[0]);
  7905. intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset);
  7906. intel_ring_emit(ring, 0); /* aux display base address, unused */
  7907. intel_mark_page_flip_active(intel_crtc);
  7908. __intel_ring_advance(ring);
  7909. return 0;
  7910. }
  7911. static int intel_gen3_queue_flip(struct drm_device *dev,
  7912. struct drm_crtc *crtc,
  7913. struct drm_framebuffer *fb,
  7914. struct drm_i915_gem_object *obj,
  7915. struct intel_engine_cs *ring,
  7916. uint32_t flags)
  7917. {
  7918. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7919. u32 flip_mask;
  7920. int ret;
  7921. ret = intel_ring_begin(ring, 6);
  7922. if (ret)
  7923. return ret;
  7924. if (intel_crtc->plane)
  7925. flip_mask = MI_WAIT_FOR_PLANE_B_FLIP;
  7926. else
  7927. flip_mask = MI_WAIT_FOR_PLANE_A_FLIP;
  7928. intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask);
  7929. intel_ring_emit(ring, MI_NOOP);
  7930. intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 |
  7931. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  7932. intel_ring_emit(ring, fb->pitches[0]);
  7933. intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset);
  7934. intel_ring_emit(ring, MI_NOOP);
  7935. intel_mark_page_flip_active(intel_crtc);
  7936. __intel_ring_advance(ring);
  7937. return 0;
  7938. }
  7939. static int intel_gen4_queue_flip(struct drm_device *dev,
  7940. struct drm_crtc *crtc,
  7941. struct drm_framebuffer *fb,
  7942. struct drm_i915_gem_object *obj,
  7943. struct intel_engine_cs *ring,
  7944. uint32_t flags)
  7945. {
  7946. struct drm_i915_private *dev_priv = dev->dev_private;
  7947. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7948. uint32_t pf, pipesrc;
  7949. int ret;
  7950. ret = intel_ring_begin(ring, 4);
  7951. if (ret)
  7952. return ret;
  7953. /* i965+ uses the linear or tiled offsets from the
  7954. * Display Registers (which do not change across a page-flip)
  7955. * so we need only reprogram the base address.
  7956. */
  7957. intel_ring_emit(ring, MI_DISPLAY_FLIP |
  7958. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  7959. intel_ring_emit(ring, fb->pitches[0]);
  7960. intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset |
  7961. obj->tiling_mode);
  7962. /* XXX Enabling the panel-fitter across page-flip is so far
  7963. * untested on non-native modes, so ignore it for now.
  7964. * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE;
  7965. */
  7966. pf = 0;
  7967. pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
  7968. intel_ring_emit(ring, pf | pipesrc);
  7969. intel_mark_page_flip_active(intel_crtc);
  7970. __intel_ring_advance(ring);
  7971. return 0;
  7972. }
  7973. static int intel_gen6_queue_flip(struct drm_device *dev,
  7974. struct drm_crtc *crtc,
  7975. struct drm_framebuffer *fb,
  7976. struct drm_i915_gem_object *obj,
  7977. struct intel_engine_cs *ring,
  7978. uint32_t flags)
  7979. {
  7980. struct drm_i915_private *dev_priv = dev->dev_private;
  7981. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7982. uint32_t pf, pipesrc;
  7983. int ret;
  7984. ret = intel_ring_begin(ring, 4);
  7985. if (ret)
  7986. return ret;
  7987. intel_ring_emit(ring, MI_DISPLAY_FLIP |
  7988. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  7989. intel_ring_emit(ring, fb->pitches[0] | obj->tiling_mode);
  7990. intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset);
  7991. /* Contrary to the suggestions in the documentation,
  7992. * "Enable Panel Fitter" does not seem to be required when page
  7993. * flipping with a non-native mode, and worse causes a normal
  7994. * modeset to fail.
  7995. * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE;
  7996. */
  7997. pf = 0;
  7998. pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
  7999. intel_ring_emit(ring, pf | pipesrc);
  8000. intel_mark_page_flip_active(intel_crtc);
  8001. __intel_ring_advance(ring);
  8002. return 0;
  8003. }
  8004. static int intel_gen7_queue_flip(struct drm_device *dev,
  8005. struct drm_crtc *crtc,
  8006. struct drm_framebuffer *fb,
  8007. struct drm_i915_gem_object *obj,
  8008. struct intel_engine_cs *ring,
  8009. uint32_t flags)
  8010. {
  8011. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  8012. uint32_t plane_bit = 0;
  8013. int len, ret;
  8014. switch (intel_crtc->plane) {
  8015. case PLANE_A:
  8016. plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_A;
  8017. break;
  8018. case PLANE_B:
  8019. plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_B;
  8020. break;
  8021. case PLANE_C:
  8022. plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_C;
  8023. break;
  8024. default:
  8025. WARN_ONCE(1, "unknown plane in flip command\n");
  8026. return -ENODEV;
  8027. }
  8028. len = 4;
  8029. if (ring->id == RCS) {
  8030. len += 6;
  8031. /*
  8032. * On Gen 8, SRM is now taking an extra dword to accommodate
  8033. * 48bits addresses, and we need a NOOP for the batch size to
  8034. * stay even.
  8035. */
  8036. if (IS_GEN8(dev))
  8037. len += 2;
  8038. }
  8039. /*
  8040. * BSpec MI_DISPLAY_FLIP for IVB:
  8041. * "The full packet must be contained within the same cache line."
  8042. *
  8043. * Currently the LRI+SRM+MI_DISPLAY_FLIP all fit within the same
  8044. * cacheline, if we ever start emitting more commands before
  8045. * the MI_DISPLAY_FLIP we may need to first emit everything else,
  8046. * then do the cacheline alignment, and finally emit the
  8047. * MI_DISPLAY_FLIP.
  8048. */
  8049. ret = intel_ring_cacheline_align(ring);
  8050. if (ret)
  8051. return ret;
  8052. ret = intel_ring_begin(ring, len);
  8053. if (ret)
  8054. return ret;
  8055. /* Unmask the flip-done completion message. Note that the bspec says that
  8056. * we should do this for both the BCS and RCS, and that we must not unmask
  8057. * more than one flip event at any time (or ensure that one flip message
  8058. * can be sent by waiting for flip-done prior to queueing new flips).
  8059. * Experimentation says that BCS works despite DERRMR masking all
  8060. * flip-done completion events and that unmasking all planes at once
  8061. * for the RCS also doesn't appear to drop events. Setting the DERRMR
  8062. * to zero does lead to lockups within MI_DISPLAY_FLIP.
  8063. */
  8064. if (ring->id == RCS) {
  8065. intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1));
  8066. intel_ring_emit(ring, DERRMR);
  8067. intel_ring_emit(ring, ~(DERRMR_PIPEA_PRI_FLIP_DONE |
  8068. DERRMR_PIPEB_PRI_FLIP_DONE |
  8069. DERRMR_PIPEC_PRI_FLIP_DONE));
  8070. if (IS_GEN8(dev))
  8071. intel_ring_emit(ring, MI_STORE_REGISTER_MEM_GEN8(1) |
  8072. MI_SRM_LRM_GLOBAL_GTT);
  8073. else
  8074. intel_ring_emit(ring, MI_STORE_REGISTER_MEM(1) |
  8075. MI_SRM_LRM_GLOBAL_GTT);
  8076. intel_ring_emit(ring, DERRMR);
  8077. intel_ring_emit(ring, ring->scratch.gtt_offset + 256);
  8078. if (IS_GEN8(dev)) {
  8079. intel_ring_emit(ring, 0);
  8080. intel_ring_emit(ring, MI_NOOP);
  8081. }
  8082. }
  8083. intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | plane_bit);
  8084. intel_ring_emit(ring, (fb->pitches[0] | obj->tiling_mode));
  8085. intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset);
  8086. intel_ring_emit(ring, (MI_NOOP));
  8087. intel_mark_page_flip_active(intel_crtc);
  8088. __intel_ring_advance(ring);
  8089. return 0;
  8090. }
  8091. static bool use_mmio_flip(struct intel_engine_cs *ring,
  8092. struct drm_i915_gem_object *obj)
  8093. {
  8094. /*
  8095. * This is not being used for older platforms, because
  8096. * non-availability of flip done interrupt forces us to use
  8097. * CS flips. Older platforms derive flip done using some clever
  8098. * tricks involving the flip_pending status bits and vblank irqs.
  8099. * So using MMIO flips there would disrupt this mechanism.
  8100. */
  8101. if (ring == NULL)
  8102. return true;
  8103. if (INTEL_INFO(ring->dev)->gen < 5)
  8104. return false;
  8105. if (i915.use_mmio_flip < 0)
  8106. return false;
  8107. else if (i915.use_mmio_flip > 0)
  8108. return true;
  8109. else if (i915.enable_execlists)
  8110. return true;
  8111. else
  8112. return ring != obj->ring;
  8113. }
  8114. static void intel_do_mmio_flip(struct intel_crtc *intel_crtc)
  8115. {
  8116. struct drm_device *dev = intel_crtc->base.dev;
  8117. struct drm_i915_private *dev_priv = dev->dev_private;
  8118. struct intel_framebuffer *intel_fb =
  8119. to_intel_framebuffer(intel_crtc->base.primary->fb);
  8120. struct drm_i915_gem_object *obj = intel_fb->obj;
  8121. u32 dspcntr;
  8122. u32 reg;
  8123. intel_mark_page_flip_active(intel_crtc);
  8124. reg = DSPCNTR(intel_crtc->plane);
  8125. dspcntr = I915_READ(reg);
  8126. if (INTEL_INFO(dev)->gen >= 4) {
  8127. if (obj->tiling_mode != I915_TILING_NONE)
  8128. dspcntr |= DISPPLANE_TILED;
  8129. else
  8130. dspcntr &= ~DISPPLANE_TILED;
  8131. }
  8132. I915_WRITE(reg, dspcntr);
  8133. I915_WRITE(DSPSURF(intel_crtc->plane),
  8134. intel_crtc->unpin_work->gtt_offset);
  8135. POSTING_READ(DSPSURF(intel_crtc->plane));
  8136. }
  8137. static int intel_postpone_flip(struct drm_i915_gem_object *obj)
  8138. {
  8139. struct intel_engine_cs *ring;
  8140. int ret;
  8141. lockdep_assert_held(&obj->base.dev->struct_mutex);
  8142. if (!obj->last_write_seqno)
  8143. return 0;
  8144. ring = obj->ring;
  8145. if (i915_seqno_passed(ring->get_seqno(ring, true),
  8146. obj->last_write_seqno))
  8147. return 0;
  8148. ret = i915_gem_check_olr(ring, obj->last_write_seqno);
  8149. if (ret)
  8150. return ret;
  8151. if (WARN_ON(!ring->irq_get(ring)))
  8152. return 0;
  8153. return 1;
  8154. }
  8155. void intel_notify_mmio_flip(struct intel_engine_cs *ring)
  8156. {
  8157. struct drm_i915_private *dev_priv = to_i915(ring->dev);
  8158. struct intel_crtc *intel_crtc;
  8159. unsigned long irq_flags;
  8160. u32 seqno;
  8161. seqno = ring->get_seqno(ring, false);
  8162. spin_lock_irqsave(&dev_priv->mmio_flip_lock, irq_flags);
  8163. for_each_intel_crtc(ring->dev, intel_crtc) {
  8164. struct intel_mmio_flip *mmio_flip;
  8165. mmio_flip = &intel_crtc->mmio_flip;
  8166. if (mmio_flip->seqno == 0)
  8167. continue;
  8168. if (ring->id != mmio_flip->ring_id)
  8169. continue;
  8170. if (i915_seqno_passed(seqno, mmio_flip->seqno)) {
  8171. intel_do_mmio_flip(intel_crtc);
  8172. mmio_flip->seqno = 0;
  8173. ring->irq_put(ring);
  8174. }
  8175. }
  8176. spin_unlock_irqrestore(&dev_priv->mmio_flip_lock, irq_flags);
  8177. }
  8178. static int intel_queue_mmio_flip(struct drm_device *dev,
  8179. struct drm_crtc *crtc,
  8180. struct drm_framebuffer *fb,
  8181. struct drm_i915_gem_object *obj,
  8182. struct intel_engine_cs *ring,
  8183. uint32_t flags)
  8184. {
  8185. struct drm_i915_private *dev_priv = dev->dev_private;
  8186. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  8187. unsigned long irq_flags;
  8188. int ret;
  8189. if (WARN_ON(intel_crtc->mmio_flip.seqno))
  8190. return -EBUSY;
  8191. ret = intel_postpone_flip(obj);
  8192. if (ret < 0)
  8193. return ret;
  8194. if (ret == 0) {
  8195. intel_do_mmio_flip(intel_crtc);
  8196. return 0;
  8197. }
  8198. spin_lock_irqsave(&dev_priv->mmio_flip_lock, irq_flags);
  8199. intel_crtc->mmio_flip.seqno = obj->last_write_seqno;
  8200. intel_crtc->mmio_flip.ring_id = obj->ring->id;
  8201. spin_unlock_irqrestore(&dev_priv->mmio_flip_lock, irq_flags);
  8202. /*
  8203. * Double check to catch cases where irq fired before
  8204. * mmio flip data was ready
  8205. */
  8206. intel_notify_mmio_flip(obj->ring);
  8207. return 0;
  8208. }
  8209. static int intel_default_queue_flip(struct drm_device *dev,
  8210. struct drm_crtc *crtc,
  8211. struct drm_framebuffer *fb,
  8212. struct drm_i915_gem_object *obj,
  8213. struct intel_engine_cs *ring,
  8214. uint32_t flags)
  8215. {
  8216. return -ENODEV;
  8217. }
  8218. static bool __intel_pageflip_stall_check(struct drm_device *dev,
  8219. struct drm_crtc *crtc)
  8220. {
  8221. struct drm_i915_private *dev_priv = dev->dev_private;
  8222. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  8223. struct intel_unpin_work *work = intel_crtc->unpin_work;
  8224. u32 addr;
  8225. if (atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE)
  8226. return true;
  8227. if (!work->enable_stall_check)
  8228. return false;
  8229. if (work->flip_ready_vblank == 0) {
  8230. if (work->flip_queued_ring &&
  8231. !i915_seqno_passed(work->flip_queued_ring->get_seqno(work->flip_queued_ring, true),
  8232. work->flip_queued_seqno))
  8233. return false;
  8234. work->flip_ready_vblank = drm_vblank_count(dev, intel_crtc->pipe);
  8235. }
  8236. if (drm_vblank_count(dev, intel_crtc->pipe) - work->flip_ready_vblank < 3)
  8237. return false;
  8238. /* Potential stall - if we see that the flip has happened,
  8239. * assume a missed interrupt. */
  8240. if (INTEL_INFO(dev)->gen >= 4)
  8241. addr = I915_HI_DISPBASE(I915_READ(DSPSURF(intel_crtc->plane)));
  8242. else
  8243. addr = I915_READ(DSPADDR(intel_crtc->plane));
  8244. /* There is a potential issue here with a false positive after a flip
  8245. * to the same address. We could address this by checking for a
  8246. * non-incrementing frame counter.
  8247. */
  8248. return addr == work->gtt_offset;
  8249. }
  8250. void intel_check_page_flip(struct drm_device *dev, int pipe)
  8251. {
  8252. struct drm_i915_private *dev_priv = dev->dev_private;
  8253. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  8254. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  8255. unsigned long flags;
  8256. if (crtc == NULL)
  8257. return;
  8258. spin_lock_irqsave(&dev->event_lock, flags);
  8259. if (intel_crtc->unpin_work && __intel_pageflip_stall_check(dev, crtc)) {
  8260. WARN_ONCE(1, "Kicking stuck page flip: queued at %d, now %d\n",
  8261. intel_crtc->unpin_work->flip_queued_vblank, drm_vblank_count(dev, pipe));
  8262. page_flip_completed(intel_crtc);
  8263. }
  8264. spin_unlock_irqrestore(&dev->event_lock, flags);
  8265. }
  8266. static int intel_crtc_page_flip(struct drm_crtc *crtc,
  8267. struct drm_framebuffer *fb,
  8268. struct drm_pending_vblank_event *event,
  8269. uint32_t page_flip_flags)
  8270. {
  8271. struct drm_device *dev = crtc->dev;
  8272. struct drm_i915_private *dev_priv = dev->dev_private;
  8273. struct drm_framebuffer *old_fb = crtc->primary->fb;
  8274. struct drm_i915_gem_object *obj = intel_fb_obj(fb);
  8275. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  8276. enum pipe pipe = intel_crtc->pipe;
  8277. struct intel_unpin_work *work;
  8278. struct intel_engine_cs *ring;
  8279. unsigned long flags;
  8280. int ret;
  8281. //trigger software GT busyness calculation
  8282. gen8_flip_interrupt(dev);
  8283. /*
  8284. * drm_mode_page_flip_ioctl() should already catch this, but double
  8285. * check to be safe. In the future we may enable pageflipping from
  8286. * a disabled primary plane.
  8287. */
  8288. if (WARN_ON(intel_fb_obj(old_fb) == NULL))
  8289. return -EBUSY;
  8290. /* Can't change pixel format via MI display flips. */
  8291. if (fb->pixel_format != crtc->primary->fb->pixel_format)
  8292. return -EINVAL;
  8293. /*
  8294. * TILEOFF/LINOFF registers can't be changed via MI display flips.
  8295. * Note that pitch changes could also affect these register.
  8296. */
  8297. if (INTEL_INFO(dev)->gen > 3 &&
  8298. (fb->offsets[0] != crtc->primary->fb->offsets[0] ||
  8299. fb->pitches[0] != crtc->primary->fb->pitches[0]))
  8300. return -EINVAL;
  8301. if (i915_terminally_wedged(&dev_priv->gpu_error))
  8302. goto out_hang;
  8303. work = kzalloc(sizeof(*work), GFP_KERNEL);
  8304. if (work == NULL)
  8305. return -ENOMEM;
  8306. work->event = event;
  8307. work->crtc = crtc;
  8308. work->old_fb_obj = intel_fb_obj(old_fb);
  8309. INIT_WORK(&work->work, intel_unpin_work_fn);
  8310. ret = drm_crtc_vblank_get(crtc);
  8311. if (ret)
  8312. goto free_work;
  8313. /* We borrow the event spin lock for protecting unpin_work */
  8314. spin_lock_irqsave(&dev->event_lock, flags);
  8315. if (intel_crtc->unpin_work) {
  8316. /* Before declaring the flip queue wedged, check if
  8317. * the hardware completed the operation behind our backs.
  8318. */
  8319. if (__intel_pageflip_stall_check(dev, crtc)) {
  8320. DRM_DEBUG_DRIVER("flip queue: previous flip completed, continuing\n");
  8321. page_flip_completed(intel_crtc);
  8322. } else {
  8323. DRM_DEBUG_DRIVER("flip queue: crtc already busy\n");
  8324. spin_unlock_irqrestore(&dev->event_lock, flags);
  8325. drm_crtc_vblank_put(crtc);
  8326. kfree(work);
  8327. return -EBUSY;
  8328. }
  8329. }
  8330. intel_crtc->unpin_work = work;
  8331. spin_unlock_irqrestore(&dev->event_lock, flags);
  8332. if (atomic_read(&intel_crtc->unpin_work_count) >= 2)
  8333. flush_workqueue(dev_priv->wq);
  8334. ret = i915_mutex_lock_interruptible(dev);
  8335. if (ret)
  8336. goto cleanup;
  8337. /* Reference the objects for the scheduled work. */
  8338. drm_gem_object_reference(&work->old_fb_obj->base);
  8339. drm_gem_object_reference(&obj->base);
  8340. crtc->primary->fb = fb;
  8341. work->pending_flip_obj = obj;
  8342. atomic_inc(&intel_crtc->unpin_work_count);
  8343. intel_crtc->reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter);
  8344. if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev))
  8345. work->flip_count = I915_READ(PIPE_FLIPCOUNT_GM45(pipe)) + 1;
  8346. if (IS_VALLEYVIEW(dev)) {
  8347. ring = &dev_priv->ring[BCS];
  8348. if (obj->tiling_mode != work->old_fb_obj->tiling_mode)
  8349. /* vlv: DISPLAY_FLIP fails to change tiling */
  8350. ring = NULL;
  8351. } else if (IS_IVYBRIDGE(dev)) {
  8352. ring = &dev_priv->ring[BCS];
  8353. } else if (INTEL_INFO(dev)->gen >= 7) {
  8354. ring = obj->ring;
  8355. if (ring == NULL || ring->id != RCS)
  8356. ring = &dev_priv->ring[BCS];
  8357. } else {
  8358. ring = &dev_priv->ring[RCS];
  8359. }
  8360. ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
  8361. if (ret)
  8362. goto cleanup_pending;
  8363. work->gtt_offset =
  8364. i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset;
  8365. if (use_mmio_flip(ring, obj)) {
  8366. ret = intel_queue_mmio_flip(dev, crtc, fb, obj, ring,
  8367. page_flip_flags);
  8368. if (ret)
  8369. goto cleanup_unpin;
  8370. work->flip_queued_seqno = obj->last_write_seqno;
  8371. work->flip_queued_ring = obj->ring;
  8372. } else {
  8373. ret = dev_priv->display.queue_flip(dev, crtc, fb, obj, ring,
  8374. page_flip_flags);
  8375. if (ret)
  8376. goto cleanup_unpin;
  8377. work->flip_queued_seqno = intel_ring_get_seqno(ring);
  8378. work->flip_queued_ring = ring;
  8379. }
  8380. work->flip_queued_vblank = drm_vblank_count(dev, intel_crtc->pipe);
  8381. work->enable_stall_check = true;
  8382. i915_gem_track_fb(work->old_fb_obj, obj,
  8383. INTEL_FRONTBUFFER_PRIMARY(pipe));
  8384. intel_disable_fbc(dev);
  8385. intel_frontbuffer_flip_prepare(dev, INTEL_FRONTBUFFER_PRIMARY(pipe));
  8386. mutex_unlock(&dev->struct_mutex);
  8387. trace_i915_flip_request(intel_crtc->plane, obj);
  8388. return 0;
  8389. cleanup_unpin:
  8390. intel_unpin_fb_obj(obj);
  8391. cleanup_pending:
  8392. atomic_dec(&intel_crtc->unpin_work_count);
  8393. crtc->primary->fb = old_fb;
  8394. drm_gem_object_unreference(&work->old_fb_obj->base);
  8395. drm_gem_object_unreference(&obj->base);
  8396. mutex_unlock(&dev->struct_mutex);
  8397. cleanup:
  8398. spin_lock_irqsave(&dev->event_lock, flags);
  8399. intel_crtc->unpin_work = NULL;
  8400. spin_unlock_irqrestore(&dev->event_lock, flags);
  8401. drm_crtc_vblank_put(crtc);
  8402. free_work:
  8403. kfree(work);
  8404. if (ret == -EIO) {
  8405. out_hang:
  8406. intel_crtc_wait_for_pending_flips(crtc);
  8407. ret = intel_pipe_set_base(crtc, crtc->x, crtc->y, fb);
  8408. if (ret == 0 && event) {
  8409. spin_lock_irqsave(&dev->event_lock, flags);
  8410. drm_send_vblank_event(dev, pipe, event);
  8411. spin_unlock_irqrestore(&dev->event_lock, flags);
  8412. }
  8413. }
  8414. return ret;
  8415. }
  8416. static struct drm_crtc_helper_funcs intel_helper_funcs = {
  8417. .mode_set_base_atomic = intel_pipe_set_base_atomic,
  8418. .load_lut = intel_crtc_load_lut,
  8419. };
  8420. /**
  8421. * intel_modeset_update_staged_output_state
  8422. *
  8423. * Updates the staged output configuration state, e.g. after we've read out the
  8424. * current hw state.
  8425. */
  8426. static void intel_modeset_update_staged_output_state(struct drm_device *dev)
  8427. {
  8428. struct intel_crtc *crtc;
  8429. struct intel_encoder *encoder;
  8430. struct intel_connector *connector;
  8431. list_for_each_entry(connector, &dev->mode_config.connector_list,
  8432. base.head) {
  8433. connector->new_encoder =
  8434. to_intel_encoder(connector->base.encoder);
  8435. }
  8436. for_each_intel_encoder(dev, encoder) {
  8437. encoder->new_crtc =
  8438. to_intel_crtc(encoder->base.crtc);
  8439. }
  8440. for_each_intel_crtc(dev, crtc) {
  8441. crtc->new_enabled = crtc->base.enabled;
  8442. if (crtc->new_enabled)
  8443. crtc->new_config = &crtc->config;
  8444. else
  8445. crtc->new_config = NULL;
  8446. }
  8447. }
  8448. /**
  8449. * intel_modeset_commit_output_state
  8450. *
  8451. * This function copies the stage display pipe configuration to the real one.
  8452. */
  8453. static void intel_modeset_commit_output_state(struct drm_device *dev)
  8454. {
  8455. struct intel_crtc *crtc;
  8456. struct intel_encoder *encoder;
  8457. struct intel_connector *connector;
  8458. list_for_each_entry(connector, &dev->mode_config.connector_list,
  8459. base.head) {
  8460. connector->base.encoder = &connector->new_encoder->base;
  8461. }
  8462. for_each_intel_encoder(dev, encoder) {
  8463. encoder->base.crtc = &encoder->new_crtc->base;
  8464. }
  8465. for_each_intel_crtc(dev, crtc) {
  8466. crtc->base.enabled = crtc->new_enabled;
  8467. }
  8468. }
  8469. static void
  8470. connected_sink_compute_bpp(struct intel_connector *connector,
  8471. struct intel_crtc_config *pipe_config)
  8472. {
  8473. int bpp = pipe_config->pipe_bpp;
  8474. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n",
  8475. connector->base.base.id,
  8476. connector->base.name);
  8477. /* Don't use an invalid EDID bpc value */
  8478. if (connector->base.display_info.bpc &&
  8479. connector->base.display_info.bpc * 3 < bpp) {
  8480. DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n",
  8481. bpp, connector->base.display_info.bpc*3);
  8482. pipe_config->pipe_bpp = connector->base.display_info.bpc*3;
  8483. }
  8484. /* Clamp bpp to 8 on screens without EDID 1.4 */
  8485. if (connector->base.display_info.bpc == 0 && bpp > 24) {
  8486. DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n",
  8487. bpp);
  8488. pipe_config->pipe_bpp = 24;
  8489. }
  8490. }
  8491. static int
  8492. compute_baseline_pipe_bpp(struct intel_crtc *crtc,
  8493. struct drm_framebuffer *fb,
  8494. struct intel_crtc_config *pipe_config)
  8495. {
  8496. struct drm_device *dev = crtc->base.dev;
  8497. struct intel_connector *connector;
  8498. int bpp;
  8499. switch (fb->pixel_format) {
  8500. case DRM_FORMAT_C8:
  8501. bpp = 8*3; /* since we go through a colormap */
  8502. break;
  8503. case DRM_FORMAT_XRGB1555:
  8504. case DRM_FORMAT_ARGB1555:
  8505. /* checked in intel_framebuffer_init already */
  8506. if (WARN_ON(INTEL_INFO(dev)->gen > 3))
  8507. return -EINVAL;
  8508. case DRM_FORMAT_RGB565:
  8509. bpp = 6*3; /* min is 18bpp */
  8510. break;
  8511. case DRM_FORMAT_XBGR8888:
  8512. case DRM_FORMAT_ABGR8888:
  8513. /* checked in intel_framebuffer_init already */
  8514. if (WARN_ON(INTEL_INFO(dev)->gen < 4))
  8515. return -EINVAL;
  8516. case DRM_FORMAT_XRGB8888:
  8517. case DRM_FORMAT_ARGB8888:
  8518. bpp = 8*3;
  8519. break;
  8520. case DRM_FORMAT_XRGB2101010:
  8521. case DRM_FORMAT_ARGB2101010:
  8522. case DRM_FORMAT_XBGR2101010:
  8523. case DRM_FORMAT_ABGR2101010:
  8524. /* checked in intel_framebuffer_init already */
  8525. if (WARN_ON(INTEL_INFO(dev)->gen < 4))
  8526. return -EINVAL;
  8527. bpp = 10*3;
  8528. break;
  8529. /* TODO: gen4+ supports 16 bpc floating point, too. */
  8530. default:
  8531. DRM_DEBUG_KMS("unsupported depth\n");
  8532. return -EINVAL;
  8533. }
  8534. pipe_config->pipe_bpp = bpp;
  8535. /* Clamp display bpp to EDID value */
  8536. list_for_each_entry(connector, &dev->mode_config.connector_list,
  8537. base.head) {
  8538. if (!connector->new_encoder ||
  8539. connector->new_encoder->new_crtc != crtc)
  8540. continue;
  8541. connected_sink_compute_bpp(connector, pipe_config);
  8542. }
  8543. return bpp;
  8544. }
  8545. static void intel_dump_crtc_timings(const struct drm_display_mode *mode)
  8546. {
  8547. DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
  8548. "type: 0x%x flags: 0x%x\n",
  8549. mode->crtc_clock,
  8550. mode->crtc_hdisplay, mode->crtc_hsync_start,
  8551. mode->crtc_hsync_end, mode->crtc_htotal,
  8552. mode->crtc_vdisplay, mode->crtc_vsync_start,
  8553. mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags);
  8554. }
  8555. static void intel_dump_pipe_config(struct intel_crtc *crtc,
  8556. struct intel_crtc_config *pipe_config,
  8557. const char *context)
  8558. {
  8559. DRM_DEBUG_KMS("[CRTC:%d]%s config for pipe %c\n", crtc->base.base.id,
  8560. context, pipe_name(crtc->pipe));
  8561. DRM_DEBUG_KMS("cpu_transcoder: %c\n", transcoder_name(pipe_config->cpu_transcoder));
  8562. DRM_DEBUG_KMS("pipe bpp: %i, dithering: %i\n",
  8563. pipe_config->pipe_bpp, pipe_config->dither);
  8564. DRM_DEBUG_KMS("fdi/pch: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
  8565. pipe_config->has_pch_encoder,
  8566. pipe_config->fdi_lanes,
  8567. pipe_config->fdi_m_n.gmch_m, pipe_config->fdi_m_n.gmch_n,
  8568. pipe_config->fdi_m_n.link_m, pipe_config->fdi_m_n.link_n,
  8569. pipe_config->fdi_m_n.tu);
  8570. DRM_DEBUG_KMS("dp: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
  8571. pipe_config->has_dp_encoder,
  8572. pipe_config->dp_m_n.gmch_m, pipe_config->dp_m_n.gmch_n,
  8573. pipe_config->dp_m_n.link_m, pipe_config->dp_m_n.link_n,
  8574. pipe_config->dp_m_n.tu);
  8575. DRM_DEBUG_KMS("dp: %i, gmch_m2: %u, gmch_n2: %u, link_m2: %u, link_n2: %u, tu2: %u\n",
  8576. pipe_config->has_dp_encoder,
  8577. pipe_config->dp_m2_n2.gmch_m,
  8578. pipe_config->dp_m2_n2.gmch_n,
  8579. pipe_config->dp_m2_n2.link_m,
  8580. pipe_config->dp_m2_n2.link_n,
  8581. pipe_config->dp_m2_n2.tu);
  8582. DRM_DEBUG_KMS("requested mode:\n");
  8583. drm_mode_debug_printmodeline(&pipe_config->requested_mode);
  8584. DRM_DEBUG_KMS("adjusted mode:\n");
  8585. drm_mode_debug_printmodeline(&pipe_config->adjusted_mode);
  8586. intel_dump_crtc_timings(&pipe_config->adjusted_mode);
  8587. DRM_DEBUG_KMS("port clock: %d\n", pipe_config->port_clock);
  8588. DRM_DEBUG_KMS("pipe src size: %dx%d\n",
  8589. pipe_config->pipe_src_w, pipe_config->pipe_src_h);
  8590. DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
  8591. pipe_config->gmch_pfit.control,
  8592. pipe_config->gmch_pfit.pgm_ratios,
  8593. pipe_config->gmch_pfit.lvds_border_bits);
  8594. DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n",
  8595. pipe_config->pch_pfit.pos,
  8596. pipe_config->pch_pfit.size,
  8597. pipe_config->pch_pfit.enabled ? "enabled" : "disabled");
  8598. DRM_DEBUG_KMS("ips: %i\n", pipe_config->ips_enabled);
  8599. DRM_DEBUG_KMS("double wide: %i\n", pipe_config->double_wide);
  8600. }
  8601. static bool encoders_cloneable(const struct intel_encoder *a,
  8602. const struct intel_encoder *b)
  8603. {
  8604. /* masks could be asymmetric, so check both ways */
  8605. return a == b || (a->cloneable & (1 << b->type) &&
  8606. b->cloneable & (1 << a->type));
  8607. }
  8608. static bool check_single_encoder_cloning(struct intel_crtc *crtc,
  8609. struct intel_encoder *encoder)
  8610. {
  8611. struct drm_device *dev = crtc->base.dev;
  8612. struct intel_encoder *source_encoder;
  8613. for_each_intel_encoder(dev, source_encoder) {
  8614. if (source_encoder->new_crtc != crtc)
  8615. continue;
  8616. if (!encoders_cloneable(encoder, source_encoder))
  8617. return false;
  8618. }
  8619. return true;
  8620. }
  8621. static bool check_encoder_cloning(struct intel_crtc *crtc)
  8622. {
  8623. struct drm_device *dev = crtc->base.dev;
  8624. struct intel_encoder *encoder;
  8625. for_each_intel_encoder(dev, encoder) {
  8626. if (encoder->new_crtc != crtc)
  8627. continue;
  8628. if (!check_single_encoder_cloning(crtc, encoder))
  8629. return false;
  8630. }
  8631. return true;
  8632. }
  8633. static struct intel_crtc_config *
  8634. intel_modeset_pipe_config(struct drm_crtc *crtc,
  8635. struct drm_framebuffer *fb,
  8636. struct drm_display_mode *mode)
  8637. {
  8638. struct drm_device *dev = crtc->dev;
  8639. struct intel_encoder *encoder;
  8640. struct intel_crtc_config *pipe_config;
  8641. int plane_bpp, ret = -EINVAL;
  8642. bool retry = true;
  8643. if (!check_encoder_cloning(to_intel_crtc(crtc))) {
  8644. DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
  8645. return ERR_PTR(-EINVAL);
  8646. }
  8647. pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL);
  8648. if (!pipe_config)
  8649. return ERR_PTR(-ENOMEM);
  8650. drm_mode_copy(&pipe_config->adjusted_mode, mode);
  8651. drm_mode_copy(&pipe_config->requested_mode, mode);
  8652. pipe_config->cpu_transcoder =
  8653. (enum transcoder) to_intel_crtc(crtc)->pipe;
  8654. pipe_config->shared_dpll = DPLL_ID_PRIVATE;
  8655. /*
  8656. * Sanitize sync polarity flags based on requested ones. If neither
  8657. * positive or negative polarity is requested, treat this as meaning
  8658. * negative polarity.
  8659. */
  8660. if (!(pipe_config->adjusted_mode.flags &
  8661. (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC)))
  8662. pipe_config->adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC;
  8663. if (!(pipe_config->adjusted_mode.flags &
  8664. (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC)))
  8665. pipe_config->adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC;
  8666. /* Compute a starting value for pipe_config->pipe_bpp taking the source
  8667. * plane pixel format and any sink constraints into account. Returns the
  8668. * source plane bpp so that dithering can be selected on mismatches
  8669. * after encoders and crtc also have had their say. */
  8670. plane_bpp = compute_baseline_pipe_bpp(to_intel_crtc(crtc),
  8671. fb, pipe_config);
  8672. if (plane_bpp < 0)
  8673. goto fail;
  8674. /*
  8675. * Determine the real pipe dimensions. Note that stereo modes can
  8676. * increase the actual pipe size due to the frame doubling and
  8677. * insertion of additional space for blanks between the frame. This
  8678. * is stored in the crtc timings. We use the requested mode to do this
  8679. * computation to clearly distinguish it from the adjusted mode, which
  8680. * can be changed by the connectors in the below retry loop.
  8681. */
  8682. drm_mode_set_crtcinfo(&pipe_config->requested_mode, CRTC_STEREO_DOUBLE);
  8683. pipe_config->pipe_src_w = pipe_config->requested_mode.crtc_hdisplay;
  8684. pipe_config->pipe_src_h = pipe_config->requested_mode.crtc_vdisplay;
  8685. encoder_retry:
  8686. /* Ensure the port clock defaults are reset when retrying. */
  8687. pipe_config->port_clock = 0;
  8688. pipe_config->pixel_multiplier = 1;
  8689. /* Fill in default crtc timings, allow encoders to overwrite them. */
  8690. drm_mode_set_crtcinfo(&pipe_config->adjusted_mode, CRTC_STEREO_DOUBLE);
  8691. /* Pass our mode to the connectors and the CRTC to give them a chance to
  8692. * adjust it according to limitations or connector properties, and also
  8693. * a chance to reject the mode entirely.
  8694. */
  8695. for_each_intel_encoder(dev, encoder) {
  8696. if (&encoder->new_crtc->base != crtc)
  8697. continue;
  8698. if (!(encoder->compute_config(encoder, pipe_config))) {
  8699. DRM_DEBUG_KMS("Encoder config failure\n");
  8700. goto fail;
  8701. }
  8702. }
  8703. /* Set default port clock if not overwritten by the encoder. Needs to be
  8704. * done afterwards in case the encoder adjusts the mode. */
  8705. if (!pipe_config->port_clock)
  8706. pipe_config->port_clock = pipe_config->adjusted_mode.crtc_clock
  8707. * pipe_config->pixel_multiplier;
  8708. ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config);
  8709. if (ret < 0) {
  8710. DRM_DEBUG_KMS("CRTC fixup failed\n");
  8711. goto fail;
  8712. }
  8713. if (ret == RETRY) {
  8714. if (WARN(!retry, "loop in pipe configuration computation\n")) {
  8715. ret = -EINVAL;
  8716. goto fail;
  8717. }
  8718. DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
  8719. retry = false;
  8720. goto encoder_retry;
  8721. }
  8722. pipe_config->dither = pipe_config->pipe_bpp != plane_bpp;
  8723. DRM_DEBUG_KMS("plane bpp: %i, pipe bpp: %i, dithering: %i\n",
  8724. plane_bpp, pipe_config->pipe_bpp, pipe_config->dither);
  8725. return pipe_config;
  8726. fail:
  8727. kfree(pipe_config);
  8728. return ERR_PTR(ret);
  8729. }
  8730. /* Computes which crtcs are affected and sets the relevant bits in the mask. For
  8731. * simplicity we use the crtc's pipe number (because it's easier to obtain). */
  8732. static void
  8733. intel_modeset_affected_pipes(struct drm_crtc *crtc, unsigned *modeset_pipes,
  8734. unsigned *prepare_pipes, unsigned *disable_pipes)
  8735. {
  8736. struct intel_crtc *intel_crtc;
  8737. struct drm_device *dev = crtc->dev;
  8738. struct intel_encoder *encoder;
  8739. struct intel_connector *connector;
  8740. struct drm_crtc *tmp_crtc;
  8741. *disable_pipes = *modeset_pipes = *prepare_pipes = 0;
  8742. /* Check which crtcs have changed outputs connected to them, these need
  8743. * to be part of the prepare_pipes mask. We don't (yet) support global
  8744. * modeset across multiple crtcs, so modeset_pipes will only have one
  8745. * bit set at most. */
  8746. list_for_each_entry(connector, &dev->mode_config.connector_list,
  8747. base.head) {
  8748. if (connector->base.encoder == &connector->new_encoder->base)
  8749. continue;
  8750. if (connector->base.encoder) {
  8751. tmp_crtc = connector->base.encoder->crtc;
  8752. *prepare_pipes |= 1 << to_intel_crtc(tmp_crtc)->pipe;
  8753. }
  8754. if (connector->new_encoder)
  8755. *prepare_pipes |=
  8756. 1 << connector->new_encoder->new_crtc->pipe;
  8757. }
  8758. for_each_intel_encoder(dev, encoder) {
  8759. if (encoder->base.crtc == &encoder->new_crtc->base)
  8760. continue;
  8761. if (encoder->base.crtc) {
  8762. tmp_crtc = encoder->base.crtc;
  8763. *prepare_pipes |= 1 << to_intel_crtc(tmp_crtc)->pipe;
  8764. }
  8765. if (encoder->new_crtc)
  8766. *prepare_pipes |= 1 << encoder->new_crtc->pipe;
  8767. }
  8768. /* Check for pipes that will be enabled/disabled ... */
  8769. for_each_intel_crtc(dev, intel_crtc) {
  8770. if (intel_crtc->base.enabled == intel_crtc->new_enabled)
  8771. continue;
  8772. if (!intel_crtc->new_enabled)
  8773. *disable_pipes |= 1 << intel_crtc->pipe;
  8774. else
  8775. *prepare_pipes |= 1 << intel_crtc->pipe;
  8776. }
  8777. /* set_mode is also used to update properties on life display pipes. */
  8778. intel_crtc = to_intel_crtc(crtc);
  8779. if (intel_crtc->new_enabled)
  8780. *prepare_pipes |= 1 << intel_crtc->pipe;
  8781. /*
  8782. * For simplicity do a full modeset on any pipe where the output routing
  8783. * changed. We could be more clever, but that would require us to be
  8784. * more careful with calling the relevant encoder->mode_set functions.
  8785. */
  8786. if (*prepare_pipes)
  8787. *modeset_pipes = *prepare_pipes;
  8788. /* ... and mask these out. */
  8789. *modeset_pipes &= ~(*disable_pipes);
  8790. *prepare_pipes &= ~(*disable_pipes);
  8791. /*
  8792. * HACK: We don't (yet) fully support global modesets. intel_set_config
  8793. * obies this rule, but the modeset restore mode of
  8794. * intel_modeset_setup_hw_state does not.
  8795. */
  8796. *modeset_pipes &= 1 << intel_crtc->pipe;
  8797. *prepare_pipes &= 1 << intel_crtc->pipe;
  8798. DRM_DEBUG_KMS("set mode pipe masks: modeset: %x, prepare: %x, disable: %x\n",
  8799. *modeset_pipes, *prepare_pipes, *disable_pipes);
  8800. }
  8801. static bool intel_crtc_in_use(struct drm_crtc *crtc)
  8802. {
  8803. struct drm_encoder *encoder;
  8804. struct drm_device *dev = crtc->dev;
  8805. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head)
  8806. if (encoder->crtc == crtc)
  8807. return true;
  8808. return false;
  8809. }
  8810. static void
  8811. intel_modeset_update_state(struct drm_device *dev, unsigned prepare_pipes)
  8812. {
  8813. struct intel_encoder *intel_encoder;
  8814. struct intel_crtc *intel_crtc;
  8815. struct drm_connector *connector;
  8816. for_each_intel_encoder(dev, intel_encoder) {
  8817. if (!intel_encoder->base.crtc)
  8818. continue;
  8819. intel_crtc = to_intel_crtc(intel_encoder->base.crtc);
  8820. if (prepare_pipes & (1 << intel_crtc->pipe))
  8821. intel_encoder->connectors_active = false;
  8822. }
  8823. intel_modeset_commit_output_state(dev);
  8824. /* Double check state. */
  8825. for_each_intel_crtc(dev, intel_crtc) {
  8826. WARN_ON(intel_crtc->base.enabled != intel_crtc_in_use(&intel_crtc->base));
  8827. WARN_ON(intel_crtc->new_config &&
  8828. intel_crtc->new_config != &intel_crtc->config);
  8829. WARN_ON(intel_crtc->base.enabled != !!intel_crtc->new_config);
  8830. }
  8831. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  8832. if (!connector->encoder || !connector->encoder->crtc)
  8833. continue;
  8834. intel_crtc = to_intel_crtc(connector->encoder->crtc);
  8835. if (prepare_pipes & (1 << intel_crtc->pipe)) {
  8836. struct drm_property *dpms_property =
  8837. dev->mode_config.dpms_property;
  8838. connector->dpms = DRM_MODE_DPMS_ON;
  8839. drm_object_property_set_value(&connector->base,
  8840. dpms_property,
  8841. DRM_MODE_DPMS_ON);
  8842. intel_encoder = to_intel_encoder(connector->encoder);
  8843. intel_encoder->connectors_active = true;
  8844. }
  8845. }
  8846. }
  8847. static bool intel_fuzzy_clock_check(int clock1, int clock2)
  8848. {
  8849. int diff;
  8850. if (clock1 == clock2)
  8851. return true;
  8852. if (!clock1 || !clock2)
  8853. return false;
  8854. diff = abs(clock1 - clock2);
  8855. if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105)
  8856. return true;
  8857. return false;
  8858. }
  8859. #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \
  8860. list_for_each_entry((intel_crtc), \
  8861. &(dev)->mode_config.crtc_list, \
  8862. base.head) \
  8863. if (mask & (1 <<(intel_crtc)->pipe))
  8864. static bool
  8865. intel_pipe_config_compare(struct drm_device *dev,
  8866. struct intel_crtc_config *current_config,
  8867. struct intel_crtc_config *pipe_config)
  8868. {
  8869. #define PIPE_CONF_CHECK_X(name) \
  8870. if (current_config->name != pipe_config->name) { \
  8871. DRM_ERROR("mismatch in " #name " " \
  8872. "(expected 0x%08x, found 0x%08x)\n", \
  8873. current_config->name, \
  8874. pipe_config->name); \
  8875. return false; \
  8876. }
  8877. #define PIPE_CONF_CHECK_I(name) \
  8878. if (current_config->name != pipe_config->name) { \
  8879. DRM_ERROR("mismatch in " #name " " \
  8880. "(expected %i, found %i)\n", \
  8881. current_config->name, \
  8882. pipe_config->name); \
  8883. return false; \
  8884. }
  8885. /* This is required for BDW+ where there is only one set of registers for
  8886. * switching between high and low RR.
  8887. * This macro can be used whenever a comparison has to be made between one
  8888. * hw state and multiple sw state variables.
  8889. */
  8890. #define PIPE_CONF_CHECK_I_ALT(name, alt_name) \
  8891. if ((current_config->name != pipe_config->name) && \
  8892. (current_config->alt_name != pipe_config->name)) { \
  8893. DRM_ERROR("mismatch in " #name " " \
  8894. "(expected %i or %i, found %i)\n", \
  8895. current_config->name, \
  8896. current_config->alt_name, \
  8897. pipe_config->name); \
  8898. return false; \
  8899. }
  8900. #define PIPE_CONF_CHECK_FLAGS(name, mask) \
  8901. if ((current_config->name ^ pipe_config->name) & (mask)) { \
  8902. DRM_ERROR("mismatch in " #name "(" #mask ") " \
  8903. "(expected %i, found %i)\n", \
  8904. current_config->name & (mask), \
  8905. pipe_config->name & (mask)); \
  8906. return false; \
  8907. }
  8908. #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \
  8909. if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
  8910. DRM_ERROR("mismatch in " #name " " \
  8911. "(expected %i, found %i)\n", \
  8912. current_config->name, \
  8913. pipe_config->name); \
  8914. return false; \
  8915. }
  8916. #define PIPE_CONF_QUIRK(quirk) \
  8917. ((current_config->quirks | pipe_config->quirks) & (quirk))
  8918. PIPE_CONF_CHECK_I(cpu_transcoder);
  8919. PIPE_CONF_CHECK_I(has_pch_encoder);
  8920. PIPE_CONF_CHECK_I(fdi_lanes);
  8921. PIPE_CONF_CHECK_I(fdi_m_n.gmch_m);
  8922. PIPE_CONF_CHECK_I(fdi_m_n.gmch_n);
  8923. PIPE_CONF_CHECK_I(fdi_m_n.link_m);
  8924. PIPE_CONF_CHECK_I(fdi_m_n.link_n);
  8925. PIPE_CONF_CHECK_I(fdi_m_n.tu);
  8926. PIPE_CONF_CHECK_I(has_dp_encoder);
  8927. if (INTEL_INFO(dev)->gen < 8) {
  8928. PIPE_CONF_CHECK_I(dp_m_n.gmch_m);
  8929. PIPE_CONF_CHECK_I(dp_m_n.gmch_n);
  8930. PIPE_CONF_CHECK_I(dp_m_n.link_m);
  8931. PIPE_CONF_CHECK_I(dp_m_n.link_n);
  8932. PIPE_CONF_CHECK_I(dp_m_n.tu);
  8933. if (current_config->has_drrs) {
  8934. PIPE_CONF_CHECK_I(dp_m2_n2.gmch_m);
  8935. PIPE_CONF_CHECK_I(dp_m2_n2.gmch_n);
  8936. PIPE_CONF_CHECK_I(dp_m2_n2.link_m);
  8937. PIPE_CONF_CHECK_I(dp_m2_n2.link_n);
  8938. PIPE_CONF_CHECK_I(dp_m2_n2.tu);
  8939. }
  8940. } else {
  8941. PIPE_CONF_CHECK_I_ALT(dp_m_n.gmch_m, dp_m2_n2.gmch_m);
  8942. PIPE_CONF_CHECK_I_ALT(dp_m_n.gmch_n, dp_m2_n2.gmch_n);
  8943. PIPE_CONF_CHECK_I_ALT(dp_m_n.link_m, dp_m2_n2.link_m);
  8944. PIPE_CONF_CHECK_I_ALT(dp_m_n.link_n, dp_m2_n2.link_n);
  8945. PIPE_CONF_CHECK_I_ALT(dp_m_n.tu, dp_m2_n2.tu);
  8946. }
  8947. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hdisplay);
  8948. PIPE_CONF_CHECK_I(adjusted_mode.crtc_htotal);
  8949. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hblank_start);
  8950. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hblank_end);
  8951. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hsync_start);
  8952. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hsync_end);
  8953. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vdisplay);
  8954. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vtotal);
  8955. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vblank_start);
  8956. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vblank_end);
  8957. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vsync_start);
  8958. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vsync_end);
  8959. PIPE_CONF_CHECK_I(pixel_multiplier);
  8960. PIPE_CONF_CHECK_I(has_hdmi_sink);
  8961. if ((INTEL_INFO(dev)->gen < 8 && !IS_HASWELL(dev)) ||
  8962. IS_VALLEYVIEW(dev))
  8963. PIPE_CONF_CHECK_I(limited_color_range);
  8964. PIPE_CONF_CHECK_I(has_audio);
  8965. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  8966. DRM_MODE_FLAG_INTERLACE);
  8967. if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) {
  8968. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  8969. DRM_MODE_FLAG_PHSYNC);
  8970. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  8971. DRM_MODE_FLAG_NHSYNC);
  8972. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  8973. DRM_MODE_FLAG_PVSYNC);
  8974. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  8975. DRM_MODE_FLAG_NVSYNC);
  8976. }
  8977. PIPE_CONF_CHECK_I(pipe_src_w);
  8978. PIPE_CONF_CHECK_I(pipe_src_h);
  8979. /*
  8980. * FIXME: BIOS likes to set up a cloned config with lvds+external
  8981. * screen. Since we don't yet re-compute the pipe config when moving
  8982. * just the lvds port away to another pipe the sw tracking won't match.
  8983. *
  8984. * Proper atomic modesets with recomputed global state will fix this.
  8985. * Until then just don't check gmch state for inherited modes.
  8986. */
  8987. if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_INHERITED_MODE)) {
  8988. PIPE_CONF_CHECK_I(gmch_pfit.control);
  8989. /* pfit ratios are autocomputed by the hw on gen4+ */
  8990. if (INTEL_INFO(dev)->gen < 4)
  8991. PIPE_CONF_CHECK_I(gmch_pfit.pgm_ratios);
  8992. PIPE_CONF_CHECK_I(gmch_pfit.lvds_border_bits);
  8993. }
  8994. PIPE_CONF_CHECK_I(pch_pfit.enabled);
  8995. if (current_config->pch_pfit.enabled) {
  8996. PIPE_CONF_CHECK_I(pch_pfit.pos);
  8997. PIPE_CONF_CHECK_I(pch_pfit.size);
  8998. }
  8999. /* BDW+ don't expose a synchronous way to read the state */
  9000. if (IS_HASWELL(dev))
  9001. PIPE_CONF_CHECK_I(ips_enabled);
  9002. PIPE_CONF_CHECK_I(double_wide);
  9003. PIPE_CONF_CHECK_X(ddi_pll_sel);
  9004. PIPE_CONF_CHECK_I(shared_dpll);
  9005. PIPE_CONF_CHECK_X(dpll_hw_state.dpll);
  9006. PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md);
  9007. PIPE_CONF_CHECK_X(dpll_hw_state.fp0);
  9008. PIPE_CONF_CHECK_X(dpll_hw_state.fp1);
  9009. PIPE_CONF_CHECK_X(dpll_hw_state.wrpll);
  9010. if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5)
  9011. PIPE_CONF_CHECK_I(pipe_bpp);
  9012. PIPE_CONF_CHECK_CLOCK_FUZZY(adjusted_mode.crtc_clock);
  9013. PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock);
  9014. #undef PIPE_CONF_CHECK_X
  9015. #undef PIPE_CONF_CHECK_I
  9016. #undef PIPE_CONF_CHECK_I_ALT
  9017. #undef PIPE_CONF_CHECK_FLAGS
  9018. #undef PIPE_CONF_CHECK_CLOCK_FUZZY
  9019. #undef PIPE_CONF_QUIRK
  9020. return true;
  9021. }
  9022. static void
  9023. check_connector_state(struct drm_device *dev)
  9024. {
  9025. struct intel_connector *connector;
  9026. list_for_each_entry(connector, &dev->mode_config.connector_list,
  9027. base.head) {
  9028. /* This also checks the encoder/connector hw state with the
  9029. * ->get_hw_state callbacks. */
  9030. intel_connector_check_state(connector);
  9031. WARN(&connector->new_encoder->base != connector->base.encoder,
  9032. "connector's staged encoder doesn't match current encoder\n");
  9033. }
  9034. }
  9035. static void
  9036. check_encoder_state(struct drm_device *dev)
  9037. {
  9038. struct intel_encoder *encoder;
  9039. struct intel_connector *connector;
  9040. for_each_intel_encoder(dev, encoder) {
  9041. bool enabled = false;
  9042. bool active = false;
  9043. enum pipe pipe, tracked_pipe;
  9044. DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
  9045. encoder->base.base.id,
  9046. encoder->base.name);
  9047. WARN(&encoder->new_crtc->base != encoder->base.crtc,
  9048. "encoder's stage crtc doesn't match current crtc\n");
  9049. WARN(encoder->connectors_active && !encoder->base.crtc,
  9050. "encoder's active_connectors set, but no crtc\n");
  9051. list_for_each_entry(connector, &dev->mode_config.connector_list,
  9052. base.head) {
  9053. if (connector->base.encoder != &encoder->base)
  9054. continue;
  9055. enabled = true;
  9056. if (connector->base.dpms != DRM_MODE_DPMS_OFF)
  9057. active = true;
  9058. }
  9059. /*
  9060. * for MST connectors if we unplug the connector is gone
  9061. * away but the encoder is still connected to a crtc
  9062. * until a modeset happens in response to the hotplug.
  9063. */
  9064. if (!enabled && encoder->base.encoder_type == DRM_MODE_ENCODER_DPMST)
  9065. continue;
  9066. WARN(!!encoder->base.crtc != enabled,
  9067. "encoder's enabled state mismatch "
  9068. "(expected %i, found %i)\n",
  9069. !!encoder->base.crtc, enabled);
  9070. WARN(active && !encoder->base.crtc,
  9071. "active encoder with no crtc\n");
  9072. WARN(encoder->connectors_active != active,
  9073. "encoder's computed active state doesn't match tracked active state "
  9074. "(expected %i, found %i)\n", active, encoder->connectors_active);
  9075. active = encoder->get_hw_state(encoder, &pipe);
  9076. WARN(active != encoder->connectors_active,
  9077. "encoder's hw state doesn't match sw tracking "
  9078. "(expected %i, found %i)\n",
  9079. encoder->connectors_active, active);
  9080. if (!encoder->base.crtc)
  9081. continue;
  9082. tracked_pipe = to_intel_crtc(encoder->base.crtc)->pipe;
  9083. WARN(active && pipe != tracked_pipe,
  9084. "active encoder's pipe doesn't match"
  9085. "(expected %i, found %i)\n",
  9086. tracked_pipe, pipe);
  9087. }
  9088. }
  9089. static void
  9090. check_crtc_state(struct drm_device *dev)
  9091. {
  9092. struct drm_i915_private *dev_priv = dev->dev_private;
  9093. struct intel_crtc *crtc;
  9094. struct intel_encoder *encoder;
  9095. struct intel_crtc_config pipe_config;
  9096. for_each_intel_crtc(dev, crtc) {
  9097. bool enabled = false;
  9098. bool active = false;
  9099. memset(&pipe_config, 0, sizeof(pipe_config));
  9100. DRM_DEBUG_KMS("[CRTC:%d]\n",
  9101. crtc->base.base.id);
  9102. WARN(crtc->active && !crtc->base.enabled,
  9103. "active crtc, but not enabled in sw tracking\n");
  9104. for_each_intel_encoder(dev, encoder) {
  9105. if (encoder->base.crtc != &crtc->base)
  9106. continue;
  9107. enabled = true;
  9108. if (encoder->connectors_active)
  9109. active = true;
  9110. }
  9111. WARN(active != crtc->active,
  9112. "crtc's computed active state doesn't match tracked active state "
  9113. "(expected %i, found %i)\n", active, crtc->active);
  9114. WARN(enabled != crtc->base.enabled,
  9115. "crtc's computed enabled state doesn't match tracked enabled state "
  9116. "(expected %i, found %i)\n", enabled, crtc->base.enabled);
  9117. active = dev_priv->display.get_pipe_config(crtc,
  9118. &pipe_config);
  9119. /* hw state is inconsistent with the pipe quirk */
  9120. if ((crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) ||
  9121. (crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))
  9122. active = crtc->active;
  9123. for_each_intel_encoder(dev, encoder) {
  9124. enum pipe pipe;
  9125. if (encoder->base.crtc != &crtc->base)
  9126. continue;
  9127. if (encoder->get_hw_state(encoder, &pipe))
  9128. encoder->get_config(encoder, &pipe_config);
  9129. }
  9130. WARN(crtc->active != active,
  9131. "crtc active state doesn't match with hw state "
  9132. "(expected %i, found %i)\n", crtc->active, active);
  9133. if (active &&
  9134. !intel_pipe_config_compare(dev, &crtc->config, &pipe_config)) {
  9135. WARN(1, "pipe state doesn't match!\n");
  9136. intel_dump_pipe_config(crtc, &pipe_config,
  9137. "[hw state]");
  9138. intel_dump_pipe_config(crtc, &crtc->config,
  9139. "[sw state]");
  9140. }
  9141. }
  9142. }
  9143. static void
  9144. check_shared_dpll_state(struct drm_device *dev)
  9145. {
  9146. struct drm_i915_private *dev_priv = dev->dev_private;
  9147. struct intel_crtc *crtc;
  9148. struct intel_dpll_hw_state dpll_hw_state;
  9149. int i;
  9150. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  9151. struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
  9152. int enabled_crtcs = 0, active_crtcs = 0;
  9153. bool active;
  9154. memset(&dpll_hw_state, 0, sizeof(dpll_hw_state));
  9155. DRM_DEBUG_KMS("%s\n", pll->name);
  9156. active = pll->get_hw_state(dev_priv, pll, &dpll_hw_state);
  9157. WARN(pll->active > pll->refcount,
  9158. "more active pll users than references: %i vs %i\n",
  9159. pll->active, pll->refcount);
  9160. WARN(pll->active && !pll->on,
  9161. "pll in active use but not on in sw tracking\n");
  9162. WARN(pll->on && !pll->active,
  9163. "pll in on but not on in use in sw tracking\n");
  9164. WARN(pll->on != active,
  9165. "pll on state mismatch (expected %i, found %i)\n",
  9166. pll->on, active);
  9167. for_each_intel_crtc(dev, crtc) {
  9168. if (crtc->base.enabled && intel_crtc_to_shared_dpll(crtc) == pll)
  9169. enabled_crtcs++;
  9170. if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll)
  9171. active_crtcs++;
  9172. }
  9173. WARN(pll->active != active_crtcs,
  9174. "pll active crtcs mismatch (expected %i, found %i)\n",
  9175. pll->active, active_crtcs);
  9176. WARN(pll->refcount != enabled_crtcs,
  9177. "pll enabled crtcs mismatch (expected %i, found %i)\n",
  9178. pll->refcount, enabled_crtcs);
  9179. WARN(pll->on && memcmp(&pll->hw_state, &dpll_hw_state,
  9180. sizeof(dpll_hw_state)),
  9181. "pll hw state mismatch\n");
  9182. }
  9183. }
  9184. void
  9185. intel_modeset_check_state(struct drm_device *dev)
  9186. {
  9187. check_connector_state(dev);
  9188. check_encoder_state(dev);
  9189. check_crtc_state(dev);
  9190. check_shared_dpll_state(dev);
  9191. }
  9192. void ironlake_check_encoder_dotclock(const struct intel_crtc_config *pipe_config,
  9193. int dotclock)
  9194. {
  9195. /*
  9196. * FDI already provided one idea for the dotclock.
  9197. * Yell if the encoder disagrees.
  9198. */
  9199. WARN(!intel_fuzzy_clock_check(pipe_config->adjusted_mode.crtc_clock, dotclock),
  9200. "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
  9201. pipe_config->adjusted_mode.crtc_clock, dotclock);
  9202. }
  9203. static void update_scanline_offset(struct intel_crtc *crtc)
  9204. {
  9205. struct drm_device *dev = crtc->base.dev;
  9206. /*
  9207. * The scanline counter increments at the leading edge of hsync.
  9208. *
  9209. * On most platforms it starts counting from vtotal-1 on the
  9210. * first active line. That means the scanline counter value is
  9211. * always one less than what we would expect. Ie. just after
  9212. * start of vblank, which also occurs at start of hsync (on the
  9213. * last active line), the scanline counter will read vblank_start-1.
  9214. *
  9215. * On gen2 the scanline counter starts counting from 1 instead
  9216. * of vtotal-1, so we have to subtract one (or rather add vtotal-1
  9217. * to keep the value positive), instead of adding one.
  9218. *
  9219. * On HSW+ the behaviour of the scanline counter depends on the output
  9220. * type. For DP ports it behaves like most other platforms, but on HDMI
  9221. * there's an extra 1 line difference. So we need to add two instead of
  9222. * one to the value.
  9223. */
  9224. if (IS_GEN2(dev)) {
  9225. const struct drm_display_mode *mode = &crtc->config.adjusted_mode;
  9226. int vtotal;
  9227. vtotal = mode->crtc_vtotal;
  9228. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  9229. vtotal /= 2;
  9230. crtc->scanline_offset = vtotal - 1;
  9231. } else if (HAS_DDI(dev) &&
  9232. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_HDMI)) {
  9233. crtc->scanline_offset = 2;
  9234. } else
  9235. crtc->scanline_offset = 1;
  9236. }
  9237. static int __intel_set_mode(struct drm_crtc *crtc,
  9238. struct drm_display_mode *mode,
  9239. int x, int y, struct drm_framebuffer *fb)
  9240. {
  9241. struct drm_device *dev = crtc->dev;
  9242. struct drm_i915_private *dev_priv = dev->dev_private;
  9243. struct drm_display_mode *saved_mode;
  9244. struct intel_crtc_config *pipe_config = NULL;
  9245. struct intel_crtc *intel_crtc;
  9246. unsigned disable_pipes, prepare_pipes, modeset_pipes;
  9247. int ret = 0;
  9248. saved_mode = kmalloc(sizeof(*saved_mode), GFP_KERNEL);
  9249. if (!saved_mode)
  9250. return -ENOMEM;
  9251. intel_modeset_affected_pipes(crtc, &modeset_pipes,
  9252. &prepare_pipes, &disable_pipes);
  9253. *saved_mode = crtc->mode;
  9254. /* Hack: Because we don't (yet) support global modeset on multiple
  9255. * crtcs, we don't keep track of the new mode for more than one crtc.
  9256. * Hence simply check whether any bit is set in modeset_pipes in all the
  9257. * pieces of code that are not yet converted to deal with mutliple crtcs
  9258. * changing their mode at the same time. */
  9259. if (modeset_pipes) {
  9260. pipe_config = intel_modeset_pipe_config(crtc, fb, mode);
  9261. if (IS_ERR(pipe_config)) {
  9262. ret = PTR_ERR(pipe_config);
  9263. pipe_config = NULL;
  9264. goto out;
  9265. }
  9266. intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config,
  9267. "[modeset]");
  9268. to_intel_crtc(crtc)->new_config = pipe_config;
  9269. }
  9270. /*
  9271. * See if the config requires any additional preparation, e.g.
  9272. * to adjust global state with pipes off. We need to do this
  9273. * here so we can get the modeset_pipe updated config for the new
  9274. * mode set on this crtc. For other crtcs we need to use the
  9275. * adjusted_mode bits in the crtc directly.
  9276. */
  9277. if (IS_VALLEYVIEW(dev)) {
  9278. valleyview_modeset_global_pipes(dev, &prepare_pipes);
  9279. /* may have added more to prepare_pipes than we should */
  9280. prepare_pipes &= ~disable_pipes;
  9281. }
  9282. for_each_intel_crtc_masked(dev, disable_pipes, intel_crtc)
  9283. intel_crtc_disable(&intel_crtc->base);
  9284. for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc) {
  9285. if (intel_crtc->base.enabled)
  9286. dev_priv->display.crtc_disable(&intel_crtc->base);
  9287. }
  9288. /* crtc->mode is already used by the ->mode_set callbacks, hence we need
  9289. * to set it here already despite that we pass it down the callchain.
  9290. */
  9291. if (modeset_pipes) {
  9292. crtc->mode = *mode;
  9293. /* mode_set/enable/disable functions rely on a correct pipe
  9294. * config. */
  9295. to_intel_crtc(crtc)->config = *pipe_config;
  9296. to_intel_crtc(crtc)->new_config = &to_intel_crtc(crtc)->config;
  9297. /*
  9298. * Calculate and store various constants which
  9299. * are later needed by vblank and swap-completion
  9300. * timestamping. They are derived from true hwmode.
  9301. */
  9302. drm_calc_timestamping_constants(crtc,
  9303. &pipe_config->adjusted_mode);
  9304. }
  9305. /* Only after disabling all output pipelines that will be changed can we
  9306. * update the the output configuration. */
  9307. intel_modeset_update_state(dev, prepare_pipes);
  9308. if (dev_priv->display.modeset_global_resources)
  9309. dev_priv->display.modeset_global_resources(dev);
  9310. /* Set up the DPLL and any encoders state that needs to adjust or depend
  9311. * on the DPLL.
  9312. */
  9313. for_each_intel_crtc_masked(dev, modeset_pipes, intel_crtc) {
  9314. struct drm_framebuffer *old_fb = crtc->primary->fb;
  9315. struct drm_i915_gem_object *old_obj = intel_fb_obj(old_fb);
  9316. struct drm_i915_gem_object *obj = intel_fb_obj(fb);
  9317. mutex_lock(&dev->struct_mutex);
  9318. ret = intel_pin_and_fence_fb_obj(dev,
  9319. obj,
  9320. NULL);
  9321. if (ret != 0) {
  9322. DRM_ERROR("pin & fence failed\n");
  9323. mutex_unlock(&dev->struct_mutex);
  9324. goto done;
  9325. }
  9326. if (old_fb)
  9327. intel_unpin_fb_obj(old_obj);
  9328. i915_gem_track_fb(old_obj, obj,
  9329. INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe));
  9330. mutex_unlock(&dev->struct_mutex);
  9331. crtc->primary->fb = fb;
  9332. crtc->x = x;
  9333. crtc->y = y;
  9334. ret = dev_priv->display.crtc_mode_set(&intel_crtc->base,
  9335. x, y, fb);
  9336. if (ret)
  9337. goto done;
  9338. }
  9339. /* Now enable the clocks, plane, pipe, and connectors that we set up. */
  9340. for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc) {
  9341. update_scanline_offset(intel_crtc);
  9342. dev_priv->display.crtc_enable(&intel_crtc->base);
  9343. }
  9344. /* FIXME: add subpixel order */
  9345. done:
  9346. if (ret && crtc->enabled)
  9347. crtc->mode = *saved_mode;
  9348. out:
  9349. kfree(pipe_config);
  9350. kfree(saved_mode);
  9351. return ret;
  9352. }
  9353. static int intel_set_mode(struct drm_crtc *crtc,
  9354. struct drm_display_mode *mode,
  9355. int x, int y, struct drm_framebuffer *fb)
  9356. {
  9357. int ret;
  9358. ret = __intel_set_mode(crtc, mode, x, y, fb);
  9359. if (ret == 0)
  9360. intel_modeset_check_state(crtc->dev);
  9361. return ret;
  9362. }
  9363. void intel_crtc_restore_mode(struct drm_crtc *crtc)
  9364. {
  9365. intel_set_mode(crtc, &crtc->mode, crtc->x, crtc->y, crtc->primary->fb);
  9366. }
  9367. #undef for_each_intel_crtc_masked
  9368. static void intel_set_config_free(struct intel_set_config *config)
  9369. {
  9370. if (!config)
  9371. return;
  9372. kfree(config->save_connector_encoders);
  9373. kfree(config->save_encoder_crtcs);
  9374. kfree(config->save_crtc_enabled);
  9375. kfree(config);
  9376. }
  9377. static int intel_set_config_save_state(struct drm_device *dev,
  9378. struct intel_set_config *config)
  9379. {
  9380. struct drm_crtc *crtc;
  9381. struct drm_encoder *encoder;
  9382. struct drm_connector *connector;
  9383. int count;
  9384. config->save_crtc_enabled =
  9385. kcalloc(dev->mode_config.num_crtc,
  9386. sizeof(bool), GFP_KERNEL);
  9387. if (!config->save_crtc_enabled)
  9388. return -ENOMEM;
  9389. config->save_encoder_crtcs =
  9390. kcalloc(dev->mode_config.num_encoder,
  9391. sizeof(struct drm_crtc *), GFP_KERNEL);
  9392. if (!config->save_encoder_crtcs)
  9393. return -ENOMEM;
  9394. config->save_connector_encoders =
  9395. kcalloc(dev->mode_config.num_connector,
  9396. sizeof(struct drm_encoder *), GFP_KERNEL);
  9397. if (!config->save_connector_encoders)
  9398. return -ENOMEM;
  9399. /* Copy data. Note that driver private data is not affected.
  9400. * Should anything bad happen only the expected state is
  9401. * restored, not the drivers personal bookkeeping.
  9402. */
  9403. count = 0;
  9404. for_each_crtc(dev, crtc) {
  9405. config->save_crtc_enabled[count++] = crtc->enabled;
  9406. }
  9407. count = 0;
  9408. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  9409. config->save_encoder_crtcs[count++] = encoder->crtc;
  9410. }
  9411. count = 0;
  9412. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  9413. config->save_connector_encoders[count++] = connector->encoder;
  9414. }
  9415. return 0;
  9416. }
  9417. static void intel_set_config_restore_state(struct drm_device *dev,
  9418. struct intel_set_config *config)
  9419. {
  9420. struct intel_crtc *crtc;
  9421. struct intel_encoder *encoder;
  9422. struct intel_connector *connector;
  9423. int count;
  9424. count = 0;
  9425. for_each_intel_crtc(dev, crtc) {
  9426. crtc->new_enabled = config->save_crtc_enabled[count++];
  9427. if (crtc->new_enabled)
  9428. crtc->new_config = &crtc->config;
  9429. else
  9430. crtc->new_config = NULL;
  9431. }
  9432. count = 0;
  9433. for_each_intel_encoder(dev, encoder) {
  9434. encoder->new_crtc =
  9435. to_intel_crtc(config->save_encoder_crtcs[count++]);
  9436. }
  9437. count = 0;
  9438. list_for_each_entry(connector, &dev->mode_config.connector_list, base.head) {
  9439. connector->new_encoder =
  9440. to_intel_encoder(config->save_connector_encoders[count++]);
  9441. }
  9442. }
  9443. static bool
  9444. is_crtc_connector_off(struct drm_mode_set *set)
  9445. {
  9446. int i;
  9447. if (set->num_connectors == 0)
  9448. return false;
  9449. if (WARN_ON(set->connectors == NULL))
  9450. return false;
  9451. for (i = 0; i < set->num_connectors; i++)
  9452. if (set->connectors[i]->encoder &&
  9453. set->connectors[i]->encoder->crtc == set->crtc &&
  9454. set->connectors[i]->dpms != DRM_MODE_DPMS_ON)
  9455. return true;
  9456. return false;
  9457. }
  9458. static void
  9459. intel_set_config_compute_mode_changes(struct drm_mode_set *set,
  9460. struct intel_set_config *config)
  9461. {
  9462. /* We should be able to check here if the fb has the same properties
  9463. * and then just flip_or_move it */
  9464. if (is_crtc_connector_off(set)) {
  9465. config->mode_changed = true;
  9466. } else if (set->crtc->primary->fb != set->fb) {
  9467. /*
  9468. * If we have no fb, we can only flip as long as the crtc is
  9469. * active, otherwise we need a full mode set. The crtc may
  9470. * be active if we've only disabled the primary plane, or
  9471. * in fastboot situations.
  9472. */
  9473. if (set->crtc->primary->fb == NULL) {
  9474. struct intel_crtc *intel_crtc =
  9475. to_intel_crtc(set->crtc);
  9476. if (intel_crtc->active) {
  9477. DRM_DEBUG_KMS("crtc has no fb, will flip\n");
  9478. config->fb_changed = true;
  9479. } else {
  9480. DRM_DEBUG_KMS("inactive crtc, full mode set\n");
  9481. config->mode_changed = true;
  9482. }
  9483. } else if (set->fb == NULL) {
  9484. config->mode_changed = true;
  9485. } else if (set->fb->pixel_format !=
  9486. set->crtc->primary->fb->pixel_format) {
  9487. config->mode_changed = true;
  9488. } else {
  9489. config->fb_changed = true;
  9490. }
  9491. }
  9492. if (set->fb && (set->x != set->crtc->x || set->y != set->crtc->y))
  9493. config->fb_changed = true;
  9494. if (set->mode && !drm_mode_equal(set->mode, &set->crtc->mode)) {
  9495. DRM_DEBUG_KMS("modes are different, full mode set\n");
  9496. drm_mode_debug_printmodeline(&set->crtc->mode);
  9497. drm_mode_debug_printmodeline(set->mode);
  9498. config->mode_changed = true;
  9499. }
  9500. DRM_DEBUG_KMS("computed changes for [CRTC:%d], mode_changed=%d, fb_changed=%d\n",
  9501. set->crtc->base.id, config->mode_changed, config->fb_changed);
  9502. }
  9503. static int
  9504. intel_modeset_stage_output_state(struct drm_device *dev,
  9505. struct drm_mode_set *set,
  9506. struct intel_set_config *config)
  9507. {
  9508. struct intel_connector *connector;
  9509. struct intel_encoder *encoder;
  9510. struct intel_crtc *crtc;
  9511. int ro;
  9512. /* The upper layers ensure that we either disable a crtc or have a list
  9513. * of connectors. For paranoia, double-check this. */
  9514. WARN_ON(!set->fb && (set->num_connectors != 0));
  9515. WARN_ON(set->fb && (set->num_connectors == 0));
  9516. list_for_each_entry(connector, &dev->mode_config.connector_list,
  9517. base.head) {
  9518. /* Otherwise traverse passed in connector list and get encoders
  9519. * for them. */
  9520. for (ro = 0; ro < set->num_connectors; ro++) {
  9521. if (set->connectors[ro] == &connector->base) {
  9522. connector->new_encoder = intel_find_encoder(connector, to_intel_crtc(set->crtc)->pipe);
  9523. break;
  9524. }
  9525. }
  9526. /* If we disable the crtc, disable all its connectors. Also, if
  9527. * the connector is on the changing crtc but not on the new
  9528. * connector list, disable it. */
  9529. if ((!set->fb || ro == set->num_connectors) &&
  9530. connector->base.encoder &&
  9531. connector->base.encoder->crtc == set->crtc) {
  9532. connector->new_encoder = NULL;
  9533. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n",
  9534. connector->base.base.id,
  9535. connector->base.name);
  9536. }
  9537. if (&connector->new_encoder->base != connector->base.encoder) {
  9538. DRM_DEBUG_KMS("encoder changed, full mode switch\n");
  9539. config->mode_changed = true;
  9540. }
  9541. }
  9542. /* connector->new_encoder is now updated for all connectors. */
  9543. /* Update crtc of enabled connectors. */
  9544. list_for_each_entry(connector, &dev->mode_config.connector_list,
  9545. base.head) {
  9546. struct drm_crtc *new_crtc;
  9547. if (!connector->new_encoder)
  9548. continue;
  9549. new_crtc = connector->new_encoder->base.crtc;
  9550. for (ro = 0; ro < set->num_connectors; ro++) {
  9551. if (set->connectors[ro] == &connector->base)
  9552. new_crtc = set->crtc;
  9553. }
  9554. /* Make sure the new CRTC will work with the encoder */
  9555. if (!drm_encoder_crtc_ok(&connector->new_encoder->base,
  9556. new_crtc)) {
  9557. return -EINVAL;
  9558. }
  9559. connector->new_encoder->new_crtc = to_intel_crtc(new_crtc);
  9560. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n",
  9561. connector->base.base.id,
  9562. connector->base.name,
  9563. new_crtc->base.id);
  9564. }
  9565. /* Check for any encoders that needs to be disabled. */
  9566. for_each_intel_encoder(dev, encoder) {
  9567. int num_connectors = 0;
  9568. list_for_each_entry(connector,
  9569. &dev->mode_config.connector_list,
  9570. base.head) {
  9571. if (connector->new_encoder == encoder) {
  9572. WARN_ON(!connector->new_encoder->new_crtc);
  9573. num_connectors++;
  9574. }
  9575. }
  9576. if (num_connectors == 0)
  9577. encoder->new_crtc = NULL;
  9578. else if (num_connectors > 1)
  9579. return -EINVAL;
  9580. /* Only now check for crtc changes so we don't miss encoders
  9581. * that will be disabled. */
  9582. if (&encoder->new_crtc->base != encoder->base.crtc) {
  9583. DRM_DEBUG_KMS("crtc changed, full mode switch\n");
  9584. config->mode_changed = true;
  9585. }
  9586. }
  9587. /* Now we've also updated encoder->new_crtc for all encoders. */
  9588. list_for_each_entry(connector, &dev->mode_config.connector_list,
  9589. base.head) {
  9590. if (connector->new_encoder)
  9591. if (connector->new_encoder != connector->encoder)
  9592. connector->encoder = connector->new_encoder;
  9593. }
  9594. for_each_intel_crtc(dev, crtc) {
  9595. crtc->new_enabled = false;
  9596. for_each_intel_encoder(dev, encoder) {
  9597. if (encoder->new_crtc == crtc) {
  9598. crtc->new_enabled = true;
  9599. break;
  9600. }
  9601. }
  9602. if (crtc->new_enabled != crtc->base.enabled) {
  9603. DRM_DEBUG_KMS("crtc %sabled, full mode switch\n",
  9604. crtc->new_enabled ? "en" : "dis");
  9605. config->mode_changed = true;
  9606. }
  9607. if (crtc->new_enabled)
  9608. crtc->new_config = &crtc->config;
  9609. else
  9610. crtc->new_config = NULL;
  9611. }
  9612. return 0;
  9613. }
  9614. static void disable_crtc_nofb(struct intel_crtc *crtc)
  9615. {
  9616. struct drm_device *dev = crtc->base.dev;
  9617. struct intel_encoder *encoder;
  9618. struct intel_connector *connector;
  9619. DRM_DEBUG_KMS("Trying to restore without FB -> disabling pipe %c\n",
  9620. pipe_name(crtc->pipe));
  9621. list_for_each_entry(connector, &dev->mode_config.connector_list, base.head) {
  9622. if (connector->new_encoder &&
  9623. connector->new_encoder->new_crtc == crtc)
  9624. connector->new_encoder = NULL;
  9625. }
  9626. for_each_intel_encoder(dev, encoder) {
  9627. if (encoder->new_crtc == crtc)
  9628. encoder->new_crtc = NULL;
  9629. }
  9630. crtc->new_enabled = false;
  9631. crtc->new_config = NULL;
  9632. }
  9633. static int intel_crtc_set_config(struct drm_mode_set *set)
  9634. {
  9635. struct drm_device *dev;
  9636. struct drm_mode_set save_set;
  9637. struct intel_set_config *config;
  9638. int ret;
  9639. BUG_ON(!set);
  9640. BUG_ON(!set->crtc);
  9641. BUG_ON(!set->crtc->helper_private);
  9642. /* Enforce sane interface api - has been abused by the fb helper. */
  9643. BUG_ON(!set->mode && set->fb);
  9644. BUG_ON(set->fb && set->num_connectors == 0);
  9645. if (set->fb) {
  9646. DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n",
  9647. set->crtc->base.id, set->fb->base.id,
  9648. (int)set->num_connectors, set->x, set->y);
  9649. } else {
  9650. DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set->crtc->base.id);
  9651. }
  9652. dev = set->crtc->dev;
  9653. ret = -ENOMEM;
  9654. config = kzalloc(sizeof(*config), GFP_KERNEL);
  9655. if (!config)
  9656. goto out_config;
  9657. ret = intel_set_config_save_state(dev, config);
  9658. if (ret)
  9659. goto out_config;
  9660. save_set.crtc = set->crtc;
  9661. save_set.mode = &set->crtc->mode;
  9662. save_set.x = set->crtc->x;
  9663. save_set.y = set->crtc->y;
  9664. save_set.fb = set->crtc->primary->fb;
  9665. /* Compute whether we need a full modeset, only an fb base update or no
  9666. * change at all. In the future we might also check whether only the
  9667. * mode changed, e.g. for LVDS where we only change the panel fitter in
  9668. * such cases. */
  9669. intel_set_config_compute_mode_changes(set, config);
  9670. ret = intel_modeset_stage_output_state(dev, set, config);
  9671. if (ret)
  9672. goto fail;
  9673. if (config->mode_changed) {
  9674. ret = intel_set_mode(set->crtc, set->mode,
  9675. set->x, set->y, set->fb);
  9676. } else if (config->fb_changed) {
  9677. struct intel_crtc *intel_crtc = to_intel_crtc(set->crtc);
  9678. intel_crtc_wait_for_pending_flips(set->crtc);
  9679. ret = intel_pipe_set_base(set->crtc,
  9680. set->x, set->y, set->fb);
  9681. /*
  9682. * We need to make sure the primary plane is re-enabled if it
  9683. * has previously been turned off.
  9684. */
  9685. if (!intel_crtc->primary_enabled && ret == 0) {
  9686. WARN_ON(!intel_crtc->active);
  9687. intel_enable_primary_hw_plane(set->crtc->primary, set->crtc);
  9688. }
  9689. /*
  9690. * In the fastboot case this may be our only check of the
  9691. * state after boot. It would be better to only do it on
  9692. * the first update, but we don't have a nice way of doing that
  9693. * (and really, set_config isn't used much for high freq page
  9694. * flipping, so increasing its cost here shouldn't be a big
  9695. * deal).
  9696. */
  9697. if (i915.fastboot && ret == 0)
  9698. intel_modeset_check_state(set->crtc->dev);
  9699. }
  9700. if (ret) {
  9701. DRM_DEBUG_KMS("failed to set mode on [CRTC:%d], err = %d\n",
  9702. set->crtc->base.id, ret);
  9703. fail:
  9704. intel_set_config_restore_state(dev, config);
  9705. /*
  9706. * HACK: if the pipe was on, but we didn't have a framebuffer,
  9707. * force the pipe off to avoid oopsing in the modeset code
  9708. * due to fb==NULL. This should only happen during boot since
  9709. * we don't yet reconstruct the FB from the hardware state.
  9710. */
  9711. if (to_intel_crtc(save_set.crtc)->new_enabled && !save_set.fb)
  9712. disable_crtc_nofb(to_intel_crtc(save_set.crtc));
  9713. /* Try to restore the config */
  9714. if (config->mode_changed &&
  9715. intel_set_mode(save_set.crtc, save_set.mode,
  9716. save_set.x, save_set.y, save_set.fb))
  9717. DRM_ERROR("failed to restore config after modeset failure\n");
  9718. }
  9719. out_config:
  9720. intel_set_config_free(config);
  9721. return ret;
  9722. }
  9723. static const struct drm_crtc_funcs intel_crtc_funcs = {
  9724. .gamma_set = intel_crtc_gamma_set,
  9725. .set_config = intel_crtc_set_config,
  9726. .destroy = intel_crtc_destroy,
  9727. .page_flip = intel_crtc_page_flip,
  9728. };
  9729. static bool ibx_pch_dpll_get_hw_state(struct drm_i915_private *dev_priv,
  9730. struct intel_shared_dpll *pll,
  9731. struct intel_dpll_hw_state *hw_state)
  9732. {
  9733. uint32_t val;
  9734. if (!intel_display_power_enabled(dev_priv, POWER_DOMAIN_PLLS))
  9735. return false;
  9736. val = I915_READ(PCH_DPLL(pll->id));
  9737. hw_state->dpll = val;
  9738. hw_state->fp0 = I915_READ(PCH_FP0(pll->id));
  9739. hw_state->fp1 = I915_READ(PCH_FP1(pll->id));
  9740. return val & DPLL_VCO_ENABLE;
  9741. }
  9742. static void ibx_pch_dpll_mode_set(struct drm_i915_private *dev_priv,
  9743. struct intel_shared_dpll *pll)
  9744. {
  9745. I915_WRITE(PCH_FP0(pll->id), pll->hw_state.fp0);
  9746. I915_WRITE(PCH_FP1(pll->id), pll->hw_state.fp1);
  9747. }
  9748. static void ibx_pch_dpll_enable(struct drm_i915_private *dev_priv,
  9749. struct intel_shared_dpll *pll)
  9750. {
  9751. /* PCH refclock must be enabled first */
  9752. ibx_assert_pch_refclk_enabled(dev_priv);
  9753. I915_WRITE(PCH_DPLL(pll->id), pll->hw_state.dpll);
  9754. /* Wait for the clocks to stabilize. */
  9755. POSTING_READ(PCH_DPLL(pll->id));
  9756. udelay(150);
  9757. /* The pixel multiplier can only be updated once the
  9758. * DPLL is enabled and the clocks are stable.
  9759. *
  9760. * So write it again.
  9761. */
  9762. I915_WRITE(PCH_DPLL(pll->id), pll->hw_state.dpll);
  9763. POSTING_READ(PCH_DPLL(pll->id));
  9764. udelay(200);
  9765. }
  9766. static void ibx_pch_dpll_disable(struct drm_i915_private *dev_priv,
  9767. struct intel_shared_dpll *pll)
  9768. {
  9769. struct drm_device *dev = dev_priv->dev;
  9770. struct intel_crtc *crtc;
  9771. /* Make sure no transcoder isn't still depending on us. */
  9772. for_each_intel_crtc(dev, crtc) {
  9773. if (intel_crtc_to_shared_dpll(crtc) == pll)
  9774. assert_pch_transcoder_disabled(dev_priv, crtc->pipe);
  9775. }
  9776. I915_WRITE(PCH_DPLL(pll->id), 0);
  9777. POSTING_READ(PCH_DPLL(pll->id));
  9778. udelay(200);
  9779. }
  9780. static char *ibx_pch_dpll_names[] = {
  9781. "PCH DPLL A",
  9782. "PCH DPLL B",
  9783. };
  9784. static void ibx_pch_dpll_init(struct drm_device *dev)
  9785. {
  9786. struct drm_i915_private *dev_priv = dev->dev_private;
  9787. int i;
  9788. dev_priv->num_shared_dpll = 2;
  9789. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  9790. dev_priv->shared_dplls[i].id = i;
  9791. dev_priv->shared_dplls[i].name = ibx_pch_dpll_names[i];
  9792. dev_priv->shared_dplls[i].mode_set = ibx_pch_dpll_mode_set;
  9793. dev_priv->shared_dplls[i].enable = ibx_pch_dpll_enable;
  9794. dev_priv->shared_dplls[i].disable = ibx_pch_dpll_disable;
  9795. dev_priv->shared_dplls[i].get_hw_state =
  9796. ibx_pch_dpll_get_hw_state;
  9797. }
  9798. }
  9799. static void intel_shared_dpll_init(struct drm_device *dev)
  9800. {
  9801. struct drm_i915_private *dev_priv = dev->dev_private;
  9802. if (HAS_DDI(dev))
  9803. intel_ddi_pll_init(dev);
  9804. else if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
  9805. ibx_pch_dpll_init(dev);
  9806. else
  9807. dev_priv->num_shared_dpll = 0;
  9808. BUG_ON(dev_priv->num_shared_dpll > I915_NUM_PLLS);
  9809. }
  9810. static int
  9811. intel_primary_plane_disable(struct drm_plane *plane)
  9812. {
  9813. struct drm_device *dev = plane->dev;
  9814. struct intel_crtc *intel_crtc;
  9815. if (!plane->fb)
  9816. return 0;
  9817. BUG_ON(!plane->crtc);
  9818. intel_crtc = to_intel_crtc(plane->crtc);
  9819. /*
  9820. * Even though we checked plane->fb above, it's still possible that
  9821. * the primary plane has been implicitly disabled because the crtc
  9822. * coordinates given weren't visible, or because we detected
  9823. * that it was 100% covered by a sprite plane. Or, the CRTC may be
  9824. * off and we've set a fb, but haven't actually turned on the CRTC yet.
  9825. * In either case, we need to unpin the FB and let the fb pointer get
  9826. * updated, but otherwise we don't need to touch the hardware.
  9827. */
  9828. if (!intel_crtc->primary_enabled)
  9829. goto disable_unpin;
  9830. intel_crtc_wait_for_pending_flips(plane->crtc);
  9831. intel_disable_primary_hw_plane(plane, plane->crtc);
  9832. disable_unpin:
  9833. mutex_lock(&dev->struct_mutex);
  9834. i915_gem_track_fb(intel_fb_obj(plane->fb), NULL,
  9835. INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe));
  9836. intel_unpin_fb_obj(intel_fb_obj(plane->fb));
  9837. mutex_unlock(&dev->struct_mutex);
  9838. plane->fb = NULL;
  9839. return 0;
  9840. }
  9841. static int
  9842. intel_check_primary_plane(struct drm_plane *plane,
  9843. struct intel_plane_state *state)
  9844. {
  9845. struct drm_crtc *crtc = state->crtc;
  9846. struct drm_framebuffer *fb = state->fb;
  9847. struct drm_rect *dest = &state->dst;
  9848. struct drm_rect *src = &state->src;
  9849. const struct drm_rect *clip = &state->clip;
  9850. return drm_plane_helper_check_update(plane, crtc, fb,
  9851. src, dest, clip,
  9852. DRM_PLANE_HELPER_NO_SCALING,
  9853. DRM_PLANE_HELPER_NO_SCALING,
  9854. false, true, &state->visible);
  9855. }
  9856. static int
  9857. intel_commit_primary_plane(struct drm_plane *plane,
  9858. struct intel_plane_state *state)
  9859. {
  9860. struct drm_crtc *crtc = state->crtc;
  9861. struct drm_framebuffer *fb = state->fb;
  9862. struct drm_device *dev = crtc->dev;
  9863. struct drm_i915_private *dev_priv = dev->dev_private;
  9864. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  9865. struct drm_i915_gem_object *obj = intel_fb_obj(fb);
  9866. struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->fb);
  9867. struct intel_plane *intel_plane = to_intel_plane(plane);
  9868. struct drm_rect *src = &state->src;
  9869. int ret;
  9870. intel_crtc_wait_for_pending_flips(crtc);
  9871. /*
  9872. * If clipping results in a non-visible primary plane, we'll disable
  9873. * the primary plane. Note that this is a bit different than what
  9874. * happens if userspace explicitly disables the plane by passing fb=0
  9875. * because plane->fb still gets set and pinned.
  9876. */
  9877. if (!state->visible) {
  9878. mutex_lock(&dev->struct_mutex);
  9879. /*
  9880. * Try to pin the new fb first so that we can bail out if we
  9881. * fail.
  9882. */
  9883. if (plane->fb != fb) {
  9884. ret = intel_pin_and_fence_fb_obj(dev, obj, NULL);
  9885. if (ret) {
  9886. mutex_unlock(&dev->struct_mutex);
  9887. return ret;
  9888. }
  9889. }
  9890. i915_gem_track_fb(old_obj, obj,
  9891. INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe));
  9892. if (intel_crtc->primary_enabled)
  9893. intel_disable_primary_hw_plane(plane, crtc);
  9894. if (plane->fb != fb)
  9895. if (plane->fb)
  9896. intel_unpin_fb_obj(old_obj);
  9897. mutex_unlock(&dev->struct_mutex);
  9898. } else {
  9899. if (intel_crtc && intel_crtc->active &&
  9900. intel_crtc->primary_enabled) {
  9901. /*
  9902. * FBC does not work on some platforms for rotated
  9903. * planes, so disable it when rotation is not 0 and
  9904. * update it when rotation is set back to 0.
  9905. *
  9906. * FIXME: This is redundant with the fbc update done in
  9907. * the primary plane enable function except that that
  9908. * one is done too late. We eventually need to unify
  9909. * this.
  9910. */
  9911. if (INTEL_INFO(dev)->gen <= 4 && !IS_G4X(dev) &&
  9912. dev_priv->fbc.plane == intel_crtc->plane &&
  9913. intel_plane->rotation != BIT(DRM_ROTATE_0)) {
  9914. intel_disable_fbc(dev);
  9915. }
  9916. }
  9917. ret = intel_pipe_set_base(crtc, src->x1, src->y1, fb);
  9918. if (ret)
  9919. return ret;
  9920. if (!intel_crtc->primary_enabled)
  9921. intel_enable_primary_hw_plane(plane, crtc);
  9922. }
  9923. intel_plane->crtc_x = state->orig_dst.x1;
  9924. intel_plane->crtc_y = state->orig_dst.y1;
  9925. intel_plane->crtc_w = drm_rect_width(&state->orig_dst);
  9926. intel_plane->crtc_h = drm_rect_height(&state->orig_dst);
  9927. intel_plane->src_x = state->orig_src.x1;
  9928. intel_plane->src_y = state->orig_src.y1;
  9929. intel_plane->src_w = drm_rect_width(&state->orig_src);
  9930. intel_plane->src_h = drm_rect_height(&state->orig_src);
  9931. intel_plane->obj = obj;
  9932. return 0;
  9933. }
  9934. static int
  9935. intel_primary_plane_setplane(struct drm_plane *plane, struct drm_crtc *crtc,
  9936. struct drm_framebuffer *fb, int crtc_x, int crtc_y,
  9937. unsigned int crtc_w, unsigned int crtc_h,
  9938. uint32_t src_x, uint32_t src_y,
  9939. uint32_t src_w, uint32_t src_h)
  9940. {
  9941. struct intel_plane_state state;
  9942. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  9943. int ret;
  9944. state.crtc = crtc;
  9945. state.fb = fb;
  9946. /* sample coordinates in 16.16 fixed point */
  9947. state.src.x1 = src_x;
  9948. state.src.x2 = src_x + src_w;
  9949. state.src.y1 = src_y;
  9950. state.src.y2 = src_y + src_h;
  9951. /* integer pixels */
  9952. state.dst.x1 = crtc_x;
  9953. state.dst.x2 = crtc_x + crtc_w;
  9954. state.dst.y1 = crtc_y;
  9955. state.dst.y2 = crtc_y + crtc_h;
  9956. state.clip.x1 = 0;
  9957. state.clip.y1 = 0;
  9958. state.clip.x2 = intel_crtc->active ? intel_crtc->config.pipe_src_w : 0;
  9959. state.clip.y2 = intel_crtc->active ? intel_crtc->config.pipe_src_h : 0;
  9960. state.orig_src = state.src;
  9961. state.orig_dst = state.dst;
  9962. ret = intel_check_primary_plane(plane, &state);
  9963. if (ret)
  9964. return ret;
  9965. intel_commit_primary_plane(plane, &state);
  9966. return 0;
  9967. }
  9968. /* Common destruction function for both primary and cursor planes */
  9969. static void intel_plane_destroy(struct drm_plane *plane)
  9970. {
  9971. struct intel_plane *intel_plane = to_intel_plane(plane);
  9972. drm_plane_cleanup(plane);
  9973. kfree(intel_plane);
  9974. }
  9975. static const struct drm_plane_funcs intel_primary_plane_funcs = {
  9976. .update_plane = intel_primary_plane_setplane,
  9977. .disable_plane = intel_primary_plane_disable,
  9978. .destroy = intel_plane_destroy,
  9979. .set_property = intel_plane_set_property
  9980. };
  9981. static struct drm_plane *intel_primary_plane_create(struct drm_device *dev,
  9982. int pipe)
  9983. {
  9984. struct intel_plane *primary;
  9985. const uint32_t *intel_primary_formats;
  9986. int num_formats;
  9987. primary = kzalloc(sizeof(*primary), GFP_KERNEL);
  9988. if (primary == NULL)
  9989. return NULL;
  9990. primary->can_scale = false;
  9991. primary->max_downscale = 1;
  9992. primary->pipe = pipe;
  9993. primary->plane = pipe;
  9994. primary->rotation = BIT(DRM_ROTATE_0);
  9995. if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4)
  9996. primary->plane = !pipe;
  9997. if (INTEL_INFO(dev)->gen <= 3) {
  9998. intel_primary_formats = intel_primary_formats_gen2;
  9999. num_formats = ARRAY_SIZE(intel_primary_formats_gen2);
  10000. } else {
  10001. intel_primary_formats = intel_primary_formats_gen4;
  10002. num_formats = ARRAY_SIZE(intel_primary_formats_gen4);
  10003. }
  10004. drm_universal_plane_init(dev, &primary->base, 0,
  10005. &intel_primary_plane_funcs,
  10006. intel_primary_formats, num_formats,
  10007. DRM_PLANE_TYPE_PRIMARY);
  10008. if (INTEL_INFO(dev)->gen >= 4) {
  10009. if (!dev->mode_config.rotation_property)
  10010. dev->mode_config.rotation_property =
  10011. drm_mode_create_rotation_property(dev,
  10012. BIT(DRM_ROTATE_0) |
  10013. BIT(DRM_ROTATE_180));
  10014. if (dev->mode_config.rotation_property)
  10015. drm_object_attach_property(&primary->base.base,
  10016. dev->mode_config.rotation_property,
  10017. primary->rotation);
  10018. }
  10019. return &primary->base;
  10020. }
  10021. static int
  10022. intel_cursor_plane_disable(struct drm_plane *plane)
  10023. {
  10024. if (!plane->fb)
  10025. return 0;
  10026. BUG_ON(!plane->crtc);
  10027. return intel_crtc_cursor_set_obj(plane->crtc, NULL, 0, 0);
  10028. }
  10029. static int
  10030. intel_check_cursor_plane(struct drm_plane *plane,
  10031. struct intel_plane_state *state)
  10032. {
  10033. struct drm_crtc *crtc = state->crtc;
  10034. struct drm_framebuffer *fb = state->fb;
  10035. struct drm_rect *dest = &state->dst;
  10036. struct drm_rect *src = &state->src;
  10037. const struct drm_rect *clip = &state->clip;
  10038. return drm_plane_helper_check_update(plane, crtc, fb,
  10039. src, dest, clip,
  10040. DRM_PLANE_HELPER_NO_SCALING,
  10041. DRM_PLANE_HELPER_NO_SCALING,
  10042. true, true, &state->visible);
  10043. }
  10044. static int
  10045. intel_commit_cursor_plane(struct drm_plane *plane,
  10046. struct intel_plane_state *state)
  10047. {
  10048. struct drm_crtc *crtc = state->crtc;
  10049. struct drm_framebuffer *fb = state->fb;
  10050. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  10051. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  10052. struct drm_i915_gem_object *obj = intel_fb->obj;
  10053. int crtc_w, crtc_h;
  10054. crtc->cursor_x = state->orig_dst.x1;
  10055. crtc->cursor_y = state->orig_dst.y1;
  10056. if (fb != crtc->cursor->fb) {
  10057. crtc_w = drm_rect_width(&state->orig_dst);
  10058. crtc_h = drm_rect_height(&state->orig_dst);
  10059. return intel_crtc_cursor_set_obj(crtc, obj, crtc_w, crtc_h);
  10060. } else {
  10061. intel_crtc_update_cursor(crtc, state->visible);
  10062. intel_frontbuffer_flip(crtc->dev,
  10063. INTEL_FRONTBUFFER_CURSOR(intel_crtc->pipe));
  10064. return 0;
  10065. }
  10066. }
  10067. static int
  10068. intel_cursor_plane_update(struct drm_plane *plane, struct drm_crtc *crtc,
  10069. struct drm_framebuffer *fb, int crtc_x, int crtc_y,
  10070. unsigned int crtc_w, unsigned int crtc_h,
  10071. uint32_t src_x, uint32_t src_y,
  10072. uint32_t src_w, uint32_t src_h)
  10073. {
  10074. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  10075. struct intel_plane_state state;
  10076. int ret;
  10077. state.crtc = crtc;
  10078. state.fb = fb;
  10079. /* sample coordinates in 16.16 fixed point */
  10080. state.src.x1 = src_x;
  10081. state.src.x2 = src_x + src_w;
  10082. state.src.y1 = src_y;
  10083. state.src.y2 = src_y + src_h;
  10084. /* integer pixels */
  10085. state.dst.x1 = crtc_x;
  10086. state.dst.x2 = crtc_x + crtc_w;
  10087. state.dst.y1 = crtc_y;
  10088. state.dst.y2 = crtc_y + crtc_h;
  10089. state.clip.x1 = 0;
  10090. state.clip.y1 = 0;
  10091. state.clip.x2 = intel_crtc->active ? intel_crtc->config.pipe_src_w : 0;
  10092. state.clip.y2 = intel_crtc->active ? intel_crtc->config.pipe_src_h : 0;
  10093. state.orig_src = state.src;
  10094. state.orig_dst = state.dst;
  10095. ret = intel_check_cursor_plane(plane, &state);
  10096. if (ret)
  10097. return ret;
  10098. return intel_commit_cursor_plane(plane, &state);
  10099. }
  10100. static const struct drm_plane_funcs intel_cursor_plane_funcs = {
  10101. .update_plane = intel_cursor_plane_update,
  10102. .disable_plane = intel_cursor_plane_disable,
  10103. .destroy = intel_plane_destroy,
  10104. };
  10105. static struct drm_plane *intel_cursor_plane_create(struct drm_device *dev,
  10106. int pipe)
  10107. {
  10108. struct intel_plane *cursor;
  10109. cursor = kzalloc(sizeof(*cursor), GFP_KERNEL);
  10110. if (cursor == NULL)
  10111. return NULL;
  10112. cursor->can_scale = false;
  10113. cursor->max_downscale = 1;
  10114. cursor->pipe = pipe;
  10115. cursor->plane = pipe;
  10116. drm_universal_plane_init(dev, &cursor->base, 0,
  10117. &intel_cursor_plane_funcs,
  10118. intel_cursor_formats,
  10119. ARRAY_SIZE(intel_cursor_formats),
  10120. DRM_PLANE_TYPE_CURSOR);
  10121. return &cursor->base;
  10122. }
  10123. static void intel_crtc_init(struct drm_device *dev, int pipe)
  10124. {
  10125. struct drm_i915_private *dev_priv = dev->dev_private;
  10126. struct intel_crtc *intel_crtc;
  10127. struct drm_plane *primary = NULL;
  10128. struct drm_plane *cursor = NULL;
  10129. int i, ret;
  10130. intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL);
  10131. if (intel_crtc == NULL)
  10132. return;
  10133. primary = intel_primary_plane_create(dev, pipe);
  10134. if (!primary)
  10135. goto fail;
  10136. cursor = intel_cursor_plane_create(dev, pipe);
  10137. if (!cursor)
  10138. goto fail;
  10139. ret = drm_crtc_init_with_planes(dev, &intel_crtc->base, primary,
  10140. cursor, &intel_crtc_funcs);
  10141. if (ret)
  10142. goto fail;
  10143. drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256);
  10144. for (i = 0; i < 256; i++) {
  10145. intel_crtc->lut_r[i] = i;
  10146. intel_crtc->lut_g[i] = i;
  10147. intel_crtc->lut_b[i] = i;
  10148. }
  10149. /*
  10150. * On gen2/3 only plane A can do fbc, but the panel fitter and lvds port
  10151. * is hooked to pipe B. Hence we want plane A feeding pipe B.
  10152. */
  10153. intel_crtc->pipe = pipe;
  10154. intel_crtc->plane = pipe;
  10155. if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) {
  10156. DRM_DEBUG_KMS("swapping pipes & planes for FBC\n");
  10157. intel_crtc->plane = !pipe;
  10158. }
  10159. intel_crtc->cursor_base = ~0;
  10160. intel_crtc->cursor_cntl = ~0;
  10161. intel_crtc->cursor_size = ~0;
  10162. BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
  10163. dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL);
  10164. dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base;
  10165. dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base;
  10166. drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
  10167. WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe);
  10168. return;
  10169. fail:
  10170. if (primary)
  10171. drm_plane_cleanup(primary);
  10172. if (cursor)
  10173. drm_plane_cleanup(cursor);
  10174. kfree(intel_crtc);
  10175. }
  10176. enum pipe intel_get_pipe_from_connector(struct intel_connector *connector)
  10177. {
  10178. struct drm_encoder *encoder = connector->base.encoder;
  10179. struct drm_device *dev = connector->base.dev;
  10180. WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
  10181. if (!encoder)
  10182. return INVALID_PIPE;
  10183. return to_intel_crtc(encoder->crtc)->pipe;
  10184. }
  10185. int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data,
  10186. struct drm_file *file)
  10187. {
  10188. struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
  10189. struct drm_crtc *drmmode_crtc;
  10190. struct intel_crtc *crtc;
  10191. if (!drm_core_check_feature(dev, DRIVER_MODESET))
  10192. return -ENODEV;
  10193. drmmode_crtc = drm_crtc_find(dev, pipe_from_crtc_id->crtc_id);
  10194. if (!drmmode_crtc) {
  10195. DRM_ERROR("no such CRTC id\n");
  10196. return -ENOENT;
  10197. }
  10198. crtc = to_intel_crtc(drmmode_crtc);
  10199. pipe_from_crtc_id->pipe = crtc->pipe;
  10200. return 0;
  10201. }
  10202. static int intel_encoder_clones(struct intel_encoder *encoder)
  10203. {
  10204. struct drm_device *dev = encoder->base.dev;
  10205. struct intel_encoder *source_encoder;
  10206. int index_mask = 0;
  10207. int entry = 0;
  10208. for_each_intel_encoder(dev, source_encoder) {
  10209. if (encoders_cloneable(encoder, source_encoder))
  10210. index_mask |= (1 << entry);
  10211. entry++;
  10212. }
  10213. return index_mask;
  10214. }
  10215. static bool has_edp_a(struct drm_device *dev)
  10216. {
  10217. struct drm_i915_private *dev_priv = dev->dev_private;
  10218. if (!IS_MOBILE(dev))
  10219. return false;
  10220. if ((I915_READ(DP_A) & DP_DETECTED) == 0)
  10221. return false;
  10222. if (IS_GEN5(dev) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE))
  10223. return false;
  10224. return true;
  10225. }
  10226. const char *intel_output_name(int output)
  10227. {
  10228. static const char *names[] = {
  10229. [INTEL_OUTPUT_UNUSED] = "Unused",
  10230. [INTEL_OUTPUT_ANALOG] = "Analog",
  10231. [INTEL_OUTPUT_DVO] = "DVO",
  10232. [INTEL_OUTPUT_SDVO] = "SDVO",
  10233. [INTEL_OUTPUT_LVDS] = "LVDS",
  10234. [INTEL_OUTPUT_TVOUT] = "TV",
  10235. [INTEL_OUTPUT_HDMI] = "HDMI",
  10236. [INTEL_OUTPUT_DISPLAYPORT] = "DisplayPort",
  10237. [INTEL_OUTPUT_EDP] = "eDP",
  10238. [INTEL_OUTPUT_DSI] = "DSI",
  10239. [INTEL_OUTPUT_UNKNOWN] = "Unknown",
  10240. };
  10241. if (output < 0 || output >= ARRAY_SIZE(names) || !names[output])
  10242. return "Invalid";
  10243. return names[output];
  10244. }
  10245. static bool intel_crt_present(struct drm_device *dev)
  10246. {
  10247. struct drm_i915_private *dev_priv = dev->dev_private;
  10248. if (IS_ULT(dev))
  10249. return false;
  10250. if (IS_CHERRYVIEW(dev))
  10251. return false;
  10252. if (IS_VALLEYVIEW(dev) && !dev_priv->vbt.int_crt_support)
  10253. return false;
  10254. return true;
  10255. }
  10256. static void intel_setup_outputs(struct drm_device *dev)
  10257. {
  10258. struct drm_i915_private *dev_priv = dev->dev_private;
  10259. struct intel_encoder *encoder;
  10260. bool dpd_is_edp = false;
  10261. intel_lvds_init(dev);
  10262. if (intel_crt_present(dev))
  10263. intel_crt_init(dev);
  10264. if (HAS_DDI(dev)) {
  10265. int found;
  10266. /* Haswell uses DDI functions to detect digital outputs */
  10267. found = I915_READ(DDI_BUF_CTL_A) & DDI_INIT_DISPLAY_DETECTED;
  10268. /* DDI A only supports eDP */
  10269. if (found)
  10270. intel_ddi_init(dev, PORT_A);
  10271. /* DDI B, C and D detection is indicated by the SFUSE_STRAP
  10272. * register */
  10273. found = I915_READ(SFUSE_STRAP);
  10274. if (found & SFUSE_STRAP_DDIB_DETECTED)
  10275. intel_ddi_init(dev, PORT_B);
  10276. if (found & SFUSE_STRAP_DDIC_DETECTED)
  10277. intel_ddi_init(dev, PORT_C);
  10278. if (found & SFUSE_STRAP_DDID_DETECTED)
  10279. intel_ddi_init(dev, PORT_D);
  10280. } else if (HAS_PCH_SPLIT(dev)) {
  10281. int found;
  10282. dpd_is_edp = intel_dp_is_edp(dev, PORT_D);
  10283. if (has_edp_a(dev))
  10284. intel_dp_init(dev, DP_A, PORT_A);
  10285. if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) {
  10286. /* PCH SDVOB multiplex with HDMIB */
  10287. found = intel_sdvo_init(dev, PCH_SDVOB, true);
  10288. if (!found)
  10289. intel_hdmi_init(dev, PCH_HDMIB, PORT_B);
  10290. if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
  10291. intel_dp_init(dev, PCH_DP_B, PORT_B);
  10292. }
  10293. if (I915_READ(PCH_HDMIC) & SDVO_DETECTED)
  10294. intel_hdmi_init(dev, PCH_HDMIC, PORT_C);
  10295. if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED)
  10296. intel_hdmi_init(dev, PCH_HDMID, PORT_D);
  10297. if (I915_READ(PCH_DP_C) & DP_DETECTED)
  10298. intel_dp_init(dev, PCH_DP_C, PORT_C);
  10299. if (I915_READ(PCH_DP_D) & DP_DETECTED)
  10300. intel_dp_init(dev, PCH_DP_D, PORT_D);
  10301. } else if (IS_VALLEYVIEW(dev)) {
  10302. if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIB) & SDVO_DETECTED) {
  10303. intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIB,
  10304. PORT_B);
  10305. if (I915_READ(VLV_DISPLAY_BASE + DP_B) & DP_DETECTED)
  10306. intel_dp_init(dev, VLV_DISPLAY_BASE + DP_B, PORT_B);
  10307. }
  10308. if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIC) & SDVO_DETECTED) {
  10309. intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIC,
  10310. PORT_C);
  10311. if (I915_READ(VLV_DISPLAY_BASE + DP_C) & DP_DETECTED)
  10312. intel_dp_init(dev, VLV_DISPLAY_BASE + DP_C, PORT_C);
  10313. }
  10314. if (IS_CHERRYVIEW(dev)) {
  10315. if (I915_READ(VLV_DISPLAY_BASE + CHV_HDMID) & SDVO_DETECTED) {
  10316. intel_hdmi_init(dev, VLV_DISPLAY_BASE + CHV_HDMID,
  10317. PORT_D);
  10318. if (I915_READ(VLV_DISPLAY_BASE + DP_D) & DP_DETECTED)
  10319. intel_dp_init(dev, VLV_DISPLAY_BASE + DP_D, PORT_D);
  10320. }
  10321. }
  10322. intel_dsi_init(dev);
  10323. } else if (SUPPORTS_DIGITAL_OUTPUTS(dev)) {
  10324. bool found = false;
  10325. if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
  10326. DRM_DEBUG_KMS("probing SDVOB\n");
  10327. found = intel_sdvo_init(dev, GEN3_SDVOB, true);
  10328. if (!found && SUPPORTS_INTEGRATED_HDMI(dev)) {
  10329. DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
  10330. intel_hdmi_init(dev, GEN4_HDMIB, PORT_B);
  10331. }
  10332. if (!found && SUPPORTS_INTEGRATED_DP(dev))
  10333. intel_dp_init(dev, DP_B, PORT_B);
  10334. }
  10335. /* Before G4X SDVOC doesn't have its own detect register */
  10336. if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
  10337. DRM_DEBUG_KMS("probing SDVOC\n");
  10338. found = intel_sdvo_init(dev, GEN3_SDVOC, false);
  10339. }
  10340. if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) {
  10341. if (SUPPORTS_INTEGRATED_HDMI(dev)) {
  10342. DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
  10343. intel_hdmi_init(dev, GEN4_HDMIC, PORT_C);
  10344. }
  10345. if (SUPPORTS_INTEGRATED_DP(dev))
  10346. intel_dp_init(dev, DP_C, PORT_C);
  10347. }
  10348. if (SUPPORTS_INTEGRATED_DP(dev) &&
  10349. (I915_READ(DP_D) & DP_DETECTED))
  10350. intel_dp_init(dev, DP_D, PORT_D);
  10351. } else if (IS_GEN2(dev))
  10352. intel_dvo_init(dev);
  10353. if (SUPPORTS_TV(dev))
  10354. intel_tv_init(dev);
  10355. intel_edp_psr_init(dev);
  10356. for_each_intel_encoder(dev, encoder) {
  10357. encoder->base.possible_crtcs = encoder->crtc_mask;
  10358. encoder->base.possible_clones =
  10359. intel_encoder_clones(encoder);
  10360. }
  10361. intel_init_pch_refclk(dev);
  10362. drm_helper_move_panel_connectors_to_head(dev);
  10363. }
  10364. static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
  10365. {
  10366. struct drm_device *dev = fb->dev;
  10367. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  10368. drm_framebuffer_cleanup(fb);
  10369. mutex_lock(&dev->struct_mutex);
  10370. WARN_ON(!intel_fb->obj->framebuffer_references--);
  10371. drm_gem_object_unreference(&intel_fb->obj->base);
  10372. mutex_unlock(&dev->struct_mutex);
  10373. kfree(intel_fb);
  10374. }
  10375. static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
  10376. struct drm_file *file,
  10377. unsigned int *handle)
  10378. {
  10379. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  10380. struct drm_i915_gem_object *obj = intel_fb->obj;
  10381. return drm_gem_handle_create(file, &obj->base, handle);
  10382. }
  10383. static const struct drm_framebuffer_funcs intel_fb_funcs = {
  10384. .destroy = intel_user_framebuffer_destroy,
  10385. .create_handle = intel_user_framebuffer_create_handle,
  10386. };
  10387. static int intel_framebuffer_init(struct drm_device *dev,
  10388. struct intel_framebuffer *intel_fb,
  10389. struct drm_mode_fb_cmd2 *mode_cmd,
  10390. struct drm_i915_gem_object *obj)
  10391. {
  10392. int aligned_height;
  10393. int pitch_limit;
  10394. int ret;
  10395. WARN_ON(!mutex_is_locked(&dev->struct_mutex));
  10396. if (obj->tiling_mode == I915_TILING_Y) {
  10397. DRM_DEBUG("hardware does not support tiling Y\n");
  10398. return -EINVAL;
  10399. }
  10400. if (mode_cmd->pitches[0] & 63) {
  10401. DRM_DEBUG("pitch (%d) must be at least 64 byte aligned\n",
  10402. mode_cmd->pitches[0]);
  10403. return -EINVAL;
  10404. }
  10405. if (INTEL_INFO(dev)->gen >= 5 && !IS_VALLEYVIEW(dev)) {
  10406. pitch_limit = 32*1024;
  10407. } else if (INTEL_INFO(dev)->gen >= 4) {
  10408. if (obj->tiling_mode)
  10409. pitch_limit = 16*1024;
  10410. else
  10411. pitch_limit = 32*1024;
  10412. } else if (INTEL_INFO(dev)->gen >= 3) {
  10413. if (obj->tiling_mode)
  10414. pitch_limit = 8*1024;
  10415. else
  10416. pitch_limit = 16*1024;
  10417. } else
  10418. /* XXX DSPC is limited to 4k tiled */
  10419. pitch_limit = 8*1024;
  10420. if (mode_cmd->pitches[0] > pitch_limit) {
  10421. DRM_DEBUG("%s pitch (%d) must be at less than %d\n",
  10422. obj->tiling_mode ? "tiled" : "linear",
  10423. mode_cmd->pitches[0], pitch_limit);
  10424. return -EINVAL;
  10425. }
  10426. if (obj->tiling_mode != I915_TILING_NONE &&
  10427. mode_cmd->pitches[0] != obj->stride) {
  10428. DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n",
  10429. mode_cmd->pitches[0], obj->stride);
  10430. return -EINVAL;
  10431. }
  10432. /* Reject formats not supported by any plane early. */
  10433. switch (mode_cmd->pixel_format) {
  10434. case DRM_FORMAT_C8:
  10435. case DRM_FORMAT_RGB565:
  10436. case DRM_FORMAT_XRGB8888:
  10437. case DRM_FORMAT_ARGB8888:
  10438. break;
  10439. case DRM_FORMAT_XRGB1555:
  10440. case DRM_FORMAT_ARGB1555:
  10441. if (INTEL_INFO(dev)->gen > 3) {
  10442. DRM_DEBUG("unsupported pixel format: %s\n",
  10443. drm_get_format_name(mode_cmd->pixel_format));
  10444. return -EINVAL;
  10445. }
  10446. break;
  10447. case DRM_FORMAT_XBGR8888:
  10448. case DRM_FORMAT_ABGR8888:
  10449. case DRM_FORMAT_XRGB2101010:
  10450. case DRM_FORMAT_ARGB2101010:
  10451. case DRM_FORMAT_XBGR2101010:
  10452. case DRM_FORMAT_ABGR2101010:
  10453. if (INTEL_INFO(dev)->gen < 4) {
  10454. DRM_DEBUG("unsupported pixel format: %s\n",
  10455. drm_get_format_name(mode_cmd->pixel_format));
  10456. return -EINVAL;
  10457. }
  10458. break;
  10459. case DRM_FORMAT_YUYV:
  10460. case DRM_FORMAT_UYVY:
  10461. case DRM_FORMAT_YVYU:
  10462. case DRM_FORMAT_VYUY:
  10463. if (INTEL_INFO(dev)->gen < 5) {
  10464. DRM_DEBUG("unsupported pixel format: %s\n",
  10465. drm_get_format_name(mode_cmd->pixel_format));
  10466. return -EINVAL;
  10467. }
  10468. break;
  10469. default:
  10470. DRM_DEBUG("unsupported pixel format: %s\n",
  10471. drm_get_format_name(mode_cmd->pixel_format));
  10472. return -EINVAL;
  10473. }
  10474. /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
  10475. if (mode_cmd->offsets[0] != 0)
  10476. return -EINVAL;
  10477. aligned_height = intel_align_height(dev, mode_cmd->height,
  10478. obj->tiling_mode);
  10479. /* FIXME drm helper for size checks (especially planar formats)? */
  10480. if (obj->base.size < aligned_height * mode_cmd->pitches[0])
  10481. return -EINVAL;
  10482. drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd);
  10483. intel_fb->obj = obj;
  10484. intel_fb->obj->framebuffer_references++;
  10485. ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs);
  10486. if (ret) {
  10487. DRM_ERROR("framebuffer init failed %d\n", ret);
  10488. return ret;
  10489. }
  10490. return 0;
  10491. }
  10492. static struct drm_framebuffer *
  10493. intel_user_framebuffer_create(struct drm_device *dev,
  10494. struct drm_file *filp,
  10495. struct drm_mode_fb_cmd2 *mode_cmd)
  10496. {
  10497. struct drm_i915_gem_object *obj;
  10498. obj = to_intel_bo(drm_gem_object_lookup(dev, filp,
  10499. mode_cmd->handles[0]));
  10500. if (&obj->base == NULL)
  10501. return ERR_PTR(-ENOENT);
  10502. return intel_framebuffer_create(dev, mode_cmd, obj);
  10503. }
  10504. #ifndef CONFIG_DRM_I915_FBDEV
  10505. static inline void intel_fbdev_output_poll_changed(struct drm_device *dev)
  10506. {
  10507. }
  10508. #endif
  10509. static const struct drm_mode_config_funcs intel_mode_funcs = {
  10510. .fb_create = intel_user_framebuffer_create,
  10511. .output_poll_changed = intel_fbdev_output_poll_changed,
  10512. };
  10513. /* Set up chip specific display functions */
  10514. static void intel_init_display(struct drm_device *dev)
  10515. {
  10516. struct drm_i915_private *dev_priv = dev->dev_private;
  10517. if (HAS_PCH_SPLIT(dev) || IS_G4X(dev))
  10518. dev_priv->display.find_dpll = g4x_find_best_dpll;
  10519. else if (IS_CHERRYVIEW(dev))
  10520. dev_priv->display.find_dpll = chv_find_best_dpll;
  10521. else if (IS_VALLEYVIEW(dev))
  10522. dev_priv->display.find_dpll = vlv_find_best_dpll;
  10523. else if (IS_PINEVIEW(dev))
  10524. dev_priv->display.find_dpll = pnv_find_best_dpll;
  10525. else
  10526. dev_priv->display.find_dpll = i9xx_find_best_dpll;
  10527. if (HAS_DDI(dev)) {
  10528. dev_priv->display.get_pipe_config = haswell_get_pipe_config;
  10529. dev_priv->display.get_plane_config = ironlake_get_plane_config;
  10530. dev_priv->display.crtc_mode_set = haswell_crtc_mode_set;
  10531. dev_priv->display.crtc_enable = haswell_crtc_enable;
  10532. dev_priv->display.crtc_disable = haswell_crtc_disable;
  10533. dev_priv->display.off = ironlake_crtc_off;
  10534. dev_priv->display.update_primary_plane =
  10535. ironlake_update_primary_plane;
  10536. } else if (HAS_PCH_SPLIT(dev)) {
  10537. dev_priv->display.get_pipe_config = ironlake_get_pipe_config;
  10538. dev_priv->display.get_plane_config = ironlake_get_plane_config;
  10539. dev_priv->display.crtc_mode_set = ironlake_crtc_mode_set;
  10540. dev_priv->display.crtc_enable = ironlake_crtc_enable;
  10541. dev_priv->display.crtc_disable = ironlake_crtc_disable;
  10542. dev_priv->display.off = ironlake_crtc_off;
  10543. dev_priv->display.update_primary_plane =
  10544. ironlake_update_primary_plane;
  10545. } else if (IS_VALLEYVIEW(dev)) {
  10546. dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
  10547. dev_priv->display.get_plane_config = i9xx_get_plane_config;
  10548. dev_priv->display.crtc_mode_set = i9xx_crtc_mode_set;
  10549. dev_priv->display.crtc_enable = valleyview_crtc_enable;
  10550. dev_priv->display.crtc_disable = i9xx_crtc_disable;
  10551. dev_priv->display.off = i9xx_crtc_off;
  10552. dev_priv->display.update_primary_plane =
  10553. i9xx_update_primary_plane;
  10554. } else {
  10555. dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
  10556. dev_priv->display.get_plane_config = i9xx_get_plane_config;
  10557. dev_priv->display.crtc_mode_set = i9xx_crtc_mode_set;
  10558. dev_priv->display.crtc_enable = i9xx_crtc_enable;
  10559. dev_priv->display.crtc_disable = i9xx_crtc_disable;
  10560. dev_priv->display.off = i9xx_crtc_off;
  10561. dev_priv->display.update_primary_plane =
  10562. i9xx_update_primary_plane;
  10563. }
  10564. /* Returns the core display clock speed */
  10565. if (IS_VALLEYVIEW(dev))
  10566. dev_priv->display.get_display_clock_speed =
  10567. valleyview_get_display_clock_speed;
  10568. else if (IS_I945G(dev) || (IS_G33(dev) && !IS_PINEVIEW_M(dev)))
  10569. dev_priv->display.get_display_clock_speed =
  10570. i945_get_display_clock_speed;
  10571. else if (IS_I915G(dev))
  10572. dev_priv->display.get_display_clock_speed =
  10573. i915_get_display_clock_speed;
  10574. else if (IS_I945GM(dev) || IS_845G(dev))
  10575. dev_priv->display.get_display_clock_speed =
  10576. i9xx_misc_get_display_clock_speed;
  10577. else if (IS_PINEVIEW(dev))
  10578. dev_priv->display.get_display_clock_speed =
  10579. pnv_get_display_clock_speed;
  10580. else if (IS_I915GM(dev))
  10581. dev_priv->display.get_display_clock_speed =
  10582. i915gm_get_display_clock_speed;
  10583. else if (IS_I865G(dev))
  10584. dev_priv->display.get_display_clock_speed =
  10585. i865_get_display_clock_speed;
  10586. else if (IS_I85X(dev))
  10587. dev_priv->display.get_display_clock_speed =
  10588. i855_get_display_clock_speed;
  10589. else /* 852, 830 */
  10590. dev_priv->display.get_display_clock_speed =
  10591. i830_get_display_clock_speed;
  10592. if (IS_G4X(dev)) {
  10593. dev_priv->display.write_eld = g4x_write_eld;
  10594. } else if (IS_GEN5(dev)) {
  10595. dev_priv->display.fdi_link_train = ironlake_fdi_link_train;
  10596. dev_priv->display.write_eld = ironlake_write_eld;
  10597. } else if (IS_GEN6(dev)) {
  10598. dev_priv->display.fdi_link_train = gen6_fdi_link_train;
  10599. dev_priv->display.write_eld = ironlake_write_eld;
  10600. dev_priv->display.modeset_global_resources =
  10601. snb_modeset_global_resources;
  10602. } else if (IS_IVYBRIDGE(dev)) {
  10603. /* FIXME: detect B0+ stepping and use auto training */
  10604. dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train;
  10605. dev_priv->display.write_eld = ironlake_write_eld;
  10606. dev_priv->display.modeset_global_resources =
  10607. ivb_modeset_global_resources;
  10608. } else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
  10609. dev_priv->display.fdi_link_train = hsw_fdi_link_train;
  10610. dev_priv->display.write_eld = haswell_write_eld;
  10611. dev_priv->display.modeset_global_resources =
  10612. haswell_modeset_global_resources;
  10613. } else if (IS_VALLEYVIEW(dev)) {
  10614. dev_priv->display.modeset_global_resources =
  10615. valleyview_modeset_global_resources;
  10616. dev_priv->display.write_eld = ironlake_write_eld;
  10617. }
  10618. /* Default just returns -ENODEV to indicate unsupported */
  10619. dev_priv->display.queue_flip = intel_default_queue_flip;
  10620. switch (INTEL_INFO(dev)->gen) {
  10621. case 2:
  10622. dev_priv->display.queue_flip = intel_gen2_queue_flip;
  10623. break;
  10624. case 3:
  10625. dev_priv->display.queue_flip = intel_gen3_queue_flip;
  10626. break;
  10627. case 4:
  10628. case 5:
  10629. dev_priv->display.queue_flip = intel_gen4_queue_flip;
  10630. break;
  10631. case 6:
  10632. dev_priv->display.queue_flip = intel_gen6_queue_flip;
  10633. break;
  10634. case 7:
  10635. case 8: /* FIXME(BDW): Check that the gen8 RCS flip works. */
  10636. dev_priv->display.queue_flip = intel_gen7_queue_flip;
  10637. break;
  10638. }
  10639. intel_panel_init_backlight_funcs(dev);
  10640. mutex_init(&dev_priv->pps_mutex);
  10641. }
  10642. /*
  10643. * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend,
  10644. * resume, or other times. This quirk makes sure that's the case for
  10645. * affected systems.
  10646. */
  10647. static void quirk_pipea_force(struct drm_device *dev)
  10648. {
  10649. struct drm_i915_private *dev_priv = dev->dev_private;
  10650. dev_priv->quirks |= QUIRK_PIPEA_FORCE;
  10651. DRM_INFO("applying pipe a force quirk\n");
  10652. }
  10653. static void quirk_pipeb_force(struct drm_device *dev)
  10654. {
  10655. struct drm_i915_private *dev_priv = dev->dev_private;
  10656. dev_priv->quirks |= QUIRK_PIPEB_FORCE;
  10657. DRM_INFO("applying pipe b force quirk\n");
  10658. }
  10659. /*
  10660. * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason
  10661. */
  10662. static void quirk_ssc_force_disable(struct drm_device *dev)
  10663. {
  10664. struct drm_i915_private *dev_priv = dev->dev_private;
  10665. dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE;
  10666. DRM_INFO("applying lvds SSC disable quirk\n");
  10667. }
  10668. /*
  10669. * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight
  10670. * brightness value
  10671. */
  10672. static void quirk_invert_brightness(struct drm_device *dev)
  10673. {
  10674. struct drm_i915_private *dev_priv = dev->dev_private;
  10675. dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS;
  10676. DRM_INFO("applying inverted panel brightness quirk\n");
  10677. }
  10678. /* Some VBT's incorrectly indicate no backlight is present */
  10679. static void quirk_backlight_present(struct drm_device *dev)
  10680. {
  10681. struct drm_i915_private *dev_priv = dev->dev_private;
  10682. dev_priv->quirks |= QUIRK_BACKLIGHT_PRESENT;
  10683. DRM_INFO("applying backlight present quirk\n");
  10684. }
  10685. struct intel_quirk {
  10686. int device;
  10687. int subsystem_vendor;
  10688. int subsystem_device;
  10689. void (*hook)(struct drm_device *dev);
  10690. };
  10691. /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
  10692. struct intel_dmi_quirk {
  10693. void (*hook)(struct drm_device *dev);
  10694. const struct dmi_system_id (*dmi_id_list)[];
  10695. };
  10696. static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
  10697. {
  10698. DRM_INFO("Backlight polarity reversed on %s\n", id->ident);
  10699. return 1;
  10700. }
  10701. static const struct intel_dmi_quirk intel_dmi_quirks[] = {
  10702. {
  10703. .dmi_id_list = &(const struct dmi_system_id[]) {
  10704. {
  10705. .callback = intel_dmi_reverse_brightness,
  10706. .ident = "NCR Corporation",
  10707. .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
  10708. DMI_MATCH(DMI_PRODUCT_NAME, ""),
  10709. },
  10710. },
  10711. { } /* terminating entry */
  10712. },
  10713. .hook = quirk_invert_brightness,
  10714. },
  10715. };
  10716. static struct intel_quirk intel_quirks[] = {
  10717. /* HP Mini needs pipe A force quirk (LP: #322104) */
  10718. { 0x27ae, 0x103c, 0x361a, quirk_pipea_force },
  10719. /* Toshiba Protege R-205, S-209 needs pipe A force quirk */
  10720. { 0x2592, 0x1179, 0x0001, quirk_pipea_force },
  10721. /* ThinkPad T60 needs pipe A force quirk (bug #16494) */
  10722. { 0x2782, 0x17aa, 0x201a, quirk_pipea_force },
  10723. /* 830 needs to leave pipe A & dpll A up */
  10724. { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force },
  10725. /* 830 needs to leave pipe B & dpll B up */
  10726. { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipeb_force },
  10727. /* Lenovo U160 cannot use SSC on LVDS */
  10728. { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable },
  10729. /* Sony Vaio Y cannot use SSC on LVDS */
  10730. { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable },
  10731. /* Acer Aspire 5734Z must invert backlight brightness */
  10732. { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness },
  10733. /* Acer/eMachines G725 */
  10734. { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness },
  10735. /* Acer/eMachines e725 */
  10736. { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness },
  10737. /* Acer/Packard Bell NCL20 */
  10738. { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness },
  10739. /* Acer Aspire 4736Z */
  10740. { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness },
  10741. /* Acer Aspire 5336 */
  10742. { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness },
  10743. /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */
  10744. { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present },
  10745. /* Acer C720 Chromebook (Core i3 4005U) */
  10746. { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present },
  10747. /* Toshiba CB35 Chromebook (Celeron 2955U) */
  10748. { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present },
  10749. /* HP Chromebook 14 (Celeron 2955U) */
  10750. { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present },
  10751. };
  10752. static void intel_init_quirks(struct drm_device *dev)
  10753. {
  10754. struct pci_dev *d = dev->pdev;
  10755. int i;
  10756. for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) {
  10757. struct intel_quirk *q = &intel_quirks[i];
  10758. if (d->device == q->device &&
  10759. (d->subsystem_vendor == q->subsystem_vendor ||
  10760. q->subsystem_vendor == PCI_ANY_ID) &&
  10761. (d->subsystem_device == q->subsystem_device ||
  10762. q->subsystem_device == PCI_ANY_ID))
  10763. q->hook(dev);
  10764. }
  10765. for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) {
  10766. if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0)
  10767. intel_dmi_quirks[i].hook(dev);
  10768. }
  10769. }
  10770. /* Disable the VGA plane that we never use */
  10771. static void i915_disable_vga(struct drm_device *dev)
  10772. {
  10773. struct drm_i915_private *dev_priv = dev->dev_private;
  10774. u8 sr1;
  10775. u32 vga_reg = i915_vgacntrl_reg(dev);
  10776. /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
  10777. vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO);
  10778. outb(SR01, VGA_SR_INDEX);
  10779. sr1 = inb(VGA_SR_DATA);
  10780. outb(sr1 | 1<<5, VGA_SR_DATA);
  10781. vga_put(dev->pdev, VGA_RSRC_LEGACY_IO);
  10782. udelay(300);
  10783. /*
  10784. * Fujitsu-Siemens Lifebook S6010 (830) has problems resuming
  10785. * from S3 without preserving (some of?) the other bits.
  10786. */
  10787. I915_WRITE(vga_reg, dev_priv->bios_vgacntr | VGA_DISP_DISABLE);
  10788. POSTING_READ(vga_reg);
  10789. }
  10790. void intel_modeset_init_hw(struct drm_device *dev)
  10791. {
  10792. intel_prepare_ddi(dev);
  10793. if (IS_VALLEYVIEW(dev))
  10794. vlv_update_cdclk(dev);
  10795. intel_init_clock_gating(dev);
  10796. intel_enable_gt_powersave(dev);
  10797. }
  10798. void intel_modeset_suspend_hw(struct drm_device *dev)
  10799. {
  10800. intel_suspend_hw(dev);
  10801. }
  10802. void intel_modeset_init(struct drm_device *dev)
  10803. {
  10804. struct drm_i915_private *dev_priv = dev->dev_private;
  10805. int sprite, ret;
  10806. enum pipe pipe;
  10807. struct intel_crtc *crtc;
  10808. drm_mode_config_init(dev);
  10809. dev->mode_config.min_width = 0;
  10810. dev->mode_config.min_height = 0;
  10811. dev->mode_config.preferred_depth = 24;
  10812. dev->mode_config.prefer_shadow = 1;
  10813. dev->mode_config.funcs = &intel_mode_funcs;
  10814. intel_init_quirks(dev);
  10815. intel_init_pm(dev);
  10816. if (INTEL_INFO(dev)->num_pipes == 0)
  10817. return;
  10818. intel_init_display(dev);
  10819. if (IS_GEN2(dev)) {
  10820. dev->mode_config.max_width = 2048;
  10821. dev->mode_config.max_height = 2048;
  10822. } else if (IS_GEN3(dev)) {
  10823. dev->mode_config.max_width = 4096;
  10824. dev->mode_config.max_height = 4096;
  10825. } else {
  10826. dev->mode_config.max_width = 8192;
  10827. dev->mode_config.max_height = 8192;
  10828. }
  10829. if (IS_845G(dev) || IS_I865G(dev)) {
  10830. dev->mode_config.cursor_width = IS_845G(dev) ? 64 : 512;
  10831. dev->mode_config.cursor_height = 1023;
  10832. } else if (IS_GEN2(dev)) {
  10833. dev->mode_config.cursor_width = GEN2_CURSOR_WIDTH;
  10834. dev->mode_config.cursor_height = GEN2_CURSOR_HEIGHT;
  10835. } else {
  10836. dev->mode_config.cursor_width = MAX_CURSOR_WIDTH;
  10837. dev->mode_config.cursor_height = MAX_CURSOR_HEIGHT;
  10838. }
  10839. dev->mode_config.fb_base = dev_priv->gtt.mappable_base;
  10840. DRM_DEBUG_KMS("%d display pipe%s available.\n",
  10841. INTEL_INFO(dev)->num_pipes,
  10842. INTEL_INFO(dev)->num_pipes > 1 ? "s" : "");
  10843. for_each_pipe(dev_priv, pipe) {
  10844. intel_crtc_init(dev, pipe);
  10845. for_each_sprite(pipe, sprite) {
  10846. ret = intel_plane_init(dev, pipe, sprite);
  10847. if (ret)
  10848. DRM_DEBUG_KMS("pipe %c sprite %c init failed: %d\n",
  10849. pipe_name(pipe), sprite_name(pipe, sprite), ret);
  10850. }
  10851. }
  10852. intel_init_dpio(dev);
  10853. intel_shared_dpll_init(dev);
  10854. /* save the BIOS value before clobbering it */
  10855. dev_priv->bios_vgacntr = I915_READ(i915_vgacntrl_reg(dev));
  10856. /* Just disable it once at startup */
  10857. i915_disable_vga(dev);
  10858. intel_setup_outputs(dev);
  10859. /* Just in case the BIOS is doing something questionable. */
  10860. intel_disable_fbc(dev);
  10861. drm_modeset_lock_all(dev);
  10862. intel_modeset_setup_hw_state(dev, false);
  10863. drm_modeset_unlock_all(dev);
  10864. for_each_intel_crtc(dev, crtc) {
  10865. if (!crtc->active)
  10866. continue;
  10867. /*
  10868. * Note that reserving the BIOS fb up front prevents us
  10869. * from stuffing other stolen allocations like the ring
  10870. * on top. This prevents some ugliness at boot time, and
  10871. * can even allow for smooth boot transitions if the BIOS
  10872. * fb is large enough for the active pipe configuration.
  10873. */
  10874. if (dev_priv->display.get_plane_config) {
  10875. dev_priv->display.get_plane_config(crtc,
  10876. &crtc->plane_config);
  10877. /*
  10878. * If the fb is shared between multiple heads, we'll
  10879. * just get the first one.
  10880. */
  10881. intel_find_plane_obj(crtc, &crtc->plane_config);
  10882. }
  10883. }
  10884. }
  10885. static void intel_enable_pipe_a(struct drm_device *dev)
  10886. {
  10887. struct intel_connector *connector;
  10888. struct drm_connector *crt = NULL;
  10889. struct intel_load_detect_pipe load_detect_temp;
  10890. struct drm_modeset_acquire_ctx *ctx = dev->mode_config.acquire_ctx;
  10891. /* We can't just switch on the pipe A, we need to set things up with a
  10892. * proper mode and output configuration. As a gross hack, enable pipe A
  10893. * by enabling the load detect pipe once. */
  10894. list_for_each_entry(connector,
  10895. &dev->mode_config.connector_list,
  10896. base.head) {
  10897. if (connector->encoder->type == INTEL_OUTPUT_ANALOG) {
  10898. crt = &connector->base;
  10899. break;
  10900. }
  10901. }
  10902. if (!crt)
  10903. return;
  10904. if (intel_get_load_detect_pipe(crt, NULL, &load_detect_temp, ctx))
  10905. intel_release_load_detect_pipe(crt, &load_detect_temp);
  10906. }
  10907. static bool
  10908. intel_check_plane_mapping(struct intel_crtc *crtc)
  10909. {
  10910. struct drm_device *dev = crtc->base.dev;
  10911. struct drm_i915_private *dev_priv = dev->dev_private;
  10912. u32 reg, val;
  10913. if (INTEL_INFO(dev)->num_pipes == 1)
  10914. return true;
  10915. reg = DSPCNTR(!crtc->plane);
  10916. val = I915_READ(reg);
  10917. if ((val & DISPLAY_PLANE_ENABLE) &&
  10918. (!!(val & DISPPLANE_SEL_PIPE_MASK) == crtc->pipe))
  10919. return false;
  10920. return true;
  10921. }
  10922. static void intel_sanitize_crtc(struct intel_crtc *crtc)
  10923. {
  10924. struct drm_device *dev = crtc->base.dev;
  10925. struct drm_i915_private *dev_priv = dev->dev_private;
  10926. u32 reg;
  10927. /* Clear any frame start delays used for debugging left by the BIOS */
  10928. reg = PIPECONF(crtc->config.cpu_transcoder);
  10929. I915_WRITE(reg, I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK);
  10930. /* restore vblank interrupts to correct state */
  10931. if (crtc->active) {
  10932. update_scanline_offset(crtc);
  10933. drm_vblank_on(dev, crtc->pipe);
  10934. } else
  10935. drm_vblank_off(dev, crtc->pipe);
  10936. /* We need to sanitize the plane -> pipe mapping first because this will
  10937. * disable the crtc (and hence change the state) if it is wrong. Note
  10938. * that gen4+ has a fixed plane -> pipe mapping. */
  10939. if (INTEL_INFO(dev)->gen < 4 && !intel_check_plane_mapping(crtc)) {
  10940. struct intel_connector *connector;
  10941. bool plane;
  10942. DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n",
  10943. crtc->base.base.id);
  10944. /* Pipe has the wrong plane attached and the plane is active.
  10945. * Temporarily change the plane mapping and disable everything
  10946. * ... */
  10947. plane = crtc->plane;
  10948. crtc->plane = !plane;
  10949. crtc->primary_enabled = true;
  10950. dev_priv->display.crtc_disable(&crtc->base);
  10951. crtc->plane = plane;
  10952. /* ... and break all links. */
  10953. list_for_each_entry(connector, &dev->mode_config.connector_list,
  10954. base.head) {
  10955. if (connector->encoder->base.crtc != &crtc->base)
  10956. continue;
  10957. connector->base.dpms = DRM_MODE_DPMS_OFF;
  10958. connector->base.encoder = NULL;
  10959. }
  10960. /* multiple connectors may have the same encoder:
  10961. * handle them and break crtc link separately */
  10962. list_for_each_entry(connector, &dev->mode_config.connector_list,
  10963. base.head)
  10964. if (connector->encoder->base.crtc == &crtc->base) {
  10965. connector->encoder->base.crtc = NULL;
  10966. connector->encoder->connectors_active = false;
  10967. }
  10968. WARN_ON(crtc->active);
  10969. crtc->base.enabled = false;
  10970. }
  10971. if (dev_priv->quirks & QUIRK_PIPEA_FORCE &&
  10972. crtc->pipe == PIPE_A && !crtc->active) {
  10973. /* BIOS forgot to enable pipe A, this mostly happens after
  10974. * resume. Force-enable the pipe to fix this, the update_dpms
  10975. * call below we restore the pipe to the right state, but leave
  10976. * the required bits on. */
  10977. intel_enable_pipe_a(dev);
  10978. }
  10979. /* Adjust the state of the output pipe according to whether we
  10980. * have active connectors/encoders. */
  10981. intel_crtc_update_dpms(&crtc->base);
  10982. if (crtc->active != crtc->base.enabled) {
  10983. struct intel_encoder *encoder;
  10984. /* This can happen either due to bugs in the get_hw_state
  10985. * functions or because the pipe is force-enabled due to the
  10986. * pipe A quirk. */
  10987. DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n",
  10988. crtc->base.base.id,
  10989. crtc->base.enabled ? "enabled" : "disabled",
  10990. crtc->active ? "enabled" : "disabled");
  10991. crtc->base.enabled = crtc->active;
  10992. /* Because we only establish the connector -> encoder ->
  10993. * crtc links if something is active, this means the
  10994. * crtc is now deactivated. Break the links. connector
  10995. * -> encoder links are only establish when things are
  10996. * actually up, hence no need to break them. */
  10997. WARN_ON(crtc->active);
  10998. for_each_encoder_on_crtc(dev, &crtc->base, encoder) {
  10999. WARN_ON(encoder->connectors_active);
  11000. encoder->base.crtc = NULL;
  11001. }
  11002. }
  11003. if (crtc->active || HAS_GMCH_DISPLAY(dev)) {
  11004. /*
  11005. * We start out with underrun reporting disabled to avoid races.
  11006. * For correct bookkeeping mark this on active crtcs.
  11007. *
  11008. * Also on gmch platforms we dont have any hardware bits to
  11009. * disable the underrun reporting. Which means we need to start
  11010. * out with underrun reporting disabled also on inactive pipes,
  11011. * since otherwise we'll complain about the garbage we read when
  11012. * e.g. coming up after runtime pm.
  11013. *
  11014. * No protection against concurrent access is required - at
  11015. * worst a fifo underrun happens which also sets this to false.
  11016. */
  11017. crtc->cpu_fifo_underrun_disabled = true;
  11018. crtc->pch_fifo_underrun_disabled = true;
  11019. }
  11020. }
  11021. static void intel_sanitize_encoder(struct intel_encoder *encoder)
  11022. {
  11023. struct intel_connector *connector;
  11024. struct drm_device *dev = encoder->base.dev;
  11025. /* We need to check both for a crtc link (meaning that the
  11026. * encoder is active and trying to read from a pipe) and the
  11027. * pipe itself being active. */
  11028. bool has_active_crtc = encoder->base.crtc &&
  11029. to_intel_crtc(encoder->base.crtc)->active;
  11030. if (encoder->connectors_active && !has_active_crtc) {
  11031. DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
  11032. encoder->base.base.id,
  11033. encoder->base.name);
  11034. /* Connector is active, but has no active pipe. This is
  11035. * fallout from our resume register restoring. Disable
  11036. * the encoder manually again. */
  11037. if (encoder->base.crtc) {
  11038. DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
  11039. encoder->base.base.id,
  11040. encoder->base.name);
  11041. encoder->disable(encoder);
  11042. if (encoder->post_disable)
  11043. encoder->post_disable(encoder);
  11044. }
  11045. encoder->base.crtc = NULL;
  11046. encoder->connectors_active = false;
  11047. /* Inconsistent output/port/pipe state happens presumably due to
  11048. * a bug in one of the get_hw_state functions. Or someplace else
  11049. * in our code, like the register restore mess on resume. Clamp
  11050. * things to off as a safer default. */
  11051. list_for_each_entry(connector,
  11052. &dev->mode_config.connector_list,
  11053. base.head) {
  11054. if (connector->encoder != encoder)
  11055. continue;
  11056. connector->base.dpms = DRM_MODE_DPMS_OFF;
  11057. connector->base.encoder = NULL;
  11058. }
  11059. }
  11060. /* Enabled encoders without active connectors will be fixed in
  11061. * the crtc fixup. */
  11062. }
  11063. void i915_redisable_vga_power_on(struct drm_device *dev)
  11064. {
  11065. struct drm_i915_private *dev_priv = dev->dev_private;
  11066. u32 vga_reg = i915_vgacntrl_reg(dev);
  11067. if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) {
  11068. DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
  11069. i915_disable_vga(dev);
  11070. }
  11071. }
  11072. void i915_redisable_vga(struct drm_device *dev)
  11073. {
  11074. struct drm_i915_private *dev_priv = dev->dev_private;
  11075. /* This function can be called both from intel_modeset_setup_hw_state or
  11076. * at a very early point in our resume sequence, where the power well
  11077. * structures are not yet restored. Since this function is at a very
  11078. * paranoid "someone might have enabled VGA while we were not looking"
  11079. * level, just check if the power well is enabled instead of trying to
  11080. * follow the "don't touch the power well if we don't need it" policy
  11081. * the rest of the driver uses. */
  11082. if (!intel_display_power_enabled(dev_priv, POWER_DOMAIN_VGA))
  11083. return;
  11084. i915_redisable_vga_power_on(dev);
  11085. }
  11086. static bool primary_get_hw_state(struct intel_crtc *crtc)
  11087. {
  11088. struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
  11089. if (!crtc->active)
  11090. return false;
  11091. return I915_READ(DSPCNTR(crtc->plane)) & DISPLAY_PLANE_ENABLE;
  11092. }
  11093. static void intel_modeset_readout_hw_state(struct drm_device *dev)
  11094. {
  11095. struct drm_i915_private *dev_priv = dev->dev_private;
  11096. enum pipe pipe;
  11097. struct intel_crtc *crtc;
  11098. struct intel_encoder *encoder;
  11099. struct intel_connector *connector;
  11100. int i;
  11101. for_each_intel_crtc(dev, crtc) {
  11102. memset(&crtc->config, 0, sizeof(crtc->config));
  11103. crtc->config.quirks |= PIPE_CONFIG_QUIRK_INHERITED_MODE;
  11104. crtc->active = dev_priv->display.get_pipe_config(crtc,
  11105. &crtc->config);
  11106. crtc->base.enabled = crtc->active;
  11107. crtc->primary_enabled = primary_get_hw_state(crtc);
  11108. DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n",
  11109. crtc->base.base.id,
  11110. crtc->active ? "enabled" : "disabled");
  11111. }
  11112. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  11113. struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
  11114. pll->on = pll->get_hw_state(dev_priv, pll, &pll->hw_state);
  11115. pll->active = 0;
  11116. for_each_intel_crtc(dev, crtc) {
  11117. if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll)
  11118. pll->active++;
  11119. }
  11120. pll->refcount = pll->active;
  11121. DRM_DEBUG_KMS("%s hw state readout: refcount %i, on %i\n",
  11122. pll->name, pll->refcount, pll->on);
  11123. if (pll->refcount)
  11124. intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS);
  11125. }
  11126. for_each_intel_encoder(dev, encoder) {
  11127. pipe = 0;
  11128. if (encoder->get_hw_state(encoder, &pipe)) {
  11129. crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  11130. encoder->base.crtc = &crtc->base;
  11131. encoder->get_config(encoder, &crtc->config);
  11132. } else {
  11133. encoder->base.crtc = NULL;
  11134. }
  11135. encoder->connectors_active = false;
  11136. DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
  11137. encoder->base.base.id,
  11138. encoder->base.name,
  11139. encoder->base.crtc ? "enabled" : "disabled",
  11140. pipe_name(pipe));
  11141. }
  11142. list_for_each_entry(connector, &dev->mode_config.connector_list,
  11143. base.head) {
  11144. if (connector->get_hw_state(connector)) {
  11145. connector->base.dpms = DRM_MODE_DPMS_ON;
  11146. connector->encoder->connectors_active = true;
  11147. connector->base.encoder = &connector->encoder->base;
  11148. } else {
  11149. connector->base.dpms = DRM_MODE_DPMS_OFF;
  11150. connector->base.encoder = NULL;
  11151. }
  11152. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
  11153. connector->base.base.id,
  11154. connector->base.name,
  11155. connector->base.encoder ? "enabled" : "disabled");
  11156. }
  11157. }
  11158. /* Scan out the current hw modeset state, sanitizes it and maps it into the drm
  11159. * and i915 state tracking structures. */
  11160. void intel_modeset_setup_hw_state(struct drm_device *dev,
  11161. bool force_restore)
  11162. {
  11163. struct drm_i915_private *dev_priv = dev->dev_private;
  11164. enum pipe pipe;
  11165. struct intel_crtc *crtc;
  11166. struct intel_encoder *encoder;
  11167. int i;
  11168. intel_modeset_readout_hw_state(dev);
  11169. /*
  11170. * Now that we have the config, copy it to each CRTC struct
  11171. * Note that this could go away if we move to using crtc_config
  11172. * checking everywhere.
  11173. */
  11174. for_each_intel_crtc(dev, crtc) {
  11175. if (crtc->active && i915.fastboot) {
  11176. intel_mode_from_pipe_config(&crtc->base.mode, &crtc->config);
  11177. DRM_DEBUG_KMS("[CRTC:%d] found active mode: ",
  11178. crtc->base.base.id);
  11179. drm_mode_debug_printmodeline(&crtc->base.mode);
  11180. }
  11181. }
  11182. /* HW state is read out, now we need to sanitize this mess. */
  11183. for_each_intel_encoder(dev, encoder) {
  11184. intel_sanitize_encoder(encoder);
  11185. }
  11186. for_each_pipe(dev_priv, pipe) {
  11187. crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  11188. intel_sanitize_crtc(crtc);
  11189. intel_dump_pipe_config(crtc, &crtc->config, "[setup_hw_state]");
  11190. }
  11191. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  11192. struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
  11193. if (!pll->on || pll->active)
  11194. continue;
  11195. DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll->name);
  11196. pll->disable(dev_priv, pll);
  11197. pll->on = false;
  11198. }
  11199. if (HAS_PCH_SPLIT(dev))
  11200. ilk_wm_get_hw_state(dev);
  11201. if (force_restore) {
  11202. i915_redisable_vga(dev);
  11203. /*
  11204. * We need to use raw interfaces for restoring state to avoid
  11205. * checking (bogus) intermediate states.
  11206. */
  11207. for_each_pipe(dev_priv, pipe) {
  11208. struct drm_crtc *crtc =
  11209. dev_priv->pipe_to_crtc_mapping[pipe];
  11210. __intel_set_mode(crtc, &crtc->mode, crtc->x, crtc->y,
  11211. crtc->primary->fb);
  11212. }
  11213. } else {
  11214. intel_modeset_update_staged_output_state(dev);
  11215. }
  11216. intel_modeset_check_state(dev);
  11217. }
  11218. void intel_modeset_gem_init(struct drm_device *dev)
  11219. {
  11220. struct drm_crtc *c;
  11221. struct drm_i915_gem_object *obj;
  11222. mutex_lock(&dev->struct_mutex);
  11223. intel_init_gt_powersave(dev);
  11224. mutex_unlock(&dev->struct_mutex);
  11225. intel_modeset_init_hw(dev);
  11226. intel_setup_overlay(dev);
  11227. /*
  11228. * Make sure any fbs we allocated at startup are properly
  11229. * pinned & fenced. When we do the allocation it's too early
  11230. * for this.
  11231. */
  11232. mutex_lock(&dev->struct_mutex);
  11233. for_each_crtc(dev, c) {
  11234. obj = intel_fb_obj(c->primary->fb);
  11235. if (obj == NULL)
  11236. continue;
  11237. if (intel_pin_and_fence_fb_obj(dev, obj, NULL)) {
  11238. DRM_ERROR("failed to pin boot fb on pipe %d\n",
  11239. to_intel_crtc(c)->pipe);
  11240. drm_framebuffer_unreference(c->primary->fb);
  11241. c->primary->fb = NULL;
  11242. }
  11243. }
  11244. mutex_unlock(&dev->struct_mutex);
  11245. }
  11246. void intel_connector_unregister(struct intel_connector *intel_connector)
  11247. {
  11248. struct drm_connector *connector = &intel_connector->base;
  11249. intel_panel_destroy_backlight(connector);
  11250. drm_connector_unregister(connector);
  11251. }
  11252. void intel_modeset_cleanup(struct drm_device *dev)
  11253. {
  11254. struct drm_i915_private *dev_priv = dev->dev_private;
  11255. struct drm_connector *connector;
  11256. /*
  11257. * Interrupts and polling as the first thing to avoid creating havoc.
  11258. * Too much stuff here (turning of rps, connectors, ...) would
  11259. * experience fancy races otherwise.
  11260. */
  11261. drm_irq_uninstall(dev);
  11262. intel_hpd_cancel_work(dev_priv);
  11263. dev_priv->pm._irqs_disabled = true;
  11264. /*
  11265. * Due to the hpd irq storm handling the hotplug work can re-arm the
  11266. * poll handlers. Hence disable polling after hpd handling is shut down.
  11267. */
  11268. drm_kms_helper_poll_fini(dev);
  11269. mutex_lock(&dev->struct_mutex);
  11270. intel_unregister_dsm_handler();
  11271. intel_disable_fbc(dev);
  11272. intel_disable_gt_powersave(dev);
  11273. ironlake_teardown_rc6(dev);
  11274. mutex_unlock(&dev->struct_mutex);
  11275. /* flush any delayed tasks or pending work */
  11276. flush_scheduled_work();
  11277. /* destroy the backlight and sysfs files before encoders/connectors */
  11278. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  11279. struct intel_connector *intel_connector;
  11280. intel_connector = to_intel_connector(connector);
  11281. intel_connector->unregister(intel_connector);
  11282. }
  11283. drm_mode_config_cleanup(dev);
  11284. intel_cleanup_overlay(dev);
  11285. mutex_lock(&dev->struct_mutex);
  11286. intel_cleanup_gt_powersave(dev);
  11287. mutex_unlock(&dev->struct_mutex);
  11288. }
  11289. /*
  11290. * Return which encoder is currently attached for connector.
  11291. */
  11292. struct drm_encoder *intel_best_encoder(struct drm_connector *connector)
  11293. {
  11294. return &intel_attached_encoder(connector)->base;
  11295. }
  11296. void intel_connector_attach_encoder(struct intel_connector *connector,
  11297. struct intel_encoder *encoder)
  11298. {
  11299. connector->encoder = encoder;
  11300. drm_mode_connector_attach_encoder(&connector->base,
  11301. &encoder->base);
  11302. }
  11303. /*
  11304. * set vga decode state - true == enable VGA decode
  11305. */
  11306. int intel_modeset_vga_set_state(struct drm_device *dev, bool state)
  11307. {
  11308. struct drm_i915_private *dev_priv = dev->dev_private;
  11309. unsigned reg = INTEL_INFO(dev)->gen >= 6 ? SNB_GMCH_CTRL : INTEL_GMCH_CTRL;
  11310. u16 gmch_ctrl;
  11311. if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) {
  11312. DRM_ERROR("failed to read control word\n");
  11313. return -EIO;
  11314. }
  11315. if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state)
  11316. return 0;
  11317. if (state)
  11318. gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE;
  11319. else
  11320. gmch_ctrl |= INTEL_GMCH_VGA_DISABLE;
  11321. if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) {
  11322. DRM_ERROR("failed to write control word\n");
  11323. return -EIO;
  11324. }
  11325. return 0;
  11326. }
  11327. struct intel_display_error_state {
  11328. u32 power_well_driver;
  11329. int num_transcoders;
  11330. struct intel_cursor_error_state {
  11331. u32 control;
  11332. u32 position;
  11333. u32 base;
  11334. u32 size;
  11335. } cursor[I915_MAX_PIPES];
  11336. struct intel_pipe_error_state {
  11337. bool power_domain_on;
  11338. u32 source;
  11339. u32 stat;
  11340. } pipe[I915_MAX_PIPES];
  11341. struct intel_plane_error_state {
  11342. u32 control;
  11343. u32 stride;
  11344. u32 size;
  11345. u32 pos;
  11346. u32 addr;
  11347. u32 surface;
  11348. u32 tile_offset;
  11349. } plane[I915_MAX_PIPES];
  11350. struct intel_transcoder_error_state {
  11351. bool power_domain_on;
  11352. enum transcoder cpu_transcoder;
  11353. u32 conf;
  11354. u32 htotal;
  11355. u32 hblank;
  11356. u32 hsync;
  11357. u32 vtotal;
  11358. u32 vblank;
  11359. u32 vsync;
  11360. } transcoder[4];
  11361. };
  11362. struct intel_display_error_state *
  11363. intel_display_capture_error_state(struct drm_device *dev)
  11364. {
  11365. struct drm_i915_private *dev_priv = dev->dev_private;
  11366. struct intel_display_error_state *error;
  11367. int transcoders[] = {
  11368. TRANSCODER_A,
  11369. TRANSCODER_B,
  11370. TRANSCODER_C,
  11371. TRANSCODER_EDP,
  11372. };
  11373. int i;
  11374. if (INTEL_INFO(dev)->num_pipes == 0)
  11375. return NULL;
  11376. error = kzalloc(sizeof(*error), GFP_ATOMIC);
  11377. if (error == NULL)
  11378. return NULL;
  11379. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  11380. error->power_well_driver = I915_READ(HSW_PWR_WELL_DRIVER);
  11381. for_each_pipe(dev_priv, i) {
  11382. error->pipe[i].power_domain_on =
  11383. intel_display_power_enabled_unlocked(dev_priv,
  11384. POWER_DOMAIN_PIPE(i));
  11385. if (!error->pipe[i].power_domain_on)
  11386. continue;
  11387. error->cursor[i].control = I915_READ(CURCNTR(i));
  11388. error->cursor[i].position = I915_READ(CURPOS(i));
  11389. error->cursor[i].base = I915_READ(CURBASE(i));
  11390. error->plane[i].control = I915_READ(DSPCNTR(i));
  11391. error->plane[i].stride = I915_READ(DSPSTRIDE(i));
  11392. if (INTEL_INFO(dev)->gen <= 3) {
  11393. error->plane[i].size = I915_READ(DSPSIZE(i));
  11394. error->plane[i].pos = I915_READ(DSPPOS(i));
  11395. }
  11396. if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev))
  11397. error->plane[i].addr = I915_READ(DSPADDR(i));
  11398. if (INTEL_INFO(dev)->gen >= 4) {
  11399. error->plane[i].surface = I915_READ(DSPSURF(i));
  11400. error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i));
  11401. }
  11402. error->pipe[i].source = I915_READ(PIPESRC(i));
  11403. if (HAS_GMCH_DISPLAY(dev))
  11404. error->pipe[i].stat = I915_READ(PIPESTAT(i));
  11405. }
  11406. error->num_transcoders = INTEL_INFO(dev)->num_pipes;
  11407. if (HAS_DDI(dev_priv->dev))
  11408. error->num_transcoders++; /* Account for eDP. */
  11409. for (i = 0; i < error->num_transcoders; i++) {
  11410. enum transcoder cpu_transcoder = transcoders[i];
  11411. error->transcoder[i].power_domain_on =
  11412. intel_display_power_enabled_unlocked(dev_priv,
  11413. POWER_DOMAIN_TRANSCODER(cpu_transcoder));
  11414. if (!error->transcoder[i].power_domain_on)
  11415. continue;
  11416. error->transcoder[i].cpu_transcoder = cpu_transcoder;
  11417. error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder));
  11418. error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder));
  11419. error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder));
  11420. error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder));
  11421. error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder));
  11422. error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder));
  11423. error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder));
  11424. }
  11425. return error;
  11426. }
  11427. #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
  11428. void
  11429. intel_display_print_error_state(struct drm_i915_error_state_buf *m,
  11430. struct drm_device *dev,
  11431. struct intel_display_error_state *error)
  11432. {
  11433. struct drm_i915_private *dev_priv = dev->dev_private;
  11434. int i;
  11435. if (!error)
  11436. return;
  11437. err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev)->num_pipes);
  11438. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  11439. err_printf(m, "PWR_WELL_CTL2: %08x\n",
  11440. error->power_well_driver);
  11441. for_each_pipe(dev_priv, i) {
  11442. err_printf(m, "Pipe [%d]:\n", i);
  11443. err_printf(m, " Power: %s\n",
  11444. error->pipe[i].power_domain_on ? "on" : "off");
  11445. err_printf(m, " SRC: %08x\n", error->pipe[i].source);
  11446. err_printf(m, " STAT: %08x\n", error->pipe[i].stat);
  11447. err_printf(m, "Plane [%d]:\n", i);
  11448. err_printf(m, " CNTR: %08x\n", error->plane[i].control);
  11449. err_printf(m, " STRIDE: %08x\n", error->plane[i].stride);
  11450. if (INTEL_INFO(dev)->gen <= 3) {
  11451. err_printf(m, " SIZE: %08x\n", error->plane[i].size);
  11452. err_printf(m, " POS: %08x\n", error->plane[i].pos);
  11453. }
  11454. if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev))
  11455. err_printf(m, " ADDR: %08x\n", error->plane[i].addr);
  11456. if (INTEL_INFO(dev)->gen >= 4) {
  11457. err_printf(m, " SURF: %08x\n", error->plane[i].surface);
  11458. err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset);
  11459. }
  11460. err_printf(m, "Cursor [%d]:\n", i);
  11461. err_printf(m, " CNTR: %08x\n", error->cursor[i].control);
  11462. err_printf(m, " POS: %08x\n", error->cursor[i].position);
  11463. err_printf(m, " BASE: %08x\n", error->cursor[i].base);
  11464. }
  11465. for (i = 0; i < error->num_transcoders; i++) {
  11466. err_printf(m, "CPU transcoder: %c\n",
  11467. transcoder_name(error->transcoder[i].cpu_transcoder));
  11468. err_printf(m, " Power: %s\n",
  11469. error->transcoder[i].power_domain_on ? "on" : "off");
  11470. err_printf(m, " CONF: %08x\n", error->transcoder[i].conf);
  11471. err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal);
  11472. err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank);
  11473. err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync);
  11474. err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal);
  11475. err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank);
  11476. err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync);
  11477. }
  11478. }
  11479. void intel_modeset_preclose(struct drm_device *dev, struct drm_file *file)
  11480. {
  11481. struct intel_crtc *crtc;
  11482. for_each_intel_crtc(dev, crtc) {
  11483. struct intel_unpin_work *work;
  11484. unsigned long irqflags;
  11485. spin_lock_irqsave(&dev->event_lock, irqflags);
  11486. work = crtc->unpin_work;
  11487. if (work && work->event &&
  11488. work->event->base.file_priv == file) {
  11489. kfree(work->event);
  11490. work->event = NULL;
  11491. }
  11492. spin_unlock_irqrestore(&dev->event_lock, irqflags);
  11493. }
  11494. }