intel_display.c 213 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646
  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/module.h>
  27. #include <linux/input.h>
  28. #include <linux/i2c.h>
  29. #include <linux/kernel.h>
  30. #include <linux/slab.h>
  31. #include <linux/vgaarb.h>
  32. #include "drmP.h"
  33. #include "intel_drv.h"
  34. #include "i915_drm.h"
  35. #include "i915_drv.h"
  36. #include "i915_trace.h"
  37. #include "drm_dp_helper.h"
  38. #include "drm_crtc_helper.h"
  39. #define HAS_eDP (intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))
  40. bool intel_pipe_has_type (struct drm_crtc *crtc, int type);
  41. static void intel_update_watermarks(struct drm_device *dev);
  42. static void intel_increase_pllclock(struct drm_crtc *crtc);
  43. static void intel_crtc_update_cursor(struct drm_crtc *crtc, bool on);
  44. typedef struct {
  45. /* given values */
  46. int n;
  47. int m1, m2;
  48. int p1, p2;
  49. /* derived values */
  50. int dot;
  51. int vco;
  52. int m;
  53. int p;
  54. } intel_clock_t;
  55. typedef struct {
  56. int min, max;
  57. } intel_range_t;
  58. typedef struct {
  59. int dot_limit;
  60. int p2_slow, p2_fast;
  61. } intel_p2_t;
  62. #define INTEL_P2_NUM 2
  63. typedef struct intel_limit intel_limit_t;
  64. struct intel_limit {
  65. intel_range_t dot, vco, n, m, m1, m2, p, p1;
  66. intel_p2_t p2;
  67. bool (* find_pll)(const intel_limit_t *, struct drm_crtc *,
  68. int, int, intel_clock_t *);
  69. };
  70. #define I8XX_DOT_MIN 25000
  71. #define I8XX_DOT_MAX 350000
  72. #define I8XX_VCO_MIN 930000
  73. #define I8XX_VCO_MAX 1400000
  74. #define I8XX_N_MIN 3
  75. #define I8XX_N_MAX 16
  76. #define I8XX_M_MIN 96
  77. #define I8XX_M_MAX 140
  78. #define I8XX_M1_MIN 18
  79. #define I8XX_M1_MAX 26
  80. #define I8XX_M2_MIN 6
  81. #define I8XX_M2_MAX 16
  82. #define I8XX_P_MIN 4
  83. #define I8XX_P_MAX 128
  84. #define I8XX_P1_MIN 2
  85. #define I8XX_P1_MAX 33
  86. #define I8XX_P1_LVDS_MIN 1
  87. #define I8XX_P1_LVDS_MAX 6
  88. #define I8XX_P2_SLOW 4
  89. #define I8XX_P2_FAST 2
  90. #define I8XX_P2_LVDS_SLOW 14
  91. #define I8XX_P2_LVDS_FAST 7
  92. #define I8XX_P2_SLOW_LIMIT 165000
  93. #define I9XX_DOT_MIN 20000
  94. #define I9XX_DOT_MAX 400000
  95. #define I9XX_VCO_MIN 1400000
  96. #define I9XX_VCO_MAX 2800000
  97. #define PINEVIEW_VCO_MIN 1700000
  98. #define PINEVIEW_VCO_MAX 3500000
  99. #define I9XX_N_MIN 1
  100. #define I9XX_N_MAX 6
  101. /* Pineview's Ncounter is a ring counter */
  102. #define PINEVIEW_N_MIN 3
  103. #define PINEVIEW_N_MAX 6
  104. #define I9XX_M_MIN 70
  105. #define I9XX_M_MAX 120
  106. #define PINEVIEW_M_MIN 2
  107. #define PINEVIEW_M_MAX 256
  108. #define I9XX_M1_MIN 10
  109. #define I9XX_M1_MAX 22
  110. #define I9XX_M2_MIN 5
  111. #define I9XX_M2_MAX 9
  112. /* Pineview M1 is reserved, and must be 0 */
  113. #define PINEVIEW_M1_MIN 0
  114. #define PINEVIEW_M1_MAX 0
  115. #define PINEVIEW_M2_MIN 0
  116. #define PINEVIEW_M2_MAX 254
  117. #define I9XX_P_SDVO_DAC_MIN 5
  118. #define I9XX_P_SDVO_DAC_MAX 80
  119. #define I9XX_P_LVDS_MIN 7
  120. #define I9XX_P_LVDS_MAX 98
  121. #define PINEVIEW_P_LVDS_MIN 7
  122. #define PINEVIEW_P_LVDS_MAX 112
  123. #define I9XX_P1_MIN 1
  124. #define I9XX_P1_MAX 8
  125. #define I9XX_P2_SDVO_DAC_SLOW 10
  126. #define I9XX_P2_SDVO_DAC_FAST 5
  127. #define I9XX_P2_SDVO_DAC_SLOW_LIMIT 200000
  128. #define I9XX_P2_LVDS_SLOW 14
  129. #define I9XX_P2_LVDS_FAST 7
  130. #define I9XX_P2_LVDS_SLOW_LIMIT 112000
  131. /*The parameter is for SDVO on G4x platform*/
  132. #define G4X_DOT_SDVO_MIN 25000
  133. #define G4X_DOT_SDVO_MAX 270000
  134. #define G4X_VCO_MIN 1750000
  135. #define G4X_VCO_MAX 3500000
  136. #define G4X_N_SDVO_MIN 1
  137. #define G4X_N_SDVO_MAX 4
  138. #define G4X_M_SDVO_MIN 104
  139. #define G4X_M_SDVO_MAX 138
  140. #define G4X_M1_SDVO_MIN 17
  141. #define G4X_M1_SDVO_MAX 23
  142. #define G4X_M2_SDVO_MIN 5
  143. #define G4X_M2_SDVO_MAX 11
  144. #define G4X_P_SDVO_MIN 10
  145. #define G4X_P_SDVO_MAX 30
  146. #define G4X_P1_SDVO_MIN 1
  147. #define G4X_P1_SDVO_MAX 3
  148. #define G4X_P2_SDVO_SLOW 10
  149. #define G4X_P2_SDVO_FAST 10
  150. #define G4X_P2_SDVO_LIMIT 270000
  151. /*The parameter is for HDMI_DAC on G4x platform*/
  152. #define G4X_DOT_HDMI_DAC_MIN 22000
  153. #define G4X_DOT_HDMI_DAC_MAX 400000
  154. #define G4X_N_HDMI_DAC_MIN 1
  155. #define G4X_N_HDMI_DAC_MAX 4
  156. #define G4X_M_HDMI_DAC_MIN 104
  157. #define G4X_M_HDMI_DAC_MAX 138
  158. #define G4X_M1_HDMI_DAC_MIN 16
  159. #define G4X_M1_HDMI_DAC_MAX 23
  160. #define G4X_M2_HDMI_DAC_MIN 5
  161. #define G4X_M2_HDMI_DAC_MAX 11
  162. #define G4X_P_HDMI_DAC_MIN 5
  163. #define G4X_P_HDMI_DAC_MAX 80
  164. #define G4X_P1_HDMI_DAC_MIN 1
  165. #define G4X_P1_HDMI_DAC_MAX 8
  166. #define G4X_P2_HDMI_DAC_SLOW 10
  167. #define G4X_P2_HDMI_DAC_FAST 5
  168. #define G4X_P2_HDMI_DAC_LIMIT 165000
  169. /*The parameter is for SINGLE_CHANNEL_LVDS on G4x platform*/
  170. #define G4X_DOT_SINGLE_CHANNEL_LVDS_MIN 20000
  171. #define G4X_DOT_SINGLE_CHANNEL_LVDS_MAX 115000
  172. #define G4X_N_SINGLE_CHANNEL_LVDS_MIN 1
  173. #define G4X_N_SINGLE_CHANNEL_LVDS_MAX 3
  174. #define G4X_M_SINGLE_CHANNEL_LVDS_MIN 104
  175. #define G4X_M_SINGLE_CHANNEL_LVDS_MAX 138
  176. #define G4X_M1_SINGLE_CHANNEL_LVDS_MIN 17
  177. #define G4X_M1_SINGLE_CHANNEL_LVDS_MAX 23
  178. #define G4X_M2_SINGLE_CHANNEL_LVDS_MIN 5
  179. #define G4X_M2_SINGLE_CHANNEL_LVDS_MAX 11
  180. #define G4X_P_SINGLE_CHANNEL_LVDS_MIN 28
  181. #define G4X_P_SINGLE_CHANNEL_LVDS_MAX 112
  182. #define G4X_P1_SINGLE_CHANNEL_LVDS_MIN 2
  183. #define G4X_P1_SINGLE_CHANNEL_LVDS_MAX 8
  184. #define G4X_P2_SINGLE_CHANNEL_LVDS_SLOW 14
  185. #define G4X_P2_SINGLE_CHANNEL_LVDS_FAST 14
  186. #define G4X_P2_SINGLE_CHANNEL_LVDS_LIMIT 0
  187. /*The parameter is for DUAL_CHANNEL_LVDS on G4x platform*/
  188. #define G4X_DOT_DUAL_CHANNEL_LVDS_MIN 80000
  189. #define G4X_DOT_DUAL_CHANNEL_LVDS_MAX 224000
  190. #define G4X_N_DUAL_CHANNEL_LVDS_MIN 1
  191. #define G4X_N_DUAL_CHANNEL_LVDS_MAX 3
  192. #define G4X_M_DUAL_CHANNEL_LVDS_MIN 104
  193. #define G4X_M_DUAL_CHANNEL_LVDS_MAX 138
  194. #define G4X_M1_DUAL_CHANNEL_LVDS_MIN 17
  195. #define G4X_M1_DUAL_CHANNEL_LVDS_MAX 23
  196. #define G4X_M2_DUAL_CHANNEL_LVDS_MIN 5
  197. #define G4X_M2_DUAL_CHANNEL_LVDS_MAX 11
  198. #define G4X_P_DUAL_CHANNEL_LVDS_MIN 14
  199. #define G4X_P_DUAL_CHANNEL_LVDS_MAX 42
  200. #define G4X_P1_DUAL_CHANNEL_LVDS_MIN 2
  201. #define G4X_P1_DUAL_CHANNEL_LVDS_MAX 6
  202. #define G4X_P2_DUAL_CHANNEL_LVDS_SLOW 7
  203. #define G4X_P2_DUAL_CHANNEL_LVDS_FAST 7
  204. #define G4X_P2_DUAL_CHANNEL_LVDS_LIMIT 0
  205. /*The parameter is for DISPLAY PORT on G4x platform*/
  206. #define G4X_DOT_DISPLAY_PORT_MIN 161670
  207. #define G4X_DOT_DISPLAY_PORT_MAX 227000
  208. #define G4X_N_DISPLAY_PORT_MIN 1
  209. #define G4X_N_DISPLAY_PORT_MAX 2
  210. #define G4X_M_DISPLAY_PORT_MIN 97
  211. #define G4X_M_DISPLAY_PORT_MAX 108
  212. #define G4X_M1_DISPLAY_PORT_MIN 0x10
  213. #define G4X_M1_DISPLAY_PORT_MAX 0x12
  214. #define G4X_M2_DISPLAY_PORT_MIN 0x05
  215. #define G4X_M2_DISPLAY_PORT_MAX 0x06
  216. #define G4X_P_DISPLAY_PORT_MIN 10
  217. #define G4X_P_DISPLAY_PORT_MAX 20
  218. #define G4X_P1_DISPLAY_PORT_MIN 1
  219. #define G4X_P1_DISPLAY_PORT_MAX 2
  220. #define G4X_P2_DISPLAY_PORT_SLOW 10
  221. #define G4X_P2_DISPLAY_PORT_FAST 10
  222. #define G4X_P2_DISPLAY_PORT_LIMIT 0
  223. /* Ironlake / Sandybridge */
  224. /* as we calculate clock using (register_value + 2) for
  225. N/M1/M2, so here the range value for them is (actual_value-2).
  226. */
  227. #define IRONLAKE_DOT_MIN 25000
  228. #define IRONLAKE_DOT_MAX 350000
  229. #define IRONLAKE_VCO_MIN 1760000
  230. #define IRONLAKE_VCO_MAX 3510000
  231. #define IRONLAKE_M1_MIN 12
  232. #define IRONLAKE_M1_MAX 22
  233. #define IRONLAKE_M2_MIN 5
  234. #define IRONLAKE_M2_MAX 9
  235. #define IRONLAKE_P2_DOT_LIMIT 225000 /* 225Mhz */
  236. /* We have parameter ranges for different type of outputs. */
  237. /* DAC & HDMI Refclk 120Mhz */
  238. #define IRONLAKE_DAC_N_MIN 1
  239. #define IRONLAKE_DAC_N_MAX 5
  240. #define IRONLAKE_DAC_M_MIN 79
  241. #define IRONLAKE_DAC_M_MAX 127
  242. #define IRONLAKE_DAC_P_MIN 5
  243. #define IRONLAKE_DAC_P_MAX 80
  244. #define IRONLAKE_DAC_P1_MIN 1
  245. #define IRONLAKE_DAC_P1_MAX 8
  246. #define IRONLAKE_DAC_P2_SLOW 10
  247. #define IRONLAKE_DAC_P2_FAST 5
  248. /* LVDS single-channel 120Mhz refclk */
  249. #define IRONLAKE_LVDS_S_N_MIN 1
  250. #define IRONLAKE_LVDS_S_N_MAX 3
  251. #define IRONLAKE_LVDS_S_M_MIN 79
  252. #define IRONLAKE_LVDS_S_M_MAX 118
  253. #define IRONLAKE_LVDS_S_P_MIN 28
  254. #define IRONLAKE_LVDS_S_P_MAX 112
  255. #define IRONLAKE_LVDS_S_P1_MIN 2
  256. #define IRONLAKE_LVDS_S_P1_MAX 8
  257. #define IRONLAKE_LVDS_S_P2_SLOW 14
  258. #define IRONLAKE_LVDS_S_P2_FAST 14
  259. /* LVDS dual-channel 120Mhz refclk */
  260. #define IRONLAKE_LVDS_D_N_MIN 1
  261. #define IRONLAKE_LVDS_D_N_MAX 3
  262. #define IRONLAKE_LVDS_D_M_MIN 79
  263. #define IRONLAKE_LVDS_D_M_MAX 127
  264. #define IRONLAKE_LVDS_D_P_MIN 14
  265. #define IRONLAKE_LVDS_D_P_MAX 56
  266. #define IRONLAKE_LVDS_D_P1_MIN 2
  267. #define IRONLAKE_LVDS_D_P1_MAX 8
  268. #define IRONLAKE_LVDS_D_P2_SLOW 7
  269. #define IRONLAKE_LVDS_D_P2_FAST 7
  270. /* LVDS single-channel 100Mhz refclk */
  271. #define IRONLAKE_LVDS_S_SSC_N_MIN 1
  272. #define IRONLAKE_LVDS_S_SSC_N_MAX 2
  273. #define IRONLAKE_LVDS_S_SSC_M_MIN 79
  274. #define IRONLAKE_LVDS_S_SSC_M_MAX 126
  275. #define IRONLAKE_LVDS_S_SSC_P_MIN 28
  276. #define IRONLAKE_LVDS_S_SSC_P_MAX 112
  277. #define IRONLAKE_LVDS_S_SSC_P1_MIN 2
  278. #define IRONLAKE_LVDS_S_SSC_P1_MAX 8
  279. #define IRONLAKE_LVDS_S_SSC_P2_SLOW 14
  280. #define IRONLAKE_LVDS_S_SSC_P2_FAST 14
  281. /* LVDS dual-channel 100Mhz refclk */
  282. #define IRONLAKE_LVDS_D_SSC_N_MIN 1
  283. #define IRONLAKE_LVDS_D_SSC_N_MAX 3
  284. #define IRONLAKE_LVDS_D_SSC_M_MIN 79
  285. #define IRONLAKE_LVDS_D_SSC_M_MAX 126
  286. #define IRONLAKE_LVDS_D_SSC_P_MIN 14
  287. #define IRONLAKE_LVDS_D_SSC_P_MAX 42
  288. #define IRONLAKE_LVDS_D_SSC_P1_MIN 2
  289. #define IRONLAKE_LVDS_D_SSC_P1_MAX 6
  290. #define IRONLAKE_LVDS_D_SSC_P2_SLOW 7
  291. #define IRONLAKE_LVDS_D_SSC_P2_FAST 7
  292. /* DisplayPort */
  293. #define IRONLAKE_DP_N_MIN 1
  294. #define IRONLAKE_DP_N_MAX 2
  295. #define IRONLAKE_DP_M_MIN 81
  296. #define IRONLAKE_DP_M_MAX 90
  297. #define IRONLAKE_DP_P_MIN 10
  298. #define IRONLAKE_DP_P_MAX 20
  299. #define IRONLAKE_DP_P2_FAST 10
  300. #define IRONLAKE_DP_P2_SLOW 10
  301. #define IRONLAKE_DP_P2_LIMIT 0
  302. #define IRONLAKE_DP_P1_MIN 1
  303. #define IRONLAKE_DP_P1_MAX 2
  304. /* FDI */
  305. #define IRONLAKE_FDI_FREQ 2700000 /* in kHz for mode->clock */
  306. static bool
  307. intel_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
  308. int target, int refclk, intel_clock_t *best_clock);
  309. static bool
  310. intel_g4x_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
  311. int target, int refclk, intel_clock_t *best_clock);
  312. static bool
  313. intel_find_pll_g4x_dp(const intel_limit_t *, struct drm_crtc *crtc,
  314. int target, int refclk, intel_clock_t *best_clock);
  315. static bool
  316. intel_find_pll_ironlake_dp(const intel_limit_t *, struct drm_crtc *crtc,
  317. int target, int refclk, intel_clock_t *best_clock);
  318. static inline u32 /* units of 100MHz */
  319. intel_fdi_link_freq(struct drm_device *dev)
  320. {
  321. if (IS_GEN5(dev)) {
  322. struct drm_i915_private *dev_priv = dev->dev_private;
  323. return (I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK) + 2;
  324. } else
  325. return 27;
  326. }
  327. static const intel_limit_t intel_limits_i8xx_dvo = {
  328. .dot = { .min = I8XX_DOT_MIN, .max = I8XX_DOT_MAX },
  329. .vco = { .min = I8XX_VCO_MIN, .max = I8XX_VCO_MAX },
  330. .n = { .min = I8XX_N_MIN, .max = I8XX_N_MAX },
  331. .m = { .min = I8XX_M_MIN, .max = I8XX_M_MAX },
  332. .m1 = { .min = I8XX_M1_MIN, .max = I8XX_M1_MAX },
  333. .m2 = { .min = I8XX_M2_MIN, .max = I8XX_M2_MAX },
  334. .p = { .min = I8XX_P_MIN, .max = I8XX_P_MAX },
  335. .p1 = { .min = I8XX_P1_MIN, .max = I8XX_P1_MAX },
  336. .p2 = { .dot_limit = I8XX_P2_SLOW_LIMIT,
  337. .p2_slow = I8XX_P2_SLOW, .p2_fast = I8XX_P2_FAST },
  338. .find_pll = intel_find_best_PLL,
  339. };
  340. static const intel_limit_t intel_limits_i8xx_lvds = {
  341. .dot = { .min = I8XX_DOT_MIN, .max = I8XX_DOT_MAX },
  342. .vco = { .min = I8XX_VCO_MIN, .max = I8XX_VCO_MAX },
  343. .n = { .min = I8XX_N_MIN, .max = I8XX_N_MAX },
  344. .m = { .min = I8XX_M_MIN, .max = I8XX_M_MAX },
  345. .m1 = { .min = I8XX_M1_MIN, .max = I8XX_M1_MAX },
  346. .m2 = { .min = I8XX_M2_MIN, .max = I8XX_M2_MAX },
  347. .p = { .min = I8XX_P_MIN, .max = I8XX_P_MAX },
  348. .p1 = { .min = I8XX_P1_LVDS_MIN, .max = I8XX_P1_LVDS_MAX },
  349. .p2 = { .dot_limit = I8XX_P2_SLOW_LIMIT,
  350. .p2_slow = I8XX_P2_LVDS_SLOW, .p2_fast = I8XX_P2_LVDS_FAST },
  351. .find_pll = intel_find_best_PLL,
  352. };
  353. static const intel_limit_t intel_limits_i9xx_sdvo = {
  354. .dot = { .min = I9XX_DOT_MIN, .max = I9XX_DOT_MAX },
  355. .vco = { .min = I9XX_VCO_MIN, .max = I9XX_VCO_MAX },
  356. .n = { .min = I9XX_N_MIN, .max = I9XX_N_MAX },
  357. .m = { .min = I9XX_M_MIN, .max = I9XX_M_MAX },
  358. .m1 = { .min = I9XX_M1_MIN, .max = I9XX_M1_MAX },
  359. .m2 = { .min = I9XX_M2_MIN, .max = I9XX_M2_MAX },
  360. .p = { .min = I9XX_P_SDVO_DAC_MIN, .max = I9XX_P_SDVO_DAC_MAX },
  361. .p1 = { .min = I9XX_P1_MIN, .max = I9XX_P1_MAX },
  362. .p2 = { .dot_limit = I9XX_P2_SDVO_DAC_SLOW_LIMIT,
  363. .p2_slow = I9XX_P2_SDVO_DAC_SLOW, .p2_fast = I9XX_P2_SDVO_DAC_FAST },
  364. .find_pll = intel_find_best_PLL,
  365. };
  366. static const intel_limit_t intel_limits_i9xx_lvds = {
  367. .dot = { .min = I9XX_DOT_MIN, .max = I9XX_DOT_MAX },
  368. .vco = { .min = I9XX_VCO_MIN, .max = I9XX_VCO_MAX },
  369. .n = { .min = I9XX_N_MIN, .max = I9XX_N_MAX },
  370. .m = { .min = I9XX_M_MIN, .max = I9XX_M_MAX },
  371. .m1 = { .min = I9XX_M1_MIN, .max = I9XX_M1_MAX },
  372. .m2 = { .min = I9XX_M2_MIN, .max = I9XX_M2_MAX },
  373. .p = { .min = I9XX_P_LVDS_MIN, .max = I9XX_P_LVDS_MAX },
  374. .p1 = { .min = I9XX_P1_MIN, .max = I9XX_P1_MAX },
  375. /* The single-channel range is 25-112Mhz, and dual-channel
  376. * is 80-224Mhz. Prefer single channel as much as possible.
  377. */
  378. .p2 = { .dot_limit = I9XX_P2_LVDS_SLOW_LIMIT,
  379. .p2_slow = I9XX_P2_LVDS_SLOW, .p2_fast = I9XX_P2_LVDS_FAST },
  380. .find_pll = intel_find_best_PLL,
  381. };
  382. /* below parameter and function is for G4X Chipset Family*/
  383. static const intel_limit_t intel_limits_g4x_sdvo = {
  384. .dot = { .min = G4X_DOT_SDVO_MIN, .max = G4X_DOT_SDVO_MAX },
  385. .vco = { .min = G4X_VCO_MIN, .max = G4X_VCO_MAX},
  386. .n = { .min = G4X_N_SDVO_MIN, .max = G4X_N_SDVO_MAX },
  387. .m = { .min = G4X_M_SDVO_MIN, .max = G4X_M_SDVO_MAX },
  388. .m1 = { .min = G4X_M1_SDVO_MIN, .max = G4X_M1_SDVO_MAX },
  389. .m2 = { .min = G4X_M2_SDVO_MIN, .max = G4X_M2_SDVO_MAX },
  390. .p = { .min = G4X_P_SDVO_MIN, .max = G4X_P_SDVO_MAX },
  391. .p1 = { .min = G4X_P1_SDVO_MIN, .max = G4X_P1_SDVO_MAX},
  392. .p2 = { .dot_limit = G4X_P2_SDVO_LIMIT,
  393. .p2_slow = G4X_P2_SDVO_SLOW,
  394. .p2_fast = G4X_P2_SDVO_FAST
  395. },
  396. .find_pll = intel_g4x_find_best_PLL,
  397. };
  398. static const intel_limit_t intel_limits_g4x_hdmi = {
  399. .dot = { .min = G4X_DOT_HDMI_DAC_MIN, .max = G4X_DOT_HDMI_DAC_MAX },
  400. .vco = { .min = G4X_VCO_MIN, .max = G4X_VCO_MAX},
  401. .n = { .min = G4X_N_HDMI_DAC_MIN, .max = G4X_N_HDMI_DAC_MAX },
  402. .m = { .min = G4X_M_HDMI_DAC_MIN, .max = G4X_M_HDMI_DAC_MAX },
  403. .m1 = { .min = G4X_M1_HDMI_DAC_MIN, .max = G4X_M1_HDMI_DAC_MAX },
  404. .m2 = { .min = G4X_M2_HDMI_DAC_MIN, .max = G4X_M2_HDMI_DAC_MAX },
  405. .p = { .min = G4X_P_HDMI_DAC_MIN, .max = G4X_P_HDMI_DAC_MAX },
  406. .p1 = { .min = G4X_P1_HDMI_DAC_MIN, .max = G4X_P1_HDMI_DAC_MAX},
  407. .p2 = { .dot_limit = G4X_P2_HDMI_DAC_LIMIT,
  408. .p2_slow = G4X_P2_HDMI_DAC_SLOW,
  409. .p2_fast = G4X_P2_HDMI_DAC_FAST
  410. },
  411. .find_pll = intel_g4x_find_best_PLL,
  412. };
  413. static const intel_limit_t intel_limits_g4x_single_channel_lvds = {
  414. .dot = { .min = G4X_DOT_SINGLE_CHANNEL_LVDS_MIN,
  415. .max = G4X_DOT_SINGLE_CHANNEL_LVDS_MAX },
  416. .vco = { .min = G4X_VCO_MIN,
  417. .max = G4X_VCO_MAX },
  418. .n = { .min = G4X_N_SINGLE_CHANNEL_LVDS_MIN,
  419. .max = G4X_N_SINGLE_CHANNEL_LVDS_MAX },
  420. .m = { .min = G4X_M_SINGLE_CHANNEL_LVDS_MIN,
  421. .max = G4X_M_SINGLE_CHANNEL_LVDS_MAX },
  422. .m1 = { .min = G4X_M1_SINGLE_CHANNEL_LVDS_MIN,
  423. .max = G4X_M1_SINGLE_CHANNEL_LVDS_MAX },
  424. .m2 = { .min = G4X_M2_SINGLE_CHANNEL_LVDS_MIN,
  425. .max = G4X_M2_SINGLE_CHANNEL_LVDS_MAX },
  426. .p = { .min = G4X_P_SINGLE_CHANNEL_LVDS_MIN,
  427. .max = G4X_P_SINGLE_CHANNEL_LVDS_MAX },
  428. .p1 = { .min = G4X_P1_SINGLE_CHANNEL_LVDS_MIN,
  429. .max = G4X_P1_SINGLE_CHANNEL_LVDS_MAX },
  430. .p2 = { .dot_limit = G4X_P2_SINGLE_CHANNEL_LVDS_LIMIT,
  431. .p2_slow = G4X_P2_SINGLE_CHANNEL_LVDS_SLOW,
  432. .p2_fast = G4X_P2_SINGLE_CHANNEL_LVDS_FAST
  433. },
  434. .find_pll = intel_g4x_find_best_PLL,
  435. };
  436. static const intel_limit_t intel_limits_g4x_dual_channel_lvds = {
  437. .dot = { .min = G4X_DOT_DUAL_CHANNEL_LVDS_MIN,
  438. .max = G4X_DOT_DUAL_CHANNEL_LVDS_MAX },
  439. .vco = { .min = G4X_VCO_MIN,
  440. .max = G4X_VCO_MAX },
  441. .n = { .min = G4X_N_DUAL_CHANNEL_LVDS_MIN,
  442. .max = G4X_N_DUAL_CHANNEL_LVDS_MAX },
  443. .m = { .min = G4X_M_DUAL_CHANNEL_LVDS_MIN,
  444. .max = G4X_M_DUAL_CHANNEL_LVDS_MAX },
  445. .m1 = { .min = G4X_M1_DUAL_CHANNEL_LVDS_MIN,
  446. .max = G4X_M1_DUAL_CHANNEL_LVDS_MAX },
  447. .m2 = { .min = G4X_M2_DUAL_CHANNEL_LVDS_MIN,
  448. .max = G4X_M2_DUAL_CHANNEL_LVDS_MAX },
  449. .p = { .min = G4X_P_DUAL_CHANNEL_LVDS_MIN,
  450. .max = G4X_P_DUAL_CHANNEL_LVDS_MAX },
  451. .p1 = { .min = G4X_P1_DUAL_CHANNEL_LVDS_MIN,
  452. .max = G4X_P1_DUAL_CHANNEL_LVDS_MAX },
  453. .p2 = { .dot_limit = G4X_P2_DUAL_CHANNEL_LVDS_LIMIT,
  454. .p2_slow = G4X_P2_DUAL_CHANNEL_LVDS_SLOW,
  455. .p2_fast = G4X_P2_DUAL_CHANNEL_LVDS_FAST
  456. },
  457. .find_pll = intel_g4x_find_best_PLL,
  458. };
  459. static const intel_limit_t intel_limits_g4x_display_port = {
  460. .dot = { .min = G4X_DOT_DISPLAY_PORT_MIN,
  461. .max = G4X_DOT_DISPLAY_PORT_MAX },
  462. .vco = { .min = G4X_VCO_MIN,
  463. .max = G4X_VCO_MAX},
  464. .n = { .min = G4X_N_DISPLAY_PORT_MIN,
  465. .max = G4X_N_DISPLAY_PORT_MAX },
  466. .m = { .min = G4X_M_DISPLAY_PORT_MIN,
  467. .max = G4X_M_DISPLAY_PORT_MAX },
  468. .m1 = { .min = G4X_M1_DISPLAY_PORT_MIN,
  469. .max = G4X_M1_DISPLAY_PORT_MAX },
  470. .m2 = { .min = G4X_M2_DISPLAY_PORT_MIN,
  471. .max = G4X_M2_DISPLAY_PORT_MAX },
  472. .p = { .min = G4X_P_DISPLAY_PORT_MIN,
  473. .max = G4X_P_DISPLAY_PORT_MAX },
  474. .p1 = { .min = G4X_P1_DISPLAY_PORT_MIN,
  475. .max = G4X_P1_DISPLAY_PORT_MAX},
  476. .p2 = { .dot_limit = G4X_P2_DISPLAY_PORT_LIMIT,
  477. .p2_slow = G4X_P2_DISPLAY_PORT_SLOW,
  478. .p2_fast = G4X_P2_DISPLAY_PORT_FAST },
  479. .find_pll = intel_find_pll_g4x_dp,
  480. };
  481. static const intel_limit_t intel_limits_pineview_sdvo = {
  482. .dot = { .min = I9XX_DOT_MIN, .max = I9XX_DOT_MAX},
  483. .vco = { .min = PINEVIEW_VCO_MIN, .max = PINEVIEW_VCO_MAX },
  484. .n = { .min = PINEVIEW_N_MIN, .max = PINEVIEW_N_MAX },
  485. .m = { .min = PINEVIEW_M_MIN, .max = PINEVIEW_M_MAX },
  486. .m1 = { .min = PINEVIEW_M1_MIN, .max = PINEVIEW_M1_MAX },
  487. .m2 = { .min = PINEVIEW_M2_MIN, .max = PINEVIEW_M2_MAX },
  488. .p = { .min = I9XX_P_SDVO_DAC_MIN, .max = I9XX_P_SDVO_DAC_MAX },
  489. .p1 = { .min = I9XX_P1_MIN, .max = I9XX_P1_MAX },
  490. .p2 = { .dot_limit = I9XX_P2_SDVO_DAC_SLOW_LIMIT,
  491. .p2_slow = I9XX_P2_SDVO_DAC_SLOW, .p2_fast = I9XX_P2_SDVO_DAC_FAST },
  492. .find_pll = intel_find_best_PLL,
  493. };
  494. static const intel_limit_t intel_limits_pineview_lvds = {
  495. .dot = { .min = I9XX_DOT_MIN, .max = I9XX_DOT_MAX },
  496. .vco = { .min = PINEVIEW_VCO_MIN, .max = PINEVIEW_VCO_MAX },
  497. .n = { .min = PINEVIEW_N_MIN, .max = PINEVIEW_N_MAX },
  498. .m = { .min = PINEVIEW_M_MIN, .max = PINEVIEW_M_MAX },
  499. .m1 = { .min = PINEVIEW_M1_MIN, .max = PINEVIEW_M1_MAX },
  500. .m2 = { .min = PINEVIEW_M2_MIN, .max = PINEVIEW_M2_MAX },
  501. .p = { .min = PINEVIEW_P_LVDS_MIN, .max = PINEVIEW_P_LVDS_MAX },
  502. .p1 = { .min = I9XX_P1_MIN, .max = I9XX_P1_MAX },
  503. /* Pineview only supports single-channel mode. */
  504. .p2 = { .dot_limit = I9XX_P2_LVDS_SLOW_LIMIT,
  505. .p2_slow = I9XX_P2_LVDS_SLOW, .p2_fast = I9XX_P2_LVDS_SLOW },
  506. .find_pll = intel_find_best_PLL,
  507. };
  508. static const intel_limit_t intel_limits_ironlake_dac = {
  509. .dot = { .min = IRONLAKE_DOT_MIN, .max = IRONLAKE_DOT_MAX },
  510. .vco = { .min = IRONLAKE_VCO_MIN, .max = IRONLAKE_VCO_MAX },
  511. .n = { .min = IRONLAKE_DAC_N_MIN, .max = IRONLAKE_DAC_N_MAX },
  512. .m = { .min = IRONLAKE_DAC_M_MIN, .max = IRONLAKE_DAC_M_MAX },
  513. .m1 = { .min = IRONLAKE_M1_MIN, .max = IRONLAKE_M1_MAX },
  514. .m2 = { .min = IRONLAKE_M2_MIN, .max = IRONLAKE_M2_MAX },
  515. .p = { .min = IRONLAKE_DAC_P_MIN, .max = IRONLAKE_DAC_P_MAX },
  516. .p1 = { .min = IRONLAKE_DAC_P1_MIN, .max = IRONLAKE_DAC_P1_MAX },
  517. .p2 = { .dot_limit = IRONLAKE_P2_DOT_LIMIT,
  518. .p2_slow = IRONLAKE_DAC_P2_SLOW,
  519. .p2_fast = IRONLAKE_DAC_P2_FAST },
  520. .find_pll = intel_g4x_find_best_PLL,
  521. };
  522. static const intel_limit_t intel_limits_ironlake_single_lvds = {
  523. .dot = { .min = IRONLAKE_DOT_MIN, .max = IRONLAKE_DOT_MAX },
  524. .vco = { .min = IRONLAKE_VCO_MIN, .max = IRONLAKE_VCO_MAX },
  525. .n = { .min = IRONLAKE_LVDS_S_N_MIN, .max = IRONLAKE_LVDS_S_N_MAX },
  526. .m = { .min = IRONLAKE_LVDS_S_M_MIN, .max = IRONLAKE_LVDS_S_M_MAX },
  527. .m1 = { .min = IRONLAKE_M1_MIN, .max = IRONLAKE_M1_MAX },
  528. .m2 = { .min = IRONLAKE_M2_MIN, .max = IRONLAKE_M2_MAX },
  529. .p = { .min = IRONLAKE_LVDS_S_P_MIN, .max = IRONLAKE_LVDS_S_P_MAX },
  530. .p1 = { .min = IRONLAKE_LVDS_S_P1_MIN, .max = IRONLAKE_LVDS_S_P1_MAX },
  531. .p2 = { .dot_limit = IRONLAKE_P2_DOT_LIMIT,
  532. .p2_slow = IRONLAKE_LVDS_S_P2_SLOW,
  533. .p2_fast = IRONLAKE_LVDS_S_P2_FAST },
  534. .find_pll = intel_g4x_find_best_PLL,
  535. };
  536. static const intel_limit_t intel_limits_ironlake_dual_lvds = {
  537. .dot = { .min = IRONLAKE_DOT_MIN, .max = IRONLAKE_DOT_MAX },
  538. .vco = { .min = IRONLAKE_VCO_MIN, .max = IRONLAKE_VCO_MAX },
  539. .n = { .min = IRONLAKE_LVDS_D_N_MIN, .max = IRONLAKE_LVDS_D_N_MAX },
  540. .m = { .min = IRONLAKE_LVDS_D_M_MIN, .max = IRONLAKE_LVDS_D_M_MAX },
  541. .m1 = { .min = IRONLAKE_M1_MIN, .max = IRONLAKE_M1_MAX },
  542. .m2 = { .min = IRONLAKE_M2_MIN, .max = IRONLAKE_M2_MAX },
  543. .p = { .min = IRONLAKE_LVDS_D_P_MIN, .max = IRONLAKE_LVDS_D_P_MAX },
  544. .p1 = { .min = IRONLAKE_LVDS_D_P1_MIN, .max = IRONLAKE_LVDS_D_P1_MAX },
  545. .p2 = { .dot_limit = IRONLAKE_P2_DOT_LIMIT,
  546. .p2_slow = IRONLAKE_LVDS_D_P2_SLOW,
  547. .p2_fast = IRONLAKE_LVDS_D_P2_FAST },
  548. .find_pll = intel_g4x_find_best_PLL,
  549. };
  550. static const intel_limit_t intel_limits_ironlake_single_lvds_100m = {
  551. .dot = { .min = IRONLAKE_DOT_MIN, .max = IRONLAKE_DOT_MAX },
  552. .vco = { .min = IRONLAKE_VCO_MIN, .max = IRONLAKE_VCO_MAX },
  553. .n = { .min = IRONLAKE_LVDS_S_SSC_N_MIN, .max = IRONLAKE_LVDS_S_SSC_N_MAX },
  554. .m = { .min = IRONLAKE_LVDS_S_SSC_M_MIN, .max = IRONLAKE_LVDS_S_SSC_M_MAX },
  555. .m1 = { .min = IRONLAKE_M1_MIN, .max = IRONLAKE_M1_MAX },
  556. .m2 = { .min = IRONLAKE_M2_MIN, .max = IRONLAKE_M2_MAX },
  557. .p = { .min = IRONLAKE_LVDS_S_SSC_P_MIN, .max = IRONLAKE_LVDS_S_SSC_P_MAX },
  558. .p1 = { .min = IRONLAKE_LVDS_S_SSC_P1_MIN,.max = IRONLAKE_LVDS_S_SSC_P1_MAX },
  559. .p2 = { .dot_limit = IRONLAKE_P2_DOT_LIMIT,
  560. .p2_slow = IRONLAKE_LVDS_S_SSC_P2_SLOW,
  561. .p2_fast = IRONLAKE_LVDS_S_SSC_P2_FAST },
  562. .find_pll = intel_g4x_find_best_PLL,
  563. };
  564. static const intel_limit_t intel_limits_ironlake_dual_lvds_100m = {
  565. .dot = { .min = IRONLAKE_DOT_MIN, .max = IRONLAKE_DOT_MAX },
  566. .vco = { .min = IRONLAKE_VCO_MIN, .max = IRONLAKE_VCO_MAX },
  567. .n = { .min = IRONLAKE_LVDS_D_SSC_N_MIN, .max = IRONLAKE_LVDS_D_SSC_N_MAX },
  568. .m = { .min = IRONLAKE_LVDS_D_SSC_M_MIN, .max = IRONLAKE_LVDS_D_SSC_M_MAX },
  569. .m1 = { .min = IRONLAKE_M1_MIN, .max = IRONLAKE_M1_MAX },
  570. .m2 = { .min = IRONLAKE_M2_MIN, .max = IRONLAKE_M2_MAX },
  571. .p = { .min = IRONLAKE_LVDS_D_SSC_P_MIN, .max = IRONLAKE_LVDS_D_SSC_P_MAX },
  572. .p1 = { .min = IRONLAKE_LVDS_D_SSC_P1_MIN,.max = IRONLAKE_LVDS_D_SSC_P1_MAX },
  573. .p2 = { .dot_limit = IRONLAKE_P2_DOT_LIMIT,
  574. .p2_slow = IRONLAKE_LVDS_D_SSC_P2_SLOW,
  575. .p2_fast = IRONLAKE_LVDS_D_SSC_P2_FAST },
  576. .find_pll = intel_g4x_find_best_PLL,
  577. };
  578. static const intel_limit_t intel_limits_ironlake_display_port = {
  579. .dot = { .min = IRONLAKE_DOT_MIN,
  580. .max = IRONLAKE_DOT_MAX },
  581. .vco = { .min = IRONLAKE_VCO_MIN,
  582. .max = IRONLAKE_VCO_MAX},
  583. .n = { .min = IRONLAKE_DP_N_MIN,
  584. .max = IRONLAKE_DP_N_MAX },
  585. .m = { .min = IRONLAKE_DP_M_MIN,
  586. .max = IRONLAKE_DP_M_MAX },
  587. .m1 = { .min = IRONLAKE_M1_MIN,
  588. .max = IRONLAKE_M1_MAX },
  589. .m2 = { .min = IRONLAKE_M2_MIN,
  590. .max = IRONLAKE_M2_MAX },
  591. .p = { .min = IRONLAKE_DP_P_MIN,
  592. .max = IRONLAKE_DP_P_MAX },
  593. .p1 = { .min = IRONLAKE_DP_P1_MIN,
  594. .max = IRONLAKE_DP_P1_MAX},
  595. .p2 = { .dot_limit = IRONLAKE_DP_P2_LIMIT,
  596. .p2_slow = IRONLAKE_DP_P2_SLOW,
  597. .p2_fast = IRONLAKE_DP_P2_FAST },
  598. .find_pll = intel_find_pll_ironlake_dp,
  599. };
  600. static const intel_limit_t *intel_ironlake_limit(struct drm_crtc *crtc,
  601. int refclk)
  602. {
  603. struct drm_device *dev = crtc->dev;
  604. struct drm_i915_private *dev_priv = dev->dev_private;
  605. const intel_limit_t *limit;
  606. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  607. if ((I915_READ(PCH_LVDS) & LVDS_CLKB_POWER_MASK) ==
  608. LVDS_CLKB_POWER_UP) {
  609. /* LVDS dual channel */
  610. if (refclk == 100000)
  611. limit = &intel_limits_ironlake_dual_lvds_100m;
  612. else
  613. limit = &intel_limits_ironlake_dual_lvds;
  614. } else {
  615. if (refclk == 100000)
  616. limit = &intel_limits_ironlake_single_lvds_100m;
  617. else
  618. limit = &intel_limits_ironlake_single_lvds;
  619. }
  620. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) ||
  621. HAS_eDP)
  622. limit = &intel_limits_ironlake_display_port;
  623. else
  624. limit = &intel_limits_ironlake_dac;
  625. return limit;
  626. }
  627. static const intel_limit_t *intel_g4x_limit(struct drm_crtc *crtc)
  628. {
  629. struct drm_device *dev = crtc->dev;
  630. struct drm_i915_private *dev_priv = dev->dev_private;
  631. const intel_limit_t *limit;
  632. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  633. if ((I915_READ(LVDS) & LVDS_CLKB_POWER_MASK) ==
  634. LVDS_CLKB_POWER_UP)
  635. /* LVDS with dual channel */
  636. limit = &intel_limits_g4x_dual_channel_lvds;
  637. else
  638. /* LVDS with dual channel */
  639. limit = &intel_limits_g4x_single_channel_lvds;
  640. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI) ||
  641. intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG)) {
  642. limit = &intel_limits_g4x_hdmi;
  643. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO)) {
  644. limit = &intel_limits_g4x_sdvo;
  645. } else if (intel_pipe_has_type (crtc, INTEL_OUTPUT_DISPLAYPORT)) {
  646. limit = &intel_limits_g4x_display_port;
  647. } else /* The option is for other outputs */
  648. limit = &intel_limits_i9xx_sdvo;
  649. return limit;
  650. }
  651. static const intel_limit_t *intel_limit(struct drm_crtc *crtc, int refclk)
  652. {
  653. struct drm_device *dev = crtc->dev;
  654. const intel_limit_t *limit;
  655. if (HAS_PCH_SPLIT(dev))
  656. limit = intel_ironlake_limit(crtc, refclk);
  657. else if (IS_G4X(dev)) {
  658. limit = intel_g4x_limit(crtc);
  659. } else if (IS_PINEVIEW(dev)) {
  660. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  661. limit = &intel_limits_pineview_lvds;
  662. else
  663. limit = &intel_limits_pineview_sdvo;
  664. } else if (!IS_GEN2(dev)) {
  665. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  666. limit = &intel_limits_i9xx_lvds;
  667. else
  668. limit = &intel_limits_i9xx_sdvo;
  669. } else {
  670. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  671. limit = &intel_limits_i8xx_lvds;
  672. else
  673. limit = &intel_limits_i8xx_dvo;
  674. }
  675. return limit;
  676. }
  677. /* m1 is reserved as 0 in Pineview, n is a ring counter */
  678. static void pineview_clock(int refclk, intel_clock_t *clock)
  679. {
  680. clock->m = clock->m2 + 2;
  681. clock->p = clock->p1 * clock->p2;
  682. clock->vco = refclk * clock->m / clock->n;
  683. clock->dot = clock->vco / clock->p;
  684. }
  685. static void intel_clock(struct drm_device *dev, int refclk, intel_clock_t *clock)
  686. {
  687. if (IS_PINEVIEW(dev)) {
  688. pineview_clock(refclk, clock);
  689. return;
  690. }
  691. clock->m = 5 * (clock->m1 + 2) + (clock->m2 + 2);
  692. clock->p = clock->p1 * clock->p2;
  693. clock->vco = refclk * clock->m / (clock->n + 2);
  694. clock->dot = clock->vco / clock->p;
  695. }
  696. /**
  697. * Returns whether any output on the specified pipe is of the specified type
  698. */
  699. bool intel_pipe_has_type(struct drm_crtc *crtc, int type)
  700. {
  701. struct drm_device *dev = crtc->dev;
  702. struct drm_mode_config *mode_config = &dev->mode_config;
  703. struct intel_encoder *encoder;
  704. list_for_each_entry(encoder, &mode_config->encoder_list, base.head)
  705. if (encoder->base.crtc == crtc && encoder->type == type)
  706. return true;
  707. return false;
  708. }
  709. #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
  710. /**
  711. * Returns whether the given set of divisors are valid for a given refclk with
  712. * the given connectors.
  713. */
  714. static bool intel_PLL_is_valid(struct drm_device *dev,
  715. const intel_limit_t *limit,
  716. const intel_clock_t *clock)
  717. {
  718. if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1)
  719. INTELPllInvalid ("p1 out of range\n");
  720. if (clock->p < limit->p.min || limit->p.max < clock->p)
  721. INTELPllInvalid ("p out of range\n");
  722. if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2)
  723. INTELPllInvalid ("m2 out of range\n");
  724. if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1)
  725. INTELPllInvalid ("m1 out of range\n");
  726. if (clock->m1 <= clock->m2 && !IS_PINEVIEW(dev))
  727. INTELPllInvalid ("m1 <= m2\n");
  728. if (clock->m < limit->m.min || limit->m.max < clock->m)
  729. INTELPllInvalid ("m out of range\n");
  730. if (clock->n < limit->n.min || limit->n.max < clock->n)
  731. INTELPllInvalid ("n out of range\n");
  732. if (clock->vco < limit->vco.min || limit->vco.max < clock->vco)
  733. INTELPllInvalid ("vco out of range\n");
  734. /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
  735. * connector, etc., rather than just a single range.
  736. */
  737. if (clock->dot < limit->dot.min || limit->dot.max < clock->dot)
  738. INTELPllInvalid ("dot out of range\n");
  739. return true;
  740. }
  741. static bool
  742. intel_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
  743. int target, int refclk, intel_clock_t *best_clock)
  744. {
  745. struct drm_device *dev = crtc->dev;
  746. struct drm_i915_private *dev_priv = dev->dev_private;
  747. intel_clock_t clock;
  748. int err = target;
  749. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
  750. (I915_READ(LVDS)) != 0) {
  751. /*
  752. * For LVDS, if the panel is on, just rely on its current
  753. * settings for dual-channel. We haven't figured out how to
  754. * reliably set up different single/dual channel state, if we
  755. * even can.
  756. */
  757. if ((I915_READ(LVDS) & LVDS_CLKB_POWER_MASK) ==
  758. LVDS_CLKB_POWER_UP)
  759. clock.p2 = limit->p2.p2_fast;
  760. else
  761. clock.p2 = limit->p2.p2_slow;
  762. } else {
  763. if (target < limit->p2.dot_limit)
  764. clock.p2 = limit->p2.p2_slow;
  765. else
  766. clock.p2 = limit->p2.p2_fast;
  767. }
  768. memset (best_clock, 0, sizeof (*best_clock));
  769. for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
  770. clock.m1++) {
  771. for (clock.m2 = limit->m2.min;
  772. clock.m2 <= limit->m2.max; clock.m2++) {
  773. /* m1 is always 0 in Pineview */
  774. if (clock.m2 >= clock.m1 && !IS_PINEVIEW(dev))
  775. break;
  776. for (clock.n = limit->n.min;
  777. clock.n <= limit->n.max; clock.n++) {
  778. for (clock.p1 = limit->p1.min;
  779. clock.p1 <= limit->p1.max; clock.p1++) {
  780. int this_err;
  781. intel_clock(dev, refclk, &clock);
  782. if (!intel_PLL_is_valid(dev, limit,
  783. &clock))
  784. continue;
  785. this_err = abs(clock.dot - target);
  786. if (this_err < err) {
  787. *best_clock = clock;
  788. err = this_err;
  789. }
  790. }
  791. }
  792. }
  793. }
  794. return (err != target);
  795. }
  796. static bool
  797. intel_g4x_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
  798. int target, int refclk, intel_clock_t *best_clock)
  799. {
  800. struct drm_device *dev = crtc->dev;
  801. struct drm_i915_private *dev_priv = dev->dev_private;
  802. intel_clock_t clock;
  803. int max_n;
  804. bool found;
  805. /* approximately equals target * 0.00585 */
  806. int err_most = (target >> 8) + (target >> 9);
  807. found = false;
  808. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  809. int lvds_reg;
  810. if (HAS_PCH_SPLIT(dev))
  811. lvds_reg = PCH_LVDS;
  812. else
  813. lvds_reg = LVDS;
  814. if ((I915_READ(lvds_reg) & LVDS_CLKB_POWER_MASK) ==
  815. LVDS_CLKB_POWER_UP)
  816. clock.p2 = limit->p2.p2_fast;
  817. else
  818. clock.p2 = limit->p2.p2_slow;
  819. } else {
  820. if (target < limit->p2.dot_limit)
  821. clock.p2 = limit->p2.p2_slow;
  822. else
  823. clock.p2 = limit->p2.p2_fast;
  824. }
  825. memset(best_clock, 0, sizeof(*best_clock));
  826. max_n = limit->n.max;
  827. /* based on hardware requirement, prefer smaller n to precision */
  828. for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
  829. /* based on hardware requirement, prefere larger m1,m2 */
  830. for (clock.m1 = limit->m1.max;
  831. clock.m1 >= limit->m1.min; clock.m1--) {
  832. for (clock.m2 = limit->m2.max;
  833. clock.m2 >= limit->m2.min; clock.m2--) {
  834. for (clock.p1 = limit->p1.max;
  835. clock.p1 >= limit->p1.min; clock.p1--) {
  836. int this_err;
  837. intel_clock(dev, refclk, &clock);
  838. if (!intel_PLL_is_valid(dev, limit,
  839. &clock))
  840. continue;
  841. this_err = abs(clock.dot - target);
  842. if (this_err < err_most) {
  843. *best_clock = clock;
  844. err_most = this_err;
  845. max_n = clock.n;
  846. found = true;
  847. }
  848. }
  849. }
  850. }
  851. }
  852. return found;
  853. }
  854. static bool
  855. intel_find_pll_ironlake_dp(const intel_limit_t *limit, struct drm_crtc *crtc,
  856. int target, int refclk, intel_clock_t *best_clock)
  857. {
  858. struct drm_device *dev = crtc->dev;
  859. intel_clock_t clock;
  860. if (target < 200000) {
  861. clock.n = 1;
  862. clock.p1 = 2;
  863. clock.p2 = 10;
  864. clock.m1 = 12;
  865. clock.m2 = 9;
  866. } else {
  867. clock.n = 2;
  868. clock.p1 = 1;
  869. clock.p2 = 10;
  870. clock.m1 = 14;
  871. clock.m2 = 8;
  872. }
  873. intel_clock(dev, refclk, &clock);
  874. memcpy(best_clock, &clock, sizeof(intel_clock_t));
  875. return true;
  876. }
  877. /* DisplayPort has only two frequencies, 162MHz and 270MHz */
  878. static bool
  879. intel_find_pll_g4x_dp(const intel_limit_t *limit, struct drm_crtc *crtc,
  880. int target, int refclk, intel_clock_t *best_clock)
  881. {
  882. intel_clock_t clock;
  883. if (target < 200000) {
  884. clock.p1 = 2;
  885. clock.p2 = 10;
  886. clock.n = 2;
  887. clock.m1 = 23;
  888. clock.m2 = 8;
  889. } else {
  890. clock.p1 = 1;
  891. clock.p2 = 10;
  892. clock.n = 1;
  893. clock.m1 = 14;
  894. clock.m2 = 2;
  895. }
  896. clock.m = 5 * (clock.m1 + 2) + (clock.m2 + 2);
  897. clock.p = (clock.p1 * clock.p2);
  898. clock.dot = 96000 * clock.m / (clock.n + 2) / clock.p;
  899. clock.vco = 0;
  900. memcpy(best_clock, &clock, sizeof(intel_clock_t));
  901. return true;
  902. }
  903. /**
  904. * intel_wait_for_vblank - wait for vblank on a given pipe
  905. * @dev: drm device
  906. * @pipe: pipe to wait for
  907. *
  908. * Wait for vblank to occur on a given pipe. Needed for various bits of
  909. * mode setting code.
  910. */
  911. void intel_wait_for_vblank(struct drm_device *dev, int pipe)
  912. {
  913. struct drm_i915_private *dev_priv = dev->dev_private;
  914. int pipestat_reg = PIPESTAT(pipe);
  915. /* Clear existing vblank status. Note this will clear any other
  916. * sticky status fields as well.
  917. *
  918. * This races with i915_driver_irq_handler() with the result
  919. * that either function could miss a vblank event. Here it is not
  920. * fatal, as we will either wait upon the next vblank interrupt or
  921. * timeout. Generally speaking intel_wait_for_vblank() is only
  922. * called during modeset at which time the GPU should be idle and
  923. * should *not* be performing page flips and thus not waiting on
  924. * vblanks...
  925. * Currently, the result of us stealing a vblank from the irq
  926. * handler is that a single frame will be skipped during swapbuffers.
  927. */
  928. I915_WRITE(pipestat_reg,
  929. I915_READ(pipestat_reg) | PIPE_VBLANK_INTERRUPT_STATUS);
  930. /* Wait for vblank interrupt bit to set */
  931. if (wait_for(I915_READ(pipestat_reg) &
  932. PIPE_VBLANK_INTERRUPT_STATUS,
  933. 50))
  934. DRM_DEBUG_KMS("vblank wait timed out\n");
  935. }
  936. /*
  937. * intel_wait_for_pipe_off - wait for pipe to turn off
  938. * @dev: drm device
  939. * @pipe: pipe to wait for
  940. *
  941. * After disabling a pipe, we can't wait for vblank in the usual way,
  942. * spinning on the vblank interrupt status bit, since we won't actually
  943. * see an interrupt when the pipe is disabled.
  944. *
  945. * On Gen4 and above:
  946. * wait for the pipe register state bit to turn off
  947. *
  948. * Otherwise:
  949. * wait for the display line value to settle (it usually
  950. * ends up stopping at the start of the next frame).
  951. *
  952. */
  953. void intel_wait_for_pipe_off(struct drm_device *dev, int pipe)
  954. {
  955. struct drm_i915_private *dev_priv = dev->dev_private;
  956. if (INTEL_INFO(dev)->gen >= 4) {
  957. int reg = PIPECONF(pipe);
  958. /* Wait for the Pipe State to go off */
  959. if (wait_for((I915_READ(reg) & I965_PIPECONF_ACTIVE) == 0,
  960. 100))
  961. DRM_DEBUG_KMS("pipe_off wait timed out\n");
  962. } else {
  963. u32 last_line;
  964. int reg = PIPEDSL(pipe);
  965. unsigned long timeout = jiffies + msecs_to_jiffies(100);
  966. /* Wait for the display line to settle */
  967. do {
  968. last_line = I915_READ(reg) & DSL_LINEMASK;
  969. mdelay(5);
  970. } while (((I915_READ(reg) & DSL_LINEMASK) != last_line) &&
  971. time_after(timeout, jiffies));
  972. if (time_after(jiffies, timeout))
  973. DRM_DEBUG_KMS("pipe_off wait timed out\n");
  974. }
  975. }
  976. static const char *state_string(bool enabled)
  977. {
  978. return enabled ? "on" : "off";
  979. }
  980. /* Only for pre-ILK configs */
  981. static void assert_pll(struct drm_i915_private *dev_priv,
  982. enum pipe pipe, bool state)
  983. {
  984. int reg;
  985. u32 val;
  986. bool cur_state;
  987. reg = DPLL(pipe);
  988. val = I915_READ(reg);
  989. cur_state = !!(val & DPLL_VCO_ENABLE);
  990. WARN(cur_state != state,
  991. "PLL state assertion failure (expected %s, current %s)\n",
  992. state_string(state), state_string(cur_state));
  993. }
  994. #define assert_pll_enabled(d, p) assert_pll(d, p, true)
  995. #define assert_pll_disabled(d, p) assert_pll(d, p, false)
  996. /* For ILK+ */
  997. static void assert_pch_pll(struct drm_i915_private *dev_priv,
  998. enum pipe pipe, bool state)
  999. {
  1000. int reg;
  1001. u32 val;
  1002. bool cur_state;
  1003. reg = PCH_DPLL(pipe);
  1004. val = I915_READ(reg);
  1005. cur_state = !!(val & DPLL_VCO_ENABLE);
  1006. WARN(cur_state != state,
  1007. "PCH PLL state assertion failure (expected %s, current %s)\n",
  1008. state_string(state), state_string(cur_state));
  1009. }
  1010. #define assert_pch_pll_enabled(d, p) assert_pch_pll(d, p, true)
  1011. #define assert_pch_pll_disabled(d, p) assert_pch_pll(d, p, false)
  1012. static void assert_fdi_tx(struct drm_i915_private *dev_priv,
  1013. enum pipe pipe, bool state)
  1014. {
  1015. int reg;
  1016. u32 val;
  1017. bool cur_state;
  1018. reg = FDI_TX_CTL(pipe);
  1019. val = I915_READ(reg);
  1020. cur_state = !!(val & FDI_TX_ENABLE);
  1021. WARN(cur_state != state,
  1022. "FDI TX state assertion failure (expected %s, current %s)\n",
  1023. state_string(state), state_string(cur_state));
  1024. }
  1025. #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
  1026. #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
  1027. static void assert_fdi_rx(struct drm_i915_private *dev_priv,
  1028. enum pipe pipe, bool state)
  1029. {
  1030. int reg;
  1031. u32 val;
  1032. bool cur_state;
  1033. reg = FDI_RX_CTL(pipe);
  1034. val = I915_READ(reg);
  1035. cur_state = !!(val & FDI_RX_ENABLE);
  1036. WARN(cur_state != state,
  1037. "FDI RX state assertion failure (expected %s, current %s)\n",
  1038. state_string(state), state_string(cur_state));
  1039. }
  1040. #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
  1041. #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
  1042. static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv,
  1043. enum pipe pipe)
  1044. {
  1045. int reg;
  1046. u32 val;
  1047. /* ILK FDI PLL is always enabled */
  1048. if (dev_priv->info->gen == 5)
  1049. return;
  1050. reg = FDI_TX_CTL(pipe);
  1051. val = I915_READ(reg);
  1052. WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n");
  1053. }
  1054. static void assert_fdi_rx_pll_enabled(struct drm_i915_private *dev_priv,
  1055. enum pipe pipe)
  1056. {
  1057. int reg;
  1058. u32 val;
  1059. reg = FDI_RX_CTL(pipe);
  1060. val = I915_READ(reg);
  1061. WARN(!(val & FDI_RX_PLL_ENABLE), "FDI RX PLL assertion failure, should be active but is disabled\n");
  1062. }
  1063. static void assert_panel_unlocked(struct drm_i915_private *dev_priv,
  1064. enum pipe pipe)
  1065. {
  1066. int pp_reg, lvds_reg;
  1067. u32 val;
  1068. enum pipe panel_pipe = PIPE_A;
  1069. bool locked = locked;
  1070. if (HAS_PCH_SPLIT(dev_priv->dev)) {
  1071. pp_reg = PCH_PP_CONTROL;
  1072. lvds_reg = PCH_LVDS;
  1073. } else {
  1074. pp_reg = PP_CONTROL;
  1075. lvds_reg = LVDS;
  1076. }
  1077. val = I915_READ(pp_reg);
  1078. if (!(val & PANEL_POWER_ON) ||
  1079. ((val & PANEL_UNLOCK_REGS) == PANEL_UNLOCK_REGS))
  1080. locked = false;
  1081. if (I915_READ(lvds_reg) & LVDS_PIPEB_SELECT)
  1082. panel_pipe = PIPE_B;
  1083. WARN(panel_pipe == pipe && locked,
  1084. "panel assertion failure, pipe %c regs locked\n",
  1085. pipe_name(pipe));
  1086. }
  1087. static void assert_pipe(struct drm_i915_private *dev_priv,
  1088. enum pipe pipe, bool state)
  1089. {
  1090. int reg;
  1091. u32 val;
  1092. bool cur_state;
  1093. reg = PIPECONF(pipe);
  1094. val = I915_READ(reg);
  1095. cur_state = !!(val & PIPECONF_ENABLE);
  1096. WARN(cur_state != state,
  1097. "pipe %c assertion failure (expected %s, current %s)\n",
  1098. pipe_name(pipe), state_string(state), state_string(cur_state));
  1099. }
  1100. #define assert_pipe_enabled(d, p) assert_pipe(d, p, true)
  1101. #define assert_pipe_disabled(d, p) assert_pipe(d, p, false)
  1102. static void assert_plane_enabled(struct drm_i915_private *dev_priv,
  1103. enum plane plane)
  1104. {
  1105. int reg;
  1106. u32 val;
  1107. reg = DSPCNTR(plane);
  1108. val = I915_READ(reg);
  1109. WARN(!(val & DISPLAY_PLANE_ENABLE),
  1110. "plane %c assertion failure, should be active but is disabled\n",
  1111. plane_name(plane));
  1112. }
  1113. static void assert_planes_disabled(struct drm_i915_private *dev_priv,
  1114. enum pipe pipe)
  1115. {
  1116. int reg, i;
  1117. u32 val;
  1118. int cur_pipe;
  1119. /* Planes are fixed to pipes on ILK+ */
  1120. if (HAS_PCH_SPLIT(dev_priv->dev))
  1121. return;
  1122. /* Need to check both planes against the pipe */
  1123. for (i = 0; i < 2; i++) {
  1124. reg = DSPCNTR(i);
  1125. val = I915_READ(reg);
  1126. cur_pipe = (val & DISPPLANE_SEL_PIPE_MASK) >>
  1127. DISPPLANE_SEL_PIPE_SHIFT;
  1128. WARN((val & DISPLAY_PLANE_ENABLE) && pipe == cur_pipe,
  1129. "plane %c assertion failure, should be off on pipe %c but is still active\n",
  1130. plane_name(i), pipe_name(pipe));
  1131. }
  1132. }
  1133. static void assert_pch_refclk_enabled(struct drm_i915_private *dev_priv)
  1134. {
  1135. u32 val;
  1136. bool enabled;
  1137. val = I915_READ(PCH_DREF_CONTROL);
  1138. enabled = !!(val & (DREF_SSC_SOURCE_MASK | DREF_NONSPREAD_SOURCE_MASK |
  1139. DREF_SUPERSPREAD_SOURCE_MASK));
  1140. WARN(!enabled, "PCH refclk assertion failure, should be active but is disabled\n");
  1141. }
  1142. static void assert_transcoder_disabled(struct drm_i915_private *dev_priv,
  1143. enum pipe pipe)
  1144. {
  1145. int reg;
  1146. u32 val;
  1147. bool enabled;
  1148. reg = TRANSCONF(pipe);
  1149. val = I915_READ(reg);
  1150. enabled = !!(val & TRANS_ENABLE);
  1151. WARN(enabled,
  1152. "transcoder assertion failed, should be off on pipe %c but is still active\n",
  1153. pipe_name(pipe));
  1154. }
  1155. static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv,
  1156. enum pipe pipe, int reg)
  1157. {
  1158. u32 val = I915_READ(reg);
  1159. WARN(DP_PIPE_ENABLED(val, pipe),
  1160. "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n",
  1161. reg, pipe_name(pipe));
  1162. }
  1163. static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv,
  1164. enum pipe pipe, int reg)
  1165. {
  1166. u32 val = I915_READ(reg);
  1167. WARN(HDMI_PIPE_ENABLED(val, pipe),
  1168. "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n",
  1169. reg, pipe_name(pipe));
  1170. }
  1171. static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv,
  1172. enum pipe pipe)
  1173. {
  1174. int reg;
  1175. u32 val;
  1176. assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_B);
  1177. assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_C);
  1178. assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_D);
  1179. reg = PCH_ADPA;
  1180. val = I915_READ(reg);
  1181. WARN(ADPA_PIPE_ENABLED(val, pipe),
  1182. "PCH VGA enabled on transcoder %c, should be disabled\n",
  1183. pipe_name(pipe));
  1184. reg = PCH_LVDS;
  1185. val = I915_READ(reg);
  1186. WARN(LVDS_PIPE_ENABLED(val, pipe),
  1187. "PCH LVDS enabled on transcoder %c, should be disabled\n",
  1188. pipe_name(pipe));
  1189. assert_pch_hdmi_disabled(dev_priv, pipe, HDMIB);
  1190. assert_pch_hdmi_disabled(dev_priv, pipe, HDMIC);
  1191. assert_pch_hdmi_disabled(dev_priv, pipe, HDMID);
  1192. }
  1193. /**
  1194. * intel_enable_pll - enable a PLL
  1195. * @dev_priv: i915 private structure
  1196. * @pipe: pipe PLL to enable
  1197. *
  1198. * Enable @pipe's PLL so we can start pumping pixels from a plane. Check to
  1199. * make sure the PLL reg is writable first though, since the panel write
  1200. * protect mechanism may be enabled.
  1201. *
  1202. * Note! This is for pre-ILK only.
  1203. */
  1204. static void intel_enable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
  1205. {
  1206. int reg;
  1207. u32 val;
  1208. /* No really, not for ILK+ */
  1209. BUG_ON(dev_priv->info->gen >= 5);
  1210. /* PLL is protected by panel, make sure we can write it */
  1211. if (IS_MOBILE(dev_priv->dev) && !IS_I830(dev_priv->dev))
  1212. assert_panel_unlocked(dev_priv, pipe);
  1213. reg = DPLL(pipe);
  1214. val = I915_READ(reg);
  1215. val |= DPLL_VCO_ENABLE;
  1216. /* We do this three times for luck */
  1217. I915_WRITE(reg, val);
  1218. POSTING_READ(reg);
  1219. udelay(150); /* wait for warmup */
  1220. I915_WRITE(reg, val);
  1221. POSTING_READ(reg);
  1222. udelay(150); /* wait for warmup */
  1223. I915_WRITE(reg, val);
  1224. POSTING_READ(reg);
  1225. udelay(150); /* wait for warmup */
  1226. }
  1227. /**
  1228. * intel_disable_pll - disable a PLL
  1229. * @dev_priv: i915 private structure
  1230. * @pipe: pipe PLL to disable
  1231. *
  1232. * Disable the PLL for @pipe, making sure the pipe is off first.
  1233. *
  1234. * Note! This is for pre-ILK only.
  1235. */
  1236. static void intel_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
  1237. {
  1238. int reg;
  1239. u32 val;
  1240. /* Don't disable pipe A or pipe A PLLs if needed */
  1241. if (pipe == PIPE_A && (dev_priv->quirks & QUIRK_PIPEA_FORCE))
  1242. return;
  1243. /* Make sure the pipe isn't still relying on us */
  1244. assert_pipe_disabled(dev_priv, pipe);
  1245. reg = DPLL(pipe);
  1246. val = I915_READ(reg);
  1247. val &= ~DPLL_VCO_ENABLE;
  1248. I915_WRITE(reg, val);
  1249. POSTING_READ(reg);
  1250. }
  1251. /**
  1252. * intel_enable_pch_pll - enable PCH PLL
  1253. * @dev_priv: i915 private structure
  1254. * @pipe: pipe PLL to enable
  1255. *
  1256. * The PCH PLL needs to be enabled before the PCH transcoder, since it
  1257. * drives the transcoder clock.
  1258. */
  1259. static void intel_enable_pch_pll(struct drm_i915_private *dev_priv,
  1260. enum pipe pipe)
  1261. {
  1262. int reg;
  1263. u32 val;
  1264. /* PCH only available on ILK+ */
  1265. BUG_ON(dev_priv->info->gen < 5);
  1266. /* PCH refclock must be enabled first */
  1267. assert_pch_refclk_enabled(dev_priv);
  1268. reg = PCH_DPLL(pipe);
  1269. val = I915_READ(reg);
  1270. val |= DPLL_VCO_ENABLE;
  1271. I915_WRITE(reg, val);
  1272. POSTING_READ(reg);
  1273. udelay(200);
  1274. }
  1275. static void intel_disable_pch_pll(struct drm_i915_private *dev_priv,
  1276. enum pipe pipe)
  1277. {
  1278. int reg;
  1279. u32 val;
  1280. /* PCH only available on ILK+ */
  1281. BUG_ON(dev_priv->info->gen < 5);
  1282. /* Make sure transcoder isn't still depending on us */
  1283. assert_transcoder_disabled(dev_priv, pipe);
  1284. reg = PCH_DPLL(pipe);
  1285. val = I915_READ(reg);
  1286. val &= ~DPLL_VCO_ENABLE;
  1287. I915_WRITE(reg, val);
  1288. POSTING_READ(reg);
  1289. udelay(200);
  1290. }
  1291. static void intel_enable_transcoder(struct drm_i915_private *dev_priv,
  1292. enum pipe pipe)
  1293. {
  1294. int reg;
  1295. u32 val;
  1296. /* PCH only available on ILK+ */
  1297. BUG_ON(dev_priv->info->gen < 5);
  1298. /* Make sure PCH DPLL is enabled */
  1299. assert_pch_pll_enabled(dev_priv, pipe);
  1300. /* FDI must be feeding us bits for PCH ports */
  1301. assert_fdi_tx_enabled(dev_priv, pipe);
  1302. assert_fdi_rx_enabled(dev_priv, pipe);
  1303. reg = TRANSCONF(pipe);
  1304. val = I915_READ(reg);
  1305. /*
  1306. * make the BPC in transcoder be consistent with
  1307. * that in pipeconf reg.
  1308. */
  1309. val &= ~PIPE_BPC_MASK;
  1310. val |= I915_READ(PIPECONF(pipe)) & PIPE_BPC_MASK;
  1311. I915_WRITE(reg, val | TRANS_ENABLE);
  1312. if (wait_for(I915_READ(reg) & TRANS_STATE_ENABLE, 100))
  1313. DRM_ERROR("failed to enable transcoder %d\n", pipe);
  1314. }
  1315. static void intel_disable_transcoder(struct drm_i915_private *dev_priv,
  1316. enum pipe pipe)
  1317. {
  1318. int reg;
  1319. u32 val;
  1320. /* FDI relies on the transcoder */
  1321. assert_fdi_tx_disabled(dev_priv, pipe);
  1322. assert_fdi_rx_disabled(dev_priv, pipe);
  1323. /* Ports must be off as well */
  1324. assert_pch_ports_disabled(dev_priv, pipe);
  1325. reg = TRANSCONF(pipe);
  1326. val = I915_READ(reg);
  1327. val &= ~TRANS_ENABLE;
  1328. I915_WRITE(reg, val);
  1329. /* wait for PCH transcoder off, transcoder state */
  1330. if (wait_for((I915_READ(reg) & TRANS_STATE_ENABLE) == 0, 50))
  1331. DRM_ERROR("failed to disable transcoder\n");
  1332. }
  1333. /**
  1334. * intel_enable_pipe - enable a pipe, asserting requirements
  1335. * @dev_priv: i915 private structure
  1336. * @pipe: pipe to enable
  1337. * @pch_port: on ILK+, is this pipe driving a PCH port or not
  1338. *
  1339. * Enable @pipe, making sure that various hardware specific requirements
  1340. * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc.
  1341. *
  1342. * @pipe should be %PIPE_A or %PIPE_B.
  1343. *
  1344. * Will wait until the pipe is actually running (i.e. first vblank) before
  1345. * returning.
  1346. */
  1347. static void intel_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe,
  1348. bool pch_port)
  1349. {
  1350. int reg;
  1351. u32 val;
  1352. /*
  1353. * A pipe without a PLL won't actually be able to drive bits from
  1354. * a plane. On ILK+ the pipe PLLs are integrated, so we don't
  1355. * need the check.
  1356. */
  1357. if (!HAS_PCH_SPLIT(dev_priv->dev))
  1358. assert_pll_enabled(dev_priv, pipe);
  1359. else {
  1360. if (pch_port) {
  1361. /* if driving the PCH, we need FDI enabled */
  1362. assert_fdi_rx_pll_enabled(dev_priv, pipe);
  1363. assert_fdi_tx_pll_enabled(dev_priv, pipe);
  1364. }
  1365. /* FIXME: assert CPU port conditions for SNB+ */
  1366. }
  1367. reg = PIPECONF(pipe);
  1368. val = I915_READ(reg);
  1369. val |= PIPECONF_ENABLE;
  1370. I915_WRITE(reg, val);
  1371. POSTING_READ(reg);
  1372. intel_wait_for_vblank(dev_priv->dev, pipe);
  1373. }
  1374. /**
  1375. * intel_disable_pipe - disable a pipe, asserting requirements
  1376. * @dev_priv: i915 private structure
  1377. * @pipe: pipe to disable
  1378. *
  1379. * Disable @pipe, making sure that various hardware specific requirements
  1380. * are met, if applicable, e.g. plane disabled, panel fitter off, etc.
  1381. *
  1382. * @pipe should be %PIPE_A or %PIPE_B.
  1383. *
  1384. * Will wait until the pipe has shut down before returning.
  1385. */
  1386. static void intel_disable_pipe(struct drm_i915_private *dev_priv,
  1387. enum pipe pipe)
  1388. {
  1389. int reg;
  1390. u32 val;
  1391. /*
  1392. * Make sure planes won't keep trying to pump pixels to us,
  1393. * or we might hang the display.
  1394. */
  1395. assert_planes_disabled(dev_priv, pipe);
  1396. /* Don't disable pipe A or pipe A PLLs if needed */
  1397. if (pipe == PIPE_A && (dev_priv->quirks & QUIRK_PIPEA_FORCE))
  1398. return;
  1399. reg = PIPECONF(pipe);
  1400. val = I915_READ(reg);
  1401. val &= ~PIPECONF_ENABLE;
  1402. I915_WRITE(reg, val);
  1403. POSTING_READ(reg);
  1404. intel_wait_for_pipe_off(dev_priv->dev, pipe);
  1405. }
  1406. /**
  1407. * intel_enable_plane - enable a display plane on a given pipe
  1408. * @dev_priv: i915 private structure
  1409. * @plane: plane to enable
  1410. * @pipe: pipe being fed
  1411. *
  1412. * Enable @plane on @pipe, making sure that @pipe is running first.
  1413. */
  1414. static void intel_enable_plane(struct drm_i915_private *dev_priv,
  1415. enum plane plane, enum pipe pipe)
  1416. {
  1417. int reg;
  1418. u32 val;
  1419. /* If the pipe isn't enabled, we can't pump pixels and may hang */
  1420. assert_pipe_enabled(dev_priv, pipe);
  1421. reg = DSPCNTR(plane);
  1422. val = I915_READ(reg);
  1423. val |= DISPLAY_PLANE_ENABLE;
  1424. I915_WRITE(reg, val);
  1425. POSTING_READ(reg);
  1426. intel_wait_for_vblank(dev_priv->dev, pipe);
  1427. }
  1428. /*
  1429. * Plane regs are double buffered, going from enabled->disabled needs a
  1430. * trigger in order to latch. The display address reg provides this.
  1431. */
  1432. static void intel_flush_display_plane(struct drm_i915_private *dev_priv,
  1433. enum plane plane)
  1434. {
  1435. u32 reg = DSPADDR(plane);
  1436. I915_WRITE(reg, I915_READ(reg));
  1437. }
  1438. /**
  1439. * intel_disable_plane - disable a display plane
  1440. * @dev_priv: i915 private structure
  1441. * @plane: plane to disable
  1442. * @pipe: pipe consuming the data
  1443. *
  1444. * Disable @plane; should be an independent operation.
  1445. */
  1446. static void intel_disable_plane(struct drm_i915_private *dev_priv,
  1447. enum plane plane, enum pipe pipe)
  1448. {
  1449. int reg;
  1450. u32 val;
  1451. reg = DSPCNTR(plane);
  1452. val = I915_READ(reg);
  1453. val &= ~DISPLAY_PLANE_ENABLE;
  1454. I915_WRITE(reg, val);
  1455. POSTING_READ(reg);
  1456. intel_flush_display_plane(dev_priv, plane);
  1457. intel_wait_for_vblank(dev_priv->dev, pipe);
  1458. }
  1459. static void disable_pch_dp(struct drm_i915_private *dev_priv,
  1460. enum pipe pipe, int reg)
  1461. {
  1462. u32 val = I915_READ(reg);
  1463. if (DP_PIPE_ENABLED(val, pipe))
  1464. I915_WRITE(reg, val & ~DP_PORT_EN);
  1465. }
  1466. static void disable_pch_hdmi(struct drm_i915_private *dev_priv,
  1467. enum pipe pipe, int reg)
  1468. {
  1469. u32 val = I915_READ(reg);
  1470. if (HDMI_PIPE_ENABLED(val, pipe))
  1471. I915_WRITE(reg, val & ~PORT_ENABLE);
  1472. }
  1473. /* Disable any ports connected to this transcoder */
  1474. static void intel_disable_pch_ports(struct drm_i915_private *dev_priv,
  1475. enum pipe pipe)
  1476. {
  1477. u32 reg, val;
  1478. val = I915_READ(PCH_PP_CONTROL);
  1479. I915_WRITE(PCH_PP_CONTROL, val | PANEL_UNLOCK_REGS);
  1480. disable_pch_dp(dev_priv, pipe, PCH_DP_B);
  1481. disable_pch_dp(dev_priv, pipe, PCH_DP_C);
  1482. disable_pch_dp(dev_priv, pipe, PCH_DP_D);
  1483. reg = PCH_ADPA;
  1484. val = I915_READ(reg);
  1485. if (ADPA_PIPE_ENABLED(val, pipe))
  1486. I915_WRITE(reg, val & ~ADPA_DAC_ENABLE);
  1487. reg = PCH_LVDS;
  1488. val = I915_READ(reg);
  1489. if (LVDS_PIPE_ENABLED(val, pipe)) {
  1490. I915_WRITE(reg, val & ~LVDS_PORT_EN);
  1491. POSTING_READ(reg);
  1492. udelay(100);
  1493. }
  1494. disable_pch_hdmi(dev_priv, pipe, HDMIB);
  1495. disable_pch_hdmi(dev_priv, pipe, HDMIC);
  1496. disable_pch_hdmi(dev_priv, pipe, HDMID);
  1497. }
  1498. static void i8xx_enable_fbc(struct drm_crtc *crtc, unsigned long interval)
  1499. {
  1500. struct drm_device *dev = crtc->dev;
  1501. struct drm_i915_private *dev_priv = dev->dev_private;
  1502. struct drm_framebuffer *fb = crtc->fb;
  1503. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  1504. struct drm_i915_gem_object *obj = intel_fb->obj;
  1505. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1506. int plane, i;
  1507. u32 fbc_ctl, fbc_ctl2;
  1508. if (fb->pitch == dev_priv->cfb_pitch &&
  1509. obj->fence_reg == dev_priv->cfb_fence &&
  1510. intel_crtc->plane == dev_priv->cfb_plane &&
  1511. I915_READ(FBC_CONTROL) & FBC_CTL_EN)
  1512. return;
  1513. i8xx_disable_fbc(dev);
  1514. dev_priv->cfb_pitch = dev_priv->cfb_size / FBC_LL_SIZE;
  1515. if (fb->pitch < dev_priv->cfb_pitch)
  1516. dev_priv->cfb_pitch = fb->pitch;
  1517. /* FBC_CTL wants 64B units */
  1518. dev_priv->cfb_pitch = (dev_priv->cfb_pitch / 64) - 1;
  1519. dev_priv->cfb_fence = obj->fence_reg;
  1520. dev_priv->cfb_plane = intel_crtc->plane;
  1521. plane = dev_priv->cfb_plane == 0 ? FBC_CTL_PLANEA : FBC_CTL_PLANEB;
  1522. /* Clear old tags */
  1523. for (i = 0; i < (FBC_LL_SIZE / 32) + 1; i++)
  1524. I915_WRITE(FBC_TAG + (i * 4), 0);
  1525. /* Set it up... */
  1526. fbc_ctl2 = FBC_CTL_FENCE_DBL | FBC_CTL_IDLE_IMM | plane;
  1527. if (obj->tiling_mode != I915_TILING_NONE)
  1528. fbc_ctl2 |= FBC_CTL_CPU_FENCE;
  1529. I915_WRITE(FBC_CONTROL2, fbc_ctl2);
  1530. I915_WRITE(FBC_FENCE_OFF, crtc->y);
  1531. /* enable it... */
  1532. fbc_ctl = FBC_CTL_EN | FBC_CTL_PERIODIC;
  1533. if (IS_I945GM(dev))
  1534. fbc_ctl |= FBC_CTL_C3_IDLE; /* 945 needs special SR handling */
  1535. fbc_ctl |= (dev_priv->cfb_pitch & 0xff) << FBC_CTL_STRIDE_SHIFT;
  1536. fbc_ctl |= (interval & 0x2fff) << FBC_CTL_INTERVAL_SHIFT;
  1537. if (obj->tiling_mode != I915_TILING_NONE)
  1538. fbc_ctl |= dev_priv->cfb_fence;
  1539. I915_WRITE(FBC_CONTROL, fbc_ctl);
  1540. DRM_DEBUG_KMS("enabled FBC, pitch %ld, yoff %d, plane %d, ",
  1541. dev_priv->cfb_pitch, crtc->y, dev_priv->cfb_plane);
  1542. }
  1543. void i8xx_disable_fbc(struct drm_device *dev)
  1544. {
  1545. struct drm_i915_private *dev_priv = dev->dev_private;
  1546. u32 fbc_ctl;
  1547. /* Disable compression */
  1548. fbc_ctl = I915_READ(FBC_CONTROL);
  1549. if ((fbc_ctl & FBC_CTL_EN) == 0)
  1550. return;
  1551. fbc_ctl &= ~FBC_CTL_EN;
  1552. I915_WRITE(FBC_CONTROL, fbc_ctl);
  1553. /* Wait for compressing bit to clear */
  1554. if (wait_for((I915_READ(FBC_STATUS) & FBC_STAT_COMPRESSING) == 0, 10)) {
  1555. DRM_DEBUG_KMS("FBC idle timed out\n");
  1556. return;
  1557. }
  1558. DRM_DEBUG_KMS("disabled FBC\n");
  1559. }
  1560. static bool i8xx_fbc_enabled(struct drm_device *dev)
  1561. {
  1562. struct drm_i915_private *dev_priv = dev->dev_private;
  1563. return I915_READ(FBC_CONTROL) & FBC_CTL_EN;
  1564. }
  1565. static void g4x_enable_fbc(struct drm_crtc *crtc, unsigned long interval)
  1566. {
  1567. struct drm_device *dev = crtc->dev;
  1568. struct drm_i915_private *dev_priv = dev->dev_private;
  1569. struct drm_framebuffer *fb = crtc->fb;
  1570. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  1571. struct drm_i915_gem_object *obj = intel_fb->obj;
  1572. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1573. int plane = intel_crtc->plane == 0 ? DPFC_CTL_PLANEA : DPFC_CTL_PLANEB;
  1574. unsigned long stall_watermark = 200;
  1575. u32 dpfc_ctl;
  1576. dpfc_ctl = I915_READ(DPFC_CONTROL);
  1577. if (dpfc_ctl & DPFC_CTL_EN) {
  1578. if (dev_priv->cfb_pitch == dev_priv->cfb_pitch / 64 - 1 &&
  1579. dev_priv->cfb_fence == obj->fence_reg &&
  1580. dev_priv->cfb_plane == intel_crtc->plane &&
  1581. dev_priv->cfb_y == crtc->y)
  1582. return;
  1583. I915_WRITE(DPFC_CONTROL, dpfc_ctl & ~DPFC_CTL_EN);
  1584. POSTING_READ(DPFC_CONTROL);
  1585. intel_wait_for_vblank(dev, intel_crtc->pipe);
  1586. }
  1587. dev_priv->cfb_pitch = (dev_priv->cfb_pitch / 64) - 1;
  1588. dev_priv->cfb_fence = obj->fence_reg;
  1589. dev_priv->cfb_plane = intel_crtc->plane;
  1590. dev_priv->cfb_y = crtc->y;
  1591. dpfc_ctl = plane | DPFC_SR_EN | DPFC_CTL_LIMIT_1X;
  1592. if (obj->tiling_mode != I915_TILING_NONE) {
  1593. dpfc_ctl |= DPFC_CTL_FENCE_EN | dev_priv->cfb_fence;
  1594. I915_WRITE(DPFC_CHICKEN, DPFC_HT_MODIFY);
  1595. } else {
  1596. I915_WRITE(DPFC_CHICKEN, ~DPFC_HT_MODIFY);
  1597. }
  1598. I915_WRITE(DPFC_RECOMP_CTL, DPFC_RECOMP_STALL_EN |
  1599. (stall_watermark << DPFC_RECOMP_STALL_WM_SHIFT) |
  1600. (interval << DPFC_RECOMP_TIMER_COUNT_SHIFT));
  1601. I915_WRITE(DPFC_FENCE_YOFF, crtc->y);
  1602. /* enable it... */
  1603. I915_WRITE(DPFC_CONTROL, I915_READ(DPFC_CONTROL) | DPFC_CTL_EN);
  1604. DRM_DEBUG_KMS("enabled fbc on plane %d\n", intel_crtc->plane);
  1605. }
  1606. void g4x_disable_fbc(struct drm_device *dev)
  1607. {
  1608. struct drm_i915_private *dev_priv = dev->dev_private;
  1609. u32 dpfc_ctl;
  1610. /* Disable compression */
  1611. dpfc_ctl = I915_READ(DPFC_CONTROL);
  1612. if (dpfc_ctl & DPFC_CTL_EN) {
  1613. dpfc_ctl &= ~DPFC_CTL_EN;
  1614. I915_WRITE(DPFC_CONTROL, dpfc_ctl);
  1615. DRM_DEBUG_KMS("disabled FBC\n");
  1616. }
  1617. }
  1618. static bool g4x_fbc_enabled(struct drm_device *dev)
  1619. {
  1620. struct drm_i915_private *dev_priv = dev->dev_private;
  1621. return I915_READ(DPFC_CONTROL) & DPFC_CTL_EN;
  1622. }
  1623. static void sandybridge_blit_fbc_update(struct drm_device *dev)
  1624. {
  1625. struct drm_i915_private *dev_priv = dev->dev_private;
  1626. u32 blt_ecoskpd;
  1627. /* Make sure blitter notifies FBC of writes */
  1628. __gen6_force_wake_get(dev_priv);
  1629. blt_ecoskpd = I915_READ(GEN6_BLITTER_ECOSKPD);
  1630. blt_ecoskpd |= GEN6_BLITTER_FBC_NOTIFY <<
  1631. GEN6_BLITTER_LOCK_SHIFT;
  1632. I915_WRITE(GEN6_BLITTER_ECOSKPD, blt_ecoskpd);
  1633. blt_ecoskpd |= GEN6_BLITTER_FBC_NOTIFY;
  1634. I915_WRITE(GEN6_BLITTER_ECOSKPD, blt_ecoskpd);
  1635. blt_ecoskpd &= ~(GEN6_BLITTER_FBC_NOTIFY <<
  1636. GEN6_BLITTER_LOCK_SHIFT);
  1637. I915_WRITE(GEN6_BLITTER_ECOSKPD, blt_ecoskpd);
  1638. POSTING_READ(GEN6_BLITTER_ECOSKPD);
  1639. __gen6_force_wake_put(dev_priv);
  1640. }
  1641. static void ironlake_enable_fbc(struct drm_crtc *crtc, unsigned long interval)
  1642. {
  1643. struct drm_device *dev = crtc->dev;
  1644. struct drm_i915_private *dev_priv = dev->dev_private;
  1645. struct drm_framebuffer *fb = crtc->fb;
  1646. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  1647. struct drm_i915_gem_object *obj = intel_fb->obj;
  1648. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1649. int plane = intel_crtc->plane == 0 ? DPFC_CTL_PLANEA : DPFC_CTL_PLANEB;
  1650. unsigned long stall_watermark = 200;
  1651. u32 dpfc_ctl;
  1652. dpfc_ctl = I915_READ(ILK_DPFC_CONTROL);
  1653. if (dpfc_ctl & DPFC_CTL_EN) {
  1654. if (dev_priv->cfb_pitch == dev_priv->cfb_pitch / 64 - 1 &&
  1655. dev_priv->cfb_fence == obj->fence_reg &&
  1656. dev_priv->cfb_plane == intel_crtc->plane &&
  1657. dev_priv->cfb_offset == obj->gtt_offset &&
  1658. dev_priv->cfb_y == crtc->y)
  1659. return;
  1660. I915_WRITE(ILK_DPFC_CONTROL, dpfc_ctl & ~DPFC_CTL_EN);
  1661. POSTING_READ(ILK_DPFC_CONTROL);
  1662. intel_wait_for_vblank(dev, intel_crtc->pipe);
  1663. }
  1664. dev_priv->cfb_pitch = (dev_priv->cfb_pitch / 64) - 1;
  1665. dev_priv->cfb_fence = obj->fence_reg;
  1666. dev_priv->cfb_plane = intel_crtc->plane;
  1667. dev_priv->cfb_offset = obj->gtt_offset;
  1668. dev_priv->cfb_y = crtc->y;
  1669. dpfc_ctl &= DPFC_RESERVED;
  1670. dpfc_ctl |= (plane | DPFC_CTL_LIMIT_1X);
  1671. if (obj->tiling_mode != I915_TILING_NONE) {
  1672. dpfc_ctl |= (DPFC_CTL_FENCE_EN | dev_priv->cfb_fence);
  1673. I915_WRITE(ILK_DPFC_CHICKEN, DPFC_HT_MODIFY);
  1674. } else {
  1675. I915_WRITE(ILK_DPFC_CHICKEN, ~DPFC_HT_MODIFY);
  1676. }
  1677. I915_WRITE(ILK_DPFC_RECOMP_CTL, DPFC_RECOMP_STALL_EN |
  1678. (stall_watermark << DPFC_RECOMP_STALL_WM_SHIFT) |
  1679. (interval << DPFC_RECOMP_TIMER_COUNT_SHIFT));
  1680. I915_WRITE(ILK_DPFC_FENCE_YOFF, crtc->y);
  1681. I915_WRITE(ILK_FBC_RT_BASE, obj->gtt_offset | ILK_FBC_RT_VALID);
  1682. /* enable it... */
  1683. I915_WRITE(ILK_DPFC_CONTROL, dpfc_ctl | DPFC_CTL_EN);
  1684. if (IS_GEN6(dev)) {
  1685. I915_WRITE(SNB_DPFC_CTL_SA,
  1686. SNB_CPU_FENCE_ENABLE | dev_priv->cfb_fence);
  1687. I915_WRITE(DPFC_CPU_FENCE_OFFSET, crtc->y);
  1688. sandybridge_blit_fbc_update(dev);
  1689. }
  1690. DRM_DEBUG_KMS("enabled fbc on plane %d\n", intel_crtc->plane);
  1691. }
  1692. void ironlake_disable_fbc(struct drm_device *dev)
  1693. {
  1694. struct drm_i915_private *dev_priv = dev->dev_private;
  1695. u32 dpfc_ctl;
  1696. /* Disable compression */
  1697. dpfc_ctl = I915_READ(ILK_DPFC_CONTROL);
  1698. if (dpfc_ctl & DPFC_CTL_EN) {
  1699. dpfc_ctl &= ~DPFC_CTL_EN;
  1700. I915_WRITE(ILK_DPFC_CONTROL, dpfc_ctl);
  1701. DRM_DEBUG_KMS("disabled FBC\n");
  1702. }
  1703. }
  1704. static bool ironlake_fbc_enabled(struct drm_device *dev)
  1705. {
  1706. struct drm_i915_private *dev_priv = dev->dev_private;
  1707. return I915_READ(ILK_DPFC_CONTROL) & DPFC_CTL_EN;
  1708. }
  1709. bool intel_fbc_enabled(struct drm_device *dev)
  1710. {
  1711. struct drm_i915_private *dev_priv = dev->dev_private;
  1712. if (!dev_priv->display.fbc_enabled)
  1713. return false;
  1714. return dev_priv->display.fbc_enabled(dev);
  1715. }
  1716. void intel_enable_fbc(struct drm_crtc *crtc, unsigned long interval)
  1717. {
  1718. struct drm_i915_private *dev_priv = crtc->dev->dev_private;
  1719. if (!dev_priv->display.enable_fbc)
  1720. return;
  1721. dev_priv->display.enable_fbc(crtc, interval);
  1722. }
  1723. void intel_disable_fbc(struct drm_device *dev)
  1724. {
  1725. struct drm_i915_private *dev_priv = dev->dev_private;
  1726. if (!dev_priv->display.disable_fbc)
  1727. return;
  1728. dev_priv->display.disable_fbc(dev);
  1729. }
  1730. /**
  1731. * intel_update_fbc - enable/disable FBC as needed
  1732. * @dev: the drm_device
  1733. *
  1734. * Set up the framebuffer compression hardware at mode set time. We
  1735. * enable it if possible:
  1736. * - plane A only (on pre-965)
  1737. * - no pixel mulitply/line duplication
  1738. * - no alpha buffer discard
  1739. * - no dual wide
  1740. * - framebuffer <= 2048 in width, 1536 in height
  1741. *
  1742. * We can't assume that any compression will take place (worst case),
  1743. * so the compressed buffer has to be the same size as the uncompressed
  1744. * one. It also must reside (along with the line length buffer) in
  1745. * stolen memory.
  1746. *
  1747. * We need to enable/disable FBC on a global basis.
  1748. */
  1749. static void intel_update_fbc(struct drm_device *dev)
  1750. {
  1751. struct drm_i915_private *dev_priv = dev->dev_private;
  1752. struct drm_crtc *crtc = NULL, *tmp_crtc;
  1753. struct intel_crtc *intel_crtc;
  1754. struct drm_framebuffer *fb;
  1755. struct intel_framebuffer *intel_fb;
  1756. struct drm_i915_gem_object *obj;
  1757. DRM_DEBUG_KMS("\n");
  1758. if (!i915_powersave)
  1759. return;
  1760. if (!I915_HAS_FBC(dev))
  1761. return;
  1762. /*
  1763. * If FBC is already on, we just have to verify that we can
  1764. * keep it that way...
  1765. * Need to disable if:
  1766. * - more than one pipe is active
  1767. * - changing FBC params (stride, fence, mode)
  1768. * - new fb is too large to fit in compressed buffer
  1769. * - going to an unsupported config (interlace, pixel multiply, etc.)
  1770. */
  1771. list_for_each_entry(tmp_crtc, &dev->mode_config.crtc_list, head) {
  1772. if (tmp_crtc->enabled && tmp_crtc->fb) {
  1773. if (crtc) {
  1774. DRM_DEBUG_KMS("more than one pipe active, disabling compression\n");
  1775. dev_priv->no_fbc_reason = FBC_MULTIPLE_PIPES;
  1776. goto out_disable;
  1777. }
  1778. crtc = tmp_crtc;
  1779. }
  1780. }
  1781. if (!crtc || crtc->fb == NULL) {
  1782. DRM_DEBUG_KMS("no output, disabling\n");
  1783. dev_priv->no_fbc_reason = FBC_NO_OUTPUT;
  1784. goto out_disable;
  1785. }
  1786. intel_crtc = to_intel_crtc(crtc);
  1787. fb = crtc->fb;
  1788. intel_fb = to_intel_framebuffer(fb);
  1789. obj = intel_fb->obj;
  1790. if (intel_fb->obj->base.size > dev_priv->cfb_size) {
  1791. DRM_DEBUG_KMS("framebuffer too large, disabling "
  1792. "compression\n");
  1793. dev_priv->no_fbc_reason = FBC_STOLEN_TOO_SMALL;
  1794. goto out_disable;
  1795. }
  1796. if ((crtc->mode.flags & DRM_MODE_FLAG_INTERLACE) ||
  1797. (crtc->mode.flags & DRM_MODE_FLAG_DBLSCAN)) {
  1798. DRM_DEBUG_KMS("mode incompatible with compression, "
  1799. "disabling\n");
  1800. dev_priv->no_fbc_reason = FBC_UNSUPPORTED_MODE;
  1801. goto out_disable;
  1802. }
  1803. if ((crtc->mode.hdisplay > 2048) ||
  1804. (crtc->mode.vdisplay > 1536)) {
  1805. DRM_DEBUG_KMS("mode too large for compression, disabling\n");
  1806. dev_priv->no_fbc_reason = FBC_MODE_TOO_LARGE;
  1807. goto out_disable;
  1808. }
  1809. if ((IS_I915GM(dev) || IS_I945GM(dev)) && intel_crtc->plane != 0) {
  1810. DRM_DEBUG_KMS("plane not 0, disabling compression\n");
  1811. dev_priv->no_fbc_reason = FBC_BAD_PLANE;
  1812. goto out_disable;
  1813. }
  1814. if (obj->tiling_mode != I915_TILING_X) {
  1815. DRM_DEBUG_KMS("framebuffer not tiled, disabling compression\n");
  1816. dev_priv->no_fbc_reason = FBC_NOT_TILED;
  1817. goto out_disable;
  1818. }
  1819. /* If the kernel debugger is active, always disable compression */
  1820. if (in_dbg_master())
  1821. goto out_disable;
  1822. intel_enable_fbc(crtc, 500);
  1823. return;
  1824. out_disable:
  1825. /* Multiple disables should be harmless */
  1826. if (intel_fbc_enabled(dev)) {
  1827. DRM_DEBUG_KMS("unsupported config, disabling FBC\n");
  1828. intel_disable_fbc(dev);
  1829. }
  1830. }
  1831. int
  1832. intel_pin_and_fence_fb_obj(struct drm_device *dev,
  1833. struct drm_i915_gem_object *obj,
  1834. struct intel_ring_buffer *pipelined)
  1835. {
  1836. u32 alignment;
  1837. int ret;
  1838. switch (obj->tiling_mode) {
  1839. case I915_TILING_NONE:
  1840. if (IS_BROADWATER(dev) || IS_CRESTLINE(dev))
  1841. alignment = 128 * 1024;
  1842. else if (INTEL_INFO(dev)->gen >= 4)
  1843. alignment = 4 * 1024;
  1844. else
  1845. alignment = 64 * 1024;
  1846. break;
  1847. case I915_TILING_X:
  1848. /* pin() will align the object as required by fence */
  1849. alignment = 0;
  1850. break;
  1851. case I915_TILING_Y:
  1852. /* FIXME: Is this true? */
  1853. DRM_ERROR("Y tiled not allowed for scan out buffers\n");
  1854. return -EINVAL;
  1855. default:
  1856. BUG();
  1857. }
  1858. ret = i915_gem_object_pin(obj, alignment, true);
  1859. if (ret)
  1860. return ret;
  1861. ret = i915_gem_object_set_to_display_plane(obj, pipelined);
  1862. if (ret)
  1863. goto err_unpin;
  1864. /* Install a fence for tiled scan-out. Pre-i965 always needs a
  1865. * fence, whereas 965+ only requires a fence if using
  1866. * framebuffer compression. For simplicity, we always install
  1867. * a fence as the cost is not that onerous.
  1868. */
  1869. if (obj->tiling_mode != I915_TILING_NONE) {
  1870. ret = i915_gem_object_get_fence(obj, pipelined, false);
  1871. if (ret)
  1872. goto err_unpin;
  1873. }
  1874. return 0;
  1875. err_unpin:
  1876. i915_gem_object_unpin(obj);
  1877. return ret;
  1878. }
  1879. /* Assume fb object is pinned & idle & fenced and just update base pointers */
  1880. static int
  1881. intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb,
  1882. int x, int y, enum mode_set_atomic state)
  1883. {
  1884. struct drm_device *dev = crtc->dev;
  1885. struct drm_i915_private *dev_priv = dev->dev_private;
  1886. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1887. struct intel_framebuffer *intel_fb;
  1888. struct drm_i915_gem_object *obj;
  1889. int plane = intel_crtc->plane;
  1890. unsigned long Start, Offset;
  1891. u32 dspcntr;
  1892. u32 reg;
  1893. switch (plane) {
  1894. case 0:
  1895. case 1:
  1896. break;
  1897. default:
  1898. DRM_ERROR("Can't update plane %d in SAREA\n", plane);
  1899. return -EINVAL;
  1900. }
  1901. intel_fb = to_intel_framebuffer(fb);
  1902. obj = intel_fb->obj;
  1903. reg = DSPCNTR(plane);
  1904. dspcntr = I915_READ(reg);
  1905. /* Mask out pixel format bits in case we change it */
  1906. dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;
  1907. switch (fb->bits_per_pixel) {
  1908. case 8:
  1909. dspcntr |= DISPPLANE_8BPP;
  1910. break;
  1911. case 16:
  1912. if (fb->depth == 15)
  1913. dspcntr |= DISPPLANE_15_16BPP;
  1914. else
  1915. dspcntr |= DISPPLANE_16BPP;
  1916. break;
  1917. case 24:
  1918. case 32:
  1919. dspcntr |= DISPPLANE_32BPP_NO_ALPHA;
  1920. break;
  1921. default:
  1922. DRM_ERROR("Unknown color depth\n");
  1923. return -EINVAL;
  1924. }
  1925. if (INTEL_INFO(dev)->gen >= 4) {
  1926. if (obj->tiling_mode != I915_TILING_NONE)
  1927. dspcntr |= DISPPLANE_TILED;
  1928. else
  1929. dspcntr &= ~DISPPLANE_TILED;
  1930. }
  1931. if (HAS_PCH_SPLIT(dev))
  1932. /* must disable */
  1933. dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
  1934. I915_WRITE(reg, dspcntr);
  1935. Start = obj->gtt_offset;
  1936. Offset = y * fb->pitch + x * (fb->bits_per_pixel / 8);
  1937. DRM_DEBUG_KMS("Writing base %08lX %08lX %d %d %d\n",
  1938. Start, Offset, x, y, fb->pitch);
  1939. I915_WRITE(DSPSTRIDE(plane), fb->pitch);
  1940. if (INTEL_INFO(dev)->gen >= 4) {
  1941. I915_WRITE(DSPSURF(plane), Start);
  1942. I915_WRITE(DSPTILEOFF(plane), (y << 16) | x);
  1943. I915_WRITE(DSPADDR(plane), Offset);
  1944. } else
  1945. I915_WRITE(DSPADDR(plane), Start + Offset);
  1946. POSTING_READ(reg);
  1947. intel_update_fbc(dev);
  1948. intel_increase_pllclock(crtc);
  1949. return 0;
  1950. }
  1951. static int
  1952. intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
  1953. struct drm_framebuffer *old_fb)
  1954. {
  1955. struct drm_device *dev = crtc->dev;
  1956. struct drm_i915_master_private *master_priv;
  1957. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1958. int ret;
  1959. /* no fb bound */
  1960. if (!crtc->fb) {
  1961. DRM_DEBUG_KMS("No FB bound\n");
  1962. return 0;
  1963. }
  1964. switch (intel_crtc->plane) {
  1965. case 0:
  1966. case 1:
  1967. break;
  1968. default:
  1969. return -EINVAL;
  1970. }
  1971. mutex_lock(&dev->struct_mutex);
  1972. ret = intel_pin_and_fence_fb_obj(dev,
  1973. to_intel_framebuffer(crtc->fb)->obj,
  1974. NULL);
  1975. if (ret != 0) {
  1976. mutex_unlock(&dev->struct_mutex);
  1977. return ret;
  1978. }
  1979. if (old_fb) {
  1980. struct drm_i915_private *dev_priv = dev->dev_private;
  1981. struct drm_i915_gem_object *obj = to_intel_framebuffer(old_fb)->obj;
  1982. wait_event(dev_priv->pending_flip_queue,
  1983. atomic_read(&dev_priv->mm.wedged) ||
  1984. atomic_read(&obj->pending_flip) == 0);
  1985. /* Big Hammer, we also need to ensure that any pending
  1986. * MI_WAIT_FOR_EVENT inside a user batch buffer on the
  1987. * current scanout is retired before unpinning the old
  1988. * framebuffer.
  1989. *
  1990. * This should only fail upon a hung GPU, in which case we
  1991. * can safely continue.
  1992. */
  1993. ret = i915_gem_object_flush_gpu(obj, false);
  1994. (void) ret;
  1995. }
  1996. ret = intel_pipe_set_base_atomic(crtc, crtc->fb, x, y,
  1997. LEAVE_ATOMIC_MODE_SET);
  1998. if (ret) {
  1999. i915_gem_object_unpin(to_intel_framebuffer(crtc->fb)->obj);
  2000. mutex_unlock(&dev->struct_mutex);
  2001. return ret;
  2002. }
  2003. if (old_fb) {
  2004. intel_wait_for_vblank(dev, intel_crtc->pipe);
  2005. i915_gem_object_unpin(to_intel_framebuffer(old_fb)->obj);
  2006. }
  2007. mutex_unlock(&dev->struct_mutex);
  2008. if (!dev->primary->master)
  2009. return 0;
  2010. master_priv = dev->primary->master->driver_priv;
  2011. if (!master_priv->sarea_priv)
  2012. return 0;
  2013. if (intel_crtc->pipe) {
  2014. master_priv->sarea_priv->pipeB_x = x;
  2015. master_priv->sarea_priv->pipeB_y = y;
  2016. } else {
  2017. master_priv->sarea_priv->pipeA_x = x;
  2018. master_priv->sarea_priv->pipeA_y = y;
  2019. }
  2020. return 0;
  2021. }
  2022. static void ironlake_set_pll_edp(struct drm_crtc *crtc, int clock)
  2023. {
  2024. struct drm_device *dev = crtc->dev;
  2025. struct drm_i915_private *dev_priv = dev->dev_private;
  2026. u32 dpa_ctl;
  2027. DRM_DEBUG_KMS("eDP PLL enable for clock %d\n", clock);
  2028. dpa_ctl = I915_READ(DP_A);
  2029. dpa_ctl &= ~DP_PLL_FREQ_MASK;
  2030. if (clock < 200000) {
  2031. u32 temp;
  2032. dpa_ctl |= DP_PLL_FREQ_160MHZ;
  2033. /* workaround for 160Mhz:
  2034. 1) program 0x4600c bits 15:0 = 0x8124
  2035. 2) program 0x46010 bit 0 = 1
  2036. 3) program 0x46034 bit 24 = 1
  2037. 4) program 0x64000 bit 14 = 1
  2038. */
  2039. temp = I915_READ(0x4600c);
  2040. temp &= 0xffff0000;
  2041. I915_WRITE(0x4600c, temp | 0x8124);
  2042. temp = I915_READ(0x46010);
  2043. I915_WRITE(0x46010, temp | 1);
  2044. temp = I915_READ(0x46034);
  2045. I915_WRITE(0x46034, temp | (1 << 24));
  2046. } else {
  2047. dpa_ctl |= DP_PLL_FREQ_270MHZ;
  2048. }
  2049. I915_WRITE(DP_A, dpa_ctl);
  2050. POSTING_READ(DP_A);
  2051. udelay(500);
  2052. }
  2053. static void intel_fdi_normal_train(struct drm_crtc *crtc)
  2054. {
  2055. struct drm_device *dev = crtc->dev;
  2056. struct drm_i915_private *dev_priv = dev->dev_private;
  2057. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2058. int pipe = intel_crtc->pipe;
  2059. u32 reg, temp;
  2060. /* enable normal train */
  2061. reg = FDI_TX_CTL(pipe);
  2062. temp = I915_READ(reg);
  2063. temp &= ~FDI_LINK_TRAIN_NONE;
  2064. temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
  2065. I915_WRITE(reg, temp);
  2066. reg = FDI_RX_CTL(pipe);
  2067. temp = I915_READ(reg);
  2068. if (HAS_PCH_CPT(dev)) {
  2069. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2070. temp |= FDI_LINK_TRAIN_NORMAL_CPT;
  2071. } else {
  2072. temp &= ~FDI_LINK_TRAIN_NONE;
  2073. temp |= FDI_LINK_TRAIN_NONE;
  2074. }
  2075. I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
  2076. /* wait one idle pattern time */
  2077. POSTING_READ(reg);
  2078. udelay(1000);
  2079. }
  2080. /* The FDI link training functions for ILK/Ibexpeak. */
  2081. static void ironlake_fdi_link_train(struct drm_crtc *crtc)
  2082. {
  2083. struct drm_device *dev = crtc->dev;
  2084. struct drm_i915_private *dev_priv = dev->dev_private;
  2085. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2086. int pipe = intel_crtc->pipe;
  2087. int plane = intel_crtc->plane;
  2088. u32 reg, temp, tries;
  2089. /* FDI needs bits from pipe & plane first */
  2090. assert_pipe_enabled(dev_priv, pipe);
  2091. assert_plane_enabled(dev_priv, plane);
  2092. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  2093. for train result */
  2094. reg = FDI_RX_IMR(pipe);
  2095. temp = I915_READ(reg);
  2096. temp &= ~FDI_RX_SYMBOL_LOCK;
  2097. temp &= ~FDI_RX_BIT_LOCK;
  2098. I915_WRITE(reg, temp);
  2099. I915_READ(reg);
  2100. udelay(150);
  2101. /* enable CPU FDI TX and PCH FDI RX */
  2102. reg = FDI_TX_CTL(pipe);
  2103. temp = I915_READ(reg);
  2104. temp &= ~(7 << 19);
  2105. temp |= (intel_crtc->fdi_lanes - 1) << 19;
  2106. temp &= ~FDI_LINK_TRAIN_NONE;
  2107. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2108. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  2109. reg = FDI_RX_CTL(pipe);
  2110. temp = I915_READ(reg);
  2111. temp &= ~FDI_LINK_TRAIN_NONE;
  2112. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2113. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  2114. POSTING_READ(reg);
  2115. udelay(150);
  2116. /* Ironlake workaround, enable clock pointer after FDI enable*/
  2117. if (HAS_PCH_IBX(dev)) {
  2118. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
  2119. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR |
  2120. FDI_RX_PHASE_SYNC_POINTER_EN);
  2121. }
  2122. reg = FDI_RX_IIR(pipe);
  2123. for (tries = 0; tries < 5; tries++) {
  2124. temp = I915_READ(reg);
  2125. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2126. if ((temp & FDI_RX_BIT_LOCK)) {
  2127. DRM_DEBUG_KMS("FDI train 1 done.\n");
  2128. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  2129. break;
  2130. }
  2131. }
  2132. if (tries == 5)
  2133. DRM_ERROR("FDI train 1 fail!\n");
  2134. /* Train 2 */
  2135. reg = FDI_TX_CTL(pipe);
  2136. temp = I915_READ(reg);
  2137. temp &= ~FDI_LINK_TRAIN_NONE;
  2138. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2139. I915_WRITE(reg, temp);
  2140. reg = FDI_RX_CTL(pipe);
  2141. temp = I915_READ(reg);
  2142. temp &= ~FDI_LINK_TRAIN_NONE;
  2143. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2144. I915_WRITE(reg, temp);
  2145. POSTING_READ(reg);
  2146. udelay(150);
  2147. reg = FDI_RX_IIR(pipe);
  2148. for (tries = 0; tries < 5; tries++) {
  2149. temp = I915_READ(reg);
  2150. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2151. if (temp & FDI_RX_SYMBOL_LOCK) {
  2152. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  2153. DRM_DEBUG_KMS("FDI train 2 done.\n");
  2154. break;
  2155. }
  2156. }
  2157. if (tries == 5)
  2158. DRM_ERROR("FDI train 2 fail!\n");
  2159. DRM_DEBUG_KMS("FDI train done\n");
  2160. }
  2161. static const int snb_b_fdi_train_param [] = {
  2162. FDI_LINK_TRAIN_400MV_0DB_SNB_B,
  2163. FDI_LINK_TRAIN_400MV_6DB_SNB_B,
  2164. FDI_LINK_TRAIN_600MV_3_5DB_SNB_B,
  2165. FDI_LINK_TRAIN_800MV_0DB_SNB_B,
  2166. };
  2167. /* The FDI link training functions for SNB/Cougarpoint. */
  2168. static void gen6_fdi_link_train(struct drm_crtc *crtc)
  2169. {
  2170. struct drm_device *dev = crtc->dev;
  2171. struct drm_i915_private *dev_priv = dev->dev_private;
  2172. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2173. int pipe = intel_crtc->pipe;
  2174. u32 reg, temp, i;
  2175. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  2176. for train result */
  2177. reg = FDI_RX_IMR(pipe);
  2178. temp = I915_READ(reg);
  2179. temp &= ~FDI_RX_SYMBOL_LOCK;
  2180. temp &= ~FDI_RX_BIT_LOCK;
  2181. I915_WRITE(reg, temp);
  2182. POSTING_READ(reg);
  2183. udelay(150);
  2184. /* enable CPU FDI TX and PCH FDI RX */
  2185. reg = FDI_TX_CTL(pipe);
  2186. temp = I915_READ(reg);
  2187. temp &= ~(7 << 19);
  2188. temp |= (intel_crtc->fdi_lanes - 1) << 19;
  2189. temp &= ~FDI_LINK_TRAIN_NONE;
  2190. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2191. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2192. /* SNB-B */
  2193. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  2194. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  2195. reg = FDI_RX_CTL(pipe);
  2196. temp = I915_READ(reg);
  2197. if (HAS_PCH_CPT(dev)) {
  2198. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2199. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2200. } else {
  2201. temp &= ~FDI_LINK_TRAIN_NONE;
  2202. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2203. }
  2204. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  2205. POSTING_READ(reg);
  2206. udelay(150);
  2207. for (i = 0; i < 4; i++ ) {
  2208. reg = FDI_TX_CTL(pipe);
  2209. temp = I915_READ(reg);
  2210. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2211. temp |= snb_b_fdi_train_param[i];
  2212. I915_WRITE(reg, temp);
  2213. POSTING_READ(reg);
  2214. udelay(500);
  2215. reg = FDI_RX_IIR(pipe);
  2216. temp = I915_READ(reg);
  2217. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2218. if (temp & FDI_RX_BIT_LOCK) {
  2219. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  2220. DRM_DEBUG_KMS("FDI train 1 done.\n");
  2221. break;
  2222. }
  2223. }
  2224. if (i == 4)
  2225. DRM_ERROR("FDI train 1 fail!\n");
  2226. /* Train 2 */
  2227. reg = FDI_TX_CTL(pipe);
  2228. temp = I915_READ(reg);
  2229. temp &= ~FDI_LINK_TRAIN_NONE;
  2230. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2231. if (IS_GEN6(dev)) {
  2232. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2233. /* SNB-B */
  2234. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  2235. }
  2236. I915_WRITE(reg, temp);
  2237. reg = FDI_RX_CTL(pipe);
  2238. temp = I915_READ(reg);
  2239. if (HAS_PCH_CPT(dev)) {
  2240. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2241. temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
  2242. } else {
  2243. temp &= ~FDI_LINK_TRAIN_NONE;
  2244. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2245. }
  2246. I915_WRITE(reg, temp);
  2247. POSTING_READ(reg);
  2248. udelay(150);
  2249. for (i = 0; i < 4; i++ ) {
  2250. reg = FDI_TX_CTL(pipe);
  2251. temp = I915_READ(reg);
  2252. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2253. temp |= snb_b_fdi_train_param[i];
  2254. I915_WRITE(reg, temp);
  2255. POSTING_READ(reg);
  2256. udelay(500);
  2257. reg = FDI_RX_IIR(pipe);
  2258. temp = I915_READ(reg);
  2259. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2260. if (temp & FDI_RX_SYMBOL_LOCK) {
  2261. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  2262. DRM_DEBUG_KMS("FDI train 2 done.\n");
  2263. break;
  2264. }
  2265. }
  2266. if (i == 4)
  2267. DRM_ERROR("FDI train 2 fail!\n");
  2268. DRM_DEBUG_KMS("FDI train done.\n");
  2269. }
  2270. static void ironlake_fdi_enable(struct drm_crtc *crtc)
  2271. {
  2272. struct drm_device *dev = crtc->dev;
  2273. struct drm_i915_private *dev_priv = dev->dev_private;
  2274. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2275. int pipe = intel_crtc->pipe;
  2276. u32 reg, temp;
  2277. /* Write the TU size bits so error detection works */
  2278. I915_WRITE(FDI_RX_TUSIZE1(pipe),
  2279. I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
  2280. /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
  2281. reg = FDI_RX_CTL(pipe);
  2282. temp = I915_READ(reg);
  2283. temp &= ~((0x7 << 19) | (0x7 << 16));
  2284. temp |= (intel_crtc->fdi_lanes - 1) << 19;
  2285. temp |= (I915_READ(PIPECONF(pipe)) & PIPE_BPC_MASK) << 11;
  2286. I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE);
  2287. POSTING_READ(reg);
  2288. udelay(200);
  2289. /* Switch from Rawclk to PCDclk */
  2290. temp = I915_READ(reg);
  2291. I915_WRITE(reg, temp | FDI_PCDCLK);
  2292. POSTING_READ(reg);
  2293. udelay(200);
  2294. /* Enable CPU FDI TX PLL, always on for Ironlake */
  2295. reg = FDI_TX_CTL(pipe);
  2296. temp = I915_READ(reg);
  2297. if ((temp & FDI_TX_PLL_ENABLE) == 0) {
  2298. I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE);
  2299. POSTING_READ(reg);
  2300. udelay(100);
  2301. }
  2302. }
  2303. static void ironlake_fdi_disable(struct drm_crtc *crtc)
  2304. {
  2305. struct drm_device *dev = crtc->dev;
  2306. struct drm_i915_private *dev_priv = dev->dev_private;
  2307. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2308. int pipe = intel_crtc->pipe;
  2309. u32 reg, temp;
  2310. /* disable CPU FDI tx and PCH FDI rx */
  2311. reg = FDI_TX_CTL(pipe);
  2312. temp = I915_READ(reg);
  2313. I915_WRITE(reg, temp & ~FDI_TX_ENABLE);
  2314. POSTING_READ(reg);
  2315. reg = FDI_RX_CTL(pipe);
  2316. temp = I915_READ(reg);
  2317. temp &= ~(0x7 << 16);
  2318. temp |= (I915_READ(PIPECONF(pipe)) & PIPE_BPC_MASK) << 11;
  2319. I915_WRITE(reg, temp & ~FDI_RX_ENABLE);
  2320. POSTING_READ(reg);
  2321. udelay(100);
  2322. /* Ironlake workaround, disable clock pointer after downing FDI */
  2323. if (HAS_PCH_IBX(dev)) {
  2324. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
  2325. I915_WRITE(FDI_RX_CHICKEN(pipe),
  2326. I915_READ(FDI_RX_CHICKEN(pipe) &
  2327. ~FDI_RX_PHASE_SYNC_POINTER_EN));
  2328. }
  2329. /* still set train pattern 1 */
  2330. reg = FDI_TX_CTL(pipe);
  2331. temp = I915_READ(reg);
  2332. temp &= ~FDI_LINK_TRAIN_NONE;
  2333. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2334. I915_WRITE(reg, temp);
  2335. reg = FDI_RX_CTL(pipe);
  2336. temp = I915_READ(reg);
  2337. if (HAS_PCH_CPT(dev)) {
  2338. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2339. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2340. } else {
  2341. temp &= ~FDI_LINK_TRAIN_NONE;
  2342. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2343. }
  2344. /* BPC in FDI rx is consistent with that in PIPECONF */
  2345. temp &= ~(0x07 << 16);
  2346. temp |= (I915_READ(PIPECONF(pipe)) & PIPE_BPC_MASK) << 11;
  2347. I915_WRITE(reg, temp);
  2348. POSTING_READ(reg);
  2349. udelay(100);
  2350. }
  2351. /*
  2352. * When we disable a pipe, we need to clear any pending scanline wait events
  2353. * to avoid hanging the ring, which we assume we are waiting on.
  2354. */
  2355. static void intel_clear_scanline_wait(struct drm_device *dev)
  2356. {
  2357. struct drm_i915_private *dev_priv = dev->dev_private;
  2358. struct intel_ring_buffer *ring;
  2359. u32 tmp;
  2360. if (IS_GEN2(dev))
  2361. /* Can't break the hang on i8xx */
  2362. return;
  2363. ring = LP_RING(dev_priv);
  2364. tmp = I915_READ_CTL(ring);
  2365. if (tmp & RING_WAIT)
  2366. I915_WRITE_CTL(ring, tmp);
  2367. }
  2368. static void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
  2369. {
  2370. struct drm_i915_gem_object *obj;
  2371. struct drm_i915_private *dev_priv;
  2372. if (crtc->fb == NULL)
  2373. return;
  2374. obj = to_intel_framebuffer(crtc->fb)->obj;
  2375. dev_priv = crtc->dev->dev_private;
  2376. wait_event(dev_priv->pending_flip_queue,
  2377. atomic_read(&obj->pending_flip) == 0);
  2378. }
  2379. static bool intel_crtc_driving_pch(struct drm_crtc *crtc)
  2380. {
  2381. struct drm_device *dev = crtc->dev;
  2382. struct drm_mode_config *mode_config = &dev->mode_config;
  2383. struct intel_encoder *encoder;
  2384. /*
  2385. * If there's a non-PCH eDP on this crtc, it must be DP_A, and that
  2386. * must be driven by its own crtc; no sharing is possible.
  2387. */
  2388. list_for_each_entry(encoder, &mode_config->encoder_list, base.head) {
  2389. if (encoder->base.crtc != crtc)
  2390. continue;
  2391. switch (encoder->type) {
  2392. case INTEL_OUTPUT_EDP:
  2393. if (!intel_encoder_is_pch_edp(&encoder->base))
  2394. return false;
  2395. continue;
  2396. }
  2397. }
  2398. return true;
  2399. }
  2400. /*
  2401. * Enable PCH resources required for PCH ports:
  2402. * - PCH PLLs
  2403. * - FDI training & RX/TX
  2404. * - update transcoder timings
  2405. * - DP transcoding bits
  2406. * - transcoder
  2407. */
  2408. static void ironlake_pch_enable(struct drm_crtc *crtc)
  2409. {
  2410. struct drm_device *dev = crtc->dev;
  2411. struct drm_i915_private *dev_priv = dev->dev_private;
  2412. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2413. int pipe = intel_crtc->pipe;
  2414. u32 reg, temp;
  2415. /* For PCH output, training FDI link */
  2416. if (IS_GEN6(dev))
  2417. gen6_fdi_link_train(crtc);
  2418. else
  2419. ironlake_fdi_link_train(crtc);
  2420. intel_enable_pch_pll(dev_priv, pipe);
  2421. if (HAS_PCH_CPT(dev)) {
  2422. /* Be sure PCH DPLL SEL is set */
  2423. temp = I915_READ(PCH_DPLL_SEL);
  2424. if (pipe == 0 && (temp & TRANSA_DPLL_ENABLE) == 0)
  2425. temp |= (TRANSA_DPLL_ENABLE | TRANSA_DPLLA_SEL);
  2426. else if (pipe == 1 && (temp & TRANSB_DPLL_ENABLE) == 0)
  2427. temp |= (TRANSB_DPLL_ENABLE | TRANSB_DPLLB_SEL);
  2428. I915_WRITE(PCH_DPLL_SEL, temp);
  2429. }
  2430. /* set transcoder timing, panel must allow it */
  2431. assert_panel_unlocked(dev_priv, pipe);
  2432. I915_WRITE(TRANS_HTOTAL(pipe), I915_READ(HTOTAL(pipe)));
  2433. I915_WRITE(TRANS_HBLANK(pipe), I915_READ(HBLANK(pipe)));
  2434. I915_WRITE(TRANS_HSYNC(pipe), I915_READ(HSYNC(pipe)));
  2435. I915_WRITE(TRANS_VTOTAL(pipe), I915_READ(VTOTAL(pipe)));
  2436. I915_WRITE(TRANS_VBLANK(pipe), I915_READ(VBLANK(pipe)));
  2437. I915_WRITE(TRANS_VSYNC(pipe), I915_READ(VSYNC(pipe)));
  2438. intel_fdi_normal_train(crtc);
  2439. /* For PCH DP, enable TRANS_DP_CTL */
  2440. if (HAS_PCH_CPT(dev) &&
  2441. intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) {
  2442. reg = TRANS_DP_CTL(pipe);
  2443. temp = I915_READ(reg);
  2444. temp &= ~(TRANS_DP_PORT_SEL_MASK |
  2445. TRANS_DP_SYNC_MASK |
  2446. TRANS_DP_BPC_MASK);
  2447. temp |= (TRANS_DP_OUTPUT_ENABLE |
  2448. TRANS_DP_ENH_FRAMING);
  2449. temp |= TRANS_DP_8BPC;
  2450. if (crtc->mode.flags & DRM_MODE_FLAG_PHSYNC)
  2451. temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
  2452. if (crtc->mode.flags & DRM_MODE_FLAG_PVSYNC)
  2453. temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
  2454. switch (intel_trans_dp_port_sel(crtc)) {
  2455. case PCH_DP_B:
  2456. temp |= TRANS_DP_PORT_SEL_B;
  2457. break;
  2458. case PCH_DP_C:
  2459. temp |= TRANS_DP_PORT_SEL_C;
  2460. break;
  2461. case PCH_DP_D:
  2462. temp |= TRANS_DP_PORT_SEL_D;
  2463. break;
  2464. default:
  2465. DRM_DEBUG_KMS("Wrong PCH DP port return. Guess port B\n");
  2466. temp |= TRANS_DP_PORT_SEL_B;
  2467. break;
  2468. }
  2469. I915_WRITE(reg, temp);
  2470. }
  2471. intel_enable_transcoder(dev_priv, pipe);
  2472. }
  2473. static void ironlake_crtc_enable(struct drm_crtc *crtc)
  2474. {
  2475. struct drm_device *dev = crtc->dev;
  2476. struct drm_i915_private *dev_priv = dev->dev_private;
  2477. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2478. int pipe = intel_crtc->pipe;
  2479. int plane = intel_crtc->plane;
  2480. u32 temp;
  2481. bool is_pch_port;
  2482. if (intel_crtc->active)
  2483. return;
  2484. intel_crtc->active = true;
  2485. intel_update_watermarks(dev);
  2486. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  2487. temp = I915_READ(PCH_LVDS);
  2488. if ((temp & LVDS_PORT_EN) == 0)
  2489. I915_WRITE(PCH_LVDS, temp | LVDS_PORT_EN);
  2490. }
  2491. is_pch_port = intel_crtc_driving_pch(crtc);
  2492. if (is_pch_port)
  2493. ironlake_fdi_enable(crtc);
  2494. else
  2495. ironlake_fdi_disable(crtc);
  2496. /* Enable panel fitting for LVDS */
  2497. if (dev_priv->pch_pf_size &&
  2498. (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) || HAS_eDP)) {
  2499. /* Force use of hard-coded filter coefficients
  2500. * as some pre-programmed values are broken,
  2501. * e.g. x201.
  2502. */
  2503. I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3);
  2504. I915_WRITE(PF_WIN_POS(pipe), dev_priv->pch_pf_pos);
  2505. I915_WRITE(PF_WIN_SZ(pipe), dev_priv->pch_pf_size);
  2506. }
  2507. intel_enable_pipe(dev_priv, pipe, is_pch_port);
  2508. intel_enable_plane(dev_priv, plane, pipe);
  2509. if (is_pch_port)
  2510. ironlake_pch_enable(crtc);
  2511. intel_crtc_load_lut(crtc);
  2512. intel_update_fbc(dev);
  2513. intel_crtc_update_cursor(crtc, true);
  2514. }
  2515. static void ironlake_crtc_disable(struct drm_crtc *crtc)
  2516. {
  2517. struct drm_device *dev = crtc->dev;
  2518. struct drm_i915_private *dev_priv = dev->dev_private;
  2519. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2520. int pipe = intel_crtc->pipe;
  2521. int plane = intel_crtc->plane;
  2522. u32 reg, temp;
  2523. if (!intel_crtc->active)
  2524. return;
  2525. intel_crtc_wait_for_pending_flips(crtc);
  2526. drm_vblank_off(dev, pipe);
  2527. intel_crtc_update_cursor(crtc, false);
  2528. intel_disable_plane(dev_priv, plane, pipe);
  2529. if (dev_priv->cfb_plane == plane &&
  2530. dev_priv->display.disable_fbc)
  2531. dev_priv->display.disable_fbc(dev);
  2532. intel_disable_pipe(dev_priv, pipe);
  2533. /* Disable PF */
  2534. I915_WRITE(PF_CTL(pipe), 0);
  2535. I915_WRITE(PF_WIN_SZ(pipe), 0);
  2536. ironlake_fdi_disable(crtc);
  2537. /* This is a horrible layering violation; we should be doing this in
  2538. * the connector/encoder ->prepare instead, but we don't always have
  2539. * enough information there about the config to know whether it will
  2540. * actually be necessary or just cause undesired flicker.
  2541. */
  2542. intel_disable_pch_ports(dev_priv, pipe);
  2543. intel_disable_transcoder(dev_priv, pipe);
  2544. if (HAS_PCH_CPT(dev)) {
  2545. /* disable TRANS_DP_CTL */
  2546. reg = TRANS_DP_CTL(pipe);
  2547. temp = I915_READ(reg);
  2548. temp &= ~(TRANS_DP_OUTPUT_ENABLE | TRANS_DP_PORT_SEL_MASK);
  2549. temp |= TRANS_DP_PORT_SEL_NONE;
  2550. I915_WRITE(reg, temp);
  2551. /* disable DPLL_SEL */
  2552. temp = I915_READ(PCH_DPLL_SEL);
  2553. switch (pipe) {
  2554. case 0:
  2555. temp &= ~(TRANSA_DPLL_ENABLE | TRANSA_DPLLA_SEL);
  2556. break;
  2557. case 1:
  2558. temp &= ~(TRANSB_DPLL_ENABLE | TRANSB_DPLLB_SEL);
  2559. break;
  2560. case 2:
  2561. /* FIXME: manage transcoder PLLs? */
  2562. temp &= ~(TRANSC_DPLL_ENABLE | TRANSC_DPLLB_SEL);
  2563. break;
  2564. default:
  2565. BUG(); /* wtf */
  2566. }
  2567. I915_WRITE(PCH_DPLL_SEL, temp);
  2568. }
  2569. /* disable PCH DPLL */
  2570. intel_disable_pch_pll(dev_priv, pipe);
  2571. /* Switch from PCDclk to Rawclk */
  2572. reg = FDI_RX_CTL(pipe);
  2573. temp = I915_READ(reg);
  2574. I915_WRITE(reg, temp & ~FDI_PCDCLK);
  2575. /* Disable CPU FDI TX PLL */
  2576. reg = FDI_TX_CTL(pipe);
  2577. temp = I915_READ(reg);
  2578. I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE);
  2579. POSTING_READ(reg);
  2580. udelay(100);
  2581. reg = FDI_RX_CTL(pipe);
  2582. temp = I915_READ(reg);
  2583. I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE);
  2584. /* Wait for the clocks to turn off. */
  2585. POSTING_READ(reg);
  2586. udelay(100);
  2587. intel_crtc->active = false;
  2588. intel_update_watermarks(dev);
  2589. intel_update_fbc(dev);
  2590. intel_clear_scanline_wait(dev);
  2591. }
  2592. static void ironlake_crtc_dpms(struct drm_crtc *crtc, int mode)
  2593. {
  2594. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2595. int pipe = intel_crtc->pipe;
  2596. int plane = intel_crtc->plane;
  2597. /* XXX: When our outputs are all unaware of DPMS modes other than off
  2598. * and on, we should map those modes to DRM_MODE_DPMS_OFF in the CRTC.
  2599. */
  2600. switch (mode) {
  2601. case DRM_MODE_DPMS_ON:
  2602. case DRM_MODE_DPMS_STANDBY:
  2603. case DRM_MODE_DPMS_SUSPEND:
  2604. DRM_DEBUG_KMS("crtc %d/%d dpms on\n", pipe, plane);
  2605. ironlake_crtc_enable(crtc);
  2606. break;
  2607. case DRM_MODE_DPMS_OFF:
  2608. DRM_DEBUG_KMS("crtc %d/%d dpms off\n", pipe, plane);
  2609. ironlake_crtc_disable(crtc);
  2610. break;
  2611. }
  2612. }
  2613. static void intel_crtc_dpms_overlay(struct intel_crtc *intel_crtc, bool enable)
  2614. {
  2615. if (!enable && intel_crtc->overlay) {
  2616. struct drm_device *dev = intel_crtc->base.dev;
  2617. mutex_lock(&dev->struct_mutex);
  2618. (void) intel_overlay_switch_off(intel_crtc->overlay, false);
  2619. mutex_unlock(&dev->struct_mutex);
  2620. }
  2621. /* Let userspace switch the overlay on again. In most cases userspace
  2622. * has to recompute where to put it anyway.
  2623. */
  2624. }
  2625. static void i9xx_crtc_enable(struct drm_crtc *crtc)
  2626. {
  2627. struct drm_device *dev = crtc->dev;
  2628. struct drm_i915_private *dev_priv = dev->dev_private;
  2629. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2630. int pipe = intel_crtc->pipe;
  2631. int plane = intel_crtc->plane;
  2632. if (intel_crtc->active)
  2633. return;
  2634. intel_crtc->active = true;
  2635. intel_update_watermarks(dev);
  2636. intel_enable_pll(dev_priv, pipe);
  2637. intel_enable_pipe(dev_priv, pipe, false);
  2638. intel_enable_plane(dev_priv, plane, pipe);
  2639. intel_crtc_load_lut(crtc);
  2640. intel_update_fbc(dev);
  2641. /* Give the overlay scaler a chance to enable if it's on this pipe */
  2642. intel_crtc_dpms_overlay(intel_crtc, true);
  2643. intel_crtc_update_cursor(crtc, true);
  2644. }
  2645. static void i9xx_crtc_disable(struct drm_crtc *crtc)
  2646. {
  2647. struct drm_device *dev = crtc->dev;
  2648. struct drm_i915_private *dev_priv = dev->dev_private;
  2649. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2650. int pipe = intel_crtc->pipe;
  2651. int plane = intel_crtc->plane;
  2652. if (!intel_crtc->active)
  2653. return;
  2654. /* Give the overlay scaler a chance to disable if it's on this pipe */
  2655. intel_crtc_wait_for_pending_flips(crtc);
  2656. drm_vblank_off(dev, pipe);
  2657. intel_crtc_dpms_overlay(intel_crtc, false);
  2658. intel_crtc_update_cursor(crtc, false);
  2659. if (dev_priv->cfb_plane == plane &&
  2660. dev_priv->display.disable_fbc)
  2661. dev_priv->display.disable_fbc(dev);
  2662. intel_disable_plane(dev_priv, plane, pipe);
  2663. intel_disable_pipe(dev_priv, pipe);
  2664. intel_disable_pll(dev_priv, pipe);
  2665. intel_crtc->active = false;
  2666. intel_update_fbc(dev);
  2667. intel_update_watermarks(dev);
  2668. intel_clear_scanline_wait(dev);
  2669. }
  2670. static void i9xx_crtc_dpms(struct drm_crtc *crtc, int mode)
  2671. {
  2672. /* XXX: When our outputs are all unaware of DPMS modes other than off
  2673. * and on, we should map those modes to DRM_MODE_DPMS_OFF in the CRTC.
  2674. */
  2675. switch (mode) {
  2676. case DRM_MODE_DPMS_ON:
  2677. case DRM_MODE_DPMS_STANDBY:
  2678. case DRM_MODE_DPMS_SUSPEND:
  2679. i9xx_crtc_enable(crtc);
  2680. break;
  2681. case DRM_MODE_DPMS_OFF:
  2682. i9xx_crtc_disable(crtc);
  2683. break;
  2684. }
  2685. }
  2686. /**
  2687. * Sets the power management mode of the pipe and plane.
  2688. */
  2689. static void intel_crtc_dpms(struct drm_crtc *crtc, int mode)
  2690. {
  2691. struct drm_device *dev = crtc->dev;
  2692. struct drm_i915_private *dev_priv = dev->dev_private;
  2693. struct drm_i915_master_private *master_priv;
  2694. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2695. int pipe = intel_crtc->pipe;
  2696. bool enabled;
  2697. if (intel_crtc->dpms_mode == mode)
  2698. return;
  2699. intel_crtc->dpms_mode = mode;
  2700. dev_priv->display.dpms(crtc, mode);
  2701. if (!dev->primary->master)
  2702. return;
  2703. master_priv = dev->primary->master->driver_priv;
  2704. if (!master_priv->sarea_priv)
  2705. return;
  2706. enabled = crtc->enabled && mode != DRM_MODE_DPMS_OFF;
  2707. switch (pipe) {
  2708. case 0:
  2709. master_priv->sarea_priv->pipeA_w = enabled ? crtc->mode.hdisplay : 0;
  2710. master_priv->sarea_priv->pipeA_h = enabled ? crtc->mode.vdisplay : 0;
  2711. break;
  2712. case 1:
  2713. master_priv->sarea_priv->pipeB_w = enabled ? crtc->mode.hdisplay : 0;
  2714. master_priv->sarea_priv->pipeB_h = enabled ? crtc->mode.vdisplay : 0;
  2715. break;
  2716. default:
  2717. DRM_ERROR("Can't update pipe %c in SAREA\n", pipe_name(pipe));
  2718. break;
  2719. }
  2720. }
  2721. static void intel_crtc_disable(struct drm_crtc *crtc)
  2722. {
  2723. struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
  2724. struct drm_device *dev = crtc->dev;
  2725. crtc_funcs->dpms(crtc, DRM_MODE_DPMS_OFF);
  2726. if (crtc->fb) {
  2727. mutex_lock(&dev->struct_mutex);
  2728. i915_gem_object_unpin(to_intel_framebuffer(crtc->fb)->obj);
  2729. mutex_unlock(&dev->struct_mutex);
  2730. }
  2731. }
  2732. /* Prepare for a mode set.
  2733. *
  2734. * Note we could be a lot smarter here. We need to figure out which outputs
  2735. * will be enabled, which disabled (in short, how the config will changes)
  2736. * and perform the minimum necessary steps to accomplish that, e.g. updating
  2737. * watermarks, FBC configuration, making sure PLLs are programmed correctly,
  2738. * panel fitting is in the proper state, etc.
  2739. */
  2740. static void i9xx_crtc_prepare(struct drm_crtc *crtc)
  2741. {
  2742. i9xx_crtc_disable(crtc);
  2743. }
  2744. static void i9xx_crtc_commit(struct drm_crtc *crtc)
  2745. {
  2746. i9xx_crtc_enable(crtc);
  2747. }
  2748. static void ironlake_crtc_prepare(struct drm_crtc *crtc)
  2749. {
  2750. ironlake_crtc_disable(crtc);
  2751. }
  2752. static void ironlake_crtc_commit(struct drm_crtc *crtc)
  2753. {
  2754. ironlake_crtc_enable(crtc);
  2755. }
  2756. void intel_encoder_prepare (struct drm_encoder *encoder)
  2757. {
  2758. struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
  2759. /* lvds has its own version of prepare see intel_lvds_prepare */
  2760. encoder_funcs->dpms(encoder, DRM_MODE_DPMS_OFF);
  2761. }
  2762. void intel_encoder_commit (struct drm_encoder *encoder)
  2763. {
  2764. struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
  2765. /* lvds has its own version of commit see intel_lvds_commit */
  2766. encoder_funcs->dpms(encoder, DRM_MODE_DPMS_ON);
  2767. }
  2768. void intel_encoder_destroy(struct drm_encoder *encoder)
  2769. {
  2770. struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
  2771. drm_encoder_cleanup(encoder);
  2772. kfree(intel_encoder);
  2773. }
  2774. static bool intel_crtc_mode_fixup(struct drm_crtc *crtc,
  2775. struct drm_display_mode *mode,
  2776. struct drm_display_mode *adjusted_mode)
  2777. {
  2778. struct drm_device *dev = crtc->dev;
  2779. if (HAS_PCH_SPLIT(dev)) {
  2780. /* FDI link clock is fixed at 2.7G */
  2781. if (mode->clock * 3 > IRONLAKE_FDI_FREQ * 4)
  2782. return false;
  2783. }
  2784. /* XXX some encoders set the crtcinfo, others don't.
  2785. * Obviously we need some form of conflict resolution here...
  2786. */
  2787. if (adjusted_mode->crtc_htotal == 0)
  2788. drm_mode_set_crtcinfo(adjusted_mode, 0);
  2789. return true;
  2790. }
  2791. static int i945_get_display_clock_speed(struct drm_device *dev)
  2792. {
  2793. return 400000;
  2794. }
  2795. static int i915_get_display_clock_speed(struct drm_device *dev)
  2796. {
  2797. return 333000;
  2798. }
  2799. static int i9xx_misc_get_display_clock_speed(struct drm_device *dev)
  2800. {
  2801. return 200000;
  2802. }
  2803. static int i915gm_get_display_clock_speed(struct drm_device *dev)
  2804. {
  2805. u16 gcfgc = 0;
  2806. pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
  2807. if (gcfgc & GC_LOW_FREQUENCY_ENABLE)
  2808. return 133000;
  2809. else {
  2810. switch (gcfgc & GC_DISPLAY_CLOCK_MASK) {
  2811. case GC_DISPLAY_CLOCK_333_MHZ:
  2812. return 333000;
  2813. default:
  2814. case GC_DISPLAY_CLOCK_190_200_MHZ:
  2815. return 190000;
  2816. }
  2817. }
  2818. }
  2819. static int i865_get_display_clock_speed(struct drm_device *dev)
  2820. {
  2821. return 266000;
  2822. }
  2823. static int i855_get_display_clock_speed(struct drm_device *dev)
  2824. {
  2825. u16 hpllcc = 0;
  2826. /* Assume that the hardware is in the high speed state. This
  2827. * should be the default.
  2828. */
  2829. switch (hpllcc & GC_CLOCK_CONTROL_MASK) {
  2830. case GC_CLOCK_133_200:
  2831. case GC_CLOCK_100_200:
  2832. return 200000;
  2833. case GC_CLOCK_166_250:
  2834. return 250000;
  2835. case GC_CLOCK_100_133:
  2836. return 133000;
  2837. }
  2838. /* Shouldn't happen */
  2839. return 0;
  2840. }
  2841. static int i830_get_display_clock_speed(struct drm_device *dev)
  2842. {
  2843. return 133000;
  2844. }
  2845. struct fdi_m_n {
  2846. u32 tu;
  2847. u32 gmch_m;
  2848. u32 gmch_n;
  2849. u32 link_m;
  2850. u32 link_n;
  2851. };
  2852. static void
  2853. fdi_reduce_ratio(u32 *num, u32 *den)
  2854. {
  2855. while (*num > 0xffffff || *den > 0xffffff) {
  2856. *num >>= 1;
  2857. *den >>= 1;
  2858. }
  2859. }
  2860. static void
  2861. ironlake_compute_m_n(int bits_per_pixel, int nlanes, int pixel_clock,
  2862. int link_clock, struct fdi_m_n *m_n)
  2863. {
  2864. m_n->tu = 64; /* default size */
  2865. /* BUG_ON(pixel_clock > INT_MAX / 36); */
  2866. m_n->gmch_m = bits_per_pixel * pixel_clock;
  2867. m_n->gmch_n = link_clock * nlanes * 8;
  2868. fdi_reduce_ratio(&m_n->gmch_m, &m_n->gmch_n);
  2869. m_n->link_m = pixel_clock;
  2870. m_n->link_n = link_clock;
  2871. fdi_reduce_ratio(&m_n->link_m, &m_n->link_n);
  2872. }
  2873. struct intel_watermark_params {
  2874. unsigned long fifo_size;
  2875. unsigned long max_wm;
  2876. unsigned long default_wm;
  2877. unsigned long guard_size;
  2878. unsigned long cacheline_size;
  2879. };
  2880. /* Pineview has different values for various configs */
  2881. static const struct intel_watermark_params pineview_display_wm = {
  2882. PINEVIEW_DISPLAY_FIFO,
  2883. PINEVIEW_MAX_WM,
  2884. PINEVIEW_DFT_WM,
  2885. PINEVIEW_GUARD_WM,
  2886. PINEVIEW_FIFO_LINE_SIZE
  2887. };
  2888. static const struct intel_watermark_params pineview_display_hplloff_wm = {
  2889. PINEVIEW_DISPLAY_FIFO,
  2890. PINEVIEW_MAX_WM,
  2891. PINEVIEW_DFT_HPLLOFF_WM,
  2892. PINEVIEW_GUARD_WM,
  2893. PINEVIEW_FIFO_LINE_SIZE
  2894. };
  2895. static const struct intel_watermark_params pineview_cursor_wm = {
  2896. PINEVIEW_CURSOR_FIFO,
  2897. PINEVIEW_CURSOR_MAX_WM,
  2898. PINEVIEW_CURSOR_DFT_WM,
  2899. PINEVIEW_CURSOR_GUARD_WM,
  2900. PINEVIEW_FIFO_LINE_SIZE,
  2901. };
  2902. static const struct intel_watermark_params pineview_cursor_hplloff_wm = {
  2903. PINEVIEW_CURSOR_FIFO,
  2904. PINEVIEW_CURSOR_MAX_WM,
  2905. PINEVIEW_CURSOR_DFT_WM,
  2906. PINEVIEW_CURSOR_GUARD_WM,
  2907. PINEVIEW_FIFO_LINE_SIZE
  2908. };
  2909. static const struct intel_watermark_params g4x_wm_info = {
  2910. G4X_FIFO_SIZE,
  2911. G4X_MAX_WM,
  2912. G4X_MAX_WM,
  2913. 2,
  2914. G4X_FIFO_LINE_SIZE,
  2915. };
  2916. static const struct intel_watermark_params g4x_cursor_wm_info = {
  2917. I965_CURSOR_FIFO,
  2918. I965_CURSOR_MAX_WM,
  2919. I965_CURSOR_DFT_WM,
  2920. 2,
  2921. G4X_FIFO_LINE_SIZE,
  2922. };
  2923. static const struct intel_watermark_params i965_cursor_wm_info = {
  2924. I965_CURSOR_FIFO,
  2925. I965_CURSOR_MAX_WM,
  2926. I965_CURSOR_DFT_WM,
  2927. 2,
  2928. I915_FIFO_LINE_SIZE,
  2929. };
  2930. static const struct intel_watermark_params i945_wm_info = {
  2931. I945_FIFO_SIZE,
  2932. I915_MAX_WM,
  2933. 1,
  2934. 2,
  2935. I915_FIFO_LINE_SIZE
  2936. };
  2937. static const struct intel_watermark_params i915_wm_info = {
  2938. I915_FIFO_SIZE,
  2939. I915_MAX_WM,
  2940. 1,
  2941. 2,
  2942. I915_FIFO_LINE_SIZE
  2943. };
  2944. static const struct intel_watermark_params i855_wm_info = {
  2945. I855GM_FIFO_SIZE,
  2946. I915_MAX_WM,
  2947. 1,
  2948. 2,
  2949. I830_FIFO_LINE_SIZE
  2950. };
  2951. static const struct intel_watermark_params i830_wm_info = {
  2952. I830_FIFO_SIZE,
  2953. I915_MAX_WM,
  2954. 1,
  2955. 2,
  2956. I830_FIFO_LINE_SIZE
  2957. };
  2958. static const struct intel_watermark_params ironlake_display_wm_info = {
  2959. ILK_DISPLAY_FIFO,
  2960. ILK_DISPLAY_MAXWM,
  2961. ILK_DISPLAY_DFTWM,
  2962. 2,
  2963. ILK_FIFO_LINE_SIZE
  2964. };
  2965. static const struct intel_watermark_params ironlake_cursor_wm_info = {
  2966. ILK_CURSOR_FIFO,
  2967. ILK_CURSOR_MAXWM,
  2968. ILK_CURSOR_DFTWM,
  2969. 2,
  2970. ILK_FIFO_LINE_SIZE
  2971. };
  2972. static const struct intel_watermark_params ironlake_display_srwm_info = {
  2973. ILK_DISPLAY_SR_FIFO,
  2974. ILK_DISPLAY_MAX_SRWM,
  2975. ILK_DISPLAY_DFT_SRWM,
  2976. 2,
  2977. ILK_FIFO_LINE_SIZE
  2978. };
  2979. static const struct intel_watermark_params ironlake_cursor_srwm_info = {
  2980. ILK_CURSOR_SR_FIFO,
  2981. ILK_CURSOR_MAX_SRWM,
  2982. ILK_CURSOR_DFT_SRWM,
  2983. 2,
  2984. ILK_FIFO_LINE_SIZE
  2985. };
  2986. static const struct intel_watermark_params sandybridge_display_wm_info = {
  2987. SNB_DISPLAY_FIFO,
  2988. SNB_DISPLAY_MAXWM,
  2989. SNB_DISPLAY_DFTWM,
  2990. 2,
  2991. SNB_FIFO_LINE_SIZE
  2992. };
  2993. static const struct intel_watermark_params sandybridge_cursor_wm_info = {
  2994. SNB_CURSOR_FIFO,
  2995. SNB_CURSOR_MAXWM,
  2996. SNB_CURSOR_DFTWM,
  2997. 2,
  2998. SNB_FIFO_LINE_SIZE
  2999. };
  3000. static const struct intel_watermark_params sandybridge_display_srwm_info = {
  3001. SNB_DISPLAY_SR_FIFO,
  3002. SNB_DISPLAY_MAX_SRWM,
  3003. SNB_DISPLAY_DFT_SRWM,
  3004. 2,
  3005. SNB_FIFO_LINE_SIZE
  3006. };
  3007. static const struct intel_watermark_params sandybridge_cursor_srwm_info = {
  3008. SNB_CURSOR_SR_FIFO,
  3009. SNB_CURSOR_MAX_SRWM,
  3010. SNB_CURSOR_DFT_SRWM,
  3011. 2,
  3012. SNB_FIFO_LINE_SIZE
  3013. };
  3014. /**
  3015. * intel_calculate_wm - calculate watermark level
  3016. * @clock_in_khz: pixel clock
  3017. * @wm: chip FIFO params
  3018. * @pixel_size: display pixel size
  3019. * @latency_ns: memory latency for the platform
  3020. *
  3021. * Calculate the watermark level (the level at which the display plane will
  3022. * start fetching from memory again). Each chip has a different display
  3023. * FIFO size and allocation, so the caller needs to figure that out and pass
  3024. * in the correct intel_watermark_params structure.
  3025. *
  3026. * As the pixel clock runs, the FIFO will be drained at a rate that depends
  3027. * on the pixel size. When it reaches the watermark level, it'll start
  3028. * fetching FIFO line sized based chunks from memory until the FIFO fills
  3029. * past the watermark point. If the FIFO drains completely, a FIFO underrun
  3030. * will occur, and a display engine hang could result.
  3031. */
  3032. static unsigned long intel_calculate_wm(unsigned long clock_in_khz,
  3033. const struct intel_watermark_params *wm,
  3034. int fifo_size,
  3035. int pixel_size,
  3036. unsigned long latency_ns)
  3037. {
  3038. long entries_required, wm_size;
  3039. /*
  3040. * Note: we need to make sure we don't overflow for various clock &
  3041. * latency values.
  3042. * clocks go from a few thousand to several hundred thousand.
  3043. * latency is usually a few thousand
  3044. */
  3045. entries_required = ((clock_in_khz / 1000) * pixel_size * latency_ns) /
  3046. 1000;
  3047. entries_required = DIV_ROUND_UP(entries_required, wm->cacheline_size);
  3048. DRM_DEBUG_KMS("FIFO entries required for mode: %d\n", entries_required);
  3049. wm_size = fifo_size - (entries_required + wm->guard_size);
  3050. DRM_DEBUG_KMS("FIFO watermark level: %d\n", wm_size);
  3051. /* Don't promote wm_size to unsigned... */
  3052. if (wm_size > (long)wm->max_wm)
  3053. wm_size = wm->max_wm;
  3054. if (wm_size <= 0)
  3055. wm_size = wm->default_wm;
  3056. return wm_size;
  3057. }
  3058. struct cxsr_latency {
  3059. int is_desktop;
  3060. int is_ddr3;
  3061. unsigned long fsb_freq;
  3062. unsigned long mem_freq;
  3063. unsigned long display_sr;
  3064. unsigned long display_hpll_disable;
  3065. unsigned long cursor_sr;
  3066. unsigned long cursor_hpll_disable;
  3067. };
  3068. static const struct cxsr_latency cxsr_latency_table[] = {
  3069. {1, 0, 800, 400, 3382, 33382, 3983, 33983}, /* DDR2-400 SC */
  3070. {1, 0, 800, 667, 3354, 33354, 3807, 33807}, /* DDR2-667 SC */
  3071. {1, 0, 800, 800, 3347, 33347, 3763, 33763}, /* DDR2-800 SC */
  3072. {1, 1, 800, 667, 6420, 36420, 6873, 36873}, /* DDR3-667 SC */
  3073. {1, 1, 800, 800, 5902, 35902, 6318, 36318}, /* DDR3-800 SC */
  3074. {1, 0, 667, 400, 3400, 33400, 4021, 34021}, /* DDR2-400 SC */
  3075. {1, 0, 667, 667, 3372, 33372, 3845, 33845}, /* DDR2-667 SC */
  3076. {1, 0, 667, 800, 3386, 33386, 3822, 33822}, /* DDR2-800 SC */
  3077. {1, 1, 667, 667, 6438, 36438, 6911, 36911}, /* DDR3-667 SC */
  3078. {1, 1, 667, 800, 5941, 35941, 6377, 36377}, /* DDR3-800 SC */
  3079. {1, 0, 400, 400, 3472, 33472, 4173, 34173}, /* DDR2-400 SC */
  3080. {1, 0, 400, 667, 3443, 33443, 3996, 33996}, /* DDR2-667 SC */
  3081. {1, 0, 400, 800, 3430, 33430, 3946, 33946}, /* DDR2-800 SC */
  3082. {1, 1, 400, 667, 6509, 36509, 7062, 37062}, /* DDR3-667 SC */
  3083. {1, 1, 400, 800, 5985, 35985, 6501, 36501}, /* DDR3-800 SC */
  3084. {0, 0, 800, 400, 3438, 33438, 4065, 34065}, /* DDR2-400 SC */
  3085. {0, 0, 800, 667, 3410, 33410, 3889, 33889}, /* DDR2-667 SC */
  3086. {0, 0, 800, 800, 3403, 33403, 3845, 33845}, /* DDR2-800 SC */
  3087. {0, 1, 800, 667, 6476, 36476, 6955, 36955}, /* DDR3-667 SC */
  3088. {0, 1, 800, 800, 5958, 35958, 6400, 36400}, /* DDR3-800 SC */
  3089. {0, 0, 667, 400, 3456, 33456, 4103, 34106}, /* DDR2-400 SC */
  3090. {0, 0, 667, 667, 3428, 33428, 3927, 33927}, /* DDR2-667 SC */
  3091. {0, 0, 667, 800, 3443, 33443, 3905, 33905}, /* DDR2-800 SC */
  3092. {0, 1, 667, 667, 6494, 36494, 6993, 36993}, /* DDR3-667 SC */
  3093. {0, 1, 667, 800, 5998, 35998, 6460, 36460}, /* DDR3-800 SC */
  3094. {0, 0, 400, 400, 3528, 33528, 4255, 34255}, /* DDR2-400 SC */
  3095. {0, 0, 400, 667, 3500, 33500, 4079, 34079}, /* DDR2-667 SC */
  3096. {0, 0, 400, 800, 3487, 33487, 4029, 34029}, /* DDR2-800 SC */
  3097. {0, 1, 400, 667, 6566, 36566, 7145, 37145}, /* DDR3-667 SC */
  3098. {0, 1, 400, 800, 6042, 36042, 6584, 36584}, /* DDR3-800 SC */
  3099. };
  3100. static const struct cxsr_latency *intel_get_cxsr_latency(int is_desktop,
  3101. int is_ddr3,
  3102. int fsb,
  3103. int mem)
  3104. {
  3105. const struct cxsr_latency *latency;
  3106. int i;
  3107. if (fsb == 0 || mem == 0)
  3108. return NULL;
  3109. for (i = 0; i < ARRAY_SIZE(cxsr_latency_table); i++) {
  3110. latency = &cxsr_latency_table[i];
  3111. if (is_desktop == latency->is_desktop &&
  3112. is_ddr3 == latency->is_ddr3 &&
  3113. fsb == latency->fsb_freq && mem == latency->mem_freq)
  3114. return latency;
  3115. }
  3116. DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n");
  3117. return NULL;
  3118. }
  3119. static void pineview_disable_cxsr(struct drm_device *dev)
  3120. {
  3121. struct drm_i915_private *dev_priv = dev->dev_private;
  3122. /* deactivate cxsr */
  3123. I915_WRITE(DSPFW3, I915_READ(DSPFW3) & ~PINEVIEW_SELF_REFRESH_EN);
  3124. }
  3125. /*
  3126. * Latency for FIFO fetches is dependent on several factors:
  3127. * - memory configuration (speed, channels)
  3128. * - chipset
  3129. * - current MCH state
  3130. * It can be fairly high in some situations, so here we assume a fairly
  3131. * pessimal value. It's a tradeoff between extra memory fetches (if we
  3132. * set this value too high, the FIFO will fetch frequently to stay full)
  3133. * and power consumption (set it too low to save power and we might see
  3134. * FIFO underruns and display "flicker").
  3135. *
  3136. * A value of 5us seems to be a good balance; safe for very low end
  3137. * platforms but not overly aggressive on lower latency configs.
  3138. */
  3139. static const int latency_ns = 5000;
  3140. static int i9xx_get_fifo_size(struct drm_device *dev, int plane)
  3141. {
  3142. struct drm_i915_private *dev_priv = dev->dev_private;
  3143. uint32_t dsparb = I915_READ(DSPARB);
  3144. int size;
  3145. size = dsparb & 0x7f;
  3146. if (plane)
  3147. size = ((dsparb >> DSPARB_CSTART_SHIFT) & 0x7f) - size;
  3148. DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb,
  3149. plane ? "B" : "A", size);
  3150. return size;
  3151. }
  3152. static int i85x_get_fifo_size(struct drm_device *dev, int plane)
  3153. {
  3154. struct drm_i915_private *dev_priv = dev->dev_private;
  3155. uint32_t dsparb = I915_READ(DSPARB);
  3156. int size;
  3157. size = dsparb & 0x1ff;
  3158. if (plane)
  3159. size = ((dsparb >> DSPARB_BEND_SHIFT) & 0x1ff) - size;
  3160. size >>= 1; /* Convert to cachelines */
  3161. DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb,
  3162. plane ? "B" : "A", size);
  3163. return size;
  3164. }
  3165. static int i845_get_fifo_size(struct drm_device *dev, int plane)
  3166. {
  3167. struct drm_i915_private *dev_priv = dev->dev_private;
  3168. uint32_t dsparb = I915_READ(DSPARB);
  3169. int size;
  3170. size = dsparb & 0x7f;
  3171. size >>= 2; /* Convert to cachelines */
  3172. DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb,
  3173. plane ? "B" : "A",
  3174. size);
  3175. return size;
  3176. }
  3177. static int i830_get_fifo_size(struct drm_device *dev, int plane)
  3178. {
  3179. struct drm_i915_private *dev_priv = dev->dev_private;
  3180. uint32_t dsparb = I915_READ(DSPARB);
  3181. int size;
  3182. size = dsparb & 0x7f;
  3183. size >>= 1; /* Convert to cachelines */
  3184. DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb,
  3185. plane ? "B" : "A", size);
  3186. return size;
  3187. }
  3188. static struct drm_crtc *single_enabled_crtc(struct drm_device *dev)
  3189. {
  3190. struct drm_crtc *crtc, *enabled = NULL;
  3191. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  3192. if (crtc->enabled && crtc->fb) {
  3193. if (enabled)
  3194. return NULL;
  3195. enabled = crtc;
  3196. }
  3197. }
  3198. return enabled;
  3199. }
  3200. static void pineview_update_wm(struct drm_device *dev)
  3201. {
  3202. struct drm_i915_private *dev_priv = dev->dev_private;
  3203. struct drm_crtc *crtc;
  3204. const struct cxsr_latency *latency;
  3205. u32 reg;
  3206. unsigned long wm;
  3207. latency = intel_get_cxsr_latency(IS_PINEVIEW_G(dev), dev_priv->is_ddr3,
  3208. dev_priv->fsb_freq, dev_priv->mem_freq);
  3209. if (!latency) {
  3210. DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n");
  3211. pineview_disable_cxsr(dev);
  3212. return;
  3213. }
  3214. crtc = single_enabled_crtc(dev);
  3215. if (crtc) {
  3216. int clock = crtc->mode.clock;
  3217. int pixel_size = crtc->fb->bits_per_pixel / 8;
  3218. /* Display SR */
  3219. wm = intel_calculate_wm(clock, &pineview_display_wm,
  3220. pineview_display_wm.fifo_size,
  3221. pixel_size, latency->display_sr);
  3222. reg = I915_READ(DSPFW1);
  3223. reg &= ~DSPFW_SR_MASK;
  3224. reg |= wm << DSPFW_SR_SHIFT;
  3225. I915_WRITE(DSPFW1, reg);
  3226. DRM_DEBUG_KMS("DSPFW1 register is %x\n", reg);
  3227. /* cursor SR */
  3228. wm = intel_calculate_wm(clock, &pineview_cursor_wm,
  3229. pineview_display_wm.fifo_size,
  3230. pixel_size, latency->cursor_sr);
  3231. reg = I915_READ(DSPFW3);
  3232. reg &= ~DSPFW_CURSOR_SR_MASK;
  3233. reg |= (wm & 0x3f) << DSPFW_CURSOR_SR_SHIFT;
  3234. I915_WRITE(DSPFW3, reg);
  3235. /* Display HPLL off SR */
  3236. wm = intel_calculate_wm(clock, &pineview_display_hplloff_wm,
  3237. pineview_display_hplloff_wm.fifo_size,
  3238. pixel_size, latency->display_hpll_disable);
  3239. reg = I915_READ(DSPFW3);
  3240. reg &= ~DSPFW_HPLL_SR_MASK;
  3241. reg |= wm & DSPFW_HPLL_SR_MASK;
  3242. I915_WRITE(DSPFW3, reg);
  3243. /* cursor HPLL off SR */
  3244. wm = intel_calculate_wm(clock, &pineview_cursor_hplloff_wm,
  3245. pineview_display_hplloff_wm.fifo_size,
  3246. pixel_size, latency->cursor_hpll_disable);
  3247. reg = I915_READ(DSPFW3);
  3248. reg &= ~DSPFW_HPLL_CURSOR_MASK;
  3249. reg |= (wm & 0x3f) << DSPFW_HPLL_CURSOR_SHIFT;
  3250. I915_WRITE(DSPFW3, reg);
  3251. DRM_DEBUG_KMS("DSPFW3 register is %x\n", reg);
  3252. /* activate cxsr */
  3253. I915_WRITE(DSPFW3,
  3254. I915_READ(DSPFW3) | PINEVIEW_SELF_REFRESH_EN);
  3255. DRM_DEBUG_KMS("Self-refresh is enabled\n");
  3256. } else {
  3257. pineview_disable_cxsr(dev);
  3258. DRM_DEBUG_KMS("Self-refresh is disabled\n");
  3259. }
  3260. }
  3261. static bool g4x_compute_wm0(struct drm_device *dev,
  3262. int plane,
  3263. const struct intel_watermark_params *display,
  3264. int display_latency_ns,
  3265. const struct intel_watermark_params *cursor,
  3266. int cursor_latency_ns,
  3267. int *plane_wm,
  3268. int *cursor_wm)
  3269. {
  3270. struct drm_crtc *crtc;
  3271. int htotal, hdisplay, clock, pixel_size;
  3272. int line_time_us, line_count;
  3273. int entries, tlb_miss;
  3274. crtc = intel_get_crtc_for_plane(dev, plane);
  3275. if (crtc->fb == NULL || !crtc->enabled)
  3276. return false;
  3277. htotal = crtc->mode.htotal;
  3278. hdisplay = crtc->mode.hdisplay;
  3279. clock = crtc->mode.clock;
  3280. pixel_size = crtc->fb->bits_per_pixel / 8;
  3281. /* Use the small buffer method to calculate plane watermark */
  3282. entries = ((clock * pixel_size / 1000) * display_latency_ns) / 1000;
  3283. tlb_miss = display->fifo_size*display->cacheline_size - hdisplay * 8;
  3284. if (tlb_miss > 0)
  3285. entries += tlb_miss;
  3286. entries = DIV_ROUND_UP(entries, display->cacheline_size);
  3287. *plane_wm = entries + display->guard_size;
  3288. if (*plane_wm > (int)display->max_wm)
  3289. *plane_wm = display->max_wm;
  3290. /* Use the large buffer method to calculate cursor watermark */
  3291. line_time_us = ((htotal * 1000) / clock);
  3292. line_count = (cursor_latency_ns / line_time_us + 1000) / 1000;
  3293. entries = line_count * 64 * pixel_size;
  3294. tlb_miss = cursor->fifo_size*cursor->cacheline_size - hdisplay * 8;
  3295. if (tlb_miss > 0)
  3296. entries += tlb_miss;
  3297. entries = DIV_ROUND_UP(entries, cursor->cacheline_size);
  3298. *cursor_wm = entries + cursor->guard_size;
  3299. if (*cursor_wm > (int)cursor->max_wm)
  3300. *cursor_wm = (int)cursor->max_wm;
  3301. return true;
  3302. }
  3303. /*
  3304. * Check the wm result.
  3305. *
  3306. * If any calculated watermark values is larger than the maximum value that
  3307. * can be programmed into the associated watermark register, that watermark
  3308. * must be disabled.
  3309. */
  3310. static bool g4x_check_srwm(struct drm_device *dev,
  3311. int display_wm, int cursor_wm,
  3312. const struct intel_watermark_params *display,
  3313. const struct intel_watermark_params *cursor)
  3314. {
  3315. DRM_DEBUG_KMS("SR watermark: display plane %d, cursor %d\n",
  3316. display_wm, cursor_wm);
  3317. if (display_wm > display->max_wm) {
  3318. DRM_DEBUG_KMS("display watermark is too large(%d), disabling\n",
  3319. display_wm, display->max_wm);
  3320. return false;
  3321. }
  3322. if (cursor_wm > cursor->max_wm) {
  3323. DRM_DEBUG_KMS("cursor watermark is too large(%d), disabling\n",
  3324. cursor_wm, cursor->max_wm);
  3325. return false;
  3326. }
  3327. if (!(display_wm || cursor_wm)) {
  3328. DRM_DEBUG_KMS("SR latency is 0, disabling\n");
  3329. return false;
  3330. }
  3331. return true;
  3332. }
  3333. static bool g4x_compute_srwm(struct drm_device *dev,
  3334. int plane,
  3335. int latency_ns,
  3336. const struct intel_watermark_params *display,
  3337. const struct intel_watermark_params *cursor,
  3338. int *display_wm, int *cursor_wm)
  3339. {
  3340. struct drm_crtc *crtc;
  3341. int hdisplay, htotal, pixel_size, clock;
  3342. unsigned long line_time_us;
  3343. int line_count, line_size;
  3344. int small, large;
  3345. int entries;
  3346. if (!latency_ns) {
  3347. *display_wm = *cursor_wm = 0;
  3348. return false;
  3349. }
  3350. crtc = intel_get_crtc_for_plane(dev, plane);
  3351. hdisplay = crtc->mode.hdisplay;
  3352. htotal = crtc->mode.htotal;
  3353. clock = crtc->mode.clock;
  3354. pixel_size = crtc->fb->bits_per_pixel / 8;
  3355. line_time_us = (htotal * 1000) / clock;
  3356. line_count = (latency_ns / line_time_us + 1000) / 1000;
  3357. line_size = hdisplay * pixel_size;
  3358. /* Use the minimum of the small and large buffer method for primary */
  3359. small = ((clock * pixel_size / 1000) * latency_ns) / 1000;
  3360. large = line_count * line_size;
  3361. entries = DIV_ROUND_UP(min(small, large), display->cacheline_size);
  3362. *display_wm = entries + display->guard_size;
  3363. /* calculate the self-refresh watermark for display cursor */
  3364. entries = line_count * pixel_size * 64;
  3365. entries = DIV_ROUND_UP(entries, cursor->cacheline_size);
  3366. *cursor_wm = entries + cursor->guard_size;
  3367. return g4x_check_srwm(dev,
  3368. *display_wm, *cursor_wm,
  3369. display, cursor);
  3370. }
  3371. static inline bool single_plane_enabled(unsigned int mask)
  3372. {
  3373. return mask && (mask & -mask) == 0;
  3374. }
  3375. static void g4x_update_wm(struct drm_device *dev)
  3376. {
  3377. static const int sr_latency_ns = 12000;
  3378. struct drm_i915_private *dev_priv = dev->dev_private;
  3379. int planea_wm, planeb_wm, cursora_wm, cursorb_wm;
  3380. int plane_sr, cursor_sr;
  3381. unsigned int enabled = 0;
  3382. if (g4x_compute_wm0(dev, 0,
  3383. &g4x_wm_info, latency_ns,
  3384. &g4x_cursor_wm_info, latency_ns,
  3385. &planea_wm, &cursora_wm))
  3386. enabled |= 1;
  3387. if (g4x_compute_wm0(dev, 1,
  3388. &g4x_wm_info, latency_ns,
  3389. &g4x_cursor_wm_info, latency_ns,
  3390. &planeb_wm, &cursorb_wm))
  3391. enabled |= 2;
  3392. plane_sr = cursor_sr = 0;
  3393. if (single_plane_enabled(enabled) &&
  3394. g4x_compute_srwm(dev, ffs(enabled) - 1,
  3395. sr_latency_ns,
  3396. &g4x_wm_info,
  3397. &g4x_cursor_wm_info,
  3398. &plane_sr, &cursor_sr))
  3399. I915_WRITE(FW_BLC_SELF, FW_BLC_SELF_EN);
  3400. else
  3401. I915_WRITE(FW_BLC_SELF,
  3402. I915_READ(FW_BLC_SELF) & ~FW_BLC_SELF_EN);
  3403. DRM_DEBUG_KMS("Setting FIFO watermarks - A: plane=%d, cursor=%d, B: plane=%d, cursor=%d, SR: plane=%d, cursor=%d\n",
  3404. planea_wm, cursora_wm,
  3405. planeb_wm, cursorb_wm,
  3406. plane_sr, cursor_sr);
  3407. I915_WRITE(DSPFW1,
  3408. (plane_sr << DSPFW_SR_SHIFT) |
  3409. (cursorb_wm << DSPFW_CURSORB_SHIFT) |
  3410. (planeb_wm << DSPFW_PLANEB_SHIFT) |
  3411. planea_wm);
  3412. I915_WRITE(DSPFW2,
  3413. (I915_READ(DSPFW2) & DSPFW_CURSORA_MASK) |
  3414. (cursora_wm << DSPFW_CURSORA_SHIFT));
  3415. /* HPLL off in SR has some issues on G4x... disable it */
  3416. I915_WRITE(DSPFW3,
  3417. (I915_READ(DSPFW3) & ~DSPFW_HPLL_SR_EN) |
  3418. (cursor_sr << DSPFW_CURSOR_SR_SHIFT));
  3419. }
  3420. static void i965_update_wm(struct drm_device *dev)
  3421. {
  3422. struct drm_i915_private *dev_priv = dev->dev_private;
  3423. struct drm_crtc *crtc;
  3424. int srwm = 1;
  3425. int cursor_sr = 16;
  3426. /* Calc sr entries for one plane configs */
  3427. crtc = single_enabled_crtc(dev);
  3428. if (crtc) {
  3429. /* self-refresh has much higher latency */
  3430. static const int sr_latency_ns = 12000;
  3431. int clock = crtc->mode.clock;
  3432. int htotal = crtc->mode.htotal;
  3433. int hdisplay = crtc->mode.hdisplay;
  3434. int pixel_size = crtc->fb->bits_per_pixel / 8;
  3435. unsigned long line_time_us;
  3436. int entries;
  3437. line_time_us = ((htotal * 1000) / clock);
  3438. /* Use ns/us then divide to preserve precision */
  3439. entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) *
  3440. pixel_size * hdisplay;
  3441. entries = DIV_ROUND_UP(entries, I915_FIFO_LINE_SIZE);
  3442. srwm = I965_FIFO_SIZE - entries;
  3443. if (srwm < 0)
  3444. srwm = 1;
  3445. srwm &= 0x1ff;
  3446. DRM_DEBUG_KMS("self-refresh entries: %d, wm: %d\n",
  3447. entries, srwm);
  3448. entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) *
  3449. pixel_size * 64;
  3450. entries = DIV_ROUND_UP(entries,
  3451. i965_cursor_wm_info.cacheline_size);
  3452. cursor_sr = i965_cursor_wm_info.fifo_size -
  3453. (entries + i965_cursor_wm_info.guard_size);
  3454. if (cursor_sr > i965_cursor_wm_info.max_wm)
  3455. cursor_sr = i965_cursor_wm_info.max_wm;
  3456. DRM_DEBUG_KMS("self-refresh watermark: display plane %d "
  3457. "cursor %d\n", srwm, cursor_sr);
  3458. if (IS_CRESTLINE(dev))
  3459. I915_WRITE(FW_BLC_SELF, FW_BLC_SELF_EN);
  3460. } else {
  3461. /* Turn off self refresh if both pipes are enabled */
  3462. if (IS_CRESTLINE(dev))
  3463. I915_WRITE(FW_BLC_SELF, I915_READ(FW_BLC_SELF)
  3464. & ~FW_BLC_SELF_EN);
  3465. }
  3466. DRM_DEBUG_KMS("Setting FIFO watermarks - A: 8, B: 8, C: 8, SR %d\n",
  3467. srwm);
  3468. /* 965 has limitations... */
  3469. I915_WRITE(DSPFW1, (srwm << DSPFW_SR_SHIFT) |
  3470. (8 << 16) | (8 << 8) | (8 << 0));
  3471. I915_WRITE(DSPFW2, (8 << 8) | (8 << 0));
  3472. /* update cursor SR watermark */
  3473. I915_WRITE(DSPFW3, (cursor_sr << DSPFW_CURSOR_SR_SHIFT));
  3474. }
  3475. static void i9xx_update_wm(struct drm_device *dev)
  3476. {
  3477. struct drm_i915_private *dev_priv = dev->dev_private;
  3478. const struct intel_watermark_params *wm_info;
  3479. uint32_t fwater_lo;
  3480. uint32_t fwater_hi;
  3481. int cwm, srwm = 1;
  3482. int fifo_size;
  3483. int planea_wm, planeb_wm;
  3484. struct drm_crtc *crtc, *enabled = NULL;
  3485. if (IS_I945GM(dev))
  3486. wm_info = &i945_wm_info;
  3487. else if (!IS_GEN2(dev))
  3488. wm_info = &i915_wm_info;
  3489. else
  3490. wm_info = &i855_wm_info;
  3491. fifo_size = dev_priv->display.get_fifo_size(dev, 0);
  3492. crtc = intel_get_crtc_for_plane(dev, 0);
  3493. if (crtc->enabled && crtc->fb) {
  3494. planea_wm = intel_calculate_wm(crtc->mode.clock,
  3495. wm_info, fifo_size,
  3496. crtc->fb->bits_per_pixel / 8,
  3497. latency_ns);
  3498. enabled = crtc;
  3499. } else
  3500. planea_wm = fifo_size - wm_info->guard_size;
  3501. fifo_size = dev_priv->display.get_fifo_size(dev, 1);
  3502. crtc = intel_get_crtc_for_plane(dev, 1);
  3503. if (crtc->enabled && crtc->fb) {
  3504. planeb_wm = intel_calculate_wm(crtc->mode.clock,
  3505. wm_info, fifo_size,
  3506. crtc->fb->bits_per_pixel / 8,
  3507. latency_ns);
  3508. if (enabled == NULL)
  3509. enabled = crtc;
  3510. else
  3511. enabled = NULL;
  3512. } else
  3513. planeb_wm = fifo_size - wm_info->guard_size;
  3514. DRM_DEBUG_KMS("FIFO watermarks - A: %d, B: %d\n", planea_wm, planeb_wm);
  3515. /*
  3516. * Overlay gets an aggressive default since video jitter is bad.
  3517. */
  3518. cwm = 2;
  3519. /* Play safe and disable self-refresh before adjusting watermarks. */
  3520. if (IS_I945G(dev) || IS_I945GM(dev))
  3521. I915_WRITE(FW_BLC_SELF, FW_BLC_SELF_EN_MASK | 0);
  3522. else if (IS_I915GM(dev))
  3523. I915_WRITE(INSTPM, I915_READ(INSTPM) & ~INSTPM_SELF_EN);
  3524. /* Calc sr entries for one plane configs */
  3525. if (HAS_FW_BLC(dev) && enabled) {
  3526. /* self-refresh has much higher latency */
  3527. static const int sr_latency_ns = 6000;
  3528. int clock = enabled->mode.clock;
  3529. int htotal = enabled->mode.htotal;
  3530. int hdisplay = enabled->mode.hdisplay;
  3531. int pixel_size = enabled->fb->bits_per_pixel / 8;
  3532. unsigned long line_time_us;
  3533. int entries;
  3534. line_time_us = (htotal * 1000) / clock;
  3535. /* Use ns/us then divide to preserve precision */
  3536. entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) *
  3537. pixel_size * hdisplay;
  3538. entries = DIV_ROUND_UP(entries, wm_info->cacheline_size);
  3539. DRM_DEBUG_KMS("self-refresh entries: %d\n", entries);
  3540. srwm = wm_info->fifo_size - entries;
  3541. if (srwm < 0)
  3542. srwm = 1;
  3543. if (IS_I945G(dev) || IS_I945GM(dev))
  3544. I915_WRITE(FW_BLC_SELF,
  3545. FW_BLC_SELF_FIFO_MASK | (srwm & 0xff));
  3546. else if (IS_I915GM(dev))
  3547. I915_WRITE(FW_BLC_SELF, srwm & 0x3f);
  3548. }
  3549. DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d, B: %d, C: %d, SR %d\n",
  3550. planea_wm, planeb_wm, cwm, srwm);
  3551. fwater_lo = ((planeb_wm & 0x3f) << 16) | (planea_wm & 0x3f);
  3552. fwater_hi = (cwm & 0x1f);
  3553. /* Set request length to 8 cachelines per fetch */
  3554. fwater_lo = fwater_lo | (1 << 24) | (1 << 8);
  3555. fwater_hi = fwater_hi | (1 << 8);
  3556. I915_WRITE(FW_BLC, fwater_lo);
  3557. I915_WRITE(FW_BLC2, fwater_hi);
  3558. if (HAS_FW_BLC(dev)) {
  3559. if (enabled) {
  3560. if (IS_I945G(dev) || IS_I945GM(dev))
  3561. I915_WRITE(FW_BLC_SELF,
  3562. FW_BLC_SELF_EN_MASK | FW_BLC_SELF_EN);
  3563. else if (IS_I915GM(dev))
  3564. I915_WRITE(INSTPM, I915_READ(INSTPM) | INSTPM_SELF_EN);
  3565. DRM_DEBUG_KMS("memory self refresh enabled\n");
  3566. } else
  3567. DRM_DEBUG_KMS("memory self refresh disabled\n");
  3568. }
  3569. }
  3570. static void i830_update_wm(struct drm_device *dev)
  3571. {
  3572. struct drm_i915_private *dev_priv = dev->dev_private;
  3573. struct drm_crtc *crtc;
  3574. uint32_t fwater_lo;
  3575. int planea_wm;
  3576. crtc = single_enabled_crtc(dev);
  3577. if (crtc == NULL)
  3578. return;
  3579. planea_wm = intel_calculate_wm(crtc->mode.clock, &i830_wm_info,
  3580. dev_priv->display.get_fifo_size(dev, 0),
  3581. crtc->fb->bits_per_pixel / 8,
  3582. latency_ns);
  3583. fwater_lo = I915_READ(FW_BLC) & ~0xfff;
  3584. fwater_lo |= (3<<8) | planea_wm;
  3585. DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d\n", planea_wm);
  3586. I915_WRITE(FW_BLC, fwater_lo);
  3587. }
  3588. #define ILK_LP0_PLANE_LATENCY 700
  3589. #define ILK_LP0_CURSOR_LATENCY 1300
  3590. static bool ironlake_compute_wm0(struct drm_device *dev,
  3591. int pipe,
  3592. const struct intel_watermark_params *display,
  3593. int display_latency_ns,
  3594. const struct intel_watermark_params *cursor,
  3595. int cursor_latency_ns,
  3596. int *plane_wm,
  3597. int *cursor_wm)
  3598. {
  3599. struct drm_crtc *crtc;
  3600. int htotal, hdisplay, clock, pixel_size;
  3601. int line_time_us, line_count;
  3602. int entries, tlb_miss;
  3603. crtc = intel_get_crtc_for_pipe(dev, pipe);
  3604. if (crtc->fb == NULL || !crtc->enabled)
  3605. return false;
  3606. htotal = crtc->mode.htotal;
  3607. hdisplay = crtc->mode.hdisplay;
  3608. clock = crtc->mode.clock;
  3609. pixel_size = crtc->fb->bits_per_pixel / 8;
  3610. /* Use the small buffer method to calculate plane watermark */
  3611. entries = ((clock * pixel_size / 1000) * display_latency_ns) / 1000;
  3612. tlb_miss = display->fifo_size*display->cacheline_size - hdisplay * 8;
  3613. if (tlb_miss > 0)
  3614. entries += tlb_miss;
  3615. entries = DIV_ROUND_UP(entries, display->cacheline_size);
  3616. *plane_wm = entries + display->guard_size;
  3617. if (*plane_wm > (int)display->max_wm)
  3618. *plane_wm = display->max_wm;
  3619. /* Use the large buffer method to calculate cursor watermark */
  3620. line_time_us = ((htotal * 1000) / clock);
  3621. line_count = (cursor_latency_ns / line_time_us + 1000) / 1000;
  3622. entries = line_count * 64 * pixel_size;
  3623. tlb_miss = cursor->fifo_size*cursor->cacheline_size - hdisplay * 8;
  3624. if (tlb_miss > 0)
  3625. entries += tlb_miss;
  3626. entries = DIV_ROUND_UP(entries, cursor->cacheline_size);
  3627. *cursor_wm = entries + cursor->guard_size;
  3628. if (*cursor_wm > (int)cursor->max_wm)
  3629. *cursor_wm = (int)cursor->max_wm;
  3630. return true;
  3631. }
  3632. /*
  3633. * Check the wm result.
  3634. *
  3635. * If any calculated watermark values is larger than the maximum value that
  3636. * can be programmed into the associated watermark register, that watermark
  3637. * must be disabled.
  3638. */
  3639. static bool ironlake_check_srwm(struct drm_device *dev, int level,
  3640. int fbc_wm, int display_wm, int cursor_wm,
  3641. const struct intel_watermark_params *display,
  3642. const struct intel_watermark_params *cursor)
  3643. {
  3644. struct drm_i915_private *dev_priv = dev->dev_private;
  3645. DRM_DEBUG_KMS("watermark %d: display plane %d, fbc lines %d,"
  3646. " cursor %d\n", level, display_wm, fbc_wm, cursor_wm);
  3647. if (fbc_wm > SNB_FBC_MAX_SRWM) {
  3648. DRM_DEBUG_KMS("fbc watermark(%d) is too large(%d), disabling wm%d+\n",
  3649. fbc_wm, SNB_FBC_MAX_SRWM, level);
  3650. /* fbc has it's own way to disable FBC WM */
  3651. I915_WRITE(DISP_ARB_CTL,
  3652. I915_READ(DISP_ARB_CTL) | DISP_FBC_WM_DIS);
  3653. return false;
  3654. }
  3655. if (display_wm > display->max_wm) {
  3656. DRM_DEBUG_KMS("display watermark(%d) is too large(%d), disabling wm%d+\n",
  3657. display_wm, SNB_DISPLAY_MAX_SRWM, level);
  3658. return false;
  3659. }
  3660. if (cursor_wm > cursor->max_wm) {
  3661. DRM_DEBUG_KMS("cursor watermark(%d) is too large(%d), disabling wm%d+\n",
  3662. cursor_wm, SNB_CURSOR_MAX_SRWM, level);
  3663. return false;
  3664. }
  3665. if (!(fbc_wm || display_wm || cursor_wm)) {
  3666. DRM_DEBUG_KMS("latency %d is 0, disabling wm%d+\n", level, level);
  3667. return false;
  3668. }
  3669. return true;
  3670. }
  3671. /*
  3672. * Compute watermark values of WM[1-3],
  3673. */
  3674. static bool ironlake_compute_srwm(struct drm_device *dev, int level, int plane,
  3675. int latency_ns,
  3676. const struct intel_watermark_params *display,
  3677. const struct intel_watermark_params *cursor,
  3678. int *fbc_wm, int *display_wm, int *cursor_wm)
  3679. {
  3680. struct drm_crtc *crtc;
  3681. unsigned long line_time_us;
  3682. int hdisplay, htotal, pixel_size, clock;
  3683. int line_count, line_size;
  3684. int small, large;
  3685. int entries;
  3686. if (!latency_ns) {
  3687. *fbc_wm = *display_wm = *cursor_wm = 0;
  3688. return false;
  3689. }
  3690. crtc = intel_get_crtc_for_plane(dev, plane);
  3691. hdisplay = crtc->mode.hdisplay;
  3692. htotal = crtc->mode.htotal;
  3693. clock = crtc->mode.clock;
  3694. pixel_size = crtc->fb->bits_per_pixel / 8;
  3695. line_time_us = (htotal * 1000) / clock;
  3696. line_count = (latency_ns / line_time_us + 1000) / 1000;
  3697. line_size = hdisplay * pixel_size;
  3698. /* Use the minimum of the small and large buffer method for primary */
  3699. small = ((clock * pixel_size / 1000) * latency_ns) / 1000;
  3700. large = line_count * line_size;
  3701. entries = DIV_ROUND_UP(min(small, large), display->cacheline_size);
  3702. *display_wm = entries + display->guard_size;
  3703. /*
  3704. * Spec says:
  3705. * FBC WM = ((Final Primary WM * 64) / number of bytes per line) + 2
  3706. */
  3707. *fbc_wm = DIV_ROUND_UP(*display_wm * 64, line_size) + 2;
  3708. /* calculate the self-refresh watermark for display cursor */
  3709. entries = line_count * pixel_size * 64;
  3710. entries = DIV_ROUND_UP(entries, cursor->cacheline_size);
  3711. *cursor_wm = entries + cursor->guard_size;
  3712. return ironlake_check_srwm(dev, level,
  3713. *fbc_wm, *display_wm, *cursor_wm,
  3714. display, cursor);
  3715. }
  3716. static void ironlake_update_wm(struct drm_device *dev)
  3717. {
  3718. struct drm_i915_private *dev_priv = dev->dev_private;
  3719. int fbc_wm, plane_wm, cursor_wm;
  3720. unsigned int enabled;
  3721. enabled = 0;
  3722. if (ironlake_compute_wm0(dev, 0,
  3723. &ironlake_display_wm_info,
  3724. ILK_LP0_PLANE_LATENCY,
  3725. &ironlake_cursor_wm_info,
  3726. ILK_LP0_CURSOR_LATENCY,
  3727. &plane_wm, &cursor_wm)) {
  3728. I915_WRITE(WM0_PIPEA_ILK,
  3729. (plane_wm << WM0_PIPE_PLANE_SHIFT) | cursor_wm);
  3730. DRM_DEBUG_KMS("FIFO watermarks For pipe A -"
  3731. " plane %d, " "cursor: %d\n",
  3732. plane_wm, cursor_wm);
  3733. enabled |= 1;
  3734. }
  3735. if (ironlake_compute_wm0(dev, 1,
  3736. &ironlake_display_wm_info,
  3737. ILK_LP0_PLANE_LATENCY,
  3738. &ironlake_cursor_wm_info,
  3739. ILK_LP0_CURSOR_LATENCY,
  3740. &plane_wm, &cursor_wm)) {
  3741. I915_WRITE(WM0_PIPEB_ILK,
  3742. (plane_wm << WM0_PIPE_PLANE_SHIFT) | cursor_wm);
  3743. DRM_DEBUG_KMS("FIFO watermarks For pipe B -"
  3744. " plane %d, cursor: %d\n",
  3745. plane_wm, cursor_wm);
  3746. enabled |= 2;
  3747. }
  3748. /*
  3749. * Calculate and update the self-refresh watermark only when one
  3750. * display plane is used.
  3751. */
  3752. I915_WRITE(WM3_LP_ILK, 0);
  3753. I915_WRITE(WM2_LP_ILK, 0);
  3754. I915_WRITE(WM1_LP_ILK, 0);
  3755. if (!single_plane_enabled(enabled))
  3756. return;
  3757. enabled = ffs(enabled) - 1;
  3758. /* WM1 */
  3759. if (!ironlake_compute_srwm(dev, 1, enabled,
  3760. ILK_READ_WM1_LATENCY() * 500,
  3761. &ironlake_display_srwm_info,
  3762. &ironlake_cursor_srwm_info,
  3763. &fbc_wm, &plane_wm, &cursor_wm))
  3764. return;
  3765. I915_WRITE(WM1_LP_ILK,
  3766. WM1_LP_SR_EN |
  3767. (ILK_READ_WM1_LATENCY() << WM1_LP_LATENCY_SHIFT) |
  3768. (fbc_wm << WM1_LP_FBC_SHIFT) |
  3769. (plane_wm << WM1_LP_SR_SHIFT) |
  3770. cursor_wm);
  3771. /* WM2 */
  3772. if (!ironlake_compute_srwm(dev, 2, enabled,
  3773. ILK_READ_WM2_LATENCY() * 500,
  3774. &ironlake_display_srwm_info,
  3775. &ironlake_cursor_srwm_info,
  3776. &fbc_wm, &plane_wm, &cursor_wm))
  3777. return;
  3778. I915_WRITE(WM2_LP_ILK,
  3779. WM2_LP_EN |
  3780. (ILK_READ_WM2_LATENCY() << WM1_LP_LATENCY_SHIFT) |
  3781. (fbc_wm << WM1_LP_FBC_SHIFT) |
  3782. (plane_wm << WM1_LP_SR_SHIFT) |
  3783. cursor_wm);
  3784. /*
  3785. * WM3 is unsupported on ILK, probably because we don't have latency
  3786. * data for that power state
  3787. */
  3788. }
  3789. static void sandybridge_update_wm(struct drm_device *dev)
  3790. {
  3791. struct drm_i915_private *dev_priv = dev->dev_private;
  3792. int latency = SNB_READ_WM0_LATENCY() * 100; /* In unit 0.1us */
  3793. int fbc_wm, plane_wm, cursor_wm;
  3794. unsigned int enabled;
  3795. enabled = 0;
  3796. if (ironlake_compute_wm0(dev, 0,
  3797. &sandybridge_display_wm_info, latency,
  3798. &sandybridge_cursor_wm_info, latency,
  3799. &plane_wm, &cursor_wm)) {
  3800. I915_WRITE(WM0_PIPEA_ILK,
  3801. (plane_wm << WM0_PIPE_PLANE_SHIFT) | cursor_wm);
  3802. DRM_DEBUG_KMS("FIFO watermarks For pipe A -"
  3803. " plane %d, " "cursor: %d\n",
  3804. plane_wm, cursor_wm);
  3805. enabled |= 1;
  3806. }
  3807. if (ironlake_compute_wm0(dev, 1,
  3808. &sandybridge_display_wm_info, latency,
  3809. &sandybridge_cursor_wm_info, latency,
  3810. &plane_wm, &cursor_wm)) {
  3811. I915_WRITE(WM0_PIPEB_ILK,
  3812. (plane_wm << WM0_PIPE_PLANE_SHIFT) | cursor_wm);
  3813. DRM_DEBUG_KMS("FIFO watermarks For pipe B -"
  3814. " plane %d, cursor: %d\n",
  3815. plane_wm, cursor_wm);
  3816. enabled |= 2;
  3817. }
  3818. /*
  3819. * Calculate and update the self-refresh watermark only when one
  3820. * display plane is used.
  3821. *
  3822. * SNB support 3 levels of watermark.
  3823. *
  3824. * WM1/WM2/WM2 watermarks have to be enabled in the ascending order,
  3825. * and disabled in the descending order
  3826. *
  3827. */
  3828. I915_WRITE(WM3_LP_ILK, 0);
  3829. I915_WRITE(WM2_LP_ILK, 0);
  3830. I915_WRITE(WM1_LP_ILK, 0);
  3831. if (!single_plane_enabled(enabled))
  3832. return;
  3833. enabled = ffs(enabled) - 1;
  3834. /* WM1 */
  3835. if (!ironlake_compute_srwm(dev, 1, enabled,
  3836. SNB_READ_WM1_LATENCY() * 500,
  3837. &sandybridge_display_srwm_info,
  3838. &sandybridge_cursor_srwm_info,
  3839. &fbc_wm, &plane_wm, &cursor_wm))
  3840. return;
  3841. I915_WRITE(WM1_LP_ILK,
  3842. WM1_LP_SR_EN |
  3843. (SNB_READ_WM1_LATENCY() << WM1_LP_LATENCY_SHIFT) |
  3844. (fbc_wm << WM1_LP_FBC_SHIFT) |
  3845. (plane_wm << WM1_LP_SR_SHIFT) |
  3846. cursor_wm);
  3847. /* WM2 */
  3848. if (!ironlake_compute_srwm(dev, 2, enabled,
  3849. SNB_READ_WM2_LATENCY() * 500,
  3850. &sandybridge_display_srwm_info,
  3851. &sandybridge_cursor_srwm_info,
  3852. &fbc_wm, &plane_wm, &cursor_wm))
  3853. return;
  3854. I915_WRITE(WM2_LP_ILK,
  3855. WM2_LP_EN |
  3856. (SNB_READ_WM2_LATENCY() << WM1_LP_LATENCY_SHIFT) |
  3857. (fbc_wm << WM1_LP_FBC_SHIFT) |
  3858. (plane_wm << WM1_LP_SR_SHIFT) |
  3859. cursor_wm);
  3860. /* WM3 */
  3861. if (!ironlake_compute_srwm(dev, 3, enabled,
  3862. SNB_READ_WM3_LATENCY() * 500,
  3863. &sandybridge_display_srwm_info,
  3864. &sandybridge_cursor_srwm_info,
  3865. &fbc_wm, &plane_wm, &cursor_wm))
  3866. return;
  3867. I915_WRITE(WM3_LP_ILK,
  3868. WM3_LP_EN |
  3869. (SNB_READ_WM3_LATENCY() << WM1_LP_LATENCY_SHIFT) |
  3870. (fbc_wm << WM1_LP_FBC_SHIFT) |
  3871. (plane_wm << WM1_LP_SR_SHIFT) |
  3872. cursor_wm);
  3873. }
  3874. /**
  3875. * intel_update_watermarks - update FIFO watermark values based on current modes
  3876. *
  3877. * Calculate watermark values for the various WM regs based on current mode
  3878. * and plane configuration.
  3879. *
  3880. * There are several cases to deal with here:
  3881. * - normal (i.e. non-self-refresh)
  3882. * - self-refresh (SR) mode
  3883. * - lines are large relative to FIFO size (buffer can hold up to 2)
  3884. * - lines are small relative to FIFO size (buffer can hold more than 2
  3885. * lines), so need to account for TLB latency
  3886. *
  3887. * The normal calculation is:
  3888. * watermark = dotclock * bytes per pixel * latency
  3889. * where latency is platform & configuration dependent (we assume pessimal
  3890. * values here).
  3891. *
  3892. * The SR calculation is:
  3893. * watermark = (trunc(latency/line time)+1) * surface width *
  3894. * bytes per pixel
  3895. * where
  3896. * line time = htotal / dotclock
  3897. * surface width = hdisplay for normal plane and 64 for cursor
  3898. * and latency is assumed to be high, as above.
  3899. *
  3900. * The final value programmed to the register should always be rounded up,
  3901. * and include an extra 2 entries to account for clock crossings.
  3902. *
  3903. * We don't use the sprite, so we can ignore that. And on Crestline we have
  3904. * to set the non-SR watermarks to 8.
  3905. */
  3906. static void intel_update_watermarks(struct drm_device *dev)
  3907. {
  3908. struct drm_i915_private *dev_priv = dev->dev_private;
  3909. if (dev_priv->display.update_wm)
  3910. dev_priv->display.update_wm(dev);
  3911. }
  3912. static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
  3913. {
  3914. return dev_priv->lvds_use_ssc && i915_panel_use_ssc;
  3915. }
  3916. static int intel_crtc_mode_set(struct drm_crtc *crtc,
  3917. struct drm_display_mode *mode,
  3918. struct drm_display_mode *adjusted_mode,
  3919. int x, int y,
  3920. struct drm_framebuffer *old_fb)
  3921. {
  3922. struct drm_device *dev = crtc->dev;
  3923. struct drm_i915_private *dev_priv = dev->dev_private;
  3924. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3925. int pipe = intel_crtc->pipe;
  3926. int plane = intel_crtc->plane;
  3927. u32 fp_reg, dpll_reg;
  3928. int refclk, num_connectors = 0;
  3929. intel_clock_t clock, reduced_clock;
  3930. u32 dpll, fp = 0, fp2 = 0, dspcntr, pipeconf;
  3931. bool ok, has_reduced_clock = false, is_sdvo = false, is_dvo = false;
  3932. bool is_crt = false, is_lvds = false, is_tv = false, is_dp = false;
  3933. struct intel_encoder *has_edp_encoder = NULL;
  3934. struct drm_mode_config *mode_config = &dev->mode_config;
  3935. struct intel_encoder *encoder;
  3936. const intel_limit_t *limit;
  3937. int ret;
  3938. struct fdi_m_n m_n = {0};
  3939. u32 reg, temp;
  3940. u32 lvds_sync = 0;
  3941. int target_clock;
  3942. drm_vblank_pre_modeset(dev, pipe);
  3943. list_for_each_entry(encoder, &mode_config->encoder_list, base.head) {
  3944. if (encoder->base.crtc != crtc)
  3945. continue;
  3946. switch (encoder->type) {
  3947. case INTEL_OUTPUT_LVDS:
  3948. is_lvds = true;
  3949. break;
  3950. case INTEL_OUTPUT_SDVO:
  3951. case INTEL_OUTPUT_HDMI:
  3952. is_sdvo = true;
  3953. if (encoder->needs_tv_clock)
  3954. is_tv = true;
  3955. break;
  3956. case INTEL_OUTPUT_DVO:
  3957. is_dvo = true;
  3958. break;
  3959. case INTEL_OUTPUT_TVOUT:
  3960. is_tv = true;
  3961. break;
  3962. case INTEL_OUTPUT_ANALOG:
  3963. is_crt = true;
  3964. break;
  3965. case INTEL_OUTPUT_DISPLAYPORT:
  3966. is_dp = true;
  3967. break;
  3968. case INTEL_OUTPUT_EDP:
  3969. has_edp_encoder = encoder;
  3970. break;
  3971. }
  3972. num_connectors++;
  3973. }
  3974. if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) {
  3975. refclk = dev_priv->lvds_ssc_freq * 1000;
  3976. DRM_DEBUG_KMS("using SSC reference clock of %d MHz\n",
  3977. refclk / 1000);
  3978. } else if (!IS_GEN2(dev)) {
  3979. refclk = 96000;
  3980. if (HAS_PCH_SPLIT(dev) &&
  3981. (!has_edp_encoder || intel_encoder_is_pch_edp(&has_edp_encoder->base)))
  3982. refclk = 120000; /* 120Mhz refclk */
  3983. } else {
  3984. refclk = 48000;
  3985. }
  3986. /*
  3987. * Returns a set of divisors for the desired target clock with the given
  3988. * refclk, or FALSE. The returned values represent the clock equation:
  3989. * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
  3990. */
  3991. limit = intel_limit(crtc, refclk);
  3992. ok = limit->find_pll(limit, crtc, adjusted_mode->clock, refclk, &clock);
  3993. if (!ok) {
  3994. DRM_ERROR("Couldn't find PLL settings for mode!\n");
  3995. drm_vblank_post_modeset(dev, pipe);
  3996. return -EINVAL;
  3997. }
  3998. /* Ensure that the cursor is valid for the new mode before changing... */
  3999. intel_crtc_update_cursor(crtc, true);
  4000. if (is_lvds && dev_priv->lvds_downclock_avail) {
  4001. has_reduced_clock = limit->find_pll(limit, crtc,
  4002. dev_priv->lvds_downclock,
  4003. refclk,
  4004. &reduced_clock);
  4005. if (has_reduced_clock && (clock.p != reduced_clock.p)) {
  4006. /*
  4007. * If the different P is found, it means that we can't
  4008. * switch the display clock by using the FP0/FP1.
  4009. * In such case we will disable the LVDS downclock
  4010. * feature.
  4011. */
  4012. DRM_DEBUG_KMS("Different P is found for "
  4013. "LVDS clock/downclock\n");
  4014. has_reduced_clock = 0;
  4015. }
  4016. }
  4017. /* SDVO TV has fixed PLL values depend on its clock range,
  4018. this mirrors vbios setting. */
  4019. if (is_sdvo && is_tv) {
  4020. if (adjusted_mode->clock >= 100000
  4021. && adjusted_mode->clock < 140500) {
  4022. clock.p1 = 2;
  4023. clock.p2 = 10;
  4024. clock.n = 3;
  4025. clock.m1 = 16;
  4026. clock.m2 = 8;
  4027. } else if (adjusted_mode->clock >= 140500
  4028. && adjusted_mode->clock <= 200000) {
  4029. clock.p1 = 1;
  4030. clock.p2 = 10;
  4031. clock.n = 6;
  4032. clock.m1 = 12;
  4033. clock.m2 = 8;
  4034. }
  4035. }
  4036. /* FDI link */
  4037. if (HAS_PCH_SPLIT(dev)) {
  4038. int pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode);
  4039. int lane = 0, link_bw, bpp;
  4040. /* CPU eDP doesn't require FDI link, so just set DP M/N
  4041. according to current link config */
  4042. if (has_edp_encoder && !intel_encoder_is_pch_edp(&has_edp_encoder->base)) {
  4043. target_clock = mode->clock;
  4044. intel_edp_link_config(has_edp_encoder,
  4045. &lane, &link_bw);
  4046. } else {
  4047. /* [e]DP over FDI requires target mode clock
  4048. instead of link clock */
  4049. if (is_dp || intel_encoder_is_pch_edp(&has_edp_encoder->base))
  4050. target_clock = mode->clock;
  4051. else
  4052. target_clock = adjusted_mode->clock;
  4053. /* FDI is a binary signal running at ~2.7GHz, encoding
  4054. * each output octet as 10 bits. The actual frequency
  4055. * is stored as a divider into a 100MHz clock, and the
  4056. * mode pixel clock is stored in units of 1KHz.
  4057. * Hence the bw of each lane in terms of the mode signal
  4058. * is:
  4059. */
  4060. link_bw = intel_fdi_link_freq(dev) * MHz(100)/KHz(1)/10;
  4061. }
  4062. /* determine panel color depth */
  4063. temp = I915_READ(PIPECONF(pipe));
  4064. temp &= ~PIPE_BPC_MASK;
  4065. if (is_lvds) {
  4066. /* the BPC will be 6 if it is 18-bit LVDS panel */
  4067. if ((I915_READ(PCH_LVDS) & LVDS_A3_POWER_MASK) == LVDS_A3_POWER_UP)
  4068. temp |= PIPE_8BPC;
  4069. else
  4070. temp |= PIPE_6BPC;
  4071. } else if (has_edp_encoder) {
  4072. switch (dev_priv->edp.bpp/3) {
  4073. case 8:
  4074. temp |= PIPE_8BPC;
  4075. break;
  4076. case 10:
  4077. temp |= PIPE_10BPC;
  4078. break;
  4079. case 6:
  4080. temp |= PIPE_6BPC;
  4081. break;
  4082. case 12:
  4083. temp |= PIPE_12BPC;
  4084. break;
  4085. }
  4086. } else
  4087. temp |= PIPE_8BPC;
  4088. I915_WRITE(PIPECONF(pipe), temp);
  4089. switch (temp & PIPE_BPC_MASK) {
  4090. case PIPE_8BPC:
  4091. bpp = 24;
  4092. break;
  4093. case PIPE_10BPC:
  4094. bpp = 30;
  4095. break;
  4096. case PIPE_6BPC:
  4097. bpp = 18;
  4098. break;
  4099. case PIPE_12BPC:
  4100. bpp = 36;
  4101. break;
  4102. default:
  4103. DRM_ERROR("unknown pipe bpc value\n");
  4104. bpp = 24;
  4105. }
  4106. if (!lane) {
  4107. /*
  4108. * Account for spread spectrum to avoid
  4109. * oversubscribing the link. Max center spread
  4110. * is 2.5%; use 5% for safety's sake.
  4111. */
  4112. u32 bps = target_clock * bpp * 21 / 20;
  4113. lane = bps / (link_bw * 8) + 1;
  4114. }
  4115. intel_crtc->fdi_lanes = lane;
  4116. if (pixel_multiplier > 1)
  4117. link_bw *= pixel_multiplier;
  4118. ironlake_compute_m_n(bpp, lane, target_clock, link_bw, &m_n);
  4119. }
  4120. /* Ironlake: try to setup display ref clock before DPLL
  4121. * enabling. This is only under driver's control after
  4122. * PCH B stepping, previous chipset stepping should be
  4123. * ignoring this setting.
  4124. */
  4125. if (HAS_PCH_SPLIT(dev)) {
  4126. temp = I915_READ(PCH_DREF_CONTROL);
  4127. /* Always enable nonspread source */
  4128. temp &= ~DREF_NONSPREAD_SOURCE_MASK;
  4129. temp |= DREF_NONSPREAD_SOURCE_ENABLE;
  4130. temp &= ~DREF_SSC_SOURCE_MASK;
  4131. temp |= DREF_SSC_SOURCE_ENABLE;
  4132. I915_WRITE(PCH_DREF_CONTROL, temp);
  4133. POSTING_READ(PCH_DREF_CONTROL);
  4134. udelay(200);
  4135. if (has_edp_encoder) {
  4136. if (intel_panel_use_ssc(dev_priv)) {
  4137. temp |= DREF_SSC1_ENABLE;
  4138. I915_WRITE(PCH_DREF_CONTROL, temp);
  4139. POSTING_READ(PCH_DREF_CONTROL);
  4140. udelay(200);
  4141. }
  4142. temp &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
  4143. /* Enable CPU source on CPU attached eDP */
  4144. if (!intel_encoder_is_pch_edp(&has_edp_encoder->base)) {
  4145. if (intel_panel_use_ssc(dev_priv))
  4146. temp |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
  4147. else
  4148. temp |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
  4149. } else {
  4150. /* Enable SSC on PCH eDP if needed */
  4151. if (intel_panel_use_ssc(dev_priv)) {
  4152. DRM_ERROR("enabling SSC on PCH\n");
  4153. temp |= DREF_SUPERSPREAD_SOURCE_ENABLE;
  4154. }
  4155. }
  4156. I915_WRITE(PCH_DREF_CONTROL, temp);
  4157. POSTING_READ(PCH_DREF_CONTROL);
  4158. udelay(200);
  4159. }
  4160. }
  4161. if (IS_PINEVIEW(dev)) {
  4162. fp = (1 << clock.n) << 16 | clock.m1 << 8 | clock.m2;
  4163. if (has_reduced_clock)
  4164. fp2 = (1 << reduced_clock.n) << 16 |
  4165. reduced_clock.m1 << 8 | reduced_clock.m2;
  4166. } else {
  4167. fp = clock.n << 16 | clock.m1 << 8 | clock.m2;
  4168. if (has_reduced_clock)
  4169. fp2 = reduced_clock.n << 16 | reduced_clock.m1 << 8 |
  4170. reduced_clock.m2;
  4171. }
  4172. /* Enable autotuning of the PLL clock (if permissible) */
  4173. if (HAS_PCH_SPLIT(dev)) {
  4174. int factor = 21;
  4175. if (is_lvds) {
  4176. if ((intel_panel_use_ssc(dev_priv) &&
  4177. dev_priv->lvds_ssc_freq == 100) ||
  4178. (I915_READ(PCH_LVDS) & LVDS_CLKB_POWER_MASK) == LVDS_CLKB_POWER_UP)
  4179. factor = 25;
  4180. } else if (is_sdvo && is_tv)
  4181. factor = 20;
  4182. if (clock.m1 < factor * clock.n)
  4183. fp |= FP_CB_TUNE;
  4184. }
  4185. dpll = 0;
  4186. if (!HAS_PCH_SPLIT(dev))
  4187. dpll = DPLL_VGA_MODE_DIS;
  4188. if (!IS_GEN2(dev)) {
  4189. if (is_lvds)
  4190. dpll |= DPLLB_MODE_LVDS;
  4191. else
  4192. dpll |= DPLLB_MODE_DAC_SERIAL;
  4193. if (is_sdvo) {
  4194. int pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode);
  4195. if (pixel_multiplier > 1) {
  4196. if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev))
  4197. dpll |= (pixel_multiplier - 1) << SDVO_MULTIPLIER_SHIFT_HIRES;
  4198. else if (HAS_PCH_SPLIT(dev))
  4199. dpll |= (pixel_multiplier - 1) << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
  4200. }
  4201. dpll |= DPLL_DVO_HIGH_SPEED;
  4202. }
  4203. if (is_dp || intel_encoder_is_pch_edp(&has_edp_encoder->base))
  4204. dpll |= DPLL_DVO_HIGH_SPEED;
  4205. /* compute bitmask from p1 value */
  4206. if (IS_PINEVIEW(dev))
  4207. dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
  4208. else {
  4209. dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  4210. /* also FPA1 */
  4211. if (HAS_PCH_SPLIT(dev))
  4212. dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
  4213. if (IS_G4X(dev) && has_reduced_clock)
  4214. dpll |= (1 << (reduced_clock.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
  4215. }
  4216. switch (clock.p2) {
  4217. case 5:
  4218. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
  4219. break;
  4220. case 7:
  4221. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
  4222. break;
  4223. case 10:
  4224. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
  4225. break;
  4226. case 14:
  4227. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
  4228. break;
  4229. }
  4230. if (INTEL_INFO(dev)->gen >= 4 && !HAS_PCH_SPLIT(dev))
  4231. dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
  4232. } else {
  4233. if (is_lvds) {
  4234. dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  4235. } else {
  4236. if (clock.p1 == 2)
  4237. dpll |= PLL_P1_DIVIDE_BY_TWO;
  4238. else
  4239. dpll |= (clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  4240. if (clock.p2 == 4)
  4241. dpll |= PLL_P2_DIVIDE_BY_4;
  4242. }
  4243. }
  4244. if (is_sdvo && is_tv)
  4245. dpll |= PLL_REF_INPUT_TVCLKINBC;
  4246. else if (is_tv)
  4247. /* XXX: just matching BIOS for now */
  4248. /* dpll |= PLL_REF_INPUT_TVCLKINBC; */
  4249. dpll |= 3;
  4250. else if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2)
  4251. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  4252. else
  4253. dpll |= PLL_REF_INPUT_DREFCLK;
  4254. /* setup pipeconf */
  4255. pipeconf = I915_READ(PIPECONF(pipe));
  4256. /* Set up the display plane register */
  4257. dspcntr = DISPPLANE_GAMMA_ENABLE;
  4258. /* Ironlake's plane is forced to pipe, bit 24 is to
  4259. enable color space conversion */
  4260. if (!HAS_PCH_SPLIT(dev)) {
  4261. if (pipe == 0)
  4262. dspcntr &= ~DISPPLANE_SEL_PIPE_MASK;
  4263. else
  4264. dspcntr |= DISPPLANE_SEL_PIPE_B;
  4265. }
  4266. if (pipe == 0 && INTEL_INFO(dev)->gen < 4) {
  4267. /* Enable pixel doubling when the dot clock is > 90% of the (display)
  4268. * core speed.
  4269. *
  4270. * XXX: No double-wide on 915GM pipe B. Is that the only reason for the
  4271. * pipe == 0 check?
  4272. */
  4273. if (mode->clock >
  4274. dev_priv->display.get_display_clock_speed(dev) * 9 / 10)
  4275. pipeconf |= PIPECONF_DOUBLE_WIDE;
  4276. else
  4277. pipeconf &= ~PIPECONF_DOUBLE_WIDE;
  4278. }
  4279. if (!HAS_PCH_SPLIT(dev))
  4280. dpll |= DPLL_VCO_ENABLE;
  4281. DRM_DEBUG_KMS("Mode for pipe %c:\n", pipe == 0 ? 'A' : 'B');
  4282. drm_mode_debug_printmodeline(mode);
  4283. /* assign to Ironlake registers */
  4284. if (HAS_PCH_SPLIT(dev)) {
  4285. fp_reg = PCH_FP0(pipe);
  4286. dpll_reg = PCH_DPLL(pipe);
  4287. } else {
  4288. fp_reg = FP0(pipe);
  4289. dpll_reg = DPLL(pipe);
  4290. }
  4291. /* PCH eDP needs FDI, but CPU eDP does not */
  4292. if (!has_edp_encoder || intel_encoder_is_pch_edp(&has_edp_encoder->base)) {
  4293. I915_WRITE(fp_reg, fp);
  4294. I915_WRITE(dpll_reg, dpll & ~DPLL_VCO_ENABLE);
  4295. POSTING_READ(dpll_reg);
  4296. udelay(150);
  4297. }
  4298. /* enable transcoder DPLL */
  4299. if (HAS_PCH_CPT(dev)) {
  4300. temp = I915_READ(PCH_DPLL_SEL);
  4301. switch (pipe) {
  4302. case 0:
  4303. temp |= TRANSA_DPLL_ENABLE | TRANSA_DPLLA_SEL;
  4304. break;
  4305. case 1:
  4306. temp |= TRANSB_DPLL_ENABLE | TRANSB_DPLLB_SEL;
  4307. break;
  4308. case 2:
  4309. /* FIXME: manage transcoder PLLs? */
  4310. temp |= TRANSC_DPLL_ENABLE | TRANSC_DPLLB_SEL;
  4311. break;
  4312. default:
  4313. BUG();
  4314. }
  4315. I915_WRITE(PCH_DPLL_SEL, temp);
  4316. POSTING_READ(PCH_DPLL_SEL);
  4317. udelay(150);
  4318. }
  4319. /* The LVDS pin pair needs to be on before the DPLLs are enabled.
  4320. * This is an exception to the general rule that mode_set doesn't turn
  4321. * things on.
  4322. */
  4323. if (is_lvds) {
  4324. reg = LVDS;
  4325. if (HAS_PCH_SPLIT(dev))
  4326. reg = PCH_LVDS;
  4327. temp = I915_READ(reg);
  4328. temp |= LVDS_PORT_EN | LVDS_A0A2_CLKA_POWER_UP;
  4329. if (pipe == 1) {
  4330. if (HAS_PCH_CPT(dev))
  4331. temp |= PORT_TRANS_B_SEL_CPT;
  4332. else
  4333. temp |= LVDS_PIPEB_SELECT;
  4334. } else {
  4335. if (HAS_PCH_CPT(dev))
  4336. temp &= ~PORT_TRANS_SEL_MASK;
  4337. else
  4338. temp &= ~LVDS_PIPEB_SELECT;
  4339. }
  4340. /* set the corresponsding LVDS_BORDER bit */
  4341. temp |= dev_priv->lvds_border_bits;
  4342. /* Set the B0-B3 data pairs corresponding to whether we're going to
  4343. * set the DPLLs for dual-channel mode or not.
  4344. */
  4345. if (clock.p2 == 7)
  4346. temp |= LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP;
  4347. else
  4348. temp &= ~(LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP);
  4349. /* It would be nice to set 24 vs 18-bit mode (LVDS_A3_POWER_UP)
  4350. * appropriately here, but we need to look more thoroughly into how
  4351. * panels behave in the two modes.
  4352. */
  4353. /* set the dithering flag on non-PCH LVDS as needed */
  4354. if (INTEL_INFO(dev)->gen >= 4 && !HAS_PCH_SPLIT(dev)) {
  4355. if (dev_priv->lvds_dither)
  4356. temp |= LVDS_ENABLE_DITHER;
  4357. else
  4358. temp &= ~LVDS_ENABLE_DITHER;
  4359. }
  4360. if (adjusted_mode->flags & DRM_MODE_FLAG_NHSYNC)
  4361. lvds_sync |= LVDS_HSYNC_POLARITY;
  4362. if (adjusted_mode->flags & DRM_MODE_FLAG_NVSYNC)
  4363. lvds_sync |= LVDS_VSYNC_POLARITY;
  4364. if ((temp & (LVDS_HSYNC_POLARITY | LVDS_VSYNC_POLARITY))
  4365. != lvds_sync) {
  4366. char flags[2] = "-+";
  4367. DRM_INFO("Changing LVDS panel from "
  4368. "(%chsync, %cvsync) to (%chsync, %cvsync)\n",
  4369. flags[!(temp & LVDS_HSYNC_POLARITY)],
  4370. flags[!(temp & LVDS_VSYNC_POLARITY)],
  4371. flags[!(lvds_sync & LVDS_HSYNC_POLARITY)],
  4372. flags[!(lvds_sync & LVDS_VSYNC_POLARITY)]);
  4373. temp &= ~(LVDS_HSYNC_POLARITY | LVDS_VSYNC_POLARITY);
  4374. temp |= lvds_sync;
  4375. }
  4376. I915_WRITE(reg, temp);
  4377. }
  4378. /* set the dithering flag and clear for anything other than a panel. */
  4379. if (HAS_PCH_SPLIT(dev)) {
  4380. pipeconf &= ~PIPECONF_DITHER_EN;
  4381. pipeconf &= ~PIPECONF_DITHER_TYPE_MASK;
  4382. if (dev_priv->lvds_dither && (is_lvds || has_edp_encoder)) {
  4383. pipeconf |= PIPECONF_DITHER_EN;
  4384. pipeconf |= PIPECONF_DITHER_TYPE_ST1;
  4385. }
  4386. }
  4387. if (is_dp || intel_encoder_is_pch_edp(&has_edp_encoder->base)) {
  4388. intel_dp_set_m_n(crtc, mode, adjusted_mode);
  4389. } else if (HAS_PCH_SPLIT(dev)) {
  4390. /* For non-DP output, clear any trans DP clock recovery setting.*/
  4391. I915_WRITE(TRANSDATA_M1(pipe), 0);
  4392. I915_WRITE(TRANSDATA_N1(pipe), 0);
  4393. I915_WRITE(TRANSDPLINK_M1(pipe), 0);
  4394. I915_WRITE(TRANSDPLINK_N1(pipe), 0);
  4395. }
  4396. if (!has_edp_encoder || intel_encoder_is_pch_edp(&has_edp_encoder->base)) {
  4397. I915_WRITE(dpll_reg, dpll);
  4398. /* Wait for the clocks to stabilize. */
  4399. POSTING_READ(dpll_reg);
  4400. udelay(150);
  4401. if (INTEL_INFO(dev)->gen >= 4 && !HAS_PCH_SPLIT(dev)) {
  4402. temp = 0;
  4403. if (is_sdvo) {
  4404. temp = intel_mode_get_pixel_multiplier(adjusted_mode);
  4405. if (temp > 1)
  4406. temp = (temp - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
  4407. else
  4408. temp = 0;
  4409. }
  4410. I915_WRITE(DPLL_MD(pipe), temp);
  4411. } else {
  4412. /* The pixel multiplier can only be updated once the
  4413. * DPLL is enabled and the clocks are stable.
  4414. *
  4415. * So write it again.
  4416. */
  4417. I915_WRITE(dpll_reg, dpll);
  4418. }
  4419. }
  4420. intel_crtc->lowfreq_avail = false;
  4421. if (is_lvds && has_reduced_clock && i915_powersave) {
  4422. I915_WRITE(fp_reg + 4, fp2);
  4423. intel_crtc->lowfreq_avail = true;
  4424. if (HAS_PIPE_CXSR(dev)) {
  4425. DRM_DEBUG_KMS("enabling CxSR downclocking\n");
  4426. pipeconf |= PIPECONF_CXSR_DOWNCLOCK;
  4427. }
  4428. } else {
  4429. I915_WRITE(fp_reg + 4, fp);
  4430. if (HAS_PIPE_CXSR(dev)) {
  4431. DRM_DEBUG_KMS("disabling CxSR downclocking\n");
  4432. pipeconf &= ~PIPECONF_CXSR_DOWNCLOCK;
  4433. }
  4434. }
  4435. if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
  4436. pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
  4437. /* the chip adds 2 halflines automatically */
  4438. adjusted_mode->crtc_vdisplay -= 1;
  4439. adjusted_mode->crtc_vtotal -= 1;
  4440. adjusted_mode->crtc_vblank_start -= 1;
  4441. adjusted_mode->crtc_vblank_end -= 1;
  4442. adjusted_mode->crtc_vsync_end -= 1;
  4443. adjusted_mode->crtc_vsync_start -= 1;
  4444. } else
  4445. pipeconf &= ~PIPECONF_INTERLACE_W_FIELD_INDICATION; /* progressive */
  4446. I915_WRITE(HTOTAL(pipe),
  4447. (adjusted_mode->crtc_hdisplay - 1) |
  4448. ((adjusted_mode->crtc_htotal - 1) << 16));
  4449. I915_WRITE(HBLANK(pipe),
  4450. (adjusted_mode->crtc_hblank_start - 1) |
  4451. ((adjusted_mode->crtc_hblank_end - 1) << 16));
  4452. I915_WRITE(HSYNC(pipe),
  4453. (adjusted_mode->crtc_hsync_start - 1) |
  4454. ((adjusted_mode->crtc_hsync_end - 1) << 16));
  4455. I915_WRITE(VTOTAL(pipe),
  4456. (adjusted_mode->crtc_vdisplay - 1) |
  4457. ((adjusted_mode->crtc_vtotal - 1) << 16));
  4458. I915_WRITE(VBLANK(pipe),
  4459. (adjusted_mode->crtc_vblank_start - 1) |
  4460. ((adjusted_mode->crtc_vblank_end - 1) << 16));
  4461. I915_WRITE(VSYNC(pipe),
  4462. (adjusted_mode->crtc_vsync_start - 1) |
  4463. ((adjusted_mode->crtc_vsync_end - 1) << 16));
  4464. /* pipesrc and dspsize control the size that is scaled from,
  4465. * which should always be the user's requested size.
  4466. */
  4467. if (!HAS_PCH_SPLIT(dev)) {
  4468. I915_WRITE(DSPSIZE(plane),
  4469. ((mode->vdisplay - 1) << 16) |
  4470. (mode->hdisplay - 1));
  4471. I915_WRITE(DSPPOS(plane), 0);
  4472. }
  4473. I915_WRITE(PIPESRC(pipe),
  4474. ((mode->hdisplay - 1) << 16) | (mode->vdisplay - 1));
  4475. if (HAS_PCH_SPLIT(dev)) {
  4476. I915_WRITE(PIPE_DATA_M1(pipe), TU_SIZE(m_n.tu) | m_n.gmch_m);
  4477. I915_WRITE(PIPE_DATA_N1(pipe), m_n.gmch_n);
  4478. I915_WRITE(PIPE_LINK_M1(pipe), m_n.link_m);
  4479. I915_WRITE(PIPE_LINK_N1(pipe), m_n.link_n);
  4480. if (has_edp_encoder && !intel_encoder_is_pch_edp(&has_edp_encoder->base)) {
  4481. ironlake_set_pll_edp(crtc, adjusted_mode->clock);
  4482. }
  4483. }
  4484. I915_WRITE(PIPECONF(pipe), pipeconf);
  4485. POSTING_READ(PIPECONF(pipe));
  4486. if (!HAS_PCH_SPLIT(dev))
  4487. intel_enable_pipe(dev_priv, pipe, false);
  4488. intel_wait_for_vblank(dev, pipe);
  4489. if (IS_GEN5(dev)) {
  4490. /* enable address swizzle for tiling buffer */
  4491. temp = I915_READ(DISP_ARB_CTL);
  4492. I915_WRITE(DISP_ARB_CTL, temp | DISP_TILE_SURFACE_SWIZZLING);
  4493. }
  4494. I915_WRITE(DSPCNTR(plane), dspcntr);
  4495. POSTING_READ(DSPCNTR(plane));
  4496. if (!HAS_PCH_SPLIT(dev))
  4497. intel_enable_plane(dev_priv, plane, pipe);
  4498. ret = intel_pipe_set_base(crtc, x, y, old_fb);
  4499. intel_update_watermarks(dev);
  4500. drm_vblank_post_modeset(dev, pipe);
  4501. return ret;
  4502. }
  4503. /** Loads the palette/gamma unit for the CRTC with the prepared values */
  4504. void intel_crtc_load_lut(struct drm_crtc *crtc)
  4505. {
  4506. struct drm_device *dev = crtc->dev;
  4507. struct drm_i915_private *dev_priv = dev->dev_private;
  4508. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4509. int palreg = PALETTE(intel_crtc->pipe);
  4510. int i;
  4511. /* The clocks have to be on to load the palette. */
  4512. if (!crtc->enabled)
  4513. return;
  4514. /* use legacy palette for Ironlake */
  4515. if (HAS_PCH_SPLIT(dev))
  4516. palreg = LGC_PALETTE(intel_crtc->pipe);
  4517. for (i = 0; i < 256; i++) {
  4518. I915_WRITE(palreg + 4 * i,
  4519. (intel_crtc->lut_r[i] << 16) |
  4520. (intel_crtc->lut_g[i] << 8) |
  4521. intel_crtc->lut_b[i]);
  4522. }
  4523. }
  4524. static void i845_update_cursor(struct drm_crtc *crtc, u32 base)
  4525. {
  4526. struct drm_device *dev = crtc->dev;
  4527. struct drm_i915_private *dev_priv = dev->dev_private;
  4528. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4529. bool visible = base != 0;
  4530. u32 cntl;
  4531. if (intel_crtc->cursor_visible == visible)
  4532. return;
  4533. cntl = I915_READ(_CURACNTR);
  4534. if (visible) {
  4535. /* On these chipsets we can only modify the base whilst
  4536. * the cursor is disabled.
  4537. */
  4538. I915_WRITE(_CURABASE, base);
  4539. cntl &= ~(CURSOR_FORMAT_MASK);
  4540. /* XXX width must be 64, stride 256 => 0x00 << 28 */
  4541. cntl |= CURSOR_ENABLE |
  4542. CURSOR_GAMMA_ENABLE |
  4543. CURSOR_FORMAT_ARGB;
  4544. } else
  4545. cntl &= ~(CURSOR_ENABLE | CURSOR_GAMMA_ENABLE);
  4546. I915_WRITE(_CURACNTR, cntl);
  4547. intel_crtc->cursor_visible = visible;
  4548. }
  4549. static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base)
  4550. {
  4551. struct drm_device *dev = crtc->dev;
  4552. struct drm_i915_private *dev_priv = dev->dev_private;
  4553. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4554. int pipe = intel_crtc->pipe;
  4555. bool visible = base != 0;
  4556. if (intel_crtc->cursor_visible != visible) {
  4557. uint32_t cntl = I915_READ(CURCNTR(pipe));
  4558. if (base) {
  4559. cntl &= ~(CURSOR_MODE | MCURSOR_PIPE_SELECT);
  4560. cntl |= CURSOR_MODE_64_ARGB_AX | MCURSOR_GAMMA_ENABLE;
  4561. cntl |= pipe << 28; /* Connect to correct pipe */
  4562. } else {
  4563. cntl &= ~(CURSOR_MODE | MCURSOR_GAMMA_ENABLE);
  4564. cntl |= CURSOR_MODE_DISABLE;
  4565. }
  4566. I915_WRITE(CURCNTR(pipe), cntl);
  4567. intel_crtc->cursor_visible = visible;
  4568. }
  4569. /* and commit changes on next vblank */
  4570. I915_WRITE(CURBASE(pipe), base);
  4571. }
  4572. /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */
  4573. static void intel_crtc_update_cursor(struct drm_crtc *crtc,
  4574. bool on)
  4575. {
  4576. struct drm_device *dev = crtc->dev;
  4577. struct drm_i915_private *dev_priv = dev->dev_private;
  4578. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4579. int pipe = intel_crtc->pipe;
  4580. int x = intel_crtc->cursor_x;
  4581. int y = intel_crtc->cursor_y;
  4582. u32 base, pos;
  4583. bool visible;
  4584. pos = 0;
  4585. if (on && crtc->enabled && crtc->fb) {
  4586. base = intel_crtc->cursor_addr;
  4587. if (x > (int) crtc->fb->width)
  4588. base = 0;
  4589. if (y > (int) crtc->fb->height)
  4590. base = 0;
  4591. } else
  4592. base = 0;
  4593. if (x < 0) {
  4594. if (x + intel_crtc->cursor_width < 0)
  4595. base = 0;
  4596. pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
  4597. x = -x;
  4598. }
  4599. pos |= x << CURSOR_X_SHIFT;
  4600. if (y < 0) {
  4601. if (y + intel_crtc->cursor_height < 0)
  4602. base = 0;
  4603. pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
  4604. y = -y;
  4605. }
  4606. pos |= y << CURSOR_Y_SHIFT;
  4607. visible = base != 0;
  4608. if (!visible && !intel_crtc->cursor_visible)
  4609. return;
  4610. I915_WRITE(CURPOS(pipe), pos);
  4611. if (IS_845G(dev) || IS_I865G(dev))
  4612. i845_update_cursor(crtc, base);
  4613. else
  4614. i9xx_update_cursor(crtc, base);
  4615. if (visible)
  4616. intel_mark_busy(dev, to_intel_framebuffer(crtc->fb)->obj);
  4617. }
  4618. static int intel_crtc_cursor_set(struct drm_crtc *crtc,
  4619. struct drm_file *file,
  4620. uint32_t handle,
  4621. uint32_t width, uint32_t height)
  4622. {
  4623. struct drm_device *dev = crtc->dev;
  4624. struct drm_i915_private *dev_priv = dev->dev_private;
  4625. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4626. struct drm_i915_gem_object *obj;
  4627. uint32_t addr;
  4628. int ret;
  4629. DRM_DEBUG_KMS("\n");
  4630. /* if we want to turn off the cursor ignore width and height */
  4631. if (!handle) {
  4632. DRM_DEBUG_KMS("cursor off\n");
  4633. addr = 0;
  4634. obj = NULL;
  4635. mutex_lock(&dev->struct_mutex);
  4636. goto finish;
  4637. }
  4638. /* Currently we only support 64x64 cursors */
  4639. if (width != 64 || height != 64) {
  4640. DRM_ERROR("we currently only support 64x64 cursors\n");
  4641. return -EINVAL;
  4642. }
  4643. obj = to_intel_bo(drm_gem_object_lookup(dev, file, handle));
  4644. if (!obj)
  4645. return -ENOENT;
  4646. if (obj->base.size < width * height * 4) {
  4647. DRM_ERROR("buffer is to small\n");
  4648. ret = -ENOMEM;
  4649. goto fail;
  4650. }
  4651. /* we only need to pin inside GTT if cursor is non-phy */
  4652. mutex_lock(&dev->struct_mutex);
  4653. if (!dev_priv->info->cursor_needs_physical) {
  4654. if (obj->tiling_mode) {
  4655. DRM_ERROR("cursor cannot be tiled\n");
  4656. ret = -EINVAL;
  4657. goto fail_locked;
  4658. }
  4659. ret = i915_gem_object_pin(obj, PAGE_SIZE, true);
  4660. if (ret) {
  4661. DRM_ERROR("failed to pin cursor bo\n");
  4662. goto fail_locked;
  4663. }
  4664. ret = i915_gem_object_set_to_gtt_domain(obj, 0);
  4665. if (ret) {
  4666. DRM_ERROR("failed to move cursor bo into the GTT\n");
  4667. goto fail_unpin;
  4668. }
  4669. ret = i915_gem_object_put_fence(obj);
  4670. if (ret) {
  4671. DRM_ERROR("failed to move cursor bo into the GTT\n");
  4672. goto fail_unpin;
  4673. }
  4674. addr = obj->gtt_offset;
  4675. } else {
  4676. int align = IS_I830(dev) ? 16 * 1024 : 256;
  4677. ret = i915_gem_attach_phys_object(dev, obj,
  4678. (intel_crtc->pipe == 0) ? I915_GEM_PHYS_CURSOR_0 : I915_GEM_PHYS_CURSOR_1,
  4679. align);
  4680. if (ret) {
  4681. DRM_ERROR("failed to attach phys object\n");
  4682. goto fail_locked;
  4683. }
  4684. addr = obj->phys_obj->handle->busaddr;
  4685. }
  4686. if (IS_GEN2(dev))
  4687. I915_WRITE(CURSIZE, (height << 12) | width);
  4688. finish:
  4689. if (intel_crtc->cursor_bo) {
  4690. if (dev_priv->info->cursor_needs_physical) {
  4691. if (intel_crtc->cursor_bo != obj)
  4692. i915_gem_detach_phys_object(dev, intel_crtc->cursor_bo);
  4693. } else
  4694. i915_gem_object_unpin(intel_crtc->cursor_bo);
  4695. drm_gem_object_unreference(&intel_crtc->cursor_bo->base);
  4696. }
  4697. mutex_unlock(&dev->struct_mutex);
  4698. intel_crtc->cursor_addr = addr;
  4699. intel_crtc->cursor_bo = obj;
  4700. intel_crtc->cursor_width = width;
  4701. intel_crtc->cursor_height = height;
  4702. intel_crtc_update_cursor(crtc, true);
  4703. return 0;
  4704. fail_unpin:
  4705. i915_gem_object_unpin(obj);
  4706. fail_locked:
  4707. mutex_unlock(&dev->struct_mutex);
  4708. fail:
  4709. drm_gem_object_unreference_unlocked(&obj->base);
  4710. return ret;
  4711. }
  4712. static int intel_crtc_cursor_move(struct drm_crtc *crtc, int x, int y)
  4713. {
  4714. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4715. intel_crtc->cursor_x = x;
  4716. intel_crtc->cursor_y = y;
  4717. intel_crtc_update_cursor(crtc, true);
  4718. return 0;
  4719. }
  4720. /** Sets the color ramps on behalf of RandR */
  4721. void intel_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green,
  4722. u16 blue, int regno)
  4723. {
  4724. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4725. intel_crtc->lut_r[regno] = red >> 8;
  4726. intel_crtc->lut_g[regno] = green >> 8;
  4727. intel_crtc->lut_b[regno] = blue >> 8;
  4728. }
  4729. void intel_crtc_fb_gamma_get(struct drm_crtc *crtc, u16 *red, u16 *green,
  4730. u16 *blue, int regno)
  4731. {
  4732. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4733. *red = intel_crtc->lut_r[regno] << 8;
  4734. *green = intel_crtc->lut_g[regno] << 8;
  4735. *blue = intel_crtc->lut_b[regno] << 8;
  4736. }
  4737. static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
  4738. u16 *blue, uint32_t start, uint32_t size)
  4739. {
  4740. int end = (start + size > 256) ? 256 : start + size, i;
  4741. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4742. for (i = start; i < end; i++) {
  4743. intel_crtc->lut_r[i] = red[i] >> 8;
  4744. intel_crtc->lut_g[i] = green[i] >> 8;
  4745. intel_crtc->lut_b[i] = blue[i] >> 8;
  4746. }
  4747. intel_crtc_load_lut(crtc);
  4748. }
  4749. /**
  4750. * Get a pipe with a simple mode set on it for doing load-based monitor
  4751. * detection.
  4752. *
  4753. * It will be up to the load-detect code to adjust the pipe as appropriate for
  4754. * its requirements. The pipe will be connected to no other encoders.
  4755. *
  4756. * Currently this code will only succeed if there is a pipe with no encoders
  4757. * configured for it. In the future, it could choose to temporarily disable
  4758. * some outputs to free up a pipe for its use.
  4759. *
  4760. * \return crtc, or NULL if no pipes are available.
  4761. */
  4762. /* VESA 640x480x72Hz mode to set on the pipe */
  4763. static struct drm_display_mode load_detect_mode = {
  4764. DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
  4765. 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  4766. };
  4767. struct drm_crtc *intel_get_load_detect_pipe(struct intel_encoder *intel_encoder,
  4768. struct drm_connector *connector,
  4769. struct drm_display_mode *mode,
  4770. int *dpms_mode)
  4771. {
  4772. struct intel_crtc *intel_crtc;
  4773. struct drm_crtc *possible_crtc;
  4774. struct drm_crtc *supported_crtc =NULL;
  4775. struct drm_encoder *encoder = &intel_encoder->base;
  4776. struct drm_crtc *crtc = NULL;
  4777. struct drm_device *dev = encoder->dev;
  4778. struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
  4779. struct drm_crtc_helper_funcs *crtc_funcs;
  4780. int i = -1;
  4781. /*
  4782. * Algorithm gets a little messy:
  4783. * - if the connector already has an assigned crtc, use it (but make
  4784. * sure it's on first)
  4785. * - try to find the first unused crtc that can drive this connector,
  4786. * and use that if we find one
  4787. * - if there are no unused crtcs available, try to use the first
  4788. * one we found that supports the connector
  4789. */
  4790. /* See if we already have a CRTC for this connector */
  4791. if (encoder->crtc) {
  4792. crtc = encoder->crtc;
  4793. /* Make sure the crtc and connector are running */
  4794. intel_crtc = to_intel_crtc(crtc);
  4795. *dpms_mode = intel_crtc->dpms_mode;
  4796. if (intel_crtc->dpms_mode != DRM_MODE_DPMS_ON) {
  4797. crtc_funcs = crtc->helper_private;
  4798. crtc_funcs->dpms(crtc, DRM_MODE_DPMS_ON);
  4799. encoder_funcs->dpms(encoder, DRM_MODE_DPMS_ON);
  4800. }
  4801. return crtc;
  4802. }
  4803. /* Find an unused one (if possible) */
  4804. list_for_each_entry(possible_crtc, &dev->mode_config.crtc_list, head) {
  4805. i++;
  4806. if (!(encoder->possible_crtcs & (1 << i)))
  4807. continue;
  4808. if (!possible_crtc->enabled) {
  4809. crtc = possible_crtc;
  4810. break;
  4811. }
  4812. if (!supported_crtc)
  4813. supported_crtc = possible_crtc;
  4814. }
  4815. /*
  4816. * If we didn't find an unused CRTC, don't use any.
  4817. */
  4818. if (!crtc) {
  4819. return NULL;
  4820. }
  4821. encoder->crtc = crtc;
  4822. connector->encoder = encoder;
  4823. intel_encoder->load_detect_temp = true;
  4824. intel_crtc = to_intel_crtc(crtc);
  4825. *dpms_mode = intel_crtc->dpms_mode;
  4826. if (!crtc->enabled) {
  4827. if (!mode)
  4828. mode = &load_detect_mode;
  4829. drm_crtc_helper_set_mode(crtc, mode, 0, 0, crtc->fb);
  4830. } else {
  4831. if (intel_crtc->dpms_mode != DRM_MODE_DPMS_ON) {
  4832. crtc_funcs = crtc->helper_private;
  4833. crtc_funcs->dpms(crtc, DRM_MODE_DPMS_ON);
  4834. }
  4835. /* Add this connector to the crtc */
  4836. encoder_funcs->mode_set(encoder, &crtc->mode, &crtc->mode);
  4837. encoder_funcs->commit(encoder);
  4838. }
  4839. /* let the connector get through one full cycle before testing */
  4840. intel_wait_for_vblank(dev, intel_crtc->pipe);
  4841. return crtc;
  4842. }
  4843. void intel_release_load_detect_pipe(struct intel_encoder *intel_encoder,
  4844. struct drm_connector *connector, int dpms_mode)
  4845. {
  4846. struct drm_encoder *encoder = &intel_encoder->base;
  4847. struct drm_device *dev = encoder->dev;
  4848. struct drm_crtc *crtc = encoder->crtc;
  4849. struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
  4850. struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
  4851. if (intel_encoder->load_detect_temp) {
  4852. encoder->crtc = NULL;
  4853. connector->encoder = NULL;
  4854. intel_encoder->load_detect_temp = false;
  4855. crtc->enabled = drm_helper_crtc_in_use(crtc);
  4856. drm_helper_disable_unused_functions(dev);
  4857. }
  4858. /* Switch crtc and encoder back off if necessary */
  4859. if (crtc->enabled && dpms_mode != DRM_MODE_DPMS_ON) {
  4860. if (encoder->crtc == crtc)
  4861. encoder_funcs->dpms(encoder, dpms_mode);
  4862. crtc_funcs->dpms(crtc, dpms_mode);
  4863. }
  4864. }
  4865. /* Returns the clock of the currently programmed mode of the given pipe. */
  4866. static int intel_crtc_clock_get(struct drm_device *dev, struct drm_crtc *crtc)
  4867. {
  4868. struct drm_i915_private *dev_priv = dev->dev_private;
  4869. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4870. int pipe = intel_crtc->pipe;
  4871. u32 dpll = I915_READ(DPLL(pipe));
  4872. u32 fp;
  4873. intel_clock_t clock;
  4874. if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
  4875. fp = FP0(pipe);
  4876. else
  4877. fp = FP1(pipe);
  4878. clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
  4879. if (IS_PINEVIEW(dev)) {
  4880. clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
  4881. clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
  4882. } else {
  4883. clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
  4884. clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
  4885. }
  4886. if (!IS_GEN2(dev)) {
  4887. if (IS_PINEVIEW(dev))
  4888. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
  4889. DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
  4890. else
  4891. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
  4892. DPLL_FPA01_P1_POST_DIV_SHIFT);
  4893. switch (dpll & DPLL_MODE_MASK) {
  4894. case DPLLB_MODE_DAC_SERIAL:
  4895. clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
  4896. 5 : 10;
  4897. break;
  4898. case DPLLB_MODE_LVDS:
  4899. clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
  4900. 7 : 14;
  4901. break;
  4902. default:
  4903. DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
  4904. "mode\n", (int)(dpll & DPLL_MODE_MASK));
  4905. return 0;
  4906. }
  4907. /* XXX: Handle the 100Mhz refclk */
  4908. intel_clock(dev, 96000, &clock);
  4909. } else {
  4910. bool is_lvds = (pipe == 1) && (I915_READ(LVDS) & LVDS_PORT_EN);
  4911. if (is_lvds) {
  4912. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
  4913. DPLL_FPA01_P1_POST_DIV_SHIFT);
  4914. clock.p2 = 14;
  4915. if ((dpll & PLL_REF_INPUT_MASK) ==
  4916. PLLB_REF_INPUT_SPREADSPECTRUMIN) {
  4917. /* XXX: might not be 66MHz */
  4918. intel_clock(dev, 66000, &clock);
  4919. } else
  4920. intel_clock(dev, 48000, &clock);
  4921. } else {
  4922. if (dpll & PLL_P1_DIVIDE_BY_TWO)
  4923. clock.p1 = 2;
  4924. else {
  4925. clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
  4926. DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
  4927. }
  4928. if (dpll & PLL_P2_DIVIDE_BY_4)
  4929. clock.p2 = 4;
  4930. else
  4931. clock.p2 = 2;
  4932. intel_clock(dev, 48000, &clock);
  4933. }
  4934. }
  4935. /* XXX: It would be nice to validate the clocks, but we can't reuse
  4936. * i830PllIsValid() because it relies on the xf86_config connector
  4937. * configuration being accurate, which it isn't necessarily.
  4938. */
  4939. return clock.dot;
  4940. }
  4941. /** Returns the currently programmed mode of the given pipe. */
  4942. struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev,
  4943. struct drm_crtc *crtc)
  4944. {
  4945. struct drm_i915_private *dev_priv = dev->dev_private;
  4946. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4947. int pipe = intel_crtc->pipe;
  4948. struct drm_display_mode *mode;
  4949. int htot = I915_READ(HTOTAL(pipe));
  4950. int hsync = I915_READ(HSYNC(pipe));
  4951. int vtot = I915_READ(VTOTAL(pipe));
  4952. int vsync = I915_READ(VSYNC(pipe));
  4953. mode = kzalloc(sizeof(*mode), GFP_KERNEL);
  4954. if (!mode)
  4955. return NULL;
  4956. mode->clock = intel_crtc_clock_get(dev, crtc);
  4957. mode->hdisplay = (htot & 0xffff) + 1;
  4958. mode->htotal = ((htot & 0xffff0000) >> 16) + 1;
  4959. mode->hsync_start = (hsync & 0xffff) + 1;
  4960. mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1;
  4961. mode->vdisplay = (vtot & 0xffff) + 1;
  4962. mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1;
  4963. mode->vsync_start = (vsync & 0xffff) + 1;
  4964. mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1;
  4965. drm_mode_set_name(mode);
  4966. drm_mode_set_crtcinfo(mode, 0);
  4967. return mode;
  4968. }
  4969. #define GPU_IDLE_TIMEOUT 500 /* ms */
  4970. /* When this timer fires, we've been idle for awhile */
  4971. static void intel_gpu_idle_timer(unsigned long arg)
  4972. {
  4973. struct drm_device *dev = (struct drm_device *)arg;
  4974. drm_i915_private_t *dev_priv = dev->dev_private;
  4975. if (!list_empty(&dev_priv->mm.active_list)) {
  4976. /* Still processing requests, so just re-arm the timer. */
  4977. mod_timer(&dev_priv->idle_timer, jiffies +
  4978. msecs_to_jiffies(GPU_IDLE_TIMEOUT));
  4979. return;
  4980. }
  4981. dev_priv->busy = false;
  4982. queue_work(dev_priv->wq, &dev_priv->idle_work);
  4983. }
  4984. #define CRTC_IDLE_TIMEOUT 1000 /* ms */
  4985. static void intel_crtc_idle_timer(unsigned long arg)
  4986. {
  4987. struct intel_crtc *intel_crtc = (struct intel_crtc *)arg;
  4988. struct drm_crtc *crtc = &intel_crtc->base;
  4989. drm_i915_private_t *dev_priv = crtc->dev->dev_private;
  4990. struct intel_framebuffer *intel_fb;
  4991. intel_fb = to_intel_framebuffer(crtc->fb);
  4992. if (intel_fb && intel_fb->obj->active) {
  4993. /* The framebuffer is still being accessed by the GPU. */
  4994. mod_timer(&intel_crtc->idle_timer, jiffies +
  4995. msecs_to_jiffies(CRTC_IDLE_TIMEOUT));
  4996. return;
  4997. }
  4998. intel_crtc->busy = false;
  4999. queue_work(dev_priv->wq, &dev_priv->idle_work);
  5000. }
  5001. static void intel_increase_pllclock(struct drm_crtc *crtc)
  5002. {
  5003. struct drm_device *dev = crtc->dev;
  5004. drm_i915_private_t *dev_priv = dev->dev_private;
  5005. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5006. int pipe = intel_crtc->pipe;
  5007. int dpll_reg = DPLL(pipe);
  5008. int dpll;
  5009. if (HAS_PCH_SPLIT(dev))
  5010. return;
  5011. if (!dev_priv->lvds_downclock_avail)
  5012. return;
  5013. dpll = I915_READ(dpll_reg);
  5014. if (!HAS_PIPE_CXSR(dev) && (dpll & DISPLAY_RATE_SELECT_FPA1)) {
  5015. DRM_DEBUG_DRIVER("upclocking LVDS\n");
  5016. /* Unlock panel regs */
  5017. I915_WRITE(PP_CONTROL,
  5018. I915_READ(PP_CONTROL) | PANEL_UNLOCK_REGS);
  5019. dpll &= ~DISPLAY_RATE_SELECT_FPA1;
  5020. I915_WRITE(dpll_reg, dpll);
  5021. POSTING_READ(dpll_reg);
  5022. intel_wait_for_vblank(dev, pipe);
  5023. dpll = I915_READ(dpll_reg);
  5024. if (dpll & DISPLAY_RATE_SELECT_FPA1)
  5025. DRM_DEBUG_DRIVER("failed to upclock LVDS!\n");
  5026. /* ...and lock them again */
  5027. I915_WRITE(PP_CONTROL, I915_READ(PP_CONTROL) & 0x3);
  5028. }
  5029. /* Schedule downclock */
  5030. mod_timer(&intel_crtc->idle_timer, jiffies +
  5031. msecs_to_jiffies(CRTC_IDLE_TIMEOUT));
  5032. }
  5033. static void intel_decrease_pllclock(struct drm_crtc *crtc)
  5034. {
  5035. struct drm_device *dev = crtc->dev;
  5036. drm_i915_private_t *dev_priv = dev->dev_private;
  5037. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5038. int pipe = intel_crtc->pipe;
  5039. int dpll_reg = DPLL(pipe);
  5040. int dpll = I915_READ(dpll_reg);
  5041. if (HAS_PCH_SPLIT(dev))
  5042. return;
  5043. if (!dev_priv->lvds_downclock_avail)
  5044. return;
  5045. /*
  5046. * Since this is called by a timer, we should never get here in
  5047. * the manual case.
  5048. */
  5049. if (!HAS_PIPE_CXSR(dev) && intel_crtc->lowfreq_avail) {
  5050. DRM_DEBUG_DRIVER("downclocking LVDS\n");
  5051. /* Unlock panel regs */
  5052. I915_WRITE(PP_CONTROL, I915_READ(PP_CONTROL) |
  5053. PANEL_UNLOCK_REGS);
  5054. dpll |= DISPLAY_RATE_SELECT_FPA1;
  5055. I915_WRITE(dpll_reg, dpll);
  5056. dpll = I915_READ(dpll_reg);
  5057. intel_wait_for_vblank(dev, pipe);
  5058. dpll = I915_READ(dpll_reg);
  5059. if (!(dpll & DISPLAY_RATE_SELECT_FPA1))
  5060. DRM_DEBUG_DRIVER("failed to downclock LVDS!\n");
  5061. /* ...and lock them again */
  5062. I915_WRITE(PP_CONTROL, I915_READ(PP_CONTROL) & 0x3);
  5063. }
  5064. }
  5065. /**
  5066. * intel_idle_update - adjust clocks for idleness
  5067. * @work: work struct
  5068. *
  5069. * Either the GPU or display (or both) went idle. Check the busy status
  5070. * here and adjust the CRTC and GPU clocks as necessary.
  5071. */
  5072. static void intel_idle_update(struct work_struct *work)
  5073. {
  5074. drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
  5075. idle_work);
  5076. struct drm_device *dev = dev_priv->dev;
  5077. struct drm_crtc *crtc;
  5078. struct intel_crtc *intel_crtc;
  5079. if (!i915_powersave)
  5080. return;
  5081. mutex_lock(&dev->struct_mutex);
  5082. i915_update_gfx_val(dev_priv);
  5083. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  5084. /* Skip inactive CRTCs */
  5085. if (!crtc->fb)
  5086. continue;
  5087. intel_crtc = to_intel_crtc(crtc);
  5088. if (!intel_crtc->busy)
  5089. intel_decrease_pllclock(crtc);
  5090. }
  5091. mutex_unlock(&dev->struct_mutex);
  5092. }
  5093. /**
  5094. * intel_mark_busy - mark the GPU and possibly the display busy
  5095. * @dev: drm device
  5096. * @obj: object we're operating on
  5097. *
  5098. * Callers can use this function to indicate that the GPU is busy processing
  5099. * commands. If @obj matches one of the CRTC objects (i.e. it's a scanout
  5100. * buffer), we'll also mark the display as busy, so we know to increase its
  5101. * clock frequency.
  5102. */
  5103. void intel_mark_busy(struct drm_device *dev, struct drm_i915_gem_object *obj)
  5104. {
  5105. drm_i915_private_t *dev_priv = dev->dev_private;
  5106. struct drm_crtc *crtc = NULL;
  5107. struct intel_framebuffer *intel_fb;
  5108. struct intel_crtc *intel_crtc;
  5109. if (!drm_core_check_feature(dev, DRIVER_MODESET))
  5110. return;
  5111. if (!dev_priv->busy)
  5112. dev_priv->busy = true;
  5113. else
  5114. mod_timer(&dev_priv->idle_timer, jiffies +
  5115. msecs_to_jiffies(GPU_IDLE_TIMEOUT));
  5116. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  5117. if (!crtc->fb)
  5118. continue;
  5119. intel_crtc = to_intel_crtc(crtc);
  5120. intel_fb = to_intel_framebuffer(crtc->fb);
  5121. if (intel_fb->obj == obj) {
  5122. if (!intel_crtc->busy) {
  5123. /* Non-busy -> busy, upclock */
  5124. intel_increase_pllclock(crtc);
  5125. intel_crtc->busy = true;
  5126. } else {
  5127. /* Busy -> busy, put off timer */
  5128. mod_timer(&intel_crtc->idle_timer, jiffies +
  5129. msecs_to_jiffies(CRTC_IDLE_TIMEOUT));
  5130. }
  5131. }
  5132. }
  5133. }
  5134. static void intel_crtc_destroy(struct drm_crtc *crtc)
  5135. {
  5136. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5137. struct drm_device *dev = crtc->dev;
  5138. struct intel_unpin_work *work;
  5139. unsigned long flags;
  5140. spin_lock_irqsave(&dev->event_lock, flags);
  5141. work = intel_crtc->unpin_work;
  5142. intel_crtc->unpin_work = NULL;
  5143. spin_unlock_irqrestore(&dev->event_lock, flags);
  5144. if (work) {
  5145. cancel_work_sync(&work->work);
  5146. kfree(work);
  5147. }
  5148. drm_crtc_cleanup(crtc);
  5149. kfree(intel_crtc);
  5150. }
  5151. static void intel_unpin_work_fn(struct work_struct *__work)
  5152. {
  5153. struct intel_unpin_work *work =
  5154. container_of(__work, struct intel_unpin_work, work);
  5155. mutex_lock(&work->dev->struct_mutex);
  5156. i915_gem_object_unpin(work->old_fb_obj);
  5157. drm_gem_object_unreference(&work->pending_flip_obj->base);
  5158. drm_gem_object_unreference(&work->old_fb_obj->base);
  5159. mutex_unlock(&work->dev->struct_mutex);
  5160. kfree(work);
  5161. }
  5162. static void do_intel_finish_page_flip(struct drm_device *dev,
  5163. struct drm_crtc *crtc)
  5164. {
  5165. drm_i915_private_t *dev_priv = dev->dev_private;
  5166. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5167. struct intel_unpin_work *work;
  5168. struct drm_i915_gem_object *obj;
  5169. struct drm_pending_vblank_event *e;
  5170. struct timeval tnow, tvbl;
  5171. unsigned long flags;
  5172. /* Ignore early vblank irqs */
  5173. if (intel_crtc == NULL)
  5174. return;
  5175. do_gettimeofday(&tnow);
  5176. spin_lock_irqsave(&dev->event_lock, flags);
  5177. work = intel_crtc->unpin_work;
  5178. if (work == NULL || !work->pending) {
  5179. spin_unlock_irqrestore(&dev->event_lock, flags);
  5180. return;
  5181. }
  5182. intel_crtc->unpin_work = NULL;
  5183. if (work->event) {
  5184. e = work->event;
  5185. e->event.sequence = drm_vblank_count_and_time(dev, intel_crtc->pipe, &tvbl);
  5186. /* Called before vblank count and timestamps have
  5187. * been updated for the vblank interval of flip
  5188. * completion? Need to increment vblank count and
  5189. * add one videorefresh duration to returned timestamp
  5190. * to account for this. We assume this happened if we
  5191. * get called over 0.9 frame durations after the last
  5192. * timestamped vblank.
  5193. *
  5194. * This calculation can not be used with vrefresh rates
  5195. * below 5Hz (10Hz to be on the safe side) without
  5196. * promoting to 64 integers.
  5197. */
  5198. if (10 * (timeval_to_ns(&tnow) - timeval_to_ns(&tvbl)) >
  5199. 9 * crtc->framedur_ns) {
  5200. e->event.sequence++;
  5201. tvbl = ns_to_timeval(timeval_to_ns(&tvbl) +
  5202. crtc->framedur_ns);
  5203. }
  5204. e->event.tv_sec = tvbl.tv_sec;
  5205. e->event.tv_usec = tvbl.tv_usec;
  5206. list_add_tail(&e->base.link,
  5207. &e->base.file_priv->event_list);
  5208. wake_up_interruptible(&e->base.file_priv->event_wait);
  5209. }
  5210. drm_vblank_put(dev, intel_crtc->pipe);
  5211. spin_unlock_irqrestore(&dev->event_lock, flags);
  5212. obj = work->old_fb_obj;
  5213. atomic_clear_mask(1 << intel_crtc->plane,
  5214. &obj->pending_flip.counter);
  5215. if (atomic_read(&obj->pending_flip) == 0)
  5216. wake_up(&dev_priv->pending_flip_queue);
  5217. schedule_work(&work->work);
  5218. trace_i915_flip_complete(intel_crtc->plane, work->pending_flip_obj);
  5219. }
  5220. void intel_finish_page_flip(struct drm_device *dev, int pipe)
  5221. {
  5222. drm_i915_private_t *dev_priv = dev->dev_private;
  5223. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  5224. do_intel_finish_page_flip(dev, crtc);
  5225. }
  5226. void intel_finish_page_flip_plane(struct drm_device *dev, int plane)
  5227. {
  5228. drm_i915_private_t *dev_priv = dev->dev_private;
  5229. struct drm_crtc *crtc = dev_priv->plane_to_crtc_mapping[plane];
  5230. do_intel_finish_page_flip(dev, crtc);
  5231. }
  5232. void intel_prepare_page_flip(struct drm_device *dev, int plane)
  5233. {
  5234. drm_i915_private_t *dev_priv = dev->dev_private;
  5235. struct intel_crtc *intel_crtc =
  5236. to_intel_crtc(dev_priv->plane_to_crtc_mapping[plane]);
  5237. unsigned long flags;
  5238. spin_lock_irqsave(&dev->event_lock, flags);
  5239. if (intel_crtc->unpin_work) {
  5240. if ((++intel_crtc->unpin_work->pending) > 1)
  5241. DRM_ERROR("Prepared flip multiple times\n");
  5242. } else {
  5243. DRM_DEBUG_DRIVER("preparing flip with no unpin work?\n");
  5244. }
  5245. spin_unlock_irqrestore(&dev->event_lock, flags);
  5246. }
  5247. static int intel_crtc_page_flip(struct drm_crtc *crtc,
  5248. struct drm_framebuffer *fb,
  5249. struct drm_pending_vblank_event *event)
  5250. {
  5251. struct drm_device *dev = crtc->dev;
  5252. struct drm_i915_private *dev_priv = dev->dev_private;
  5253. struct intel_framebuffer *intel_fb;
  5254. struct drm_i915_gem_object *obj;
  5255. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5256. struct intel_unpin_work *work;
  5257. unsigned long flags, offset;
  5258. int pipe = intel_crtc->pipe;
  5259. u32 pf, pipesrc;
  5260. int ret;
  5261. work = kzalloc(sizeof *work, GFP_KERNEL);
  5262. if (work == NULL)
  5263. return -ENOMEM;
  5264. work->event = event;
  5265. work->dev = crtc->dev;
  5266. intel_fb = to_intel_framebuffer(crtc->fb);
  5267. work->old_fb_obj = intel_fb->obj;
  5268. INIT_WORK(&work->work, intel_unpin_work_fn);
  5269. /* We borrow the event spin lock for protecting unpin_work */
  5270. spin_lock_irqsave(&dev->event_lock, flags);
  5271. if (intel_crtc->unpin_work) {
  5272. spin_unlock_irqrestore(&dev->event_lock, flags);
  5273. kfree(work);
  5274. DRM_DEBUG_DRIVER("flip queue: crtc already busy\n");
  5275. return -EBUSY;
  5276. }
  5277. intel_crtc->unpin_work = work;
  5278. spin_unlock_irqrestore(&dev->event_lock, flags);
  5279. intel_fb = to_intel_framebuffer(fb);
  5280. obj = intel_fb->obj;
  5281. mutex_lock(&dev->struct_mutex);
  5282. ret = intel_pin_and_fence_fb_obj(dev, obj, LP_RING(dev_priv));
  5283. if (ret)
  5284. goto cleanup_work;
  5285. /* Reference the objects for the scheduled work. */
  5286. drm_gem_object_reference(&work->old_fb_obj->base);
  5287. drm_gem_object_reference(&obj->base);
  5288. crtc->fb = fb;
  5289. ret = drm_vblank_get(dev, intel_crtc->pipe);
  5290. if (ret)
  5291. goto cleanup_objs;
  5292. if (IS_GEN3(dev) || IS_GEN2(dev)) {
  5293. u32 flip_mask;
  5294. /* Can't queue multiple flips, so wait for the previous
  5295. * one to finish before executing the next.
  5296. */
  5297. ret = BEGIN_LP_RING(2);
  5298. if (ret)
  5299. goto cleanup_objs;
  5300. if (intel_crtc->plane)
  5301. flip_mask = MI_WAIT_FOR_PLANE_B_FLIP;
  5302. else
  5303. flip_mask = MI_WAIT_FOR_PLANE_A_FLIP;
  5304. OUT_RING(MI_WAIT_FOR_EVENT | flip_mask);
  5305. OUT_RING(MI_NOOP);
  5306. ADVANCE_LP_RING();
  5307. }
  5308. work->pending_flip_obj = obj;
  5309. work->enable_stall_check = true;
  5310. /* Offset into the new buffer for cases of shared fbs between CRTCs */
  5311. offset = crtc->y * fb->pitch + crtc->x * fb->bits_per_pixel/8;
  5312. ret = BEGIN_LP_RING(4);
  5313. if (ret)
  5314. goto cleanup_objs;
  5315. /* Block clients from rendering to the new back buffer until
  5316. * the flip occurs and the object is no longer visible.
  5317. */
  5318. atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
  5319. switch (INTEL_INFO(dev)->gen) {
  5320. case 2:
  5321. OUT_RING(MI_DISPLAY_FLIP |
  5322. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  5323. OUT_RING(fb->pitch);
  5324. OUT_RING(obj->gtt_offset + offset);
  5325. OUT_RING(MI_NOOP);
  5326. break;
  5327. case 3:
  5328. OUT_RING(MI_DISPLAY_FLIP_I915 |
  5329. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  5330. OUT_RING(fb->pitch);
  5331. OUT_RING(obj->gtt_offset + offset);
  5332. OUT_RING(MI_NOOP);
  5333. break;
  5334. case 4:
  5335. case 5:
  5336. /* i965+ uses the linear or tiled offsets from the
  5337. * Display Registers (which do not change across a page-flip)
  5338. * so we need only reprogram the base address.
  5339. */
  5340. OUT_RING(MI_DISPLAY_FLIP |
  5341. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  5342. OUT_RING(fb->pitch);
  5343. OUT_RING(obj->gtt_offset | obj->tiling_mode);
  5344. /* XXX Enabling the panel-fitter across page-flip is so far
  5345. * untested on non-native modes, so ignore it for now.
  5346. * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE;
  5347. */
  5348. pf = 0;
  5349. pipesrc = I915_READ(PIPESRC(pipe)) & 0x0fff0fff;
  5350. OUT_RING(pf | pipesrc);
  5351. break;
  5352. case 6:
  5353. OUT_RING(MI_DISPLAY_FLIP |
  5354. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  5355. OUT_RING(fb->pitch | obj->tiling_mode);
  5356. OUT_RING(obj->gtt_offset);
  5357. pf = I915_READ(PF_CTL(pipe)) & PF_ENABLE;
  5358. pipesrc = I915_READ(PIPESRC(pipe)) & 0x0fff0fff;
  5359. OUT_RING(pf | pipesrc);
  5360. break;
  5361. }
  5362. ADVANCE_LP_RING();
  5363. mutex_unlock(&dev->struct_mutex);
  5364. trace_i915_flip_request(intel_crtc->plane, obj);
  5365. return 0;
  5366. cleanup_objs:
  5367. drm_gem_object_unreference(&work->old_fb_obj->base);
  5368. drm_gem_object_unreference(&obj->base);
  5369. cleanup_work:
  5370. mutex_unlock(&dev->struct_mutex);
  5371. spin_lock_irqsave(&dev->event_lock, flags);
  5372. intel_crtc->unpin_work = NULL;
  5373. spin_unlock_irqrestore(&dev->event_lock, flags);
  5374. kfree(work);
  5375. return ret;
  5376. }
  5377. static void intel_crtc_reset(struct drm_crtc *crtc)
  5378. {
  5379. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5380. /* Reset flags back to the 'unknown' status so that they
  5381. * will be correctly set on the initial modeset.
  5382. */
  5383. intel_crtc->dpms_mode = -1;
  5384. }
  5385. static struct drm_crtc_helper_funcs intel_helper_funcs = {
  5386. .dpms = intel_crtc_dpms,
  5387. .mode_fixup = intel_crtc_mode_fixup,
  5388. .mode_set = intel_crtc_mode_set,
  5389. .mode_set_base = intel_pipe_set_base,
  5390. .mode_set_base_atomic = intel_pipe_set_base_atomic,
  5391. .load_lut = intel_crtc_load_lut,
  5392. .disable = intel_crtc_disable,
  5393. };
  5394. static const struct drm_crtc_funcs intel_crtc_funcs = {
  5395. .reset = intel_crtc_reset,
  5396. .cursor_set = intel_crtc_cursor_set,
  5397. .cursor_move = intel_crtc_cursor_move,
  5398. .gamma_set = intel_crtc_gamma_set,
  5399. .set_config = drm_crtc_helper_set_config,
  5400. .destroy = intel_crtc_destroy,
  5401. .page_flip = intel_crtc_page_flip,
  5402. };
  5403. static void intel_sanitize_modesetting(struct drm_device *dev,
  5404. int pipe, int plane)
  5405. {
  5406. struct drm_i915_private *dev_priv = dev->dev_private;
  5407. u32 reg, val;
  5408. if (HAS_PCH_SPLIT(dev))
  5409. return;
  5410. /* Who knows what state these registers were left in by the BIOS or
  5411. * grub?
  5412. *
  5413. * If we leave the registers in a conflicting state (e.g. with the
  5414. * display plane reading from the other pipe than the one we intend
  5415. * to use) then when we attempt to teardown the active mode, we will
  5416. * not disable the pipes and planes in the correct order -- leaving
  5417. * a plane reading from a disabled pipe and possibly leading to
  5418. * undefined behaviour.
  5419. */
  5420. reg = DSPCNTR(plane);
  5421. val = I915_READ(reg);
  5422. if ((val & DISPLAY_PLANE_ENABLE) == 0)
  5423. return;
  5424. if (!!(val & DISPPLANE_SEL_PIPE_MASK) == pipe)
  5425. return;
  5426. /* This display plane is active and attached to the other CPU pipe. */
  5427. pipe = !pipe;
  5428. /* Disable the plane and wait for it to stop reading from the pipe. */
  5429. intel_disable_plane(dev_priv, plane, pipe);
  5430. intel_disable_pipe(dev_priv, pipe);
  5431. }
  5432. static void intel_crtc_init(struct drm_device *dev, int pipe)
  5433. {
  5434. drm_i915_private_t *dev_priv = dev->dev_private;
  5435. struct intel_crtc *intel_crtc;
  5436. int i;
  5437. intel_crtc = kzalloc(sizeof(struct intel_crtc) + (INTELFB_CONN_LIMIT * sizeof(struct drm_connector *)), GFP_KERNEL);
  5438. if (intel_crtc == NULL)
  5439. return;
  5440. drm_crtc_init(dev, &intel_crtc->base, &intel_crtc_funcs);
  5441. drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256);
  5442. for (i = 0; i < 256; i++) {
  5443. intel_crtc->lut_r[i] = i;
  5444. intel_crtc->lut_g[i] = i;
  5445. intel_crtc->lut_b[i] = i;
  5446. }
  5447. /* Swap pipes & planes for FBC on pre-965 */
  5448. intel_crtc->pipe = pipe;
  5449. intel_crtc->plane = pipe;
  5450. if (IS_MOBILE(dev) && IS_GEN3(dev)) {
  5451. DRM_DEBUG_KMS("swapping pipes & planes for FBC\n");
  5452. intel_crtc->plane = !pipe;
  5453. }
  5454. BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
  5455. dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL);
  5456. dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base;
  5457. dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base;
  5458. intel_crtc_reset(&intel_crtc->base);
  5459. intel_crtc->active = true; /* force the pipe off on setup_init_config */
  5460. if (HAS_PCH_SPLIT(dev)) {
  5461. intel_helper_funcs.prepare = ironlake_crtc_prepare;
  5462. intel_helper_funcs.commit = ironlake_crtc_commit;
  5463. } else {
  5464. intel_helper_funcs.prepare = i9xx_crtc_prepare;
  5465. intel_helper_funcs.commit = i9xx_crtc_commit;
  5466. }
  5467. drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
  5468. intel_crtc->busy = false;
  5469. setup_timer(&intel_crtc->idle_timer, intel_crtc_idle_timer,
  5470. (unsigned long)intel_crtc);
  5471. intel_sanitize_modesetting(dev, intel_crtc->pipe, intel_crtc->plane);
  5472. }
  5473. int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data,
  5474. struct drm_file *file)
  5475. {
  5476. drm_i915_private_t *dev_priv = dev->dev_private;
  5477. struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
  5478. struct drm_mode_object *drmmode_obj;
  5479. struct intel_crtc *crtc;
  5480. if (!dev_priv) {
  5481. DRM_ERROR("called with no initialization\n");
  5482. return -EINVAL;
  5483. }
  5484. drmmode_obj = drm_mode_object_find(dev, pipe_from_crtc_id->crtc_id,
  5485. DRM_MODE_OBJECT_CRTC);
  5486. if (!drmmode_obj) {
  5487. DRM_ERROR("no such CRTC id\n");
  5488. return -EINVAL;
  5489. }
  5490. crtc = to_intel_crtc(obj_to_crtc(drmmode_obj));
  5491. pipe_from_crtc_id->pipe = crtc->pipe;
  5492. return 0;
  5493. }
  5494. static int intel_encoder_clones(struct drm_device *dev, int type_mask)
  5495. {
  5496. struct intel_encoder *encoder;
  5497. int index_mask = 0;
  5498. int entry = 0;
  5499. list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head) {
  5500. if (type_mask & encoder->clone_mask)
  5501. index_mask |= (1 << entry);
  5502. entry++;
  5503. }
  5504. return index_mask;
  5505. }
  5506. static bool has_edp_a(struct drm_device *dev)
  5507. {
  5508. struct drm_i915_private *dev_priv = dev->dev_private;
  5509. if (!IS_MOBILE(dev))
  5510. return false;
  5511. if ((I915_READ(DP_A) & DP_DETECTED) == 0)
  5512. return false;
  5513. if (IS_GEN5(dev) &&
  5514. (I915_READ(ILK_DISPLAY_CHICKEN_FUSES) & ILK_eDP_A_DISABLE))
  5515. return false;
  5516. return true;
  5517. }
  5518. static void intel_setup_outputs(struct drm_device *dev)
  5519. {
  5520. struct drm_i915_private *dev_priv = dev->dev_private;
  5521. struct intel_encoder *encoder;
  5522. bool dpd_is_edp = false;
  5523. bool has_lvds = false;
  5524. if (IS_MOBILE(dev) && !IS_I830(dev))
  5525. has_lvds = intel_lvds_init(dev);
  5526. if (!has_lvds && !HAS_PCH_SPLIT(dev)) {
  5527. /* disable the panel fitter on everything but LVDS */
  5528. I915_WRITE(PFIT_CONTROL, 0);
  5529. }
  5530. if (HAS_PCH_SPLIT(dev)) {
  5531. dpd_is_edp = intel_dpd_is_edp(dev);
  5532. if (has_edp_a(dev))
  5533. intel_dp_init(dev, DP_A);
  5534. if (dpd_is_edp && (I915_READ(PCH_DP_D) & DP_DETECTED))
  5535. intel_dp_init(dev, PCH_DP_D);
  5536. }
  5537. intel_crt_init(dev);
  5538. if (HAS_PCH_SPLIT(dev)) {
  5539. int found;
  5540. if (I915_READ(HDMIB) & PORT_DETECTED) {
  5541. /* PCH SDVOB multiplex with HDMIB */
  5542. found = intel_sdvo_init(dev, PCH_SDVOB);
  5543. if (!found)
  5544. intel_hdmi_init(dev, HDMIB);
  5545. if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
  5546. intel_dp_init(dev, PCH_DP_B);
  5547. }
  5548. if (I915_READ(HDMIC) & PORT_DETECTED)
  5549. intel_hdmi_init(dev, HDMIC);
  5550. if (I915_READ(HDMID) & PORT_DETECTED)
  5551. intel_hdmi_init(dev, HDMID);
  5552. if (I915_READ(PCH_DP_C) & DP_DETECTED)
  5553. intel_dp_init(dev, PCH_DP_C);
  5554. if (!dpd_is_edp && (I915_READ(PCH_DP_D) & DP_DETECTED))
  5555. intel_dp_init(dev, PCH_DP_D);
  5556. } else if (SUPPORTS_DIGITAL_OUTPUTS(dev)) {
  5557. bool found = false;
  5558. if (I915_READ(SDVOB) & SDVO_DETECTED) {
  5559. DRM_DEBUG_KMS("probing SDVOB\n");
  5560. found = intel_sdvo_init(dev, SDVOB);
  5561. if (!found && SUPPORTS_INTEGRATED_HDMI(dev)) {
  5562. DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
  5563. intel_hdmi_init(dev, SDVOB);
  5564. }
  5565. if (!found && SUPPORTS_INTEGRATED_DP(dev)) {
  5566. DRM_DEBUG_KMS("probing DP_B\n");
  5567. intel_dp_init(dev, DP_B);
  5568. }
  5569. }
  5570. /* Before G4X SDVOC doesn't have its own detect register */
  5571. if (I915_READ(SDVOB) & SDVO_DETECTED) {
  5572. DRM_DEBUG_KMS("probing SDVOC\n");
  5573. found = intel_sdvo_init(dev, SDVOC);
  5574. }
  5575. if (!found && (I915_READ(SDVOC) & SDVO_DETECTED)) {
  5576. if (SUPPORTS_INTEGRATED_HDMI(dev)) {
  5577. DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
  5578. intel_hdmi_init(dev, SDVOC);
  5579. }
  5580. if (SUPPORTS_INTEGRATED_DP(dev)) {
  5581. DRM_DEBUG_KMS("probing DP_C\n");
  5582. intel_dp_init(dev, DP_C);
  5583. }
  5584. }
  5585. if (SUPPORTS_INTEGRATED_DP(dev) &&
  5586. (I915_READ(DP_D) & DP_DETECTED)) {
  5587. DRM_DEBUG_KMS("probing DP_D\n");
  5588. intel_dp_init(dev, DP_D);
  5589. }
  5590. } else if (IS_GEN2(dev))
  5591. intel_dvo_init(dev);
  5592. if (SUPPORTS_TV(dev))
  5593. intel_tv_init(dev);
  5594. list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head) {
  5595. encoder->base.possible_crtcs = encoder->crtc_mask;
  5596. encoder->base.possible_clones =
  5597. intel_encoder_clones(dev, encoder->clone_mask);
  5598. }
  5599. intel_panel_setup_backlight(dev);
  5600. }
  5601. static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
  5602. {
  5603. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  5604. drm_framebuffer_cleanup(fb);
  5605. drm_gem_object_unreference_unlocked(&intel_fb->obj->base);
  5606. kfree(intel_fb);
  5607. }
  5608. static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
  5609. struct drm_file *file,
  5610. unsigned int *handle)
  5611. {
  5612. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  5613. struct drm_i915_gem_object *obj = intel_fb->obj;
  5614. return drm_gem_handle_create(file, &obj->base, handle);
  5615. }
  5616. static const struct drm_framebuffer_funcs intel_fb_funcs = {
  5617. .destroy = intel_user_framebuffer_destroy,
  5618. .create_handle = intel_user_framebuffer_create_handle,
  5619. };
  5620. int intel_framebuffer_init(struct drm_device *dev,
  5621. struct intel_framebuffer *intel_fb,
  5622. struct drm_mode_fb_cmd *mode_cmd,
  5623. struct drm_i915_gem_object *obj)
  5624. {
  5625. int ret;
  5626. if (obj->tiling_mode == I915_TILING_Y)
  5627. return -EINVAL;
  5628. if (mode_cmd->pitch & 63)
  5629. return -EINVAL;
  5630. switch (mode_cmd->bpp) {
  5631. case 8:
  5632. case 16:
  5633. case 24:
  5634. case 32:
  5635. break;
  5636. default:
  5637. return -EINVAL;
  5638. }
  5639. ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs);
  5640. if (ret) {
  5641. DRM_ERROR("framebuffer init failed %d\n", ret);
  5642. return ret;
  5643. }
  5644. drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd);
  5645. intel_fb->obj = obj;
  5646. return 0;
  5647. }
  5648. static struct drm_framebuffer *
  5649. intel_user_framebuffer_create(struct drm_device *dev,
  5650. struct drm_file *filp,
  5651. struct drm_mode_fb_cmd *mode_cmd)
  5652. {
  5653. struct drm_i915_gem_object *obj;
  5654. struct intel_framebuffer *intel_fb;
  5655. int ret;
  5656. obj = to_intel_bo(drm_gem_object_lookup(dev, filp, mode_cmd->handle));
  5657. if (!obj)
  5658. return ERR_PTR(-ENOENT);
  5659. intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
  5660. if (!intel_fb)
  5661. return ERR_PTR(-ENOMEM);
  5662. ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj);
  5663. if (ret) {
  5664. drm_gem_object_unreference_unlocked(&obj->base);
  5665. kfree(intel_fb);
  5666. return ERR_PTR(ret);
  5667. }
  5668. return &intel_fb->base;
  5669. }
  5670. static const struct drm_mode_config_funcs intel_mode_funcs = {
  5671. .fb_create = intel_user_framebuffer_create,
  5672. .output_poll_changed = intel_fb_output_poll_changed,
  5673. };
  5674. static struct drm_i915_gem_object *
  5675. intel_alloc_context_page(struct drm_device *dev)
  5676. {
  5677. struct drm_i915_gem_object *ctx;
  5678. int ret;
  5679. ctx = i915_gem_alloc_object(dev, 4096);
  5680. if (!ctx) {
  5681. DRM_DEBUG("failed to alloc power context, RC6 disabled\n");
  5682. return NULL;
  5683. }
  5684. mutex_lock(&dev->struct_mutex);
  5685. ret = i915_gem_object_pin(ctx, 4096, true);
  5686. if (ret) {
  5687. DRM_ERROR("failed to pin power context: %d\n", ret);
  5688. goto err_unref;
  5689. }
  5690. ret = i915_gem_object_set_to_gtt_domain(ctx, 1);
  5691. if (ret) {
  5692. DRM_ERROR("failed to set-domain on power context: %d\n", ret);
  5693. goto err_unpin;
  5694. }
  5695. mutex_unlock(&dev->struct_mutex);
  5696. return ctx;
  5697. err_unpin:
  5698. i915_gem_object_unpin(ctx);
  5699. err_unref:
  5700. drm_gem_object_unreference(&ctx->base);
  5701. mutex_unlock(&dev->struct_mutex);
  5702. return NULL;
  5703. }
  5704. bool ironlake_set_drps(struct drm_device *dev, u8 val)
  5705. {
  5706. struct drm_i915_private *dev_priv = dev->dev_private;
  5707. u16 rgvswctl;
  5708. rgvswctl = I915_READ16(MEMSWCTL);
  5709. if (rgvswctl & MEMCTL_CMD_STS) {
  5710. DRM_DEBUG("gpu busy, RCS change rejected\n");
  5711. return false; /* still busy with another command */
  5712. }
  5713. rgvswctl = (MEMCTL_CMD_CHFREQ << MEMCTL_CMD_SHIFT) |
  5714. (val << MEMCTL_FREQ_SHIFT) | MEMCTL_SFCAVM;
  5715. I915_WRITE16(MEMSWCTL, rgvswctl);
  5716. POSTING_READ16(MEMSWCTL);
  5717. rgvswctl |= MEMCTL_CMD_STS;
  5718. I915_WRITE16(MEMSWCTL, rgvswctl);
  5719. return true;
  5720. }
  5721. void ironlake_enable_drps(struct drm_device *dev)
  5722. {
  5723. struct drm_i915_private *dev_priv = dev->dev_private;
  5724. u32 rgvmodectl = I915_READ(MEMMODECTL);
  5725. u8 fmax, fmin, fstart, vstart;
  5726. /* Enable temp reporting */
  5727. I915_WRITE16(PMMISC, I915_READ(PMMISC) | MCPPCE_EN);
  5728. I915_WRITE16(TSC1, I915_READ(TSC1) | TSE);
  5729. /* 100ms RC evaluation intervals */
  5730. I915_WRITE(RCUPEI, 100000);
  5731. I915_WRITE(RCDNEI, 100000);
  5732. /* Set max/min thresholds to 90ms and 80ms respectively */
  5733. I915_WRITE(RCBMAXAVG, 90000);
  5734. I915_WRITE(RCBMINAVG, 80000);
  5735. I915_WRITE(MEMIHYST, 1);
  5736. /* Set up min, max, and cur for interrupt handling */
  5737. fmax = (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT;
  5738. fmin = (rgvmodectl & MEMMODE_FMIN_MASK);
  5739. fstart = (rgvmodectl & MEMMODE_FSTART_MASK) >>
  5740. MEMMODE_FSTART_SHIFT;
  5741. vstart = (I915_READ(PXVFREQ_BASE + (fstart * 4)) & PXVFREQ_PX_MASK) >>
  5742. PXVFREQ_PX_SHIFT;
  5743. dev_priv->fmax = fmax; /* IPS callback will increase this */
  5744. dev_priv->fstart = fstart;
  5745. dev_priv->max_delay = fstart;
  5746. dev_priv->min_delay = fmin;
  5747. dev_priv->cur_delay = fstart;
  5748. DRM_DEBUG_DRIVER("fmax: %d, fmin: %d, fstart: %d\n",
  5749. fmax, fmin, fstart);
  5750. I915_WRITE(MEMINTREN, MEMINT_CX_SUPR_EN | MEMINT_EVAL_CHG_EN);
  5751. /*
  5752. * Interrupts will be enabled in ironlake_irq_postinstall
  5753. */
  5754. I915_WRITE(VIDSTART, vstart);
  5755. POSTING_READ(VIDSTART);
  5756. rgvmodectl |= MEMMODE_SWMODE_EN;
  5757. I915_WRITE(MEMMODECTL, rgvmodectl);
  5758. if (wait_for((I915_READ(MEMSWCTL) & MEMCTL_CMD_STS) == 0, 10))
  5759. DRM_ERROR("stuck trying to change perf mode\n");
  5760. msleep(1);
  5761. ironlake_set_drps(dev, fstart);
  5762. dev_priv->last_count1 = I915_READ(0x112e4) + I915_READ(0x112e8) +
  5763. I915_READ(0x112e0);
  5764. dev_priv->last_time1 = jiffies_to_msecs(jiffies);
  5765. dev_priv->last_count2 = I915_READ(0x112f4);
  5766. getrawmonotonic(&dev_priv->last_time2);
  5767. }
  5768. void ironlake_disable_drps(struct drm_device *dev)
  5769. {
  5770. struct drm_i915_private *dev_priv = dev->dev_private;
  5771. u16 rgvswctl = I915_READ16(MEMSWCTL);
  5772. /* Ack interrupts, disable EFC interrupt */
  5773. I915_WRITE(MEMINTREN, I915_READ(MEMINTREN) & ~MEMINT_EVAL_CHG_EN);
  5774. I915_WRITE(MEMINTRSTS, MEMINT_EVAL_CHG);
  5775. I915_WRITE(DEIER, I915_READ(DEIER) & ~DE_PCU_EVENT);
  5776. I915_WRITE(DEIIR, DE_PCU_EVENT);
  5777. I915_WRITE(DEIMR, I915_READ(DEIMR) | DE_PCU_EVENT);
  5778. /* Go back to the starting frequency */
  5779. ironlake_set_drps(dev, dev_priv->fstart);
  5780. msleep(1);
  5781. rgvswctl |= MEMCTL_CMD_STS;
  5782. I915_WRITE(MEMSWCTL, rgvswctl);
  5783. msleep(1);
  5784. }
  5785. void gen6_set_rps(struct drm_device *dev, u8 val)
  5786. {
  5787. struct drm_i915_private *dev_priv = dev->dev_private;
  5788. u32 swreq;
  5789. swreq = (val & 0x3ff) << 25;
  5790. I915_WRITE(GEN6_RPNSWREQ, swreq);
  5791. }
  5792. void gen6_disable_rps(struct drm_device *dev)
  5793. {
  5794. struct drm_i915_private *dev_priv = dev->dev_private;
  5795. I915_WRITE(GEN6_RPNSWREQ, 1 << 31);
  5796. I915_WRITE(GEN6_PMINTRMSK, 0xffffffff);
  5797. I915_WRITE(GEN6_PMIER, 0);
  5798. I915_WRITE(GEN6_PMIIR, I915_READ(GEN6_PMIIR));
  5799. }
  5800. static unsigned long intel_pxfreq(u32 vidfreq)
  5801. {
  5802. unsigned long freq;
  5803. int div = (vidfreq & 0x3f0000) >> 16;
  5804. int post = (vidfreq & 0x3000) >> 12;
  5805. int pre = (vidfreq & 0x7);
  5806. if (!pre)
  5807. return 0;
  5808. freq = ((div * 133333) / ((1<<post) * pre));
  5809. return freq;
  5810. }
  5811. void intel_init_emon(struct drm_device *dev)
  5812. {
  5813. struct drm_i915_private *dev_priv = dev->dev_private;
  5814. u32 lcfuse;
  5815. u8 pxw[16];
  5816. int i;
  5817. /* Disable to program */
  5818. I915_WRITE(ECR, 0);
  5819. POSTING_READ(ECR);
  5820. /* Program energy weights for various events */
  5821. I915_WRITE(SDEW, 0x15040d00);
  5822. I915_WRITE(CSIEW0, 0x007f0000);
  5823. I915_WRITE(CSIEW1, 0x1e220004);
  5824. I915_WRITE(CSIEW2, 0x04000004);
  5825. for (i = 0; i < 5; i++)
  5826. I915_WRITE(PEW + (i * 4), 0);
  5827. for (i = 0; i < 3; i++)
  5828. I915_WRITE(DEW + (i * 4), 0);
  5829. /* Program P-state weights to account for frequency power adjustment */
  5830. for (i = 0; i < 16; i++) {
  5831. u32 pxvidfreq = I915_READ(PXVFREQ_BASE + (i * 4));
  5832. unsigned long freq = intel_pxfreq(pxvidfreq);
  5833. unsigned long vid = (pxvidfreq & PXVFREQ_PX_MASK) >>
  5834. PXVFREQ_PX_SHIFT;
  5835. unsigned long val;
  5836. val = vid * vid;
  5837. val *= (freq / 1000);
  5838. val *= 255;
  5839. val /= (127*127*900);
  5840. if (val > 0xff)
  5841. DRM_ERROR("bad pxval: %ld\n", val);
  5842. pxw[i] = val;
  5843. }
  5844. /* Render standby states get 0 weight */
  5845. pxw[14] = 0;
  5846. pxw[15] = 0;
  5847. for (i = 0; i < 4; i++) {
  5848. u32 val = (pxw[i*4] << 24) | (pxw[(i*4)+1] << 16) |
  5849. (pxw[(i*4)+2] << 8) | (pxw[(i*4)+3]);
  5850. I915_WRITE(PXW + (i * 4), val);
  5851. }
  5852. /* Adjust magic regs to magic values (more experimental results) */
  5853. I915_WRITE(OGW0, 0);
  5854. I915_WRITE(OGW1, 0);
  5855. I915_WRITE(EG0, 0x00007f00);
  5856. I915_WRITE(EG1, 0x0000000e);
  5857. I915_WRITE(EG2, 0x000e0000);
  5858. I915_WRITE(EG3, 0x68000300);
  5859. I915_WRITE(EG4, 0x42000000);
  5860. I915_WRITE(EG5, 0x00140031);
  5861. I915_WRITE(EG6, 0);
  5862. I915_WRITE(EG7, 0);
  5863. for (i = 0; i < 8; i++)
  5864. I915_WRITE(PXWL + (i * 4), 0);
  5865. /* Enable PMON + select events */
  5866. I915_WRITE(ECR, 0x80000019);
  5867. lcfuse = I915_READ(LCFUSE02);
  5868. dev_priv->corr = (lcfuse & LCFUSE_HIV_MASK);
  5869. }
  5870. void gen6_enable_rps(struct drm_i915_private *dev_priv)
  5871. {
  5872. u32 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
  5873. u32 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
  5874. u32 pcu_mbox;
  5875. int cur_freq, min_freq, max_freq;
  5876. int i;
  5877. /* Here begins a magic sequence of register writes to enable
  5878. * auto-downclocking.
  5879. *
  5880. * Perhaps there might be some value in exposing these to
  5881. * userspace...
  5882. */
  5883. I915_WRITE(GEN6_RC_STATE, 0);
  5884. __gen6_force_wake_get(dev_priv);
  5885. /* disable the counters and set deterministic thresholds */
  5886. I915_WRITE(GEN6_RC_CONTROL, 0);
  5887. I915_WRITE(GEN6_RC1_WAKE_RATE_LIMIT, 1000 << 16);
  5888. I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16 | 30);
  5889. I915_WRITE(GEN6_RC6pp_WAKE_RATE_LIMIT, 30);
  5890. I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000);
  5891. I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25);
  5892. for (i = 0; i < I915_NUM_RINGS; i++)
  5893. I915_WRITE(RING_MAX_IDLE(dev_priv->ring[i].mmio_base), 10);
  5894. I915_WRITE(GEN6_RC_SLEEP, 0);
  5895. I915_WRITE(GEN6_RC1e_THRESHOLD, 1000);
  5896. I915_WRITE(GEN6_RC6_THRESHOLD, 50000);
  5897. I915_WRITE(GEN6_RC6p_THRESHOLD, 100000);
  5898. I915_WRITE(GEN6_RC6pp_THRESHOLD, 64000); /* unused */
  5899. I915_WRITE(GEN6_RC_CONTROL,
  5900. GEN6_RC_CTL_RC6p_ENABLE |
  5901. GEN6_RC_CTL_RC6_ENABLE |
  5902. GEN6_RC_CTL_EI_MODE(1) |
  5903. GEN6_RC_CTL_HW_ENABLE);
  5904. I915_WRITE(GEN6_RPNSWREQ,
  5905. GEN6_FREQUENCY(10) |
  5906. GEN6_OFFSET(0) |
  5907. GEN6_AGGRESSIVE_TURBO);
  5908. I915_WRITE(GEN6_RC_VIDEO_FREQ,
  5909. GEN6_FREQUENCY(12));
  5910. I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 1000000);
  5911. I915_WRITE(GEN6_RP_INTERRUPT_LIMITS,
  5912. 18 << 24 |
  5913. 6 << 16);
  5914. I915_WRITE(GEN6_RP_UP_THRESHOLD, 10000);
  5915. I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 1000000);
  5916. I915_WRITE(GEN6_RP_UP_EI, 100000);
  5917. I915_WRITE(GEN6_RP_DOWN_EI, 5000000);
  5918. I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10);
  5919. I915_WRITE(GEN6_RP_CONTROL,
  5920. GEN6_RP_MEDIA_TURBO |
  5921. GEN6_RP_USE_NORMAL_FREQ |
  5922. GEN6_RP_MEDIA_IS_GFX |
  5923. GEN6_RP_ENABLE |
  5924. GEN6_RP_UP_BUSY_AVG |
  5925. GEN6_RP_DOWN_IDLE_CONT);
  5926. if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0,
  5927. 500))
  5928. DRM_ERROR("timeout waiting for pcode mailbox to become idle\n");
  5929. I915_WRITE(GEN6_PCODE_DATA, 0);
  5930. I915_WRITE(GEN6_PCODE_MAILBOX,
  5931. GEN6_PCODE_READY |
  5932. GEN6_PCODE_WRITE_MIN_FREQ_TABLE);
  5933. if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0,
  5934. 500))
  5935. DRM_ERROR("timeout waiting for pcode mailbox to finish\n");
  5936. min_freq = (rp_state_cap & 0xff0000) >> 16;
  5937. max_freq = rp_state_cap & 0xff;
  5938. cur_freq = (gt_perf_status & 0xff00) >> 8;
  5939. /* Check for overclock support */
  5940. if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0,
  5941. 500))
  5942. DRM_ERROR("timeout waiting for pcode mailbox to become idle\n");
  5943. I915_WRITE(GEN6_PCODE_MAILBOX, GEN6_READ_OC_PARAMS);
  5944. pcu_mbox = I915_READ(GEN6_PCODE_DATA);
  5945. if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0,
  5946. 500))
  5947. DRM_ERROR("timeout waiting for pcode mailbox to finish\n");
  5948. if (pcu_mbox & (1<<31)) { /* OC supported */
  5949. max_freq = pcu_mbox & 0xff;
  5950. DRM_DEBUG_DRIVER("overclocking supported, adjusting frequency max to %dMHz\n", pcu_mbox * 100);
  5951. }
  5952. /* In units of 100MHz */
  5953. dev_priv->max_delay = max_freq;
  5954. dev_priv->min_delay = min_freq;
  5955. dev_priv->cur_delay = cur_freq;
  5956. /* requires MSI enabled */
  5957. I915_WRITE(GEN6_PMIER,
  5958. GEN6_PM_MBOX_EVENT |
  5959. GEN6_PM_THERMAL_EVENT |
  5960. GEN6_PM_RP_DOWN_TIMEOUT |
  5961. GEN6_PM_RP_UP_THRESHOLD |
  5962. GEN6_PM_RP_DOWN_THRESHOLD |
  5963. GEN6_PM_RP_UP_EI_EXPIRED |
  5964. GEN6_PM_RP_DOWN_EI_EXPIRED);
  5965. I915_WRITE(GEN6_PMIMR, 0);
  5966. /* enable all PM interrupts */
  5967. I915_WRITE(GEN6_PMINTRMSK, 0);
  5968. __gen6_force_wake_put(dev_priv);
  5969. }
  5970. void intel_enable_clock_gating(struct drm_device *dev)
  5971. {
  5972. struct drm_i915_private *dev_priv = dev->dev_private;
  5973. int pipe;
  5974. /*
  5975. * Disable clock gating reported to work incorrectly according to the
  5976. * specs, but enable as much else as we can.
  5977. */
  5978. if (HAS_PCH_SPLIT(dev)) {
  5979. uint32_t dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE;
  5980. if (IS_GEN5(dev)) {
  5981. /* Required for FBC */
  5982. dspclk_gate |= DPFCUNIT_CLOCK_GATE_DISABLE |
  5983. DPFCRUNIT_CLOCK_GATE_DISABLE |
  5984. DPFDUNIT_CLOCK_GATE_DISABLE;
  5985. /* Required for CxSR */
  5986. dspclk_gate |= DPARBUNIT_CLOCK_GATE_DISABLE;
  5987. I915_WRITE(PCH_3DCGDIS0,
  5988. MARIUNIT_CLOCK_GATE_DISABLE |
  5989. SVSMUNIT_CLOCK_GATE_DISABLE);
  5990. I915_WRITE(PCH_3DCGDIS1,
  5991. VFMUNIT_CLOCK_GATE_DISABLE);
  5992. }
  5993. I915_WRITE(PCH_DSPCLK_GATE_D, dspclk_gate);
  5994. /*
  5995. * On Ibex Peak and Cougar Point, we need to disable clock
  5996. * gating for the panel power sequencer or it will fail to
  5997. * start up when no ports are active.
  5998. */
  5999. I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE);
  6000. /*
  6001. * According to the spec the following bits should be set in
  6002. * order to enable memory self-refresh
  6003. * The bit 22/21 of 0x42004
  6004. * The bit 5 of 0x42020
  6005. * The bit 15 of 0x45000
  6006. */
  6007. if (IS_GEN5(dev)) {
  6008. I915_WRITE(ILK_DISPLAY_CHICKEN2,
  6009. (I915_READ(ILK_DISPLAY_CHICKEN2) |
  6010. ILK_DPARB_GATE | ILK_VSDPFD_FULL));
  6011. I915_WRITE(ILK_DSPCLK_GATE,
  6012. (I915_READ(ILK_DSPCLK_GATE) |
  6013. ILK_DPARB_CLK_GATE));
  6014. I915_WRITE(DISP_ARB_CTL,
  6015. (I915_READ(DISP_ARB_CTL) |
  6016. DISP_FBC_WM_DIS));
  6017. I915_WRITE(WM3_LP_ILK, 0);
  6018. I915_WRITE(WM2_LP_ILK, 0);
  6019. I915_WRITE(WM1_LP_ILK, 0);
  6020. }
  6021. /*
  6022. * Based on the document from hardware guys the following bits
  6023. * should be set unconditionally in order to enable FBC.
  6024. * The bit 22 of 0x42000
  6025. * The bit 22 of 0x42004
  6026. * The bit 7,8,9 of 0x42020.
  6027. */
  6028. if (IS_IRONLAKE_M(dev)) {
  6029. I915_WRITE(ILK_DISPLAY_CHICKEN1,
  6030. I915_READ(ILK_DISPLAY_CHICKEN1) |
  6031. ILK_FBCQ_DIS);
  6032. I915_WRITE(ILK_DISPLAY_CHICKEN2,
  6033. I915_READ(ILK_DISPLAY_CHICKEN2) |
  6034. ILK_DPARB_GATE);
  6035. I915_WRITE(ILK_DSPCLK_GATE,
  6036. I915_READ(ILK_DSPCLK_GATE) |
  6037. ILK_DPFC_DIS1 |
  6038. ILK_DPFC_DIS2 |
  6039. ILK_CLK_FBC);
  6040. }
  6041. I915_WRITE(ILK_DISPLAY_CHICKEN2,
  6042. I915_READ(ILK_DISPLAY_CHICKEN2) |
  6043. ILK_ELPIN_409_SELECT);
  6044. if (IS_GEN5(dev)) {
  6045. I915_WRITE(_3D_CHICKEN2,
  6046. _3D_CHICKEN2_WM_READ_PIPELINED << 16 |
  6047. _3D_CHICKEN2_WM_READ_PIPELINED);
  6048. }
  6049. if (IS_GEN6(dev)) {
  6050. I915_WRITE(WM3_LP_ILK, 0);
  6051. I915_WRITE(WM2_LP_ILK, 0);
  6052. I915_WRITE(WM1_LP_ILK, 0);
  6053. /*
  6054. * According to the spec the following bits should be
  6055. * set in order to enable memory self-refresh and fbc:
  6056. * The bit21 and bit22 of 0x42000
  6057. * The bit21 and bit22 of 0x42004
  6058. * The bit5 and bit7 of 0x42020
  6059. * The bit14 of 0x70180
  6060. * The bit14 of 0x71180
  6061. */
  6062. I915_WRITE(ILK_DISPLAY_CHICKEN1,
  6063. I915_READ(ILK_DISPLAY_CHICKEN1) |
  6064. ILK_FBCQ_DIS | ILK_PABSTRETCH_DIS);
  6065. I915_WRITE(ILK_DISPLAY_CHICKEN2,
  6066. I915_READ(ILK_DISPLAY_CHICKEN2) |
  6067. ILK_DPARB_GATE | ILK_VSDPFD_FULL);
  6068. I915_WRITE(ILK_DSPCLK_GATE,
  6069. I915_READ(ILK_DSPCLK_GATE) |
  6070. ILK_DPARB_CLK_GATE |
  6071. ILK_DPFD_CLK_GATE);
  6072. for_each_pipe(pipe)
  6073. I915_WRITE(DSPCNTR(pipe),
  6074. I915_READ(DSPCNTR(pipe)) |
  6075. DISPPLANE_TRICKLE_FEED_DISABLE);
  6076. }
  6077. } else if (IS_G4X(dev)) {
  6078. uint32_t dspclk_gate;
  6079. I915_WRITE(RENCLK_GATE_D1, 0);
  6080. I915_WRITE(RENCLK_GATE_D2, VF_UNIT_CLOCK_GATE_DISABLE |
  6081. GS_UNIT_CLOCK_GATE_DISABLE |
  6082. CL_UNIT_CLOCK_GATE_DISABLE);
  6083. I915_WRITE(RAMCLK_GATE_D, 0);
  6084. dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE |
  6085. OVRUNIT_CLOCK_GATE_DISABLE |
  6086. OVCUNIT_CLOCK_GATE_DISABLE;
  6087. if (IS_GM45(dev))
  6088. dspclk_gate |= DSSUNIT_CLOCK_GATE_DISABLE;
  6089. I915_WRITE(DSPCLK_GATE_D, dspclk_gate);
  6090. } else if (IS_CRESTLINE(dev)) {
  6091. I915_WRITE(RENCLK_GATE_D1, I965_RCC_CLOCK_GATE_DISABLE);
  6092. I915_WRITE(RENCLK_GATE_D2, 0);
  6093. I915_WRITE(DSPCLK_GATE_D, 0);
  6094. I915_WRITE(RAMCLK_GATE_D, 0);
  6095. I915_WRITE16(DEUC, 0);
  6096. } else if (IS_BROADWATER(dev)) {
  6097. I915_WRITE(RENCLK_GATE_D1, I965_RCZ_CLOCK_GATE_DISABLE |
  6098. I965_RCC_CLOCK_GATE_DISABLE |
  6099. I965_RCPB_CLOCK_GATE_DISABLE |
  6100. I965_ISC_CLOCK_GATE_DISABLE |
  6101. I965_FBC_CLOCK_GATE_DISABLE);
  6102. I915_WRITE(RENCLK_GATE_D2, 0);
  6103. } else if (IS_GEN3(dev)) {
  6104. u32 dstate = I915_READ(D_STATE);
  6105. dstate |= DSTATE_PLL_D3_OFF | DSTATE_GFX_CLOCK_GATING |
  6106. DSTATE_DOT_CLOCK_GATING;
  6107. I915_WRITE(D_STATE, dstate);
  6108. } else if (IS_I85X(dev) || IS_I865G(dev)) {
  6109. I915_WRITE(RENCLK_GATE_D1, SV_CLOCK_GATE_DISABLE);
  6110. } else if (IS_I830(dev)) {
  6111. I915_WRITE(DSPCLK_GATE_D, OVRUNIT_CLOCK_GATE_DISABLE);
  6112. }
  6113. }
  6114. static void ironlake_teardown_rc6(struct drm_device *dev)
  6115. {
  6116. struct drm_i915_private *dev_priv = dev->dev_private;
  6117. if (dev_priv->renderctx) {
  6118. i915_gem_object_unpin(dev_priv->renderctx);
  6119. drm_gem_object_unreference(&dev_priv->renderctx->base);
  6120. dev_priv->renderctx = NULL;
  6121. }
  6122. if (dev_priv->pwrctx) {
  6123. i915_gem_object_unpin(dev_priv->pwrctx);
  6124. drm_gem_object_unreference(&dev_priv->pwrctx->base);
  6125. dev_priv->pwrctx = NULL;
  6126. }
  6127. }
  6128. static void ironlake_disable_rc6(struct drm_device *dev)
  6129. {
  6130. struct drm_i915_private *dev_priv = dev->dev_private;
  6131. if (I915_READ(PWRCTXA)) {
  6132. /* Wake the GPU, prevent RC6, then restore RSTDBYCTL */
  6133. I915_WRITE(RSTDBYCTL, I915_READ(RSTDBYCTL) | RCX_SW_EXIT);
  6134. wait_for(((I915_READ(RSTDBYCTL) & RSX_STATUS_MASK) == RSX_STATUS_ON),
  6135. 50);
  6136. I915_WRITE(PWRCTXA, 0);
  6137. POSTING_READ(PWRCTXA);
  6138. I915_WRITE(RSTDBYCTL, I915_READ(RSTDBYCTL) & ~RCX_SW_EXIT);
  6139. POSTING_READ(RSTDBYCTL);
  6140. }
  6141. ironlake_disable_rc6(dev);
  6142. }
  6143. static int ironlake_setup_rc6(struct drm_device *dev)
  6144. {
  6145. struct drm_i915_private *dev_priv = dev->dev_private;
  6146. if (dev_priv->renderctx == NULL)
  6147. dev_priv->renderctx = intel_alloc_context_page(dev);
  6148. if (!dev_priv->renderctx)
  6149. return -ENOMEM;
  6150. if (dev_priv->pwrctx == NULL)
  6151. dev_priv->pwrctx = intel_alloc_context_page(dev);
  6152. if (!dev_priv->pwrctx) {
  6153. ironlake_teardown_rc6(dev);
  6154. return -ENOMEM;
  6155. }
  6156. return 0;
  6157. }
  6158. void ironlake_enable_rc6(struct drm_device *dev)
  6159. {
  6160. struct drm_i915_private *dev_priv = dev->dev_private;
  6161. int ret;
  6162. /* rc6 disabled by default due to repeated reports of hanging during
  6163. * boot and resume.
  6164. */
  6165. if (!i915_enable_rc6)
  6166. return;
  6167. ret = ironlake_setup_rc6(dev);
  6168. if (ret)
  6169. return;
  6170. /*
  6171. * GPU can automatically power down the render unit if given a page
  6172. * to save state.
  6173. */
  6174. ret = BEGIN_LP_RING(6);
  6175. if (ret) {
  6176. ironlake_teardown_rc6(dev);
  6177. return;
  6178. }
  6179. OUT_RING(MI_SUSPEND_FLUSH | MI_SUSPEND_FLUSH_EN);
  6180. OUT_RING(MI_SET_CONTEXT);
  6181. OUT_RING(dev_priv->renderctx->gtt_offset |
  6182. MI_MM_SPACE_GTT |
  6183. MI_SAVE_EXT_STATE_EN |
  6184. MI_RESTORE_EXT_STATE_EN |
  6185. MI_RESTORE_INHIBIT);
  6186. OUT_RING(MI_SUSPEND_FLUSH);
  6187. OUT_RING(MI_NOOP);
  6188. OUT_RING(MI_FLUSH);
  6189. ADVANCE_LP_RING();
  6190. I915_WRITE(PWRCTXA, dev_priv->pwrctx->gtt_offset | PWRCTX_EN);
  6191. I915_WRITE(RSTDBYCTL, I915_READ(RSTDBYCTL) & ~RCX_SW_EXIT);
  6192. }
  6193. /* Set up chip specific display functions */
  6194. static void intel_init_display(struct drm_device *dev)
  6195. {
  6196. struct drm_i915_private *dev_priv = dev->dev_private;
  6197. /* We always want a DPMS function */
  6198. if (HAS_PCH_SPLIT(dev))
  6199. dev_priv->display.dpms = ironlake_crtc_dpms;
  6200. else
  6201. dev_priv->display.dpms = i9xx_crtc_dpms;
  6202. if (I915_HAS_FBC(dev)) {
  6203. if (HAS_PCH_SPLIT(dev)) {
  6204. dev_priv->display.fbc_enabled = ironlake_fbc_enabled;
  6205. dev_priv->display.enable_fbc = ironlake_enable_fbc;
  6206. dev_priv->display.disable_fbc = ironlake_disable_fbc;
  6207. } else if (IS_GM45(dev)) {
  6208. dev_priv->display.fbc_enabled = g4x_fbc_enabled;
  6209. dev_priv->display.enable_fbc = g4x_enable_fbc;
  6210. dev_priv->display.disable_fbc = g4x_disable_fbc;
  6211. } else if (IS_CRESTLINE(dev)) {
  6212. dev_priv->display.fbc_enabled = i8xx_fbc_enabled;
  6213. dev_priv->display.enable_fbc = i8xx_enable_fbc;
  6214. dev_priv->display.disable_fbc = i8xx_disable_fbc;
  6215. }
  6216. /* 855GM needs testing */
  6217. }
  6218. /* Returns the core display clock speed */
  6219. if (IS_I945G(dev) || (IS_G33(dev) && ! IS_PINEVIEW_M(dev)))
  6220. dev_priv->display.get_display_clock_speed =
  6221. i945_get_display_clock_speed;
  6222. else if (IS_I915G(dev))
  6223. dev_priv->display.get_display_clock_speed =
  6224. i915_get_display_clock_speed;
  6225. else if (IS_I945GM(dev) || IS_845G(dev) || IS_PINEVIEW_M(dev))
  6226. dev_priv->display.get_display_clock_speed =
  6227. i9xx_misc_get_display_clock_speed;
  6228. else if (IS_I915GM(dev))
  6229. dev_priv->display.get_display_clock_speed =
  6230. i915gm_get_display_clock_speed;
  6231. else if (IS_I865G(dev))
  6232. dev_priv->display.get_display_clock_speed =
  6233. i865_get_display_clock_speed;
  6234. else if (IS_I85X(dev))
  6235. dev_priv->display.get_display_clock_speed =
  6236. i855_get_display_clock_speed;
  6237. else /* 852, 830 */
  6238. dev_priv->display.get_display_clock_speed =
  6239. i830_get_display_clock_speed;
  6240. /* For FIFO watermark updates */
  6241. if (HAS_PCH_SPLIT(dev)) {
  6242. if (IS_GEN5(dev)) {
  6243. if (I915_READ(MLTR_ILK) & ILK_SRLT_MASK)
  6244. dev_priv->display.update_wm = ironlake_update_wm;
  6245. else {
  6246. DRM_DEBUG_KMS("Failed to get proper latency. "
  6247. "Disable CxSR\n");
  6248. dev_priv->display.update_wm = NULL;
  6249. }
  6250. } else if (IS_GEN6(dev)) {
  6251. if (SNB_READ_WM0_LATENCY()) {
  6252. dev_priv->display.update_wm = sandybridge_update_wm;
  6253. } else {
  6254. DRM_DEBUG_KMS("Failed to read display plane latency. "
  6255. "Disable CxSR\n");
  6256. dev_priv->display.update_wm = NULL;
  6257. }
  6258. } else
  6259. dev_priv->display.update_wm = NULL;
  6260. } else if (IS_PINEVIEW(dev)) {
  6261. if (!intel_get_cxsr_latency(IS_PINEVIEW_G(dev),
  6262. dev_priv->is_ddr3,
  6263. dev_priv->fsb_freq,
  6264. dev_priv->mem_freq)) {
  6265. DRM_INFO("failed to find known CxSR latency "
  6266. "(found ddr%s fsb freq %d, mem freq %d), "
  6267. "disabling CxSR\n",
  6268. (dev_priv->is_ddr3 == 1) ? "3": "2",
  6269. dev_priv->fsb_freq, dev_priv->mem_freq);
  6270. /* Disable CxSR and never update its watermark again */
  6271. pineview_disable_cxsr(dev);
  6272. dev_priv->display.update_wm = NULL;
  6273. } else
  6274. dev_priv->display.update_wm = pineview_update_wm;
  6275. } else if (IS_G4X(dev))
  6276. dev_priv->display.update_wm = g4x_update_wm;
  6277. else if (IS_GEN4(dev))
  6278. dev_priv->display.update_wm = i965_update_wm;
  6279. else if (IS_GEN3(dev)) {
  6280. dev_priv->display.update_wm = i9xx_update_wm;
  6281. dev_priv->display.get_fifo_size = i9xx_get_fifo_size;
  6282. } else if (IS_I85X(dev)) {
  6283. dev_priv->display.update_wm = i9xx_update_wm;
  6284. dev_priv->display.get_fifo_size = i85x_get_fifo_size;
  6285. } else {
  6286. dev_priv->display.update_wm = i830_update_wm;
  6287. if (IS_845G(dev))
  6288. dev_priv->display.get_fifo_size = i845_get_fifo_size;
  6289. else
  6290. dev_priv->display.get_fifo_size = i830_get_fifo_size;
  6291. }
  6292. }
  6293. /*
  6294. * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend,
  6295. * resume, or other times. This quirk makes sure that's the case for
  6296. * affected systems.
  6297. */
  6298. static void quirk_pipea_force (struct drm_device *dev)
  6299. {
  6300. struct drm_i915_private *dev_priv = dev->dev_private;
  6301. dev_priv->quirks |= QUIRK_PIPEA_FORCE;
  6302. DRM_DEBUG_DRIVER("applying pipe a force quirk\n");
  6303. }
  6304. struct intel_quirk {
  6305. int device;
  6306. int subsystem_vendor;
  6307. int subsystem_device;
  6308. void (*hook)(struct drm_device *dev);
  6309. };
  6310. struct intel_quirk intel_quirks[] = {
  6311. /* HP Compaq 2730p needs pipe A force quirk (LP: #291555) */
  6312. { 0x2a42, 0x103c, 0x30eb, quirk_pipea_force },
  6313. /* HP Mini needs pipe A force quirk (LP: #322104) */
  6314. { 0x27ae,0x103c, 0x361a, quirk_pipea_force },
  6315. /* Thinkpad R31 needs pipe A force quirk */
  6316. { 0x3577, 0x1014, 0x0505, quirk_pipea_force },
  6317. /* Toshiba Protege R-205, S-209 needs pipe A force quirk */
  6318. { 0x2592, 0x1179, 0x0001, quirk_pipea_force },
  6319. /* ThinkPad X30 needs pipe A force quirk (LP: #304614) */
  6320. { 0x3577, 0x1014, 0x0513, quirk_pipea_force },
  6321. /* ThinkPad X40 needs pipe A force quirk */
  6322. /* ThinkPad T60 needs pipe A force quirk (bug #16494) */
  6323. { 0x2782, 0x17aa, 0x201a, quirk_pipea_force },
  6324. /* 855 & before need to leave pipe A & dpll A up */
  6325. { 0x3582, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force },
  6326. { 0x2562, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force },
  6327. };
  6328. static void intel_init_quirks(struct drm_device *dev)
  6329. {
  6330. struct pci_dev *d = dev->pdev;
  6331. int i;
  6332. for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) {
  6333. struct intel_quirk *q = &intel_quirks[i];
  6334. if (d->device == q->device &&
  6335. (d->subsystem_vendor == q->subsystem_vendor ||
  6336. q->subsystem_vendor == PCI_ANY_ID) &&
  6337. (d->subsystem_device == q->subsystem_device ||
  6338. q->subsystem_device == PCI_ANY_ID))
  6339. q->hook(dev);
  6340. }
  6341. }
  6342. /* Disable the VGA plane that we never use */
  6343. static void i915_disable_vga(struct drm_device *dev)
  6344. {
  6345. struct drm_i915_private *dev_priv = dev->dev_private;
  6346. u8 sr1;
  6347. u32 vga_reg;
  6348. if (HAS_PCH_SPLIT(dev))
  6349. vga_reg = CPU_VGACNTRL;
  6350. else
  6351. vga_reg = VGACNTRL;
  6352. vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO);
  6353. outb(1, VGA_SR_INDEX);
  6354. sr1 = inb(VGA_SR_DATA);
  6355. outb(sr1 | 1<<5, VGA_SR_DATA);
  6356. vga_put(dev->pdev, VGA_RSRC_LEGACY_IO);
  6357. udelay(300);
  6358. I915_WRITE(vga_reg, VGA_DISP_DISABLE);
  6359. POSTING_READ(vga_reg);
  6360. }
  6361. void intel_modeset_init(struct drm_device *dev)
  6362. {
  6363. struct drm_i915_private *dev_priv = dev->dev_private;
  6364. int i;
  6365. drm_mode_config_init(dev);
  6366. dev->mode_config.min_width = 0;
  6367. dev->mode_config.min_height = 0;
  6368. dev->mode_config.funcs = (void *)&intel_mode_funcs;
  6369. intel_init_quirks(dev);
  6370. intel_init_display(dev);
  6371. if (IS_GEN2(dev)) {
  6372. dev->mode_config.max_width = 2048;
  6373. dev->mode_config.max_height = 2048;
  6374. } else if (IS_GEN3(dev)) {
  6375. dev->mode_config.max_width = 4096;
  6376. dev->mode_config.max_height = 4096;
  6377. } else {
  6378. dev->mode_config.max_width = 8192;
  6379. dev->mode_config.max_height = 8192;
  6380. }
  6381. dev->mode_config.fb_base = dev->agp->base;
  6382. DRM_DEBUG_KMS("%d display pipe%s available.\n",
  6383. dev_priv->num_pipe, dev_priv->num_pipe > 1 ? "s" : "");
  6384. for (i = 0; i < dev_priv->num_pipe; i++) {
  6385. intel_crtc_init(dev, i);
  6386. }
  6387. intel_setup_outputs(dev);
  6388. intel_enable_clock_gating(dev);
  6389. /* Just disable it once at startup */
  6390. i915_disable_vga(dev);
  6391. if (IS_IRONLAKE_M(dev)) {
  6392. ironlake_enable_drps(dev);
  6393. intel_init_emon(dev);
  6394. }
  6395. if (IS_GEN6(dev))
  6396. gen6_enable_rps(dev_priv);
  6397. if (IS_IRONLAKE_M(dev))
  6398. ironlake_enable_rc6(dev);
  6399. INIT_WORK(&dev_priv->idle_work, intel_idle_update);
  6400. setup_timer(&dev_priv->idle_timer, intel_gpu_idle_timer,
  6401. (unsigned long)dev);
  6402. intel_setup_overlay(dev);
  6403. }
  6404. void intel_modeset_cleanup(struct drm_device *dev)
  6405. {
  6406. struct drm_i915_private *dev_priv = dev->dev_private;
  6407. struct drm_crtc *crtc;
  6408. struct intel_crtc *intel_crtc;
  6409. drm_kms_helper_poll_fini(dev);
  6410. mutex_lock(&dev->struct_mutex);
  6411. intel_unregister_dsm_handler();
  6412. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  6413. /* Skip inactive CRTCs */
  6414. if (!crtc->fb)
  6415. continue;
  6416. intel_crtc = to_intel_crtc(crtc);
  6417. intel_increase_pllclock(crtc);
  6418. }
  6419. if (dev_priv->display.disable_fbc)
  6420. dev_priv->display.disable_fbc(dev);
  6421. if (IS_IRONLAKE_M(dev))
  6422. ironlake_disable_drps(dev);
  6423. if (IS_GEN6(dev))
  6424. gen6_disable_rps(dev);
  6425. if (IS_IRONLAKE_M(dev))
  6426. ironlake_disable_rc6(dev);
  6427. mutex_unlock(&dev->struct_mutex);
  6428. /* Disable the irq before mode object teardown, for the irq might
  6429. * enqueue unpin/hotplug work. */
  6430. drm_irq_uninstall(dev);
  6431. cancel_work_sync(&dev_priv->hotplug_work);
  6432. /* Shut off idle work before the crtcs get freed. */
  6433. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  6434. intel_crtc = to_intel_crtc(crtc);
  6435. del_timer_sync(&intel_crtc->idle_timer);
  6436. }
  6437. del_timer_sync(&dev_priv->idle_timer);
  6438. cancel_work_sync(&dev_priv->idle_work);
  6439. drm_mode_config_cleanup(dev);
  6440. }
  6441. /*
  6442. * Return which encoder is currently attached for connector.
  6443. */
  6444. struct drm_encoder *intel_best_encoder(struct drm_connector *connector)
  6445. {
  6446. return &intel_attached_encoder(connector)->base;
  6447. }
  6448. void intel_connector_attach_encoder(struct intel_connector *connector,
  6449. struct intel_encoder *encoder)
  6450. {
  6451. connector->encoder = encoder;
  6452. drm_mode_connector_attach_encoder(&connector->base,
  6453. &encoder->base);
  6454. }
  6455. /*
  6456. * set vga decode state - true == enable VGA decode
  6457. */
  6458. int intel_modeset_vga_set_state(struct drm_device *dev, bool state)
  6459. {
  6460. struct drm_i915_private *dev_priv = dev->dev_private;
  6461. u16 gmch_ctrl;
  6462. pci_read_config_word(dev_priv->bridge_dev, INTEL_GMCH_CTRL, &gmch_ctrl);
  6463. if (state)
  6464. gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE;
  6465. else
  6466. gmch_ctrl |= INTEL_GMCH_VGA_DISABLE;
  6467. pci_write_config_word(dev_priv->bridge_dev, INTEL_GMCH_CTRL, gmch_ctrl);
  6468. return 0;
  6469. }
  6470. #ifdef CONFIG_DEBUG_FS
  6471. #include <linux/seq_file.h>
  6472. struct intel_display_error_state {
  6473. struct intel_cursor_error_state {
  6474. u32 control;
  6475. u32 position;
  6476. u32 base;
  6477. u32 size;
  6478. } cursor[2];
  6479. struct intel_pipe_error_state {
  6480. u32 conf;
  6481. u32 source;
  6482. u32 htotal;
  6483. u32 hblank;
  6484. u32 hsync;
  6485. u32 vtotal;
  6486. u32 vblank;
  6487. u32 vsync;
  6488. } pipe[2];
  6489. struct intel_plane_error_state {
  6490. u32 control;
  6491. u32 stride;
  6492. u32 size;
  6493. u32 pos;
  6494. u32 addr;
  6495. u32 surface;
  6496. u32 tile_offset;
  6497. } plane[2];
  6498. };
  6499. struct intel_display_error_state *
  6500. intel_display_capture_error_state(struct drm_device *dev)
  6501. {
  6502. drm_i915_private_t *dev_priv = dev->dev_private;
  6503. struct intel_display_error_state *error;
  6504. int i;
  6505. error = kmalloc(sizeof(*error), GFP_ATOMIC);
  6506. if (error == NULL)
  6507. return NULL;
  6508. for (i = 0; i < 2; i++) {
  6509. error->cursor[i].control = I915_READ(CURCNTR(i));
  6510. error->cursor[i].position = I915_READ(CURPOS(i));
  6511. error->cursor[i].base = I915_READ(CURBASE(i));
  6512. error->plane[i].control = I915_READ(DSPCNTR(i));
  6513. error->plane[i].stride = I915_READ(DSPSTRIDE(i));
  6514. error->plane[i].size = I915_READ(DSPSIZE(i));
  6515. error->plane[i].pos= I915_READ(DSPPOS(i));
  6516. error->plane[i].addr = I915_READ(DSPADDR(i));
  6517. if (INTEL_INFO(dev)->gen >= 4) {
  6518. error->plane[i].surface = I915_READ(DSPSURF(i));
  6519. error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i));
  6520. }
  6521. error->pipe[i].conf = I915_READ(PIPECONF(i));
  6522. error->pipe[i].source = I915_READ(PIPESRC(i));
  6523. error->pipe[i].htotal = I915_READ(HTOTAL(i));
  6524. error->pipe[i].hblank = I915_READ(HBLANK(i));
  6525. error->pipe[i].hsync = I915_READ(HSYNC(i));
  6526. error->pipe[i].vtotal = I915_READ(VTOTAL(i));
  6527. error->pipe[i].vblank = I915_READ(VBLANK(i));
  6528. error->pipe[i].vsync = I915_READ(VSYNC(i));
  6529. }
  6530. return error;
  6531. }
  6532. void
  6533. intel_display_print_error_state(struct seq_file *m,
  6534. struct drm_device *dev,
  6535. struct intel_display_error_state *error)
  6536. {
  6537. int i;
  6538. for (i = 0; i < 2; i++) {
  6539. seq_printf(m, "Pipe [%d]:\n", i);
  6540. seq_printf(m, " CONF: %08x\n", error->pipe[i].conf);
  6541. seq_printf(m, " SRC: %08x\n", error->pipe[i].source);
  6542. seq_printf(m, " HTOTAL: %08x\n", error->pipe[i].htotal);
  6543. seq_printf(m, " HBLANK: %08x\n", error->pipe[i].hblank);
  6544. seq_printf(m, " HSYNC: %08x\n", error->pipe[i].hsync);
  6545. seq_printf(m, " VTOTAL: %08x\n", error->pipe[i].vtotal);
  6546. seq_printf(m, " VBLANK: %08x\n", error->pipe[i].vblank);
  6547. seq_printf(m, " VSYNC: %08x\n", error->pipe[i].vsync);
  6548. seq_printf(m, "Plane [%d]:\n", i);
  6549. seq_printf(m, " CNTR: %08x\n", error->plane[i].control);
  6550. seq_printf(m, " STRIDE: %08x\n", error->plane[i].stride);
  6551. seq_printf(m, " SIZE: %08x\n", error->plane[i].size);
  6552. seq_printf(m, " POS: %08x\n", error->plane[i].pos);
  6553. seq_printf(m, " ADDR: %08x\n", error->plane[i].addr);
  6554. if (INTEL_INFO(dev)->gen >= 4) {
  6555. seq_printf(m, " SURF: %08x\n", error->plane[i].surface);
  6556. seq_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset);
  6557. }
  6558. seq_printf(m, "Cursor [%d]:\n", i);
  6559. seq_printf(m, " CNTR: %08x\n", error->cursor[i].control);
  6560. seq_printf(m, " POS: %08x\n", error->cursor[i].position);
  6561. seq_printf(m, " BASE: %08x\n", error->cursor[i].base);
  6562. }
  6563. }
  6564. #endif