si.c 184 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230
  1. /*
  2. * Copyright 2011 Advanced Micro Devices, Inc.
  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 shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * Authors: Alex Deucher
  23. */
  24. #include <linux/firmware.h>
  25. #include <linux/platform_device.h>
  26. #include <linux/slab.h>
  27. #include <linux/module.h>
  28. #include <drm/drmP.h>
  29. #include "radeon.h"
  30. #include "radeon_asic.h"
  31. #include <drm/radeon_drm.h>
  32. #include "sid.h"
  33. #include "atom.h"
  34. #include "si_blit_shaders.h"
  35. #define SI_PFP_UCODE_SIZE 2144
  36. #define SI_PM4_UCODE_SIZE 2144
  37. #define SI_CE_UCODE_SIZE 2144
  38. #define SI_RLC_UCODE_SIZE 2048
  39. #define SI_MC_UCODE_SIZE 7769
  40. #define OLAND_MC_UCODE_SIZE 7863
  41. MODULE_FIRMWARE("radeon/TAHITI_pfp.bin");
  42. MODULE_FIRMWARE("radeon/TAHITI_me.bin");
  43. MODULE_FIRMWARE("radeon/TAHITI_ce.bin");
  44. MODULE_FIRMWARE("radeon/TAHITI_mc.bin");
  45. MODULE_FIRMWARE("radeon/TAHITI_rlc.bin");
  46. MODULE_FIRMWARE("radeon/PITCAIRN_pfp.bin");
  47. MODULE_FIRMWARE("radeon/PITCAIRN_me.bin");
  48. MODULE_FIRMWARE("radeon/PITCAIRN_ce.bin");
  49. MODULE_FIRMWARE("radeon/PITCAIRN_mc.bin");
  50. MODULE_FIRMWARE("radeon/PITCAIRN_rlc.bin");
  51. MODULE_FIRMWARE("radeon/VERDE_pfp.bin");
  52. MODULE_FIRMWARE("radeon/VERDE_me.bin");
  53. MODULE_FIRMWARE("radeon/VERDE_ce.bin");
  54. MODULE_FIRMWARE("radeon/VERDE_mc.bin");
  55. MODULE_FIRMWARE("radeon/VERDE_rlc.bin");
  56. MODULE_FIRMWARE("radeon/OLAND_pfp.bin");
  57. MODULE_FIRMWARE("radeon/OLAND_me.bin");
  58. MODULE_FIRMWARE("radeon/OLAND_ce.bin");
  59. MODULE_FIRMWARE("radeon/OLAND_mc.bin");
  60. MODULE_FIRMWARE("radeon/OLAND_rlc.bin");
  61. MODULE_FIRMWARE("radeon/HAINAN_pfp.bin");
  62. MODULE_FIRMWARE("radeon/HAINAN_me.bin");
  63. MODULE_FIRMWARE("radeon/HAINAN_ce.bin");
  64. MODULE_FIRMWARE("radeon/HAINAN_mc.bin");
  65. MODULE_FIRMWARE("radeon/HAINAN_rlc.bin");
  66. static void si_pcie_gen3_enable(struct radeon_device *rdev);
  67. static void si_program_aspm(struct radeon_device *rdev);
  68. extern int r600_ih_ring_alloc(struct radeon_device *rdev);
  69. extern void r600_ih_ring_fini(struct radeon_device *rdev);
  70. extern void evergreen_fix_pci_max_read_req_size(struct radeon_device *rdev);
  71. extern void evergreen_mc_stop(struct radeon_device *rdev, struct evergreen_mc_save *save);
  72. extern void evergreen_mc_resume(struct radeon_device *rdev, struct evergreen_mc_save *save);
  73. extern u32 evergreen_get_number_of_dram_channels(struct radeon_device *rdev);
  74. extern void evergreen_print_gpu_status_regs(struct radeon_device *rdev);
  75. extern bool evergreen_is_display_hung(struct radeon_device *rdev);
  76. static const u32 tahiti_golden_rlc_registers[] =
  77. {
  78. 0xc424, 0xffffffff, 0x00601005,
  79. 0xc47c, 0xffffffff, 0x10104040,
  80. 0xc488, 0xffffffff, 0x0100000a,
  81. 0xc314, 0xffffffff, 0x00000800,
  82. 0xc30c, 0xffffffff, 0x800000f4,
  83. 0xf4a8, 0xffffffff, 0x00000000
  84. };
  85. static const u32 tahiti_golden_registers[] =
  86. {
  87. 0x9a10, 0x00010000, 0x00018208,
  88. 0x9830, 0xffffffff, 0x00000000,
  89. 0x9834, 0xf00fffff, 0x00000400,
  90. 0x9838, 0x0002021c, 0x00020200,
  91. 0xc78, 0x00000080, 0x00000000,
  92. 0xd030, 0x000300c0, 0x00800040,
  93. 0xd830, 0x000300c0, 0x00800040,
  94. 0x5bb0, 0x000000f0, 0x00000070,
  95. 0x5bc0, 0x00200000, 0x50100000,
  96. 0x7030, 0x31000311, 0x00000011,
  97. 0x277c, 0x00000003, 0x000007ff,
  98. 0x240c, 0x000007ff, 0x00000000,
  99. 0x8a14, 0xf000001f, 0x00000007,
  100. 0x8b24, 0xffffffff, 0x00ffffff,
  101. 0x8b10, 0x0000ff0f, 0x00000000,
  102. 0x28a4c, 0x07ffffff, 0x4e000000,
  103. 0x28350, 0x3f3f3fff, 0x2a00126a,
  104. 0x30, 0x000000ff, 0x0040,
  105. 0x34, 0x00000040, 0x00004040,
  106. 0x9100, 0x07ffffff, 0x03000000,
  107. 0x8e88, 0x01ff1f3f, 0x00000000,
  108. 0x8e84, 0x01ff1f3f, 0x00000000,
  109. 0x9060, 0x0000007f, 0x00000020,
  110. 0x9508, 0x00010000, 0x00010000,
  111. 0xac14, 0x00000200, 0x000002fb,
  112. 0xac10, 0xffffffff, 0x0000543b,
  113. 0xac0c, 0xffffffff, 0xa9210876,
  114. 0x88d0, 0xffffffff, 0x000fff40,
  115. 0x88d4, 0x0000001f, 0x00000010,
  116. 0x1410, 0x20000000, 0x20fffed8,
  117. 0x15c0, 0x000c0fc0, 0x000c0400
  118. };
  119. static const u32 tahiti_golden_registers2[] =
  120. {
  121. 0xc64, 0x00000001, 0x00000001
  122. };
  123. static const u32 pitcairn_golden_rlc_registers[] =
  124. {
  125. 0xc424, 0xffffffff, 0x00601004,
  126. 0xc47c, 0xffffffff, 0x10102020,
  127. 0xc488, 0xffffffff, 0x01000020,
  128. 0xc314, 0xffffffff, 0x00000800,
  129. 0xc30c, 0xffffffff, 0x800000a4
  130. };
  131. static const u32 pitcairn_golden_registers[] =
  132. {
  133. 0x9a10, 0x00010000, 0x00018208,
  134. 0x9830, 0xffffffff, 0x00000000,
  135. 0x9834, 0xf00fffff, 0x00000400,
  136. 0x9838, 0x0002021c, 0x00020200,
  137. 0xc78, 0x00000080, 0x00000000,
  138. 0xd030, 0x000300c0, 0x00800040,
  139. 0xd830, 0x000300c0, 0x00800040,
  140. 0x5bb0, 0x000000f0, 0x00000070,
  141. 0x5bc0, 0x00200000, 0x50100000,
  142. 0x7030, 0x31000311, 0x00000011,
  143. 0x2ae4, 0x00073ffe, 0x000022a2,
  144. 0x240c, 0x000007ff, 0x00000000,
  145. 0x8a14, 0xf000001f, 0x00000007,
  146. 0x8b24, 0xffffffff, 0x00ffffff,
  147. 0x8b10, 0x0000ff0f, 0x00000000,
  148. 0x28a4c, 0x07ffffff, 0x4e000000,
  149. 0x28350, 0x3f3f3fff, 0x2a00126a,
  150. 0x30, 0x000000ff, 0x0040,
  151. 0x34, 0x00000040, 0x00004040,
  152. 0x9100, 0x07ffffff, 0x03000000,
  153. 0x9060, 0x0000007f, 0x00000020,
  154. 0x9508, 0x00010000, 0x00010000,
  155. 0xac14, 0x000003ff, 0x000000f7,
  156. 0xac10, 0xffffffff, 0x00000000,
  157. 0xac0c, 0xffffffff, 0x32761054,
  158. 0x88d4, 0x0000001f, 0x00000010,
  159. 0x15c0, 0x000c0fc0, 0x000c0400
  160. };
  161. static const u32 verde_golden_rlc_registers[] =
  162. {
  163. 0xc424, 0xffffffff, 0x033f1005,
  164. 0xc47c, 0xffffffff, 0x10808020,
  165. 0xc488, 0xffffffff, 0x00800008,
  166. 0xc314, 0xffffffff, 0x00001000,
  167. 0xc30c, 0xffffffff, 0x80010014
  168. };
  169. static const u32 verde_golden_registers[] =
  170. {
  171. 0x9a10, 0x00010000, 0x00018208,
  172. 0x9830, 0xffffffff, 0x00000000,
  173. 0x9834, 0xf00fffff, 0x00000400,
  174. 0x9838, 0x0002021c, 0x00020200,
  175. 0xc78, 0x00000080, 0x00000000,
  176. 0xd030, 0x000300c0, 0x00800040,
  177. 0xd030, 0x000300c0, 0x00800040,
  178. 0xd830, 0x000300c0, 0x00800040,
  179. 0xd830, 0x000300c0, 0x00800040,
  180. 0x5bb0, 0x000000f0, 0x00000070,
  181. 0x5bc0, 0x00200000, 0x50100000,
  182. 0x7030, 0x31000311, 0x00000011,
  183. 0x2ae4, 0x00073ffe, 0x000022a2,
  184. 0x2ae4, 0x00073ffe, 0x000022a2,
  185. 0x2ae4, 0x00073ffe, 0x000022a2,
  186. 0x240c, 0x000007ff, 0x00000000,
  187. 0x240c, 0x000007ff, 0x00000000,
  188. 0x240c, 0x000007ff, 0x00000000,
  189. 0x8a14, 0xf000001f, 0x00000007,
  190. 0x8a14, 0xf000001f, 0x00000007,
  191. 0x8a14, 0xf000001f, 0x00000007,
  192. 0x8b24, 0xffffffff, 0x00ffffff,
  193. 0x8b10, 0x0000ff0f, 0x00000000,
  194. 0x28a4c, 0x07ffffff, 0x4e000000,
  195. 0x28350, 0x3f3f3fff, 0x0000124a,
  196. 0x28350, 0x3f3f3fff, 0x0000124a,
  197. 0x28350, 0x3f3f3fff, 0x0000124a,
  198. 0x30, 0x000000ff, 0x0040,
  199. 0x34, 0x00000040, 0x00004040,
  200. 0x9100, 0x07ffffff, 0x03000000,
  201. 0x9100, 0x07ffffff, 0x03000000,
  202. 0x8e88, 0x01ff1f3f, 0x00000000,
  203. 0x8e88, 0x01ff1f3f, 0x00000000,
  204. 0x8e88, 0x01ff1f3f, 0x00000000,
  205. 0x8e84, 0x01ff1f3f, 0x00000000,
  206. 0x8e84, 0x01ff1f3f, 0x00000000,
  207. 0x8e84, 0x01ff1f3f, 0x00000000,
  208. 0x9060, 0x0000007f, 0x00000020,
  209. 0x9508, 0x00010000, 0x00010000,
  210. 0xac14, 0x000003ff, 0x00000003,
  211. 0xac14, 0x000003ff, 0x00000003,
  212. 0xac14, 0x000003ff, 0x00000003,
  213. 0xac10, 0xffffffff, 0x00000000,
  214. 0xac10, 0xffffffff, 0x00000000,
  215. 0xac10, 0xffffffff, 0x00000000,
  216. 0xac0c, 0xffffffff, 0x00001032,
  217. 0xac0c, 0xffffffff, 0x00001032,
  218. 0xac0c, 0xffffffff, 0x00001032,
  219. 0x88d4, 0x0000001f, 0x00000010,
  220. 0x88d4, 0x0000001f, 0x00000010,
  221. 0x88d4, 0x0000001f, 0x00000010,
  222. 0x15c0, 0x000c0fc0, 0x000c0400
  223. };
  224. static const u32 oland_golden_rlc_registers[] =
  225. {
  226. 0xc424, 0xffffffff, 0x00601005,
  227. 0xc47c, 0xffffffff, 0x10104040,
  228. 0xc488, 0xffffffff, 0x0100000a,
  229. 0xc314, 0xffffffff, 0x00000800,
  230. 0xc30c, 0xffffffff, 0x800000f4
  231. };
  232. static const u32 oland_golden_registers[] =
  233. {
  234. 0x9a10, 0x00010000, 0x00018208,
  235. 0x9830, 0xffffffff, 0x00000000,
  236. 0x9834, 0xf00fffff, 0x00000400,
  237. 0x9838, 0x0002021c, 0x00020200,
  238. 0xc78, 0x00000080, 0x00000000,
  239. 0xd030, 0x000300c0, 0x00800040,
  240. 0xd830, 0x000300c0, 0x00800040,
  241. 0x5bb0, 0x000000f0, 0x00000070,
  242. 0x5bc0, 0x00200000, 0x50100000,
  243. 0x7030, 0x31000311, 0x00000011,
  244. 0x2ae4, 0x00073ffe, 0x000022a2,
  245. 0x240c, 0x000007ff, 0x00000000,
  246. 0x8a14, 0xf000001f, 0x00000007,
  247. 0x8b24, 0xffffffff, 0x00ffffff,
  248. 0x8b10, 0x0000ff0f, 0x00000000,
  249. 0x28a4c, 0x07ffffff, 0x4e000000,
  250. 0x28350, 0x3f3f3fff, 0x00000082,
  251. 0x30, 0x000000ff, 0x0040,
  252. 0x34, 0x00000040, 0x00004040,
  253. 0x9100, 0x07ffffff, 0x03000000,
  254. 0x9060, 0x0000007f, 0x00000020,
  255. 0x9508, 0x00010000, 0x00010000,
  256. 0xac14, 0x000003ff, 0x000000f3,
  257. 0xac10, 0xffffffff, 0x00000000,
  258. 0xac0c, 0xffffffff, 0x00003210,
  259. 0x88d4, 0x0000001f, 0x00000010,
  260. 0x15c0, 0x000c0fc0, 0x000c0400
  261. };
  262. static const u32 hainan_golden_registers[] =
  263. {
  264. 0x9a10, 0x00010000, 0x00018208,
  265. 0x9830, 0xffffffff, 0x00000000,
  266. 0x9834, 0xf00fffff, 0x00000400,
  267. 0x9838, 0x0002021c, 0x00020200,
  268. 0xd0c0, 0xff000fff, 0x00000100,
  269. 0xd030, 0x000300c0, 0x00800040,
  270. 0xd8c0, 0xff000fff, 0x00000100,
  271. 0xd830, 0x000300c0, 0x00800040,
  272. 0x2ae4, 0x00073ffe, 0x000022a2,
  273. 0x240c, 0x000007ff, 0x00000000,
  274. 0x8a14, 0xf000001f, 0x00000007,
  275. 0x8b24, 0xffffffff, 0x00ffffff,
  276. 0x8b10, 0x0000ff0f, 0x00000000,
  277. 0x28a4c, 0x07ffffff, 0x4e000000,
  278. 0x28350, 0x3f3f3fff, 0x00000000,
  279. 0x30, 0x000000ff, 0x0040,
  280. 0x34, 0x00000040, 0x00004040,
  281. 0x9100, 0x03e00000, 0x03600000,
  282. 0x9060, 0x0000007f, 0x00000020,
  283. 0x9508, 0x00010000, 0x00010000,
  284. 0xac14, 0x000003ff, 0x000000f1,
  285. 0xac10, 0xffffffff, 0x00000000,
  286. 0xac0c, 0xffffffff, 0x00003210,
  287. 0x88d4, 0x0000001f, 0x00000010,
  288. 0x15c0, 0x000c0fc0, 0x000c0400
  289. };
  290. static const u32 hainan_golden_registers2[] =
  291. {
  292. 0x98f8, 0xffffffff, 0x02010001
  293. };
  294. static const u32 tahiti_mgcg_cgcg_init[] =
  295. {
  296. 0xc400, 0xffffffff, 0xfffffffc,
  297. 0x802c, 0xffffffff, 0xe0000000,
  298. 0x9a60, 0xffffffff, 0x00000100,
  299. 0x92a4, 0xffffffff, 0x00000100,
  300. 0xc164, 0xffffffff, 0x00000100,
  301. 0x9774, 0xffffffff, 0x00000100,
  302. 0x8984, 0xffffffff, 0x06000100,
  303. 0x8a18, 0xffffffff, 0x00000100,
  304. 0x92a0, 0xffffffff, 0x00000100,
  305. 0xc380, 0xffffffff, 0x00000100,
  306. 0x8b28, 0xffffffff, 0x00000100,
  307. 0x9144, 0xffffffff, 0x00000100,
  308. 0x8d88, 0xffffffff, 0x00000100,
  309. 0x8d8c, 0xffffffff, 0x00000100,
  310. 0x9030, 0xffffffff, 0x00000100,
  311. 0x9034, 0xffffffff, 0x00000100,
  312. 0x9038, 0xffffffff, 0x00000100,
  313. 0x903c, 0xffffffff, 0x00000100,
  314. 0xad80, 0xffffffff, 0x00000100,
  315. 0xac54, 0xffffffff, 0x00000100,
  316. 0x897c, 0xffffffff, 0x06000100,
  317. 0x9868, 0xffffffff, 0x00000100,
  318. 0x9510, 0xffffffff, 0x00000100,
  319. 0xaf04, 0xffffffff, 0x00000100,
  320. 0xae04, 0xffffffff, 0x00000100,
  321. 0x949c, 0xffffffff, 0x00000100,
  322. 0x802c, 0xffffffff, 0xe0000000,
  323. 0x9160, 0xffffffff, 0x00010000,
  324. 0x9164, 0xffffffff, 0x00030002,
  325. 0x9168, 0xffffffff, 0x00040007,
  326. 0x916c, 0xffffffff, 0x00060005,
  327. 0x9170, 0xffffffff, 0x00090008,
  328. 0x9174, 0xffffffff, 0x00020001,
  329. 0x9178, 0xffffffff, 0x00040003,
  330. 0x917c, 0xffffffff, 0x00000007,
  331. 0x9180, 0xffffffff, 0x00060005,
  332. 0x9184, 0xffffffff, 0x00090008,
  333. 0x9188, 0xffffffff, 0x00030002,
  334. 0x918c, 0xffffffff, 0x00050004,
  335. 0x9190, 0xffffffff, 0x00000008,
  336. 0x9194, 0xffffffff, 0x00070006,
  337. 0x9198, 0xffffffff, 0x000a0009,
  338. 0x919c, 0xffffffff, 0x00040003,
  339. 0x91a0, 0xffffffff, 0x00060005,
  340. 0x91a4, 0xffffffff, 0x00000009,
  341. 0x91a8, 0xffffffff, 0x00080007,
  342. 0x91ac, 0xffffffff, 0x000b000a,
  343. 0x91b0, 0xffffffff, 0x00050004,
  344. 0x91b4, 0xffffffff, 0x00070006,
  345. 0x91b8, 0xffffffff, 0x0008000b,
  346. 0x91bc, 0xffffffff, 0x000a0009,
  347. 0x91c0, 0xffffffff, 0x000d000c,
  348. 0x91c4, 0xffffffff, 0x00060005,
  349. 0x91c8, 0xffffffff, 0x00080007,
  350. 0x91cc, 0xffffffff, 0x0000000b,
  351. 0x91d0, 0xffffffff, 0x000a0009,
  352. 0x91d4, 0xffffffff, 0x000d000c,
  353. 0x91d8, 0xffffffff, 0x00070006,
  354. 0x91dc, 0xffffffff, 0x00090008,
  355. 0x91e0, 0xffffffff, 0x0000000c,
  356. 0x91e4, 0xffffffff, 0x000b000a,
  357. 0x91e8, 0xffffffff, 0x000e000d,
  358. 0x91ec, 0xffffffff, 0x00080007,
  359. 0x91f0, 0xffffffff, 0x000a0009,
  360. 0x91f4, 0xffffffff, 0x0000000d,
  361. 0x91f8, 0xffffffff, 0x000c000b,
  362. 0x91fc, 0xffffffff, 0x000f000e,
  363. 0x9200, 0xffffffff, 0x00090008,
  364. 0x9204, 0xffffffff, 0x000b000a,
  365. 0x9208, 0xffffffff, 0x000c000f,
  366. 0x920c, 0xffffffff, 0x000e000d,
  367. 0x9210, 0xffffffff, 0x00110010,
  368. 0x9214, 0xffffffff, 0x000a0009,
  369. 0x9218, 0xffffffff, 0x000c000b,
  370. 0x921c, 0xffffffff, 0x0000000f,
  371. 0x9220, 0xffffffff, 0x000e000d,
  372. 0x9224, 0xffffffff, 0x00110010,
  373. 0x9228, 0xffffffff, 0x000b000a,
  374. 0x922c, 0xffffffff, 0x000d000c,
  375. 0x9230, 0xffffffff, 0x00000010,
  376. 0x9234, 0xffffffff, 0x000f000e,
  377. 0x9238, 0xffffffff, 0x00120011,
  378. 0x923c, 0xffffffff, 0x000c000b,
  379. 0x9240, 0xffffffff, 0x000e000d,
  380. 0x9244, 0xffffffff, 0x00000011,
  381. 0x9248, 0xffffffff, 0x0010000f,
  382. 0x924c, 0xffffffff, 0x00130012,
  383. 0x9250, 0xffffffff, 0x000d000c,
  384. 0x9254, 0xffffffff, 0x000f000e,
  385. 0x9258, 0xffffffff, 0x00100013,
  386. 0x925c, 0xffffffff, 0x00120011,
  387. 0x9260, 0xffffffff, 0x00150014,
  388. 0x9264, 0xffffffff, 0x000e000d,
  389. 0x9268, 0xffffffff, 0x0010000f,
  390. 0x926c, 0xffffffff, 0x00000013,
  391. 0x9270, 0xffffffff, 0x00120011,
  392. 0x9274, 0xffffffff, 0x00150014,
  393. 0x9278, 0xffffffff, 0x000f000e,
  394. 0x927c, 0xffffffff, 0x00110010,
  395. 0x9280, 0xffffffff, 0x00000014,
  396. 0x9284, 0xffffffff, 0x00130012,
  397. 0x9288, 0xffffffff, 0x00160015,
  398. 0x928c, 0xffffffff, 0x0010000f,
  399. 0x9290, 0xffffffff, 0x00120011,
  400. 0x9294, 0xffffffff, 0x00000015,
  401. 0x9298, 0xffffffff, 0x00140013,
  402. 0x929c, 0xffffffff, 0x00170016,
  403. 0x9150, 0xffffffff, 0x96940200,
  404. 0x8708, 0xffffffff, 0x00900100,
  405. 0xc478, 0xffffffff, 0x00000080,
  406. 0xc404, 0xffffffff, 0x0020003f,
  407. 0x30, 0xffffffff, 0x0000001c,
  408. 0x34, 0x000f0000, 0x000f0000,
  409. 0x160c, 0xffffffff, 0x00000100,
  410. 0x1024, 0xffffffff, 0x00000100,
  411. 0x102c, 0x00000101, 0x00000000,
  412. 0x20a8, 0xffffffff, 0x00000104,
  413. 0x264c, 0x000c0000, 0x000c0000,
  414. 0x2648, 0x000c0000, 0x000c0000,
  415. 0x55e4, 0xff000fff, 0x00000100,
  416. 0x55e8, 0x00000001, 0x00000001,
  417. 0x2f50, 0x00000001, 0x00000001,
  418. 0x30cc, 0xc0000fff, 0x00000104,
  419. 0xc1e4, 0x00000001, 0x00000001,
  420. 0xd0c0, 0xfffffff0, 0x00000100,
  421. 0xd8c0, 0xfffffff0, 0x00000100
  422. };
  423. static const u32 pitcairn_mgcg_cgcg_init[] =
  424. {
  425. 0xc400, 0xffffffff, 0xfffffffc,
  426. 0x802c, 0xffffffff, 0xe0000000,
  427. 0x9a60, 0xffffffff, 0x00000100,
  428. 0x92a4, 0xffffffff, 0x00000100,
  429. 0xc164, 0xffffffff, 0x00000100,
  430. 0x9774, 0xffffffff, 0x00000100,
  431. 0x8984, 0xffffffff, 0x06000100,
  432. 0x8a18, 0xffffffff, 0x00000100,
  433. 0x92a0, 0xffffffff, 0x00000100,
  434. 0xc380, 0xffffffff, 0x00000100,
  435. 0x8b28, 0xffffffff, 0x00000100,
  436. 0x9144, 0xffffffff, 0x00000100,
  437. 0x8d88, 0xffffffff, 0x00000100,
  438. 0x8d8c, 0xffffffff, 0x00000100,
  439. 0x9030, 0xffffffff, 0x00000100,
  440. 0x9034, 0xffffffff, 0x00000100,
  441. 0x9038, 0xffffffff, 0x00000100,
  442. 0x903c, 0xffffffff, 0x00000100,
  443. 0xad80, 0xffffffff, 0x00000100,
  444. 0xac54, 0xffffffff, 0x00000100,
  445. 0x897c, 0xffffffff, 0x06000100,
  446. 0x9868, 0xffffffff, 0x00000100,
  447. 0x9510, 0xffffffff, 0x00000100,
  448. 0xaf04, 0xffffffff, 0x00000100,
  449. 0xae04, 0xffffffff, 0x00000100,
  450. 0x949c, 0xffffffff, 0x00000100,
  451. 0x802c, 0xffffffff, 0xe0000000,
  452. 0x9160, 0xffffffff, 0x00010000,
  453. 0x9164, 0xffffffff, 0x00030002,
  454. 0x9168, 0xffffffff, 0x00040007,
  455. 0x916c, 0xffffffff, 0x00060005,
  456. 0x9170, 0xffffffff, 0x00090008,
  457. 0x9174, 0xffffffff, 0x00020001,
  458. 0x9178, 0xffffffff, 0x00040003,
  459. 0x917c, 0xffffffff, 0x00000007,
  460. 0x9180, 0xffffffff, 0x00060005,
  461. 0x9184, 0xffffffff, 0x00090008,
  462. 0x9188, 0xffffffff, 0x00030002,
  463. 0x918c, 0xffffffff, 0x00050004,
  464. 0x9190, 0xffffffff, 0x00000008,
  465. 0x9194, 0xffffffff, 0x00070006,
  466. 0x9198, 0xffffffff, 0x000a0009,
  467. 0x919c, 0xffffffff, 0x00040003,
  468. 0x91a0, 0xffffffff, 0x00060005,
  469. 0x91a4, 0xffffffff, 0x00000009,
  470. 0x91a8, 0xffffffff, 0x00080007,
  471. 0x91ac, 0xffffffff, 0x000b000a,
  472. 0x91b0, 0xffffffff, 0x00050004,
  473. 0x91b4, 0xffffffff, 0x00070006,
  474. 0x91b8, 0xffffffff, 0x0008000b,
  475. 0x91bc, 0xffffffff, 0x000a0009,
  476. 0x91c0, 0xffffffff, 0x000d000c,
  477. 0x9200, 0xffffffff, 0x00090008,
  478. 0x9204, 0xffffffff, 0x000b000a,
  479. 0x9208, 0xffffffff, 0x000c000f,
  480. 0x920c, 0xffffffff, 0x000e000d,
  481. 0x9210, 0xffffffff, 0x00110010,
  482. 0x9214, 0xffffffff, 0x000a0009,
  483. 0x9218, 0xffffffff, 0x000c000b,
  484. 0x921c, 0xffffffff, 0x0000000f,
  485. 0x9220, 0xffffffff, 0x000e000d,
  486. 0x9224, 0xffffffff, 0x00110010,
  487. 0x9228, 0xffffffff, 0x000b000a,
  488. 0x922c, 0xffffffff, 0x000d000c,
  489. 0x9230, 0xffffffff, 0x00000010,
  490. 0x9234, 0xffffffff, 0x000f000e,
  491. 0x9238, 0xffffffff, 0x00120011,
  492. 0x923c, 0xffffffff, 0x000c000b,
  493. 0x9240, 0xffffffff, 0x000e000d,
  494. 0x9244, 0xffffffff, 0x00000011,
  495. 0x9248, 0xffffffff, 0x0010000f,
  496. 0x924c, 0xffffffff, 0x00130012,
  497. 0x9250, 0xffffffff, 0x000d000c,
  498. 0x9254, 0xffffffff, 0x000f000e,
  499. 0x9258, 0xffffffff, 0x00100013,
  500. 0x925c, 0xffffffff, 0x00120011,
  501. 0x9260, 0xffffffff, 0x00150014,
  502. 0x9150, 0xffffffff, 0x96940200,
  503. 0x8708, 0xffffffff, 0x00900100,
  504. 0xc478, 0xffffffff, 0x00000080,
  505. 0xc404, 0xffffffff, 0x0020003f,
  506. 0x30, 0xffffffff, 0x0000001c,
  507. 0x34, 0x000f0000, 0x000f0000,
  508. 0x160c, 0xffffffff, 0x00000100,
  509. 0x1024, 0xffffffff, 0x00000100,
  510. 0x102c, 0x00000101, 0x00000000,
  511. 0x20a8, 0xffffffff, 0x00000104,
  512. 0x55e4, 0xff000fff, 0x00000100,
  513. 0x55e8, 0x00000001, 0x00000001,
  514. 0x2f50, 0x00000001, 0x00000001,
  515. 0x30cc, 0xc0000fff, 0x00000104,
  516. 0xc1e4, 0x00000001, 0x00000001,
  517. 0xd0c0, 0xfffffff0, 0x00000100,
  518. 0xd8c0, 0xfffffff0, 0x00000100
  519. };
  520. static const u32 verde_mgcg_cgcg_init[] =
  521. {
  522. 0xc400, 0xffffffff, 0xfffffffc,
  523. 0x802c, 0xffffffff, 0xe0000000,
  524. 0x9a60, 0xffffffff, 0x00000100,
  525. 0x92a4, 0xffffffff, 0x00000100,
  526. 0xc164, 0xffffffff, 0x00000100,
  527. 0x9774, 0xffffffff, 0x00000100,
  528. 0x8984, 0xffffffff, 0x06000100,
  529. 0x8a18, 0xffffffff, 0x00000100,
  530. 0x92a0, 0xffffffff, 0x00000100,
  531. 0xc380, 0xffffffff, 0x00000100,
  532. 0x8b28, 0xffffffff, 0x00000100,
  533. 0x9144, 0xffffffff, 0x00000100,
  534. 0x8d88, 0xffffffff, 0x00000100,
  535. 0x8d8c, 0xffffffff, 0x00000100,
  536. 0x9030, 0xffffffff, 0x00000100,
  537. 0x9034, 0xffffffff, 0x00000100,
  538. 0x9038, 0xffffffff, 0x00000100,
  539. 0x903c, 0xffffffff, 0x00000100,
  540. 0xad80, 0xffffffff, 0x00000100,
  541. 0xac54, 0xffffffff, 0x00000100,
  542. 0x897c, 0xffffffff, 0x06000100,
  543. 0x9868, 0xffffffff, 0x00000100,
  544. 0x9510, 0xffffffff, 0x00000100,
  545. 0xaf04, 0xffffffff, 0x00000100,
  546. 0xae04, 0xffffffff, 0x00000100,
  547. 0x949c, 0xffffffff, 0x00000100,
  548. 0x802c, 0xffffffff, 0xe0000000,
  549. 0x9160, 0xffffffff, 0x00010000,
  550. 0x9164, 0xffffffff, 0x00030002,
  551. 0x9168, 0xffffffff, 0x00040007,
  552. 0x916c, 0xffffffff, 0x00060005,
  553. 0x9170, 0xffffffff, 0x00090008,
  554. 0x9174, 0xffffffff, 0x00020001,
  555. 0x9178, 0xffffffff, 0x00040003,
  556. 0x917c, 0xffffffff, 0x00000007,
  557. 0x9180, 0xffffffff, 0x00060005,
  558. 0x9184, 0xffffffff, 0x00090008,
  559. 0x9188, 0xffffffff, 0x00030002,
  560. 0x918c, 0xffffffff, 0x00050004,
  561. 0x9190, 0xffffffff, 0x00000008,
  562. 0x9194, 0xffffffff, 0x00070006,
  563. 0x9198, 0xffffffff, 0x000a0009,
  564. 0x919c, 0xffffffff, 0x00040003,
  565. 0x91a0, 0xffffffff, 0x00060005,
  566. 0x91a4, 0xffffffff, 0x00000009,
  567. 0x91a8, 0xffffffff, 0x00080007,
  568. 0x91ac, 0xffffffff, 0x000b000a,
  569. 0x91b0, 0xffffffff, 0x00050004,
  570. 0x91b4, 0xffffffff, 0x00070006,
  571. 0x91b8, 0xffffffff, 0x0008000b,
  572. 0x91bc, 0xffffffff, 0x000a0009,
  573. 0x91c0, 0xffffffff, 0x000d000c,
  574. 0x9200, 0xffffffff, 0x00090008,
  575. 0x9204, 0xffffffff, 0x000b000a,
  576. 0x9208, 0xffffffff, 0x000c000f,
  577. 0x920c, 0xffffffff, 0x000e000d,
  578. 0x9210, 0xffffffff, 0x00110010,
  579. 0x9214, 0xffffffff, 0x000a0009,
  580. 0x9218, 0xffffffff, 0x000c000b,
  581. 0x921c, 0xffffffff, 0x0000000f,
  582. 0x9220, 0xffffffff, 0x000e000d,
  583. 0x9224, 0xffffffff, 0x00110010,
  584. 0x9228, 0xffffffff, 0x000b000a,
  585. 0x922c, 0xffffffff, 0x000d000c,
  586. 0x9230, 0xffffffff, 0x00000010,
  587. 0x9234, 0xffffffff, 0x000f000e,
  588. 0x9238, 0xffffffff, 0x00120011,
  589. 0x923c, 0xffffffff, 0x000c000b,
  590. 0x9240, 0xffffffff, 0x000e000d,
  591. 0x9244, 0xffffffff, 0x00000011,
  592. 0x9248, 0xffffffff, 0x0010000f,
  593. 0x924c, 0xffffffff, 0x00130012,
  594. 0x9250, 0xffffffff, 0x000d000c,
  595. 0x9254, 0xffffffff, 0x000f000e,
  596. 0x9258, 0xffffffff, 0x00100013,
  597. 0x925c, 0xffffffff, 0x00120011,
  598. 0x9260, 0xffffffff, 0x00150014,
  599. 0x9150, 0xffffffff, 0x96940200,
  600. 0x8708, 0xffffffff, 0x00900100,
  601. 0xc478, 0xffffffff, 0x00000080,
  602. 0xc404, 0xffffffff, 0x0020003f,
  603. 0x30, 0xffffffff, 0x0000001c,
  604. 0x34, 0x000f0000, 0x000f0000,
  605. 0x160c, 0xffffffff, 0x00000100,
  606. 0x1024, 0xffffffff, 0x00000100,
  607. 0x102c, 0x00000101, 0x00000000,
  608. 0x20a8, 0xffffffff, 0x00000104,
  609. 0x264c, 0x000c0000, 0x000c0000,
  610. 0x2648, 0x000c0000, 0x000c0000,
  611. 0x55e4, 0xff000fff, 0x00000100,
  612. 0x55e8, 0x00000001, 0x00000001,
  613. 0x2f50, 0x00000001, 0x00000001,
  614. 0x30cc, 0xc0000fff, 0x00000104,
  615. 0xc1e4, 0x00000001, 0x00000001,
  616. 0xd0c0, 0xfffffff0, 0x00000100,
  617. 0xd8c0, 0xfffffff0, 0x00000100
  618. };
  619. static const u32 oland_mgcg_cgcg_init[] =
  620. {
  621. 0xc400, 0xffffffff, 0xfffffffc,
  622. 0x802c, 0xffffffff, 0xe0000000,
  623. 0x9a60, 0xffffffff, 0x00000100,
  624. 0x92a4, 0xffffffff, 0x00000100,
  625. 0xc164, 0xffffffff, 0x00000100,
  626. 0x9774, 0xffffffff, 0x00000100,
  627. 0x8984, 0xffffffff, 0x06000100,
  628. 0x8a18, 0xffffffff, 0x00000100,
  629. 0x92a0, 0xffffffff, 0x00000100,
  630. 0xc380, 0xffffffff, 0x00000100,
  631. 0x8b28, 0xffffffff, 0x00000100,
  632. 0x9144, 0xffffffff, 0x00000100,
  633. 0x8d88, 0xffffffff, 0x00000100,
  634. 0x8d8c, 0xffffffff, 0x00000100,
  635. 0x9030, 0xffffffff, 0x00000100,
  636. 0x9034, 0xffffffff, 0x00000100,
  637. 0x9038, 0xffffffff, 0x00000100,
  638. 0x903c, 0xffffffff, 0x00000100,
  639. 0xad80, 0xffffffff, 0x00000100,
  640. 0xac54, 0xffffffff, 0x00000100,
  641. 0x897c, 0xffffffff, 0x06000100,
  642. 0x9868, 0xffffffff, 0x00000100,
  643. 0x9510, 0xffffffff, 0x00000100,
  644. 0xaf04, 0xffffffff, 0x00000100,
  645. 0xae04, 0xffffffff, 0x00000100,
  646. 0x949c, 0xffffffff, 0x00000100,
  647. 0x802c, 0xffffffff, 0xe0000000,
  648. 0x9160, 0xffffffff, 0x00010000,
  649. 0x9164, 0xffffffff, 0x00030002,
  650. 0x9168, 0xffffffff, 0x00040007,
  651. 0x916c, 0xffffffff, 0x00060005,
  652. 0x9170, 0xffffffff, 0x00090008,
  653. 0x9174, 0xffffffff, 0x00020001,
  654. 0x9178, 0xffffffff, 0x00040003,
  655. 0x917c, 0xffffffff, 0x00000007,
  656. 0x9180, 0xffffffff, 0x00060005,
  657. 0x9184, 0xffffffff, 0x00090008,
  658. 0x9188, 0xffffffff, 0x00030002,
  659. 0x918c, 0xffffffff, 0x00050004,
  660. 0x9190, 0xffffffff, 0x00000008,
  661. 0x9194, 0xffffffff, 0x00070006,
  662. 0x9198, 0xffffffff, 0x000a0009,
  663. 0x919c, 0xffffffff, 0x00040003,
  664. 0x91a0, 0xffffffff, 0x00060005,
  665. 0x91a4, 0xffffffff, 0x00000009,
  666. 0x91a8, 0xffffffff, 0x00080007,
  667. 0x91ac, 0xffffffff, 0x000b000a,
  668. 0x91b0, 0xffffffff, 0x00050004,
  669. 0x91b4, 0xffffffff, 0x00070006,
  670. 0x91b8, 0xffffffff, 0x0008000b,
  671. 0x91bc, 0xffffffff, 0x000a0009,
  672. 0x91c0, 0xffffffff, 0x000d000c,
  673. 0x91c4, 0xffffffff, 0x00060005,
  674. 0x91c8, 0xffffffff, 0x00080007,
  675. 0x91cc, 0xffffffff, 0x0000000b,
  676. 0x91d0, 0xffffffff, 0x000a0009,
  677. 0x91d4, 0xffffffff, 0x000d000c,
  678. 0x9150, 0xffffffff, 0x96940200,
  679. 0x8708, 0xffffffff, 0x00900100,
  680. 0xc478, 0xffffffff, 0x00000080,
  681. 0xc404, 0xffffffff, 0x0020003f,
  682. 0x30, 0xffffffff, 0x0000001c,
  683. 0x34, 0x000f0000, 0x000f0000,
  684. 0x160c, 0xffffffff, 0x00000100,
  685. 0x1024, 0xffffffff, 0x00000100,
  686. 0x102c, 0x00000101, 0x00000000,
  687. 0x20a8, 0xffffffff, 0x00000104,
  688. 0x264c, 0x000c0000, 0x000c0000,
  689. 0x2648, 0x000c0000, 0x000c0000,
  690. 0x55e4, 0xff000fff, 0x00000100,
  691. 0x55e8, 0x00000001, 0x00000001,
  692. 0x2f50, 0x00000001, 0x00000001,
  693. 0x30cc, 0xc0000fff, 0x00000104,
  694. 0xc1e4, 0x00000001, 0x00000001,
  695. 0xd0c0, 0xfffffff0, 0x00000100,
  696. 0xd8c0, 0xfffffff0, 0x00000100
  697. };
  698. static const u32 hainan_mgcg_cgcg_init[] =
  699. {
  700. 0xc400, 0xffffffff, 0xfffffffc,
  701. 0x802c, 0xffffffff, 0xe0000000,
  702. 0x9a60, 0xffffffff, 0x00000100,
  703. 0x92a4, 0xffffffff, 0x00000100,
  704. 0xc164, 0xffffffff, 0x00000100,
  705. 0x9774, 0xffffffff, 0x00000100,
  706. 0x8984, 0xffffffff, 0x06000100,
  707. 0x8a18, 0xffffffff, 0x00000100,
  708. 0x92a0, 0xffffffff, 0x00000100,
  709. 0xc380, 0xffffffff, 0x00000100,
  710. 0x8b28, 0xffffffff, 0x00000100,
  711. 0x9144, 0xffffffff, 0x00000100,
  712. 0x8d88, 0xffffffff, 0x00000100,
  713. 0x8d8c, 0xffffffff, 0x00000100,
  714. 0x9030, 0xffffffff, 0x00000100,
  715. 0x9034, 0xffffffff, 0x00000100,
  716. 0x9038, 0xffffffff, 0x00000100,
  717. 0x903c, 0xffffffff, 0x00000100,
  718. 0xad80, 0xffffffff, 0x00000100,
  719. 0xac54, 0xffffffff, 0x00000100,
  720. 0x897c, 0xffffffff, 0x06000100,
  721. 0x9868, 0xffffffff, 0x00000100,
  722. 0x9510, 0xffffffff, 0x00000100,
  723. 0xaf04, 0xffffffff, 0x00000100,
  724. 0xae04, 0xffffffff, 0x00000100,
  725. 0x949c, 0xffffffff, 0x00000100,
  726. 0x802c, 0xffffffff, 0xe0000000,
  727. 0x9160, 0xffffffff, 0x00010000,
  728. 0x9164, 0xffffffff, 0x00030002,
  729. 0x9168, 0xffffffff, 0x00040007,
  730. 0x916c, 0xffffffff, 0x00060005,
  731. 0x9170, 0xffffffff, 0x00090008,
  732. 0x9174, 0xffffffff, 0x00020001,
  733. 0x9178, 0xffffffff, 0x00040003,
  734. 0x917c, 0xffffffff, 0x00000007,
  735. 0x9180, 0xffffffff, 0x00060005,
  736. 0x9184, 0xffffffff, 0x00090008,
  737. 0x9188, 0xffffffff, 0x00030002,
  738. 0x918c, 0xffffffff, 0x00050004,
  739. 0x9190, 0xffffffff, 0x00000008,
  740. 0x9194, 0xffffffff, 0x00070006,
  741. 0x9198, 0xffffffff, 0x000a0009,
  742. 0x919c, 0xffffffff, 0x00040003,
  743. 0x91a0, 0xffffffff, 0x00060005,
  744. 0x91a4, 0xffffffff, 0x00000009,
  745. 0x91a8, 0xffffffff, 0x00080007,
  746. 0x91ac, 0xffffffff, 0x000b000a,
  747. 0x91b0, 0xffffffff, 0x00050004,
  748. 0x91b4, 0xffffffff, 0x00070006,
  749. 0x91b8, 0xffffffff, 0x0008000b,
  750. 0x91bc, 0xffffffff, 0x000a0009,
  751. 0x91c0, 0xffffffff, 0x000d000c,
  752. 0x91c4, 0xffffffff, 0x00060005,
  753. 0x91c8, 0xffffffff, 0x00080007,
  754. 0x91cc, 0xffffffff, 0x0000000b,
  755. 0x91d0, 0xffffffff, 0x000a0009,
  756. 0x91d4, 0xffffffff, 0x000d000c,
  757. 0x9150, 0xffffffff, 0x96940200,
  758. 0x8708, 0xffffffff, 0x00900100,
  759. 0xc478, 0xffffffff, 0x00000080,
  760. 0xc404, 0xffffffff, 0x0020003f,
  761. 0x30, 0xffffffff, 0x0000001c,
  762. 0x34, 0x000f0000, 0x000f0000,
  763. 0x160c, 0xffffffff, 0x00000100,
  764. 0x1024, 0xffffffff, 0x00000100,
  765. 0x20a8, 0xffffffff, 0x00000104,
  766. 0x264c, 0x000c0000, 0x000c0000,
  767. 0x2648, 0x000c0000, 0x000c0000,
  768. 0x2f50, 0x00000001, 0x00000001,
  769. 0x30cc, 0xc0000fff, 0x00000104,
  770. 0xc1e4, 0x00000001, 0x00000001,
  771. 0xd0c0, 0xfffffff0, 0x00000100,
  772. 0xd8c0, 0xfffffff0, 0x00000100
  773. };
  774. static u32 verde_pg_init[] =
  775. {
  776. 0x353c, 0xffffffff, 0x40000,
  777. 0x3538, 0xffffffff, 0x200010ff,
  778. 0x353c, 0xffffffff, 0x0,
  779. 0x353c, 0xffffffff, 0x0,
  780. 0x353c, 0xffffffff, 0x0,
  781. 0x353c, 0xffffffff, 0x0,
  782. 0x353c, 0xffffffff, 0x0,
  783. 0x353c, 0xffffffff, 0x7007,
  784. 0x3538, 0xffffffff, 0x300010ff,
  785. 0x353c, 0xffffffff, 0x0,
  786. 0x353c, 0xffffffff, 0x0,
  787. 0x353c, 0xffffffff, 0x0,
  788. 0x353c, 0xffffffff, 0x0,
  789. 0x353c, 0xffffffff, 0x0,
  790. 0x353c, 0xffffffff, 0x400000,
  791. 0x3538, 0xffffffff, 0x100010ff,
  792. 0x353c, 0xffffffff, 0x0,
  793. 0x353c, 0xffffffff, 0x0,
  794. 0x353c, 0xffffffff, 0x0,
  795. 0x353c, 0xffffffff, 0x0,
  796. 0x353c, 0xffffffff, 0x0,
  797. 0x353c, 0xffffffff, 0x120200,
  798. 0x3538, 0xffffffff, 0x500010ff,
  799. 0x353c, 0xffffffff, 0x0,
  800. 0x353c, 0xffffffff, 0x0,
  801. 0x353c, 0xffffffff, 0x0,
  802. 0x353c, 0xffffffff, 0x0,
  803. 0x353c, 0xffffffff, 0x0,
  804. 0x353c, 0xffffffff, 0x1e1e16,
  805. 0x3538, 0xffffffff, 0x600010ff,
  806. 0x353c, 0xffffffff, 0x0,
  807. 0x353c, 0xffffffff, 0x0,
  808. 0x353c, 0xffffffff, 0x0,
  809. 0x353c, 0xffffffff, 0x0,
  810. 0x353c, 0xffffffff, 0x0,
  811. 0x353c, 0xffffffff, 0x171f1e,
  812. 0x3538, 0xffffffff, 0x700010ff,
  813. 0x353c, 0xffffffff, 0x0,
  814. 0x353c, 0xffffffff, 0x0,
  815. 0x353c, 0xffffffff, 0x0,
  816. 0x353c, 0xffffffff, 0x0,
  817. 0x353c, 0xffffffff, 0x0,
  818. 0x353c, 0xffffffff, 0x0,
  819. 0x3538, 0xffffffff, 0x9ff,
  820. 0x3500, 0xffffffff, 0x0,
  821. 0x3504, 0xffffffff, 0x10000800,
  822. 0x3504, 0xffffffff, 0xf,
  823. 0x3504, 0xffffffff, 0xf,
  824. 0x3500, 0xffffffff, 0x4,
  825. 0x3504, 0xffffffff, 0x1000051e,
  826. 0x3504, 0xffffffff, 0xffff,
  827. 0x3504, 0xffffffff, 0xffff,
  828. 0x3500, 0xffffffff, 0x8,
  829. 0x3504, 0xffffffff, 0x80500,
  830. 0x3500, 0xffffffff, 0x12,
  831. 0x3504, 0xffffffff, 0x9050c,
  832. 0x3500, 0xffffffff, 0x1d,
  833. 0x3504, 0xffffffff, 0xb052c,
  834. 0x3500, 0xffffffff, 0x2a,
  835. 0x3504, 0xffffffff, 0x1053e,
  836. 0x3500, 0xffffffff, 0x2d,
  837. 0x3504, 0xffffffff, 0x10546,
  838. 0x3500, 0xffffffff, 0x30,
  839. 0x3504, 0xffffffff, 0xa054e,
  840. 0x3500, 0xffffffff, 0x3c,
  841. 0x3504, 0xffffffff, 0x1055f,
  842. 0x3500, 0xffffffff, 0x3f,
  843. 0x3504, 0xffffffff, 0x10567,
  844. 0x3500, 0xffffffff, 0x42,
  845. 0x3504, 0xffffffff, 0x1056f,
  846. 0x3500, 0xffffffff, 0x45,
  847. 0x3504, 0xffffffff, 0x10572,
  848. 0x3500, 0xffffffff, 0x48,
  849. 0x3504, 0xffffffff, 0x20575,
  850. 0x3500, 0xffffffff, 0x4c,
  851. 0x3504, 0xffffffff, 0x190801,
  852. 0x3500, 0xffffffff, 0x67,
  853. 0x3504, 0xffffffff, 0x1082a,
  854. 0x3500, 0xffffffff, 0x6a,
  855. 0x3504, 0xffffffff, 0x1b082d,
  856. 0x3500, 0xffffffff, 0x87,
  857. 0x3504, 0xffffffff, 0x310851,
  858. 0x3500, 0xffffffff, 0xba,
  859. 0x3504, 0xffffffff, 0x891,
  860. 0x3500, 0xffffffff, 0xbc,
  861. 0x3504, 0xffffffff, 0x893,
  862. 0x3500, 0xffffffff, 0xbe,
  863. 0x3504, 0xffffffff, 0x20895,
  864. 0x3500, 0xffffffff, 0xc2,
  865. 0x3504, 0xffffffff, 0x20899,
  866. 0x3500, 0xffffffff, 0xc6,
  867. 0x3504, 0xffffffff, 0x2089d,
  868. 0x3500, 0xffffffff, 0xca,
  869. 0x3504, 0xffffffff, 0x8a1,
  870. 0x3500, 0xffffffff, 0xcc,
  871. 0x3504, 0xffffffff, 0x8a3,
  872. 0x3500, 0xffffffff, 0xce,
  873. 0x3504, 0xffffffff, 0x308a5,
  874. 0x3500, 0xffffffff, 0xd3,
  875. 0x3504, 0xffffffff, 0x6d08cd,
  876. 0x3500, 0xffffffff, 0x142,
  877. 0x3504, 0xffffffff, 0x2000095a,
  878. 0x3504, 0xffffffff, 0x1,
  879. 0x3500, 0xffffffff, 0x144,
  880. 0x3504, 0xffffffff, 0x301f095b,
  881. 0x3500, 0xffffffff, 0x165,
  882. 0x3504, 0xffffffff, 0xc094d,
  883. 0x3500, 0xffffffff, 0x173,
  884. 0x3504, 0xffffffff, 0xf096d,
  885. 0x3500, 0xffffffff, 0x184,
  886. 0x3504, 0xffffffff, 0x15097f,
  887. 0x3500, 0xffffffff, 0x19b,
  888. 0x3504, 0xffffffff, 0xc0998,
  889. 0x3500, 0xffffffff, 0x1a9,
  890. 0x3504, 0xffffffff, 0x409a7,
  891. 0x3500, 0xffffffff, 0x1af,
  892. 0x3504, 0xffffffff, 0xcdc,
  893. 0x3500, 0xffffffff, 0x1b1,
  894. 0x3504, 0xffffffff, 0x800,
  895. 0x3508, 0xffffffff, 0x6c9b2000,
  896. 0x3510, 0xfc00, 0x2000,
  897. 0x3544, 0xffffffff, 0xfc0,
  898. 0x28d4, 0x00000100, 0x100
  899. };
  900. static void si_init_golden_registers(struct radeon_device *rdev)
  901. {
  902. switch (rdev->family) {
  903. case CHIP_TAHITI:
  904. radeon_program_register_sequence(rdev,
  905. tahiti_golden_registers,
  906. (const u32)ARRAY_SIZE(tahiti_golden_registers));
  907. radeon_program_register_sequence(rdev,
  908. tahiti_golden_rlc_registers,
  909. (const u32)ARRAY_SIZE(tahiti_golden_rlc_registers));
  910. radeon_program_register_sequence(rdev,
  911. tahiti_mgcg_cgcg_init,
  912. (const u32)ARRAY_SIZE(tahiti_mgcg_cgcg_init));
  913. radeon_program_register_sequence(rdev,
  914. tahiti_golden_registers2,
  915. (const u32)ARRAY_SIZE(tahiti_golden_registers2));
  916. break;
  917. case CHIP_PITCAIRN:
  918. radeon_program_register_sequence(rdev,
  919. pitcairn_golden_registers,
  920. (const u32)ARRAY_SIZE(pitcairn_golden_registers));
  921. radeon_program_register_sequence(rdev,
  922. pitcairn_golden_rlc_registers,
  923. (const u32)ARRAY_SIZE(pitcairn_golden_rlc_registers));
  924. radeon_program_register_sequence(rdev,
  925. pitcairn_mgcg_cgcg_init,
  926. (const u32)ARRAY_SIZE(pitcairn_mgcg_cgcg_init));
  927. break;
  928. case CHIP_VERDE:
  929. radeon_program_register_sequence(rdev,
  930. verde_golden_registers,
  931. (const u32)ARRAY_SIZE(verde_golden_registers));
  932. radeon_program_register_sequence(rdev,
  933. verde_golden_rlc_registers,
  934. (const u32)ARRAY_SIZE(verde_golden_rlc_registers));
  935. radeon_program_register_sequence(rdev,
  936. verde_mgcg_cgcg_init,
  937. (const u32)ARRAY_SIZE(verde_mgcg_cgcg_init));
  938. radeon_program_register_sequence(rdev,
  939. verde_pg_init,
  940. (const u32)ARRAY_SIZE(verde_pg_init));
  941. break;
  942. case CHIP_OLAND:
  943. radeon_program_register_sequence(rdev,
  944. oland_golden_registers,
  945. (const u32)ARRAY_SIZE(oland_golden_registers));
  946. radeon_program_register_sequence(rdev,
  947. oland_golden_rlc_registers,
  948. (const u32)ARRAY_SIZE(oland_golden_rlc_registers));
  949. radeon_program_register_sequence(rdev,
  950. oland_mgcg_cgcg_init,
  951. (const u32)ARRAY_SIZE(oland_mgcg_cgcg_init));
  952. break;
  953. case CHIP_HAINAN:
  954. radeon_program_register_sequence(rdev,
  955. hainan_golden_registers,
  956. (const u32)ARRAY_SIZE(hainan_golden_registers));
  957. radeon_program_register_sequence(rdev,
  958. hainan_golden_registers2,
  959. (const u32)ARRAY_SIZE(hainan_golden_registers2));
  960. radeon_program_register_sequence(rdev,
  961. hainan_mgcg_cgcg_init,
  962. (const u32)ARRAY_SIZE(hainan_mgcg_cgcg_init));
  963. break;
  964. default:
  965. break;
  966. }
  967. }
  968. #define PCIE_BUS_CLK 10000
  969. #define TCLK (PCIE_BUS_CLK / 10)
  970. /**
  971. * si_get_xclk - get the xclk
  972. *
  973. * @rdev: radeon_device pointer
  974. *
  975. * Returns the reference clock used by the gfx engine
  976. * (SI).
  977. */
  978. u32 si_get_xclk(struct radeon_device *rdev)
  979. {
  980. u32 reference_clock = rdev->clock.spll.reference_freq;
  981. u32 tmp;
  982. tmp = RREG32(CG_CLKPIN_CNTL_2);
  983. if (tmp & MUX_TCLK_TO_XCLK)
  984. return TCLK;
  985. tmp = RREG32(CG_CLKPIN_CNTL);
  986. if (tmp & XTALIN_DIVIDE)
  987. return reference_clock / 4;
  988. return reference_clock;
  989. }
  990. /* get temperature in millidegrees */
  991. int si_get_temp(struct radeon_device *rdev)
  992. {
  993. u32 temp;
  994. int actual_temp = 0;
  995. temp = (RREG32(CG_MULT_THERMAL_STATUS) & CTF_TEMP_MASK) >>
  996. CTF_TEMP_SHIFT;
  997. if (temp & 0x200)
  998. actual_temp = 255;
  999. else
  1000. actual_temp = temp & 0x1ff;
  1001. actual_temp = (actual_temp * 1000);
  1002. return actual_temp;
  1003. }
  1004. #define TAHITI_IO_MC_REGS_SIZE 36
  1005. static const u32 tahiti_io_mc_regs[TAHITI_IO_MC_REGS_SIZE][2] = {
  1006. {0x0000006f, 0x03044000},
  1007. {0x00000070, 0x0480c018},
  1008. {0x00000071, 0x00000040},
  1009. {0x00000072, 0x01000000},
  1010. {0x00000074, 0x000000ff},
  1011. {0x00000075, 0x00143400},
  1012. {0x00000076, 0x08ec0800},
  1013. {0x00000077, 0x040000cc},
  1014. {0x00000079, 0x00000000},
  1015. {0x0000007a, 0x21000409},
  1016. {0x0000007c, 0x00000000},
  1017. {0x0000007d, 0xe8000000},
  1018. {0x0000007e, 0x044408a8},
  1019. {0x0000007f, 0x00000003},
  1020. {0x00000080, 0x00000000},
  1021. {0x00000081, 0x01000000},
  1022. {0x00000082, 0x02000000},
  1023. {0x00000083, 0x00000000},
  1024. {0x00000084, 0xe3f3e4f4},
  1025. {0x00000085, 0x00052024},
  1026. {0x00000087, 0x00000000},
  1027. {0x00000088, 0x66036603},
  1028. {0x00000089, 0x01000000},
  1029. {0x0000008b, 0x1c0a0000},
  1030. {0x0000008c, 0xff010000},
  1031. {0x0000008e, 0xffffefff},
  1032. {0x0000008f, 0xfff3efff},
  1033. {0x00000090, 0xfff3efbf},
  1034. {0x00000094, 0x00101101},
  1035. {0x00000095, 0x00000fff},
  1036. {0x00000096, 0x00116fff},
  1037. {0x00000097, 0x60010000},
  1038. {0x00000098, 0x10010000},
  1039. {0x00000099, 0x00006000},
  1040. {0x0000009a, 0x00001000},
  1041. {0x0000009f, 0x00a77400}
  1042. };
  1043. static const u32 pitcairn_io_mc_regs[TAHITI_IO_MC_REGS_SIZE][2] = {
  1044. {0x0000006f, 0x03044000},
  1045. {0x00000070, 0x0480c018},
  1046. {0x00000071, 0x00000040},
  1047. {0x00000072, 0x01000000},
  1048. {0x00000074, 0x000000ff},
  1049. {0x00000075, 0x00143400},
  1050. {0x00000076, 0x08ec0800},
  1051. {0x00000077, 0x040000cc},
  1052. {0x00000079, 0x00000000},
  1053. {0x0000007a, 0x21000409},
  1054. {0x0000007c, 0x00000000},
  1055. {0x0000007d, 0xe8000000},
  1056. {0x0000007e, 0x044408a8},
  1057. {0x0000007f, 0x00000003},
  1058. {0x00000080, 0x00000000},
  1059. {0x00000081, 0x01000000},
  1060. {0x00000082, 0x02000000},
  1061. {0x00000083, 0x00000000},
  1062. {0x00000084, 0xe3f3e4f4},
  1063. {0x00000085, 0x00052024},
  1064. {0x00000087, 0x00000000},
  1065. {0x00000088, 0x66036603},
  1066. {0x00000089, 0x01000000},
  1067. {0x0000008b, 0x1c0a0000},
  1068. {0x0000008c, 0xff010000},
  1069. {0x0000008e, 0xffffefff},
  1070. {0x0000008f, 0xfff3efff},
  1071. {0x00000090, 0xfff3efbf},
  1072. {0x00000094, 0x00101101},
  1073. {0x00000095, 0x00000fff},
  1074. {0x00000096, 0x00116fff},
  1075. {0x00000097, 0x60010000},
  1076. {0x00000098, 0x10010000},
  1077. {0x00000099, 0x00006000},
  1078. {0x0000009a, 0x00001000},
  1079. {0x0000009f, 0x00a47400}
  1080. };
  1081. static const u32 verde_io_mc_regs[TAHITI_IO_MC_REGS_SIZE][2] = {
  1082. {0x0000006f, 0x03044000},
  1083. {0x00000070, 0x0480c018},
  1084. {0x00000071, 0x00000040},
  1085. {0x00000072, 0x01000000},
  1086. {0x00000074, 0x000000ff},
  1087. {0x00000075, 0x00143400},
  1088. {0x00000076, 0x08ec0800},
  1089. {0x00000077, 0x040000cc},
  1090. {0x00000079, 0x00000000},
  1091. {0x0000007a, 0x21000409},
  1092. {0x0000007c, 0x00000000},
  1093. {0x0000007d, 0xe8000000},
  1094. {0x0000007e, 0x044408a8},
  1095. {0x0000007f, 0x00000003},
  1096. {0x00000080, 0x00000000},
  1097. {0x00000081, 0x01000000},
  1098. {0x00000082, 0x02000000},
  1099. {0x00000083, 0x00000000},
  1100. {0x00000084, 0xe3f3e4f4},
  1101. {0x00000085, 0x00052024},
  1102. {0x00000087, 0x00000000},
  1103. {0x00000088, 0x66036603},
  1104. {0x00000089, 0x01000000},
  1105. {0x0000008b, 0x1c0a0000},
  1106. {0x0000008c, 0xff010000},
  1107. {0x0000008e, 0xffffefff},
  1108. {0x0000008f, 0xfff3efff},
  1109. {0x00000090, 0xfff3efbf},
  1110. {0x00000094, 0x00101101},
  1111. {0x00000095, 0x00000fff},
  1112. {0x00000096, 0x00116fff},
  1113. {0x00000097, 0x60010000},
  1114. {0x00000098, 0x10010000},
  1115. {0x00000099, 0x00006000},
  1116. {0x0000009a, 0x00001000},
  1117. {0x0000009f, 0x00a37400}
  1118. };
  1119. static const u32 oland_io_mc_regs[TAHITI_IO_MC_REGS_SIZE][2] = {
  1120. {0x0000006f, 0x03044000},
  1121. {0x00000070, 0x0480c018},
  1122. {0x00000071, 0x00000040},
  1123. {0x00000072, 0x01000000},
  1124. {0x00000074, 0x000000ff},
  1125. {0x00000075, 0x00143400},
  1126. {0x00000076, 0x08ec0800},
  1127. {0x00000077, 0x040000cc},
  1128. {0x00000079, 0x00000000},
  1129. {0x0000007a, 0x21000409},
  1130. {0x0000007c, 0x00000000},
  1131. {0x0000007d, 0xe8000000},
  1132. {0x0000007e, 0x044408a8},
  1133. {0x0000007f, 0x00000003},
  1134. {0x00000080, 0x00000000},
  1135. {0x00000081, 0x01000000},
  1136. {0x00000082, 0x02000000},
  1137. {0x00000083, 0x00000000},
  1138. {0x00000084, 0xe3f3e4f4},
  1139. {0x00000085, 0x00052024},
  1140. {0x00000087, 0x00000000},
  1141. {0x00000088, 0x66036603},
  1142. {0x00000089, 0x01000000},
  1143. {0x0000008b, 0x1c0a0000},
  1144. {0x0000008c, 0xff010000},
  1145. {0x0000008e, 0xffffefff},
  1146. {0x0000008f, 0xfff3efff},
  1147. {0x00000090, 0xfff3efbf},
  1148. {0x00000094, 0x00101101},
  1149. {0x00000095, 0x00000fff},
  1150. {0x00000096, 0x00116fff},
  1151. {0x00000097, 0x60010000},
  1152. {0x00000098, 0x10010000},
  1153. {0x00000099, 0x00006000},
  1154. {0x0000009a, 0x00001000},
  1155. {0x0000009f, 0x00a17730}
  1156. };
  1157. static const u32 hainan_io_mc_regs[TAHITI_IO_MC_REGS_SIZE][2] = {
  1158. {0x0000006f, 0x03044000},
  1159. {0x00000070, 0x0480c018},
  1160. {0x00000071, 0x00000040},
  1161. {0x00000072, 0x01000000},
  1162. {0x00000074, 0x000000ff},
  1163. {0x00000075, 0x00143400},
  1164. {0x00000076, 0x08ec0800},
  1165. {0x00000077, 0x040000cc},
  1166. {0x00000079, 0x00000000},
  1167. {0x0000007a, 0x21000409},
  1168. {0x0000007c, 0x00000000},
  1169. {0x0000007d, 0xe8000000},
  1170. {0x0000007e, 0x044408a8},
  1171. {0x0000007f, 0x00000003},
  1172. {0x00000080, 0x00000000},
  1173. {0x00000081, 0x01000000},
  1174. {0x00000082, 0x02000000},
  1175. {0x00000083, 0x00000000},
  1176. {0x00000084, 0xe3f3e4f4},
  1177. {0x00000085, 0x00052024},
  1178. {0x00000087, 0x00000000},
  1179. {0x00000088, 0x66036603},
  1180. {0x00000089, 0x01000000},
  1181. {0x0000008b, 0x1c0a0000},
  1182. {0x0000008c, 0xff010000},
  1183. {0x0000008e, 0xffffefff},
  1184. {0x0000008f, 0xfff3efff},
  1185. {0x00000090, 0xfff3efbf},
  1186. {0x00000094, 0x00101101},
  1187. {0x00000095, 0x00000fff},
  1188. {0x00000096, 0x00116fff},
  1189. {0x00000097, 0x60010000},
  1190. {0x00000098, 0x10010000},
  1191. {0x00000099, 0x00006000},
  1192. {0x0000009a, 0x00001000},
  1193. {0x0000009f, 0x00a07730}
  1194. };
  1195. /* ucode loading */
  1196. static int si_mc_load_microcode(struct radeon_device *rdev)
  1197. {
  1198. const __be32 *fw_data;
  1199. u32 running, blackout = 0;
  1200. u32 *io_mc_regs;
  1201. int i, ucode_size, regs_size;
  1202. if (!rdev->mc_fw)
  1203. return -EINVAL;
  1204. switch (rdev->family) {
  1205. case CHIP_TAHITI:
  1206. io_mc_regs = (u32 *)&tahiti_io_mc_regs;
  1207. ucode_size = SI_MC_UCODE_SIZE;
  1208. regs_size = TAHITI_IO_MC_REGS_SIZE;
  1209. break;
  1210. case CHIP_PITCAIRN:
  1211. io_mc_regs = (u32 *)&pitcairn_io_mc_regs;
  1212. ucode_size = SI_MC_UCODE_SIZE;
  1213. regs_size = TAHITI_IO_MC_REGS_SIZE;
  1214. break;
  1215. case CHIP_VERDE:
  1216. default:
  1217. io_mc_regs = (u32 *)&verde_io_mc_regs;
  1218. ucode_size = SI_MC_UCODE_SIZE;
  1219. regs_size = TAHITI_IO_MC_REGS_SIZE;
  1220. break;
  1221. case CHIP_OLAND:
  1222. io_mc_regs = (u32 *)&oland_io_mc_regs;
  1223. ucode_size = OLAND_MC_UCODE_SIZE;
  1224. regs_size = TAHITI_IO_MC_REGS_SIZE;
  1225. break;
  1226. case CHIP_HAINAN:
  1227. io_mc_regs = (u32 *)&hainan_io_mc_regs;
  1228. ucode_size = OLAND_MC_UCODE_SIZE;
  1229. regs_size = TAHITI_IO_MC_REGS_SIZE;
  1230. break;
  1231. }
  1232. running = RREG32(MC_SEQ_SUP_CNTL) & RUN_MASK;
  1233. if (running == 0) {
  1234. if (running) {
  1235. blackout = RREG32(MC_SHARED_BLACKOUT_CNTL);
  1236. WREG32(MC_SHARED_BLACKOUT_CNTL, blackout | 1);
  1237. }
  1238. /* reset the engine and set to writable */
  1239. WREG32(MC_SEQ_SUP_CNTL, 0x00000008);
  1240. WREG32(MC_SEQ_SUP_CNTL, 0x00000010);
  1241. /* load mc io regs */
  1242. for (i = 0; i < regs_size; i++) {
  1243. WREG32(MC_SEQ_IO_DEBUG_INDEX, io_mc_regs[(i << 1)]);
  1244. WREG32(MC_SEQ_IO_DEBUG_DATA, io_mc_regs[(i << 1) + 1]);
  1245. }
  1246. /* load the MC ucode */
  1247. fw_data = (const __be32 *)rdev->mc_fw->data;
  1248. for (i = 0; i < ucode_size; i++)
  1249. WREG32(MC_SEQ_SUP_PGM, be32_to_cpup(fw_data++));
  1250. /* put the engine back into the active state */
  1251. WREG32(MC_SEQ_SUP_CNTL, 0x00000008);
  1252. WREG32(MC_SEQ_SUP_CNTL, 0x00000004);
  1253. WREG32(MC_SEQ_SUP_CNTL, 0x00000001);
  1254. /* wait for training to complete */
  1255. for (i = 0; i < rdev->usec_timeout; i++) {
  1256. if (RREG32(MC_SEQ_TRAIN_WAKEUP_CNTL) & TRAIN_DONE_D0)
  1257. break;
  1258. udelay(1);
  1259. }
  1260. for (i = 0; i < rdev->usec_timeout; i++) {
  1261. if (RREG32(MC_SEQ_TRAIN_WAKEUP_CNTL) & TRAIN_DONE_D1)
  1262. break;
  1263. udelay(1);
  1264. }
  1265. if (running)
  1266. WREG32(MC_SHARED_BLACKOUT_CNTL, blackout);
  1267. }
  1268. return 0;
  1269. }
  1270. static int si_init_microcode(struct radeon_device *rdev)
  1271. {
  1272. struct platform_device *pdev;
  1273. const char *chip_name;
  1274. const char *rlc_chip_name;
  1275. size_t pfp_req_size, me_req_size, ce_req_size, rlc_req_size, mc_req_size;
  1276. char fw_name[30];
  1277. int err;
  1278. DRM_DEBUG("\n");
  1279. pdev = platform_device_register_simple("radeon_cp", 0, NULL, 0);
  1280. err = IS_ERR(pdev);
  1281. if (err) {
  1282. printk(KERN_ERR "radeon_cp: Failed to register firmware\n");
  1283. return -EINVAL;
  1284. }
  1285. switch (rdev->family) {
  1286. case CHIP_TAHITI:
  1287. chip_name = "TAHITI";
  1288. rlc_chip_name = "TAHITI";
  1289. pfp_req_size = SI_PFP_UCODE_SIZE * 4;
  1290. me_req_size = SI_PM4_UCODE_SIZE * 4;
  1291. ce_req_size = SI_CE_UCODE_SIZE * 4;
  1292. rlc_req_size = SI_RLC_UCODE_SIZE * 4;
  1293. mc_req_size = SI_MC_UCODE_SIZE * 4;
  1294. break;
  1295. case CHIP_PITCAIRN:
  1296. chip_name = "PITCAIRN";
  1297. rlc_chip_name = "PITCAIRN";
  1298. pfp_req_size = SI_PFP_UCODE_SIZE * 4;
  1299. me_req_size = SI_PM4_UCODE_SIZE * 4;
  1300. ce_req_size = SI_CE_UCODE_SIZE * 4;
  1301. rlc_req_size = SI_RLC_UCODE_SIZE * 4;
  1302. mc_req_size = SI_MC_UCODE_SIZE * 4;
  1303. break;
  1304. case CHIP_VERDE:
  1305. chip_name = "VERDE";
  1306. rlc_chip_name = "VERDE";
  1307. pfp_req_size = SI_PFP_UCODE_SIZE * 4;
  1308. me_req_size = SI_PM4_UCODE_SIZE * 4;
  1309. ce_req_size = SI_CE_UCODE_SIZE * 4;
  1310. rlc_req_size = SI_RLC_UCODE_SIZE * 4;
  1311. mc_req_size = SI_MC_UCODE_SIZE * 4;
  1312. break;
  1313. case CHIP_OLAND:
  1314. chip_name = "OLAND";
  1315. rlc_chip_name = "OLAND";
  1316. pfp_req_size = SI_PFP_UCODE_SIZE * 4;
  1317. me_req_size = SI_PM4_UCODE_SIZE * 4;
  1318. ce_req_size = SI_CE_UCODE_SIZE * 4;
  1319. rlc_req_size = SI_RLC_UCODE_SIZE * 4;
  1320. mc_req_size = OLAND_MC_UCODE_SIZE * 4;
  1321. break;
  1322. case CHIP_HAINAN:
  1323. chip_name = "HAINAN";
  1324. rlc_chip_name = "HAINAN";
  1325. pfp_req_size = SI_PFP_UCODE_SIZE * 4;
  1326. me_req_size = SI_PM4_UCODE_SIZE * 4;
  1327. ce_req_size = SI_CE_UCODE_SIZE * 4;
  1328. rlc_req_size = SI_RLC_UCODE_SIZE * 4;
  1329. mc_req_size = OLAND_MC_UCODE_SIZE * 4;
  1330. break;
  1331. default: BUG();
  1332. }
  1333. DRM_INFO("Loading %s Microcode\n", chip_name);
  1334. snprintf(fw_name, sizeof(fw_name), "radeon/%s_pfp.bin", chip_name);
  1335. err = request_firmware(&rdev->pfp_fw, fw_name, &pdev->dev);
  1336. if (err)
  1337. goto out;
  1338. if (rdev->pfp_fw->size != pfp_req_size) {
  1339. printk(KERN_ERR
  1340. "si_cp: Bogus length %zu in firmware \"%s\"\n",
  1341. rdev->pfp_fw->size, fw_name);
  1342. err = -EINVAL;
  1343. goto out;
  1344. }
  1345. snprintf(fw_name, sizeof(fw_name), "radeon/%s_me.bin", chip_name);
  1346. err = request_firmware(&rdev->me_fw, fw_name, &pdev->dev);
  1347. if (err)
  1348. goto out;
  1349. if (rdev->me_fw->size != me_req_size) {
  1350. printk(KERN_ERR
  1351. "si_cp: Bogus length %zu in firmware \"%s\"\n",
  1352. rdev->me_fw->size, fw_name);
  1353. err = -EINVAL;
  1354. }
  1355. snprintf(fw_name, sizeof(fw_name), "radeon/%s_ce.bin", chip_name);
  1356. err = request_firmware(&rdev->ce_fw, fw_name, &pdev->dev);
  1357. if (err)
  1358. goto out;
  1359. if (rdev->ce_fw->size != ce_req_size) {
  1360. printk(KERN_ERR
  1361. "si_cp: Bogus length %zu in firmware \"%s\"\n",
  1362. rdev->ce_fw->size, fw_name);
  1363. err = -EINVAL;
  1364. }
  1365. snprintf(fw_name, sizeof(fw_name), "radeon/%s_rlc.bin", rlc_chip_name);
  1366. err = request_firmware(&rdev->rlc_fw, fw_name, &pdev->dev);
  1367. if (err)
  1368. goto out;
  1369. if (rdev->rlc_fw->size != rlc_req_size) {
  1370. printk(KERN_ERR
  1371. "si_rlc: Bogus length %zu in firmware \"%s\"\n",
  1372. rdev->rlc_fw->size, fw_name);
  1373. err = -EINVAL;
  1374. }
  1375. snprintf(fw_name, sizeof(fw_name), "radeon/%s_mc.bin", chip_name);
  1376. err = request_firmware(&rdev->mc_fw, fw_name, &pdev->dev);
  1377. if (err)
  1378. goto out;
  1379. if (rdev->mc_fw->size != mc_req_size) {
  1380. printk(KERN_ERR
  1381. "si_mc: Bogus length %zu in firmware \"%s\"\n",
  1382. rdev->mc_fw->size, fw_name);
  1383. err = -EINVAL;
  1384. }
  1385. out:
  1386. platform_device_unregister(pdev);
  1387. if (err) {
  1388. if (err != -EINVAL)
  1389. printk(KERN_ERR
  1390. "si_cp: Failed to load firmware \"%s\"\n",
  1391. fw_name);
  1392. release_firmware(rdev->pfp_fw);
  1393. rdev->pfp_fw = NULL;
  1394. release_firmware(rdev->me_fw);
  1395. rdev->me_fw = NULL;
  1396. release_firmware(rdev->ce_fw);
  1397. rdev->ce_fw = NULL;
  1398. release_firmware(rdev->rlc_fw);
  1399. rdev->rlc_fw = NULL;
  1400. release_firmware(rdev->mc_fw);
  1401. rdev->mc_fw = NULL;
  1402. }
  1403. return err;
  1404. }
  1405. /* watermark setup */
  1406. static u32 dce6_line_buffer_adjust(struct radeon_device *rdev,
  1407. struct radeon_crtc *radeon_crtc,
  1408. struct drm_display_mode *mode,
  1409. struct drm_display_mode *other_mode)
  1410. {
  1411. u32 tmp;
  1412. /*
  1413. * Line Buffer Setup
  1414. * There are 3 line buffers, each one shared by 2 display controllers.
  1415. * DC_LB_MEMORY_SPLIT controls how that line buffer is shared between
  1416. * the display controllers. The paritioning is done via one of four
  1417. * preset allocations specified in bits 21:20:
  1418. * 0 - half lb
  1419. * 2 - whole lb, other crtc must be disabled
  1420. */
  1421. /* this can get tricky if we have two large displays on a paired group
  1422. * of crtcs. Ideally for multiple large displays we'd assign them to
  1423. * non-linked crtcs for maximum line buffer allocation.
  1424. */
  1425. if (radeon_crtc->base.enabled && mode) {
  1426. if (other_mode)
  1427. tmp = 0; /* 1/2 */
  1428. else
  1429. tmp = 2; /* whole */
  1430. } else
  1431. tmp = 0;
  1432. WREG32(DC_LB_MEMORY_SPLIT + radeon_crtc->crtc_offset,
  1433. DC_LB_MEMORY_CONFIG(tmp));
  1434. if (radeon_crtc->base.enabled && mode) {
  1435. switch (tmp) {
  1436. case 0:
  1437. default:
  1438. return 4096 * 2;
  1439. case 2:
  1440. return 8192 * 2;
  1441. }
  1442. }
  1443. /* controller not enabled, so no lb used */
  1444. return 0;
  1445. }
  1446. static u32 si_get_number_of_dram_channels(struct radeon_device *rdev)
  1447. {
  1448. u32 tmp = RREG32(MC_SHARED_CHMAP);
  1449. switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
  1450. case 0:
  1451. default:
  1452. return 1;
  1453. case 1:
  1454. return 2;
  1455. case 2:
  1456. return 4;
  1457. case 3:
  1458. return 8;
  1459. case 4:
  1460. return 3;
  1461. case 5:
  1462. return 6;
  1463. case 6:
  1464. return 10;
  1465. case 7:
  1466. return 12;
  1467. case 8:
  1468. return 16;
  1469. }
  1470. }
  1471. struct dce6_wm_params {
  1472. u32 dram_channels; /* number of dram channels */
  1473. u32 yclk; /* bandwidth per dram data pin in kHz */
  1474. u32 sclk; /* engine clock in kHz */
  1475. u32 disp_clk; /* display clock in kHz */
  1476. u32 src_width; /* viewport width */
  1477. u32 active_time; /* active display time in ns */
  1478. u32 blank_time; /* blank time in ns */
  1479. bool interlaced; /* mode is interlaced */
  1480. fixed20_12 vsc; /* vertical scale ratio */
  1481. u32 num_heads; /* number of active crtcs */
  1482. u32 bytes_per_pixel; /* bytes per pixel display + overlay */
  1483. u32 lb_size; /* line buffer allocated to pipe */
  1484. u32 vtaps; /* vertical scaler taps */
  1485. };
  1486. static u32 dce6_dram_bandwidth(struct dce6_wm_params *wm)
  1487. {
  1488. /* Calculate raw DRAM Bandwidth */
  1489. fixed20_12 dram_efficiency; /* 0.7 */
  1490. fixed20_12 yclk, dram_channels, bandwidth;
  1491. fixed20_12 a;
  1492. a.full = dfixed_const(1000);
  1493. yclk.full = dfixed_const(wm->yclk);
  1494. yclk.full = dfixed_div(yclk, a);
  1495. dram_channels.full = dfixed_const(wm->dram_channels * 4);
  1496. a.full = dfixed_const(10);
  1497. dram_efficiency.full = dfixed_const(7);
  1498. dram_efficiency.full = dfixed_div(dram_efficiency, a);
  1499. bandwidth.full = dfixed_mul(dram_channels, yclk);
  1500. bandwidth.full = dfixed_mul(bandwidth, dram_efficiency);
  1501. return dfixed_trunc(bandwidth);
  1502. }
  1503. static u32 dce6_dram_bandwidth_for_display(struct dce6_wm_params *wm)
  1504. {
  1505. /* Calculate DRAM Bandwidth and the part allocated to display. */
  1506. fixed20_12 disp_dram_allocation; /* 0.3 to 0.7 */
  1507. fixed20_12 yclk, dram_channels, bandwidth;
  1508. fixed20_12 a;
  1509. a.full = dfixed_const(1000);
  1510. yclk.full = dfixed_const(wm->yclk);
  1511. yclk.full = dfixed_div(yclk, a);
  1512. dram_channels.full = dfixed_const(wm->dram_channels * 4);
  1513. a.full = dfixed_const(10);
  1514. disp_dram_allocation.full = dfixed_const(3); /* XXX worse case value 0.3 */
  1515. disp_dram_allocation.full = dfixed_div(disp_dram_allocation, a);
  1516. bandwidth.full = dfixed_mul(dram_channels, yclk);
  1517. bandwidth.full = dfixed_mul(bandwidth, disp_dram_allocation);
  1518. return dfixed_trunc(bandwidth);
  1519. }
  1520. static u32 dce6_data_return_bandwidth(struct dce6_wm_params *wm)
  1521. {
  1522. /* Calculate the display Data return Bandwidth */
  1523. fixed20_12 return_efficiency; /* 0.8 */
  1524. fixed20_12 sclk, bandwidth;
  1525. fixed20_12 a;
  1526. a.full = dfixed_const(1000);
  1527. sclk.full = dfixed_const(wm->sclk);
  1528. sclk.full = dfixed_div(sclk, a);
  1529. a.full = dfixed_const(10);
  1530. return_efficiency.full = dfixed_const(8);
  1531. return_efficiency.full = dfixed_div(return_efficiency, a);
  1532. a.full = dfixed_const(32);
  1533. bandwidth.full = dfixed_mul(a, sclk);
  1534. bandwidth.full = dfixed_mul(bandwidth, return_efficiency);
  1535. return dfixed_trunc(bandwidth);
  1536. }
  1537. static u32 dce6_get_dmif_bytes_per_request(struct dce6_wm_params *wm)
  1538. {
  1539. return 32;
  1540. }
  1541. static u32 dce6_dmif_request_bandwidth(struct dce6_wm_params *wm)
  1542. {
  1543. /* Calculate the DMIF Request Bandwidth */
  1544. fixed20_12 disp_clk_request_efficiency; /* 0.8 */
  1545. fixed20_12 disp_clk, sclk, bandwidth;
  1546. fixed20_12 a, b1, b2;
  1547. u32 min_bandwidth;
  1548. a.full = dfixed_const(1000);
  1549. disp_clk.full = dfixed_const(wm->disp_clk);
  1550. disp_clk.full = dfixed_div(disp_clk, a);
  1551. a.full = dfixed_const(dce6_get_dmif_bytes_per_request(wm) / 2);
  1552. b1.full = dfixed_mul(a, disp_clk);
  1553. a.full = dfixed_const(1000);
  1554. sclk.full = dfixed_const(wm->sclk);
  1555. sclk.full = dfixed_div(sclk, a);
  1556. a.full = dfixed_const(dce6_get_dmif_bytes_per_request(wm));
  1557. b2.full = dfixed_mul(a, sclk);
  1558. a.full = dfixed_const(10);
  1559. disp_clk_request_efficiency.full = dfixed_const(8);
  1560. disp_clk_request_efficiency.full = dfixed_div(disp_clk_request_efficiency, a);
  1561. min_bandwidth = min(dfixed_trunc(b1), dfixed_trunc(b2));
  1562. a.full = dfixed_const(min_bandwidth);
  1563. bandwidth.full = dfixed_mul(a, disp_clk_request_efficiency);
  1564. return dfixed_trunc(bandwidth);
  1565. }
  1566. static u32 dce6_available_bandwidth(struct dce6_wm_params *wm)
  1567. {
  1568. /* Calculate the Available bandwidth. Display can use this temporarily but not in average. */
  1569. u32 dram_bandwidth = dce6_dram_bandwidth(wm);
  1570. u32 data_return_bandwidth = dce6_data_return_bandwidth(wm);
  1571. u32 dmif_req_bandwidth = dce6_dmif_request_bandwidth(wm);
  1572. return min(dram_bandwidth, min(data_return_bandwidth, dmif_req_bandwidth));
  1573. }
  1574. static u32 dce6_average_bandwidth(struct dce6_wm_params *wm)
  1575. {
  1576. /* Calculate the display mode Average Bandwidth
  1577. * DisplayMode should contain the source and destination dimensions,
  1578. * timing, etc.
  1579. */
  1580. fixed20_12 bpp;
  1581. fixed20_12 line_time;
  1582. fixed20_12 src_width;
  1583. fixed20_12 bandwidth;
  1584. fixed20_12 a;
  1585. a.full = dfixed_const(1000);
  1586. line_time.full = dfixed_const(wm->active_time + wm->blank_time);
  1587. line_time.full = dfixed_div(line_time, a);
  1588. bpp.full = dfixed_const(wm->bytes_per_pixel);
  1589. src_width.full = dfixed_const(wm->src_width);
  1590. bandwidth.full = dfixed_mul(src_width, bpp);
  1591. bandwidth.full = dfixed_mul(bandwidth, wm->vsc);
  1592. bandwidth.full = dfixed_div(bandwidth, line_time);
  1593. return dfixed_trunc(bandwidth);
  1594. }
  1595. static u32 dce6_latency_watermark(struct dce6_wm_params *wm)
  1596. {
  1597. /* First calcualte the latency in ns */
  1598. u32 mc_latency = 2000; /* 2000 ns. */
  1599. u32 available_bandwidth = dce6_available_bandwidth(wm);
  1600. u32 worst_chunk_return_time = (512 * 8 * 1000) / available_bandwidth;
  1601. u32 cursor_line_pair_return_time = (128 * 4 * 1000) / available_bandwidth;
  1602. u32 dc_latency = 40000000 / wm->disp_clk; /* dc pipe latency */
  1603. u32 other_heads_data_return_time = ((wm->num_heads + 1) * worst_chunk_return_time) +
  1604. (wm->num_heads * cursor_line_pair_return_time);
  1605. u32 latency = mc_latency + other_heads_data_return_time + dc_latency;
  1606. u32 max_src_lines_per_dst_line, lb_fill_bw, line_fill_time;
  1607. u32 tmp, dmif_size = 12288;
  1608. fixed20_12 a, b, c;
  1609. if (wm->num_heads == 0)
  1610. return 0;
  1611. a.full = dfixed_const(2);
  1612. b.full = dfixed_const(1);
  1613. if ((wm->vsc.full > a.full) ||
  1614. ((wm->vsc.full > b.full) && (wm->vtaps >= 3)) ||
  1615. (wm->vtaps >= 5) ||
  1616. ((wm->vsc.full >= a.full) && wm->interlaced))
  1617. max_src_lines_per_dst_line = 4;
  1618. else
  1619. max_src_lines_per_dst_line = 2;
  1620. a.full = dfixed_const(available_bandwidth);
  1621. b.full = dfixed_const(wm->num_heads);
  1622. a.full = dfixed_div(a, b);
  1623. b.full = dfixed_const(mc_latency + 512);
  1624. c.full = dfixed_const(wm->disp_clk);
  1625. b.full = dfixed_div(b, c);
  1626. c.full = dfixed_const(dmif_size);
  1627. b.full = dfixed_div(c, b);
  1628. tmp = min(dfixed_trunc(a), dfixed_trunc(b));
  1629. b.full = dfixed_const(1000);
  1630. c.full = dfixed_const(wm->disp_clk);
  1631. b.full = dfixed_div(c, b);
  1632. c.full = dfixed_const(wm->bytes_per_pixel);
  1633. b.full = dfixed_mul(b, c);
  1634. lb_fill_bw = min(tmp, dfixed_trunc(b));
  1635. a.full = dfixed_const(max_src_lines_per_dst_line * wm->src_width * wm->bytes_per_pixel);
  1636. b.full = dfixed_const(1000);
  1637. c.full = dfixed_const(lb_fill_bw);
  1638. b.full = dfixed_div(c, b);
  1639. a.full = dfixed_div(a, b);
  1640. line_fill_time = dfixed_trunc(a);
  1641. if (line_fill_time < wm->active_time)
  1642. return latency;
  1643. else
  1644. return latency + (line_fill_time - wm->active_time);
  1645. }
  1646. static bool dce6_average_bandwidth_vs_dram_bandwidth_for_display(struct dce6_wm_params *wm)
  1647. {
  1648. if (dce6_average_bandwidth(wm) <=
  1649. (dce6_dram_bandwidth_for_display(wm) / wm->num_heads))
  1650. return true;
  1651. else
  1652. return false;
  1653. };
  1654. static bool dce6_average_bandwidth_vs_available_bandwidth(struct dce6_wm_params *wm)
  1655. {
  1656. if (dce6_average_bandwidth(wm) <=
  1657. (dce6_available_bandwidth(wm) / wm->num_heads))
  1658. return true;
  1659. else
  1660. return false;
  1661. };
  1662. static bool dce6_check_latency_hiding(struct dce6_wm_params *wm)
  1663. {
  1664. u32 lb_partitions = wm->lb_size / wm->src_width;
  1665. u32 line_time = wm->active_time + wm->blank_time;
  1666. u32 latency_tolerant_lines;
  1667. u32 latency_hiding;
  1668. fixed20_12 a;
  1669. a.full = dfixed_const(1);
  1670. if (wm->vsc.full > a.full)
  1671. latency_tolerant_lines = 1;
  1672. else {
  1673. if (lb_partitions <= (wm->vtaps + 1))
  1674. latency_tolerant_lines = 1;
  1675. else
  1676. latency_tolerant_lines = 2;
  1677. }
  1678. latency_hiding = (latency_tolerant_lines * line_time + wm->blank_time);
  1679. if (dce6_latency_watermark(wm) <= latency_hiding)
  1680. return true;
  1681. else
  1682. return false;
  1683. }
  1684. static void dce6_program_watermarks(struct radeon_device *rdev,
  1685. struct radeon_crtc *radeon_crtc,
  1686. u32 lb_size, u32 num_heads)
  1687. {
  1688. struct drm_display_mode *mode = &radeon_crtc->base.mode;
  1689. struct dce6_wm_params wm_low, wm_high;
  1690. u32 dram_channels;
  1691. u32 pixel_period;
  1692. u32 line_time = 0;
  1693. u32 latency_watermark_a = 0, latency_watermark_b = 0;
  1694. u32 priority_a_mark = 0, priority_b_mark = 0;
  1695. u32 priority_a_cnt = PRIORITY_OFF;
  1696. u32 priority_b_cnt = PRIORITY_OFF;
  1697. u32 tmp, arb_control3;
  1698. fixed20_12 a, b, c;
  1699. if (radeon_crtc->base.enabled && num_heads && mode) {
  1700. pixel_period = 1000000 / (u32)mode->clock;
  1701. line_time = min((u32)mode->crtc_htotal * pixel_period, (u32)65535);
  1702. priority_a_cnt = 0;
  1703. priority_b_cnt = 0;
  1704. if (rdev->family == CHIP_ARUBA)
  1705. dram_channels = evergreen_get_number_of_dram_channels(rdev);
  1706. else
  1707. dram_channels = si_get_number_of_dram_channels(rdev);
  1708. /* watermark for high clocks */
  1709. if ((rdev->pm.pm_method == PM_METHOD_DPM) && rdev->pm.dpm_enabled) {
  1710. wm_high.yclk =
  1711. radeon_dpm_get_mclk(rdev, false) * 10;
  1712. wm_high.sclk =
  1713. radeon_dpm_get_sclk(rdev, false) * 10;
  1714. } else {
  1715. wm_high.yclk = rdev->pm.current_mclk * 10;
  1716. wm_high.sclk = rdev->pm.current_sclk * 10;
  1717. }
  1718. wm_high.disp_clk = mode->clock;
  1719. wm_high.src_width = mode->crtc_hdisplay;
  1720. wm_high.active_time = mode->crtc_hdisplay * pixel_period;
  1721. wm_high.blank_time = line_time - wm_high.active_time;
  1722. wm_high.interlaced = false;
  1723. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  1724. wm_high.interlaced = true;
  1725. wm_high.vsc = radeon_crtc->vsc;
  1726. wm_high.vtaps = 1;
  1727. if (radeon_crtc->rmx_type != RMX_OFF)
  1728. wm_high.vtaps = 2;
  1729. wm_high.bytes_per_pixel = 4; /* XXX: get this from fb config */
  1730. wm_high.lb_size = lb_size;
  1731. wm_high.dram_channels = dram_channels;
  1732. wm_high.num_heads = num_heads;
  1733. /* watermark for low clocks */
  1734. if ((rdev->pm.pm_method == PM_METHOD_DPM) && rdev->pm.dpm_enabled) {
  1735. wm_low.yclk =
  1736. radeon_dpm_get_mclk(rdev, true) * 10;
  1737. wm_low.sclk =
  1738. radeon_dpm_get_sclk(rdev, true) * 10;
  1739. } else {
  1740. wm_low.yclk = rdev->pm.current_mclk * 10;
  1741. wm_low.sclk = rdev->pm.current_sclk * 10;
  1742. }
  1743. wm_low.disp_clk = mode->clock;
  1744. wm_low.src_width = mode->crtc_hdisplay;
  1745. wm_low.active_time = mode->crtc_hdisplay * pixel_period;
  1746. wm_low.blank_time = line_time - wm_low.active_time;
  1747. wm_low.interlaced = false;
  1748. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  1749. wm_low.interlaced = true;
  1750. wm_low.vsc = radeon_crtc->vsc;
  1751. wm_low.vtaps = 1;
  1752. if (radeon_crtc->rmx_type != RMX_OFF)
  1753. wm_low.vtaps = 2;
  1754. wm_low.bytes_per_pixel = 4; /* XXX: get this from fb config */
  1755. wm_low.lb_size = lb_size;
  1756. wm_low.dram_channels = dram_channels;
  1757. wm_low.num_heads = num_heads;
  1758. /* set for high clocks */
  1759. latency_watermark_a = min(dce6_latency_watermark(&wm_high), (u32)65535);
  1760. /* set for low clocks */
  1761. latency_watermark_b = min(dce6_latency_watermark(&wm_low), (u32)65535);
  1762. /* possibly force display priority to high */
  1763. /* should really do this at mode validation time... */
  1764. if (!dce6_average_bandwidth_vs_dram_bandwidth_for_display(&wm_high) ||
  1765. !dce6_average_bandwidth_vs_available_bandwidth(&wm_high) ||
  1766. !dce6_check_latency_hiding(&wm_high) ||
  1767. (rdev->disp_priority == 2)) {
  1768. DRM_DEBUG_KMS("force priority to high\n");
  1769. priority_a_cnt |= PRIORITY_ALWAYS_ON;
  1770. priority_b_cnt |= PRIORITY_ALWAYS_ON;
  1771. }
  1772. if (!dce6_average_bandwidth_vs_dram_bandwidth_for_display(&wm_low) ||
  1773. !dce6_average_bandwidth_vs_available_bandwidth(&wm_low) ||
  1774. !dce6_check_latency_hiding(&wm_low) ||
  1775. (rdev->disp_priority == 2)) {
  1776. DRM_DEBUG_KMS("force priority to high\n");
  1777. priority_a_cnt |= PRIORITY_ALWAYS_ON;
  1778. priority_b_cnt |= PRIORITY_ALWAYS_ON;
  1779. }
  1780. a.full = dfixed_const(1000);
  1781. b.full = dfixed_const(mode->clock);
  1782. b.full = dfixed_div(b, a);
  1783. c.full = dfixed_const(latency_watermark_a);
  1784. c.full = dfixed_mul(c, b);
  1785. c.full = dfixed_mul(c, radeon_crtc->hsc);
  1786. c.full = dfixed_div(c, a);
  1787. a.full = dfixed_const(16);
  1788. c.full = dfixed_div(c, a);
  1789. priority_a_mark = dfixed_trunc(c);
  1790. priority_a_cnt |= priority_a_mark & PRIORITY_MARK_MASK;
  1791. a.full = dfixed_const(1000);
  1792. b.full = dfixed_const(mode->clock);
  1793. b.full = dfixed_div(b, a);
  1794. c.full = dfixed_const(latency_watermark_b);
  1795. c.full = dfixed_mul(c, b);
  1796. c.full = dfixed_mul(c, radeon_crtc->hsc);
  1797. c.full = dfixed_div(c, a);
  1798. a.full = dfixed_const(16);
  1799. c.full = dfixed_div(c, a);
  1800. priority_b_mark = dfixed_trunc(c);
  1801. priority_b_cnt |= priority_b_mark & PRIORITY_MARK_MASK;
  1802. }
  1803. /* select wm A */
  1804. arb_control3 = RREG32(DPG_PIPE_ARBITRATION_CONTROL3 + radeon_crtc->crtc_offset);
  1805. tmp = arb_control3;
  1806. tmp &= ~LATENCY_WATERMARK_MASK(3);
  1807. tmp |= LATENCY_WATERMARK_MASK(1);
  1808. WREG32(DPG_PIPE_ARBITRATION_CONTROL3 + radeon_crtc->crtc_offset, tmp);
  1809. WREG32(DPG_PIPE_LATENCY_CONTROL + radeon_crtc->crtc_offset,
  1810. (LATENCY_LOW_WATERMARK(latency_watermark_a) |
  1811. LATENCY_HIGH_WATERMARK(line_time)));
  1812. /* select wm B */
  1813. tmp = RREG32(DPG_PIPE_ARBITRATION_CONTROL3 + radeon_crtc->crtc_offset);
  1814. tmp &= ~LATENCY_WATERMARK_MASK(3);
  1815. tmp |= LATENCY_WATERMARK_MASK(2);
  1816. WREG32(DPG_PIPE_ARBITRATION_CONTROL3 + radeon_crtc->crtc_offset, tmp);
  1817. WREG32(DPG_PIPE_LATENCY_CONTROL + radeon_crtc->crtc_offset,
  1818. (LATENCY_LOW_WATERMARK(latency_watermark_b) |
  1819. LATENCY_HIGH_WATERMARK(line_time)));
  1820. /* restore original selection */
  1821. WREG32(DPG_PIPE_ARBITRATION_CONTROL3 + radeon_crtc->crtc_offset, arb_control3);
  1822. /* write the priority marks */
  1823. WREG32(PRIORITY_A_CNT + radeon_crtc->crtc_offset, priority_a_cnt);
  1824. WREG32(PRIORITY_B_CNT + radeon_crtc->crtc_offset, priority_b_cnt);
  1825. }
  1826. void dce6_bandwidth_update(struct radeon_device *rdev)
  1827. {
  1828. struct drm_display_mode *mode0 = NULL;
  1829. struct drm_display_mode *mode1 = NULL;
  1830. u32 num_heads = 0, lb_size;
  1831. int i;
  1832. radeon_update_display_priority(rdev);
  1833. for (i = 0; i < rdev->num_crtc; i++) {
  1834. if (rdev->mode_info.crtcs[i]->base.enabled)
  1835. num_heads++;
  1836. }
  1837. for (i = 0; i < rdev->num_crtc; i += 2) {
  1838. mode0 = &rdev->mode_info.crtcs[i]->base.mode;
  1839. mode1 = &rdev->mode_info.crtcs[i+1]->base.mode;
  1840. lb_size = dce6_line_buffer_adjust(rdev, rdev->mode_info.crtcs[i], mode0, mode1);
  1841. dce6_program_watermarks(rdev, rdev->mode_info.crtcs[i], lb_size, num_heads);
  1842. lb_size = dce6_line_buffer_adjust(rdev, rdev->mode_info.crtcs[i+1], mode1, mode0);
  1843. dce6_program_watermarks(rdev, rdev->mode_info.crtcs[i+1], lb_size, num_heads);
  1844. }
  1845. }
  1846. /*
  1847. * Core functions
  1848. */
  1849. static void si_tiling_mode_table_init(struct radeon_device *rdev)
  1850. {
  1851. const u32 num_tile_mode_states = 32;
  1852. u32 reg_offset, gb_tile_moden, split_equal_to_row_size;
  1853. switch (rdev->config.si.mem_row_size_in_kb) {
  1854. case 1:
  1855. split_equal_to_row_size = ADDR_SURF_TILE_SPLIT_1KB;
  1856. break;
  1857. case 2:
  1858. default:
  1859. split_equal_to_row_size = ADDR_SURF_TILE_SPLIT_2KB;
  1860. break;
  1861. case 4:
  1862. split_equal_to_row_size = ADDR_SURF_TILE_SPLIT_4KB;
  1863. break;
  1864. }
  1865. if ((rdev->family == CHIP_TAHITI) ||
  1866. (rdev->family == CHIP_PITCAIRN)) {
  1867. for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++) {
  1868. switch (reg_offset) {
  1869. case 0: /* non-AA compressed depth or any compressed stencil */
  1870. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1871. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  1872. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1873. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  1874. NUM_BANKS(ADDR_SURF_16_BANK) |
  1875. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1876. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  1877. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  1878. break;
  1879. case 1: /* 2xAA/4xAA compressed depth only */
  1880. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1881. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  1882. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1883. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
  1884. NUM_BANKS(ADDR_SURF_16_BANK) |
  1885. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1886. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  1887. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  1888. break;
  1889. case 2: /* 8xAA compressed depth only */
  1890. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1891. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  1892. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1893. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  1894. NUM_BANKS(ADDR_SURF_16_BANK) |
  1895. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1896. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  1897. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  1898. break;
  1899. case 3: /* 2xAA/4xAA compressed depth with stencil (for depth buffer) */
  1900. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1901. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  1902. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1903. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
  1904. NUM_BANKS(ADDR_SURF_16_BANK) |
  1905. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1906. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  1907. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  1908. break;
  1909. case 4: /* Maps w/ a dimension less than the 2D macro-tile dimensions (for mipmapped depth textures) */
  1910. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  1911. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  1912. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1913. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  1914. NUM_BANKS(ADDR_SURF_16_BANK) |
  1915. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1916. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  1917. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  1918. break;
  1919. case 5: /* Uncompressed 16bpp depth - and stencil buffer allocated with it */
  1920. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1921. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  1922. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1923. TILE_SPLIT(split_equal_to_row_size) |
  1924. NUM_BANKS(ADDR_SURF_16_BANK) |
  1925. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1926. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  1927. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  1928. break;
  1929. case 6: /* Uncompressed 32bpp depth - and stencil buffer allocated with it */
  1930. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1931. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  1932. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1933. TILE_SPLIT(split_equal_to_row_size) |
  1934. NUM_BANKS(ADDR_SURF_16_BANK) |
  1935. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1936. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  1937. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
  1938. break;
  1939. case 7: /* Uncompressed 8bpp stencil without depth (drivers typically do not use) */
  1940. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1941. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  1942. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1943. TILE_SPLIT(split_equal_to_row_size) |
  1944. NUM_BANKS(ADDR_SURF_16_BANK) |
  1945. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1946. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  1947. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  1948. break;
  1949. case 8: /* 1D and 1D Array Surfaces */
  1950. gb_tile_moden = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
  1951. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  1952. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1953. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  1954. NUM_BANKS(ADDR_SURF_16_BANK) |
  1955. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1956. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  1957. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  1958. break;
  1959. case 9: /* Displayable maps. */
  1960. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  1961. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  1962. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1963. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  1964. NUM_BANKS(ADDR_SURF_16_BANK) |
  1965. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1966. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  1967. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  1968. break;
  1969. case 10: /* Display 8bpp. */
  1970. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1971. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  1972. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1973. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  1974. NUM_BANKS(ADDR_SURF_16_BANK) |
  1975. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1976. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  1977. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  1978. break;
  1979. case 11: /* Display 16bpp. */
  1980. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1981. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  1982. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1983. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  1984. NUM_BANKS(ADDR_SURF_16_BANK) |
  1985. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1986. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  1987. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  1988. break;
  1989. case 12: /* Display 32bpp. */
  1990. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1991. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  1992. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1993. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
  1994. NUM_BANKS(ADDR_SURF_16_BANK) |
  1995. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1996. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  1997. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
  1998. break;
  1999. case 13: /* Thin. */
  2000. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2001. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2002. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2003. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  2004. NUM_BANKS(ADDR_SURF_16_BANK) |
  2005. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2006. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2007. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2008. break;
  2009. case 14: /* Thin 8 bpp. */
  2010. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2011. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2012. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2013. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2014. NUM_BANKS(ADDR_SURF_16_BANK) |
  2015. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2016. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2017. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
  2018. break;
  2019. case 15: /* Thin 16 bpp. */
  2020. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2021. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2022. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2023. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2024. NUM_BANKS(ADDR_SURF_16_BANK) |
  2025. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2026. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2027. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
  2028. break;
  2029. case 16: /* Thin 32 bpp. */
  2030. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2031. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2032. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2033. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
  2034. NUM_BANKS(ADDR_SURF_16_BANK) |
  2035. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2036. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2037. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
  2038. break;
  2039. case 17: /* Thin 64 bpp. */
  2040. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2041. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2042. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2043. TILE_SPLIT(split_equal_to_row_size) |
  2044. NUM_BANKS(ADDR_SURF_16_BANK) |
  2045. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2046. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2047. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
  2048. break;
  2049. case 21: /* 8 bpp PRT. */
  2050. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2051. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2052. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2053. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2054. NUM_BANKS(ADDR_SURF_16_BANK) |
  2055. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
  2056. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2057. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2058. break;
  2059. case 22: /* 16 bpp PRT */
  2060. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2061. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2062. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2063. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2064. NUM_BANKS(ADDR_SURF_16_BANK) |
  2065. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2066. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2067. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
  2068. break;
  2069. case 23: /* 32 bpp PRT */
  2070. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2071. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2072. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2073. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2074. NUM_BANKS(ADDR_SURF_16_BANK) |
  2075. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2076. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2077. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2078. break;
  2079. case 24: /* 64 bpp PRT */
  2080. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2081. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2082. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2083. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
  2084. NUM_BANKS(ADDR_SURF_16_BANK) |
  2085. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2086. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2087. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2088. break;
  2089. case 25: /* 128 bpp PRT */
  2090. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2091. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2092. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2093. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_1KB) |
  2094. NUM_BANKS(ADDR_SURF_8_BANK) |
  2095. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2096. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2097. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
  2098. break;
  2099. default:
  2100. gb_tile_moden = 0;
  2101. break;
  2102. }
  2103. rdev->config.si.tile_mode_array[reg_offset] = gb_tile_moden;
  2104. WREG32(GB_TILE_MODE0 + (reg_offset * 4), gb_tile_moden);
  2105. }
  2106. } else if ((rdev->family == CHIP_VERDE) ||
  2107. (rdev->family == CHIP_OLAND) ||
  2108. (rdev->family == CHIP_HAINAN)) {
  2109. for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++) {
  2110. switch (reg_offset) {
  2111. case 0: /* non-AA compressed depth or any compressed stencil */
  2112. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2113. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2114. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2115. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  2116. NUM_BANKS(ADDR_SURF_16_BANK) |
  2117. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2118. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2119. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
  2120. break;
  2121. case 1: /* 2xAA/4xAA compressed depth only */
  2122. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2123. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2124. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2125. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
  2126. NUM_BANKS(ADDR_SURF_16_BANK) |
  2127. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2128. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2129. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
  2130. break;
  2131. case 2: /* 8xAA compressed depth only */
  2132. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2133. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2134. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2135. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2136. NUM_BANKS(ADDR_SURF_16_BANK) |
  2137. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2138. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2139. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
  2140. break;
  2141. case 3: /* 2xAA/4xAA compressed depth with stencil (for depth buffer) */
  2142. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2143. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2144. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2145. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
  2146. NUM_BANKS(ADDR_SURF_16_BANK) |
  2147. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2148. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2149. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
  2150. break;
  2151. case 4: /* Maps w/ a dimension less than the 2D macro-tile dimensions (for mipmapped depth textures) */
  2152. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2153. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2154. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2155. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  2156. NUM_BANKS(ADDR_SURF_16_BANK) |
  2157. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2158. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2159. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2160. break;
  2161. case 5: /* Uncompressed 16bpp depth - and stencil buffer allocated with it */
  2162. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2163. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2164. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2165. TILE_SPLIT(split_equal_to_row_size) |
  2166. NUM_BANKS(ADDR_SURF_16_BANK) |
  2167. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2168. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2169. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2170. break;
  2171. case 6: /* Uncompressed 32bpp depth - and stencil buffer allocated with it */
  2172. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2173. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2174. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2175. TILE_SPLIT(split_equal_to_row_size) |
  2176. NUM_BANKS(ADDR_SURF_16_BANK) |
  2177. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2178. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2179. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2180. break;
  2181. case 7: /* Uncompressed 8bpp stencil without depth (drivers typically do not use) */
  2182. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2183. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2184. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2185. TILE_SPLIT(split_equal_to_row_size) |
  2186. NUM_BANKS(ADDR_SURF_16_BANK) |
  2187. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2188. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2189. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
  2190. break;
  2191. case 8: /* 1D and 1D Array Surfaces */
  2192. gb_tile_moden = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
  2193. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2194. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2195. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  2196. NUM_BANKS(ADDR_SURF_16_BANK) |
  2197. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2198. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2199. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2200. break;
  2201. case 9: /* Displayable maps. */
  2202. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2203. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2204. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2205. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  2206. NUM_BANKS(ADDR_SURF_16_BANK) |
  2207. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2208. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2209. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2210. break;
  2211. case 10: /* Display 8bpp. */
  2212. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2213. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2214. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2215. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2216. NUM_BANKS(ADDR_SURF_16_BANK) |
  2217. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2218. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2219. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
  2220. break;
  2221. case 11: /* Display 16bpp. */
  2222. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2223. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2224. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2225. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2226. NUM_BANKS(ADDR_SURF_16_BANK) |
  2227. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2228. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2229. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2230. break;
  2231. case 12: /* Display 32bpp. */
  2232. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2233. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2234. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2235. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
  2236. NUM_BANKS(ADDR_SURF_16_BANK) |
  2237. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2238. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2239. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2240. break;
  2241. case 13: /* Thin. */
  2242. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2243. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2244. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2245. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  2246. NUM_BANKS(ADDR_SURF_16_BANK) |
  2247. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2248. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2249. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2250. break;
  2251. case 14: /* Thin 8 bpp. */
  2252. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2253. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2254. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2255. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2256. NUM_BANKS(ADDR_SURF_16_BANK) |
  2257. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2258. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2259. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2260. break;
  2261. case 15: /* Thin 16 bpp. */
  2262. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2263. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2264. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2265. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2266. NUM_BANKS(ADDR_SURF_16_BANK) |
  2267. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2268. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2269. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2270. break;
  2271. case 16: /* Thin 32 bpp. */
  2272. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2273. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2274. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2275. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
  2276. NUM_BANKS(ADDR_SURF_16_BANK) |
  2277. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2278. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2279. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2280. break;
  2281. case 17: /* Thin 64 bpp. */
  2282. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2283. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2284. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2285. TILE_SPLIT(split_equal_to_row_size) |
  2286. NUM_BANKS(ADDR_SURF_16_BANK) |
  2287. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2288. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2289. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2290. break;
  2291. case 21: /* 8 bpp PRT. */
  2292. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2293. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2294. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2295. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2296. NUM_BANKS(ADDR_SURF_16_BANK) |
  2297. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
  2298. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2299. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2300. break;
  2301. case 22: /* 16 bpp PRT */
  2302. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2303. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2304. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2305. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2306. NUM_BANKS(ADDR_SURF_16_BANK) |
  2307. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2308. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2309. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
  2310. break;
  2311. case 23: /* 32 bpp PRT */
  2312. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2313. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2314. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2315. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2316. NUM_BANKS(ADDR_SURF_16_BANK) |
  2317. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2318. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2319. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2320. break;
  2321. case 24: /* 64 bpp PRT */
  2322. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2323. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2324. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2325. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
  2326. NUM_BANKS(ADDR_SURF_16_BANK) |
  2327. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2328. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2329. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2330. break;
  2331. case 25: /* 128 bpp PRT */
  2332. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2333. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2334. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2335. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_1KB) |
  2336. NUM_BANKS(ADDR_SURF_8_BANK) |
  2337. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2338. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2339. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
  2340. break;
  2341. default:
  2342. gb_tile_moden = 0;
  2343. break;
  2344. }
  2345. rdev->config.si.tile_mode_array[reg_offset] = gb_tile_moden;
  2346. WREG32(GB_TILE_MODE0 + (reg_offset * 4), gb_tile_moden);
  2347. }
  2348. } else
  2349. DRM_ERROR("unknown asic: 0x%x\n", rdev->family);
  2350. }
  2351. static void si_select_se_sh(struct radeon_device *rdev,
  2352. u32 se_num, u32 sh_num)
  2353. {
  2354. u32 data = INSTANCE_BROADCAST_WRITES;
  2355. if ((se_num == 0xffffffff) && (sh_num == 0xffffffff))
  2356. data |= SH_BROADCAST_WRITES | SE_BROADCAST_WRITES;
  2357. else if (se_num == 0xffffffff)
  2358. data |= SE_BROADCAST_WRITES | SH_INDEX(sh_num);
  2359. else if (sh_num == 0xffffffff)
  2360. data |= SH_BROADCAST_WRITES | SE_INDEX(se_num);
  2361. else
  2362. data |= SH_INDEX(sh_num) | SE_INDEX(se_num);
  2363. WREG32(GRBM_GFX_INDEX, data);
  2364. }
  2365. static u32 si_create_bitmask(u32 bit_width)
  2366. {
  2367. u32 i, mask = 0;
  2368. for (i = 0; i < bit_width; i++) {
  2369. mask <<= 1;
  2370. mask |= 1;
  2371. }
  2372. return mask;
  2373. }
  2374. static u32 si_get_cu_enabled(struct radeon_device *rdev, u32 cu_per_sh)
  2375. {
  2376. u32 data, mask;
  2377. data = RREG32(CC_GC_SHADER_ARRAY_CONFIG);
  2378. if (data & 1)
  2379. data &= INACTIVE_CUS_MASK;
  2380. else
  2381. data = 0;
  2382. data |= RREG32(GC_USER_SHADER_ARRAY_CONFIG);
  2383. data >>= INACTIVE_CUS_SHIFT;
  2384. mask = si_create_bitmask(cu_per_sh);
  2385. return ~data & mask;
  2386. }
  2387. static void si_setup_spi(struct radeon_device *rdev,
  2388. u32 se_num, u32 sh_per_se,
  2389. u32 cu_per_sh)
  2390. {
  2391. int i, j, k;
  2392. u32 data, mask, active_cu;
  2393. for (i = 0; i < se_num; i++) {
  2394. for (j = 0; j < sh_per_se; j++) {
  2395. si_select_se_sh(rdev, i, j);
  2396. data = RREG32(SPI_STATIC_THREAD_MGMT_3);
  2397. active_cu = si_get_cu_enabled(rdev, cu_per_sh);
  2398. mask = 1;
  2399. for (k = 0; k < 16; k++) {
  2400. mask <<= k;
  2401. if (active_cu & mask) {
  2402. data &= ~mask;
  2403. WREG32(SPI_STATIC_THREAD_MGMT_3, data);
  2404. break;
  2405. }
  2406. }
  2407. }
  2408. }
  2409. si_select_se_sh(rdev, 0xffffffff, 0xffffffff);
  2410. }
  2411. static u32 si_get_rb_disabled(struct radeon_device *rdev,
  2412. u32 max_rb_num, u32 se_num,
  2413. u32 sh_per_se)
  2414. {
  2415. u32 data, mask;
  2416. data = RREG32(CC_RB_BACKEND_DISABLE);
  2417. if (data & 1)
  2418. data &= BACKEND_DISABLE_MASK;
  2419. else
  2420. data = 0;
  2421. data |= RREG32(GC_USER_RB_BACKEND_DISABLE);
  2422. data >>= BACKEND_DISABLE_SHIFT;
  2423. mask = si_create_bitmask(max_rb_num / se_num / sh_per_se);
  2424. return data & mask;
  2425. }
  2426. static void si_setup_rb(struct radeon_device *rdev,
  2427. u32 se_num, u32 sh_per_se,
  2428. u32 max_rb_num)
  2429. {
  2430. int i, j;
  2431. u32 data, mask;
  2432. u32 disabled_rbs = 0;
  2433. u32 enabled_rbs = 0;
  2434. for (i = 0; i < se_num; i++) {
  2435. for (j = 0; j < sh_per_se; j++) {
  2436. si_select_se_sh(rdev, i, j);
  2437. data = si_get_rb_disabled(rdev, max_rb_num, se_num, sh_per_se);
  2438. disabled_rbs |= data << ((i * sh_per_se + j) * TAHITI_RB_BITMAP_WIDTH_PER_SH);
  2439. }
  2440. }
  2441. si_select_se_sh(rdev, 0xffffffff, 0xffffffff);
  2442. mask = 1;
  2443. for (i = 0; i < max_rb_num; i++) {
  2444. if (!(disabled_rbs & mask))
  2445. enabled_rbs |= mask;
  2446. mask <<= 1;
  2447. }
  2448. for (i = 0; i < se_num; i++) {
  2449. si_select_se_sh(rdev, i, 0xffffffff);
  2450. data = 0;
  2451. for (j = 0; j < sh_per_se; j++) {
  2452. switch (enabled_rbs & 3) {
  2453. case 1:
  2454. data |= (RASTER_CONFIG_RB_MAP_0 << (i * sh_per_se + j) * 2);
  2455. break;
  2456. case 2:
  2457. data |= (RASTER_CONFIG_RB_MAP_3 << (i * sh_per_se + j) * 2);
  2458. break;
  2459. case 3:
  2460. default:
  2461. data |= (RASTER_CONFIG_RB_MAP_2 << (i * sh_per_se + j) * 2);
  2462. break;
  2463. }
  2464. enabled_rbs >>= 2;
  2465. }
  2466. WREG32(PA_SC_RASTER_CONFIG, data);
  2467. }
  2468. si_select_se_sh(rdev, 0xffffffff, 0xffffffff);
  2469. }
  2470. static void si_gpu_init(struct radeon_device *rdev)
  2471. {
  2472. u32 gb_addr_config = 0;
  2473. u32 mc_shared_chmap, mc_arb_ramcfg;
  2474. u32 sx_debug_1;
  2475. u32 hdp_host_path_cntl;
  2476. u32 tmp;
  2477. int i, j;
  2478. switch (rdev->family) {
  2479. case CHIP_TAHITI:
  2480. rdev->config.si.max_shader_engines = 2;
  2481. rdev->config.si.max_tile_pipes = 12;
  2482. rdev->config.si.max_cu_per_sh = 8;
  2483. rdev->config.si.max_sh_per_se = 2;
  2484. rdev->config.si.max_backends_per_se = 4;
  2485. rdev->config.si.max_texture_channel_caches = 12;
  2486. rdev->config.si.max_gprs = 256;
  2487. rdev->config.si.max_gs_threads = 32;
  2488. rdev->config.si.max_hw_contexts = 8;
  2489. rdev->config.si.sc_prim_fifo_size_frontend = 0x20;
  2490. rdev->config.si.sc_prim_fifo_size_backend = 0x100;
  2491. rdev->config.si.sc_hiz_tile_fifo_size = 0x30;
  2492. rdev->config.si.sc_earlyz_tile_fifo_size = 0x130;
  2493. gb_addr_config = TAHITI_GB_ADDR_CONFIG_GOLDEN;
  2494. break;
  2495. case CHIP_PITCAIRN:
  2496. rdev->config.si.max_shader_engines = 2;
  2497. rdev->config.si.max_tile_pipes = 8;
  2498. rdev->config.si.max_cu_per_sh = 5;
  2499. rdev->config.si.max_sh_per_se = 2;
  2500. rdev->config.si.max_backends_per_se = 4;
  2501. rdev->config.si.max_texture_channel_caches = 8;
  2502. rdev->config.si.max_gprs = 256;
  2503. rdev->config.si.max_gs_threads = 32;
  2504. rdev->config.si.max_hw_contexts = 8;
  2505. rdev->config.si.sc_prim_fifo_size_frontend = 0x20;
  2506. rdev->config.si.sc_prim_fifo_size_backend = 0x100;
  2507. rdev->config.si.sc_hiz_tile_fifo_size = 0x30;
  2508. rdev->config.si.sc_earlyz_tile_fifo_size = 0x130;
  2509. gb_addr_config = TAHITI_GB_ADDR_CONFIG_GOLDEN;
  2510. break;
  2511. case CHIP_VERDE:
  2512. default:
  2513. rdev->config.si.max_shader_engines = 1;
  2514. rdev->config.si.max_tile_pipes = 4;
  2515. rdev->config.si.max_cu_per_sh = 5;
  2516. rdev->config.si.max_sh_per_se = 2;
  2517. rdev->config.si.max_backends_per_se = 4;
  2518. rdev->config.si.max_texture_channel_caches = 4;
  2519. rdev->config.si.max_gprs = 256;
  2520. rdev->config.si.max_gs_threads = 32;
  2521. rdev->config.si.max_hw_contexts = 8;
  2522. rdev->config.si.sc_prim_fifo_size_frontend = 0x20;
  2523. rdev->config.si.sc_prim_fifo_size_backend = 0x40;
  2524. rdev->config.si.sc_hiz_tile_fifo_size = 0x30;
  2525. rdev->config.si.sc_earlyz_tile_fifo_size = 0x130;
  2526. gb_addr_config = VERDE_GB_ADDR_CONFIG_GOLDEN;
  2527. break;
  2528. case CHIP_OLAND:
  2529. rdev->config.si.max_shader_engines = 1;
  2530. rdev->config.si.max_tile_pipes = 4;
  2531. rdev->config.si.max_cu_per_sh = 6;
  2532. rdev->config.si.max_sh_per_se = 1;
  2533. rdev->config.si.max_backends_per_se = 2;
  2534. rdev->config.si.max_texture_channel_caches = 4;
  2535. rdev->config.si.max_gprs = 256;
  2536. rdev->config.si.max_gs_threads = 16;
  2537. rdev->config.si.max_hw_contexts = 8;
  2538. rdev->config.si.sc_prim_fifo_size_frontend = 0x20;
  2539. rdev->config.si.sc_prim_fifo_size_backend = 0x40;
  2540. rdev->config.si.sc_hiz_tile_fifo_size = 0x30;
  2541. rdev->config.si.sc_earlyz_tile_fifo_size = 0x130;
  2542. gb_addr_config = VERDE_GB_ADDR_CONFIG_GOLDEN;
  2543. break;
  2544. case CHIP_HAINAN:
  2545. rdev->config.si.max_shader_engines = 1;
  2546. rdev->config.si.max_tile_pipes = 4;
  2547. rdev->config.si.max_cu_per_sh = 5;
  2548. rdev->config.si.max_sh_per_se = 1;
  2549. rdev->config.si.max_backends_per_se = 1;
  2550. rdev->config.si.max_texture_channel_caches = 2;
  2551. rdev->config.si.max_gprs = 256;
  2552. rdev->config.si.max_gs_threads = 16;
  2553. rdev->config.si.max_hw_contexts = 8;
  2554. rdev->config.si.sc_prim_fifo_size_frontend = 0x20;
  2555. rdev->config.si.sc_prim_fifo_size_backend = 0x40;
  2556. rdev->config.si.sc_hiz_tile_fifo_size = 0x30;
  2557. rdev->config.si.sc_earlyz_tile_fifo_size = 0x130;
  2558. gb_addr_config = HAINAN_GB_ADDR_CONFIG_GOLDEN;
  2559. break;
  2560. }
  2561. /* Initialize HDP */
  2562. for (i = 0, j = 0; i < 32; i++, j += 0x18) {
  2563. WREG32((0x2c14 + j), 0x00000000);
  2564. WREG32((0x2c18 + j), 0x00000000);
  2565. WREG32((0x2c1c + j), 0x00000000);
  2566. WREG32((0x2c20 + j), 0x00000000);
  2567. WREG32((0x2c24 + j), 0x00000000);
  2568. }
  2569. WREG32(GRBM_CNTL, GRBM_READ_TIMEOUT(0xff));
  2570. evergreen_fix_pci_max_read_req_size(rdev);
  2571. WREG32(BIF_FB_EN, FB_READ_EN | FB_WRITE_EN);
  2572. mc_shared_chmap = RREG32(MC_SHARED_CHMAP);
  2573. mc_arb_ramcfg = RREG32(MC_ARB_RAMCFG);
  2574. rdev->config.si.num_tile_pipes = rdev->config.si.max_tile_pipes;
  2575. rdev->config.si.mem_max_burst_length_bytes = 256;
  2576. tmp = (mc_arb_ramcfg & NOOFCOLS_MASK) >> NOOFCOLS_SHIFT;
  2577. rdev->config.si.mem_row_size_in_kb = (4 * (1 << (8 + tmp))) / 1024;
  2578. if (rdev->config.si.mem_row_size_in_kb > 4)
  2579. rdev->config.si.mem_row_size_in_kb = 4;
  2580. /* XXX use MC settings? */
  2581. rdev->config.si.shader_engine_tile_size = 32;
  2582. rdev->config.si.num_gpus = 1;
  2583. rdev->config.si.multi_gpu_tile_size = 64;
  2584. /* fix up row size */
  2585. gb_addr_config &= ~ROW_SIZE_MASK;
  2586. switch (rdev->config.si.mem_row_size_in_kb) {
  2587. case 1:
  2588. default:
  2589. gb_addr_config |= ROW_SIZE(0);
  2590. break;
  2591. case 2:
  2592. gb_addr_config |= ROW_SIZE(1);
  2593. break;
  2594. case 4:
  2595. gb_addr_config |= ROW_SIZE(2);
  2596. break;
  2597. }
  2598. /* setup tiling info dword. gb_addr_config is not adequate since it does
  2599. * not have bank info, so create a custom tiling dword.
  2600. * bits 3:0 num_pipes
  2601. * bits 7:4 num_banks
  2602. * bits 11:8 group_size
  2603. * bits 15:12 row_size
  2604. */
  2605. rdev->config.si.tile_config = 0;
  2606. switch (rdev->config.si.num_tile_pipes) {
  2607. case 1:
  2608. rdev->config.si.tile_config |= (0 << 0);
  2609. break;
  2610. case 2:
  2611. rdev->config.si.tile_config |= (1 << 0);
  2612. break;
  2613. case 4:
  2614. rdev->config.si.tile_config |= (2 << 0);
  2615. break;
  2616. case 8:
  2617. default:
  2618. /* XXX what about 12? */
  2619. rdev->config.si.tile_config |= (3 << 0);
  2620. break;
  2621. }
  2622. switch ((mc_arb_ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT) {
  2623. case 0: /* four banks */
  2624. rdev->config.si.tile_config |= 0 << 4;
  2625. break;
  2626. case 1: /* eight banks */
  2627. rdev->config.si.tile_config |= 1 << 4;
  2628. break;
  2629. case 2: /* sixteen banks */
  2630. default:
  2631. rdev->config.si.tile_config |= 2 << 4;
  2632. break;
  2633. }
  2634. rdev->config.si.tile_config |=
  2635. ((gb_addr_config & PIPE_INTERLEAVE_SIZE_MASK) >> PIPE_INTERLEAVE_SIZE_SHIFT) << 8;
  2636. rdev->config.si.tile_config |=
  2637. ((gb_addr_config & ROW_SIZE_MASK) >> ROW_SIZE_SHIFT) << 12;
  2638. WREG32(GB_ADDR_CONFIG, gb_addr_config);
  2639. WREG32(DMIF_ADDR_CONFIG, gb_addr_config);
  2640. WREG32(DMIF_ADDR_CALC, gb_addr_config);
  2641. WREG32(HDP_ADDR_CONFIG, gb_addr_config);
  2642. WREG32(DMA_TILING_CONFIG + DMA0_REGISTER_OFFSET, gb_addr_config);
  2643. WREG32(DMA_TILING_CONFIG + DMA1_REGISTER_OFFSET, gb_addr_config);
  2644. if (rdev->has_uvd) {
  2645. WREG32(UVD_UDEC_ADDR_CONFIG, gb_addr_config);
  2646. WREG32(UVD_UDEC_DB_ADDR_CONFIG, gb_addr_config);
  2647. WREG32(UVD_UDEC_DBW_ADDR_CONFIG, gb_addr_config);
  2648. }
  2649. si_tiling_mode_table_init(rdev);
  2650. si_setup_rb(rdev, rdev->config.si.max_shader_engines,
  2651. rdev->config.si.max_sh_per_se,
  2652. rdev->config.si.max_backends_per_se);
  2653. si_setup_spi(rdev, rdev->config.si.max_shader_engines,
  2654. rdev->config.si.max_sh_per_se,
  2655. rdev->config.si.max_cu_per_sh);
  2656. /* set HW defaults for 3D engine */
  2657. WREG32(CP_QUEUE_THRESHOLDS, (ROQ_IB1_START(0x16) |
  2658. ROQ_IB2_START(0x2b)));
  2659. WREG32(CP_MEQ_THRESHOLDS, MEQ1_START(0x30) | MEQ2_START(0x60));
  2660. sx_debug_1 = RREG32(SX_DEBUG_1);
  2661. WREG32(SX_DEBUG_1, sx_debug_1);
  2662. WREG32(SPI_CONFIG_CNTL_1, VTX_DONE_DELAY(4));
  2663. WREG32(PA_SC_FIFO_SIZE, (SC_FRONTEND_PRIM_FIFO_SIZE(rdev->config.si.sc_prim_fifo_size_frontend) |
  2664. SC_BACKEND_PRIM_FIFO_SIZE(rdev->config.si.sc_prim_fifo_size_backend) |
  2665. SC_HIZ_TILE_FIFO_SIZE(rdev->config.si.sc_hiz_tile_fifo_size) |
  2666. SC_EARLYZ_TILE_FIFO_SIZE(rdev->config.si.sc_earlyz_tile_fifo_size)));
  2667. WREG32(VGT_NUM_INSTANCES, 1);
  2668. WREG32(CP_PERFMON_CNTL, 0);
  2669. WREG32(SQ_CONFIG, 0);
  2670. WREG32(PA_SC_FORCE_EOV_MAX_CNTS, (FORCE_EOV_MAX_CLK_CNT(4095) |
  2671. FORCE_EOV_MAX_REZ_CNT(255)));
  2672. WREG32(VGT_CACHE_INVALIDATION, CACHE_INVALIDATION(VC_AND_TC) |
  2673. AUTO_INVLD_EN(ES_AND_GS_AUTO));
  2674. WREG32(VGT_GS_VERTEX_REUSE, 16);
  2675. WREG32(PA_SC_LINE_STIPPLE_STATE, 0);
  2676. WREG32(CB_PERFCOUNTER0_SELECT0, 0);
  2677. WREG32(CB_PERFCOUNTER0_SELECT1, 0);
  2678. WREG32(CB_PERFCOUNTER1_SELECT0, 0);
  2679. WREG32(CB_PERFCOUNTER1_SELECT1, 0);
  2680. WREG32(CB_PERFCOUNTER2_SELECT0, 0);
  2681. WREG32(CB_PERFCOUNTER2_SELECT1, 0);
  2682. WREG32(CB_PERFCOUNTER3_SELECT0, 0);
  2683. WREG32(CB_PERFCOUNTER3_SELECT1, 0);
  2684. tmp = RREG32(HDP_MISC_CNTL);
  2685. tmp |= HDP_FLUSH_INVALIDATE_CACHE;
  2686. WREG32(HDP_MISC_CNTL, tmp);
  2687. hdp_host_path_cntl = RREG32(HDP_HOST_PATH_CNTL);
  2688. WREG32(HDP_HOST_PATH_CNTL, hdp_host_path_cntl);
  2689. WREG32(PA_CL_ENHANCE, CLIP_VTX_REORDER_ENA | NUM_CLIP_SEQ(3));
  2690. udelay(50);
  2691. }
  2692. /*
  2693. * GPU scratch registers helpers function.
  2694. */
  2695. static void si_scratch_init(struct radeon_device *rdev)
  2696. {
  2697. int i;
  2698. rdev->scratch.num_reg = 7;
  2699. rdev->scratch.reg_base = SCRATCH_REG0;
  2700. for (i = 0; i < rdev->scratch.num_reg; i++) {
  2701. rdev->scratch.free[i] = true;
  2702. rdev->scratch.reg[i] = rdev->scratch.reg_base + (i * 4);
  2703. }
  2704. }
  2705. void si_fence_ring_emit(struct radeon_device *rdev,
  2706. struct radeon_fence *fence)
  2707. {
  2708. struct radeon_ring *ring = &rdev->ring[fence->ring];
  2709. u64 addr = rdev->fence_drv[fence->ring].gpu_addr;
  2710. /* flush read cache over gart */
  2711. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
  2712. radeon_ring_write(ring, (CP_COHER_CNTL2 - PACKET3_SET_CONFIG_REG_START) >> 2);
  2713. radeon_ring_write(ring, 0);
  2714. radeon_ring_write(ring, PACKET3(PACKET3_SURFACE_SYNC, 3));
  2715. radeon_ring_write(ring, PACKET3_TCL1_ACTION_ENA |
  2716. PACKET3_TC_ACTION_ENA |
  2717. PACKET3_SH_KCACHE_ACTION_ENA |
  2718. PACKET3_SH_ICACHE_ACTION_ENA);
  2719. radeon_ring_write(ring, 0xFFFFFFFF);
  2720. radeon_ring_write(ring, 0);
  2721. radeon_ring_write(ring, 10); /* poll interval */
  2722. /* EVENT_WRITE_EOP - flush caches, send int */
  2723. radeon_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE_EOP, 4));
  2724. radeon_ring_write(ring, EVENT_TYPE(CACHE_FLUSH_AND_INV_TS_EVENT) | EVENT_INDEX(5));
  2725. radeon_ring_write(ring, addr & 0xffffffff);
  2726. radeon_ring_write(ring, (upper_32_bits(addr) & 0xff) | DATA_SEL(1) | INT_SEL(2));
  2727. radeon_ring_write(ring, fence->seq);
  2728. radeon_ring_write(ring, 0);
  2729. }
  2730. /*
  2731. * IB stuff
  2732. */
  2733. void si_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib)
  2734. {
  2735. struct radeon_ring *ring = &rdev->ring[ib->ring];
  2736. u32 header;
  2737. if (ib->is_const_ib) {
  2738. /* set switch buffer packet before const IB */
  2739. radeon_ring_write(ring, PACKET3(PACKET3_SWITCH_BUFFER, 0));
  2740. radeon_ring_write(ring, 0);
  2741. header = PACKET3(PACKET3_INDIRECT_BUFFER_CONST, 2);
  2742. } else {
  2743. u32 next_rptr;
  2744. if (ring->rptr_save_reg) {
  2745. next_rptr = ring->wptr + 3 + 4 + 8;
  2746. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
  2747. radeon_ring_write(ring, ((ring->rptr_save_reg -
  2748. PACKET3_SET_CONFIG_REG_START) >> 2));
  2749. radeon_ring_write(ring, next_rptr);
  2750. } else if (rdev->wb.enabled) {
  2751. next_rptr = ring->wptr + 5 + 4 + 8;
  2752. radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  2753. radeon_ring_write(ring, (1 << 8));
  2754. radeon_ring_write(ring, ring->next_rptr_gpu_addr & 0xfffffffc);
  2755. radeon_ring_write(ring, upper_32_bits(ring->next_rptr_gpu_addr) & 0xffffffff);
  2756. radeon_ring_write(ring, next_rptr);
  2757. }
  2758. header = PACKET3(PACKET3_INDIRECT_BUFFER, 2);
  2759. }
  2760. radeon_ring_write(ring, header);
  2761. radeon_ring_write(ring,
  2762. #ifdef __BIG_ENDIAN
  2763. (2 << 0) |
  2764. #endif
  2765. (ib->gpu_addr & 0xFFFFFFFC));
  2766. radeon_ring_write(ring, upper_32_bits(ib->gpu_addr) & 0xFFFF);
  2767. radeon_ring_write(ring, ib->length_dw |
  2768. (ib->vm ? (ib->vm->id << 24) : 0));
  2769. if (!ib->is_const_ib) {
  2770. /* flush read cache over gart for this vmid */
  2771. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
  2772. radeon_ring_write(ring, (CP_COHER_CNTL2 - PACKET3_SET_CONFIG_REG_START) >> 2);
  2773. radeon_ring_write(ring, ib->vm ? ib->vm->id : 0);
  2774. radeon_ring_write(ring, PACKET3(PACKET3_SURFACE_SYNC, 3));
  2775. radeon_ring_write(ring, PACKET3_TCL1_ACTION_ENA |
  2776. PACKET3_TC_ACTION_ENA |
  2777. PACKET3_SH_KCACHE_ACTION_ENA |
  2778. PACKET3_SH_ICACHE_ACTION_ENA);
  2779. radeon_ring_write(ring, 0xFFFFFFFF);
  2780. radeon_ring_write(ring, 0);
  2781. radeon_ring_write(ring, 10); /* poll interval */
  2782. }
  2783. }
  2784. /*
  2785. * CP.
  2786. */
  2787. static void si_cp_enable(struct radeon_device *rdev, bool enable)
  2788. {
  2789. if (enable)
  2790. WREG32(CP_ME_CNTL, 0);
  2791. else {
  2792. radeon_ttm_set_active_vram_size(rdev, rdev->mc.visible_vram_size);
  2793. WREG32(CP_ME_CNTL, (CP_ME_HALT | CP_PFP_HALT | CP_CE_HALT));
  2794. WREG32(SCRATCH_UMSK, 0);
  2795. rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false;
  2796. rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX].ready = false;
  2797. rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX].ready = false;
  2798. }
  2799. udelay(50);
  2800. }
  2801. static int si_cp_load_microcode(struct radeon_device *rdev)
  2802. {
  2803. const __be32 *fw_data;
  2804. int i;
  2805. if (!rdev->me_fw || !rdev->pfp_fw)
  2806. return -EINVAL;
  2807. si_cp_enable(rdev, false);
  2808. /* PFP */
  2809. fw_data = (const __be32 *)rdev->pfp_fw->data;
  2810. WREG32(CP_PFP_UCODE_ADDR, 0);
  2811. for (i = 0; i < SI_PFP_UCODE_SIZE; i++)
  2812. WREG32(CP_PFP_UCODE_DATA, be32_to_cpup(fw_data++));
  2813. WREG32(CP_PFP_UCODE_ADDR, 0);
  2814. /* CE */
  2815. fw_data = (const __be32 *)rdev->ce_fw->data;
  2816. WREG32(CP_CE_UCODE_ADDR, 0);
  2817. for (i = 0; i < SI_CE_UCODE_SIZE; i++)
  2818. WREG32(CP_CE_UCODE_DATA, be32_to_cpup(fw_data++));
  2819. WREG32(CP_CE_UCODE_ADDR, 0);
  2820. /* ME */
  2821. fw_data = (const __be32 *)rdev->me_fw->data;
  2822. WREG32(CP_ME_RAM_WADDR, 0);
  2823. for (i = 0; i < SI_PM4_UCODE_SIZE; i++)
  2824. WREG32(CP_ME_RAM_DATA, be32_to_cpup(fw_data++));
  2825. WREG32(CP_ME_RAM_WADDR, 0);
  2826. WREG32(CP_PFP_UCODE_ADDR, 0);
  2827. WREG32(CP_CE_UCODE_ADDR, 0);
  2828. WREG32(CP_ME_RAM_WADDR, 0);
  2829. WREG32(CP_ME_RAM_RADDR, 0);
  2830. return 0;
  2831. }
  2832. static int si_cp_start(struct radeon_device *rdev)
  2833. {
  2834. struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  2835. int r, i;
  2836. r = radeon_ring_lock(rdev, ring, 7 + 4);
  2837. if (r) {
  2838. DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
  2839. return r;
  2840. }
  2841. /* init the CP */
  2842. radeon_ring_write(ring, PACKET3(PACKET3_ME_INITIALIZE, 5));
  2843. radeon_ring_write(ring, 0x1);
  2844. radeon_ring_write(ring, 0x0);
  2845. radeon_ring_write(ring, rdev->config.si.max_hw_contexts - 1);
  2846. radeon_ring_write(ring, PACKET3_ME_INITIALIZE_DEVICE_ID(1));
  2847. radeon_ring_write(ring, 0);
  2848. radeon_ring_write(ring, 0);
  2849. /* init the CE partitions */
  2850. radeon_ring_write(ring, PACKET3(PACKET3_SET_BASE, 2));
  2851. radeon_ring_write(ring, PACKET3_BASE_INDEX(CE_PARTITION_BASE));
  2852. radeon_ring_write(ring, 0xc000);
  2853. radeon_ring_write(ring, 0xe000);
  2854. radeon_ring_unlock_commit(rdev, ring);
  2855. si_cp_enable(rdev, true);
  2856. r = radeon_ring_lock(rdev, ring, si_default_size + 10);
  2857. if (r) {
  2858. DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
  2859. return r;
  2860. }
  2861. /* setup clear context state */
  2862. radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
  2863. radeon_ring_write(ring, PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);
  2864. for (i = 0; i < si_default_size; i++)
  2865. radeon_ring_write(ring, si_default_state[i]);
  2866. radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
  2867. radeon_ring_write(ring, PACKET3_PREAMBLE_END_CLEAR_STATE);
  2868. /* set clear context state */
  2869. radeon_ring_write(ring, PACKET3(PACKET3_CLEAR_STATE, 0));
  2870. radeon_ring_write(ring, 0);
  2871. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 2));
  2872. radeon_ring_write(ring, 0x00000316);
  2873. radeon_ring_write(ring, 0x0000000e); /* VGT_VERTEX_REUSE_BLOCK_CNTL */
  2874. radeon_ring_write(ring, 0x00000010); /* VGT_OUT_DEALLOC_CNTL */
  2875. radeon_ring_unlock_commit(rdev, ring);
  2876. for (i = RADEON_RING_TYPE_GFX_INDEX; i <= CAYMAN_RING_TYPE_CP2_INDEX; ++i) {
  2877. ring = &rdev->ring[i];
  2878. r = radeon_ring_lock(rdev, ring, 2);
  2879. /* clear the compute context state */
  2880. radeon_ring_write(ring, PACKET3_COMPUTE(PACKET3_CLEAR_STATE, 0));
  2881. radeon_ring_write(ring, 0);
  2882. radeon_ring_unlock_commit(rdev, ring);
  2883. }
  2884. return 0;
  2885. }
  2886. static void si_cp_fini(struct radeon_device *rdev)
  2887. {
  2888. struct radeon_ring *ring;
  2889. si_cp_enable(rdev, false);
  2890. ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  2891. radeon_ring_fini(rdev, ring);
  2892. radeon_scratch_free(rdev, ring->rptr_save_reg);
  2893. ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
  2894. radeon_ring_fini(rdev, ring);
  2895. radeon_scratch_free(rdev, ring->rptr_save_reg);
  2896. ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
  2897. radeon_ring_fini(rdev, ring);
  2898. radeon_scratch_free(rdev, ring->rptr_save_reg);
  2899. }
  2900. static int si_cp_resume(struct radeon_device *rdev)
  2901. {
  2902. struct radeon_ring *ring;
  2903. u32 tmp;
  2904. u32 rb_bufsz;
  2905. int r;
  2906. /* Reset cp; if cp is reset, then PA, SH, VGT also need to be reset */
  2907. WREG32(GRBM_SOFT_RESET, (SOFT_RESET_CP |
  2908. SOFT_RESET_PA |
  2909. SOFT_RESET_VGT |
  2910. SOFT_RESET_SPI |
  2911. SOFT_RESET_SX));
  2912. RREG32(GRBM_SOFT_RESET);
  2913. mdelay(15);
  2914. WREG32(GRBM_SOFT_RESET, 0);
  2915. RREG32(GRBM_SOFT_RESET);
  2916. WREG32(CP_SEM_WAIT_TIMER, 0x0);
  2917. WREG32(CP_SEM_INCOMPLETE_TIMER_CNTL, 0x0);
  2918. /* Set the write pointer delay */
  2919. WREG32(CP_RB_WPTR_DELAY, 0);
  2920. WREG32(CP_DEBUG, 0);
  2921. WREG32(SCRATCH_ADDR, ((rdev->wb.gpu_addr + RADEON_WB_SCRATCH_OFFSET) >> 8) & 0xFFFFFFFF);
  2922. /* ring 0 - compute and gfx */
  2923. /* Set ring buffer size */
  2924. ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  2925. rb_bufsz = drm_order(ring->ring_size / 8);
  2926. tmp = (drm_order(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
  2927. #ifdef __BIG_ENDIAN
  2928. tmp |= BUF_SWAP_32BIT;
  2929. #endif
  2930. WREG32(CP_RB0_CNTL, tmp);
  2931. /* Initialize the ring buffer's read and write pointers */
  2932. WREG32(CP_RB0_CNTL, tmp | RB_RPTR_WR_ENA);
  2933. ring->wptr = 0;
  2934. WREG32(CP_RB0_WPTR, ring->wptr);
  2935. /* set the wb address whether it's enabled or not */
  2936. WREG32(CP_RB0_RPTR_ADDR, (rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFFFFFFFC);
  2937. WREG32(CP_RB0_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFF);
  2938. if (rdev->wb.enabled)
  2939. WREG32(SCRATCH_UMSK, 0xff);
  2940. else {
  2941. tmp |= RB_NO_UPDATE;
  2942. WREG32(SCRATCH_UMSK, 0);
  2943. }
  2944. mdelay(1);
  2945. WREG32(CP_RB0_CNTL, tmp);
  2946. WREG32(CP_RB0_BASE, ring->gpu_addr >> 8);
  2947. ring->rptr = RREG32(CP_RB0_RPTR);
  2948. /* ring1 - compute only */
  2949. /* Set ring buffer size */
  2950. ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
  2951. rb_bufsz = drm_order(ring->ring_size / 8);
  2952. tmp = (drm_order(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
  2953. #ifdef __BIG_ENDIAN
  2954. tmp |= BUF_SWAP_32BIT;
  2955. #endif
  2956. WREG32(CP_RB1_CNTL, tmp);
  2957. /* Initialize the ring buffer's read and write pointers */
  2958. WREG32(CP_RB1_CNTL, tmp | RB_RPTR_WR_ENA);
  2959. ring->wptr = 0;
  2960. WREG32(CP_RB1_WPTR, ring->wptr);
  2961. /* set the wb address whether it's enabled or not */
  2962. WREG32(CP_RB1_RPTR_ADDR, (rdev->wb.gpu_addr + RADEON_WB_CP1_RPTR_OFFSET) & 0xFFFFFFFC);
  2963. WREG32(CP_RB1_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP1_RPTR_OFFSET) & 0xFF);
  2964. mdelay(1);
  2965. WREG32(CP_RB1_CNTL, tmp);
  2966. WREG32(CP_RB1_BASE, ring->gpu_addr >> 8);
  2967. ring->rptr = RREG32(CP_RB1_RPTR);
  2968. /* ring2 - compute only */
  2969. /* Set ring buffer size */
  2970. ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
  2971. rb_bufsz = drm_order(ring->ring_size / 8);
  2972. tmp = (drm_order(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
  2973. #ifdef __BIG_ENDIAN
  2974. tmp |= BUF_SWAP_32BIT;
  2975. #endif
  2976. WREG32(CP_RB2_CNTL, tmp);
  2977. /* Initialize the ring buffer's read and write pointers */
  2978. WREG32(CP_RB2_CNTL, tmp | RB_RPTR_WR_ENA);
  2979. ring->wptr = 0;
  2980. WREG32(CP_RB2_WPTR, ring->wptr);
  2981. /* set the wb address whether it's enabled or not */
  2982. WREG32(CP_RB2_RPTR_ADDR, (rdev->wb.gpu_addr + RADEON_WB_CP2_RPTR_OFFSET) & 0xFFFFFFFC);
  2983. WREG32(CP_RB2_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP2_RPTR_OFFSET) & 0xFF);
  2984. mdelay(1);
  2985. WREG32(CP_RB2_CNTL, tmp);
  2986. WREG32(CP_RB2_BASE, ring->gpu_addr >> 8);
  2987. ring->rptr = RREG32(CP_RB2_RPTR);
  2988. /* start the rings */
  2989. si_cp_start(rdev);
  2990. rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = true;
  2991. rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX].ready = true;
  2992. rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX].ready = true;
  2993. r = radeon_ring_test(rdev, RADEON_RING_TYPE_GFX_INDEX, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]);
  2994. if (r) {
  2995. rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false;
  2996. rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX].ready = false;
  2997. rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX].ready = false;
  2998. return r;
  2999. }
  3000. r = radeon_ring_test(rdev, CAYMAN_RING_TYPE_CP1_INDEX, &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX]);
  3001. if (r) {
  3002. rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX].ready = false;
  3003. }
  3004. r = radeon_ring_test(rdev, CAYMAN_RING_TYPE_CP2_INDEX, &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX]);
  3005. if (r) {
  3006. rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX].ready = false;
  3007. }
  3008. return 0;
  3009. }
  3010. static u32 si_gpu_check_soft_reset(struct radeon_device *rdev)
  3011. {
  3012. u32 reset_mask = 0;
  3013. u32 tmp;
  3014. /* GRBM_STATUS */
  3015. tmp = RREG32(GRBM_STATUS);
  3016. if (tmp & (PA_BUSY | SC_BUSY |
  3017. BCI_BUSY | SX_BUSY |
  3018. TA_BUSY | VGT_BUSY |
  3019. DB_BUSY | CB_BUSY |
  3020. GDS_BUSY | SPI_BUSY |
  3021. IA_BUSY | IA_BUSY_NO_DMA))
  3022. reset_mask |= RADEON_RESET_GFX;
  3023. if (tmp & (CF_RQ_PENDING | PF_RQ_PENDING |
  3024. CP_BUSY | CP_COHERENCY_BUSY))
  3025. reset_mask |= RADEON_RESET_CP;
  3026. if (tmp & GRBM_EE_BUSY)
  3027. reset_mask |= RADEON_RESET_GRBM | RADEON_RESET_GFX | RADEON_RESET_CP;
  3028. /* GRBM_STATUS2 */
  3029. tmp = RREG32(GRBM_STATUS2);
  3030. if (tmp & (RLC_RQ_PENDING | RLC_BUSY))
  3031. reset_mask |= RADEON_RESET_RLC;
  3032. /* DMA_STATUS_REG 0 */
  3033. tmp = RREG32(DMA_STATUS_REG + DMA0_REGISTER_OFFSET);
  3034. if (!(tmp & DMA_IDLE))
  3035. reset_mask |= RADEON_RESET_DMA;
  3036. /* DMA_STATUS_REG 1 */
  3037. tmp = RREG32(DMA_STATUS_REG + DMA1_REGISTER_OFFSET);
  3038. if (!(tmp & DMA_IDLE))
  3039. reset_mask |= RADEON_RESET_DMA1;
  3040. /* SRBM_STATUS2 */
  3041. tmp = RREG32(SRBM_STATUS2);
  3042. if (tmp & DMA_BUSY)
  3043. reset_mask |= RADEON_RESET_DMA;
  3044. if (tmp & DMA1_BUSY)
  3045. reset_mask |= RADEON_RESET_DMA1;
  3046. /* SRBM_STATUS */
  3047. tmp = RREG32(SRBM_STATUS);
  3048. if (tmp & IH_BUSY)
  3049. reset_mask |= RADEON_RESET_IH;
  3050. if (tmp & SEM_BUSY)
  3051. reset_mask |= RADEON_RESET_SEM;
  3052. if (tmp & GRBM_RQ_PENDING)
  3053. reset_mask |= RADEON_RESET_GRBM;
  3054. if (tmp & VMC_BUSY)
  3055. reset_mask |= RADEON_RESET_VMC;
  3056. if (tmp & (MCB_BUSY | MCB_NON_DISPLAY_BUSY |
  3057. MCC_BUSY | MCD_BUSY))
  3058. reset_mask |= RADEON_RESET_MC;
  3059. if (evergreen_is_display_hung(rdev))
  3060. reset_mask |= RADEON_RESET_DISPLAY;
  3061. /* VM_L2_STATUS */
  3062. tmp = RREG32(VM_L2_STATUS);
  3063. if (tmp & L2_BUSY)
  3064. reset_mask |= RADEON_RESET_VMC;
  3065. /* Skip MC reset as it's mostly likely not hung, just busy */
  3066. if (reset_mask & RADEON_RESET_MC) {
  3067. DRM_DEBUG("MC busy: 0x%08X, clearing.\n", reset_mask);
  3068. reset_mask &= ~RADEON_RESET_MC;
  3069. }
  3070. return reset_mask;
  3071. }
  3072. static void si_gpu_soft_reset(struct radeon_device *rdev, u32 reset_mask)
  3073. {
  3074. struct evergreen_mc_save save;
  3075. u32 grbm_soft_reset = 0, srbm_soft_reset = 0;
  3076. u32 tmp;
  3077. if (reset_mask == 0)
  3078. return;
  3079. dev_info(rdev->dev, "GPU softreset: 0x%08X\n", reset_mask);
  3080. evergreen_print_gpu_status_regs(rdev);
  3081. dev_info(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_ADDR 0x%08X\n",
  3082. RREG32(VM_CONTEXT1_PROTECTION_FAULT_ADDR));
  3083. dev_info(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_STATUS 0x%08X\n",
  3084. RREG32(VM_CONTEXT1_PROTECTION_FAULT_STATUS));
  3085. /* Disable CP parsing/prefetching */
  3086. WREG32(CP_ME_CNTL, CP_ME_HALT | CP_PFP_HALT | CP_CE_HALT);
  3087. if (reset_mask & RADEON_RESET_DMA) {
  3088. /* dma0 */
  3089. tmp = RREG32(DMA_RB_CNTL + DMA0_REGISTER_OFFSET);
  3090. tmp &= ~DMA_RB_ENABLE;
  3091. WREG32(DMA_RB_CNTL + DMA0_REGISTER_OFFSET, tmp);
  3092. }
  3093. if (reset_mask & RADEON_RESET_DMA1) {
  3094. /* dma1 */
  3095. tmp = RREG32(DMA_RB_CNTL + DMA1_REGISTER_OFFSET);
  3096. tmp &= ~DMA_RB_ENABLE;
  3097. WREG32(DMA_RB_CNTL + DMA1_REGISTER_OFFSET, tmp);
  3098. }
  3099. udelay(50);
  3100. evergreen_mc_stop(rdev, &save);
  3101. if (evergreen_mc_wait_for_idle(rdev)) {
  3102. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  3103. }
  3104. if (reset_mask & (RADEON_RESET_GFX | RADEON_RESET_COMPUTE | RADEON_RESET_CP)) {
  3105. grbm_soft_reset = SOFT_RESET_CB |
  3106. SOFT_RESET_DB |
  3107. SOFT_RESET_GDS |
  3108. SOFT_RESET_PA |
  3109. SOFT_RESET_SC |
  3110. SOFT_RESET_BCI |
  3111. SOFT_RESET_SPI |
  3112. SOFT_RESET_SX |
  3113. SOFT_RESET_TC |
  3114. SOFT_RESET_TA |
  3115. SOFT_RESET_VGT |
  3116. SOFT_RESET_IA;
  3117. }
  3118. if (reset_mask & RADEON_RESET_CP) {
  3119. grbm_soft_reset |= SOFT_RESET_CP | SOFT_RESET_VGT;
  3120. srbm_soft_reset |= SOFT_RESET_GRBM;
  3121. }
  3122. if (reset_mask & RADEON_RESET_DMA)
  3123. srbm_soft_reset |= SOFT_RESET_DMA;
  3124. if (reset_mask & RADEON_RESET_DMA1)
  3125. srbm_soft_reset |= SOFT_RESET_DMA1;
  3126. if (reset_mask & RADEON_RESET_DISPLAY)
  3127. srbm_soft_reset |= SOFT_RESET_DC;
  3128. if (reset_mask & RADEON_RESET_RLC)
  3129. grbm_soft_reset |= SOFT_RESET_RLC;
  3130. if (reset_mask & RADEON_RESET_SEM)
  3131. srbm_soft_reset |= SOFT_RESET_SEM;
  3132. if (reset_mask & RADEON_RESET_IH)
  3133. srbm_soft_reset |= SOFT_RESET_IH;
  3134. if (reset_mask & RADEON_RESET_GRBM)
  3135. srbm_soft_reset |= SOFT_RESET_GRBM;
  3136. if (reset_mask & RADEON_RESET_VMC)
  3137. srbm_soft_reset |= SOFT_RESET_VMC;
  3138. if (reset_mask & RADEON_RESET_MC)
  3139. srbm_soft_reset |= SOFT_RESET_MC;
  3140. if (grbm_soft_reset) {
  3141. tmp = RREG32(GRBM_SOFT_RESET);
  3142. tmp |= grbm_soft_reset;
  3143. dev_info(rdev->dev, "GRBM_SOFT_RESET=0x%08X\n", tmp);
  3144. WREG32(GRBM_SOFT_RESET, tmp);
  3145. tmp = RREG32(GRBM_SOFT_RESET);
  3146. udelay(50);
  3147. tmp &= ~grbm_soft_reset;
  3148. WREG32(GRBM_SOFT_RESET, tmp);
  3149. tmp = RREG32(GRBM_SOFT_RESET);
  3150. }
  3151. if (srbm_soft_reset) {
  3152. tmp = RREG32(SRBM_SOFT_RESET);
  3153. tmp |= srbm_soft_reset;
  3154. dev_info(rdev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
  3155. WREG32(SRBM_SOFT_RESET, tmp);
  3156. tmp = RREG32(SRBM_SOFT_RESET);
  3157. udelay(50);
  3158. tmp &= ~srbm_soft_reset;
  3159. WREG32(SRBM_SOFT_RESET, tmp);
  3160. tmp = RREG32(SRBM_SOFT_RESET);
  3161. }
  3162. /* Wait a little for things to settle down */
  3163. udelay(50);
  3164. evergreen_mc_resume(rdev, &save);
  3165. udelay(50);
  3166. evergreen_print_gpu_status_regs(rdev);
  3167. }
  3168. int si_asic_reset(struct radeon_device *rdev)
  3169. {
  3170. u32 reset_mask;
  3171. reset_mask = si_gpu_check_soft_reset(rdev);
  3172. if (reset_mask)
  3173. r600_set_bios_scratch_engine_hung(rdev, true);
  3174. si_gpu_soft_reset(rdev, reset_mask);
  3175. reset_mask = si_gpu_check_soft_reset(rdev);
  3176. if (!reset_mask)
  3177. r600_set_bios_scratch_engine_hung(rdev, false);
  3178. return 0;
  3179. }
  3180. /**
  3181. * si_gfx_is_lockup - Check if the GFX engine is locked up
  3182. *
  3183. * @rdev: radeon_device pointer
  3184. * @ring: radeon_ring structure holding ring information
  3185. *
  3186. * Check if the GFX engine is locked up.
  3187. * Returns true if the engine appears to be locked up, false if not.
  3188. */
  3189. bool si_gfx_is_lockup(struct radeon_device *rdev, struct radeon_ring *ring)
  3190. {
  3191. u32 reset_mask = si_gpu_check_soft_reset(rdev);
  3192. if (!(reset_mask & (RADEON_RESET_GFX |
  3193. RADEON_RESET_COMPUTE |
  3194. RADEON_RESET_CP))) {
  3195. radeon_ring_lockup_update(ring);
  3196. return false;
  3197. }
  3198. /* force CP activities */
  3199. radeon_ring_force_activity(rdev, ring);
  3200. return radeon_ring_test_lockup(rdev, ring);
  3201. }
  3202. /**
  3203. * si_dma_is_lockup - Check if the DMA engine is locked up
  3204. *
  3205. * @rdev: radeon_device pointer
  3206. * @ring: radeon_ring structure holding ring information
  3207. *
  3208. * Check if the async DMA engine is locked up.
  3209. * Returns true if the engine appears to be locked up, false if not.
  3210. */
  3211. bool si_dma_is_lockup(struct radeon_device *rdev, struct radeon_ring *ring)
  3212. {
  3213. u32 reset_mask = si_gpu_check_soft_reset(rdev);
  3214. u32 mask;
  3215. if (ring->idx == R600_RING_TYPE_DMA_INDEX)
  3216. mask = RADEON_RESET_DMA;
  3217. else
  3218. mask = RADEON_RESET_DMA1;
  3219. if (!(reset_mask & mask)) {
  3220. radeon_ring_lockup_update(ring);
  3221. return false;
  3222. }
  3223. /* force ring activities */
  3224. radeon_ring_force_activity(rdev, ring);
  3225. return radeon_ring_test_lockup(rdev, ring);
  3226. }
  3227. /* MC */
  3228. static void si_mc_program(struct radeon_device *rdev)
  3229. {
  3230. struct evergreen_mc_save save;
  3231. u32 tmp;
  3232. int i, j;
  3233. /* Initialize HDP */
  3234. for (i = 0, j = 0; i < 32; i++, j += 0x18) {
  3235. WREG32((0x2c14 + j), 0x00000000);
  3236. WREG32((0x2c18 + j), 0x00000000);
  3237. WREG32((0x2c1c + j), 0x00000000);
  3238. WREG32((0x2c20 + j), 0x00000000);
  3239. WREG32((0x2c24 + j), 0x00000000);
  3240. }
  3241. WREG32(HDP_REG_COHERENCY_FLUSH_CNTL, 0);
  3242. evergreen_mc_stop(rdev, &save);
  3243. if (radeon_mc_wait_for_idle(rdev)) {
  3244. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  3245. }
  3246. if (!ASIC_IS_NODCE(rdev))
  3247. /* Lockout access through VGA aperture*/
  3248. WREG32(VGA_HDP_CONTROL, VGA_MEMORY_DISABLE);
  3249. /* Update configuration */
  3250. WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
  3251. rdev->mc.vram_start >> 12);
  3252. WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
  3253. rdev->mc.vram_end >> 12);
  3254. WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR,
  3255. rdev->vram_scratch.gpu_addr >> 12);
  3256. tmp = ((rdev->mc.vram_end >> 24) & 0xFFFF) << 16;
  3257. tmp |= ((rdev->mc.vram_start >> 24) & 0xFFFF);
  3258. WREG32(MC_VM_FB_LOCATION, tmp);
  3259. /* XXX double check these! */
  3260. WREG32(HDP_NONSURFACE_BASE, (rdev->mc.vram_start >> 8));
  3261. WREG32(HDP_NONSURFACE_INFO, (2 << 7) | (1 << 30));
  3262. WREG32(HDP_NONSURFACE_SIZE, 0x3FFFFFFF);
  3263. WREG32(MC_VM_AGP_BASE, 0);
  3264. WREG32(MC_VM_AGP_TOP, 0x0FFFFFFF);
  3265. WREG32(MC_VM_AGP_BOT, 0x0FFFFFFF);
  3266. if (radeon_mc_wait_for_idle(rdev)) {
  3267. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  3268. }
  3269. evergreen_mc_resume(rdev, &save);
  3270. if (!ASIC_IS_NODCE(rdev)) {
  3271. /* we need to own VRAM, so turn off the VGA renderer here
  3272. * to stop it overwriting our objects */
  3273. rv515_vga_render_disable(rdev);
  3274. }
  3275. }
  3276. void si_vram_gtt_location(struct radeon_device *rdev,
  3277. struct radeon_mc *mc)
  3278. {
  3279. if (mc->mc_vram_size > 0xFFC0000000ULL) {
  3280. /* leave room for at least 1024M GTT */
  3281. dev_warn(rdev->dev, "limiting VRAM\n");
  3282. mc->real_vram_size = 0xFFC0000000ULL;
  3283. mc->mc_vram_size = 0xFFC0000000ULL;
  3284. }
  3285. radeon_vram_location(rdev, &rdev->mc, 0);
  3286. rdev->mc.gtt_base_align = 0;
  3287. radeon_gtt_location(rdev, mc);
  3288. }
  3289. static int si_mc_init(struct radeon_device *rdev)
  3290. {
  3291. u32 tmp;
  3292. int chansize, numchan;
  3293. /* Get VRAM informations */
  3294. rdev->mc.vram_is_ddr = true;
  3295. tmp = RREG32(MC_ARB_RAMCFG);
  3296. if (tmp & CHANSIZE_OVERRIDE) {
  3297. chansize = 16;
  3298. } else if (tmp & CHANSIZE_MASK) {
  3299. chansize = 64;
  3300. } else {
  3301. chansize = 32;
  3302. }
  3303. tmp = RREG32(MC_SHARED_CHMAP);
  3304. switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
  3305. case 0:
  3306. default:
  3307. numchan = 1;
  3308. break;
  3309. case 1:
  3310. numchan = 2;
  3311. break;
  3312. case 2:
  3313. numchan = 4;
  3314. break;
  3315. case 3:
  3316. numchan = 8;
  3317. break;
  3318. case 4:
  3319. numchan = 3;
  3320. break;
  3321. case 5:
  3322. numchan = 6;
  3323. break;
  3324. case 6:
  3325. numchan = 10;
  3326. break;
  3327. case 7:
  3328. numchan = 12;
  3329. break;
  3330. case 8:
  3331. numchan = 16;
  3332. break;
  3333. }
  3334. rdev->mc.vram_width = numchan * chansize;
  3335. /* Could aper size report 0 ? */
  3336. rdev->mc.aper_base = pci_resource_start(rdev->pdev, 0);
  3337. rdev->mc.aper_size = pci_resource_len(rdev->pdev, 0);
  3338. /* size in MB on si */
  3339. rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE) * 1024ULL * 1024ULL;
  3340. rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE) * 1024ULL * 1024ULL;
  3341. rdev->mc.visible_vram_size = rdev->mc.aper_size;
  3342. si_vram_gtt_location(rdev, &rdev->mc);
  3343. radeon_update_bandwidth_info(rdev);
  3344. return 0;
  3345. }
  3346. /*
  3347. * GART
  3348. */
  3349. void si_pcie_gart_tlb_flush(struct radeon_device *rdev)
  3350. {
  3351. /* flush hdp cache */
  3352. WREG32(HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1);
  3353. /* bits 0-15 are the VM contexts0-15 */
  3354. WREG32(VM_INVALIDATE_REQUEST, 1);
  3355. }
  3356. static int si_pcie_gart_enable(struct radeon_device *rdev)
  3357. {
  3358. int r, i;
  3359. if (rdev->gart.robj == NULL) {
  3360. dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
  3361. return -EINVAL;
  3362. }
  3363. r = radeon_gart_table_vram_pin(rdev);
  3364. if (r)
  3365. return r;
  3366. radeon_gart_restore(rdev);
  3367. /* Setup TLB control */
  3368. WREG32(MC_VM_MX_L1_TLB_CNTL,
  3369. (0xA << 7) |
  3370. ENABLE_L1_TLB |
  3371. SYSTEM_ACCESS_MODE_NOT_IN_SYS |
  3372. ENABLE_ADVANCED_DRIVER_MODEL |
  3373. SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU);
  3374. /* Setup L2 cache */
  3375. WREG32(VM_L2_CNTL, ENABLE_L2_CACHE |
  3376. ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
  3377. ENABLE_L2_PDE0_CACHE_LRU_UPDATE_BY_WRITE |
  3378. EFFECTIVE_L2_QUEUE_SIZE(7) |
  3379. CONTEXT1_IDENTITY_ACCESS_MODE(1));
  3380. WREG32(VM_L2_CNTL2, INVALIDATE_ALL_L1_TLBS | INVALIDATE_L2_CACHE);
  3381. WREG32(VM_L2_CNTL3, L2_CACHE_BIGK_ASSOCIATIVITY |
  3382. L2_CACHE_BIGK_FRAGMENT_SIZE(0));
  3383. /* setup context0 */
  3384. WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR, rdev->mc.gtt_start >> 12);
  3385. WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR, rdev->mc.gtt_end >> 12);
  3386. WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, rdev->gart.table_addr >> 12);
  3387. WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR,
  3388. (u32)(rdev->dummy_page.addr >> 12));
  3389. WREG32(VM_CONTEXT0_CNTL2, 0);
  3390. WREG32(VM_CONTEXT0_CNTL, (ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) |
  3391. RANGE_PROTECTION_FAULT_ENABLE_DEFAULT));
  3392. WREG32(0x15D4, 0);
  3393. WREG32(0x15D8, 0);
  3394. WREG32(0x15DC, 0);
  3395. /* empty context1-15 */
  3396. /* set vm size, must be a multiple of 4 */
  3397. WREG32(VM_CONTEXT1_PAGE_TABLE_START_ADDR, 0);
  3398. WREG32(VM_CONTEXT1_PAGE_TABLE_END_ADDR, rdev->vm_manager.max_pfn);
  3399. /* Assign the pt base to something valid for now; the pts used for
  3400. * the VMs are determined by the application and setup and assigned
  3401. * on the fly in the vm part of radeon_gart.c
  3402. */
  3403. for (i = 1; i < 16; i++) {
  3404. if (i < 8)
  3405. WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (i << 2),
  3406. rdev->gart.table_addr >> 12);
  3407. else
  3408. WREG32(VM_CONTEXT8_PAGE_TABLE_BASE_ADDR + ((i - 8) << 2),
  3409. rdev->gart.table_addr >> 12);
  3410. }
  3411. /* enable context1-15 */
  3412. WREG32(VM_CONTEXT1_PROTECTION_FAULT_DEFAULT_ADDR,
  3413. (u32)(rdev->dummy_page.addr >> 12));
  3414. WREG32(VM_CONTEXT1_CNTL2, 4);
  3415. WREG32(VM_CONTEXT1_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(1) |
  3416. RANGE_PROTECTION_FAULT_ENABLE_INTERRUPT |
  3417. RANGE_PROTECTION_FAULT_ENABLE_DEFAULT |
  3418. DUMMY_PAGE_PROTECTION_FAULT_ENABLE_INTERRUPT |
  3419. DUMMY_PAGE_PROTECTION_FAULT_ENABLE_DEFAULT |
  3420. PDE0_PROTECTION_FAULT_ENABLE_INTERRUPT |
  3421. PDE0_PROTECTION_FAULT_ENABLE_DEFAULT |
  3422. VALID_PROTECTION_FAULT_ENABLE_INTERRUPT |
  3423. VALID_PROTECTION_FAULT_ENABLE_DEFAULT |
  3424. READ_PROTECTION_FAULT_ENABLE_INTERRUPT |
  3425. READ_PROTECTION_FAULT_ENABLE_DEFAULT |
  3426. WRITE_PROTECTION_FAULT_ENABLE_INTERRUPT |
  3427. WRITE_PROTECTION_FAULT_ENABLE_DEFAULT);
  3428. si_pcie_gart_tlb_flush(rdev);
  3429. DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
  3430. (unsigned)(rdev->mc.gtt_size >> 20),
  3431. (unsigned long long)rdev->gart.table_addr);
  3432. rdev->gart.ready = true;
  3433. return 0;
  3434. }
  3435. static void si_pcie_gart_disable(struct radeon_device *rdev)
  3436. {
  3437. /* Disable all tables */
  3438. WREG32(VM_CONTEXT0_CNTL, 0);
  3439. WREG32(VM_CONTEXT1_CNTL, 0);
  3440. /* Setup TLB control */
  3441. WREG32(MC_VM_MX_L1_TLB_CNTL, SYSTEM_ACCESS_MODE_NOT_IN_SYS |
  3442. SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU);
  3443. /* Setup L2 cache */
  3444. WREG32(VM_L2_CNTL, ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
  3445. ENABLE_L2_PDE0_CACHE_LRU_UPDATE_BY_WRITE |
  3446. EFFECTIVE_L2_QUEUE_SIZE(7) |
  3447. CONTEXT1_IDENTITY_ACCESS_MODE(1));
  3448. WREG32(VM_L2_CNTL2, 0);
  3449. WREG32(VM_L2_CNTL3, L2_CACHE_BIGK_ASSOCIATIVITY |
  3450. L2_CACHE_BIGK_FRAGMENT_SIZE(0));
  3451. radeon_gart_table_vram_unpin(rdev);
  3452. }
  3453. static void si_pcie_gart_fini(struct radeon_device *rdev)
  3454. {
  3455. si_pcie_gart_disable(rdev);
  3456. radeon_gart_table_vram_free(rdev);
  3457. radeon_gart_fini(rdev);
  3458. }
  3459. /* vm parser */
  3460. static bool si_vm_reg_valid(u32 reg)
  3461. {
  3462. /* context regs are fine */
  3463. if (reg >= 0x28000)
  3464. return true;
  3465. /* check config regs */
  3466. switch (reg) {
  3467. case GRBM_GFX_INDEX:
  3468. case CP_STRMOUT_CNTL:
  3469. case VGT_VTX_VECT_EJECT_REG:
  3470. case VGT_CACHE_INVALIDATION:
  3471. case VGT_ESGS_RING_SIZE:
  3472. case VGT_GSVS_RING_SIZE:
  3473. case VGT_GS_VERTEX_REUSE:
  3474. case VGT_PRIMITIVE_TYPE:
  3475. case VGT_INDEX_TYPE:
  3476. case VGT_NUM_INDICES:
  3477. case VGT_NUM_INSTANCES:
  3478. case VGT_TF_RING_SIZE:
  3479. case VGT_HS_OFFCHIP_PARAM:
  3480. case VGT_TF_MEMORY_BASE:
  3481. case PA_CL_ENHANCE:
  3482. case PA_SU_LINE_STIPPLE_VALUE:
  3483. case PA_SC_LINE_STIPPLE_STATE:
  3484. case PA_SC_ENHANCE:
  3485. case SQC_CACHES:
  3486. case SPI_STATIC_THREAD_MGMT_1:
  3487. case SPI_STATIC_THREAD_MGMT_2:
  3488. case SPI_STATIC_THREAD_MGMT_3:
  3489. case SPI_PS_MAX_WAVE_ID:
  3490. case SPI_CONFIG_CNTL:
  3491. case SPI_CONFIG_CNTL_1:
  3492. case TA_CNTL_AUX:
  3493. return true;
  3494. default:
  3495. DRM_ERROR("Invalid register 0x%x in CS\n", reg);
  3496. return false;
  3497. }
  3498. }
  3499. static int si_vm_packet3_ce_check(struct radeon_device *rdev,
  3500. u32 *ib, struct radeon_cs_packet *pkt)
  3501. {
  3502. switch (pkt->opcode) {
  3503. case PACKET3_NOP:
  3504. case PACKET3_SET_BASE:
  3505. case PACKET3_SET_CE_DE_COUNTERS:
  3506. case PACKET3_LOAD_CONST_RAM:
  3507. case PACKET3_WRITE_CONST_RAM:
  3508. case PACKET3_WRITE_CONST_RAM_OFFSET:
  3509. case PACKET3_DUMP_CONST_RAM:
  3510. case PACKET3_INCREMENT_CE_COUNTER:
  3511. case PACKET3_WAIT_ON_DE_COUNTER:
  3512. case PACKET3_CE_WRITE:
  3513. break;
  3514. default:
  3515. DRM_ERROR("Invalid CE packet3: 0x%x\n", pkt->opcode);
  3516. return -EINVAL;
  3517. }
  3518. return 0;
  3519. }
  3520. static int si_vm_packet3_gfx_check(struct radeon_device *rdev,
  3521. u32 *ib, struct radeon_cs_packet *pkt)
  3522. {
  3523. u32 idx = pkt->idx + 1;
  3524. u32 idx_value = ib[idx];
  3525. u32 start_reg, end_reg, reg, i;
  3526. u32 command, info;
  3527. switch (pkt->opcode) {
  3528. case PACKET3_NOP:
  3529. case PACKET3_SET_BASE:
  3530. case PACKET3_CLEAR_STATE:
  3531. case PACKET3_INDEX_BUFFER_SIZE:
  3532. case PACKET3_DISPATCH_DIRECT:
  3533. case PACKET3_DISPATCH_INDIRECT:
  3534. case PACKET3_ALLOC_GDS:
  3535. case PACKET3_WRITE_GDS_RAM:
  3536. case PACKET3_ATOMIC_GDS:
  3537. case PACKET3_ATOMIC:
  3538. case PACKET3_OCCLUSION_QUERY:
  3539. case PACKET3_SET_PREDICATION:
  3540. case PACKET3_COND_EXEC:
  3541. case PACKET3_PRED_EXEC:
  3542. case PACKET3_DRAW_INDIRECT:
  3543. case PACKET3_DRAW_INDEX_INDIRECT:
  3544. case PACKET3_INDEX_BASE:
  3545. case PACKET3_DRAW_INDEX_2:
  3546. case PACKET3_CONTEXT_CONTROL:
  3547. case PACKET3_INDEX_TYPE:
  3548. case PACKET3_DRAW_INDIRECT_MULTI:
  3549. case PACKET3_DRAW_INDEX_AUTO:
  3550. case PACKET3_DRAW_INDEX_IMMD:
  3551. case PACKET3_NUM_INSTANCES:
  3552. case PACKET3_DRAW_INDEX_MULTI_AUTO:
  3553. case PACKET3_STRMOUT_BUFFER_UPDATE:
  3554. case PACKET3_DRAW_INDEX_OFFSET_2:
  3555. case PACKET3_DRAW_INDEX_MULTI_ELEMENT:
  3556. case PACKET3_DRAW_INDEX_INDIRECT_MULTI:
  3557. case PACKET3_MPEG_INDEX:
  3558. case PACKET3_WAIT_REG_MEM:
  3559. case PACKET3_MEM_WRITE:
  3560. case PACKET3_PFP_SYNC_ME:
  3561. case PACKET3_SURFACE_SYNC:
  3562. case PACKET3_EVENT_WRITE:
  3563. case PACKET3_EVENT_WRITE_EOP:
  3564. case PACKET3_EVENT_WRITE_EOS:
  3565. case PACKET3_SET_CONTEXT_REG:
  3566. case PACKET3_SET_CONTEXT_REG_INDIRECT:
  3567. case PACKET3_SET_SH_REG:
  3568. case PACKET3_SET_SH_REG_OFFSET:
  3569. case PACKET3_INCREMENT_DE_COUNTER:
  3570. case PACKET3_WAIT_ON_CE_COUNTER:
  3571. case PACKET3_WAIT_ON_AVAIL_BUFFER:
  3572. case PACKET3_ME_WRITE:
  3573. break;
  3574. case PACKET3_COPY_DATA:
  3575. if ((idx_value & 0xf00) == 0) {
  3576. reg = ib[idx + 3] * 4;
  3577. if (!si_vm_reg_valid(reg))
  3578. return -EINVAL;
  3579. }
  3580. break;
  3581. case PACKET3_WRITE_DATA:
  3582. if ((idx_value & 0xf00) == 0) {
  3583. start_reg = ib[idx + 1] * 4;
  3584. if (idx_value & 0x10000) {
  3585. if (!si_vm_reg_valid(start_reg))
  3586. return -EINVAL;
  3587. } else {
  3588. for (i = 0; i < (pkt->count - 2); i++) {
  3589. reg = start_reg + (4 * i);
  3590. if (!si_vm_reg_valid(reg))
  3591. return -EINVAL;
  3592. }
  3593. }
  3594. }
  3595. break;
  3596. case PACKET3_COND_WRITE:
  3597. if (idx_value & 0x100) {
  3598. reg = ib[idx + 5] * 4;
  3599. if (!si_vm_reg_valid(reg))
  3600. return -EINVAL;
  3601. }
  3602. break;
  3603. case PACKET3_COPY_DW:
  3604. if (idx_value & 0x2) {
  3605. reg = ib[idx + 3] * 4;
  3606. if (!si_vm_reg_valid(reg))
  3607. return -EINVAL;
  3608. }
  3609. break;
  3610. case PACKET3_SET_CONFIG_REG:
  3611. start_reg = (idx_value << 2) + PACKET3_SET_CONFIG_REG_START;
  3612. end_reg = 4 * pkt->count + start_reg - 4;
  3613. if ((start_reg < PACKET3_SET_CONFIG_REG_START) ||
  3614. (start_reg >= PACKET3_SET_CONFIG_REG_END) ||
  3615. (end_reg >= PACKET3_SET_CONFIG_REG_END)) {
  3616. DRM_ERROR("bad PACKET3_SET_CONFIG_REG\n");
  3617. return -EINVAL;
  3618. }
  3619. for (i = 0; i < pkt->count; i++) {
  3620. reg = start_reg + (4 * i);
  3621. if (!si_vm_reg_valid(reg))
  3622. return -EINVAL;
  3623. }
  3624. break;
  3625. case PACKET3_CP_DMA:
  3626. command = ib[idx + 4];
  3627. info = ib[idx + 1];
  3628. if (command & PACKET3_CP_DMA_CMD_SAS) {
  3629. /* src address space is register */
  3630. if (((info & 0x60000000) >> 29) == 0) {
  3631. start_reg = idx_value << 2;
  3632. if (command & PACKET3_CP_DMA_CMD_SAIC) {
  3633. reg = start_reg;
  3634. if (!si_vm_reg_valid(reg)) {
  3635. DRM_ERROR("CP DMA Bad SRC register\n");
  3636. return -EINVAL;
  3637. }
  3638. } else {
  3639. for (i = 0; i < (command & 0x1fffff); i++) {
  3640. reg = start_reg + (4 * i);
  3641. if (!si_vm_reg_valid(reg)) {
  3642. DRM_ERROR("CP DMA Bad SRC register\n");
  3643. return -EINVAL;
  3644. }
  3645. }
  3646. }
  3647. }
  3648. }
  3649. if (command & PACKET3_CP_DMA_CMD_DAS) {
  3650. /* dst address space is register */
  3651. if (((info & 0x00300000) >> 20) == 0) {
  3652. start_reg = ib[idx + 2];
  3653. if (command & PACKET3_CP_DMA_CMD_DAIC) {
  3654. reg = start_reg;
  3655. if (!si_vm_reg_valid(reg)) {
  3656. DRM_ERROR("CP DMA Bad DST register\n");
  3657. return -EINVAL;
  3658. }
  3659. } else {
  3660. for (i = 0; i < (command & 0x1fffff); i++) {
  3661. reg = start_reg + (4 * i);
  3662. if (!si_vm_reg_valid(reg)) {
  3663. DRM_ERROR("CP DMA Bad DST register\n");
  3664. return -EINVAL;
  3665. }
  3666. }
  3667. }
  3668. }
  3669. }
  3670. break;
  3671. default:
  3672. DRM_ERROR("Invalid GFX packet3: 0x%x\n", pkt->opcode);
  3673. return -EINVAL;
  3674. }
  3675. return 0;
  3676. }
  3677. static int si_vm_packet3_compute_check(struct radeon_device *rdev,
  3678. u32 *ib, struct radeon_cs_packet *pkt)
  3679. {
  3680. u32 idx = pkt->idx + 1;
  3681. u32 idx_value = ib[idx];
  3682. u32 start_reg, reg, i;
  3683. switch (pkt->opcode) {
  3684. case PACKET3_NOP:
  3685. case PACKET3_SET_BASE:
  3686. case PACKET3_CLEAR_STATE:
  3687. case PACKET3_DISPATCH_DIRECT:
  3688. case PACKET3_DISPATCH_INDIRECT:
  3689. case PACKET3_ALLOC_GDS:
  3690. case PACKET3_WRITE_GDS_RAM:
  3691. case PACKET3_ATOMIC_GDS:
  3692. case PACKET3_ATOMIC:
  3693. case PACKET3_OCCLUSION_QUERY:
  3694. case PACKET3_SET_PREDICATION:
  3695. case PACKET3_COND_EXEC:
  3696. case PACKET3_PRED_EXEC:
  3697. case PACKET3_CONTEXT_CONTROL:
  3698. case PACKET3_STRMOUT_BUFFER_UPDATE:
  3699. case PACKET3_WAIT_REG_MEM:
  3700. case PACKET3_MEM_WRITE:
  3701. case PACKET3_PFP_SYNC_ME:
  3702. case PACKET3_SURFACE_SYNC:
  3703. case PACKET3_EVENT_WRITE:
  3704. case PACKET3_EVENT_WRITE_EOP:
  3705. case PACKET3_EVENT_WRITE_EOS:
  3706. case PACKET3_SET_CONTEXT_REG:
  3707. case PACKET3_SET_CONTEXT_REG_INDIRECT:
  3708. case PACKET3_SET_SH_REG:
  3709. case PACKET3_SET_SH_REG_OFFSET:
  3710. case PACKET3_INCREMENT_DE_COUNTER:
  3711. case PACKET3_WAIT_ON_CE_COUNTER:
  3712. case PACKET3_WAIT_ON_AVAIL_BUFFER:
  3713. case PACKET3_ME_WRITE:
  3714. break;
  3715. case PACKET3_COPY_DATA:
  3716. if ((idx_value & 0xf00) == 0) {
  3717. reg = ib[idx + 3] * 4;
  3718. if (!si_vm_reg_valid(reg))
  3719. return -EINVAL;
  3720. }
  3721. break;
  3722. case PACKET3_WRITE_DATA:
  3723. if ((idx_value & 0xf00) == 0) {
  3724. start_reg = ib[idx + 1] * 4;
  3725. if (idx_value & 0x10000) {
  3726. if (!si_vm_reg_valid(start_reg))
  3727. return -EINVAL;
  3728. } else {
  3729. for (i = 0; i < (pkt->count - 2); i++) {
  3730. reg = start_reg + (4 * i);
  3731. if (!si_vm_reg_valid(reg))
  3732. return -EINVAL;
  3733. }
  3734. }
  3735. }
  3736. break;
  3737. case PACKET3_COND_WRITE:
  3738. if (idx_value & 0x100) {
  3739. reg = ib[idx + 5] * 4;
  3740. if (!si_vm_reg_valid(reg))
  3741. return -EINVAL;
  3742. }
  3743. break;
  3744. case PACKET3_COPY_DW:
  3745. if (idx_value & 0x2) {
  3746. reg = ib[idx + 3] * 4;
  3747. if (!si_vm_reg_valid(reg))
  3748. return -EINVAL;
  3749. }
  3750. break;
  3751. default:
  3752. DRM_ERROR("Invalid Compute packet3: 0x%x\n", pkt->opcode);
  3753. return -EINVAL;
  3754. }
  3755. return 0;
  3756. }
  3757. int si_ib_parse(struct radeon_device *rdev, struct radeon_ib *ib)
  3758. {
  3759. int ret = 0;
  3760. u32 idx = 0;
  3761. struct radeon_cs_packet pkt;
  3762. do {
  3763. pkt.idx = idx;
  3764. pkt.type = RADEON_CP_PACKET_GET_TYPE(ib->ptr[idx]);
  3765. pkt.count = RADEON_CP_PACKET_GET_COUNT(ib->ptr[idx]);
  3766. pkt.one_reg_wr = 0;
  3767. switch (pkt.type) {
  3768. case RADEON_PACKET_TYPE0:
  3769. dev_err(rdev->dev, "Packet0 not allowed!\n");
  3770. ret = -EINVAL;
  3771. break;
  3772. case RADEON_PACKET_TYPE2:
  3773. idx += 1;
  3774. break;
  3775. case RADEON_PACKET_TYPE3:
  3776. pkt.opcode = RADEON_CP_PACKET3_GET_OPCODE(ib->ptr[idx]);
  3777. if (ib->is_const_ib)
  3778. ret = si_vm_packet3_ce_check(rdev, ib->ptr, &pkt);
  3779. else {
  3780. switch (ib->ring) {
  3781. case RADEON_RING_TYPE_GFX_INDEX:
  3782. ret = si_vm_packet3_gfx_check(rdev, ib->ptr, &pkt);
  3783. break;
  3784. case CAYMAN_RING_TYPE_CP1_INDEX:
  3785. case CAYMAN_RING_TYPE_CP2_INDEX:
  3786. ret = si_vm_packet3_compute_check(rdev, ib->ptr, &pkt);
  3787. break;
  3788. default:
  3789. dev_err(rdev->dev, "Non-PM4 ring %d !\n", ib->ring);
  3790. ret = -EINVAL;
  3791. break;
  3792. }
  3793. }
  3794. idx += pkt.count + 2;
  3795. break;
  3796. default:
  3797. dev_err(rdev->dev, "Unknown packet type %d !\n", pkt.type);
  3798. ret = -EINVAL;
  3799. break;
  3800. }
  3801. if (ret)
  3802. break;
  3803. } while (idx < ib->length_dw);
  3804. return ret;
  3805. }
  3806. /*
  3807. * vm
  3808. */
  3809. int si_vm_init(struct radeon_device *rdev)
  3810. {
  3811. /* number of VMs */
  3812. rdev->vm_manager.nvm = 16;
  3813. /* base offset of vram pages */
  3814. rdev->vm_manager.vram_base_offset = 0;
  3815. return 0;
  3816. }
  3817. void si_vm_fini(struct radeon_device *rdev)
  3818. {
  3819. }
  3820. /**
  3821. * si_vm_set_page - update the page tables using the CP
  3822. *
  3823. * @rdev: radeon_device pointer
  3824. * @ib: indirect buffer to fill with commands
  3825. * @pe: addr of the page entry
  3826. * @addr: dst addr to write into pe
  3827. * @count: number of page entries to update
  3828. * @incr: increase next addr by incr bytes
  3829. * @flags: access flags
  3830. *
  3831. * Update the page tables using the CP (SI).
  3832. */
  3833. void si_vm_set_page(struct radeon_device *rdev,
  3834. struct radeon_ib *ib,
  3835. uint64_t pe,
  3836. uint64_t addr, unsigned count,
  3837. uint32_t incr, uint32_t flags)
  3838. {
  3839. uint32_t r600_flags = cayman_vm_page_flags(rdev, flags);
  3840. uint64_t value;
  3841. unsigned ndw;
  3842. if (rdev->asic->vm.pt_ring_index == RADEON_RING_TYPE_GFX_INDEX) {
  3843. while (count) {
  3844. ndw = 2 + count * 2;
  3845. if (ndw > 0x3FFE)
  3846. ndw = 0x3FFE;
  3847. ib->ptr[ib->length_dw++] = PACKET3(PACKET3_WRITE_DATA, ndw);
  3848. ib->ptr[ib->length_dw++] = (WRITE_DATA_ENGINE_SEL(0) |
  3849. WRITE_DATA_DST_SEL(1));
  3850. ib->ptr[ib->length_dw++] = pe;
  3851. ib->ptr[ib->length_dw++] = upper_32_bits(pe);
  3852. for (; ndw > 2; ndw -= 2, --count, pe += 8) {
  3853. if (flags & RADEON_VM_PAGE_SYSTEM) {
  3854. value = radeon_vm_map_gart(rdev, addr);
  3855. value &= 0xFFFFFFFFFFFFF000ULL;
  3856. } else if (flags & RADEON_VM_PAGE_VALID) {
  3857. value = addr;
  3858. } else {
  3859. value = 0;
  3860. }
  3861. addr += incr;
  3862. value |= r600_flags;
  3863. ib->ptr[ib->length_dw++] = value;
  3864. ib->ptr[ib->length_dw++] = upper_32_bits(value);
  3865. }
  3866. }
  3867. } else {
  3868. /* DMA */
  3869. if (flags & RADEON_VM_PAGE_SYSTEM) {
  3870. while (count) {
  3871. ndw = count * 2;
  3872. if (ndw > 0xFFFFE)
  3873. ndw = 0xFFFFE;
  3874. /* for non-physically contiguous pages (system) */
  3875. ib->ptr[ib->length_dw++] = DMA_PACKET(DMA_PACKET_WRITE, 0, 0, 0, ndw);
  3876. ib->ptr[ib->length_dw++] = pe;
  3877. ib->ptr[ib->length_dw++] = upper_32_bits(pe) & 0xff;
  3878. for (; ndw > 0; ndw -= 2, --count, pe += 8) {
  3879. if (flags & RADEON_VM_PAGE_SYSTEM) {
  3880. value = radeon_vm_map_gart(rdev, addr);
  3881. value &= 0xFFFFFFFFFFFFF000ULL;
  3882. } else if (flags & RADEON_VM_PAGE_VALID) {
  3883. value = addr;
  3884. } else {
  3885. value = 0;
  3886. }
  3887. addr += incr;
  3888. value |= r600_flags;
  3889. ib->ptr[ib->length_dw++] = value;
  3890. ib->ptr[ib->length_dw++] = upper_32_bits(value);
  3891. }
  3892. }
  3893. } else {
  3894. while (count) {
  3895. ndw = count * 2;
  3896. if (ndw > 0xFFFFE)
  3897. ndw = 0xFFFFE;
  3898. if (flags & RADEON_VM_PAGE_VALID)
  3899. value = addr;
  3900. else
  3901. value = 0;
  3902. /* for physically contiguous pages (vram) */
  3903. ib->ptr[ib->length_dw++] = DMA_PTE_PDE_PACKET(ndw);
  3904. ib->ptr[ib->length_dw++] = pe; /* dst addr */
  3905. ib->ptr[ib->length_dw++] = upper_32_bits(pe) & 0xff;
  3906. ib->ptr[ib->length_dw++] = r600_flags; /* mask */
  3907. ib->ptr[ib->length_dw++] = 0;
  3908. ib->ptr[ib->length_dw++] = value; /* value */
  3909. ib->ptr[ib->length_dw++] = upper_32_bits(value);
  3910. ib->ptr[ib->length_dw++] = incr; /* increment size */
  3911. ib->ptr[ib->length_dw++] = 0;
  3912. pe += ndw * 4;
  3913. addr += (ndw / 2) * incr;
  3914. count -= ndw / 2;
  3915. }
  3916. }
  3917. while (ib->length_dw & 0x7)
  3918. ib->ptr[ib->length_dw++] = DMA_PACKET(DMA_PACKET_NOP, 0, 0, 0, 0);
  3919. }
  3920. }
  3921. void si_vm_flush(struct radeon_device *rdev, int ridx, struct radeon_vm *vm)
  3922. {
  3923. struct radeon_ring *ring = &rdev->ring[ridx];
  3924. if (vm == NULL)
  3925. return;
  3926. /* write new base address */
  3927. radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  3928. radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
  3929. WRITE_DATA_DST_SEL(0)));
  3930. if (vm->id < 8) {
  3931. radeon_ring_write(ring,
  3932. (VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (vm->id << 2)) >> 2);
  3933. } else {
  3934. radeon_ring_write(ring,
  3935. (VM_CONTEXT8_PAGE_TABLE_BASE_ADDR + ((vm->id - 8) << 2)) >> 2);
  3936. }
  3937. radeon_ring_write(ring, 0);
  3938. radeon_ring_write(ring, vm->pd_gpu_addr >> 12);
  3939. /* flush hdp cache */
  3940. radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  3941. radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
  3942. WRITE_DATA_DST_SEL(0)));
  3943. radeon_ring_write(ring, HDP_MEM_COHERENCY_FLUSH_CNTL >> 2);
  3944. radeon_ring_write(ring, 0);
  3945. radeon_ring_write(ring, 0x1);
  3946. /* bits 0-15 are the VM contexts0-15 */
  3947. radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  3948. radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
  3949. WRITE_DATA_DST_SEL(0)));
  3950. radeon_ring_write(ring, VM_INVALIDATE_REQUEST >> 2);
  3951. radeon_ring_write(ring, 0);
  3952. radeon_ring_write(ring, 1 << vm->id);
  3953. /* sync PFP to ME, otherwise we might get invalid PFP reads */
  3954. radeon_ring_write(ring, PACKET3(PACKET3_PFP_SYNC_ME, 0));
  3955. radeon_ring_write(ring, 0x0);
  3956. }
  3957. void si_dma_vm_flush(struct radeon_device *rdev, int ridx, struct radeon_vm *vm)
  3958. {
  3959. struct radeon_ring *ring = &rdev->ring[ridx];
  3960. if (vm == NULL)
  3961. return;
  3962. radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_SRBM_WRITE, 0, 0, 0, 0));
  3963. if (vm->id < 8) {
  3964. radeon_ring_write(ring, (0xf << 16) | ((VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (vm->id << 2)) >> 2));
  3965. } else {
  3966. radeon_ring_write(ring, (0xf << 16) | ((VM_CONTEXT8_PAGE_TABLE_BASE_ADDR + ((vm->id - 8) << 2)) >> 2));
  3967. }
  3968. radeon_ring_write(ring, vm->pd_gpu_addr >> 12);
  3969. /* flush hdp cache */
  3970. radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_SRBM_WRITE, 0, 0, 0, 0));
  3971. radeon_ring_write(ring, (0xf << 16) | (HDP_MEM_COHERENCY_FLUSH_CNTL >> 2));
  3972. radeon_ring_write(ring, 1);
  3973. /* bits 0-7 are the VM contexts0-7 */
  3974. radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_SRBM_WRITE, 0, 0, 0, 0));
  3975. radeon_ring_write(ring, (0xf << 16) | (VM_INVALIDATE_REQUEST >> 2));
  3976. radeon_ring_write(ring, 1 << vm->id);
  3977. }
  3978. /*
  3979. * RLC
  3980. */
  3981. void si_rlc_fini(struct radeon_device *rdev)
  3982. {
  3983. int r;
  3984. /* save restore block */
  3985. if (rdev->rlc.save_restore_obj) {
  3986. r = radeon_bo_reserve(rdev->rlc.save_restore_obj, false);
  3987. if (unlikely(r != 0))
  3988. dev_warn(rdev->dev, "(%d) reserve RLC sr bo failed\n", r);
  3989. radeon_bo_unpin(rdev->rlc.save_restore_obj);
  3990. radeon_bo_unreserve(rdev->rlc.save_restore_obj);
  3991. radeon_bo_unref(&rdev->rlc.save_restore_obj);
  3992. rdev->rlc.save_restore_obj = NULL;
  3993. }
  3994. /* clear state block */
  3995. if (rdev->rlc.clear_state_obj) {
  3996. r = radeon_bo_reserve(rdev->rlc.clear_state_obj, false);
  3997. if (unlikely(r != 0))
  3998. dev_warn(rdev->dev, "(%d) reserve RLC c bo failed\n", r);
  3999. radeon_bo_unpin(rdev->rlc.clear_state_obj);
  4000. radeon_bo_unreserve(rdev->rlc.clear_state_obj);
  4001. radeon_bo_unref(&rdev->rlc.clear_state_obj);
  4002. rdev->rlc.clear_state_obj = NULL;
  4003. }
  4004. }
  4005. int si_rlc_init(struct radeon_device *rdev)
  4006. {
  4007. int r;
  4008. /* save restore block */
  4009. if (rdev->rlc.save_restore_obj == NULL) {
  4010. r = radeon_bo_create(rdev, RADEON_GPU_PAGE_SIZE, PAGE_SIZE, true,
  4011. RADEON_GEM_DOMAIN_VRAM, NULL,
  4012. &rdev->rlc.save_restore_obj);
  4013. if (r) {
  4014. dev_warn(rdev->dev, "(%d) create RLC sr bo failed\n", r);
  4015. return r;
  4016. }
  4017. }
  4018. r = radeon_bo_reserve(rdev->rlc.save_restore_obj, false);
  4019. if (unlikely(r != 0)) {
  4020. si_rlc_fini(rdev);
  4021. return r;
  4022. }
  4023. r = radeon_bo_pin(rdev->rlc.save_restore_obj, RADEON_GEM_DOMAIN_VRAM,
  4024. &rdev->rlc.save_restore_gpu_addr);
  4025. radeon_bo_unreserve(rdev->rlc.save_restore_obj);
  4026. if (r) {
  4027. dev_warn(rdev->dev, "(%d) pin RLC sr bo failed\n", r);
  4028. si_rlc_fini(rdev);
  4029. return r;
  4030. }
  4031. /* clear state block */
  4032. if (rdev->rlc.clear_state_obj == NULL) {
  4033. r = radeon_bo_create(rdev, RADEON_GPU_PAGE_SIZE, PAGE_SIZE, true,
  4034. RADEON_GEM_DOMAIN_VRAM, NULL,
  4035. &rdev->rlc.clear_state_obj);
  4036. if (r) {
  4037. dev_warn(rdev->dev, "(%d) create RLC c bo failed\n", r);
  4038. si_rlc_fini(rdev);
  4039. return r;
  4040. }
  4041. }
  4042. r = radeon_bo_reserve(rdev->rlc.clear_state_obj, false);
  4043. if (unlikely(r != 0)) {
  4044. si_rlc_fini(rdev);
  4045. return r;
  4046. }
  4047. r = radeon_bo_pin(rdev->rlc.clear_state_obj, RADEON_GEM_DOMAIN_VRAM,
  4048. &rdev->rlc.clear_state_gpu_addr);
  4049. radeon_bo_unreserve(rdev->rlc.clear_state_obj);
  4050. if (r) {
  4051. dev_warn(rdev->dev, "(%d) pin RLC c bo failed\n", r);
  4052. si_rlc_fini(rdev);
  4053. return r;
  4054. }
  4055. return 0;
  4056. }
  4057. static void si_enable_gui_idle_interrupt(struct radeon_device *rdev,
  4058. bool enable)
  4059. {
  4060. u32 tmp = RREG32(CP_INT_CNTL_RING0);
  4061. u32 mask;
  4062. int i;
  4063. if (enable)
  4064. tmp |= (CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
  4065. else
  4066. tmp &= ~(CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
  4067. WREG32(CP_INT_CNTL_RING0, tmp);
  4068. if (!enable) {
  4069. /* read a gfx register */
  4070. tmp = RREG32(DB_DEPTH_INFO);
  4071. mask = RLC_BUSY_STATUS | GFX_POWER_STATUS | GFX_CLOCK_STATUS | GFX_LS_STATUS;
  4072. for (i = 0; i < rdev->usec_timeout; i++) {
  4073. if ((RREG32(RLC_STAT) & mask) == (GFX_CLOCK_STATUS | GFX_POWER_STATUS))
  4074. break;
  4075. udelay(1);
  4076. }
  4077. }
  4078. }
  4079. static void si_wait_for_rlc_serdes(struct radeon_device *rdev)
  4080. {
  4081. int i;
  4082. for (i = 0; i < rdev->usec_timeout; i++) {
  4083. if (RREG32(RLC_SERDES_MASTER_BUSY_0) == 0)
  4084. break;
  4085. udelay(1);
  4086. }
  4087. for (i = 0; i < rdev->usec_timeout; i++) {
  4088. if (RREG32(RLC_SERDES_MASTER_BUSY_1) == 0)
  4089. break;
  4090. udelay(1);
  4091. }
  4092. }
  4093. static void si_rlc_stop(struct radeon_device *rdev)
  4094. {
  4095. WREG32(RLC_CNTL, 0);
  4096. si_enable_gui_idle_interrupt(rdev, false);
  4097. si_wait_for_rlc_serdes(rdev);
  4098. }
  4099. static void si_rlc_start(struct radeon_device *rdev)
  4100. {
  4101. WREG32(RLC_CNTL, RLC_ENABLE);
  4102. si_enable_gui_idle_interrupt(rdev, true);
  4103. udelay(50);
  4104. }
  4105. static bool si_lbpw_supported(struct radeon_device *rdev)
  4106. {
  4107. u32 tmp;
  4108. /* Enable LBPW only for DDR3 */
  4109. tmp = RREG32(MC_SEQ_MISC0);
  4110. if ((tmp & 0xF0000000) == 0xB0000000)
  4111. return true;
  4112. return false;
  4113. }
  4114. static void si_enable_lbpw(struct radeon_device *rdev, bool enable)
  4115. {
  4116. u32 tmp;
  4117. tmp = RREG32(RLC_LB_CNTL);
  4118. if (enable)
  4119. tmp |= LOAD_BALANCE_ENABLE;
  4120. else
  4121. tmp &= ~LOAD_BALANCE_ENABLE;
  4122. WREG32(RLC_LB_CNTL, tmp);
  4123. if (!enable) {
  4124. si_select_se_sh(rdev, 0xffffffff, 0xffffffff);
  4125. WREG32(SPI_LB_CU_MASK, 0x00ff);
  4126. }
  4127. }
  4128. static int si_rlc_resume(struct radeon_device *rdev)
  4129. {
  4130. u32 i;
  4131. const __be32 *fw_data;
  4132. if (!rdev->rlc_fw)
  4133. return -EINVAL;
  4134. si_rlc_stop(rdev);
  4135. WREG32(RLC_RL_BASE, 0);
  4136. WREG32(RLC_RL_SIZE, 0);
  4137. WREG32(RLC_LB_CNTL, 0);
  4138. WREG32(RLC_LB_CNTR_MAX, 0xffffffff);
  4139. WREG32(RLC_LB_CNTR_INIT, 0);
  4140. WREG32(RLC_LB_INIT_CU_MASK, 0xffffffff);
  4141. WREG32(RLC_SAVE_AND_RESTORE_BASE, rdev->rlc.save_restore_gpu_addr >> 8);
  4142. WREG32(RLC_CLEAR_STATE_RESTORE_BASE, rdev->rlc.clear_state_gpu_addr >> 8);
  4143. WREG32(RLC_MC_CNTL, 0);
  4144. WREG32(RLC_UCODE_CNTL, 0);
  4145. fw_data = (const __be32 *)rdev->rlc_fw->data;
  4146. for (i = 0; i < SI_RLC_UCODE_SIZE; i++) {
  4147. WREG32(RLC_UCODE_ADDR, i);
  4148. WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
  4149. }
  4150. WREG32(RLC_UCODE_ADDR, 0);
  4151. si_enable_lbpw(rdev, si_lbpw_supported(rdev));
  4152. si_rlc_start(rdev);
  4153. return 0;
  4154. }
  4155. static void si_enable_interrupts(struct radeon_device *rdev)
  4156. {
  4157. u32 ih_cntl = RREG32(IH_CNTL);
  4158. u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
  4159. ih_cntl |= ENABLE_INTR;
  4160. ih_rb_cntl |= IH_RB_ENABLE;
  4161. WREG32(IH_CNTL, ih_cntl);
  4162. WREG32(IH_RB_CNTL, ih_rb_cntl);
  4163. rdev->ih.enabled = true;
  4164. }
  4165. static void si_disable_interrupts(struct radeon_device *rdev)
  4166. {
  4167. u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
  4168. u32 ih_cntl = RREG32(IH_CNTL);
  4169. ih_rb_cntl &= ~IH_RB_ENABLE;
  4170. ih_cntl &= ~ENABLE_INTR;
  4171. WREG32(IH_RB_CNTL, ih_rb_cntl);
  4172. WREG32(IH_CNTL, ih_cntl);
  4173. /* set rptr, wptr to 0 */
  4174. WREG32(IH_RB_RPTR, 0);
  4175. WREG32(IH_RB_WPTR, 0);
  4176. rdev->ih.enabled = false;
  4177. rdev->ih.rptr = 0;
  4178. }
  4179. static void si_disable_interrupt_state(struct radeon_device *rdev)
  4180. {
  4181. u32 tmp;
  4182. WREG32(CP_INT_CNTL_RING0, CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
  4183. WREG32(CP_INT_CNTL_RING1, 0);
  4184. WREG32(CP_INT_CNTL_RING2, 0);
  4185. tmp = RREG32(DMA_CNTL + DMA0_REGISTER_OFFSET) & ~TRAP_ENABLE;
  4186. WREG32(DMA_CNTL + DMA0_REGISTER_OFFSET, tmp);
  4187. tmp = RREG32(DMA_CNTL + DMA1_REGISTER_OFFSET) & ~TRAP_ENABLE;
  4188. WREG32(DMA_CNTL + DMA1_REGISTER_OFFSET, tmp);
  4189. WREG32(GRBM_INT_CNTL, 0);
  4190. if (rdev->num_crtc >= 2) {
  4191. WREG32(INT_MASK + EVERGREEN_CRTC0_REGISTER_OFFSET, 0);
  4192. WREG32(INT_MASK + EVERGREEN_CRTC1_REGISTER_OFFSET, 0);
  4193. }
  4194. if (rdev->num_crtc >= 4) {
  4195. WREG32(INT_MASK + EVERGREEN_CRTC2_REGISTER_OFFSET, 0);
  4196. WREG32(INT_MASK + EVERGREEN_CRTC3_REGISTER_OFFSET, 0);
  4197. }
  4198. if (rdev->num_crtc >= 6) {
  4199. WREG32(INT_MASK + EVERGREEN_CRTC4_REGISTER_OFFSET, 0);
  4200. WREG32(INT_MASK + EVERGREEN_CRTC5_REGISTER_OFFSET, 0);
  4201. }
  4202. if (rdev->num_crtc >= 2) {
  4203. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET, 0);
  4204. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET, 0);
  4205. }
  4206. if (rdev->num_crtc >= 4) {
  4207. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET, 0);
  4208. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET, 0);
  4209. }
  4210. if (rdev->num_crtc >= 6) {
  4211. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET, 0);
  4212. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET, 0);
  4213. }
  4214. if (!ASIC_IS_NODCE(rdev)) {
  4215. WREG32(DACA_AUTODETECT_INT_CONTROL, 0);
  4216. tmp = RREG32(DC_HPD1_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  4217. WREG32(DC_HPD1_INT_CONTROL, tmp);
  4218. tmp = RREG32(DC_HPD2_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  4219. WREG32(DC_HPD2_INT_CONTROL, tmp);
  4220. tmp = RREG32(DC_HPD3_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  4221. WREG32(DC_HPD3_INT_CONTROL, tmp);
  4222. tmp = RREG32(DC_HPD4_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  4223. WREG32(DC_HPD4_INT_CONTROL, tmp);
  4224. tmp = RREG32(DC_HPD5_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  4225. WREG32(DC_HPD5_INT_CONTROL, tmp);
  4226. tmp = RREG32(DC_HPD6_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  4227. WREG32(DC_HPD6_INT_CONTROL, tmp);
  4228. }
  4229. }
  4230. static int si_irq_init(struct radeon_device *rdev)
  4231. {
  4232. int ret = 0;
  4233. int rb_bufsz;
  4234. u32 interrupt_cntl, ih_cntl, ih_rb_cntl;
  4235. /* allocate ring */
  4236. ret = r600_ih_ring_alloc(rdev);
  4237. if (ret)
  4238. return ret;
  4239. /* disable irqs */
  4240. si_disable_interrupts(rdev);
  4241. /* init rlc */
  4242. ret = si_rlc_resume(rdev);
  4243. if (ret) {
  4244. r600_ih_ring_fini(rdev);
  4245. return ret;
  4246. }
  4247. /* setup interrupt control */
  4248. /* set dummy read address to ring address */
  4249. WREG32(INTERRUPT_CNTL2, rdev->ih.gpu_addr >> 8);
  4250. interrupt_cntl = RREG32(INTERRUPT_CNTL);
  4251. /* IH_DUMMY_RD_OVERRIDE=0 - dummy read disabled with msi, enabled without msi
  4252. * IH_DUMMY_RD_OVERRIDE=1 - dummy read controlled by IH_DUMMY_RD_EN
  4253. */
  4254. interrupt_cntl &= ~IH_DUMMY_RD_OVERRIDE;
  4255. /* IH_REQ_NONSNOOP_EN=1 if ring is in non-cacheable memory, e.g., vram */
  4256. interrupt_cntl &= ~IH_REQ_NONSNOOP_EN;
  4257. WREG32(INTERRUPT_CNTL, interrupt_cntl);
  4258. WREG32(IH_RB_BASE, rdev->ih.gpu_addr >> 8);
  4259. rb_bufsz = drm_order(rdev->ih.ring_size / 4);
  4260. ih_rb_cntl = (IH_WPTR_OVERFLOW_ENABLE |
  4261. IH_WPTR_OVERFLOW_CLEAR |
  4262. (rb_bufsz << 1));
  4263. if (rdev->wb.enabled)
  4264. ih_rb_cntl |= IH_WPTR_WRITEBACK_ENABLE;
  4265. /* set the writeback address whether it's enabled or not */
  4266. WREG32(IH_RB_WPTR_ADDR_LO, (rdev->wb.gpu_addr + R600_WB_IH_WPTR_OFFSET) & 0xFFFFFFFC);
  4267. WREG32(IH_RB_WPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + R600_WB_IH_WPTR_OFFSET) & 0xFF);
  4268. WREG32(IH_RB_CNTL, ih_rb_cntl);
  4269. /* set rptr, wptr to 0 */
  4270. WREG32(IH_RB_RPTR, 0);
  4271. WREG32(IH_RB_WPTR, 0);
  4272. /* Default settings for IH_CNTL (disabled at first) */
  4273. ih_cntl = MC_WRREQ_CREDIT(0x10) | MC_WR_CLEAN_CNT(0x10) | MC_VMID(0);
  4274. /* RPTR_REARM only works if msi's are enabled */
  4275. if (rdev->msi_enabled)
  4276. ih_cntl |= RPTR_REARM;
  4277. WREG32(IH_CNTL, ih_cntl);
  4278. /* force the active interrupt state to all disabled */
  4279. si_disable_interrupt_state(rdev);
  4280. pci_set_master(rdev->pdev);
  4281. /* enable irqs */
  4282. si_enable_interrupts(rdev);
  4283. return ret;
  4284. }
  4285. int si_irq_set(struct radeon_device *rdev)
  4286. {
  4287. u32 cp_int_cntl = CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE;
  4288. u32 cp_int_cntl1 = 0, cp_int_cntl2 = 0;
  4289. u32 crtc1 = 0, crtc2 = 0, crtc3 = 0, crtc4 = 0, crtc5 = 0, crtc6 = 0;
  4290. u32 hpd1 = 0, hpd2 = 0, hpd3 = 0, hpd4 = 0, hpd5 = 0, hpd6 = 0;
  4291. u32 grbm_int_cntl = 0;
  4292. u32 grph1 = 0, grph2 = 0, grph3 = 0, grph4 = 0, grph5 = 0, grph6 = 0;
  4293. u32 dma_cntl, dma_cntl1;
  4294. if (!rdev->irq.installed) {
  4295. WARN(1, "Can't enable IRQ/MSI because no handler is installed\n");
  4296. return -EINVAL;
  4297. }
  4298. /* don't enable anything if the ih is disabled */
  4299. if (!rdev->ih.enabled) {
  4300. si_disable_interrupts(rdev);
  4301. /* force the active interrupt state to all disabled */
  4302. si_disable_interrupt_state(rdev);
  4303. return 0;
  4304. }
  4305. if (!ASIC_IS_NODCE(rdev)) {
  4306. hpd1 = RREG32(DC_HPD1_INT_CONTROL) & ~DC_HPDx_INT_EN;
  4307. hpd2 = RREG32(DC_HPD2_INT_CONTROL) & ~DC_HPDx_INT_EN;
  4308. hpd3 = RREG32(DC_HPD3_INT_CONTROL) & ~DC_HPDx_INT_EN;
  4309. hpd4 = RREG32(DC_HPD4_INT_CONTROL) & ~DC_HPDx_INT_EN;
  4310. hpd5 = RREG32(DC_HPD5_INT_CONTROL) & ~DC_HPDx_INT_EN;
  4311. hpd6 = RREG32(DC_HPD6_INT_CONTROL) & ~DC_HPDx_INT_EN;
  4312. }
  4313. dma_cntl = RREG32(DMA_CNTL + DMA0_REGISTER_OFFSET) & ~TRAP_ENABLE;
  4314. dma_cntl1 = RREG32(DMA_CNTL + DMA1_REGISTER_OFFSET) & ~TRAP_ENABLE;
  4315. /* enable CP interrupts on all rings */
  4316. if (atomic_read(&rdev->irq.ring_int[RADEON_RING_TYPE_GFX_INDEX])) {
  4317. DRM_DEBUG("si_irq_set: sw int gfx\n");
  4318. cp_int_cntl |= TIME_STAMP_INT_ENABLE;
  4319. }
  4320. if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_CP1_INDEX])) {
  4321. DRM_DEBUG("si_irq_set: sw int cp1\n");
  4322. cp_int_cntl1 |= TIME_STAMP_INT_ENABLE;
  4323. }
  4324. if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_CP2_INDEX])) {
  4325. DRM_DEBUG("si_irq_set: sw int cp2\n");
  4326. cp_int_cntl2 |= TIME_STAMP_INT_ENABLE;
  4327. }
  4328. if (atomic_read(&rdev->irq.ring_int[R600_RING_TYPE_DMA_INDEX])) {
  4329. DRM_DEBUG("si_irq_set: sw int dma\n");
  4330. dma_cntl |= TRAP_ENABLE;
  4331. }
  4332. if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_DMA1_INDEX])) {
  4333. DRM_DEBUG("si_irq_set: sw int dma1\n");
  4334. dma_cntl1 |= TRAP_ENABLE;
  4335. }
  4336. if (rdev->irq.crtc_vblank_int[0] ||
  4337. atomic_read(&rdev->irq.pflip[0])) {
  4338. DRM_DEBUG("si_irq_set: vblank 0\n");
  4339. crtc1 |= VBLANK_INT_MASK;
  4340. }
  4341. if (rdev->irq.crtc_vblank_int[1] ||
  4342. atomic_read(&rdev->irq.pflip[1])) {
  4343. DRM_DEBUG("si_irq_set: vblank 1\n");
  4344. crtc2 |= VBLANK_INT_MASK;
  4345. }
  4346. if (rdev->irq.crtc_vblank_int[2] ||
  4347. atomic_read(&rdev->irq.pflip[2])) {
  4348. DRM_DEBUG("si_irq_set: vblank 2\n");
  4349. crtc3 |= VBLANK_INT_MASK;
  4350. }
  4351. if (rdev->irq.crtc_vblank_int[3] ||
  4352. atomic_read(&rdev->irq.pflip[3])) {
  4353. DRM_DEBUG("si_irq_set: vblank 3\n");
  4354. crtc4 |= VBLANK_INT_MASK;
  4355. }
  4356. if (rdev->irq.crtc_vblank_int[4] ||
  4357. atomic_read(&rdev->irq.pflip[4])) {
  4358. DRM_DEBUG("si_irq_set: vblank 4\n");
  4359. crtc5 |= VBLANK_INT_MASK;
  4360. }
  4361. if (rdev->irq.crtc_vblank_int[5] ||
  4362. atomic_read(&rdev->irq.pflip[5])) {
  4363. DRM_DEBUG("si_irq_set: vblank 5\n");
  4364. crtc6 |= VBLANK_INT_MASK;
  4365. }
  4366. if (rdev->irq.hpd[0]) {
  4367. DRM_DEBUG("si_irq_set: hpd 1\n");
  4368. hpd1 |= DC_HPDx_INT_EN;
  4369. }
  4370. if (rdev->irq.hpd[1]) {
  4371. DRM_DEBUG("si_irq_set: hpd 2\n");
  4372. hpd2 |= DC_HPDx_INT_EN;
  4373. }
  4374. if (rdev->irq.hpd[2]) {
  4375. DRM_DEBUG("si_irq_set: hpd 3\n");
  4376. hpd3 |= DC_HPDx_INT_EN;
  4377. }
  4378. if (rdev->irq.hpd[3]) {
  4379. DRM_DEBUG("si_irq_set: hpd 4\n");
  4380. hpd4 |= DC_HPDx_INT_EN;
  4381. }
  4382. if (rdev->irq.hpd[4]) {
  4383. DRM_DEBUG("si_irq_set: hpd 5\n");
  4384. hpd5 |= DC_HPDx_INT_EN;
  4385. }
  4386. if (rdev->irq.hpd[5]) {
  4387. DRM_DEBUG("si_irq_set: hpd 6\n");
  4388. hpd6 |= DC_HPDx_INT_EN;
  4389. }
  4390. WREG32(CP_INT_CNTL_RING0, cp_int_cntl);
  4391. WREG32(CP_INT_CNTL_RING1, cp_int_cntl1);
  4392. WREG32(CP_INT_CNTL_RING2, cp_int_cntl2);
  4393. WREG32(DMA_CNTL + DMA0_REGISTER_OFFSET, dma_cntl);
  4394. WREG32(DMA_CNTL + DMA1_REGISTER_OFFSET, dma_cntl1);
  4395. WREG32(GRBM_INT_CNTL, grbm_int_cntl);
  4396. if (rdev->num_crtc >= 2) {
  4397. WREG32(INT_MASK + EVERGREEN_CRTC0_REGISTER_OFFSET, crtc1);
  4398. WREG32(INT_MASK + EVERGREEN_CRTC1_REGISTER_OFFSET, crtc2);
  4399. }
  4400. if (rdev->num_crtc >= 4) {
  4401. WREG32(INT_MASK + EVERGREEN_CRTC2_REGISTER_OFFSET, crtc3);
  4402. WREG32(INT_MASK + EVERGREEN_CRTC3_REGISTER_OFFSET, crtc4);
  4403. }
  4404. if (rdev->num_crtc >= 6) {
  4405. WREG32(INT_MASK + EVERGREEN_CRTC4_REGISTER_OFFSET, crtc5);
  4406. WREG32(INT_MASK + EVERGREEN_CRTC5_REGISTER_OFFSET, crtc6);
  4407. }
  4408. if (rdev->num_crtc >= 2) {
  4409. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET, grph1);
  4410. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET, grph2);
  4411. }
  4412. if (rdev->num_crtc >= 4) {
  4413. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET, grph3);
  4414. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET, grph4);
  4415. }
  4416. if (rdev->num_crtc >= 6) {
  4417. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET, grph5);
  4418. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET, grph6);
  4419. }
  4420. if (!ASIC_IS_NODCE(rdev)) {
  4421. WREG32(DC_HPD1_INT_CONTROL, hpd1);
  4422. WREG32(DC_HPD2_INT_CONTROL, hpd2);
  4423. WREG32(DC_HPD3_INT_CONTROL, hpd3);
  4424. WREG32(DC_HPD4_INT_CONTROL, hpd4);
  4425. WREG32(DC_HPD5_INT_CONTROL, hpd5);
  4426. WREG32(DC_HPD6_INT_CONTROL, hpd6);
  4427. }
  4428. return 0;
  4429. }
  4430. static inline void si_irq_ack(struct radeon_device *rdev)
  4431. {
  4432. u32 tmp;
  4433. if (ASIC_IS_NODCE(rdev))
  4434. return;
  4435. rdev->irq.stat_regs.evergreen.disp_int = RREG32(DISP_INTERRUPT_STATUS);
  4436. rdev->irq.stat_regs.evergreen.disp_int_cont = RREG32(DISP_INTERRUPT_STATUS_CONTINUE);
  4437. rdev->irq.stat_regs.evergreen.disp_int_cont2 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE2);
  4438. rdev->irq.stat_regs.evergreen.disp_int_cont3 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE3);
  4439. rdev->irq.stat_regs.evergreen.disp_int_cont4 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE4);
  4440. rdev->irq.stat_regs.evergreen.disp_int_cont5 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE5);
  4441. rdev->irq.stat_regs.evergreen.d1grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET);
  4442. rdev->irq.stat_regs.evergreen.d2grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET);
  4443. if (rdev->num_crtc >= 4) {
  4444. rdev->irq.stat_regs.evergreen.d3grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET);
  4445. rdev->irq.stat_regs.evergreen.d4grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET);
  4446. }
  4447. if (rdev->num_crtc >= 6) {
  4448. rdev->irq.stat_regs.evergreen.d5grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET);
  4449. rdev->irq.stat_regs.evergreen.d6grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET);
  4450. }
  4451. if (rdev->irq.stat_regs.evergreen.d1grph_int & GRPH_PFLIP_INT_OCCURRED)
  4452. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  4453. if (rdev->irq.stat_regs.evergreen.d2grph_int & GRPH_PFLIP_INT_OCCURRED)
  4454. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  4455. if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VBLANK_INTERRUPT)
  4456. WREG32(VBLANK_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, VBLANK_ACK);
  4457. if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VLINE_INTERRUPT)
  4458. WREG32(VLINE_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, VLINE_ACK);
  4459. if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VBLANK_INTERRUPT)
  4460. WREG32(VBLANK_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, VBLANK_ACK);
  4461. if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VLINE_INTERRUPT)
  4462. WREG32(VLINE_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, VLINE_ACK);
  4463. if (rdev->num_crtc >= 4) {
  4464. if (rdev->irq.stat_regs.evergreen.d3grph_int & GRPH_PFLIP_INT_OCCURRED)
  4465. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  4466. if (rdev->irq.stat_regs.evergreen.d4grph_int & GRPH_PFLIP_INT_OCCURRED)
  4467. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  4468. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VBLANK_INTERRUPT)
  4469. WREG32(VBLANK_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, VBLANK_ACK);
  4470. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VLINE_INTERRUPT)
  4471. WREG32(VLINE_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, VLINE_ACK);
  4472. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VBLANK_INTERRUPT)
  4473. WREG32(VBLANK_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, VBLANK_ACK);
  4474. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VLINE_INTERRUPT)
  4475. WREG32(VLINE_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, VLINE_ACK);
  4476. }
  4477. if (rdev->num_crtc >= 6) {
  4478. if (rdev->irq.stat_regs.evergreen.d5grph_int & GRPH_PFLIP_INT_OCCURRED)
  4479. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  4480. if (rdev->irq.stat_regs.evergreen.d6grph_int & GRPH_PFLIP_INT_OCCURRED)
  4481. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  4482. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VBLANK_INTERRUPT)
  4483. WREG32(VBLANK_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, VBLANK_ACK);
  4484. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VLINE_INTERRUPT)
  4485. WREG32(VLINE_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, VLINE_ACK);
  4486. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VBLANK_INTERRUPT)
  4487. WREG32(VBLANK_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, VBLANK_ACK);
  4488. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VLINE_INTERRUPT)
  4489. WREG32(VLINE_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, VLINE_ACK);
  4490. }
  4491. if (rdev->irq.stat_regs.evergreen.disp_int & DC_HPD1_INTERRUPT) {
  4492. tmp = RREG32(DC_HPD1_INT_CONTROL);
  4493. tmp |= DC_HPDx_INT_ACK;
  4494. WREG32(DC_HPD1_INT_CONTROL, tmp);
  4495. }
  4496. if (rdev->irq.stat_regs.evergreen.disp_int_cont & DC_HPD2_INTERRUPT) {
  4497. tmp = RREG32(DC_HPD2_INT_CONTROL);
  4498. tmp |= DC_HPDx_INT_ACK;
  4499. WREG32(DC_HPD2_INT_CONTROL, tmp);
  4500. }
  4501. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & DC_HPD3_INTERRUPT) {
  4502. tmp = RREG32(DC_HPD3_INT_CONTROL);
  4503. tmp |= DC_HPDx_INT_ACK;
  4504. WREG32(DC_HPD3_INT_CONTROL, tmp);
  4505. }
  4506. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & DC_HPD4_INTERRUPT) {
  4507. tmp = RREG32(DC_HPD4_INT_CONTROL);
  4508. tmp |= DC_HPDx_INT_ACK;
  4509. WREG32(DC_HPD4_INT_CONTROL, tmp);
  4510. }
  4511. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & DC_HPD5_INTERRUPT) {
  4512. tmp = RREG32(DC_HPD5_INT_CONTROL);
  4513. tmp |= DC_HPDx_INT_ACK;
  4514. WREG32(DC_HPD5_INT_CONTROL, tmp);
  4515. }
  4516. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & DC_HPD6_INTERRUPT) {
  4517. tmp = RREG32(DC_HPD5_INT_CONTROL);
  4518. tmp |= DC_HPDx_INT_ACK;
  4519. WREG32(DC_HPD6_INT_CONTROL, tmp);
  4520. }
  4521. }
  4522. static void si_irq_disable(struct radeon_device *rdev)
  4523. {
  4524. si_disable_interrupts(rdev);
  4525. /* Wait and acknowledge irq */
  4526. mdelay(1);
  4527. si_irq_ack(rdev);
  4528. si_disable_interrupt_state(rdev);
  4529. }
  4530. static void si_irq_suspend(struct radeon_device *rdev)
  4531. {
  4532. si_irq_disable(rdev);
  4533. si_rlc_stop(rdev);
  4534. }
  4535. static void si_irq_fini(struct radeon_device *rdev)
  4536. {
  4537. si_irq_suspend(rdev);
  4538. r600_ih_ring_fini(rdev);
  4539. }
  4540. static inline u32 si_get_ih_wptr(struct radeon_device *rdev)
  4541. {
  4542. u32 wptr, tmp;
  4543. if (rdev->wb.enabled)
  4544. wptr = le32_to_cpu(rdev->wb.wb[R600_WB_IH_WPTR_OFFSET/4]);
  4545. else
  4546. wptr = RREG32(IH_RB_WPTR);
  4547. if (wptr & RB_OVERFLOW) {
  4548. /* When a ring buffer overflow happen start parsing interrupt
  4549. * from the last not overwritten vector (wptr + 16). Hopefully
  4550. * this should allow us to catchup.
  4551. */
  4552. dev_warn(rdev->dev, "IH ring buffer overflow (0x%08X, %d, %d)\n",
  4553. wptr, rdev->ih.rptr, (wptr + 16) + rdev->ih.ptr_mask);
  4554. rdev->ih.rptr = (wptr + 16) & rdev->ih.ptr_mask;
  4555. tmp = RREG32(IH_RB_CNTL);
  4556. tmp |= IH_WPTR_OVERFLOW_CLEAR;
  4557. WREG32(IH_RB_CNTL, tmp);
  4558. }
  4559. return (wptr & rdev->ih.ptr_mask);
  4560. }
  4561. /* SI IV Ring
  4562. * Each IV ring entry is 128 bits:
  4563. * [7:0] - interrupt source id
  4564. * [31:8] - reserved
  4565. * [59:32] - interrupt source data
  4566. * [63:60] - reserved
  4567. * [71:64] - RINGID
  4568. * [79:72] - VMID
  4569. * [127:80] - reserved
  4570. */
  4571. int si_irq_process(struct radeon_device *rdev)
  4572. {
  4573. u32 wptr;
  4574. u32 rptr;
  4575. u32 src_id, src_data, ring_id;
  4576. u32 ring_index;
  4577. bool queue_hotplug = false;
  4578. if (!rdev->ih.enabled || rdev->shutdown)
  4579. return IRQ_NONE;
  4580. wptr = si_get_ih_wptr(rdev);
  4581. restart_ih:
  4582. /* is somebody else already processing irqs? */
  4583. if (atomic_xchg(&rdev->ih.lock, 1))
  4584. return IRQ_NONE;
  4585. rptr = rdev->ih.rptr;
  4586. DRM_DEBUG("si_irq_process start: rptr %d, wptr %d\n", rptr, wptr);
  4587. /* Order reading of wptr vs. reading of IH ring data */
  4588. rmb();
  4589. /* display interrupts */
  4590. si_irq_ack(rdev);
  4591. while (rptr != wptr) {
  4592. /* wptr/rptr are in bytes! */
  4593. ring_index = rptr / 4;
  4594. src_id = le32_to_cpu(rdev->ih.ring[ring_index]) & 0xff;
  4595. src_data = le32_to_cpu(rdev->ih.ring[ring_index + 1]) & 0xfffffff;
  4596. ring_id = le32_to_cpu(rdev->ih.ring[ring_index + 2]) & 0xff;
  4597. switch (src_id) {
  4598. case 1: /* D1 vblank/vline */
  4599. switch (src_data) {
  4600. case 0: /* D1 vblank */
  4601. if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VBLANK_INTERRUPT) {
  4602. if (rdev->irq.crtc_vblank_int[0]) {
  4603. drm_handle_vblank(rdev->ddev, 0);
  4604. rdev->pm.vblank_sync = true;
  4605. wake_up(&rdev->irq.vblank_queue);
  4606. }
  4607. if (atomic_read(&rdev->irq.pflip[0]))
  4608. radeon_crtc_handle_flip(rdev, 0);
  4609. rdev->irq.stat_regs.evergreen.disp_int &= ~LB_D1_VBLANK_INTERRUPT;
  4610. DRM_DEBUG("IH: D1 vblank\n");
  4611. }
  4612. break;
  4613. case 1: /* D1 vline */
  4614. if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VLINE_INTERRUPT) {
  4615. rdev->irq.stat_regs.evergreen.disp_int &= ~LB_D1_VLINE_INTERRUPT;
  4616. DRM_DEBUG("IH: D1 vline\n");
  4617. }
  4618. break;
  4619. default:
  4620. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4621. break;
  4622. }
  4623. break;
  4624. case 2: /* D2 vblank/vline */
  4625. switch (src_data) {
  4626. case 0: /* D2 vblank */
  4627. if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VBLANK_INTERRUPT) {
  4628. if (rdev->irq.crtc_vblank_int[1]) {
  4629. drm_handle_vblank(rdev->ddev, 1);
  4630. rdev->pm.vblank_sync = true;
  4631. wake_up(&rdev->irq.vblank_queue);
  4632. }
  4633. if (atomic_read(&rdev->irq.pflip[1]))
  4634. radeon_crtc_handle_flip(rdev, 1);
  4635. rdev->irq.stat_regs.evergreen.disp_int_cont &= ~LB_D2_VBLANK_INTERRUPT;
  4636. DRM_DEBUG("IH: D2 vblank\n");
  4637. }
  4638. break;
  4639. case 1: /* D2 vline */
  4640. if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VLINE_INTERRUPT) {
  4641. rdev->irq.stat_regs.evergreen.disp_int_cont &= ~LB_D2_VLINE_INTERRUPT;
  4642. DRM_DEBUG("IH: D2 vline\n");
  4643. }
  4644. break;
  4645. default:
  4646. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4647. break;
  4648. }
  4649. break;
  4650. case 3: /* D3 vblank/vline */
  4651. switch (src_data) {
  4652. case 0: /* D3 vblank */
  4653. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VBLANK_INTERRUPT) {
  4654. if (rdev->irq.crtc_vblank_int[2]) {
  4655. drm_handle_vblank(rdev->ddev, 2);
  4656. rdev->pm.vblank_sync = true;
  4657. wake_up(&rdev->irq.vblank_queue);
  4658. }
  4659. if (atomic_read(&rdev->irq.pflip[2]))
  4660. radeon_crtc_handle_flip(rdev, 2);
  4661. rdev->irq.stat_regs.evergreen.disp_int_cont2 &= ~LB_D3_VBLANK_INTERRUPT;
  4662. DRM_DEBUG("IH: D3 vblank\n");
  4663. }
  4664. break;
  4665. case 1: /* D3 vline */
  4666. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VLINE_INTERRUPT) {
  4667. rdev->irq.stat_regs.evergreen.disp_int_cont2 &= ~LB_D3_VLINE_INTERRUPT;
  4668. DRM_DEBUG("IH: D3 vline\n");
  4669. }
  4670. break;
  4671. default:
  4672. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4673. break;
  4674. }
  4675. break;
  4676. case 4: /* D4 vblank/vline */
  4677. switch (src_data) {
  4678. case 0: /* D4 vblank */
  4679. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VBLANK_INTERRUPT) {
  4680. if (rdev->irq.crtc_vblank_int[3]) {
  4681. drm_handle_vblank(rdev->ddev, 3);
  4682. rdev->pm.vblank_sync = true;
  4683. wake_up(&rdev->irq.vblank_queue);
  4684. }
  4685. if (atomic_read(&rdev->irq.pflip[3]))
  4686. radeon_crtc_handle_flip(rdev, 3);
  4687. rdev->irq.stat_regs.evergreen.disp_int_cont3 &= ~LB_D4_VBLANK_INTERRUPT;
  4688. DRM_DEBUG("IH: D4 vblank\n");
  4689. }
  4690. break;
  4691. case 1: /* D4 vline */
  4692. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VLINE_INTERRUPT) {
  4693. rdev->irq.stat_regs.evergreen.disp_int_cont3 &= ~LB_D4_VLINE_INTERRUPT;
  4694. DRM_DEBUG("IH: D4 vline\n");
  4695. }
  4696. break;
  4697. default:
  4698. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4699. break;
  4700. }
  4701. break;
  4702. case 5: /* D5 vblank/vline */
  4703. switch (src_data) {
  4704. case 0: /* D5 vblank */
  4705. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VBLANK_INTERRUPT) {
  4706. if (rdev->irq.crtc_vblank_int[4]) {
  4707. drm_handle_vblank(rdev->ddev, 4);
  4708. rdev->pm.vblank_sync = true;
  4709. wake_up(&rdev->irq.vblank_queue);
  4710. }
  4711. if (atomic_read(&rdev->irq.pflip[4]))
  4712. radeon_crtc_handle_flip(rdev, 4);
  4713. rdev->irq.stat_regs.evergreen.disp_int_cont4 &= ~LB_D5_VBLANK_INTERRUPT;
  4714. DRM_DEBUG("IH: D5 vblank\n");
  4715. }
  4716. break;
  4717. case 1: /* D5 vline */
  4718. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VLINE_INTERRUPT) {
  4719. rdev->irq.stat_regs.evergreen.disp_int_cont4 &= ~LB_D5_VLINE_INTERRUPT;
  4720. DRM_DEBUG("IH: D5 vline\n");
  4721. }
  4722. break;
  4723. default:
  4724. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4725. break;
  4726. }
  4727. break;
  4728. case 6: /* D6 vblank/vline */
  4729. switch (src_data) {
  4730. case 0: /* D6 vblank */
  4731. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VBLANK_INTERRUPT) {
  4732. if (rdev->irq.crtc_vblank_int[5]) {
  4733. drm_handle_vblank(rdev->ddev, 5);
  4734. rdev->pm.vblank_sync = true;
  4735. wake_up(&rdev->irq.vblank_queue);
  4736. }
  4737. if (atomic_read(&rdev->irq.pflip[5]))
  4738. radeon_crtc_handle_flip(rdev, 5);
  4739. rdev->irq.stat_regs.evergreen.disp_int_cont5 &= ~LB_D6_VBLANK_INTERRUPT;
  4740. DRM_DEBUG("IH: D6 vblank\n");
  4741. }
  4742. break;
  4743. case 1: /* D6 vline */
  4744. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VLINE_INTERRUPT) {
  4745. rdev->irq.stat_regs.evergreen.disp_int_cont5 &= ~LB_D6_VLINE_INTERRUPT;
  4746. DRM_DEBUG("IH: D6 vline\n");
  4747. }
  4748. break;
  4749. default:
  4750. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4751. break;
  4752. }
  4753. break;
  4754. case 42: /* HPD hotplug */
  4755. switch (src_data) {
  4756. case 0:
  4757. if (rdev->irq.stat_regs.evergreen.disp_int & DC_HPD1_INTERRUPT) {
  4758. rdev->irq.stat_regs.evergreen.disp_int &= ~DC_HPD1_INTERRUPT;
  4759. queue_hotplug = true;
  4760. DRM_DEBUG("IH: HPD1\n");
  4761. }
  4762. break;
  4763. case 1:
  4764. if (rdev->irq.stat_regs.evergreen.disp_int_cont & DC_HPD2_INTERRUPT) {
  4765. rdev->irq.stat_regs.evergreen.disp_int_cont &= ~DC_HPD2_INTERRUPT;
  4766. queue_hotplug = true;
  4767. DRM_DEBUG("IH: HPD2\n");
  4768. }
  4769. break;
  4770. case 2:
  4771. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & DC_HPD3_INTERRUPT) {
  4772. rdev->irq.stat_regs.evergreen.disp_int_cont2 &= ~DC_HPD3_INTERRUPT;
  4773. queue_hotplug = true;
  4774. DRM_DEBUG("IH: HPD3\n");
  4775. }
  4776. break;
  4777. case 3:
  4778. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & DC_HPD4_INTERRUPT) {
  4779. rdev->irq.stat_regs.evergreen.disp_int_cont3 &= ~DC_HPD4_INTERRUPT;
  4780. queue_hotplug = true;
  4781. DRM_DEBUG("IH: HPD4\n");
  4782. }
  4783. break;
  4784. case 4:
  4785. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & DC_HPD5_INTERRUPT) {
  4786. rdev->irq.stat_regs.evergreen.disp_int_cont4 &= ~DC_HPD5_INTERRUPT;
  4787. queue_hotplug = true;
  4788. DRM_DEBUG("IH: HPD5\n");
  4789. }
  4790. break;
  4791. case 5:
  4792. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & DC_HPD6_INTERRUPT) {
  4793. rdev->irq.stat_regs.evergreen.disp_int_cont5 &= ~DC_HPD6_INTERRUPT;
  4794. queue_hotplug = true;
  4795. DRM_DEBUG("IH: HPD6\n");
  4796. }
  4797. break;
  4798. default:
  4799. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4800. break;
  4801. }
  4802. break;
  4803. case 146:
  4804. case 147:
  4805. dev_err(rdev->dev, "GPU fault detected: %d 0x%08x\n", src_id, src_data);
  4806. dev_err(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_ADDR 0x%08X\n",
  4807. RREG32(VM_CONTEXT1_PROTECTION_FAULT_ADDR));
  4808. dev_err(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_STATUS 0x%08X\n",
  4809. RREG32(VM_CONTEXT1_PROTECTION_FAULT_STATUS));
  4810. /* reset addr and status */
  4811. WREG32_P(VM_CONTEXT1_CNTL2, 1, ~1);
  4812. break;
  4813. case 176: /* RINGID0 CP_INT */
  4814. radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
  4815. break;
  4816. case 177: /* RINGID1 CP_INT */
  4817. radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP1_INDEX);
  4818. break;
  4819. case 178: /* RINGID2 CP_INT */
  4820. radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP2_INDEX);
  4821. break;
  4822. case 181: /* CP EOP event */
  4823. DRM_DEBUG("IH: CP EOP\n");
  4824. switch (ring_id) {
  4825. case 0:
  4826. radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
  4827. break;
  4828. case 1:
  4829. radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP1_INDEX);
  4830. break;
  4831. case 2:
  4832. radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP2_INDEX);
  4833. break;
  4834. }
  4835. break;
  4836. case 224: /* DMA trap event */
  4837. DRM_DEBUG("IH: DMA trap\n");
  4838. radeon_fence_process(rdev, R600_RING_TYPE_DMA_INDEX);
  4839. break;
  4840. case 233: /* GUI IDLE */
  4841. DRM_DEBUG("IH: GUI idle\n");
  4842. break;
  4843. case 244: /* DMA trap event */
  4844. DRM_DEBUG("IH: DMA1 trap\n");
  4845. radeon_fence_process(rdev, CAYMAN_RING_TYPE_DMA1_INDEX);
  4846. break;
  4847. default:
  4848. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4849. break;
  4850. }
  4851. /* wptr/rptr are in bytes! */
  4852. rptr += 16;
  4853. rptr &= rdev->ih.ptr_mask;
  4854. }
  4855. if (queue_hotplug)
  4856. schedule_work(&rdev->hotplug_work);
  4857. rdev->ih.rptr = rptr;
  4858. WREG32(IH_RB_RPTR, rdev->ih.rptr);
  4859. atomic_set(&rdev->ih.lock, 0);
  4860. /* make sure wptr hasn't changed while processing */
  4861. wptr = si_get_ih_wptr(rdev);
  4862. if (wptr != rptr)
  4863. goto restart_ih;
  4864. return IRQ_HANDLED;
  4865. }
  4866. /**
  4867. * si_copy_dma - copy pages using the DMA engine
  4868. *
  4869. * @rdev: radeon_device pointer
  4870. * @src_offset: src GPU address
  4871. * @dst_offset: dst GPU address
  4872. * @num_gpu_pages: number of GPU pages to xfer
  4873. * @fence: radeon fence object
  4874. *
  4875. * Copy GPU paging using the DMA engine (SI).
  4876. * Used by the radeon ttm implementation to move pages if
  4877. * registered as the asic copy callback.
  4878. */
  4879. int si_copy_dma(struct radeon_device *rdev,
  4880. uint64_t src_offset, uint64_t dst_offset,
  4881. unsigned num_gpu_pages,
  4882. struct radeon_fence **fence)
  4883. {
  4884. struct radeon_semaphore *sem = NULL;
  4885. int ring_index = rdev->asic->copy.dma_ring_index;
  4886. struct radeon_ring *ring = &rdev->ring[ring_index];
  4887. u32 size_in_bytes, cur_size_in_bytes;
  4888. int i, num_loops;
  4889. int r = 0;
  4890. r = radeon_semaphore_create(rdev, &sem);
  4891. if (r) {
  4892. DRM_ERROR("radeon: moving bo (%d).\n", r);
  4893. return r;
  4894. }
  4895. size_in_bytes = (num_gpu_pages << RADEON_GPU_PAGE_SHIFT);
  4896. num_loops = DIV_ROUND_UP(size_in_bytes, 0xfffff);
  4897. r = radeon_ring_lock(rdev, ring, num_loops * 5 + 11);
  4898. if (r) {
  4899. DRM_ERROR("radeon: moving bo (%d).\n", r);
  4900. radeon_semaphore_free(rdev, &sem, NULL);
  4901. return r;
  4902. }
  4903. if (radeon_fence_need_sync(*fence, ring->idx)) {
  4904. radeon_semaphore_sync_rings(rdev, sem, (*fence)->ring,
  4905. ring->idx);
  4906. radeon_fence_note_sync(*fence, ring->idx);
  4907. } else {
  4908. radeon_semaphore_free(rdev, &sem, NULL);
  4909. }
  4910. for (i = 0; i < num_loops; i++) {
  4911. cur_size_in_bytes = size_in_bytes;
  4912. if (cur_size_in_bytes > 0xFFFFF)
  4913. cur_size_in_bytes = 0xFFFFF;
  4914. size_in_bytes -= cur_size_in_bytes;
  4915. radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_COPY, 1, 0, 0, cur_size_in_bytes));
  4916. radeon_ring_write(ring, dst_offset & 0xffffffff);
  4917. radeon_ring_write(ring, src_offset & 0xffffffff);
  4918. radeon_ring_write(ring, upper_32_bits(dst_offset) & 0xff);
  4919. radeon_ring_write(ring, upper_32_bits(src_offset) & 0xff);
  4920. src_offset += cur_size_in_bytes;
  4921. dst_offset += cur_size_in_bytes;
  4922. }
  4923. r = radeon_fence_emit(rdev, fence, ring->idx);
  4924. if (r) {
  4925. radeon_ring_unlock_undo(rdev, ring);
  4926. return r;
  4927. }
  4928. radeon_ring_unlock_commit(rdev, ring);
  4929. radeon_semaphore_free(rdev, &sem, *fence);
  4930. return r;
  4931. }
  4932. /*
  4933. * startup/shutdown callbacks
  4934. */
  4935. static int si_startup(struct radeon_device *rdev)
  4936. {
  4937. struct radeon_ring *ring;
  4938. int r;
  4939. /* enable pcie gen2/3 link */
  4940. si_pcie_gen3_enable(rdev);
  4941. /* enable aspm */
  4942. si_program_aspm(rdev);
  4943. if (!rdev->me_fw || !rdev->pfp_fw || !rdev->ce_fw ||
  4944. !rdev->rlc_fw || !rdev->mc_fw) {
  4945. r = si_init_microcode(rdev);
  4946. if (r) {
  4947. DRM_ERROR("Failed to load firmware!\n");
  4948. return r;
  4949. }
  4950. }
  4951. r = si_mc_load_microcode(rdev);
  4952. if (r) {
  4953. DRM_ERROR("Failed to load MC firmware!\n");
  4954. return r;
  4955. }
  4956. r = r600_vram_scratch_init(rdev);
  4957. if (r)
  4958. return r;
  4959. si_mc_program(rdev);
  4960. r = si_pcie_gart_enable(rdev);
  4961. if (r)
  4962. return r;
  4963. si_gpu_init(rdev);
  4964. /* allocate rlc buffers */
  4965. r = si_rlc_init(rdev);
  4966. if (r) {
  4967. DRM_ERROR("Failed to init rlc BOs!\n");
  4968. return r;
  4969. }
  4970. /* allocate wb buffer */
  4971. r = radeon_wb_init(rdev);
  4972. if (r)
  4973. return r;
  4974. r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX);
  4975. if (r) {
  4976. dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
  4977. return r;
  4978. }
  4979. r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_CP1_INDEX);
  4980. if (r) {
  4981. dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
  4982. return r;
  4983. }
  4984. r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_CP2_INDEX);
  4985. if (r) {
  4986. dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
  4987. return r;
  4988. }
  4989. r = radeon_fence_driver_start_ring(rdev, R600_RING_TYPE_DMA_INDEX);
  4990. if (r) {
  4991. dev_err(rdev->dev, "failed initializing DMA fences (%d).\n", r);
  4992. return r;
  4993. }
  4994. r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_DMA1_INDEX);
  4995. if (r) {
  4996. dev_err(rdev->dev, "failed initializing DMA fences (%d).\n", r);
  4997. return r;
  4998. }
  4999. if (rdev->has_uvd) {
  5000. r = rv770_uvd_resume(rdev);
  5001. if (!r) {
  5002. r = radeon_fence_driver_start_ring(rdev,
  5003. R600_RING_TYPE_UVD_INDEX);
  5004. if (r)
  5005. dev_err(rdev->dev, "UVD fences init error (%d).\n", r);
  5006. }
  5007. if (r)
  5008. rdev->ring[R600_RING_TYPE_UVD_INDEX].ring_size = 0;
  5009. }
  5010. /* Enable IRQ */
  5011. if (!rdev->irq.installed) {
  5012. r = radeon_irq_kms_init(rdev);
  5013. if (r)
  5014. return r;
  5015. }
  5016. r = si_irq_init(rdev);
  5017. if (r) {
  5018. DRM_ERROR("radeon: IH init failed (%d).\n", r);
  5019. radeon_irq_kms_fini(rdev);
  5020. return r;
  5021. }
  5022. si_irq_set(rdev);
  5023. ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  5024. r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP_RPTR_OFFSET,
  5025. CP_RB0_RPTR, CP_RB0_WPTR,
  5026. 0, 0xfffff, RADEON_CP_PACKET2);
  5027. if (r)
  5028. return r;
  5029. ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
  5030. r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP1_RPTR_OFFSET,
  5031. CP_RB1_RPTR, CP_RB1_WPTR,
  5032. 0, 0xfffff, RADEON_CP_PACKET2);
  5033. if (r)
  5034. return r;
  5035. ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
  5036. r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP2_RPTR_OFFSET,
  5037. CP_RB2_RPTR, CP_RB2_WPTR,
  5038. 0, 0xfffff, RADEON_CP_PACKET2);
  5039. if (r)
  5040. return r;
  5041. ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
  5042. r = radeon_ring_init(rdev, ring, ring->ring_size, R600_WB_DMA_RPTR_OFFSET,
  5043. DMA_RB_RPTR + DMA0_REGISTER_OFFSET,
  5044. DMA_RB_WPTR + DMA0_REGISTER_OFFSET,
  5045. 2, 0x3fffc, DMA_PACKET(DMA_PACKET_NOP, 0, 0, 0, 0));
  5046. if (r)
  5047. return r;
  5048. ring = &rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX];
  5049. r = radeon_ring_init(rdev, ring, ring->ring_size, CAYMAN_WB_DMA1_RPTR_OFFSET,
  5050. DMA_RB_RPTR + DMA1_REGISTER_OFFSET,
  5051. DMA_RB_WPTR + DMA1_REGISTER_OFFSET,
  5052. 2, 0x3fffc, DMA_PACKET(DMA_PACKET_NOP, 0, 0, 0, 0));
  5053. if (r)
  5054. return r;
  5055. r = si_cp_load_microcode(rdev);
  5056. if (r)
  5057. return r;
  5058. r = si_cp_resume(rdev);
  5059. if (r)
  5060. return r;
  5061. r = cayman_dma_resume(rdev);
  5062. if (r)
  5063. return r;
  5064. if (rdev->has_uvd) {
  5065. ring = &rdev->ring[R600_RING_TYPE_UVD_INDEX];
  5066. if (ring->ring_size) {
  5067. r = radeon_ring_init(rdev, ring, ring->ring_size,
  5068. R600_WB_UVD_RPTR_OFFSET,
  5069. UVD_RBC_RB_RPTR, UVD_RBC_RB_WPTR,
  5070. 0, 0xfffff, RADEON_CP_PACKET2);
  5071. if (!r)
  5072. r = r600_uvd_init(rdev);
  5073. if (r)
  5074. DRM_ERROR("radeon: failed initializing UVD (%d).\n", r);
  5075. }
  5076. }
  5077. r = radeon_ib_pool_init(rdev);
  5078. if (r) {
  5079. dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
  5080. return r;
  5081. }
  5082. r = radeon_vm_manager_init(rdev);
  5083. if (r) {
  5084. dev_err(rdev->dev, "vm manager initialization failed (%d).\n", r);
  5085. return r;
  5086. }
  5087. return 0;
  5088. }
  5089. int si_resume(struct radeon_device *rdev)
  5090. {
  5091. int r;
  5092. /* Do not reset GPU before posting, on rv770 hw unlike on r500 hw,
  5093. * posting will perform necessary task to bring back GPU into good
  5094. * shape.
  5095. */
  5096. /* post card */
  5097. atom_asic_init(rdev->mode_info.atom_context);
  5098. /* init golden registers */
  5099. si_init_golden_registers(rdev);
  5100. rdev->accel_working = true;
  5101. r = si_startup(rdev);
  5102. if (r) {
  5103. DRM_ERROR("si startup failed on resume\n");
  5104. rdev->accel_working = false;
  5105. return r;
  5106. }
  5107. return r;
  5108. }
  5109. int si_suspend(struct radeon_device *rdev)
  5110. {
  5111. radeon_vm_manager_fini(rdev);
  5112. si_cp_enable(rdev, false);
  5113. cayman_dma_stop(rdev);
  5114. if (rdev->has_uvd) {
  5115. r600_uvd_rbc_stop(rdev);
  5116. radeon_uvd_suspend(rdev);
  5117. }
  5118. si_irq_suspend(rdev);
  5119. radeon_wb_disable(rdev);
  5120. si_pcie_gart_disable(rdev);
  5121. return 0;
  5122. }
  5123. /* Plan is to move initialization in that function and use
  5124. * helper function so that radeon_device_init pretty much
  5125. * do nothing more than calling asic specific function. This
  5126. * should also allow to remove a bunch of callback function
  5127. * like vram_info.
  5128. */
  5129. int si_init(struct radeon_device *rdev)
  5130. {
  5131. struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  5132. int r;
  5133. /* Read BIOS */
  5134. if (!radeon_get_bios(rdev)) {
  5135. if (ASIC_IS_AVIVO(rdev))
  5136. return -EINVAL;
  5137. }
  5138. /* Must be an ATOMBIOS */
  5139. if (!rdev->is_atom_bios) {
  5140. dev_err(rdev->dev, "Expecting atombios for cayman GPU\n");
  5141. return -EINVAL;
  5142. }
  5143. r = radeon_atombios_init(rdev);
  5144. if (r)
  5145. return r;
  5146. /* Post card if necessary */
  5147. if (!radeon_card_posted(rdev)) {
  5148. if (!rdev->bios) {
  5149. dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n");
  5150. return -EINVAL;
  5151. }
  5152. DRM_INFO("GPU not posted. posting now...\n");
  5153. atom_asic_init(rdev->mode_info.atom_context);
  5154. }
  5155. /* init golden registers */
  5156. si_init_golden_registers(rdev);
  5157. /* Initialize scratch registers */
  5158. si_scratch_init(rdev);
  5159. /* Initialize surface registers */
  5160. radeon_surface_init(rdev);
  5161. /* Initialize clocks */
  5162. radeon_get_clock_info(rdev->ddev);
  5163. /* Fence driver */
  5164. r = radeon_fence_driver_init(rdev);
  5165. if (r)
  5166. return r;
  5167. /* initialize memory controller */
  5168. r = si_mc_init(rdev);
  5169. if (r)
  5170. return r;
  5171. /* Memory manager */
  5172. r = radeon_bo_init(rdev);
  5173. if (r)
  5174. return r;
  5175. ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  5176. ring->ring_obj = NULL;
  5177. r600_ring_init(rdev, ring, 1024 * 1024);
  5178. ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
  5179. ring->ring_obj = NULL;
  5180. r600_ring_init(rdev, ring, 1024 * 1024);
  5181. ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
  5182. ring->ring_obj = NULL;
  5183. r600_ring_init(rdev, ring, 1024 * 1024);
  5184. ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
  5185. ring->ring_obj = NULL;
  5186. r600_ring_init(rdev, ring, 64 * 1024);
  5187. ring = &rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX];
  5188. ring->ring_obj = NULL;
  5189. r600_ring_init(rdev, ring, 64 * 1024);
  5190. if (rdev->has_uvd) {
  5191. r = radeon_uvd_init(rdev);
  5192. if (!r) {
  5193. ring = &rdev->ring[R600_RING_TYPE_UVD_INDEX];
  5194. ring->ring_obj = NULL;
  5195. r600_ring_init(rdev, ring, 4096);
  5196. }
  5197. }
  5198. rdev->ih.ring_obj = NULL;
  5199. r600_ih_ring_init(rdev, 64 * 1024);
  5200. r = r600_pcie_gart_init(rdev);
  5201. if (r)
  5202. return r;
  5203. rdev->accel_working = true;
  5204. r = si_startup(rdev);
  5205. if (r) {
  5206. dev_err(rdev->dev, "disabling GPU acceleration\n");
  5207. si_cp_fini(rdev);
  5208. cayman_dma_fini(rdev);
  5209. si_irq_fini(rdev);
  5210. si_rlc_fini(rdev);
  5211. radeon_wb_fini(rdev);
  5212. radeon_ib_pool_fini(rdev);
  5213. radeon_vm_manager_fini(rdev);
  5214. radeon_irq_kms_fini(rdev);
  5215. si_pcie_gart_fini(rdev);
  5216. rdev->accel_working = false;
  5217. }
  5218. /* Don't start up if the MC ucode is missing.
  5219. * The default clocks and voltages before the MC ucode
  5220. * is loaded are not suffient for advanced operations.
  5221. */
  5222. if (!rdev->mc_fw) {
  5223. DRM_ERROR("radeon: MC ucode required for NI+.\n");
  5224. return -EINVAL;
  5225. }
  5226. return 0;
  5227. }
  5228. void si_fini(struct radeon_device *rdev)
  5229. {
  5230. si_cp_fini(rdev);
  5231. cayman_dma_fini(rdev);
  5232. si_irq_fini(rdev);
  5233. si_rlc_fini(rdev);
  5234. radeon_wb_fini(rdev);
  5235. radeon_vm_manager_fini(rdev);
  5236. radeon_ib_pool_fini(rdev);
  5237. radeon_irq_kms_fini(rdev);
  5238. if (rdev->has_uvd)
  5239. radeon_uvd_fini(rdev);
  5240. si_pcie_gart_fini(rdev);
  5241. r600_vram_scratch_fini(rdev);
  5242. radeon_gem_fini(rdev);
  5243. radeon_fence_driver_fini(rdev);
  5244. radeon_bo_fini(rdev);
  5245. radeon_atombios_fini(rdev);
  5246. kfree(rdev->bios);
  5247. rdev->bios = NULL;
  5248. }
  5249. /**
  5250. * si_get_gpu_clock_counter - return GPU clock counter snapshot
  5251. *
  5252. * @rdev: radeon_device pointer
  5253. *
  5254. * Fetches a GPU clock counter snapshot (SI).
  5255. * Returns the 64 bit clock counter snapshot.
  5256. */
  5257. uint64_t si_get_gpu_clock_counter(struct radeon_device *rdev)
  5258. {
  5259. uint64_t clock;
  5260. mutex_lock(&rdev->gpu_clock_mutex);
  5261. WREG32(RLC_CAPTURE_GPU_CLOCK_COUNT, 1);
  5262. clock = (uint64_t)RREG32(RLC_GPU_CLOCK_COUNT_LSB) |
  5263. ((uint64_t)RREG32(RLC_GPU_CLOCK_COUNT_MSB) << 32ULL);
  5264. mutex_unlock(&rdev->gpu_clock_mutex);
  5265. return clock;
  5266. }
  5267. int si_set_uvd_clocks(struct radeon_device *rdev, u32 vclk, u32 dclk)
  5268. {
  5269. unsigned fb_div = 0, vclk_div = 0, dclk_div = 0;
  5270. int r;
  5271. /* bypass vclk and dclk with bclk */
  5272. WREG32_P(CG_UPLL_FUNC_CNTL_2,
  5273. VCLK_SRC_SEL(1) | DCLK_SRC_SEL(1),
  5274. ~(VCLK_SRC_SEL_MASK | DCLK_SRC_SEL_MASK));
  5275. /* put PLL in bypass mode */
  5276. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_BYPASS_EN_MASK, ~UPLL_BYPASS_EN_MASK);
  5277. if (!vclk || !dclk) {
  5278. /* keep the Bypass mode, put PLL to sleep */
  5279. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_SLEEP_MASK, ~UPLL_SLEEP_MASK);
  5280. return 0;
  5281. }
  5282. r = radeon_uvd_calc_upll_dividers(rdev, vclk, dclk, 125000, 250000,
  5283. 16384, 0x03FFFFFF, 0, 128, 5,
  5284. &fb_div, &vclk_div, &dclk_div);
  5285. if (r)
  5286. return r;
  5287. /* set RESET_ANTI_MUX to 0 */
  5288. WREG32_P(CG_UPLL_FUNC_CNTL_5, 0, ~RESET_ANTI_MUX_MASK);
  5289. /* set VCO_MODE to 1 */
  5290. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_VCO_MODE_MASK, ~UPLL_VCO_MODE_MASK);
  5291. /* toggle UPLL_SLEEP to 1 then back to 0 */
  5292. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_SLEEP_MASK, ~UPLL_SLEEP_MASK);
  5293. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_SLEEP_MASK);
  5294. /* deassert UPLL_RESET */
  5295. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_RESET_MASK);
  5296. mdelay(1);
  5297. r = radeon_uvd_send_upll_ctlreq(rdev, CG_UPLL_FUNC_CNTL);
  5298. if (r)
  5299. return r;
  5300. /* assert UPLL_RESET again */
  5301. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_RESET_MASK, ~UPLL_RESET_MASK);
  5302. /* disable spread spectrum. */
  5303. WREG32_P(CG_UPLL_SPREAD_SPECTRUM, 0, ~SSEN_MASK);
  5304. /* set feedback divider */
  5305. WREG32_P(CG_UPLL_FUNC_CNTL_3, UPLL_FB_DIV(fb_div), ~UPLL_FB_DIV_MASK);
  5306. /* set ref divider to 0 */
  5307. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_REF_DIV_MASK);
  5308. if (fb_div < 307200)
  5309. WREG32_P(CG_UPLL_FUNC_CNTL_4, 0, ~UPLL_SPARE_ISPARE9);
  5310. else
  5311. WREG32_P(CG_UPLL_FUNC_CNTL_4, UPLL_SPARE_ISPARE9, ~UPLL_SPARE_ISPARE9);
  5312. /* set PDIV_A and PDIV_B */
  5313. WREG32_P(CG_UPLL_FUNC_CNTL_2,
  5314. UPLL_PDIV_A(vclk_div) | UPLL_PDIV_B(dclk_div),
  5315. ~(UPLL_PDIV_A_MASK | UPLL_PDIV_B_MASK));
  5316. /* give the PLL some time to settle */
  5317. mdelay(15);
  5318. /* deassert PLL_RESET */
  5319. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_RESET_MASK);
  5320. mdelay(15);
  5321. /* switch from bypass mode to normal mode */
  5322. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_BYPASS_EN_MASK);
  5323. r = radeon_uvd_send_upll_ctlreq(rdev, CG_UPLL_FUNC_CNTL);
  5324. if (r)
  5325. return r;
  5326. /* switch VCLK and DCLK selection */
  5327. WREG32_P(CG_UPLL_FUNC_CNTL_2,
  5328. VCLK_SRC_SEL(2) | DCLK_SRC_SEL(2),
  5329. ~(VCLK_SRC_SEL_MASK | DCLK_SRC_SEL_MASK));
  5330. mdelay(100);
  5331. return 0;
  5332. }
  5333. static void si_pcie_gen3_enable(struct radeon_device *rdev)
  5334. {
  5335. struct pci_dev *root = rdev->pdev->bus->self;
  5336. int bridge_pos, gpu_pos;
  5337. u32 speed_cntl, mask, current_data_rate;
  5338. int ret, i;
  5339. u16 tmp16;
  5340. if (radeon_pcie_gen2 == 0)
  5341. return;
  5342. if (rdev->flags & RADEON_IS_IGP)
  5343. return;
  5344. if (!(rdev->flags & RADEON_IS_PCIE))
  5345. return;
  5346. ret = drm_pcie_get_speed_cap_mask(rdev->ddev, &mask);
  5347. if (ret != 0)
  5348. return;
  5349. if (!(mask & (DRM_PCIE_SPEED_50 | DRM_PCIE_SPEED_80)))
  5350. return;
  5351. speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  5352. current_data_rate = (speed_cntl & LC_CURRENT_DATA_RATE_MASK) >>
  5353. LC_CURRENT_DATA_RATE_SHIFT;
  5354. if (mask & DRM_PCIE_SPEED_80) {
  5355. if (current_data_rate == 2) {
  5356. DRM_INFO("PCIE gen 3 link speeds already enabled\n");
  5357. return;
  5358. }
  5359. DRM_INFO("enabling PCIE gen 3 link speeds, disable with radeon.pcie_gen2=0\n");
  5360. } else if (mask & DRM_PCIE_SPEED_50) {
  5361. if (current_data_rate == 1) {
  5362. DRM_INFO("PCIE gen 2 link speeds already enabled\n");
  5363. return;
  5364. }
  5365. DRM_INFO("enabling PCIE gen 2 link speeds, disable with radeon.pcie_gen2=0\n");
  5366. }
  5367. bridge_pos = pci_pcie_cap(root);
  5368. if (!bridge_pos)
  5369. return;
  5370. gpu_pos = pci_pcie_cap(rdev->pdev);
  5371. if (!gpu_pos)
  5372. return;
  5373. if (mask & DRM_PCIE_SPEED_80) {
  5374. /* re-try equalization if gen3 is not already enabled */
  5375. if (current_data_rate != 2) {
  5376. u16 bridge_cfg, gpu_cfg;
  5377. u16 bridge_cfg2, gpu_cfg2;
  5378. u32 max_lw, current_lw, tmp;
  5379. pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL, &bridge_cfg);
  5380. pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, &gpu_cfg);
  5381. tmp16 = bridge_cfg | PCI_EXP_LNKCTL_HAWD;
  5382. pci_write_config_word(root, bridge_pos + PCI_EXP_LNKCTL, tmp16);
  5383. tmp16 = gpu_cfg | PCI_EXP_LNKCTL_HAWD;
  5384. pci_write_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, tmp16);
  5385. tmp = RREG32_PCIE(PCIE_LC_STATUS1);
  5386. max_lw = (tmp & LC_DETECTED_LINK_WIDTH_MASK) >> LC_DETECTED_LINK_WIDTH_SHIFT;
  5387. current_lw = (tmp & LC_OPERATING_LINK_WIDTH_MASK) >> LC_OPERATING_LINK_WIDTH_SHIFT;
  5388. if (current_lw < max_lw) {
  5389. tmp = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
  5390. if (tmp & LC_RENEGOTIATION_SUPPORT) {
  5391. tmp &= ~(LC_LINK_WIDTH_MASK | LC_UPCONFIGURE_DIS);
  5392. tmp |= (max_lw << LC_LINK_WIDTH_SHIFT);
  5393. tmp |= LC_UPCONFIGURE_SUPPORT | LC_RENEGOTIATE_EN | LC_RECONFIG_NOW;
  5394. WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, tmp);
  5395. }
  5396. }
  5397. for (i = 0; i < 10; i++) {
  5398. /* check status */
  5399. pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_DEVSTA, &tmp16);
  5400. if (tmp16 & PCI_EXP_DEVSTA_TRPND)
  5401. break;
  5402. pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL, &bridge_cfg);
  5403. pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, &gpu_cfg);
  5404. pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL2, &bridge_cfg2);
  5405. pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, &gpu_cfg2);
  5406. tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL4);
  5407. tmp |= LC_SET_QUIESCE;
  5408. WREG32_PCIE_PORT(PCIE_LC_CNTL4, tmp);
  5409. tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL4);
  5410. tmp |= LC_REDO_EQ;
  5411. WREG32_PCIE_PORT(PCIE_LC_CNTL4, tmp);
  5412. mdelay(100);
  5413. /* linkctl */
  5414. pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL, &tmp16);
  5415. tmp16 &= ~PCI_EXP_LNKCTL_HAWD;
  5416. tmp16 |= (bridge_cfg & PCI_EXP_LNKCTL_HAWD);
  5417. pci_write_config_word(root, bridge_pos + PCI_EXP_LNKCTL, tmp16);
  5418. pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, &tmp16);
  5419. tmp16 &= ~PCI_EXP_LNKCTL_HAWD;
  5420. tmp16 |= (gpu_cfg & PCI_EXP_LNKCTL_HAWD);
  5421. pci_write_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, tmp16);
  5422. /* linkctl2 */
  5423. pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL2, &tmp16);
  5424. tmp16 &= ~((1 << 4) | (7 << 9));
  5425. tmp16 |= (bridge_cfg2 & ((1 << 4) | (7 << 9)));
  5426. pci_write_config_word(root, bridge_pos + PCI_EXP_LNKCTL2, tmp16);
  5427. pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, &tmp16);
  5428. tmp16 &= ~((1 << 4) | (7 << 9));
  5429. tmp16 |= (gpu_cfg2 & ((1 << 4) | (7 << 9)));
  5430. pci_write_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, tmp16);
  5431. tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL4);
  5432. tmp &= ~LC_SET_QUIESCE;
  5433. WREG32_PCIE_PORT(PCIE_LC_CNTL4, tmp);
  5434. }
  5435. }
  5436. }
  5437. /* set the link speed */
  5438. speed_cntl |= LC_FORCE_EN_SW_SPEED_CHANGE | LC_FORCE_DIS_HW_SPEED_CHANGE;
  5439. speed_cntl &= ~LC_FORCE_DIS_SW_SPEED_CHANGE;
  5440. WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
  5441. pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, &tmp16);
  5442. tmp16 &= ~0xf;
  5443. if (mask & DRM_PCIE_SPEED_80)
  5444. tmp16 |= 3; /* gen3 */
  5445. else if (mask & DRM_PCIE_SPEED_50)
  5446. tmp16 |= 2; /* gen2 */
  5447. else
  5448. tmp16 |= 1; /* gen1 */
  5449. pci_write_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, tmp16);
  5450. speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  5451. speed_cntl |= LC_INITIATE_LINK_SPEED_CHANGE;
  5452. WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
  5453. for (i = 0; i < rdev->usec_timeout; i++) {
  5454. speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  5455. if ((speed_cntl & LC_INITIATE_LINK_SPEED_CHANGE) == 0)
  5456. break;
  5457. udelay(1);
  5458. }
  5459. }
  5460. static void si_program_aspm(struct radeon_device *rdev)
  5461. {
  5462. u32 data, orig;
  5463. bool disable_l0s = false, disable_l1 = false, disable_plloff_in_l1 = false;
  5464. bool disable_clkreq = false;
  5465. if (!(rdev->flags & RADEON_IS_PCIE))
  5466. return;
  5467. orig = data = RREG32_PCIE_PORT(PCIE_LC_N_FTS_CNTL);
  5468. data &= ~LC_XMIT_N_FTS_MASK;
  5469. data |= LC_XMIT_N_FTS(0x24) | LC_XMIT_N_FTS_OVERRIDE_EN;
  5470. if (orig != data)
  5471. WREG32_PCIE_PORT(PCIE_LC_N_FTS_CNTL, data);
  5472. orig = data = RREG32_PCIE_PORT(PCIE_LC_CNTL3);
  5473. data |= LC_GO_TO_RECOVERY;
  5474. if (orig != data)
  5475. WREG32_PCIE_PORT(PCIE_LC_CNTL3, data);
  5476. orig = data = RREG32_PCIE(PCIE_P_CNTL);
  5477. data |= P_IGNORE_EDB_ERR;
  5478. if (orig != data)
  5479. WREG32_PCIE(PCIE_P_CNTL, data);
  5480. orig = data = RREG32_PCIE_PORT(PCIE_LC_CNTL);
  5481. data &= ~(LC_L0S_INACTIVITY_MASK | LC_L1_INACTIVITY_MASK);
  5482. data |= LC_PMI_TO_L1_DIS;
  5483. if (!disable_l0s)
  5484. data |= LC_L0S_INACTIVITY(7);
  5485. if (!disable_l1) {
  5486. data |= LC_L1_INACTIVITY(7);
  5487. data &= ~LC_PMI_TO_L1_DIS;
  5488. if (orig != data)
  5489. WREG32_PCIE_PORT(PCIE_LC_CNTL, data);
  5490. if (!disable_plloff_in_l1) {
  5491. bool clk_req_support;
  5492. orig = data = RREG32_PIF_PHY0(PB0_PIF_PWRDOWN_0);
  5493. data &= ~(PLL_POWER_STATE_IN_OFF_0_MASK | PLL_POWER_STATE_IN_TXS2_0_MASK);
  5494. data |= PLL_POWER_STATE_IN_OFF_0(7) | PLL_POWER_STATE_IN_TXS2_0(7);
  5495. if (orig != data)
  5496. WREG32_PIF_PHY0(PB0_PIF_PWRDOWN_0, data);
  5497. orig = data = RREG32_PIF_PHY0(PB0_PIF_PWRDOWN_1);
  5498. data &= ~(PLL_POWER_STATE_IN_OFF_1_MASK | PLL_POWER_STATE_IN_TXS2_1_MASK);
  5499. data |= PLL_POWER_STATE_IN_OFF_1(7) | PLL_POWER_STATE_IN_TXS2_1(7);
  5500. if (orig != data)
  5501. WREG32_PIF_PHY0(PB0_PIF_PWRDOWN_1, data);
  5502. orig = data = RREG32_PIF_PHY1(PB1_PIF_PWRDOWN_0);
  5503. data &= ~(PLL_POWER_STATE_IN_OFF_0_MASK | PLL_POWER_STATE_IN_TXS2_0_MASK);
  5504. data |= PLL_POWER_STATE_IN_OFF_0(7) | PLL_POWER_STATE_IN_TXS2_0(7);
  5505. if (orig != data)
  5506. WREG32_PIF_PHY1(PB1_PIF_PWRDOWN_0, data);
  5507. orig = data = RREG32_PIF_PHY1(PB1_PIF_PWRDOWN_1);
  5508. data &= ~(PLL_POWER_STATE_IN_OFF_1_MASK | PLL_POWER_STATE_IN_TXS2_1_MASK);
  5509. data |= PLL_POWER_STATE_IN_OFF_1(7) | PLL_POWER_STATE_IN_TXS2_1(7);
  5510. if (orig != data)
  5511. WREG32_PIF_PHY1(PB1_PIF_PWRDOWN_1, data);
  5512. if ((rdev->family != CHIP_OLAND) && (rdev->family != CHIP_HAINAN)) {
  5513. orig = data = RREG32_PIF_PHY0(PB0_PIF_PWRDOWN_0);
  5514. data &= ~PLL_RAMP_UP_TIME_0_MASK;
  5515. if (orig != data)
  5516. WREG32_PIF_PHY0(PB0_PIF_PWRDOWN_0, data);
  5517. orig = data = RREG32_PIF_PHY0(PB0_PIF_PWRDOWN_1);
  5518. data &= ~PLL_RAMP_UP_TIME_1_MASK;
  5519. if (orig != data)
  5520. WREG32_PIF_PHY0(PB0_PIF_PWRDOWN_1, data);
  5521. orig = data = RREG32_PIF_PHY0(PB0_PIF_PWRDOWN_2);
  5522. data &= ~PLL_RAMP_UP_TIME_2_MASK;
  5523. if (orig != data)
  5524. WREG32_PIF_PHY0(PB0_PIF_PWRDOWN_2, data);
  5525. orig = data = RREG32_PIF_PHY0(PB0_PIF_PWRDOWN_3);
  5526. data &= ~PLL_RAMP_UP_TIME_3_MASK;
  5527. if (orig != data)
  5528. WREG32_PIF_PHY0(PB0_PIF_PWRDOWN_3, data);
  5529. orig = data = RREG32_PIF_PHY1(PB1_PIF_PWRDOWN_0);
  5530. data &= ~PLL_RAMP_UP_TIME_0_MASK;
  5531. if (orig != data)
  5532. WREG32_PIF_PHY1(PB1_PIF_PWRDOWN_0, data);
  5533. orig = data = RREG32_PIF_PHY1(PB1_PIF_PWRDOWN_1);
  5534. data &= ~PLL_RAMP_UP_TIME_1_MASK;
  5535. if (orig != data)
  5536. WREG32_PIF_PHY1(PB1_PIF_PWRDOWN_1, data);
  5537. orig = data = RREG32_PIF_PHY1(PB1_PIF_PWRDOWN_2);
  5538. data &= ~PLL_RAMP_UP_TIME_2_MASK;
  5539. if (orig != data)
  5540. WREG32_PIF_PHY1(PB1_PIF_PWRDOWN_2, data);
  5541. orig = data = RREG32_PIF_PHY1(PB1_PIF_PWRDOWN_3);
  5542. data &= ~PLL_RAMP_UP_TIME_3_MASK;
  5543. if (orig != data)
  5544. WREG32_PIF_PHY1(PB1_PIF_PWRDOWN_3, data);
  5545. }
  5546. orig = data = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
  5547. data &= ~LC_DYN_LANES_PWR_STATE_MASK;
  5548. data |= LC_DYN_LANES_PWR_STATE(3);
  5549. if (orig != data)
  5550. WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, data);
  5551. orig = data = RREG32_PIF_PHY0(PB0_PIF_CNTL);
  5552. data &= ~LS2_EXIT_TIME_MASK;
  5553. if ((rdev->family == CHIP_OLAND) || (rdev->family == CHIP_HAINAN))
  5554. data |= LS2_EXIT_TIME(5);
  5555. if (orig != data)
  5556. WREG32_PIF_PHY0(PB0_PIF_CNTL, data);
  5557. orig = data = RREG32_PIF_PHY1(PB1_PIF_CNTL);
  5558. data &= ~LS2_EXIT_TIME_MASK;
  5559. if ((rdev->family == CHIP_OLAND) || (rdev->family == CHIP_HAINAN))
  5560. data |= LS2_EXIT_TIME(5);
  5561. if (orig != data)
  5562. WREG32_PIF_PHY1(PB1_PIF_CNTL, data);
  5563. if (!disable_clkreq) {
  5564. struct pci_dev *root = rdev->pdev->bus->self;
  5565. u32 lnkcap;
  5566. clk_req_support = false;
  5567. pcie_capability_read_dword(root, PCI_EXP_LNKCAP, &lnkcap);
  5568. if (lnkcap & PCI_EXP_LNKCAP_CLKPM)
  5569. clk_req_support = true;
  5570. } else {
  5571. clk_req_support = false;
  5572. }
  5573. if (clk_req_support) {
  5574. orig = data = RREG32_PCIE_PORT(PCIE_LC_CNTL2);
  5575. data |= LC_ALLOW_PDWN_IN_L1 | LC_ALLOW_PDWN_IN_L23;
  5576. if (orig != data)
  5577. WREG32_PCIE_PORT(PCIE_LC_CNTL2, data);
  5578. orig = data = RREG32(THM_CLK_CNTL);
  5579. data &= ~(CMON_CLK_SEL_MASK | TMON_CLK_SEL_MASK);
  5580. data |= CMON_CLK_SEL(1) | TMON_CLK_SEL(1);
  5581. if (orig != data)
  5582. WREG32(THM_CLK_CNTL, data);
  5583. orig = data = RREG32(MISC_CLK_CNTL);
  5584. data &= ~(DEEP_SLEEP_CLK_SEL_MASK | ZCLK_SEL_MASK);
  5585. data |= DEEP_SLEEP_CLK_SEL(1) | ZCLK_SEL(1);
  5586. if (orig != data)
  5587. WREG32(MISC_CLK_CNTL, data);
  5588. orig = data = RREG32(CG_CLKPIN_CNTL);
  5589. data &= ~BCLK_AS_XCLK;
  5590. if (orig != data)
  5591. WREG32(CG_CLKPIN_CNTL, data);
  5592. orig = data = RREG32(CG_CLKPIN_CNTL_2);
  5593. data &= ~FORCE_BIF_REFCLK_EN;
  5594. if (orig != data)
  5595. WREG32(CG_CLKPIN_CNTL_2, data);
  5596. orig = data = RREG32(MPLL_BYPASSCLK_SEL);
  5597. data &= ~MPLL_CLKOUT_SEL_MASK;
  5598. data |= MPLL_CLKOUT_SEL(4);
  5599. if (orig != data)
  5600. WREG32(MPLL_BYPASSCLK_SEL, data);
  5601. orig = data = RREG32(SPLL_CNTL_MODE);
  5602. data &= ~SPLL_REFCLK_SEL_MASK;
  5603. if (orig != data)
  5604. WREG32(SPLL_CNTL_MODE, data);
  5605. }
  5606. }
  5607. } else {
  5608. if (orig != data)
  5609. WREG32_PCIE_PORT(PCIE_LC_CNTL, data);
  5610. }
  5611. orig = data = RREG32_PCIE(PCIE_CNTL2);
  5612. data |= SLV_MEM_LS_EN | MST_MEM_LS_EN | REPLAY_MEM_LS_EN;
  5613. if (orig != data)
  5614. WREG32_PCIE(PCIE_CNTL2, data);
  5615. if (!disable_l0s) {
  5616. data = RREG32_PCIE_PORT(PCIE_LC_N_FTS_CNTL);
  5617. if((data & LC_N_FTS_MASK) == LC_N_FTS_MASK) {
  5618. data = RREG32_PCIE(PCIE_LC_STATUS1);
  5619. if ((data & LC_REVERSE_XMIT) && (data & LC_REVERSE_RCVR)) {
  5620. orig = data = RREG32_PCIE_PORT(PCIE_LC_CNTL);
  5621. data &= ~LC_L0S_INACTIVITY_MASK;
  5622. if (orig != data)
  5623. WREG32_PCIE_PORT(PCIE_LC_CNTL, data);
  5624. }
  5625. }
  5626. }
  5627. }