gfx_v8_0.c 236 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032
  1. /*
  2. * Copyright 2014 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. */
  23. #include <linux/firmware.h>
  24. #include <drm/drmP.h>
  25. #include "amdgpu.h"
  26. #include "amdgpu_gfx.h"
  27. #include "vi.h"
  28. #include "vi_structs.h"
  29. #include "vid.h"
  30. #include "amdgpu_ucode.h"
  31. #include "amdgpu_atombios.h"
  32. #include "atombios_i2c.h"
  33. #include "clearstate_vi.h"
  34. #include "gmc/gmc_8_2_d.h"
  35. #include "gmc/gmc_8_2_sh_mask.h"
  36. #include "oss/oss_3_0_d.h"
  37. #include "oss/oss_3_0_sh_mask.h"
  38. #include "bif/bif_5_0_d.h"
  39. #include "bif/bif_5_0_sh_mask.h"
  40. #include "gca/gfx_8_0_d.h"
  41. #include "gca/gfx_8_0_enum.h"
  42. #include "gca/gfx_8_0_sh_mask.h"
  43. #include "gca/gfx_8_0_enum.h"
  44. #include "dce/dce_10_0_d.h"
  45. #include "dce/dce_10_0_sh_mask.h"
  46. #include "smu/smu_7_1_3_d.h"
  47. #define GFX8_NUM_GFX_RINGS 1
  48. #define GFX8_MEC_HPD_SIZE 2048
  49. #define TOPAZ_GB_ADDR_CONFIG_GOLDEN 0x22010001
  50. #define CARRIZO_GB_ADDR_CONFIG_GOLDEN 0x22010001
  51. #define POLARIS11_GB_ADDR_CONFIG_GOLDEN 0x22011002
  52. #define TONGA_GB_ADDR_CONFIG_GOLDEN 0x22011003
  53. #define ARRAY_MODE(x) ((x) << GB_TILE_MODE0__ARRAY_MODE__SHIFT)
  54. #define PIPE_CONFIG(x) ((x) << GB_TILE_MODE0__PIPE_CONFIG__SHIFT)
  55. #define TILE_SPLIT(x) ((x) << GB_TILE_MODE0__TILE_SPLIT__SHIFT)
  56. #define MICRO_TILE_MODE_NEW(x) ((x) << GB_TILE_MODE0__MICRO_TILE_MODE_NEW__SHIFT)
  57. #define SAMPLE_SPLIT(x) ((x) << GB_TILE_MODE0__SAMPLE_SPLIT__SHIFT)
  58. #define BANK_WIDTH(x) ((x) << GB_MACROTILE_MODE0__BANK_WIDTH__SHIFT)
  59. #define BANK_HEIGHT(x) ((x) << GB_MACROTILE_MODE0__BANK_HEIGHT__SHIFT)
  60. #define MACRO_TILE_ASPECT(x) ((x) << GB_MACROTILE_MODE0__MACRO_TILE_ASPECT__SHIFT)
  61. #define NUM_BANKS(x) ((x) << GB_MACROTILE_MODE0__NUM_BANKS__SHIFT)
  62. #define RLC_CGTT_MGCG_OVERRIDE__CPF_MASK 0x00000001L
  63. #define RLC_CGTT_MGCG_OVERRIDE__RLC_MASK 0x00000002L
  64. #define RLC_CGTT_MGCG_OVERRIDE__MGCG_MASK 0x00000004L
  65. #define RLC_CGTT_MGCG_OVERRIDE__CGCG_MASK 0x00000008L
  66. #define RLC_CGTT_MGCG_OVERRIDE__CGLS_MASK 0x00000010L
  67. #define RLC_CGTT_MGCG_OVERRIDE__GRBM_MASK 0x00000020L
  68. /* BPM SERDES CMD */
  69. #define SET_BPM_SERDES_CMD 1
  70. #define CLE_BPM_SERDES_CMD 0
  71. /* BPM Register Address*/
  72. enum {
  73. BPM_REG_CGLS_EN = 0, /* Enable/Disable CGLS */
  74. BPM_REG_CGLS_ON, /* ON/OFF CGLS: shall be controlled by RLC FW */
  75. BPM_REG_CGCG_OVERRIDE, /* Set/Clear CGCG Override */
  76. BPM_REG_MGCG_OVERRIDE, /* Set/Clear MGCG Override */
  77. BPM_REG_FGCG_OVERRIDE, /* Set/Clear FGCG Override */
  78. BPM_REG_FGCG_MAX
  79. };
  80. #define RLC_FormatDirectRegListLength 14
  81. MODULE_FIRMWARE("amdgpu/carrizo_ce.bin");
  82. MODULE_FIRMWARE("amdgpu/carrizo_pfp.bin");
  83. MODULE_FIRMWARE("amdgpu/carrizo_me.bin");
  84. MODULE_FIRMWARE("amdgpu/carrizo_mec.bin");
  85. MODULE_FIRMWARE("amdgpu/carrizo_mec2.bin");
  86. MODULE_FIRMWARE("amdgpu/carrizo_rlc.bin");
  87. MODULE_FIRMWARE("amdgpu/stoney_ce.bin");
  88. MODULE_FIRMWARE("amdgpu/stoney_pfp.bin");
  89. MODULE_FIRMWARE("amdgpu/stoney_me.bin");
  90. MODULE_FIRMWARE("amdgpu/stoney_mec.bin");
  91. MODULE_FIRMWARE("amdgpu/stoney_rlc.bin");
  92. MODULE_FIRMWARE("amdgpu/tonga_ce.bin");
  93. MODULE_FIRMWARE("amdgpu/tonga_pfp.bin");
  94. MODULE_FIRMWARE("amdgpu/tonga_me.bin");
  95. MODULE_FIRMWARE("amdgpu/tonga_mec.bin");
  96. MODULE_FIRMWARE("amdgpu/tonga_mec2.bin");
  97. MODULE_FIRMWARE("amdgpu/tonga_rlc.bin");
  98. MODULE_FIRMWARE("amdgpu/topaz_ce.bin");
  99. MODULE_FIRMWARE("amdgpu/topaz_pfp.bin");
  100. MODULE_FIRMWARE("amdgpu/topaz_me.bin");
  101. MODULE_FIRMWARE("amdgpu/topaz_mec.bin");
  102. MODULE_FIRMWARE("amdgpu/topaz_rlc.bin");
  103. MODULE_FIRMWARE("amdgpu/fiji_ce.bin");
  104. MODULE_FIRMWARE("amdgpu/fiji_pfp.bin");
  105. MODULE_FIRMWARE("amdgpu/fiji_me.bin");
  106. MODULE_FIRMWARE("amdgpu/fiji_mec.bin");
  107. MODULE_FIRMWARE("amdgpu/fiji_mec2.bin");
  108. MODULE_FIRMWARE("amdgpu/fiji_rlc.bin");
  109. MODULE_FIRMWARE("amdgpu/polaris11_ce.bin");
  110. MODULE_FIRMWARE("amdgpu/polaris11_pfp.bin");
  111. MODULE_FIRMWARE("amdgpu/polaris11_me.bin");
  112. MODULE_FIRMWARE("amdgpu/polaris11_mec.bin");
  113. MODULE_FIRMWARE("amdgpu/polaris11_mec2.bin");
  114. MODULE_FIRMWARE("amdgpu/polaris11_rlc.bin");
  115. MODULE_FIRMWARE("amdgpu/polaris10_ce.bin");
  116. MODULE_FIRMWARE("amdgpu/polaris10_pfp.bin");
  117. MODULE_FIRMWARE("amdgpu/polaris10_me.bin");
  118. MODULE_FIRMWARE("amdgpu/polaris10_mec.bin");
  119. MODULE_FIRMWARE("amdgpu/polaris10_mec2.bin");
  120. MODULE_FIRMWARE("amdgpu/polaris10_rlc.bin");
  121. MODULE_FIRMWARE("amdgpu/polaris12_ce.bin");
  122. MODULE_FIRMWARE("amdgpu/polaris12_pfp.bin");
  123. MODULE_FIRMWARE("amdgpu/polaris12_me.bin");
  124. MODULE_FIRMWARE("amdgpu/polaris12_mec.bin");
  125. MODULE_FIRMWARE("amdgpu/polaris12_mec2.bin");
  126. MODULE_FIRMWARE("amdgpu/polaris12_rlc.bin");
  127. static const struct amdgpu_gds_reg_offset amdgpu_gds_reg_offset[] =
  128. {
  129. {mmGDS_VMID0_BASE, mmGDS_VMID0_SIZE, mmGDS_GWS_VMID0, mmGDS_OA_VMID0},
  130. {mmGDS_VMID1_BASE, mmGDS_VMID1_SIZE, mmGDS_GWS_VMID1, mmGDS_OA_VMID1},
  131. {mmGDS_VMID2_BASE, mmGDS_VMID2_SIZE, mmGDS_GWS_VMID2, mmGDS_OA_VMID2},
  132. {mmGDS_VMID3_BASE, mmGDS_VMID3_SIZE, mmGDS_GWS_VMID3, mmGDS_OA_VMID3},
  133. {mmGDS_VMID4_BASE, mmGDS_VMID4_SIZE, mmGDS_GWS_VMID4, mmGDS_OA_VMID4},
  134. {mmGDS_VMID5_BASE, mmGDS_VMID5_SIZE, mmGDS_GWS_VMID5, mmGDS_OA_VMID5},
  135. {mmGDS_VMID6_BASE, mmGDS_VMID6_SIZE, mmGDS_GWS_VMID6, mmGDS_OA_VMID6},
  136. {mmGDS_VMID7_BASE, mmGDS_VMID7_SIZE, mmGDS_GWS_VMID7, mmGDS_OA_VMID7},
  137. {mmGDS_VMID8_BASE, mmGDS_VMID8_SIZE, mmGDS_GWS_VMID8, mmGDS_OA_VMID8},
  138. {mmGDS_VMID9_BASE, mmGDS_VMID9_SIZE, mmGDS_GWS_VMID9, mmGDS_OA_VMID9},
  139. {mmGDS_VMID10_BASE, mmGDS_VMID10_SIZE, mmGDS_GWS_VMID10, mmGDS_OA_VMID10},
  140. {mmGDS_VMID11_BASE, mmGDS_VMID11_SIZE, mmGDS_GWS_VMID11, mmGDS_OA_VMID11},
  141. {mmGDS_VMID12_BASE, mmGDS_VMID12_SIZE, mmGDS_GWS_VMID12, mmGDS_OA_VMID12},
  142. {mmGDS_VMID13_BASE, mmGDS_VMID13_SIZE, mmGDS_GWS_VMID13, mmGDS_OA_VMID13},
  143. {mmGDS_VMID14_BASE, mmGDS_VMID14_SIZE, mmGDS_GWS_VMID14, mmGDS_OA_VMID14},
  144. {mmGDS_VMID15_BASE, mmGDS_VMID15_SIZE, mmGDS_GWS_VMID15, mmGDS_OA_VMID15}
  145. };
  146. static const u32 golden_settings_tonga_a11[] =
  147. {
  148. mmCB_HW_CONTROL, 0xfffdf3cf, 0x00007208,
  149. mmCB_HW_CONTROL_3, 0x00000040, 0x00000040,
  150. mmDB_DEBUG2, 0xf00fffff, 0x00000400,
  151. mmGB_GPU_ID, 0x0000000f, 0x00000000,
  152. mmPA_SC_ENHANCE, 0xffffffff, 0x20000001,
  153. mmPA_SC_FIFO_DEPTH_CNTL, 0x000003ff, 0x000000fc,
  154. mmPA_SC_LINE_STIPPLE_STATE, 0x0000ff0f, 0x00000000,
  155. mmRLC_CGCG_CGLS_CTRL, 0x00000003, 0x0000003c,
  156. mmSQ_RANDOM_WAVE_PRI, 0x001fffff, 0x000006fd,
  157. mmTA_CNTL_AUX, 0x000f000f, 0x000b0000,
  158. mmTCC_CTRL, 0x00100000, 0xf31fff7f,
  159. mmTCC_EXE_DISABLE, 0x00000002, 0x00000002,
  160. mmTCP_ADDR_CONFIG, 0x000003ff, 0x000002fb,
  161. mmTCP_CHAN_STEER_HI, 0xffffffff, 0x0000543b,
  162. mmTCP_CHAN_STEER_LO, 0xffffffff, 0xa9210876,
  163. mmVGT_RESET_DEBUG, 0x00000004, 0x00000004,
  164. };
  165. static const u32 tonga_golden_common_all[] =
  166. {
  167. mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
  168. mmPA_SC_RASTER_CONFIG, 0xffffffff, 0x16000012,
  169. mmPA_SC_RASTER_CONFIG_1, 0xffffffff, 0x0000002A,
  170. mmGB_ADDR_CONFIG, 0xffffffff, 0x22011003,
  171. mmSPI_RESOURCE_RESERVE_CU_0, 0xffffffff, 0x00000800,
  172. mmSPI_RESOURCE_RESERVE_CU_1, 0xffffffff, 0x00000800,
  173. mmSPI_RESOURCE_RESERVE_EN_CU_0, 0xffffffff, 0x00FF7FBF,
  174. mmSPI_RESOURCE_RESERVE_EN_CU_1, 0xffffffff, 0x00FF7FAF
  175. };
  176. static const u32 tonga_mgcg_cgcg_init[] =
  177. {
  178. mmRLC_CGTT_MGCG_OVERRIDE, 0xffffffff, 0xffffffff,
  179. mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
  180. mmCB_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100,
  181. mmCGTT_BCI_CLK_CTRL, 0xffffffff, 0x00000100,
  182. mmCGTT_CP_CLK_CTRL, 0xffffffff, 0x00000100,
  183. mmCGTT_CPC_CLK_CTRL, 0xffffffff, 0x00000100,
  184. mmCGTT_CPF_CLK_CTRL, 0xffffffff, 0x40000100,
  185. mmCGTT_GDS_CLK_CTRL, 0xffffffff, 0x00000100,
  186. mmCGTT_IA_CLK_CTRL, 0xffffffff, 0x06000100,
  187. mmCGTT_PA_CLK_CTRL, 0xffffffff, 0x00000100,
  188. mmCGTT_WD_CLK_CTRL, 0xffffffff, 0x06000100,
  189. mmCGTT_PC_CLK_CTRL, 0xffffffff, 0x00000100,
  190. mmCGTT_RLC_CLK_CTRL, 0xffffffff, 0x00000100,
  191. mmCGTT_SC_CLK_CTRL, 0xffffffff, 0x00000100,
  192. mmCGTT_SPI_CLK_CTRL, 0xffffffff, 0x00000100,
  193. mmCGTT_SQ_CLK_CTRL, 0xffffffff, 0x00000100,
  194. mmCGTT_SQG_CLK_CTRL, 0xffffffff, 0x00000100,
  195. mmCGTT_SX_CLK_CTRL0, 0xffffffff, 0x00000100,
  196. mmCGTT_SX_CLK_CTRL1, 0xffffffff, 0x00000100,
  197. mmCGTT_SX_CLK_CTRL2, 0xffffffff, 0x00000100,
  198. mmCGTT_SX_CLK_CTRL3, 0xffffffff, 0x00000100,
  199. mmCGTT_SX_CLK_CTRL4, 0xffffffff, 0x00000100,
  200. mmCGTT_TCI_CLK_CTRL, 0xffffffff, 0x00000100,
  201. mmCGTT_TCP_CLK_CTRL, 0xffffffff, 0x00000100,
  202. mmCGTT_VGT_CLK_CTRL, 0xffffffff, 0x06000100,
  203. mmDB_CGTT_CLK_CTRL_0, 0xffffffff, 0x00000100,
  204. mmTA_CGTT_CTRL, 0xffffffff, 0x00000100,
  205. mmTCA_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100,
  206. mmTCC_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100,
  207. mmTD_CGTT_CTRL, 0xffffffff, 0x00000100,
  208. mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
  209. mmCGTS_CU0_SP0_CTRL_REG, 0xffffffff, 0x00010000,
  210. mmCGTS_CU0_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
  211. mmCGTS_CU0_TA_SQC_CTRL_REG, 0xffffffff, 0x00040007,
  212. mmCGTS_CU0_SP1_CTRL_REG, 0xffffffff, 0x00060005,
  213. mmCGTS_CU0_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
  214. mmCGTS_CU1_SP0_CTRL_REG, 0xffffffff, 0x00010000,
  215. mmCGTS_CU1_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
  216. mmCGTS_CU1_TA_CTRL_REG, 0xffffffff, 0x00040007,
  217. mmCGTS_CU1_SP1_CTRL_REG, 0xffffffff, 0x00060005,
  218. mmCGTS_CU1_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
  219. mmCGTS_CU2_SP0_CTRL_REG, 0xffffffff, 0x00010000,
  220. mmCGTS_CU2_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
  221. mmCGTS_CU2_TA_CTRL_REG, 0xffffffff, 0x00040007,
  222. mmCGTS_CU2_SP1_CTRL_REG, 0xffffffff, 0x00060005,
  223. mmCGTS_CU2_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
  224. mmCGTS_CU3_SP0_CTRL_REG, 0xffffffff, 0x00010000,
  225. mmCGTS_CU3_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
  226. mmCGTS_CU3_TA_CTRL_REG, 0xffffffff, 0x00040007,
  227. mmCGTS_CU3_SP1_CTRL_REG, 0xffffffff, 0x00060005,
  228. mmCGTS_CU3_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
  229. mmCGTS_CU4_SP0_CTRL_REG, 0xffffffff, 0x00010000,
  230. mmCGTS_CU4_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
  231. mmCGTS_CU4_TA_SQC_CTRL_REG, 0xffffffff, 0x00040007,
  232. mmCGTS_CU4_SP1_CTRL_REG, 0xffffffff, 0x00060005,
  233. mmCGTS_CU4_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
  234. mmCGTS_CU5_SP0_CTRL_REG, 0xffffffff, 0x00010000,
  235. mmCGTS_CU5_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
  236. mmCGTS_CU5_TA_CTRL_REG, 0xffffffff, 0x00040007,
  237. mmCGTS_CU5_SP1_CTRL_REG, 0xffffffff, 0x00060005,
  238. mmCGTS_CU5_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
  239. mmCGTS_CU6_SP0_CTRL_REG, 0xffffffff, 0x00010000,
  240. mmCGTS_CU6_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
  241. mmCGTS_CU6_TA_CTRL_REG, 0xffffffff, 0x00040007,
  242. mmCGTS_CU6_SP1_CTRL_REG, 0xffffffff, 0x00060005,
  243. mmCGTS_CU6_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
  244. mmCGTS_CU7_SP0_CTRL_REG, 0xffffffff, 0x00010000,
  245. mmCGTS_CU7_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
  246. mmCGTS_CU7_TA_CTRL_REG, 0xffffffff, 0x00040007,
  247. mmCGTS_CU7_SP1_CTRL_REG, 0xffffffff, 0x00060005,
  248. mmCGTS_CU7_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
  249. mmCGTS_SM_CTRL_REG, 0xffffffff, 0x96e00200,
  250. mmCP_RB_WPTR_POLL_CNTL, 0xffffffff, 0x00900100,
  251. mmRLC_CGCG_CGLS_CTRL, 0xffffffff, 0x0020003c,
  252. mmCP_MEM_SLP_CNTL, 0x00000001, 0x00000001,
  253. };
  254. static const u32 golden_settings_polaris11_a11[] =
  255. {
  256. mmCB_HW_CONTROL, 0x0000f3cf, 0x00007208,
  257. mmCB_HW_CONTROL_2, 0x0f000000, 0x0f000000,
  258. mmCB_HW_CONTROL_3, 0x000001ff, 0x00000040,
  259. mmDB_DEBUG2, 0xf00fffff, 0x00000400,
  260. mmPA_SC_ENHANCE, 0xffffffff, 0x20000001,
  261. mmPA_SC_LINE_STIPPLE_STATE, 0x0000ff0f, 0x00000000,
  262. mmPA_SC_RASTER_CONFIG, 0x3f3fffff, 0x16000012,
  263. mmPA_SC_RASTER_CONFIG_1, 0x0000003f, 0x00000000,
  264. mmRLC_CGCG_CGLS_CTRL, 0x00000003, 0x0001003c,
  265. mmRLC_CGCG_CGLS_CTRL_3D, 0xffffffff, 0x0001003c,
  266. mmSQ_CONFIG, 0x07f80000, 0x01180000,
  267. mmTA_CNTL_AUX, 0x000f000f, 0x000b0000,
  268. mmTCC_CTRL, 0x00100000, 0xf31fff7f,
  269. mmTCP_ADDR_CONFIG, 0x000003ff, 0x000000f3,
  270. mmTCP_CHAN_STEER_HI, 0xffffffff, 0x00000000,
  271. mmTCP_CHAN_STEER_LO, 0xffffffff, 0x00003210,
  272. mmVGT_RESET_DEBUG, 0x00000004, 0x00000004,
  273. };
  274. static const u32 polaris11_golden_common_all[] =
  275. {
  276. mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
  277. mmGB_ADDR_CONFIG, 0xffffffff, 0x22011002,
  278. mmSPI_RESOURCE_RESERVE_CU_0, 0xffffffff, 0x00000800,
  279. mmSPI_RESOURCE_RESERVE_CU_1, 0xffffffff, 0x00000800,
  280. mmSPI_RESOURCE_RESERVE_EN_CU_0, 0xffffffff, 0x00FF7FBF,
  281. mmSPI_RESOURCE_RESERVE_EN_CU_1, 0xffffffff, 0x00FF7FAF,
  282. };
  283. static const u32 golden_settings_polaris10_a11[] =
  284. {
  285. mmATC_MISC_CG, 0x000c0fc0, 0x000c0200,
  286. mmCB_HW_CONTROL, 0x0001f3cf, 0x00007208,
  287. mmCB_HW_CONTROL_2, 0x0f000000, 0x0f000000,
  288. mmCB_HW_CONTROL_3, 0x000001ff, 0x00000040,
  289. mmDB_DEBUG2, 0xf00fffff, 0x00000400,
  290. mmPA_SC_ENHANCE, 0xffffffff, 0x20000001,
  291. mmPA_SC_LINE_STIPPLE_STATE, 0x0000ff0f, 0x00000000,
  292. mmPA_SC_RASTER_CONFIG, 0x3f3fffff, 0x16000012,
  293. mmPA_SC_RASTER_CONFIG_1, 0x0000003f, 0x0000002a,
  294. mmRLC_CGCG_CGLS_CTRL, 0x00000003, 0x0001003c,
  295. mmRLC_CGCG_CGLS_CTRL_3D, 0xffffffff, 0x0001003c,
  296. mmSQ_CONFIG, 0x07f80000, 0x07180000,
  297. mmTA_CNTL_AUX, 0x000f000f, 0x000b0000,
  298. mmTCC_CTRL, 0x00100000, 0xf31fff7f,
  299. mmTCP_ADDR_CONFIG, 0x000003ff, 0x000000f7,
  300. mmTCP_CHAN_STEER_HI, 0xffffffff, 0x00000000,
  301. mmVGT_RESET_DEBUG, 0x00000004, 0x00000004,
  302. };
  303. static const u32 polaris10_golden_common_all[] =
  304. {
  305. mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
  306. mmPA_SC_RASTER_CONFIG, 0xffffffff, 0x16000012,
  307. mmPA_SC_RASTER_CONFIG_1, 0xffffffff, 0x0000002A,
  308. mmGB_ADDR_CONFIG, 0xffffffff, 0x22011003,
  309. mmSPI_RESOURCE_RESERVE_CU_0, 0xffffffff, 0x00000800,
  310. mmSPI_RESOURCE_RESERVE_CU_1, 0xffffffff, 0x00000800,
  311. mmSPI_RESOURCE_RESERVE_EN_CU_0, 0xffffffff, 0x00FF7FBF,
  312. mmSPI_RESOURCE_RESERVE_EN_CU_1, 0xffffffff, 0x00FF7FAF,
  313. };
  314. static const u32 fiji_golden_common_all[] =
  315. {
  316. mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
  317. mmPA_SC_RASTER_CONFIG, 0xffffffff, 0x3a00161a,
  318. mmPA_SC_RASTER_CONFIG_1, 0xffffffff, 0x0000002e,
  319. mmGB_ADDR_CONFIG, 0xffffffff, 0x22011003,
  320. mmSPI_RESOURCE_RESERVE_CU_0, 0xffffffff, 0x00000800,
  321. mmSPI_RESOURCE_RESERVE_CU_1, 0xffffffff, 0x00000800,
  322. mmSPI_RESOURCE_RESERVE_EN_CU_0, 0xffffffff, 0x00FF7FBF,
  323. mmSPI_RESOURCE_RESERVE_EN_CU_1, 0xffffffff, 0x00FF7FAF,
  324. mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
  325. mmSPI_CONFIG_CNTL_1, 0x0000000f, 0x00000009,
  326. };
  327. static const u32 golden_settings_fiji_a10[] =
  328. {
  329. mmCB_HW_CONTROL_3, 0x000001ff, 0x00000040,
  330. mmDB_DEBUG2, 0xf00fffff, 0x00000400,
  331. mmPA_SC_ENHANCE, 0xffffffff, 0x20000001,
  332. mmPA_SC_LINE_STIPPLE_STATE, 0x0000ff0f, 0x00000000,
  333. mmRLC_CGCG_CGLS_CTRL, 0x00000003, 0x0001003c,
  334. mmSQ_RANDOM_WAVE_PRI, 0x001fffff, 0x000006fd,
  335. mmTA_CNTL_AUX, 0x000f000f, 0x000b0000,
  336. mmTCC_CTRL, 0x00100000, 0xf31fff7f,
  337. mmTCC_EXE_DISABLE, 0x00000002, 0x00000002,
  338. mmTCP_ADDR_CONFIG, 0x000003ff, 0x000000ff,
  339. mmVGT_RESET_DEBUG, 0x00000004, 0x00000004,
  340. };
  341. static const u32 fiji_mgcg_cgcg_init[] =
  342. {
  343. mmRLC_CGTT_MGCG_OVERRIDE, 0xffffffff, 0xffffffff,
  344. mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
  345. mmCB_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100,
  346. mmCGTT_BCI_CLK_CTRL, 0xffffffff, 0x00000100,
  347. mmCGTT_CP_CLK_CTRL, 0xffffffff, 0x00000100,
  348. mmCGTT_CPC_CLK_CTRL, 0xffffffff, 0x00000100,
  349. mmCGTT_CPF_CLK_CTRL, 0xffffffff, 0x40000100,
  350. mmCGTT_GDS_CLK_CTRL, 0xffffffff, 0x00000100,
  351. mmCGTT_IA_CLK_CTRL, 0xffffffff, 0x06000100,
  352. mmCGTT_PA_CLK_CTRL, 0xffffffff, 0x00000100,
  353. mmCGTT_WD_CLK_CTRL, 0xffffffff, 0x06000100,
  354. mmCGTT_PC_CLK_CTRL, 0xffffffff, 0x00000100,
  355. mmCGTT_RLC_CLK_CTRL, 0xffffffff, 0x00000100,
  356. mmCGTT_SC_CLK_CTRL, 0xffffffff, 0x00000100,
  357. mmCGTT_SPI_CLK_CTRL, 0xffffffff, 0x00000100,
  358. mmCGTT_SQ_CLK_CTRL, 0xffffffff, 0x00000100,
  359. mmCGTT_SQG_CLK_CTRL, 0xffffffff, 0x00000100,
  360. mmCGTT_SX_CLK_CTRL0, 0xffffffff, 0x00000100,
  361. mmCGTT_SX_CLK_CTRL1, 0xffffffff, 0x00000100,
  362. mmCGTT_SX_CLK_CTRL2, 0xffffffff, 0x00000100,
  363. mmCGTT_SX_CLK_CTRL3, 0xffffffff, 0x00000100,
  364. mmCGTT_SX_CLK_CTRL4, 0xffffffff, 0x00000100,
  365. mmCGTT_TCI_CLK_CTRL, 0xffffffff, 0x00000100,
  366. mmCGTT_TCP_CLK_CTRL, 0xffffffff, 0x00000100,
  367. mmCGTT_VGT_CLK_CTRL, 0xffffffff, 0x06000100,
  368. mmDB_CGTT_CLK_CTRL_0, 0xffffffff, 0x00000100,
  369. mmTA_CGTT_CTRL, 0xffffffff, 0x00000100,
  370. mmTCA_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100,
  371. mmTCC_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100,
  372. mmTD_CGTT_CTRL, 0xffffffff, 0x00000100,
  373. mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
  374. mmCGTS_SM_CTRL_REG, 0xffffffff, 0x96e00200,
  375. mmCP_RB_WPTR_POLL_CNTL, 0xffffffff, 0x00900100,
  376. mmRLC_CGCG_CGLS_CTRL, 0xffffffff, 0x0020003c,
  377. mmCP_MEM_SLP_CNTL, 0x00000001, 0x00000001,
  378. };
  379. static const u32 golden_settings_iceland_a11[] =
  380. {
  381. mmCB_HW_CONTROL_3, 0x00000040, 0x00000040,
  382. mmDB_DEBUG2, 0xf00fffff, 0x00000400,
  383. mmDB_DEBUG3, 0xc0000000, 0xc0000000,
  384. mmGB_GPU_ID, 0x0000000f, 0x00000000,
  385. mmPA_SC_ENHANCE, 0xffffffff, 0x20000001,
  386. mmPA_SC_LINE_STIPPLE_STATE, 0x0000ff0f, 0x00000000,
  387. mmPA_SC_RASTER_CONFIG, 0x3f3fffff, 0x00000002,
  388. mmPA_SC_RASTER_CONFIG_1, 0x0000003f, 0x00000000,
  389. mmRLC_CGCG_CGLS_CTRL, 0x00000003, 0x0000003c,
  390. mmSQ_RANDOM_WAVE_PRI, 0x001fffff, 0x000006fd,
  391. mmTA_CNTL_AUX, 0x000f000f, 0x000b0000,
  392. mmTCC_CTRL, 0x00100000, 0xf31fff7f,
  393. mmTCC_EXE_DISABLE, 0x00000002, 0x00000002,
  394. mmTCP_ADDR_CONFIG, 0x000003ff, 0x000000f1,
  395. mmTCP_CHAN_STEER_HI, 0xffffffff, 0x00000000,
  396. mmTCP_CHAN_STEER_LO, 0xffffffff, 0x00000010,
  397. };
  398. static const u32 iceland_golden_common_all[] =
  399. {
  400. mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
  401. mmPA_SC_RASTER_CONFIG, 0xffffffff, 0x00000002,
  402. mmPA_SC_RASTER_CONFIG_1, 0xffffffff, 0x00000000,
  403. mmGB_ADDR_CONFIG, 0xffffffff, 0x22010001,
  404. mmSPI_RESOURCE_RESERVE_CU_0, 0xffffffff, 0x00000800,
  405. mmSPI_RESOURCE_RESERVE_CU_1, 0xffffffff, 0x00000800,
  406. mmSPI_RESOURCE_RESERVE_EN_CU_0, 0xffffffff, 0x00FF7FBF,
  407. mmSPI_RESOURCE_RESERVE_EN_CU_1, 0xffffffff, 0x00FF7FAF
  408. };
  409. static const u32 iceland_mgcg_cgcg_init[] =
  410. {
  411. mmRLC_CGTT_MGCG_OVERRIDE, 0xffffffff, 0xffffffff,
  412. mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
  413. mmCB_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100,
  414. mmCGTT_BCI_CLK_CTRL, 0xffffffff, 0x00000100,
  415. mmCGTT_CP_CLK_CTRL, 0xffffffff, 0xc0000100,
  416. mmCGTT_CPC_CLK_CTRL, 0xffffffff, 0xc0000100,
  417. mmCGTT_CPF_CLK_CTRL, 0xffffffff, 0xc0000100,
  418. mmCGTT_GDS_CLK_CTRL, 0xffffffff, 0x00000100,
  419. mmCGTT_IA_CLK_CTRL, 0xffffffff, 0x06000100,
  420. mmCGTT_PA_CLK_CTRL, 0xffffffff, 0x00000100,
  421. mmCGTT_WD_CLK_CTRL, 0xffffffff, 0x06000100,
  422. mmCGTT_PC_CLK_CTRL, 0xffffffff, 0x00000100,
  423. mmCGTT_RLC_CLK_CTRL, 0xffffffff, 0x00000100,
  424. mmCGTT_SC_CLK_CTRL, 0xffffffff, 0x00000100,
  425. mmCGTT_SPI_CLK_CTRL, 0xffffffff, 0x00000100,
  426. mmCGTT_SQ_CLK_CTRL, 0xffffffff, 0x00000100,
  427. mmCGTT_SQG_CLK_CTRL, 0xffffffff, 0x00000100,
  428. mmCGTT_SX_CLK_CTRL0, 0xffffffff, 0x00000100,
  429. mmCGTT_SX_CLK_CTRL1, 0xffffffff, 0x00000100,
  430. mmCGTT_SX_CLK_CTRL2, 0xffffffff, 0x00000100,
  431. mmCGTT_SX_CLK_CTRL3, 0xffffffff, 0x00000100,
  432. mmCGTT_SX_CLK_CTRL4, 0xffffffff, 0x00000100,
  433. mmCGTT_TCI_CLK_CTRL, 0xffffffff, 0xff000100,
  434. mmCGTT_TCP_CLK_CTRL, 0xffffffff, 0x00000100,
  435. mmCGTT_VGT_CLK_CTRL, 0xffffffff, 0x06000100,
  436. mmDB_CGTT_CLK_CTRL_0, 0xffffffff, 0x00000100,
  437. mmTA_CGTT_CTRL, 0xffffffff, 0x00000100,
  438. mmTCA_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100,
  439. mmTCC_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100,
  440. mmTD_CGTT_CTRL, 0xffffffff, 0x00000100,
  441. mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
  442. mmCGTS_CU0_SP0_CTRL_REG, 0xffffffff, 0x00010000,
  443. mmCGTS_CU0_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
  444. mmCGTS_CU0_TA_SQC_CTRL_REG, 0xffffffff, 0x0f840f87,
  445. mmCGTS_CU0_SP1_CTRL_REG, 0xffffffff, 0x00060005,
  446. mmCGTS_CU0_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
  447. mmCGTS_CU1_SP0_CTRL_REG, 0xffffffff, 0x00010000,
  448. mmCGTS_CU1_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
  449. mmCGTS_CU1_TA_CTRL_REG, 0xffffffff, 0x00040007,
  450. mmCGTS_CU1_SP1_CTRL_REG, 0xffffffff, 0x00060005,
  451. mmCGTS_CU1_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
  452. mmCGTS_CU2_SP0_CTRL_REG, 0xffffffff, 0x00010000,
  453. mmCGTS_CU2_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
  454. mmCGTS_CU2_TA_CTRL_REG, 0xffffffff, 0x00040007,
  455. mmCGTS_CU2_SP1_CTRL_REG, 0xffffffff, 0x00060005,
  456. mmCGTS_CU2_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
  457. mmCGTS_CU3_SP0_CTRL_REG, 0xffffffff, 0x00010000,
  458. mmCGTS_CU3_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
  459. mmCGTS_CU3_TA_CTRL_REG, 0xffffffff, 0x00040007,
  460. mmCGTS_CU3_SP1_CTRL_REG, 0xffffffff, 0x00060005,
  461. mmCGTS_CU3_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
  462. mmCGTS_CU4_SP0_CTRL_REG, 0xffffffff, 0x00010000,
  463. mmCGTS_CU4_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
  464. mmCGTS_CU4_TA_SQC_CTRL_REG, 0xffffffff, 0x0f840f87,
  465. mmCGTS_CU4_SP1_CTRL_REG, 0xffffffff, 0x00060005,
  466. mmCGTS_CU4_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
  467. mmCGTS_CU5_SP0_CTRL_REG, 0xffffffff, 0x00010000,
  468. mmCGTS_CU5_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
  469. mmCGTS_CU5_TA_CTRL_REG, 0xffffffff, 0x00040007,
  470. mmCGTS_CU5_SP1_CTRL_REG, 0xffffffff, 0x00060005,
  471. mmCGTS_CU5_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
  472. mmCGTS_SM_CTRL_REG, 0xffffffff, 0x96e00200,
  473. mmCP_RB_WPTR_POLL_CNTL, 0xffffffff, 0x00900100,
  474. mmRLC_CGCG_CGLS_CTRL, 0xffffffff, 0x0020003c,
  475. };
  476. static const u32 cz_golden_settings_a11[] =
  477. {
  478. mmCB_HW_CONTROL_3, 0x00000040, 0x00000040,
  479. mmDB_DEBUG2, 0xf00fffff, 0x00000400,
  480. mmGB_GPU_ID, 0x0000000f, 0x00000000,
  481. mmPA_SC_ENHANCE, 0xffffffff, 0x00000001,
  482. mmPA_SC_LINE_STIPPLE_STATE, 0x0000ff0f, 0x00000000,
  483. mmRLC_CGCG_CGLS_CTRL, 0x00000003, 0x0000003c,
  484. mmSQ_RANDOM_WAVE_PRI, 0x001fffff, 0x000006fd,
  485. mmTA_CNTL_AUX, 0x000f000f, 0x00010000,
  486. mmTCC_CTRL, 0x00100000, 0xf31fff7f,
  487. mmTCC_EXE_DISABLE, 0x00000002, 0x00000002,
  488. mmTCP_ADDR_CONFIG, 0x0000000f, 0x000000f3,
  489. mmTCP_CHAN_STEER_LO, 0xffffffff, 0x00001302
  490. };
  491. static const u32 cz_golden_common_all[] =
  492. {
  493. mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
  494. mmPA_SC_RASTER_CONFIG, 0xffffffff, 0x00000002,
  495. mmPA_SC_RASTER_CONFIG_1, 0xffffffff, 0x00000000,
  496. mmGB_ADDR_CONFIG, 0xffffffff, 0x22010001,
  497. mmSPI_RESOURCE_RESERVE_CU_0, 0xffffffff, 0x00000800,
  498. mmSPI_RESOURCE_RESERVE_CU_1, 0xffffffff, 0x00000800,
  499. mmSPI_RESOURCE_RESERVE_EN_CU_0, 0xffffffff, 0x00FF7FBF,
  500. mmSPI_RESOURCE_RESERVE_EN_CU_1, 0xffffffff, 0x00FF7FAF
  501. };
  502. static const u32 cz_mgcg_cgcg_init[] =
  503. {
  504. mmRLC_CGTT_MGCG_OVERRIDE, 0xffffffff, 0xffffffff,
  505. mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
  506. mmCB_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100,
  507. mmCGTT_BCI_CLK_CTRL, 0xffffffff, 0x00000100,
  508. mmCGTT_CP_CLK_CTRL, 0xffffffff, 0x00000100,
  509. mmCGTT_CPC_CLK_CTRL, 0xffffffff, 0x00000100,
  510. mmCGTT_CPF_CLK_CTRL, 0xffffffff, 0x00000100,
  511. mmCGTT_GDS_CLK_CTRL, 0xffffffff, 0x00000100,
  512. mmCGTT_IA_CLK_CTRL, 0xffffffff, 0x06000100,
  513. mmCGTT_PA_CLK_CTRL, 0xffffffff, 0x00000100,
  514. mmCGTT_WD_CLK_CTRL, 0xffffffff, 0x06000100,
  515. mmCGTT_PC_CLK_CTRL, 0xffffffff, 0x00000100,
  516. mmCGTT_RLC_CLK_CTRL, 0xffffffff, 0x00000100,
  517. mmCGTT_SC_CLK_CTRL, 0xffffffff, 0x00000100,
  518. mmCGTT_SPI_CLK_CTRL, 0xffffffff, 0x00000100,
  519. mmCGTT_SQ_CLK_CTRL, 0xffffffff, 0x00000100,
  520. mmCGTT_SQG_CLK_CTRL, 0xffffffff, 0x00000100,
  521. mmCGTT_SX_CLK_CTRL0, 0xffffffff, 0x00000100,
  522. mmCGTT_SX_CLK_CTRL1, 0xffffffff, 0x00000100,
  523. mmCGTT_SX_CLK_CTRL2, 0xffffffff, 0x00000100,
  524. mmCGTT_SX_CLK_CTRL3, 0xffffffff, 0x00000100,
  525. mmCGTT_SX_CLK_CTRL4, 0xffffffff, 0x00000100,
  526. mmCGTT_TCI_CLK_CTRL, 0xffffffff, 0x00000100,
  527. mmCGTT_TCP_CLK_CTRL, 0xffffffff, 0x00000100,
  528. mmCGTT_VGT_CLK_CTRL, 0xffffffff, 0x06000100,
  529. mmDB_CGTT_CLK_CTRL_0, 0xffffffff, 0x00000100,
  530. mmTA_CGTT_CTRL, 0xffffffff, 0x00000100,
  531. mmTCA_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100,
  532. mmTCC_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100,
  533. mmTD_CGTT_CTRL, 0xffffffff, 0x00000100,
  534. mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
  535. mmCGTS_CU0_SP0_CTRL_REG, 0xffffffff, 0x00010000,
  536. mmCGTS_CU0_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
  537. mmCGTS_CU0_TA_SQC_CTRL_REG, 0xffffffff, 0x00040007,
  538. mmCGTS_CU0_SP1_CTRL_REG, 0xffffffff, 0x00060005,
  539. mmCGTS_CU0_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
  540. mmCGTS_CU1_SP0_CTRL_REG, 0xffffffff, 0x00010000,
  541. mmCGTS_CU1_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
  542. mmCGTS_CU1_TA_CTRL_REG, 0xffffffff, 0x00040007,
  543. mmCGTS_CU1_SP1_CTRL_REG, 0xffffffff, 0x00060005,
  544. mmCGTS_CU1_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
  545. mmCGTS_CU2_SP0_CTRL_REG, 0xffffffff, 0x00010000,
  546. mmCGTS_CU2_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
  547. mmCGTS_CU2_TA_CTRL_REG, 0xffffffff, 0x00040007,
  548. mmCGTS_CU2_SP1_CTRL_REG, 0xffffffff, 0x00060005,
  549. mmCGTS_CU2_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
  550. mmCGTS_CU3_SP0_CTRL_REG, 0xffffffff, 0x00010000,
  551. mmCGTS_CU3_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
  552. mmCGTS_CU3_TA_CTRL_REG, 0xffffffff, 0x00040007,
  553. mmCGTS_CU3_SP1_CTRL_REG, 0xffffffff, 0x00060005,
  554. mmCGTS_CU3_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
  555. mmCGTS_CU4_SP0_CTRL_REG, 0xffffffff, 0x00010000,
  556. mmCGTS_CU4_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
  557. mmCGTS_CU4_TA_SQC_CTRL_REG, 0xffffffff, 0x00040007,
  558. mmCGTS_CU4_SP1_CTRL_REG, 0xffffffff, 0x00060005,
  559. mmCGTS_CU4_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
  560. mmCGTS_CU5_SP0_CTRL_REG, 0xffffffff, 0x00010000,
  561. mmCGTS_CU5_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
  562. mmCGTS_CU5_TA_CTRL_REG, 0xffffffff, 0x00040007,
  563. mmCGTS_CU5_SP1_CTRL_REG, 0xffffffff, 0x00060005,
  564. mmCGTS_CU5_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
  565. mmCGTS_CU6_SP0_CTRL_REG, 0xffffffff, 0x00010000,
  566. mmCGTS_CU6_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
  567. mmCGTS_CU6_TA_CTRL_REG, 0xffffffff, 0x00040007,
  568. mmCGTS_CU6_SP1_CTRL_REG, 0xffffffff, 0x00060005,
  569. mmCGTS_CU6_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
  570. mmCGTS_CU7_SP0_CTRL_REG, 0xffffffff, 0x00010000,
  571. mmCGTS_CU7_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
  572. mmCGTS_CU7_TA_CTRL_REG, 0xffffffff, 0x00040007,
  573. mmCGTS_CU7_SP1_CTRL_REG, 0xffffffff, 0x00060005,
  574. mmCGTS_CU7_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
  575. mmCGTS_SM_CTRL_REG, 0xffffffff, 0x96e00200,
  576. mmCP_RB_WPTR_POLL_CNTL, 0xffffffff, 0x00900100,
  577. mmRLC_CGCG_CGLS_CTRL, 0xffffffff, 0x0020003f,
  578. mmCP_MEM_SLP_CNTL, 0x00000001, 0x00000001,
  579. };
  580. static const u32 stoney_golden_settings_a11[] =
  581. {
  582. mmDB_DEBUG2, 0xf00fffff, 0x00000400,
  583. mmGB_GPU_ID, 0x0000000f, 0x00000000,
  584. mmPA_SC_ENHANCE, 0xffffffff, 0x20000001,
  585. mmPA_SC_LINE_STIPPLE_STATE, 0x0000ff0f, 0x00000000,
  586. mmRLC_CGCG_CGLS_CTRL, 0x00000003, 0x0001003c,
  587. mmTA_CNTL_AUX, 0x000f000f, 0x000b0000,
  588. mmTCC_CTRL, 0x00100000, 0xf31fff7f,
  589. mmTCC_EXE_DISABLE, 0x00000002, 0x00000002,
  590. mmTCP_ADDR_CONFIG, 0x0000000f, 0x000000f1,
  591. mmTCP_CHAN_STEER_LO, 0xffffffff, 0x10101010,
  592. };
  593. static const u32 stoney_golden_common_all[] =
  594. {
  595. mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
  596. mmPA_SC_RASTER_CONFIG, 0xffffffff, 0x00000000,
  597. mmPA_SC_RASTER_CONFIG_1, 0xffffffff, 0x00000000,
  598. mmGB_ADDR_CONFIG, 0xffffffff, 0x12010001,
  599. mmSPI_RESOURCE_RESERVE_CU_0, 0xffffffff, 0x00000800,
  600. mmSPI_RESOURCE_RESERVE_CU_1, 0xffffffff, 0x00000800,
  601. mmSPI_RESOURCE_RESERVE_EN_CU_0, 0xffffffff, 0x00FF7FBF,
  602. mmSPI_RESOURCE_RESERVE_EN_CU_1, 0xffffffff, 0x00FF7FAF,
  603. };
  604. static const u32 stoney_mgcg_cgcg_init[] =
  605. {
  606. mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
  607. mmRLC_CGCG_CGLS_CTRL, 0xffffffff, 0x0020003f,
  608. mmCP_MEM_SLP_CNTL, 0xffffffff, 0x00020201,
  609. mmRLC_MEM_SLP_CNTL, 0xffffffff, 0x00020201,
  610. mmCGTS_SM_CTRL_REG, 0xffffffff, 0x96940200,
  611. };
  612. static void gfx_v8_0_set_ring_funcs(struct amdgpu_device *adev);
  613. static void gfx_v8_0_set_irq_funcs(struct amdgpu_device *adev);
  614. static void gfx_v8_0_set_gds_init(struct amdgpu_device *adev);
  615. static void gfx_v8_0_set_rlc_funcs(struct amdgpu_device *adev);
  616. static u32 gfx_v8_0_get_csb_size(struct amdgpu_device *adev);
  617. static void gfx_v8_0_get_cu_info(struct amdgpu_device *adev);
  618. static void gfx_v8_0_ring_emit_ce_meta(struct amdgpu_ring *ring);
  619. static void gfx_v8_0_ring_emit_de_meta(struct amdgpu_ring *ring);
  620. static void gfx_v8_0_init_golden_registers(struct amdgpu_device *adev)
  621. {
  622. switch (adev->asic_type) {
  623. case CHIP_TOPAZ:
  624. amdgpu_program_register_sequence(adev,
  625. iceland_mgcg_cgcg_init,
  626. (const u32)ARRAY_SIZE(iceland_mgcg_cgcg_init));
  627. amdgpu_program_register_sequence(adev,
  628. golden_settings_iceland_a11,
  629. (const u32)ARRAY_SIZE(golden_settings_iceland_a11));
  630. amdgpu_program_register_sequence(adev,
  631. iceland_golden_common_all,
  632. (const u32)ARRAY_SIZE(iceland_golden_common_all));
  633. break;
  634. case CHIP_FIJI:
  635. amdgpu_program_register_sequence(adev,
  636. fiji_mgcg_cgcg_init,
  637. (const u32)ARRAY_SIZE(fiji_mgcg_cgcg_init));
  638. amdgpu_program_register_sequence(adev,
  639. golden_settings_fiji_a10,
  640. (const u32)ARRAY_SIZE(golden_settings_fiji_a10));
  641. amdgpu_program_register_sequence(adev,
  642. fiji_golden_common_all,
  643. (const u32)ARRAY_SIZE(fiji_golden_common_all));
  644. break;
  645. case CHIP_TONGA:
  646. amdgpu_program_register_sequence(adev,
  647. tonga_mgcg_cgcg_init,
  648. (const u32)ARRAY_SIZE(tonga_mgcg_cgcg_init));
  649. amdgpu_program_register_sequence(adev,
  650. golden_settings_tonga_a11,
  651. (const u32)ARRAY_SIZE(golden_settings_tonga_a11));
  652. amdgpu_program_register_sequence(adev,
  653. tonga_golden_common_all,
  654. (const u32)ARRAY_SIZE(tonga_golden_common_all));
  655. break;
  656. case CHIP_POLARIS11:
  657. case CHIP_POLARIS12:
  658. amdgpu_program_register_sequence(adev,
  659. golden_settings_polaris11_a11,
  660. (const u32)ARRAY_SIZE(golden_settings_polaris11_a11));
  661. amdgpu_program_register_sequence(adev,
  662. polaris11_golden_common_all,
  663. (const u32)ARRAY_SIZE(polaris11_golden_common_all));
  664. break;
  665. case CHIP_POLARIS10:
  666. amdgpu_program_register_sequence(adev,
  667. golden_settings_polaris10_a11,
  668. (const u32)ARRAY_SIZE(golden_settings_polaris10_a11));
  669. amdgpu_program_register_sequence(adev,
  670. polaris10_golden_common_all,
  671. (const u32)ARRAY_SIZE(polaris10_golden_common_all));
  672. WREG32_SMC(ixCG_ACLK_CNTL, 0x0000001C);
  673. if (adev->pdev->revision == 0xc7 &&
  674. ((adev->pdev->subsystem_device == 0xb37 && adev->pdev->subsystem_vendor == 0x1002) ||
  675. (adev->pdev->subsystem_device == 0x4a8 && adev->pdev->subsystem_vendor == 0x1043) ||
  676. (adev->pdev->subsystem_device == 0x9480 && adev->pdev->subsystem_vendor == 0x1682))) {
  677. amdgpu_atombios_i2c_channel_trans(adev, 0x10, 0x96, 0x1E, 0xDD);
  678. amdgpu_atombios_i2c_channel_trans(adev, 0x10, 0x96, 0x1F, 0xD0);
  679. }
  680. break;
  681. case CHIP_CARRIZO:
  682. amdgpu_program_register_sequence(adev,
  683. cz_mgcg_cgcg_init,
  684. (const u32)ARRAY_SIZE(cz_mgcg_cgcg_init));
  685. amdgpu_program_register_sequence(adev,
  686. cz_golden_settings_a11,
  687. (const u32)ARRAY_SIZE(cz_golden_settings_a11));
  688. amdgpu_program_register_sequence(adev,
  689. cz_golden_common_all,
  690. (const u32)ARRAY_SIZE(cz_golden_common_all));
  691. break;
  692. case CHIP_STONEY:
  693. amdgpu_program_register_sequence(adev,
  694. stoney_mgcg_cgcg_init,
  695. (const u32)ARRAY_SIZE(stoney_mgcg_cgcg_init));
  696. amdgpu_program_register_sequence(adev,
  697. stoney_golden_settings_a11,
  698. (const u32)ARRAY_SIZE(stoney_golden_settings_a11));
  699. amdgpu_program_register_sequence(adev,
  700. stoney_golden_common_all,
  701. (const u32)ARRAY_SIZE(stoney_golden_common_all));
  702. break;
  703. default:
  704. break;
  705. }
  706. }
  707. static void gfx_v8_0_scratch_init(struct amdgpu_device *adev)
  708. {
  709. adev->gfx.scratch.num_reg = 8;
  710. adev->gfx.scratch.reg_base = mmSCRATCH_REG0;
  711. adev->gfx.scratch.free_mask = (1u << adev->gfx.scratch.num_reg) - 1;
  712. }
  713. static int gfx_v8_0_ring_test_ring(struct amdgpu_ring *ring)
  714. {
  715. struct amdgpu_device *adev = ring->adev;
  716. uint32_t scratch;
  717. uint32_t tmp = 0;
  718. unsigned i;
  719. int r;
  720. r = amdgpu_gfx_scratch_get(adev, &scratch);
  721. if (r) {
  722. DRM_ERROR("amdgpu: cp failed to get scratch reg (%d).\n", r);
  723. return r;
  724. }
  725. WREG32(scratch, 0xCAFEDEAD);
  726. r = amdgpu_ring_alloc(ring, 3);
  727. if (r) {
  728. DRM_ERROR("amdgpu: cp failed to lock ring %d (%d).\n",
  729. ring->idx, r);
  730. amdgpu_gfx_scratch_free(adev, scratch);
  731. return r;
  732. }
  733. amdgpu_ring_write(ring, PACKET3(PACKET3_SET_UCONFIG_REG, 1));
  734. amdgpu_ring_write(ring, (scratch - PACKET3_SET_UCONFIG_REG_START));
  735. amdgpu_ring_write(ring, 0xDEADBEEF);
  736. amdgpu_ring_commit(ring);
  737. for (i = 0; i < adev->usec_timeout; i++) {
  738. tmp = RREG32(scratch);
  739. if (tmp == 0xDEADBEEF)
  740. break;
  741. DRM_UDELAY(1);
  742. }
  743. if (i < adev->usec_timeout) {
  744. DRM_INFO("ring test on %d succeeded in %d usecs\n",
  745. ring->idx, i);
  746. } else {
  747. DRM_ERROR("amdgpu: ring %d test failed (scratch(0x%04X)=0x%08X)\n",
  748. ring->idx, scratch, tmp);
  749. r = -EINVAL;
  750. }
  751. amdgpu_gfx_scratch_free(adev, scratch);
  752. return r;
  753. }
  754. static int gfx_v8_0_ring_test_ib(struct amdgpu_ring *ring, long timeout)
  755. {
  756. struct amdgpu_device *adev = ring->adev;
  757. struct amdgpu_ib ib;
  758. struct dma_fence *f = NULL;
  759. uint32_t scratch;
  760. uint32_t tmp = 0;
  761. long r;
  762. r = amdgpu_gfx_scratch_get(adev, &scratch);
  763. if (r) {
  764. DRM_ERROR("amdgpu: failed to get scratch reg (%ld).\n", r);
  765. return r;
  766. }
  767. WREG32(scratch, 0xCAFEDEAD);
  768. memset(&ib, 0, sizeof(ib));
  769. r = amdgpu_ib_get(adev, NULL, 256, &ib);
  770. if (r) {
  771. DRM_ERROR("amdgpu: failed to get ib (%ld).\n", r);
  772. goto err1;
  773. }
  774. ib.ptr[0] = PACKET3(PACKET3_SET_UCONFIG_REG, 1);
  775. ib.ptr[1] = ((scratch - PACKET3_SET_UCONFIG_REG_START));
  776. ib.ptr[2] = 0xDEADBEEF;
  777. ib.length_dw = 3;
  778. r = amdgpu_ib_schedule(ring, 1, &ib, NULL, &f);
  779. if (r)
  780. goto err2;
  781. r = dma_fence_wait_timeout(f, false, timeout);
  782. if (r == 0) {
  783. DRM_ERROR("amdgpu: IB test timed out.\n");
  784. r = -ETIMEDOUT;
  785. goto err2;
  786. } else if (r < 0) {
  787. DRM_ERROR("amdgpu: fence wait failed (%ld).\n", r);
  788. goto err2;
  789. }
  790. tmp = RREG32(scratch);
  791. if (tmp == 0xDEADBEEF) {
  792. DRM_INFO("ib test on ring %d succeeded\n", ring->idx);
  793. r = 0;
  794. } else {
  795. DRM_ERROR("amdgpu: ib test failed (scratch(0x%04X)=0x%08X)\n",
  796. scratch, tmp);
  797. r = -EINVAL;
  798. }
  799. err2:
  800. amdgpu_ib_free(adev, &ib, NULL);
  801. dma_fence_put(f);
  802. err1:
  803. amdgpu_gfx_scratch_free(adev, scratch);
  804. return r;
  805. }
  806. static void gfx_v8_0_free_microcode(struct amdgpu_device *adev)
  807. {
  808. release_firmware(adev->gfx.pfp_fw);
  809. adev->gfx.pfp_fw = NULL;
  810. release_firmware(adev->gfx.me_fw);
  811. adev->gfx.me_fw = NULL;
  812. release_firmware(adev->gfx.ce_fw);
  813. adev->gfx.ce_fw = NULL;
  814. release_firmware(adev->gfx.rlc_fw);
  815. adev->gfx.rlc_fw = NULL;
  816. release_firmware(adev->gfx.mec_fw);
  817. adev->gfx.mec_fw = NULL;
  818. if ((adev->asic_type != CHIP_STONEY) &&
  819. (adev->asic_type != CHIP_TOPAZ))
  820. release_firmware(adev->gfx.mec2_fw);
  821. adev->gfx.mec2_fw = NULL;
  822. kfree(adev->gfx.rlc.register_list_format);
  823. }
  824. static int gfx_v8_0_init_microcode(struct amdgpu_device *adev)
  825. {
  826. const char *chip_name;
  827. char fw_name[30];
  828. int err;
  829. struct amdgpu_firmware_info *info = NULL;
  830. const struct common_firmware_header *header = NULL;
  831. const struct gfx_firmware_header_v1_0 *cp_hdr;
  832. const struct rlc_firmware_header_v2_0 *rlc_hdr;
  833. unsigned int *tmp = NULL, i;
  834. DRM_DEBUG("\n");
  835. switch (adev->asic_type) {
  836. case CHIP_TOPAZ:
  837. chip_name = "topaz";
  838. break;
  839. case CHIP_TONGA:
  840. chip_name = "tonga";
  841. break;
  842. case CHIP_CARRIZO:
  843. chip_name = "carrizo";
  844. break;
  845. case CHIP_FIJI:
  846. chip_name = "fiji";
  847. break;
  848. case CHIP_POLARIS11:
  849. chip_name = "polaris11";
  850. break;
  851. case CHIP_POLARIS10:
  852. chip_name = "polaris10";
  853. break;
  854. case CHIP_POLARIS12:
  855. chip_name = "polaris12";
  856. break;
  857. case CHIP_STONEY:
  858. chip_name = "stoney";
  859. break;
  860. default:
  861. BUG();
  862. }
  863. snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_pfp.bin", chip_name);
  864. err = request_firmware(&adev->gfx.pfp_fw, fw_name, adev->dev);
  865. if (err)
  866. goto out;
  867. err = amdgpu_ucode_validate(adev->gfx.pfp_fw);
  868. if (err)
  869. goto out;
  870. cp_hdr = (const struct gfx_firmware_header_v1_0 *)adev->gfx.pfp_fw->data;
  871. adev->gfx.pfp_fw_version = le32_to_cpu(cp_hdr->header.ucode_version);
  872. adev->gfx.pfp_feature_version = le32_to_cpu(cp_hdr->ucode_feature_version);
  873. snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_me.bin", chip_name);
  874. err = request_firmware(&adev->gfx.me_fw, fw_name, adev->dev);
  875. if (err)
  876. goto out;
  877. err = amdgpu_ucode_validate(adev->gfx.me_fw);
  878. if (err)
  879. goto out;
  880. cp_hdr = (const struct gfx_firmware_header_v1_0 *)adev->gfx.me_fw->data;
  881. adev->gfx.me_fw_version = le32_to_cpu(cp_hdr->header.ucode_version);
  882. adev->gfx.me_feature_version = le32_to_cpu(cp_hdr->ucode_feature_version);
  883. snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_ce.bin", chip_name);
  884. err = request_firmware(&adev->gfx.ce_fw, fw_name, adev->dev);
  885. if (err)
  886. goto out;
  887. err = amdgpu_ucode_validate(adev->gfx.ce_fw);
  888. if (err)
  889. goto out;
  890. cp_hdr = (const struct gfx_firmware_header_v1_0 *)adev->gfx.ce_fw->data;
  891. adev->gfx.ce_fw_version = le32_to_cpu(cp_hdr->header.ucode_version);
  892. adev->gfx.ce_feature_version = le32_to_cpu(cp_hdr->ucode_feature_version);
  893. /*
  894. * Support for MCBP/Virtualization in combination with chained IBs is
  895. * formal released on feature version #46
  896. */
  897. if (adev->gfx.ce_feature_version >= 46 &&
  898. adev->gfx.pfp_feature_version >= 46) {
  899. adev->virt.chained_ib_support = true;
  900. DRM_INFO("Chained IB support enabled!\n");
  901. } else
  902. adev->virt.chained_ib_support = false;
  903. snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_rlc.bin", chip_name);
  904. err = request_firmware(&adev->gfx.rlc_fw, fw_name, adev->dev);
  905. if (err)
  906. goto out;
  907. err = amdgpu_ucode_validate(adev->gfx.rlc_fw);
  908. rlc_hdr = (const struct rlc_firmware_header_v2_0 *)adev->gfx.rlc_fw->data;
  909. adev->gfx.rlc_fw_version = le32_to_cpu(rlc_hdr->header.ucode_version);
  910. adev->gfx.rlc_feature_version = le32_to_cpu(rlc_hdr->ucode_feature_version);
  911. adev->gfx.rlc.save_and_restore_offset =
  912. le32_to_cpu(rlc_hdr->save_and_restore_offset);
  913. adev->gfx.rlc.clear_state_descriptor_offset =
  914. le32_to_cpu(rlc_hdr->clear_state_descriptor_offset);
  915. adev->gfx.rlc.avail_scratch_ram_locations =
  916. le32_to_cpu(rlc_hdr->avail_scratch_ram_locations);
  917. adev->gfx.rlc.reg_restore_list_size =
  918. le32_to_cpu(rlc_hdr->reg_restore_list_size);
  919. adev->gfx.rlc.reg_list_format_start =
  920. le32_to_cpu(rlc_hdr->reg_list_format_start);
  921. adev->gfx.rlc.reg_list_format_separate_start =
  922. le32_to_cpu(rlc_hdr->reg_list_format_separate_start);
  923. adev->gfx.rlc.starting_offsets_start =
  924. le32_to_cpu(rlc_hdr->starting_offsets_start);
  925. adev->gfx.rlc.reg_list_format_size_bytes =
  926. le32_to_cpu(rlc_hdr->reg_list_format_size_bytes);
  927. adev->gfx.rlc.reg_list_size_bytes =
  928. le32_to_cpu(rlc_hdr->reg_list_size_bytes);
  929. adev->gfx.rlc.register_list_format =
  930. kmalloc(adev->gfx.rlc.reg_list_format_size_bytes +
  931. adev->gfx.rlc.reg_list_size_bytes, GFP_KERNEL);
  932. if (!adev->gfx.rlc.register_list_format) {
  933. err = -ENOMEM;
  934. goto out;
  935. }
  936. tmp = (unsigned int *)((uintptr_t)rlc_hdr +
  937. le32_to_cpu(rlc_hdr->reg_list_format_array_offset_bytes));
  938. for (i = 0 ; i < (rlc_hdr->reg_list_format_size_bytes >> 2); i++)
  939. adev->gfx.rlc.register_list_format[i] = le32_to_cpu(tmp[i]);
  940. adev->gfx.rlc.register_restore = adev->gfx.rlc.register_list_format + i;
  941. tmp = (unsigned int *)((uintptr_t)rlc_hdr +
  942. le32_to_cpu(rlc_hdr->reg_list_array_offset_bytes));
  943. for (i = 0 ; i < (rlc_hdr->reg_list_size_bytes >> 2); i++)
  944. adev->gfx.rlc.register_restore[i] = le32_to_cpu(tmp[i]);
  945. snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_mec.bin", chip_name);
  946. err = request_firmware(&adev->gfx.mec_fw, fw_name, adev->dev);
  947. if (err)
  948. goto out;
  949. err = amdgpu_ucode_validate(adev->gfx.mec_fw);
  950. if (err)
  951. goto out;
  952. cp_hdr = (const struct gfx_firmware_header_v1_0 *)adev->gfx.mec_fw->data;
  953. adev->gfx.mec_fw_version = le32_to_cpu(cp_hdr->header.ucode_version);
  954. adev->gfx.mec_feature_version = le32_to_cpu(cp_hdr->ucode_feature_version);
  955. if ((adev->asic_type != CHIP_STONEY) &&
  956. (adev->asic_type != CHIP_TOPAZ)) {
  957. snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_mec2.bin", chip_name);
  958. err = request_firmware(&adev->gfx.mec2_fw, fw_name, adev->dev);
  959. if (!err) {
  960. err = amdgpu_ucode_validate(adev->gfx.mec2_fw);
  961. if (err)
  962. goto out;
  963. cp_hdr = (const struct gfx_firmware_header_v1_0 *)
  964. adev->gfx.mec2_fw->data;
  965. adev->gfx.mec2_fw_version =
  966. le32_to_cpu(cp_hdr->header.ucode_version);
  967. adev->gfx.mec2_feature_version =
  968. le32_to_cpu(cp_hdr->ucode_feature_version);
  969. } else {
  970. err = 0;
  971. adev->gfx.mec2_fw = NULL;
  972. }
  973. }
  974. if (adev->firmware.load_type == AMDGPU_FW_LOAD_SMU) {
  975. info = &adev->firmware.ucode[AMDGPU_UCODE_ID_CP_PFP];
  976. info->ucode_id = AMDGPU_UCODE_ID_CP_PFP;
  977. info->fw = adev->gfx.pfp_fw;
  978. header = (const struct common_firmware_header *)info->fw->data;
  979. adev->firmware.fw_size +=
  980. ALIGN(le32_to_cpu(header->ucode_size_bytes), PAGE_SIZE);
  981. info = &adev->firmware.ucode[AMDGPU_UCODE_ID_CP_ME];
  982. info->ucode_id = AMDGPU_UCODE_ID_CP_ME;
  983. info->fw = adev->gfx.me_fw;
  984. header = (const struct common_firmware_header *)info->fw->data;
  985. adev->firmware.fw_size +=
  986. ALIGN(le32_to_cpu(header->ucode_size_bytes), PAGE_SIZE);
  987. info = &adev->firmware.ucode[AMDGPU_UCODE_ID_CP_CE];
  988. info->ucode_id = AMDGPU_UCODE_ID_CP_CE;
  989. info->fw = adev->gfx.ce_fw;
  990. header = (const struct common_firmware_header *)info->fw->data;
  991. adev->firmware.fw_size +=
  992. ALIGN(le32_to_cpu(header->ucode_size_bytes), PAGE_SIZE);
  993. info = &adev->firmware.ucode[AMDGPU_UCODE_ID_RLC_G];
  994. info->ucode_id = AMDGPU_UCODE_ID_RLC_G;
  995. info->fw = adev->gfx.rlc_fw;
  996. header = (const struct common_firmware_header *)info->fw->data;
  997. adev->firmware.fw_size +=
  998. ALIGN(le32_to_cpu(header->ucode_size_bytes), PAGE_SIZE);
  999. info = &adev->firmware.ucode[AMDGPU_UCODE_ID_CP_MEC1];
  1000. info->ucode_id = AMDGPU_UCODE_ID_CP_MEC1;
  1001. info->fw = adev->gfx.mec_fw;
  1002. header = (const struct common_firmware_header *)info->fw->data;
  1003. adev->firmware.fw_size +=
  1004. ALIGN(le32_to_cpu(header->ucode_size_bytes), PAGE_SIZE);
  1005. /* we need account JT in */
  1006. cp_hdr = (const struct gfx_firmware_header_v1_0 *)adev->gfx.mec_fw->data;
  1007. adev->firmware.fw_size +=
  1008. ALIGN(le32_to_cpu(cp_hdr->jt_size) << 2, PAGE_SIZE);
  1009. if (amdgpu_sriov_vf(adev)) {
  1010. info = &adev->firmware.ucode[AMDGPU_UCODE_ID_STORAGE];
  1011. info->ucode_id = AMDGPU_UCODE_ID_STORAGE;
  1012. info->fw = adev->gfx.mec_fw;
  1013. adev->firmware.fw_size +=
  1014. ALIGN(le32_to_cpu(64 * PAGE_SIZE), PAGE_SIZE);
  1015. }
  1016. if (adev->gfx.mec2_fw) {
  1017. info = &adev->firmware.ucode[AMDGPU_UCODE_ID_CP_MEC2];
  1018. info->ucode_id = AMDGPU_UCODE_ID_CP_MEC2;
  1019. info->fw = adev->gfx.mec2_fw;
  1020. header = (const struct common_firmware_header *)info->fw->data;
  1021. adev->firmware.fw_size +=
  1022. ALIGN(le32_to_cpu(header->ucode_size_bytes), PAGE_SIZE);
  1023. }
  1024. }
  1025. out:
  1026. if (err) {
  1027. dev_err(adev->dev,
  1028. "gfx8: Failed to load firmware \"%s\"\n",
  1029. fw_name);
  1030. release_firmware(adev->gfx.pfp_fw);
  1031. adev->gfx.pfp_fw = NULL;
  1032. release_firmware(adev->gfx.me_fw);
  1033. adev->gfx.me_fw = NULL;
  1034. release_firmware(adev->gfx.ce_fw);
  1035. adev->gfx.ce_fw = NULL;
  1036. release_firmware(adev->gfx.rlc_fw);
  1037. adev->gfx.rlc_fw = NULL;
  1038. release_firmware(adev->gfx.mec_fw);
  1039. adev->gfx.mec_fw = NULL;
  1040. release_firmware(adev->gfx.mec2_fw);
  1041. adev->gfx.mec2_fw = NULL;
  1042. }
  1043. return err;
  1044. }
  1045. static void gfx_v8_0_get_csb_buffer(struct amdgpu_device *adev,
  1046. volatile u32 *buffer)
  1047. {
  1048. u32 count = 0, i;
  1049. const struct cs_section_def *sect = NULL;
  1050. const struct cs_extent_def *ext = NULL;
  1051. if (adev->gfx.rlc.cs_data == NULL)
  1052. return;
  1053. if (buffer == NULL)
  1054. return;
  1055. buffer[count++] = cpu_to_le32(PACKET3(PACKET3_PREAMBLE_CNTL, 0));
  1056. buffer[count++] = cpu_to_le32(PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);
  1057. buffer[count++] = cpu_to_le32(PACKET3(PACKET3_CONTEXT_CONTROL, 1));
  1058. buffer[count++] = cpu_to_le32(0x80000000);
  1059. buffer[count++] = cpu_to_le32(0x80000000);
  1060. for (sect = adev->gfx.rlc.cs_data; sect->section != NULL; ++sect) {
  1061. for (ext = sect->section; ext->extent != NULL; ++ext) {
  1062. if (sect->id == SECT_CONTEXT) {
  1063. buffer[count++] =
  1064. cpu_to_le32(PACKET3(PACKET3_SET_CONTEXT_REG, ext->reg_count));
  1065. buffer[count++] = cpu_to_le32(ext->reg_index -
  1066. PACKET3_SET_CONTEXT_REG_START);
  1067. for (i = 0; i < ext->reg_count; i++)
  1068. buffer[count++] = cpu_to_le32(ext->extent[i]);
  1069. } else {
  1070. return;
  1071. }
  1072. }
  1073. }
  1074. buffer[count++] = cpu_to_le32(PACKET3(PACKET3_SET_CONTEXT_REG, 2));
  1075. buffer[count++] = cpu_to_le32(mmPA_SC_RASTER_CONFIG -
  1076. PACKET3_SET_CONTEXT_REG_START);
  1077. buffer[count++] = cpu_to_le32(adev->gfx.config.rb_config[0][0].raster_config);
  1078. buffer[count++] = cpu_to_le32(adev->gfx.config.rb_config[0][0].raster_config_1);
  1079. buffer[count++] = cpu_to_le32(PACKET3(PACKET3_PREAMBLE_CNTL, 0));
  1080. buffer[count++] = cpu_to_le32(PACKET3_PREAMBLE_END_CLEAR_STATE);
  1081. buffer[count++] = cpu_to_le32(PACKET3(PACKET3_CLEAR_STATE, 0));
  1082. buffer[count++] = cpu_to_le32(0);
  1083. }
  1084. static void cz_init_cp_jump_table(struct amdgpu_device *adev)
  1085. {
  1086. const __le32 *fw_data;
  1087. volatile u32 *dst_ptr;
  1088. int me, i, max_me = 4;
  1089. u32 bo_offset = 0;
  1090. u32 table_offset, table_size;
  1091. if (adev->asic_type == CHIP_CARRIZO)
  1092. max_me = 5;
  1093. /* write the cp table buffer */
  1094. dst_ptr = adev->gfx.rlc.cp_table_ptr;
  1095. for (me = 0; me < max_me; me++) {
  1096. if (me == 0) {
  1097. const struct gfx_firmware_header_v1_0 *hdr =
  1098. (const struct gfx_firmware_header_v1_0 *)adev->gfx.ce_fw->data;
  1099. fw_data = (const __le32 *)
  1100. (adev->gfx.ce_fw->data +
  1101. le32_to_cpu(hdr->header.ucode_array_offset_bytes));
  1102. table_offset = le32_to_cpu(hdr->jt_offset);
  1103. table_size = le32_to_cpu(hdr->jt_size);
  1104. } else if (me == 1) {
  1105. const struct gfx_firmware_header_v1_0 *hdr =
  1106. (const struct gfx_firmware_header_v1_0 *)adev->gfx.pfp_fw->data;
  1107. fw_data = (const __le32 *)
  1108. (adev->gfx.pfp_fw->data +
  1109. le32_to_cpu(hdr->header.ucode_array_offset_bytes));
  1110. table_offset = le32_to_cpu(hdr->jt_offset);
  1111. table_size = le32_to_cpu(hdr->jt_size);
  1112. } else if (me == 2) {
  1113. const struct gfx_firmware_header_v1_0 *hdr =
  1114. (const struct gfx_firmware_header_v1_0 *)adev->gfx.me_fw->data;
  1115. fw_data = (const __le32 *)
  1116. (adev->gfx.me_fw->data +
  1117. le32_to_cpu(hdr->header.ucode_array_offset_bytes));
  1118. table_offset = le32_to_cpu(hdr->jt_offset);
  1119. table_size = le32_to_cpu(hdr->jt_size);
  1120. } else if (me == 3) {
  1121. const struct gfx_firmware_header_v1_0 *hdr =
  1122. (const struct gfx_firmware_header_v1_0 *)adev->gfx.mec_fw->data;
  1123. fw_data = (const __le32 *)
  1124. (adev->gfx.mec_fw->data +
  1125. le32_to_cpu(hdr->header.ucode_array_offset_bytes));
  1126. table_offset = le32_to_cpu(hdr->jt_offset);
  1127. table_size = le32_to_cpu(hdr->jt_size);
  1128. } else if (me == 4) {
  1129. const struct gfx_firmware_header_v1_0 *hdr =
  1130. (const struct gfx_firmware_header_v1_0 *)adev->gfx.mec2_fw->data;
  1131. fw_data = (const __le32 *)
  1132. (adev->gfx.mec2_fw->data +
  1133. le32_to_cpu(hdr->header.ucode_array_offset_bytes));
  1134. table_offset = le32_to_cpu(hdr->jt_offset);
  1135. table_size = le32_to_cpu(hdr->jt_size);
  1136. }
  1137. for (i = 0; i < table_size; i ++) {
  1138. dst_ptr[bo_offset + i] =
  1139. cpu_to_le32(le32_to_cpu(fw_data[table_offset + i]));
  1140. }
  1141. bo_offset += table_size;
  1142. }
  1143. }
  1144. static void gfx_v8_0_rlc_fini(struct amdgpu_device *adev)
  1145. {
  1146. amdgpu_bo_free_kernel(&adev->gfx.rlc.clear_state_obj, NULL, NULL);
  1147. amdgpu_bo_free_kernel(&adev->gfx.rlc.cp_table_obj, NULL, NULL);
  1148. }
  1149. static int gfx_v8_0_rlc_init(struct amdgpu_device *adev)
  1150. {
  1151. volatile u32 *dst_ptr;
  1152. u32 dws;
  1153. const struct cs_section_def *cs_data;
  1154. int r;
  1155. adev->gfx.rlc.cs_data = vi_cs_data;
  1156. cs_data = adev->gfx.rlc.cs_data;
  1157. if (cs_data) {
  1158. /* clear state block */
  1159. adev->gfx.rlc.clear_state_size = dws = gfx_v8_0_get_csb_size(adev);
  1160. r = amdgpu_bo_create_reserved(adev, dws * 4, PAGE_SIZE,
  1161. AMDGPU_GEM_DOMAIN_VRAM,
  1162. &adev->gfx.rlc.clear_state_obj,
  1163. &adev->gfx.rlc.clear_state_gpu_addr,
  1164. (void **)&adev->gfx.rlc.cs_ptr);
  1165. if (r) {
  1166. dev_warn(adev->dev, "(%d) create RLC c bo failed\n", r);
  1167. gfx_v8_0_rlc_fini(adev);
  1168. return r;
  1169. }
  1170. /* set up the cs buffer */
  1171. dst_ptr = adev->gfx.rlc.cs_ptr;
  1172. gfx_v8_0_get_csb_buffer(adev, dst_ptr);
  1173. amdgpu_bo_kunmap(adev->gfx.rlc.clear_state_obj);
  1174. amdgpu_bo_unreserve(adev->gfx.rlc.clear_state_obj);
  1175. }
  1176. if ((adev->asic_type == CHIP_CARRIZO) ||
  1177. (adev->asic_type == CHIP_STONEY)) {
  1178. adev->gfx.rlc.cp_table_size = ALIGN(96 * 5 * 4, 2048) + (64 * 1024); /* JT + GDS */
  1179. r = amdgpu_bo_create_reserved(adev, adev->gfx.rlc.cp_table_size,
  1180. PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM,
  1181. &adev->gfx.rlc.cp_table_obj,
  1182. &adev->gfx.rlc.cp_table_gpu_addr,
  1183. (void **)&adev->gfx.rlc.cp_table_ptr);
  1184. if (r) {
  1185. dev_warn(adev->dev, "(%d) create RLC cp table bo failed\n", r);
  1186. return r;
  1187. }
  1188. cz_init_cp_jump_table(adev);
  1189. amdgpu_bo_kunmap(adev->gfx.rlc.cp_table_obj);
  1190. amdgpu_bo_unreserve(adev->gfx.rlc.cp_table_obj);
  1191. }
  1192. return 0;
  1193. }
  1194. static void gfx_v8_0_mec_fini(struct amdgpu_device *adev)
  1195. {
  1196. amdgpu_bo_free_kernel(&adev->gfx.mec.hpd_eop_obj, NULL, NULL);
  1197. }
  1198. static int gfx_v8_0_mec_init(struct amdgpu_device *adev)
  1199. {
  1200. int r;
  1201. u32 *hpd;
  1202. size_t mec_hpd_size;
  1203. bitmap_zero(adev->gfx.mec.queue_bitmap, AMDGPU_MAX_COMPUTE_QUEUES);
  1204. /* take ownership of the relevant compute queues */
  1205. amdgpu_gfx_compute_queue_acquire(adev);
  1206. mec_hpd_size = adev->gfx.num_compute_rings * GFX8_MEC_HPD_SIZE;
  1207. r = amdgpu_bo_create_reserved(adev, mec_hpd_size, PAGE_SIZE,
  1208. AMDGPU_GEM_DOMAIN_GTT,
  1209. &adev->gfx.mec.hpd_eop_obj,
  1210. &adev->gfx.mec.hpd_eop_gpu_addr,
  1211. (void **)&hpd);
  1212. if (r) {
  1213. dev_warn(adev->dev, "(%d) create HDP EOP bo failed\n", r);
  1214. return r;
  1215. }
  1216. memset(hpd, 0, mec_hpd_size);
  1217. amdgpu_bo_kunmap(adev->gfx.mec.hpd_eop_obj);
  1218. amdgpu_bo_unreserve(adev->gfx.mec.hpd_eop_obj);
  1219. return 0;
  1220. }
  1221. static const u32 vgpr_init_compute_shader[] =
  1222. {
  1223. 0x7e000209, 0x7e020208,
  1224. 0x7e040207, 0x7e060206,
  1225. 0x7e080205, 0x7e0a0204,
  1226. 0x7e0c0203, 0x7e0e0202,
  1227. 0x7e100201, 0x7e120200,
  1228. 0x7e140209, 0x7e160208,
  1229. 0x7e180207, 0x7e1a0206,
  1230. 0x7e1c0205, 0x7e1e0204,
  1231. 0x7e200203, 0x7e220202,
  1232. 0x7e240201, 0x7e260200,
  1233. 0x7e280209, 0x7e2a0208,
  1234. 0x7e2c0207, 0x7e2e0206,
  1235. 0x7e300205, 0x7e320204,
  1236. 0x7e340203, 0x7e360202,
  1237. 0x7e380201, 0x7e3a0200,
  1238. 0x7e3c0209, 0x7e3e0208,
  1239. 0x7e400207, 0x7e420206,
  1240. 0x7e440205, 0x7e460204,
  1241. 0x7e480203, 0x7e4a0202,
  1242. 0x7e4c0201, 0x7e4e0200,
  1243. 0x7e500209, 0x7e520208,
  1244. 0x7e540207, 0x7e560206,
  1245. 0x7e580205, 0x7e5a0204,
  1246. 0x7e5c0203, 0x7e5e0202,
  1247. 0x7e600201, 0x7e620200,
  1248. 0x7e640209, 0x7e660208,
  1249. 0x7e680207, 0x7e6a0206,
  1250. 0x7e6c0205, 0x7e6e0204,
  1251. 0x7e700203, 0x7e720202,
  1252. 0x7e740201, 0x7e760200,
  1253. 0x7e780209, 0x7e7a0208,
  1254. 0x7e7c0207, 0x7e7e0206,
  1255. 0xbf8a0000, 0xbf810000,
  1256. };
  1257. static const u32 sgpr_init_compute_shader[] =
  1258. {
  1259. 0xbe8a0100, 0xbe8c0102,
  1260. 0xbe8e0104, 0xbe900106,
  1261. 0xbe920108, 0xbe940100,
  1262. 0xbe960102, 0xbe980104,
  1263. 0xbe9a0106, 0xbe9c0108,
  1264. 0xbe9e0100, 0xbea00102,
  1265. 0xbea20104, 0xbea40106,
  1266. 0xbea60108, 0xbea80100,
  1267. 0xbeaa0102, 0xbeac0104,
  1268. 0xbeae0106, 0xbeb00108,
  1269. 0xbeb20100, 0xbeb40102,
  1270. 0xbeb60104, 0xbeb80106,
  1271. 0xbeba0108, 0xbebc0100,
  1272. 0xbebe0102, 0xbec00104,
  1273. 0xbec20106, 0xbec40108,
  1274. 0xbec60100, 0xbec80102,
  1275. 0xbee60004, 0xbee70005,
  1276. 0xbeea0006, 0xbeeb0007,
  1277. 0xbee80008, 0xbee90009,
  1278. 0xbefc0000, 0xbf8a0000,
  1279. 0xbf810000, 0x00000000,
  1280. };
  1281. static const u32 vgpr_init_regs[] =
  1282. {
  1283. mmCOMPUTE_STATIC_THREAD_MGMT_SE0, 0xffffffff,
  1284. mmCOMPUTE_RESOURCE_LIMITS, 0x1000000, /* CU_GROUP_COUNT=1 */
  1285. mmCOMPUTE_NUM_THREAD_X, 256*4,
  1286. mmCOMPUTE_NUM_THREAD_Y, 1,
  1287. mmCOMPUTE_NUM_THREAD_Z, 1,
  1288. mmCOMPUTE_PGM_RSRC1, 0x100004f, /* VGPRS=15 (64 logical VGPRs), SGPRS=1 (16 SGPRs), BULKY=1 */
  1289. mmCOMPUTE_PGM_RSRC2, 20,
  1290. mmCOMPUTE_USER_DATA_0, 0xedcedc00,
  1291. mmCOMPUTE_USER_DATA_1, 0xedcedc01,
  1292. mmCOMPUTE_USER_DATA_2, 0xedcedc02,
  1293. mmCOMPUTE_USER_DATA_3, 0xedcedc03,
  1294. mmCOMPUTE_USER_DATA_4, 0xedcedc04,
  1295. mmCOMPUTE_USER_DATA_5, 0xedcedc05,
  1296. mmCOMPUTE_USER_DATA_6, 0xedcedc06,
  1297. mmCOMPUTE_USER_DATA_7, 0xedcedc07,
  1298. mmCOMPUTE_USER_DATA_8, 0xedcedc08,
  1299. mmCOMPUTE_USER_DATA_9, 0xedcedc09,
  1300. };
  1301. static const u32 sgpr1_init_regs[] =
  1302. {
  1303. mmCOMPUTE_STATIC_THREAD_MGMT_SE0, 0x0f,
  1304. mmCOMPUTE_RESOURCE_LIMITS, 0x1000000, /* CU_GROUP_COUNT=1 */
  1305. mmCOMPUTE_NUM_THREAD_X, 256*5,
  1306. mmCOMPUTE_NUM_THREAD_Y, 1,
  1307. mmCOMPUTE_NUM_THREAD_Z, 1,
  1308. mmCOMPUTE_PGM_RSRC1, 0x240, /* SGPRS=9 (80 GPRS) */
  1309. mmCOMPUTE_PGM_RSRC2, 20,
  1310. mmCOMPUTE_USER_DATA_0, 0xedcedc00,
  1311. mmCOMPUTE_USER_DATA_1, 0xedcedc01,
  1312. mmCOMPUTE_USER_DATA_2, 0xedcedc02,
  1313. mmCOMPUTE_USER_DATA_3, 0xedcedc03,
  1314. mmCOMPUTE_USER_DATA_4, 0xedcedc04,
  1315. mmCOMPUTE_USER_DATA_5, 0xedcedc05,
  1316. mmCOMPUTE_USER_DATA_6, 0xedcedc06,
  1317. mmCOMPUTE_USER_DATA_7, 0xedcedc07,
  1318. mmCOMPUTE_USER_DATA_8, 0xedcedc08,
  1319. mmCOMPUTE_USER_DATA_9, 0xedcedc09,
  1320. };
  1321. static const u32 sgpr2_init_regs[] =
  1322. {
  1323. mmCOMPUTE_STATIC_THREAD_MGMT_SE0, 0xf0,
  1324. mmCOMPUTE_RESOURCE_LIMITS, 0x1000000,
  1325. mmCOMPUTE_NUM_THREAD_X, 256*5,
  1326. mmCOMPUTE_NUM_THREAD_Y, 1,
  1327. mmCOMPUTE_NUM_THREAD_Z, 1,
  1328. mmCOMPUTE_PGM_RSRC1, 0x240, /* SGPRS=9 (80 GPRS) */
  1329. mmCOMPUTE_PGM_RSRC2, 20,
  1330. mmCOMPUTE_USER_DATA_0, 0xedcedc00,
  1331. mmCOMPUTE_USER_DATA_1, 0xedcedc01,
  1332. mmCOMPUTE_USER_DATA_2, 0xedcedc02,
  1333. mmCOMPUTE_USER_DATA_3, 0xedcedc03,
  1334. mmCOMPUTE_USER_DATA_4, 0xedcedc04,
  1335. mmCOMPUTE_USER_DATA_5, 0xedcedc05,
  1336. mmCOMPUTE_USER_DATA_6, 0xedcedc06,
  1337. mmCOMPUTE_USER_DATA_7, 0xedcedc07,
  1338. mmCOMPUTE_USER_DATA_8, 0xedcedc08,
  1339. mmCOMPUTE_USER_DATA_9, 0xedcedc09,
  1340. };
  1341. static const u32 sec_ded_counter_registers[] =
  1342. {
  1343. mmCPC_EDC_ATC_CNT,
  1344. mmCPC_EDC_SCRATCH_CNT,
  1345. mmCPC_EDC_UCODE_CNT,
  1346. mmCPF_EDC_ATC_CNT,
  1347. mmCPF_EDC_ROQ_CNT,
  1348. mmCPF_EDC_TAG_CNT,
  1349. mmCPG_EDC_ATC_CNT,
  1350. mmCPG_EDC_DMA_CNT,
  1351. mmCPG_EDC_TAG_CNT,
  1352. mmDC_EDC_CSINVOC_CNT,
  1353. mmDC_EDC_RESTORE_CNT,
  1354. mmDC_EDC_STATE_CNT,
  1355. mmGDS_EDC_CNT,
  1356. mmGDS_EDC_GRBM_CNT,
  1357. mmGDS_EDC_OA_DED,
  1358. mmSPI_EDC_CNT,
  1359. mmSQC_ATC_EDC_GATCL1_CNT,
  1360. mmSQC_EDC_CNT,
  1361. mmSQ_EDC_DED_CNT,
  1362. mmSQ_EDC_INFO,
  1363. mmSQ_EDC_SEC_CNT,
  1364. mmTCC_EDC_CNT,
  1365. mmTCP_ATC_EDC_GATCL1_CNT,
  1366. mmTCP_EDC_CNT,
  1367. mmTD_EDC_CNT
  1368. };
  1369. static int gfx_v8_0_do_edc_gpr_workarounds(struct amdgpu_device *adev)
  1370. {
  1371. struct amdgpu_ring *ring = &adev->gfx.compute_ring[0];
  1372. struct amdgpu_ib ib;
  1373. struct dma_fence *f = NULL;
  1374. int r, i;
  1375. u32 tmp;
  1376. unsigned total_size, vgpr_offset, sgpr_offset;
  1377. u64 gpu_addr;
  1378. /* only supported on CZ */
  1379. if (adev->asic_type != CHIP_CARRIZO)
  1380. return 0;
  1381. /* bail if the compute ring is not ready */
  1382. if (!ring->ready)
  1383. return 0;
  1384. tmp = RREG32(mmGB_EDC_MODE);
  1385. WREG32(mmGB_EDC_MODE, 0);
  1386. total_size =
  1387. (((ARRAY_SIZE(vgpr_init_regs) / 2) * 3) + 4 + 5 + 2) * 4;
  1388. total_size +=
  1389. (((ARRAY_SIZE(sgpr1_init_regs) / 2) * 3) + 4 + 5 + 2) * 4;
  1390. total_size +=
  1391. (((ARRAY_SIZE(sgpr2_init_regs) / 2) * 3) + 4 + 5 + 2) * 4;
  1392. total_size = ALIGN(total_size, 256);
  1393. vgpr_offset = total_size;
  1394. total_size += ALIGN(sizeof(vgpr_init_compute_shader), 256);
  1395. sgpr_offset = total_size;
  1396. total_size += sizeof(sgpr_init_compute_shader);
  1397. /* allocate an indirect buffer to put the commands in */
  1398. memset(&ib, 0, sizeof(ib));
  1399. r = amdgpu_ib_get(adev, NULL, total_size, &ib);
  1400. if (r) {
  1401. DRM_ERROR("amdgpu: failed to get ib (%d).\n", r);
  1402. return r;
  1403. }
  1404. /* load the compute shaders */
  1405. for (i = 0; i < ARRAY_SIZE(vgpr_init_compute_shader); i++)
  1406. ib.ptr[i + (vgpr_offset / 4)] = vgpr_init_compute_shader[i];
  1407. for (i = 0; i < ARRAY_SIZE(sgpr_init_compute_shader); i++)
  1408. ib.ptr[i + (sgpr_offset / 4)] = sgpr_init_compute_shader[i];
  1409. /* init the ib length to 0 */
  1410. ib.length_dw = 0;
  1411. /* VGPR */
  1412. /* write the register state for the compute dispatch */
  1413. for (i = 0; i < ARRAY_SIZE(vgpr_init_regs); i += 2) {
  1414. ib.ptr[ib.length_dw++] = PACKET3(PACKET3_SET_SH_REG, 1);
  1415. ib.ptr[ib.length_dw++] = vgpr_init_regs[i] - PACKET3_SET_SH_REG_START;
  1416. ib.ptr[ib.length_dw++] = vgpr_init_regs[i + 1];
  1417. }
  1418. /* write the shader start address: mmCOMPUTE_PGM_LO, mmCOMPUTE_PGM_HI */
  1419. gpu_addr = (ib.gpu_addr + (u64)vgpr_offset) >> 8;
  1420. ib.ptr[ib.length_dw++] = PACKET3(PACKET3_SET_SH_REG, 2);
  1421. ib.ptr[ib.length_dw++] = mmCOMPUTE_PGM_LO - PACKET3_SET_SH_REG_START;
  1422. ib.ptr[ib.length_dw++] = lower_32_bits(gpu_addr);
  1423. ib.ptr[ib.length_dw++] = upper_32_bits(gpu_addr);
  1424. /* write dispatch packet */
  1425. ib.ptr[ib.length_dw++] = PACKET3(PACKET3_DISPATCH_DIRECT, 3);
  1426. ib.ptr[ib.length_dw++] = 8; /* x */
  1427. ib.ptr[ib.length_dw++] = 1; /* y */
  1428. ib.ptr[ib.length_dw++] = 1; /* z */
  1429. ib.ptr[ib.length_dw++] =
  1430. REG_SET_FIELD(0, COMPUTE_DISPATCH_INITIATOR, COMPUTE_SHADER_EN, 1);
  1431. /* write CS partial flush packet */
  1432. ib.ptr[ib.length_dw++] = PACKET3(PACKET3_EVENT_WRITE, 0);
  1433. ib.ptr[ib.length_dw++] = EVENT_TYPE(7) | EVENT_INDEX(4);
  1434. /* SGPR1 */
  1435. /* write the register state for the compute dispatch */
  1436. for (i = 0; i < ARRAY_SIZE(sgpr1_init_regs); i += 2) {
  1437. ib.ptr[ib.length_dw++] = PACKET3(PACKET3_SET_SH_REG, 1);
  1438. ib.ptr[ib.length_dw++] = sgpr1_init_regs[i] - PACKET3_SET_SH_REG_START;
  1439. ib.ptr[ib.length_dw++] = sgpr1_init_regs[i + 1];
  1440. }
  1441. /* write the shader start address: mmCOMPUTE_PGM_LO, mmCOMPUTE_PGM_HI */
  1442. gpu_addr = (ib.gpu_addr + (u64)sgpr_offset) >> 8;
  1443. ib.ptr[ib.length_dw++] = PACKET3(PACKET3_SET_SH_REG, 2);
  1444. ib.ptr[ib.length_dw++] = mmCOMPUTE_PGM_LO - PACKET3_SET_SH_REG_START;
  1445. ib.ptr[ib.length_dw++] = lower_32_bits(gpu_addr);
  1446. ib.ptr[ib.length_dw++] = upper_32_bits(gpu_addr);
  1447. /* write dispatch packet */
  1448. ib.ptr[ib.length_dw++] = PACKET3(PACKET3_DISPATCH_DIRECT, 3);
  1449. ib.ptr[ib.length_dw++] = 8; /* x */
  1450. ib.ptr[ib.length_dw++] = 1; /* y */
  1451. ib.ptr[ib.length_dw++] = 1; /* z */
  1452. ib.ptr[ib.length_dw++] =
  1453. REG_SET_FIELD(0, COMPUTE_DISPATCH_INITIATOR, COMPUTE_SHADER_EN, 1);
  1454. /* write CS partial flush packet */
  1455. ib.ptr[ib.length_dw++] = PACKET3(PACKET3_EVENT_WRITE, 0);
  1456. ib.ptr[ib.length_dw++] = EVENT_TYPE(7) | EVENT_INDEX(4);
  1457. /* SGPR2 */
  1458. /* write the register state for the compute dispatch */
  1459. for (i = 0; i < ARRAY_SIZE(sgpr2_init_regs); i += 2) {
  1460. ib.ptr[ib.length_dw++] = PACKET3(PACKET3_SET_SH_REG, 1);
  1461. ib.ptr[ib.length_dw++] = sgpr2_init_regs[i] - PACKET3_SET_SH_REG_START;
  1462. ib.ptr[ib.length_dw++] = sgpr2_init_regs[i + 1];
  1463. }
  1464. /* write the shader start address: mmCOMPUTE_PGM_LO, mmCOMPUTE_PGM_HI */
  1465. gpu_addr = (ib.gpu_addr + (u64)sgpr_offset) >> 8;
  1466. ib.ptr[ib.length_dw++] = PACKET3(PACKET3_SET_SH_REG, 2);
  1467. ib.ptr[ib.length_dw++] = mmCOMPUTE_PGM_LO - PACKET3_SET_SH_REG_START;
  1468. ib.ptr[ib.length_dw++] = lower_32_bits(gpu_addr);
  1469. ib.ptr[ib.length_dw++] = upper_32_bits(gpu_addr);
  1470. /* write dispatch packet */
  1471. ib.ptr[ib.length_dw++] = PACKET3(PACKET3_DISPATCH_DIRECT, 3);
  1472. ib.ptr[ib.length_dw++] = 8; /* x */
  1473. ib.ptr[ib.length_dw++] = 1; /* y */
  1474. ib.ptr[ib.length_dw++] = 1; /* z */
  1475. ib.ptr[ib.length_dw++] =
  1476. REG_SET_FIELD(0, COMPUTE_DISPATCH_INITIATOR, COMPUTE_SHADER_EN, 1);
  1477. /* write CS partial flush packet */
  1478. ib.ptr[ib.length_dw++] = PACKET3(PACKET3_EVENT_WRITE, 0);
  1479. ib.ptr[ib.length_dw++] = EVENT_TYPE(7) | EVENT_INDEX(4);
  1480. /* shedule the ib on the ring */
  1481. r = amdgpu_ib_schedule(ring, 1, &ib, NULL, &f);
  1482. if (r) {
  1483. DRM_ERROR("amdgpu: ib submit failed (%d).\n", r);
  1484. goto fail;
  1485. }
  1486. /* wait for the GPU to finish processing the IB */
  1487. r = dma_fence_wait(f, false);
  1488. if (r) {
  1489. DRM_ERROR("amdgpu: fence wait failed (%d).\n", r);
  1490. goto fail;
  1491. }
  1492. tmp = REG_SET_FIELD(tmp, GB_EDC_MODE, DED_MODE, 2);
  1493. tmp = REG_SET_FIELD(tmp, GB_EDC_MODE, PROP_FED, 1);
  1494. WREG32(mmGB_EDC_MODE, tmp);
  1495. tmp = RREG32(mmCC_GC_EDC_CONFIG);
  1496. tmp = REG_SET_FIELD(tmp, CC_GC_EDC_CONFIG, DIS_EDC, 0) | 1;
  1497. WREG32(mmCC_GC_EDC_CONFIG, tmp);
  1498. /* read back registers to clear the counters */
  1499. for (i = 0; i < ARRAY_SIZE(sec_ded_counter_registers); i++)
  1500. RREG32(sec_ded_counter_registers[i]);
  1501. fail:
  1502. amdgpu_ib_free(adev, &ib, NULL);
  1503. dma_fence_put(f);
  1504. return r;
  1505. }
  1506. static int gfx_v8_0_gpu_early_init(struct amdgpu_device *adev)
  1507. {
  1508. u32 gb_addr_config;
  1509. u32 mc_shared_chmap, mc_arb_ramcfg;
  1510. u32 dimm00_addr_map, dimm01_addr_map, dimm10_addr_map, dimm11_addr_map;
  1511. u32 tmp;
  1512. int ret;
  1513. switch (adev->asic_type) {
  1514. case CHIP_TOPAZ:
  1515. adev->gfx.config.max_shader_engines = 1;
  1516. adev->gfx.config.max_tile_pipes = 2;
  1517. adev->gfx.config.max_cu_per_sh = 6;
  1518. adev->gfx.config.max_sh_per_se = 1;
  1519. adev->gfx.config.max_backends_per_se = 2;
  1520. adev->gfx.config.max_texture_channel_caches = 2;
  1521. adev->gfx.config.max_gprs = 256;
  1522. adev->gfx.config.max_gs_threads = 32;
  1523. adev->gfx.config.max_hw_contexts = 8;
  1524. adev->gfx.config.sc_prim_fifo_size_frontend = 0x20;
  1525. adev->gfx.config.sc_prim_fifo_size_backend = 0x100;
  1526. adev->gfx.config.sc_hiz_tile_fifo_size = 0x30;
  1527. adev->gfx.config.sc_earlyz_tile_fifo_size = 0x130;
  1528. gb_addr_config = TOPAZ_GB_ADDR_CONFIG_GOLDEN;
  1529. break;
  1530. case CHIP_FIJI:
  1531. adev->gfx.config.max_shader_engines = 4;
  1532. adev->gfx.config.max_tile_pipes = 16;
  1533. adev->gfx.config.max_cu_per_sh = 16;
  1534. adev->gfx.config.max_sh_per_se = 1;
  1535. adev->gfx.config.max_backends_per_se = 4;
  1536. adev->gfx.config.max_texture_channel_caches = 16;
  1537. adev->gfx.config.max_gprs = 256;
  1538. adev->gfx.config.max_gs_threads = 32;
  1539. adev->gfx.config.max_hw_contexts = 8;
  1540. adev->gfx.config.sc_prim_fifo_size_frontend = 0x20;
  1541. adev->gfx.config.sc_prim_fifo_size_backend = 0x100;
  1542. adev->gfx.config.sc_hiz_tile_fifo_size = 0x30;
  1543. adev->gfx.config.sc_earlyz_tile_fifo_size = 0x130;
  1544. gb_addr_config = TONGA_GB_ADDR_CONFIG_GOLDEN;
  1545. break;
  1546. case CHIP_POLARIS11:
  1547. case CHIP_POLARIS12:
  1548. ret = amdgpu_atombios_get_gfx_info(adev);
  1549. if (ret)
  1550. return ret;
  1551. adev->gfx.config.max_gprs = 256;
  1552. adev->gfx.config.max_gs_threads = 32;
  1553. adev->gfx.config.max_hw_contexts = 8;
  1554. adev->gfx.config.sc_prim_fifo_size_frontend = 0x20;
  1555. adev->gfx.config.sc_prim_fifo_size_backend = 0x100;
  1556. adev->gfx.config.sc_hiz_tile_fifo_size = 0x30;
  1557. adev->gfx.config.sc_earlyz_tile_fifo_size = 0x130;
  1558. gb_addr_config = POLARIS11_GB_ADDR_CONFIG_GOLDEN;
  1559. break;
  1560. case CHIP_POLARIS10:
  1561. ret = amdgpu_atombios_get_gfx_info(adev);
  1562. if (ret)
  1563. return ret;
  1564. adev->gfx.config.max_gprs = 256;
  1565. adev->gfx.config.max_gs_threads = 32;
  1566. adev->gfx.config.max_hw_contexts = 8;
  1567. adev->gfx.config.sc_prim_fifo_size_frontend = 0x20;
  1568. adev->gfx.config.sc_prim_fifo_size_backend = 0x100;
  1569. adev->gfx.config.sc_hiz_tile_fifo_size = 0x30;
  1570. adev->gfx.config.sc_earlyz_tile_fifo_size = 0x130;
  1571. gb_addr_config = TONGA_GB_ADDR_CONFIG_GOLDEN;
  1572. break;
  1573. case CHIP_TONGA:
  1574. adev->gfx.config.max_shader_engines = 4;
  1575. adev->gfx.config.max_tile_pipes = 8;
  1576. adev->gfx.config.max_cu_per_sh = 8;
  1577. adev->gfx.config.max_sh_per_se = 1;
  1578. adev->gfx.config.max_backends_per_se = 2;
  1579. adev->gfx.config.max_texture_channel_caches = 8;
  1580. adev->gfx.config.max_gprs = 256;
  1581. adev->gfx.config.max_gs_threads = 32;
  1582. adev->gfx.config.max_hw_contexts = 8;
  1583. adev->gfx.config.sc_prim_fifo_size_frontend = 0x20;
  1584. adev->gfx.config.sc_prim_fifo_size_backend = 0x100;
  1585. adev->gfx.config.sc_hiz_tile_fifo_size = 0x30;
  1586. adev->gfx.config.sc_earlyz_tile_fifo_size = 0x130;
  1587. gb_addr_config = TONGA_GB_ADDR_CONFIG_GOLDEN;
  1588. break;
  1589. case CHIP_CARRIZO:
  1590. adev->gfx.config.max_shader_engines = 1;
  1591. adev->gfx.config.max_tile_pipes = 2;
  1592. adev->gfx.config.max_sh_per_se = 1;
  1593. adev->gfx.config.max_backends_per_se = 2;
  1594. adev->gfx.config.max_cu_per_sh = 8;
  1595. adev->gfx.config.max_texture_channel_caches = 2;
  1596. adev->gfx.config.max_gprs = 256;
  1597. adev->gfx.config.max_gs_threads = 32;
  1598. adev->gfx.config.max_hw_contexts = 8;
  1599. adev->gfx.config.sc_prim_fifo_size_frontend = 0x20;
  1600. adev->gfx.config.sc_prim_fifo_size_backend = 0x100;
  1601. adev->gfx.config.sc_hiz_tile_fifo_size = 0x30;
  1602. adev->gfx.config.sc_earlyz_tile_fifo_size = 0x130;
  1603. gb_addr_config = CARRIZO_GB_ADDR_CONFIG_GOLDEN;
  1604. break;
  1605. case CHIP_STONEY:
  1606. adev->gfx.config.max_shader_engines = 1;
  1607. adev->gfx.config.max_tile_pipes = 2;
  1608. adev->gfx.config.max_sh_per_se = 1;
  1609. adev->gfx.config.max_backends_per_se = 1;
  1610. adev->gfx.config.max_cu_per_sh = 3;
  1611. adev->gfx.config.max_texture_channel_caches = 2;
  1612. adev->gfx.config.max_gprs = 256;
  1613. adev->gfx.config.max_gs_threads = 16;
  1614. adev->gfx.config.max_hw_contexts = 8;
  1615. adev->gfx.config.sc_prim_fifo_size_frontend = 0x20;
  1616. adev->gfx.config.sc_prim_fifo_size_backend = 0x100;
  1617. adev->gfx.config.sc_hiz_tile_fifo_size = 0x30;
  1618. adev->gfx.config.sc_earlyz_tile_fifo_size = 0x130;
  1619. gb_addr_config = CARRIZO_GB_ADDR_CONFIG_GOLDEN;
  1620. break;
  1621. default:
  1622. adev->gfx.config.max_shader_engines = 2;
  1623. adev->gfx.config.max_tile_pipes = 4;
  1624. adev->gfx.config.max_cu_per_sh = 2;
  1625. adev->gfx.config.max_sh_per_se = 1;
  1626. adev->gfx.config.max_backends_per_se = 2;
  1627. adev->gfx.config.max_texture_channel_caches = 4;
  1628. adev->gfx.config.max_gprs = 256;
  1629. adev->gfx.config.max_gs_threads = 32;
  1630. adev->gfx.config.max_hw_contexts = 8;
  1631. adev->gfx.config.sc_prim_fifo_size_frontend = 0x20;
  1632. adev->gfx.config.sc_prim_fifo_size_backend = 0x100;
  1633. adev->gfx.config.sc_hiz_tile_fifo_size = 0x30;
  1634. adev->gfx.config.sc_earlyz_tile_fifo_size = 0x130;
  1635. gb_addr_config = TONGA_GB_ADDR_CONFIG_GOLDEN;
  1636. break;
  1637. }
  1638. mc_shared_chmap = RREG32(mmMC_SHARED_CHMAP);
  1639. adev->gfx.config.mc_arb_ramcfg = RREG32(mmMC_ARB_RAMCFG);
  1640. mc_arb_ramcfg = adev->gfx.config.mc_arb_ramcfg;
  1641. adev->gfx.config.num_tile_pipes = adev->gfx.config.max_tile_pipes;
  1642. adev->gfx.config.mem_max_burst_length_bytes = 256;
  1643. if (adev->flags & AMD_IS_APU) {
  1644. /* Get memory bank mapping mode. */
  1645. tmp = RREG32(mmMC_FUS_DRAM0_BANK_ADDR_MAPPING);
  1646. dimm00_addr_map = REG_GET_FIELD(tmp, MC_FUS_DRAM0_BANK_ADDR_MAPPING, DIMM0ADDRMAP);
  1647. dimm01_addr_map = REG_GET_FIELD(tmp, MC_FUS_DRAM0_BANK_ADDR_MAPPING, DIMM1ADDRMAP);
  1648. tmp = RREG32(mmMC_FUS_DRAM1_BANK_ADDR_MAPPING);
  1649. dimm10_addr_map = REG_GET_FIELD(tmp, MC_FUS_DRAM1_BANK_ADDR_MAPPING, DIMM0ADDRMAP);
  1650. dimm11_addr_map = REG_GET_FIELD(tmp, MC_FUS_DRAM1_BANK_ADDR_MAPPING, DIMM1ADDRMAP);
  1651. /* Validate settings in case only one DIMM installed. */
  1652. if ((dimm00_addr_map == 0) || (dimm00_addr_map == 3) || (dimm00_addr_map == 4) || (dimm00_addr_map > 12))
  1653. dimm00_addr_map = 0;
  1654. if ((dimm01_addr_map == 0) || (dimm01_addr_map == 3) || (dimm01_addr_map == 4) || (dimm01_addr_map > 12))
  1655. dimm01_addr_map = 0;
  1656. if ((dimm10_addr_map == 0) || (dimm10_addr_map == 3) || (dimm10_addr_map == 4) || (dimm10_addr_map > 12))
  1657. dimm10_addr_map = 0;
  1658. if ((dimm11_addr_map == 0) || (dimm11_addr_map == 3) || (dimm11_addr_map == 4) || (dimm11_addr_map > 12))
  1659. dimm11_addr_map = 0;
  1660. /* If DIMM Addr map is 8GB, ROW size should be 2KB. Otherwise 1KB. */
  1661. /* If ROW size(DIMM1) != ROW size(DMIMM0), ROW size should be larger one. */
  1662. if ((dimm00_addr_map == 11) || (dimm01_addr_map == 11) || (dimm10_addr_map == 11) || (dimm11_addr_map == 11))
  1663. adev->gfx.config.mem_row_size_in_kb = 2;
  1664. else
  1665. adev->gfx.config.mem_row_size_in_kb = 1;
  1666. } else {
  1667. tmp = REG_GET_FIELD(mc_arb_ramcfg, MC_ARB_RAMCFG, NOOFCOLS);
  1668. adev->gfx.config.mem_row_size_in_kb = (4 * (1 << (8 + tmp))) / 1024;
  1669. if (adev->gfx.config.mem_row_size_in_kb > 4)
  1670. adev->gfx.config.mem_row_size_in_kb = 4;
  1671. }
  1672. adev->gfx.config.shader_engine_tile_size = 32;
  1673. adev->gfx.config.num_gpus = 1;
  1674. adev->gfx.config.multi_gpu_tile_size = 64;
  1675. /* fix up row size */
  1676. switch (adev->gfx.config.mem_row_size_in_kb) {
  1677. case 1:
  1678. default:
  1679. gb_addr_config = REG_SET_FIELD(gb_addr_config, GB_ADDR_CONFIG, ROW_SIZE, 0);
  1680. break;
  1681. case 2:
  1682. gb_addr_config = REG_SET_FIELD(gb_addr_config, GB_ADDR_CONFIG, ROW_SIZE, 1);
  1683. break;
  1684. case 4:
  1685. gb_addr_config = REG_SET_FIELD(gb_addr_config, GB_ADDR_CONFIG, ROW_SIZE, 2);
  1686. break;
  1687. }
  1688. adev->gfx.config.gb_addr_config = gb_addr_config;
  1689. return 0;
  1690. }
  1691. static int gfx_v8_0_compute_ring_init(struct amdgpu_device *adev, int ring_id,
  1692. int mec, int pipe, int queue)
  1693. {
  1694. int r;
  1695. unsigned irq_type;
  1696. struct amdgpu_ring *ring = &adev->gfx.compute_ring[ring_id];
  1697. ring = &adev->gfx.compute_ring[ring_id];
  1698. /* mec0 is me1 */
  1699. ring->me = mec + 1;
  1700. ring->pipe = pipe;
  1701. ring->queue = queue;
  1702. ring->ring_obj = NULL;
  1703. ring->use_doorbell = true;
  1704. ring->doorbell_index = AMDGPU_DOORBELL_MEC_RING0 + ring_id;
  1705. ring->eop_gpu_addr = adev->gfx.mec.hpd_eop_gpu_addr
  1706. + (ring_id * GFX8_MEC_HPD_SIZE);
  1707. sprintf(ring->name, "comp_%d.%d.%d", ring->me, ring->pipe, ring->queue);
  1708. irq_type = AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP
  1709. + ((ring->me - 1) * adev->gfx.mec.num_pipe_per_mec)
  1710. + ring->pipe;
  1711. /* type-2 packets are deprecated on MEC, use type-3 instead */
  1712. r = amdgpu_ring_init(adev, ring, 1024,
  1713. &adev->gfx.eop_irq, irq_type);
  1714. if (r)
  1715. return r;
  1716. return 0;
  1717. }
  1718. static int gfx_v8_0_sw_init(void *handle)
  1719. {
  1720. int i, j, k, r, ring_id;
  1721. struct amdgpu_ring *ring;
  1722. struct amdgpu_kiq *kiq;
  1723. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  1724. switch (adev->asic_type) {
  1725. case CHIP_FIJI:
  1726. case CHIP_TONGA:
  1727. case CHIP_POLARIS11:
  1728. case CHIP_POLARIS12:
  1729. case CHIP_POLARIS10:
  1730. case CHIP_CARRIZO:
  1731. adev->gfx.mec.num_mec = 2;
  1732. break;
  1733. case CHIP_TOPAZ:
  1734. case CHIP_STONEY:
  1735. default:
  1736. adev->gfx.mec.num_mec = 1;
  1737. break;
  1738. }
  1739. adev->gfx.mec.num_pipe_per_mec = 4;
  1740. adev->gfx.mec.num_queue_per_pipe = 8;
  1741. /* KIQ event */
  1742. r = amdgpu_irq_add_id(adev, AMDGPU_IH_CLIENTID_LEGACY, 178, &adev->gfx.kiq.irq);
  1743. if (r)
  1744. return r;
  1745. /* EOP Event */
  1746. r = amdgpu_irq_add_id(adev, AMDGPU_IH_CLIENTID_LEGACY, 181, &adev->gfx.eop_irq);
  1747. if (r)
  1748. return r;
  1749. /* Privileged reg */
  1750. r = amdgpu_irq_add_id(adev, AMDGPU_IH_CLIENTID_LEGACY, 184,
  1751. &adev->gfx.priv_reg_irq);
  1752. if (r)
  1753. return r;
  1754. /* Privileged inst */
  1755. r = amdgpu_irq_add_id(adev, AMDGPU_IH_CLIENTID_LEGACY, 185,
  1756. &adev->gfx.priv_inst_irq);
  1757. if (r)
  1758. return r;
  1759. adev->gfx.gfx_current_status = AMDGPU_GFX_NORMAL_MODE;
  1760. gfx_v8_0_scratch_init(adev);
  1761. r = gfx_v8_0_init_microcode(adev);
  1762. if (r) {
  1763. DRM_ERROR("Failed to load gfx firmware!\n");
  1764. return r;
  1765. }
  1766. r = gfx_v8_0_rlc_init(adev);
  1767. if (r) {
  1768. DRM_ERROR("Failed to init rlc BOs!\n");
  1769. return r;
  1770. }
  1771. r = gfx_v8_0_mec_init(adev);
  1772. if (r) {
  1773. DRM_ERROR("Failed to init MEC BOs!\n");
  1774. return r;
  1775. }
  1776. /* set up the gfx ring */
  1777. for (i = 0; i < adev->gfx.num_gfx_rings; i++) {
  1778. ring = &adev->gfx.gfx_ring[i];
  1779. ring->ring_obj = NULL;
  1780. sprintf(ring->name, "gfx");
  1781. /* no gfx doorbells on iceland */
  1782. if (adev->asic_type != CHIP_TOPAZ) {
  1783. ring->use_doorbell = true;
  1784. ring->doorbell_index = AMDGPU_DOORBELL_GFX_RING0;
  1785. }
  1786. r = amdgpu_ring_init(adev, ring, 1024, &adev->gfx.eop_irq,
  1787. AMDGPU_CP_IRQ_GFX_EOP);
  1788. if (r)
  1789. return r;
  1790. }
  1791. /* set up the compute queues - allocate horizontally across pipes */
  1792. ring_id = 0;
  1793. for (i = 0; i < adev->gfx.mec.num_mec; ++i) {
  1794. for (j = 0; j < adev->gfx.mec.num_queue_per_pipe; j++) {
  1795. for (k = 0; k < adev->gfx.mec.num_pipe_per_mec; k++) {
  1796. if (!amdgpu_gfx_is_mec_queue_enabled(adev, i, k, j))
  1797. continue;
  1798. r = gfx_v8_0_compute_ring_init(adev,
  1799. ring_id,
  1800. i, k, j);
  1801. if (r)
  1802. return r;
  1803. ring_id++;
  1804. }
  1805. }
  1806. }
  1807. r = amdgpu_gfx_kiq_init(adev, GFX8_MEC_HPD_SIZE);
  1808. if (r) {
  1809. DRM_ERROR("Failed to init KIQ BOs!\n");
  1810. return r;
  1811. }
  1812. kiq = &adev->gfx.kiq;
  1813. r = amdgpu_gfx_kiq_init_ring(adev, &kiq->ring, &kiq->irq);
  1814. if (r)
  1815. return r;
  1816. /* create MQD for all compute queues as well as KIQ for SRIOV case */
  1817. r = amdgpu_gfx_compute_mqd_sw_init(adev, sizeof(struct vi_mqd_allocation));
  1818. if (r)
  1819. return r;
  1820. /* reserve GDS, GWS and OA resource for gfx */
  1821. r = amdgpu_bo_create_kernel(adev, adev->gds.mem.gfx_partition_size,
  1822. PAGE_SIZE, AMDGPU_GEM_DOMAIN_GDS,
  1823. &adev->gds.gds_gfx_bo, NULL, NULL);
  1824. if (r)
  1825. return r;
  1826. r = amdgpu_bo_create_kernel(adev, adev->gds.gws.gfx_partition_size,
  1827. PAGE_SIZE, AMDGPU_GEM_DOMAIN_GWS,
  1828. &adev->gds.gws_gfx_bo, NULL, NULL);
  1829. if (r)
  1830. return r;
  1831. r = amdgpu_bo_create_kernel(adev, adev->gds.oa.gfx_partition_size,
  1832. PAGE_SIZE, AMDGPU_GEM_DOMAIN_OA,
  1833. &adev->gds.oa_gfx_bo, NULL, NULL);
  1834. if (r)
  1835. return r;
  1836. adev->gfx.ce_ram_size = 0x8000;
  1837. r = gfx_v8_0_gpu_early_init(adev);
  1838. if (r)
  1839. return r;
  1840. return 0;
  1841. }
  1842. static int gfx_v8_0_sw_fini(void *handle)
  1843. {
  1844. int i;
  1845. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  1846. amdgpu_bo_free_kernel(&adev->gds.oa_gfx_bo, NULL, NULL);
  1847. amdgpu_bo_free_kernel(&adev->gds.gws_gfx_bo, NULL, NULL);
  1848. amdgpu_bo_free_kernel(&adev->gds.gds_gfx_bo, NULL, NULL);
  1849. for (i = 0; i < adev->gfx.num_gfx_rings; i++)
  1850. amdgpu_ring_fini(&adev->gfx.gfx_ring[i]);
  1851. for (i = 0; i < adev->gfx.num_compute_rings; i++)
  1852. amdgpu_ring_fini(&adev->gfx.compute_ring[i]);
  1853. amdgpu_gfx_compute_mqd_sw_fini(adev);
  1854. amdgpu_gfx_kiq_free_ring(&adev->gfx.kiq.ring, &adev->gfx.kiq.irq);
  1855. amdgpu_gfx_kiq_fini(adev);
  1856. gfx_v8_0_mec_fini(adev);
  1857. gfx_v8_0_rlc_fini(adev);
  1858. gfx_v8_0_free_microcode(adev);
  1859. return 0;
  1860. }
  1861. static void gfx_v8_0_tiling_mode_table_init(struct amdgpu_device *adev)
  1862. {
  1863. uint32_t *modearray, *mod2array;
  1864. const u32 num_tile_mode_states = ARRAY_SIZE(adev->gfx.config.tile_mode_array);
  1865. const u32 num_secondary_tile_mode_states = ARRAY_SIZE(adev->gfx.config.macrotile_mode_array);
  1866. u32 reg_offset;
  1867. modearray = adev->gfx.config.tile_mode_array;
  1868. mod2array = adev->gfx.config.macrotile_mode_array;
  1869. for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++)
  1870. modearray[reg_offset] = 0;
  1871. for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++)
  1872. mod2array[reg_offset] = 0;
  1873. switch (adev->asic_type) {
  1874. case CHIP_TOPAZ:
  1875. modearray[0] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1876. PIPE_CONFIG(ADDR_SURF_P2) |
  1877. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  1878. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  1879. modearray[1] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1880. PIPE_CONFIG(ADDR_SURF_P2) |
  1881. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
  1882. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  1883. modearray[2] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1884. PIPE_CONFIG(ADDR_SURF_P2) |
  1885. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  1886. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  1887. modearray[3] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1888. PIPE_CONFIG(ADDR_SURF_P2) |
  1889. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
  1890. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  1891. modearray[4] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1892. PIPE_CONFIG(ADDR_SURF_P2) |
  1893. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
  1894. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  1895. modearray[5] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  1896. PIPE_CONFIG(ADDR_SURF_P2) |
  1897. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
  1898. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  1899. modearray[6] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  1900. PIPE_CONFIG(ADDR_SURF_P2) |
  1901. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
  1902. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  1903. modearray[8] = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
  1904. PIPE_CONFIG(ADDR_SURF_P2));
  1905. modearray[9] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  1906. PIPE_CONFIG(ADDR_SURF_P2) |
  1907. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  1908. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  1909. modearray[10] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1910. PIPE_CONFIG(ADDR_SURF_P2) |
  1911. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  1912. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  1913. modearray[11] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  1914. PIPE_CONFIG(ADDR_SURF_P2) |
  1915. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  1916. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
  1917. modearray[13] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  1918. PIPE_CONFIG(ADDR_SURF_P2) |
  1919. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  1920. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  1921. modearray[14] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1922. PIPE_CONFIG(ADDR_SURF_P2) |
  1923. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  1924. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  1925. modearray[15] = (ARRAY_MODE(ARRAY_3D_TILED_THIN1) |
  1926. PIPE_CONFIG(ADDR_SURF_P2) |
  1927. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  1928. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  1929. modearray[16] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  1930. PIPE_CONFIG(ADDR_SURF_P2) |
  1931. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  1932. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
  1933. modearray[18] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
  1934. PIPE_CONFIG(ADDR_SURF_P2) |
  1935. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  1936. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  1937. modearray[19] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
  1938. PIPE_CONFIG(ADDR_SURF_P2) |
  1939. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  1940. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  1941. modearray[20] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
  1942. PIPE_CONFIG(ADDR_SURF_P2) |
  1943. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  1944. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  1945. modearray[21] = (ARRAY_MODE(ARRAY_3D_TILED_THICK) |
  1946. PIPE_CONFIG(ADDR_SURF_P2) |
  1947. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  1948. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  1949. modearray[22] = (ARRAY_MODE(ARRAY_PRT_TILED_THICK) |
  1950. PIPE_CONFIG(ADDR_SURF_P2) |
  1951. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  1952. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  1953. modearray[24] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
  1954. PIPE_CONFIG(ADDR_SURF_P2) |
  1955. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  1956. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  1957. modearray[25] = (ARRAY_MODE(ARRAY_2D_TILED_XTHICK) |
  1958. PIPE_CONFIG(ADDR_SURF_P2) |
  1959. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  1960. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  1961. modearray[26] = (ARRAY_MODE(ARRAY_3D_TILED_XTHICK) |
  1962. PIPE_CONFIG(ADDR_SURF_P2) |
  1963. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  1964. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  1965. modearray[27] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  1966. PIPE_CONFIG(ADDR_SURF_P2) |
  1967. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  1968. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  1969. modearray[28] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1970. PIPE_CONFIG(ADDR_SURF_P2) |
  1971. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  1972. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  1973. modearray[29] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  1974. PIPE_CONFIG(ADDR_SURF_P2) |
  1975. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  1976. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
  1977. mod2array[0] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_4) |
  1978. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  1979. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  1980. NUM_BANKS(ADDR_SURF_8_BANK));
  1981. mod2array[1] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_4) |
  1982. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  1983. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  1984. NUM_BANKS(ADDR_SURF_8_BANK));
  1985. mod2array[2] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
  1986. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  1987. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  1988. NUM_BANKS(ADDR_SURF_8_BANK));
  1989. mod2array[3] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1990. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  1991. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  1992. NUM_BANKS(ADDR_SURF_8_BANK));
  1993. mod2array[4] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1994. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  1995. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  1996. NUM_BANKS(ADDR_SURF_8_BANK));
  1997. mod2array[5] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1998. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  1999. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  2000. NUM_BANKS(ADDR_SURF_8_BANK));
  2001. mod2array[6] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2002. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2003. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  2004. NUM_BANKS(ADDR_SURF_8_BANK));
  2005. mod2array[8] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_4) |
  2006. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
  2007. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2008. NUM_BANKS(ADDR_SURF_16_BANK));
  2009. mod2array[9] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_4) |
  2010. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2011. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2012. NUM_BANKS(ADDR_SURF_16_BANK));
  2013. mod2array[10] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
  2014. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2015. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2016. NUM_BANKS(ADDR_SURF_16_BANK));
  2017. mod2array[11] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
  2018. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2019. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2020. NUM_BANKS(ADDR_SURF_16_BANK));
  2021. mod2array[12] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2022. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2023. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2024. NUM_BANKS(ADDR_SURF_16_BANK));
  2025. mod2array[13] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2026. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2027. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2028. NUM_BANKS(ADDR_SURF_16_BANK));
  2029. mod2array[14] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2030. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2031. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  2032. NUM_BANKS(ADDR_SURF_8_BANK));
  2033. for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++)
  2034. if (reg_offset != 7 && reg_offset != 12 && reg_offset != 17 &&
  2035. reg_offset != 23)
  2036. WREG32(mmGB_TILE_MODE0 + reg_offset, modearray[reg_offset]);
  2037. for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++)
  2038. if (reg_offset != 7)
  2039. WREG32(mmGB_MACROTILE_MODE0 + reg_offset, mod2array[reg_offset]);
  2040. break;
  2041. case CHIP_FIJI:
  2042. modearray[0] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2043. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  2044. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  2045. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  2046. modearray[1] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2047. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  2048. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
  2049. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  2050. modearray[2] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2051. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  2052. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2053. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  2054. modearray[3] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2055. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  2056. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
  2057. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  2058. modearray[4] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2059. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  2060. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
  2061. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  2062. modearray[5] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2063. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  2064. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
  2065. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  2066. modearray[6] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2067. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  2068. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
  2069. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  2070. modearray[7] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2071. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2072. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
  2073. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  2074. modearray[8] = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
  2075. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16));
  2076. modearray[9] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2077. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  2078. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2079. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2080. modearray[10] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2081. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  2082. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2083. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2084. modearray[11] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2085. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  2086. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2087. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
  2088. modearray[12] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2089. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2090. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2091. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
  2092. modearray[13] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2093. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  2094. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2095. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2096. modearray[14] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2097. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  2098. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2099. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2100. modearray[15] = (ARRAY_MODE(ARRAY_3D_TILED_THIN1) |
  2101. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  2102. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2103. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2104. modearray[16] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2105. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  2106. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2107. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
  2108. modearray[17] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2109. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2110. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2111. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
  2112. modearray[18] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
  2113. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  2114. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2115. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  2116. modearray[19] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
  2117. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  2118. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  2119. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  2120. modearray[20] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
  2121. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  2122. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  2123. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  2124. modearray[21] = (ARRAY_MODE(ARRAY_3D_TILED_THICK) |
  2125. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  2126. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  2127. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  2128. modearray[22] = (ARRAY_MODE(ARRAY_PRT_TILED_THICK) |
  2129. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  2130. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  2131. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  2132. modearray[23] = (ARRAY_MODE(ARRAY_PRT_TILED_THICK) |
  2133. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2134. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  2135. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  2136. modearray[24] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
  2137. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  2138. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2139. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  2140. modearray[25] = (ARRAY_MODE(ARRAY_2D_TILED_XTHICK) |
  2141. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  2142. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  2143. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  2144. modearray[26] = (ARRAY_MODE(ARRAY_3D_TILED_XTHICK) |
  2145. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  2146. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  2147. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  2148. modearray[27] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2149. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  2150. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  2151. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2152. modearray[28] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2153. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  2154. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  2155. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2156. modearray[29] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2157. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  2158. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  2159. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
  2160. modearray[30] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2161. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2162. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  2163. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
  2164. mod2array[0] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2165. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2166. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  2167. NUM_BANKS(ADDR_SURF_8_BANK));
  2168. mod2array[1] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2169. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2170. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  2171. NUM_BANKS(ADDR_SURF_8_BANK));
  2172. mod2array[2] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2173. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2174. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  2175. NUM_BANKS(ADDR_SURF_8_BANK));
  2176. mod2array[3] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2177. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2178. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  2179. NUM_BANKS(ADDR_SURF_8_BANK));
  2180. mod2array[4] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2181. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2182. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  2183. NUM_BANKS(ADDR_SURF_8_BANK));
  2184. mod2array[5] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2185. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2186. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  2187. NUM_BANKS(ADDR_SURF_8_BANK));
  2188. mod2array[6] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2189. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2190. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  2191. NUM_BANKS(ADDR_SURF_8_BANK));
  2192. mod2array[8] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2193. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
  2194. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  2195. NUM_BANKS(ADDR_SURF_8_BANK));
  2196. mod2array[9] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2197. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2198. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  2199. NUM_BANKS(ADDR_SURF_8_BANK));
  2200. mod2array[10] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2201. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2202. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  2203. NUM_BANKS(ADDR_SURF_8_BANK));
  2204. mod2array[11] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2205. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2206. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  2207. NUM_BANKS(ADDR_SURF_8_BANK));
  2208. mod2array[12] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2209. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2210. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  2211. NUM_BANKS(ADDR_SURF_8_BANK));
  2212. mod2array[13] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2213. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2214. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  2215. NUM_BANKS(ADDR_SURF_8_BANK));
  2216. mod2array[14] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2217. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2218. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  2219. NUM_BANKS(ADDR_SURF_4_BANK));
  2220. for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++)
  2221. WREG32(mmGB_TILE_MODE0 + reg_offset, modearray[reg_offset]);
  2222. for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++)
  2223. if (reg_offset != 7)
  2224. WREG32(mmGB_MACROTILE_MODE0 + reg_offset, mod2array[reg_offset]);
  2225. break;
  2226. case CHIP_TONGA:
  2227. modearray[0] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2228. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2229. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  2230. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  2231. modearray[1] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2232. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2233. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
  2234. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  2235. modearray[2] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2236. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2237. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2238. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  2239. modearray[3] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2240. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2241. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
  2242. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  2243. modearray[4] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2244. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2245. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
  2246. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  2247. modearray[5] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2248. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2249. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
  2250. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  2251. modearray[6] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2252. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2253. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
  2254. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  2255. modearray[7] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2256. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2257. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
  2258. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  2259. modearray[8] = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
  2260. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16));
  2261. modearray[9] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2262. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2263. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2264. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2265. modearray[10] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2266. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2267. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2268. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2269. modearray[11] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2270. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2271. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2272. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
  2273. modearray[12] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2274. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2275. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2276. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
  2277. modearray[13] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2278. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2279. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2280. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2281. modearray[14] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2282. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2283. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2284. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2285. modearray[15] = (ARRAY_MODE(ARRAY_3D_TILED_THIN1) |
  2286. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2287. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2288. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2289. modearray[16] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2290. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2291. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2292. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
  2293. modearray[17] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2294. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2295. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2296. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
  2297. modearray[18] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
  2298. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2299. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2300. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  2301. modearray[19] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
  2302. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2303. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  2304. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  2305. modearray[20] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
  2306. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2307. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  2308. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  2309. modearray[21] = (ARRAY_MODE(ARRAY_3D_TILED_THICK) |
  2310. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2311. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  2312. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  2313. modearray[22] = (ARRAY_MODE(ARRAY_PRT_TILED_THICK) |
  2314. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2315. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  2316. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  2317. modearray[23] = (ARRAY_MODE(ARRAY_PRT_TILED_THICK) |
  2318. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2319. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  2320. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  2321. modearray[24] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
  2322. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2323. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2324. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  2325. modearray[25] = (ARRAY_MODE(ARRAY_2D_TILED_XTHICK) |
  2326. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2327. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  2328. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  2329. modearray[26] = (ARRAY_MODE(ARRAY_3D_TILED_XTHICK) |
  2330. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2331. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  2332. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  2333. modearray[27] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2334. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2335. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  2336. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2337. modearray[28] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2338. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2339. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  2340. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2341. modearray[29] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2342. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2343. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  2344. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
  2345. modearray[30] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2346. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2347. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  2348. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
  2349. mod2array[0] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2350. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2351. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2352. NUM_BANKS(ADDR_SURF_16_BANK));
  2353. mod2array[1] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2354. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2355. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2356. NUM_BANKS(ADDR_SURF_16_BANK));
  2357. mod2array[2] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2358. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2359. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2360. NUM_BANKS(ADDR_SURF_16_BANK));
  2361. mod2array[3] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2362. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2363. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2364. NUM_BANKS(ADDR_SURF_16_BANK));
  2365. mod2array[4] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2366. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2367. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  2368. NUM_BANKS(ADDR_SURF_16_BANK));
  2369. mod2array[5] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2370. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2371. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  2372. NUM_BANKS(ADDR_SURF_16_BANK));
  2373. mod2array[6] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2374. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2375. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  2376. NUM_BANKS(ADDR_SURF_16_BANK));
  2377. mod2array[8] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2378. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
  2379. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2380. NUM_BANKS(ADDR_SURF_16_BANK));
  2381. mod2array[9] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2382. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2383. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2384. NUM_BANKS(ADDR_SURF_16_BANK));
  2385. mod2array[10] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2386. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2387. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  2388. NUM_BANKS(ADDR_SURF_16_BANK));
  2389. mod2array[11] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2390. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2391. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  2392. NUM_BANKS(ADDR_SURF_16_BANK));
  2393. mod2array[12] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2394. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2395. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  2396. NUM_BANKS(ADDR_SURF_8_BANK));
  2397. mod2array[13] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2398. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2399. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  2400. NUM_BANKS(ADDR_SURF_4_BANK));
  2401. mod2array[14] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2402. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2403. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  2404. NUM_BANKS(ADDR_SURF_4_BANK));
  2405. for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++)
  2406. WREG32(mmGB_TILE_MODE0 + reg_offset, modearray[reg_offset]);
  2407. for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++)
  2408. if (reg_offset != 7)
  2409. WREG32(mmGB_MACROTILE_MODE0 + reg_offset, mod2array[reg_offset]);
  2410. break;
  2411. case CHIP_POLARIS11:
  2412. case CHIP_POLARIS12:
  2413. modearray[0] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2414. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2415. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  2416. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  2417. modearray[1] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2418. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2419. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
  2420. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  2421. modearray[2] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2422. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2423. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2424. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  2425. modearray[3] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2426. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2427. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
  2428. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  2429. modearray[4] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2430. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2431. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
  2432. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  2433. modearray[5] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2434. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2435. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
  2436. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  2437. modearray[6] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2438. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2439. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
  2440. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  2441. modearray[7] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2442. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2443. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
  2444. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  2445. modearray[8] = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
  2446. PIPE_CONFIG(ADDR_SURF_P4_16x16));
  2447. modearray[9] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2448. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2449. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2450. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2451. modearray[10] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2452. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2453. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2454. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2455. modearray[11] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2456. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2457. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2458. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
  2459. modearray[12] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2460. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2461. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2462. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
  2463. modearray[13] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2464. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2465. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2466. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2467. modearray[14] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2468. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2469. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2470. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2471. modearray[15] = (ARRAY_MODE(ARRAY_3D_TILED_THIN1) |
  2472. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2473. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2474. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2475. modearray[16] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2476. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2477. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2478. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
  2479. modearray[17] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2480. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2481. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2482. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
  2483. modearray[18] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
  2484. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2485. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2486. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  2487. modearray[19] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
  2488. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2489. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  2490. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  2491. modearray[20] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
  2492. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2493. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  2494. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  2495. modearray[21] = (ARRAY_MODE(ARRAY_3D_TILED_THICK) |
  2496. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2497. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  2498. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  2499. modearray[22] = (ARRAY_MODE(ARRAY_PRT_TILED_THICK) |
  2500. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2501. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  2502. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  2503. modearray[23] = (ARRAY_MODE(ARRAY_PRT_TILED_THICK) |
  2504. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2505. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  2506. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  2507. modearray[24] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
  2508. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2509. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2510. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  2511. modearray[25] = (ARRAY_MODE(ARRAY_2D_TILED_XTHICK) |
  2512. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2513. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  2514. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  2515. modearray[26] = (ARRAY_MODE(ARRAY_3D_TILED_XTHICK) |
  2516. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2517. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  2518. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  2519. modearray[27] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2520. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2521. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  2522. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2523. modearray[28] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2524. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2525. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  2526. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2527. modearray[29] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2528. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2529. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  2530. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
  2531. modearray[30] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2532. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2533. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  2534. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
  2535. mod2array[0] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2536. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2537. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2538. NUM_BANKS(ADDR_SURF_16_BANK));
  2539. mod2array[1] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2540. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2541. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2542. NUM_BANKS(ADDR_SURF_16_BANK));
  2543. mod2array[2] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2544. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2545. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2546. NUM_BANKS(ADDR_SURF_16_BANK));
  2547. mod2array[3] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2548. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2549. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2550. NUM_BANKS(ADDR_SURF_16_BANK));
  2551. mod2array[4] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2552. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2553. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  2554. NUM_BANKS(ADDR_SURF_16_BANK));
  2555. mod2array[5] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2556. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2557. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  2558. NUM_BANKS(ADDR_SURF_16_BANK));
  2559. mod2array[6] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2560. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2561. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  2562. NUM_BANKS(ADDR_SURF_16_BANK));
  2563. mod2array[8] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
  2564. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
  2565. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2566. NUM_BANKS(ADDR_SURF_16_BANK));
  2567. mod2array[9] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
  2568. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2569. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2570. NUM_BANKS(ADDR_SURF_16_BANK));
  2571. mod2array[10] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2572. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2573. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2574. NUM_BANKS(ADDR_SURF_16_BANK));
  2575. mod2array[11] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2576. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2577. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2578. NUM_BANKS(ADDR_SURF_16_BANK));
  2579. mod2array[12] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2580. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2581. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  2582. NUM_BANKS(ADDR_SURF_16_BANK));
  2583. mod2array[13] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2584. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2585. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  2586. NUM_BANKS(ADDR_SURF_8_BANK));
  2587. mod2array[14] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2588. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2589. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  2590. NUM_BANKS(ADDR_SURF_4_BANK));
  2591. for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++)
  2592. WREG32(mmGB_TILE_MODE0 + reg_offset, modearray[reg_offset]);
  2593. for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++)
  2594. if (reg_offset != 7)
  2595. WREG32(mmGB_MACROTILE_MODE0 + reg_offset, mod2array[reg_offset]);
  2596. break;
  2597. case CHIP_POLARIS10:
  2598. modearray[0] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2599. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2600. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  2601. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  2602. modearray[1] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2603. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2604. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
  2605. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  2606. modearray[2] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2607. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2608. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2609. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  2610. modearray[3] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2611. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2612. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
  2613. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  2614. modearray[4] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2615. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2616. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
  2617. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  2618. modearray[5] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2619. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2620. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
  2621. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  2622. modearray[6] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2623. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2624. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
  2625. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  2626. modearray[7] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2627. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2628. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
  2629. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  2630. modearray[8] = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
  2631. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16));
  2632. modearray[9] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2633. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2634. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2635. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2636. modearray[10] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2637. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2638. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2639. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2640. modearray[11] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2641. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2642. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2643. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
  2644. modearray[12] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2645. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2646. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2647. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
  2648. modearray[13] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2649. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2650. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2651. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2652. modearray[14] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2653. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2654. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2655. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2656. modearray[15] = (ARRAY_MODE(ARRAY_3D_TILED_THIN1) |
  2657. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2658. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2659. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2660. modearray[16] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2661. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2662. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2663. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
  2664. modearray[17] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2665. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2666. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2667. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
  2668. modearray[18] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
  2669. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2670. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2671. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  2672. modearray[19] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
  2673. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2674. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  2675. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  2676. modearray[20] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
  2677. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2678. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  2679. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  2680. modearray[21] = (ARRAY_MODE(ARRAY_3D_TILED_THICK) |
  2681. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2682. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  2683. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  2684. modearray[22] = (ARRAY_MODE(ARRAY_PRT_TILED_THICK) |
  2685. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2686. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  2687. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  2688. modearray[23] = (ARRAY_MODE(ARRAY_PRT_TILED_THICK) |
  2689. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2690. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  2691. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  2692. modearray[24] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
  2693. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2694. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2695. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  2696. modearray[25] = (ARRAY_MODE(ARRAY_2D_TILED_XTHICK) |
  2697. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2698. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  2699. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  2700. modearray[26] = (ARRAY_MODE(ARRAY_3D_TILED_XTHICK) |
  2701. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2702. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  2703. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  2704. modearray[27] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2705. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2706. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  2707. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2708. modearray[28] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2709. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2710. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  2711. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2712. modearray[29] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2713. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2714. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  2715. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
  2716. modearray[30] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2717. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2718. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  2719. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
  2720. mod2array[0] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2721. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2722. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2723. NUM_BANKS(ADDR_SURF_16_BANK));
  2724. mod2array[1] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2725. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2726. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2727. NUM_BANKS(ADDR_SURF_16_BANK));
  2728. mod2array[2] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2729. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2730. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2731. NUM_BANKS(ADDR_SURF_16_BANK));
  2732. mod2array[3] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2733. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2734. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2735. NUM_BANKS(ADDR_SURF_16_BANK));
  2736. mod2array[4] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2737. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2738. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  2739. NUM_BANKS(ADDR_SURF_16_BANK));
  2740. mod2array[5] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2741. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2742. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  2743. NUM_BANKS(ADDR_SURF_16_BANK));
  2744. mod2array[6] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2745. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2746. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  2747. NUM_BANKS(ADDR_SURF_16_BANK));
  2748. mod2array[8] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2749. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
  2750. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2751. NUM_BANKS(ADDR_SURF_16_BANK));
  2752. mod2array[9] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2753. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2754. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2755. NUM_BANKS(ADDR_SURF_16_BANK));
  2756. mod2array[10] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2757. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2758. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  2759. NUM_BANKS(ADDR_SURF_16_BANK));
  2760. mod2array[11] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2761. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2762. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  2763. NUM_BANKS(ADDR_SURF_16_BANK));
  2764. mod2array[12] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2765. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2766. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  2767. NUM_BANKS(ADDR_SURF_8_BANK));
  2768. mod2array[13] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2769. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2770. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  2771. NUM_BANKS(ADDR_SURF_4_BANK));
  2772. mod2array[14] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2773. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2774. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  2775. NUM_BANKS(ADDR_SURF_4_BANK));
  2776. for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++)
  2777. WREG32(mmGB_TILE_MODE0 + reg_offset, modearray[reg_offset]);
  2778. for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++)
  2779. if (reg_offset != 7)
  2780. WREG32(mmGB_MACROTILE_MODE0 + reg_offset, mod2array[reg_offset]);
  2781. break;
  2782. case CHIP_STONEY:
  2783. modearray[0] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2784. PIPE_CONFIG(ADDR_SURF_P2) |
  2785. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  2786. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  2787. modearray[1] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2788. PIPE_CONFIG(ADDR_SURF_P2) |
  2789. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
  2790. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  2791. modearray[2] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2792. PIPE_CONFIG(ADDR_SURF_P2) |
  2793. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2794. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  2795. modearray[3] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2796. PIPE_CONFIG(ADDR_SURF_P2) |
  2797. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
  2798. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  2799. modearray[4] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2800. PIPE_CONFIG(ADDR_SURF_P2) |
  2801. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
  2802. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  2803. modearray[5] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2804. PIPE_CONFIG(ADDR_SURF_P2) |
  2805. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
  2806. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  2807. modearray[6] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2808. PIPE_CONFIG(ADDR_SURF_P2) |
  2809. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
  2810. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  2811. modearray[8] = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
  2812. PIPE_CONFIG(ADDR_SURF_P2));
  2813. modearray[9] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2814. PIPE_CONFIG(ADDR_SURF_P2) |
  2815. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2816. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2817. modearray[10] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2818. PIPE_CONFIG(ADDR_SURF_P2) |
  2819. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2820. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2821. modearray[11] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2822. PIPE_CONFIG(ADDR_SURF_P2) |
  2823. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2824. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
  2825. modearray[13] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2826. PIPE_CONFIG(ADDR_SURF_P2) |
  2827. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2828. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2829. modearray[14] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2830. PIPE_CONFIG(ADDR_SURF_P2) |
  2831. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2832. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2833. modearray[15] = (ARRAY_MODE(ARRAY_3D_TILED_THIN1) |
  2834. PIPE_CONFIG(ADDR_SURF_P2) |
  2835. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2836. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2837. modearray[16] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2838. PIPE_CONFIG(ADDR_SURF_P2) |
  2839. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2840. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
  2841. modearray[18] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
  2842. PIPE_CONFIG(ADDR_SURF_P2) |
  2843. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2844. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  2845. modearray[19] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
  2846. PIPE_CONFIG(ADDR_SURF_P2) |
  2847. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  2848. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  2849. modearray[20] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
  2850. PIPE_CONFIG(ADDR_SURF_P2) |
  2851. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  2852. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  2853. modearray[21] = (ARRAY_MODE(ARRAY_3D_TILED_THICK) |
  2854. PIPE_CONFIG(ADDR_SURF_P2) |
  2855. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  2856. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  2857. modearray[22] = (ARRAY_MODE(ARRAY_PRT_TILED_THICK) |
  2858. PIPE_CONFIG(ADDR_SURF_P2) |
  2859. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  2860. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  2861. modearray[24] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
  2862. PIPE_CONFIG(ADDR_SURF_P2) |
  2863. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2864. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  2865. modearray[25] = (ARRAY_MODE(ARRAY_2D_TILED_XTHICK) |
  2866. PIPE_CONFIG(ADDR_SURF_P2) |
  2867. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  2868. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  2869. modearray[26] = (ARRAY_MODE(ARRAY_3D_TILED_XTHICK) |
  2870. PIPE_CONFIG(ADDR_SURF_P2) |
  2871. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  2872. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  2873. modearray[27] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2874. PIPE_CONFIG(ADDR_SURF_P2) |
  2875. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  2876. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2877. modearray[28] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2878. PIPE_CONFIG(ADDR_SURF_P2) |
  2879. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  2880. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2881. modearray[29] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2882. PIPE_CONFIG(ADDR_SURF_P2) |
  2883. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  2884. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
  2885. mod2array[0] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2886. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2887. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2888. NUM_BANKS(ADDR_SURF_8_BANK));
  2889. mod2array[1] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2890. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2891. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2892. NUM_BANKS(ADDR_SURF_8_BANK));
  2893. mod2array[2] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2894. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2895. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  2896. NUM_BANKS(ADDR_SURF_8_BANK));
  2897. mod2array[3] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2898. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2899. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  2900. NUM_BANKS(ADDR_SURF_8_BANK));
  2901. mod2array[4] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2902. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2903. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  2904. NUM_BANKS(ADDR_SURF_8_BANK));
  2905. mod2array[5] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2906. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2907. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  2908. NUM_BANKS(ADDR_SURF_8_BANK));
  2909. mod2array[6] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2910. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2911. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  2912. NUM_BANKS(ADDR_SURF_8_BANK));
  2913. mod2array[8] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_4) |
  2914. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
  2915. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2916. NUM_BANKS(ADDR_SURF_16_BANK));
  2917. mod2array[9] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_4) |
  2918. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2919. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2920. NUM_BANKS(ADDR_SURF_16_BANK));
  2921. mod2array[10] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
  2922. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2923. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2924. NUM_BANKS(ADDR_SURF_16_BANK));
  2925. mod2array[11] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
  2926. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2927. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2928. NUM_BANKS(ADDR_SURF_16_BANK));
  2929. mod2array[12] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2930. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2931. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2932. NUM_BANKS(ADDR_SURF_16_BANK));
  2933. mod2array[13] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2934. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2935. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2936. NUM_BANKS(ADDR_SURF_16_BANK));
  2937. mod2array[14] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2938. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2939. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  2940. NUM_BANKS(ADDR_SURF_8_BANK));
  2941. for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++)
  2942. if (reg_offset != 7 && reg_offset != 12 && reg_offset != 17 &&
  2943. reg_offset != 23)
  2944. WREG32(mmGB_TILE_MODE0 + reg_offset, modearray[reg_offset]);
  2945. for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++)
  2946. if (reg_offset != 7)
  2947. WREG32(mmGB_MACROTILE_MODE0 + reg_offset, mod2array[reg_offset]);
  2948. break;
  2949. default:
  2950. dev_warn(adev->dev,
  2951. "Unknown chip type (%d) in function gfx_v8_0_tiling_mode_table_init() falling through to CHIP_CARRIZO\n",
  2952. adev->asic_type);
  2953. case CHIP_CARRIZO:
  2954. modearray[0] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2955. PIPE_CONFIG(ADDR_SURF_P2) |
  2956. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  2957. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  2958. modearray[1] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2959. PIPE_CONFIG(ADDR_SURF_P2) |
  2960. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
  2961. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  2962. modearray[2] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2963. PIPE_CONFIG(ADDR_SURF_P2) |
  2964. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2965. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  2966. modearray[3] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2967. PIPE_CONFIG(ADDR_SURF_P2) |
  2968. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
  2969. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  2970. modearray[4] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2971. PIPE_CONFIG(ADDR_SURF_P2) |
  2972. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
  2973. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  2974. modearray[5] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2975. PIPE_CONFIG(ADDR_SURF_P2) |
  2976. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
  2977. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  2978. modearray[6] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2979. PIPE_CONFIG(ADDR_SURF_P2) |
  2980. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
  2981. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  2982. modearray[8] = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
  2983. PIPE_CONFIG(ADDR_SURF_P2));
  2984. modearray[9] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2985. PIPE_CONFIG(ADDR_SURF_P2) |
  2986. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2987. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2988. modearray[10] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2989. PIPE_CONFIG(ADDR_SURF_P2) |
  2990. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2991. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2992. modearray[11] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2993. PIPE_CONFIG(ADDR_SURF_P2) |
  2994. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2995. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
  2996. modearray[13] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2997. PIPE_CONFIG(ADDR_SURF_P2) |
  2998. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2999. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  3000. modearray[14] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  3001. PIPE_CONFIG(ADDR_SURF_P2) |
  3002. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  3003. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  3004. modearray[15] = (ARRAY_MODE(ARRAY_3D_TILED_THIN1) |
  3005. PIPE_CONFIG(ADDR_SURF_P2) |
  3006. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  3007. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  3008. modearray[16] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  3009. PIPE_CONFIG(ADDR_SURF_P2) |
  3010. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  3011. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
  3012. modearray[18] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
  3013. PIPE_CONFIG(ADDR_SURF_P2) |
  3014. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  3015. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  3016. modearray[19] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
  3017. PIPE_CONFIG(ADDR_SURF_P2) |
  3018. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  3019. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  3020. modearray[20] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
  3021. PIPE_CONFIG(ADDR_SURF_P2) |
  3022. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  3023. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  3024. modearray[21] = (ARRAY_MODE(ARRAY_3D_TILED_THICK) |
  3025. PIPE_CONFIG(ADDR_SURF_P2) |
  3026. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  3027. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  3028. modearray[22] = (ARRAY_MODE(ARRAY_PRT_TILED_THICK) |
  3029. PIPE_CONFIG(ADDR_SURF_P2) |
  3030. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  3031. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  3032. modearray[24] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
  3033. PIPE_CONFIG(ADDR_SURF_P2) |
  3034. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  3035. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  3036. modearray[25] = (ARRAY_MODE(ARRAY_2D_TILED_XTHICK) |
  3037. PIPE_CONFIG(ADDR_SURF_P2) |
  3038. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  3039. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  3040. modearray[26] = (ARRAY_MODE(ARRAY_3D_TILED_XTHICK) |
  3041. PIPE_CONFIG(ADDR_SURF_P2) |
  3042. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  3043. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  3044. modearray[27] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  3045. PIPE_CONFIG(ADDR_SURF_P2) |
  3046. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  3047. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  3048. modearray[28] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  3049. PIPE_CONFIG(ADDR_SURF_P2) |
  3050. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  3051. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  3052. modearray[29] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  3053. PIPE_CONFIG(ADDR_SURF_P2) |
  3054. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  3055. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
  3056. mod2array[0] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  3057. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  3058. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  3059. NUM_BANKS(ADDR_SURF_8_BANK));
  3060. mod2array[1] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  3061. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  3062. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  3063. NUM_BANKS(ADDR_SURF_8_BANK));
  3064. mod2array[2] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  3065. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  3066. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  3067. NUM_BANKS(ADDR_SURF_8_BANK));
  3068. mod2array[3] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  3069. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  3070. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  3071. NUM_BANKS(ADDR_SURF_8_BANK));
  3072. mod2array[4] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  3073. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  3074. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  3075. NUM_BANKS(ADDR_SURF_8_BANK));
  3076. mod2array[5] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  3077. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  3078. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  3079. NUM_BANKS(ADDR_SURF_8_BANK));
  3080. mod2array[6] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  3081. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  3082. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  3083. NUM_BANKS(ADDR_SURF_8_BANK));
  3084. mod2array[8] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_4) |
  3085. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
  3086. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  3087. NUM_BANKS(ADDR_SURF_16_BANK));
  3088. mod2array[9] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_4) |
  3089. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  3090. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  3091. NUM_BANKS(ADDR_SURF_16_BANK));
  3092. mod2array[10] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
  3093. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  3094. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  3095. NUM_BANKS(ADDR_SURF_16_BANK));
  3096. mod2array[11] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
  3097. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  3098. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  3099. NUM_BANKS(ADDR_SURF_16_BANK));
  3100. mod2array[12] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  3101. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  3102. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  3103. NUM_BANKS(ADDR_SURF_16_BANK));
  3104. mod2array[13] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  3105. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  3106. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  3107. NUM_BANKS(ADDR_SURF_16_BANK));
  3108. mod2array[14] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  3109. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  3110. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  3111. NUM_BANKS(ADDR_SURF_8_BANK));
  3112. for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++)
  3113. if (reg_offset != 7 && reg_offset != 12 && reg_offset != 17 &&
  3114. reg_offset != 23)
  3115. WREG32(mmGB_TILE_MODE0 + reg_offset, modearray[reg_offset]);
  3116. for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++)
  3117. if (reg_offset != 7)
  3118. WREG32(mmGB_MACROTILE_MODE0 + reg_offset, mod2array[reg_offset]);
  3119. break;
  3120. }
  3121. }
  3122. static void gfx_v8_0_select_se_sh(struct amdgpu_device *adev,
  3123. u32 se_num, u32 sh_num, u32 instance)
  3124. {
  3125. u32 data;
  3126. if (instance == 0xffffffff)
  3127. data = REG_SET_FIELD(0, GRBM_GFX_INDEX, INSTANCE_BROADCAST_WRITES, 1);
  3128. else
  3129. data = REG_SET_FIELD(0, GRBM_GFX_INDEX, INSTANCE_INDEX, instance);
  3130. if (se_num == 0xffffffff)
  3131. data = REG_SET_FIELD(data, GRBM_GFX_INDEX, SE_BROADCAST_WRITES, 1);
  3132. else
  3133. data = REG_SET_FIELD(data, GRBM_GFX_INDEX, SE_INDEX, se_num);
  3134. if (sh_num == 0xffffffff)
  3135. data = REG_SET_FIELD(data, GRBM_GFX_INDEX, SH_BROADCAST_WRITES, 1);
  3136. else
  3137. data = REG_SET_FIELD(data, GRBM_GFX_INDEX, SH_INDEX, sh_num);
  3138. WREG32(mmGRBM_GFX_INDEX, data);
  3139. }
  3140. static u32 gfx_v8_0_get_rb_active_bitmap(struct amdgpu_device *adev)
  3141. {
  3142. u32 data, mask;
  3143. data = RREG32(mmCC_RB_BACKEND_DISABLE) |
  3144. RREG32(mmGC_USER_RB_BACKEND_DISABLE);
  3145. data = REG_GET_FIELD(data, GC_USER_RB_BACKEND_DISABLE, BACKEND_DISABLE);
  3146. mask = amdgpu_gfx_create_bitmask(adev->gfx.config.max_backends_per_se /
  3147. adev->gfx.config.max_sh_per_se);
  3148. return (~data) & mask;
  3149. }
  3150. static void
  3151. gfx_v8_0_raster_config(struct amdgpu_device *adev, u32 *rconf, u32 *rconf1)
  3152. {
  3153. switch (adev->asic_type) {
  3154. case CHIP_FIJI:
  3155. *rconf |= RB_MAP_PKR0(2) | RB_MAP_PKR1(2) |
  3156. RB_XSEL2(1) | PKR_MAP(2) |
  3157. PKR_XSEL(1) | PKR_YSEL(1) |
  3158. SE_MAP(2) | SE_XSEL(2) | SE_YSEL(3);
  3159. *rconf1 |= SE_PAIR_MAP(2) | SE_PAIR_XSEL(3) |
  3160. SE_PAIR_YSEL(2);
  3161. break;
  3162. case CHIP_TONGA:
  3163. case CHIP_POLARIS10:
  3164. *rconf |= RB_MAP_PKR0(2) | RB_XSEL2(1) | SE_MAP(2) |
  3165. SE_XSEL(1) | SE_YSEL(1);
  3166. *rconf1 |= SE_PAIR_MAP(2) | SE_PAIR_XSEL(2) |
  3167. SE_PAIR_YSEL(2);
  3168. break;
  3169. case CHIP_TOPAZ:
  3170. case CHIP_CARRIZO:
  3171. *rconf |= RB_MAP_PKR0(2);
  3172. *rconf1 |= 0x0;
  3173. break;
  3174. case CHIP_POLARIS11:
  3175. case CHIP_POLARIS12:
  3176. *rconf |= RB_MAP_PKR0(2) | RB_XSEL2(1) | SE_MAP(2) |
  3177. SE_XSEL(1) | SE_YSEL(1);
  3178. *rconf1 |= 0x0;
  3179. break;
  3180. case CHIP_STONEY:
  3181. *rconf |= 0x0;
  3182. *rconf1 |= 0x0;
  3183. break;
  3184. default:
  3185. DRM_ERROR("unknown asic: 0x%x\n", adev->asic_type);
  3186. break;
  3187. }
  3188. }
  3189. static void
  3190. gfx_v8_0_write_harvested_raster_configs(struct amdgpu_device *adev,
  3191. u32 raster_config, u32 raster_config_1,
  3192. unsigned rb_mask, unsigned num_rb)
  3193. {
  3194. unsigned sh_per_se = max_t(unsigned, adev->gfx.config.max_sh_per_se, 1);
  3195. unsigned num_se = max_t(unsigned, adev->gfx.config.max_shader_engines, 1);
  3196. unsigned rb_per_pkr = min_t(unsigned, num_rb / num_se / sh_per_se, 2);
  3197. unsigned rb_per_se = num_rb / num_se;
  3198. unsigned se_mask[4];
  3199. unsigned se;
  3200. se_mask[0] = ((1 << rb_per_se) - 1) & rb_mask;
  3201. se_mask[1] = (se_mask[0] << rb_per_se) & rb_mask;
  3202. se_mask[2] = (se_mask[1] << rb_per_se) & rb_mask;
  3203. se_mask[3] = (se_mask[2] << rb_per_se) & rb_mask;
  3204. WARN_ON(!(num_se == 1 || num_se == 2 || num_se == 4));
  3205. WARN_ON(!(sh_per_se == 1 || sh_per_se == 2));
  3206. WARN_ON(!(rb_per_pkr == 1 || rb_per_pkr == 2));
  3207. if ((num_se > 2) && ((!se_mask[0] && !se_mask[1]) ||
  3208. (!se_mask[2] && !se_mask[3]))) {
  3209. raster_config_1 &= ~SE_PAIR_MAP_MASK;
  3210. if (!se_mask[0] && !se_mask[1]) {
  3211. raster_config_1 |=
  3212. SE_PAIR_MAP(RASTER_CONFIG_SE_PAIR_MAP_3);
  3213. } else {
  3214. raster_config_1 |=
  3215. SE_PAIR_MAP(RASTER_CONFIG_SE_PAIR_MAP_0);
  3216. }
  3217. }
  3218. for (se = 0; se < num_se; se++) {
  3219. unsigned raster_config_se = raster_config;
  3220. unsigned pkr0_mask = ((1 << rb_per_pkr) - 1) << (se * rb_per_se);
  3221. unsigned pkr1_mask = pkr0_mask << rb_per_pkr;
  3222. int idx = (se / 2) * 2;
  3223. if ((num_se > 1) && (!se_mask[idx] || !se_mask[idx + 1])) {
  3224. raster_config_se &= ~SE_MAP_MASK;
  3225. if (!se_mask[idx]) {
  3226. raster_config_se |= SE_MAP(RASTER_CONFIG_SE_MAP_3);
  3227. } else {
  3228. raster_config_se |= SE_MAP(RASTER_CONFIG_SE_MAP_0);
  3229. }
  3230. }
  3231. pkr0_mask &= rb_mask;
  3232. pkr1_mask &= rb_mask;
  3233. if (rb_per_se > 2 && (!pkr0_mask || !pkr1_mask)) {
  3234. raster_config_se &= ~PKR_MAP_MASK;
  3235. if (!pkr0_mask) {
  3236. raster_config_se |= PKR_MAP(RASTER_CONFIG_PKR_MAP_3);
  3237. } else {
  3238. raster_config_se |= PKR_MAP(RASTER_CONFIG_PKR_MAP_0);
  3239. }
  3240. }
  3241. if (rb_per_se >= 2) {
  3242. unsigned rb0_mask = 1 << (se * rb_per_se);
  3243. unsigned rb1_mask = rb0_mask << 1;
  3244. rb0_mask &= rb_mask;
  3245. rb1_mask &= rb_mask;
  3246. if (!rb0_mask || !rb1_mask) {
  3247. raster_config_se &= ~RB_MAP_PKR0_MASK;
  3248. if (!rb0_mask) {
  3249. raster_config_se |=
  3250. RB_MAP_PKR0(RASTER_CONFIG_RB_MAP_3);
  3251. } else {
  3252. raster_config_se |=
  3253. RB_MAP_PKR0(RASTER_CONFIG_RB_MAP_0);
  3254. }
  3255. }
  3256. if (rb_per_se > 2) {
  3257. rb0_mask = 1 << (se * rb_per_se + rb_per_pkr);
  3258. rb1_mask = rb0_mask << 1;
  3259. rb0_mask &= rb_mask;
  3260. rb1_mask &= rb_mask;
  3261. if (!rb0_mask || !rb1_mask) {
  3262. raster_config_se &= ~RB_MAP_PKR1_MASK;
  3263. if (!rb0_mask) {
  3264. raster_config_se |=
  3265. RB_MAP_PKR1(RASTER_CONFIG_RB_MAP_3);
  3266. } else {
  3267. raster_config_se |=
  3268. RB_MAP_PKR1(RASTER_CONFIG_RB_MAP_0);
  3269. }
  3270. }
  3271. }
  3272. }
  3273. /* GRBM_GFX_INDEX has a different offset on VI */
  3274. gfx_v8_0_select_se_sh(adev, se, 0xffffffff, 0xffffffff);
  3275. WREG32(mmPA_SC_RASTER_CONFIG, raster_config_se);
  3276. WREG32(mmPA_SC_RASTER_CONFIG_1, raster_config_1);
  3277. }
  3278. /* GRBM_GFX_INDEX has a different offset on VI */
  3279. gfx_v8_0_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
  3280. }
  3281. static void gfx_v8_0_setup_rb(struct amdgpu_device *adev)
  3282. {
  3283. int i, j;
  3284. u32 data;
  3285. u32 raster_config = 0, raster_config_1 = 0;
  3286. u32 active_rbs = 0;
  3287. u32 rb_bitmap_width_per_sh = adev->gfx.config.max_backends_per_se /
  3288. adev->gfx.config.max_sh_per_se;
  3289. unsigned num_rb_pipes;
  3290. mutex_lock(&adev->grbm_idx_mutex);
  3291. for (i = 0; i < adev->gfx.config.max_shader_engines; i++) {
  3292. for (j = 0; j < adev->gfx.config.max_sh_per_se; j++) {
  3293. gfx_v8_0_select_se_sh(adev, i, j, 0xffffffff);
  3294. data = gfx_v8_0_get_rb_active_bitmap(adev);
  3295. active_rbs |= data << ((i * adev->gfx.config.max_sh_per_se + j) *
  3296. rb_bitmap_width_per_sh);
  3297. }
  3298. }
  3299. gfx_v8_0_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
  3300. adev->gfx.config.backend_enable_mask = active_rbs;
  3301. adev->gfx.config.num_rbs = hweight32(active_rbs);
  3302. num_rb_pipes = min_t(unsigned, adev->gfx.config.max_backends_per_se *
  3303. adev->gfx.config.max_shader_engines, 16);
  3304. gfx_v8_0_raster_config(adev, &raster_config, &raster_config_1);
  3305. if (!adev->gfx.config.backend_enable_mask ||
  3306. adev->gfx.config.num_rbs >= num_rb_pipes) {
  3307. WREG32(mmPA_SC_RASTER_CONFIG, raster_config);
  3308. WREG32(mmPA_SC_RASTER_CONFIG_1, raster_config_1);
  3309. } else {
  3310. gfx_v8_0_write_harvested_raster_configs(adev, raster_config, raster_config_1,
  3311. adev->gfx.config.backend_enable_mask,
  3312. num_rb_pipes);
  3313. }
  3314. /* cache the values for userspace */
  3315. for (i = 0; i < adev->gfx.config.max_shader_engines; i++) {
  3316. for (j = 0; j < adev->gfx.config.max_sh_per_se; j++) {
  3317. gfx_v8_0_select_se_sh(adev, i, j, 0xffffffff);
  3318. adev->gfx.config.rb_config[i][j].rb_backend_disable =
  3319. RREG32(mmCC_RB_BACKEND_DISABLE);
  3320. adev->gfx.config.rb_config[i][j].user_rb_backend_disable =
  3321. RREG32(mmGC_USER_RB_BACKEND_DISABLE);
  3322. adev->gfx.config.rb_config[i][j].raster_config =
  3323. RREG32(mmPA_SC_RASTER_CONFIG);
  3324. adev->gfx.config.rb_config[i][j].raster_config_1 =
  3325. RREG32(mmPA_SC_RASTER_CONFIG_1);
  3326. }
  3327. }
  3328. gfx_v8_0_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
  3329. mutex_unlock(&adev->grbm_idx_mutex);
  3330. }
  3331. /**
  3332. * gfx_v8_0_init_compute_vmid - gart enable
  3333. *
  3334. * @adev: amdgpu_device pointer
  3335. *
  3336. * Initialize compute vmid sh_mem registers
  3337. *
  3338. */
  3339. #define DEFAULT_SH_MEM_BASES (0x6000)
  3340. #define FIRST_COMPUTE_VMID (8)
  3341. #define LAST_COMPUTE_VMID (16)
  3342. static void gfx_v8_0_init_compute_vmid(struct amdgpu_device *adev)
  3343. {
  3344. int i;
  3345. uint32_t sh_mem_config;
  3346. uint32_t sh_mem_bases;
  3347. /*
  3348. * Configure apertures:
  3349. * LDS: 0x60000000'00000000 - 0x60000001'00000000 (4GB)
  3350. * Scratch: 0x60000001'00000000 - 0x60000002'00000000 (4GB)
  3351. * GPUVM: 0x60010000'00000000 - 0x60020000'00000000 (1TB)
  3352. */
  3353. sh_mem_bases = DEFAULT_SH_MEM_BASES | (DEFAULT_SH_MEM_BASES << 16);
  3354. sh_mem_config = SH_MEM_ADDRESS_MODE_HSA64 <<
  3355. SH_MEM_CONFIG__ADDRESS_MODE__SHIFT |
  3356. SH_MEM_ALIGNMENT_MODE_UNALIGNED <<
  3357. SH_MEM_CONFIG__ALIGNMENT_MODE__SHIFT |
  3358. MTYPE_CC << SH_MEM_CONFIG__DEFAULT_MTYPE__SHIFT |
  3359. SH_MEM_CONFIG__PRIVATE_ATC_MASK;
  3360. mutex_lock(&adev->srbm_mutex);
  3361. for (i = FIRST_COMPUTE_VMID; i < LAST_COMPUTE_VMID; i++) {
  3362. vi_srbm_select(adev, 0, 0, 0, i);
  3363. /* CP and shaders */
  3364. WREG32(mmSH_MEM_CONFIG, sh_mem_config);
  3365. WREG32(mmSH_MEM_APE1_BASE, 1);
  3366. WREG32(mmSH_MEM_APE1_LIMIT, 0);
  3367. WREG32(mmSH_MEM_BASES, sh_mem_bases);
  3368. }
  3369. vi_srbm_select(adev, 0, 0, 0, 0);
  3370. mutex_unlock(&adev->srbm_mutex);
  3371. }
  3372. static void gfx_v8_0_config_init(struct amdgpu_device *adev)
  3373. {
  3374. switch (adev->asic_type) {
  3375. default:
  3376. adev->gfx.config.double_offchip_lds_buf = 1;
  3377. break;
  3378. case CHIP_CARRIZO:
  3379. case CHIP_STONEY:
  3380. adev->gfx.config.double_offchip_lds_buf = 0;
  3381. break;
  3382. }
  3383. }
  3384. static void gfx_v8_0_gpu_init(struct amdgpu_device *adev)
  3385. {
  3386. u32 tmp, sh_static_mem_cfg;
  3387. int i;
  3388. WREG32_FIELD(GRBM_CNTL, READ_TIMEOUT, 0xFF);
  3389. WREG32(mmGB_ADDR_CONFIG, adev->gfx.config.gb_addr_config);
  3390. WREG32(mmHDP_ADDR_CONFIG, adev->gfx.config.gb_addr_config);
  3391. WREG32(mmDMIF_ADDR_CALC, adev->gfx.config.gb_addr_config);
  3392. gfx_v8_0_tiling_mode_table_init(adev);
  3393. gfx_v8_0_setup_rb(adev);
  3394. gfx_v8_0_get_cu_info(adev);
  3395. gfx_v8_0_config_init(adev);
  3396. /* XXX SH_MEM regs */
  3397. /* where to put LDS, scratch, GPUVM in FSA64 space */
  3398. sh_static_mem_cfg = REG_SET_FIELD(0, SH_STATIC_MEM_CONFIG,
  3399. SWIZZLE_ENABLE, 1);
  3400. sh_static_mem_cfg = REG_SET_FIELD(sh_static_mem_cfg, SH_STATIC_MEM_CONFIG,
  3401. ELEMENT_SIZE, 1);
  3402. sh_static_mem_cfg = REG_SET_FIELD(sh_static_mem_cfg, SH_STATIC_MEM_CONFIG,
  3403. INDEX_STRIDE, 3);
  3404. WREG32(mmSH_STATIC_MEM_CONFIG, sh_static_mem_cfg);
  3405. mutex_lock(&adev->srbm_mutex);
  3406. for (i = 0; i < adev->vm_manager.id_mgr[0].num_ids; i++) {
  3407. vi_srbm_select(adev, 0, 0, 0, i);
  3408. /* CP and shaders */
  3409. if (i == 0) {
  3410. tmp = REG_SET_FIELD(0, SH_MEM_CONFIG, DEFAULT_MTYPE, MTYPE_UC);
  3411. tmp = REG_SET_FIELD(tmp, SH_MEM_CONFIG, APE1_MTYPE, MTYPE_UC);
  3412. tmp = REG_SET_FIELD(tmp, SH_MEM_CONFIG, ALIGNMENT_MODE,
  3413. SH_MEM_ALIGNMENT_MODE_UNALIGNED);
  3414. WREG32(mmSH_MEM_CONFIG, tmp);
  3415. WREG32(mmSH_MEM_BASES, 0);
  3416. } else {
  3417. tmp = REG_SET_FIELD(0, SH_MEM_CONFIG, DEFAULT_MTYPE, MTYPE_NC);
  3418. tmp = REG_SET_FIELD(tmp, SH_MEM_CONFIG, APE1_MTYPE, MTYPE_UC);
  3419. tmp = REG_SET_FIELD(tmp, SH_MEM_CONFIG, ALIGNMENT_MODE,
  3420. SH_MEM_ALIGNMENT_MODE_UNALIGNED);
  3421. WREG32(mmSH_MEM_CONFIG, tmp);
  3422. tmp = adev->mc.shared_aperture_start >> 48;
  3423. WREG32(mmSH_MEM_BASES, tmp);
  3424. }
  3425. WREG32(mmSH_MEM_APE1_BASE, 1);
  3426. WREG32(mmSH_MEM_APE1_LIMIT, 0);
  3427. }
  3428. vi_srbm_select(adev, 0, 0, 0, 0);
  3429. mutex_unlock(&adev->srbm_mutex);
  3430. gfx_v8_0_init_compute_vmid(adev);
  3431. mutex_lock(&adev->grbm_idx_mutex);
  3432. /*
  3433. * making sure that the following register writes will be broadcasted
  3434. * to all the shaders
  3435. */
  3436. gfx_v8_0_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
  3437. WREG32(mmPA_SC_FIFO_SIZE,
  3438. (adev->gfx.config.sc_prim_fifo_size_frontend <<
  3439. PA_SC_FIFO_SIZE__SC_FRONTEND_PRIM_FIFO_SIZE__SHIFT) |
  3440. (adev->gfx.config.sc_prim_fifo_size_backend <<
  3441. PA_SC_FIFO_SIZE__SC_BACKEND_PRIM_FIFO_SIZE__SHIFT) |
  3442. (adev->gfx.config.sc_hiz_tile_fifo_size <<
  3443. PA_SC_FIFO_SIZE__SC_HIZ_TILE_FIFO_SIZE__SHIFT) |
  3444. (adev->gfx.config.sc_earlyz_tile_fifo_size <<
  3445. PA_SC_FIFO_SIZE__SC_EARLYZ_TILE_FIFO_SIZE__SHIFT));
  3446. tmp = RREG32(mmSPI_ARB_PRIORITY);
  3447. tmp = REG_SET_FIELD(tmp, SPI_ARB_PRIORITY, PIPE_ORDER_TS0, 2);
  3448. tmp = REG_SET_FIELD(tmp, SPI_ARB_PRIORITY, PIPE_ORDER_TS1, 2);
  3449. tmp = REG_SET_FIELD(tmp, SPI_ARB_PRIORITY, PIPE_ORDER_TS2, 2);
  3450. tmp = REG_SET_FIELD(tmp, SPI_ARB_PRIORITY, PIPE_ORDER_TS3, 2);
  3451. WREG32(mmSPI_ARB_PRIORITY, tmp);
  3452. mutex_unlock(&adev->grbm_idx_mutex);
  3453. }
  3454. static void gfx_v8_0_wait_for_rlc_serdes(struct amdgpu_device *adev)
  3455. {
  3456. u32 i, j, k;
  3457. u32 mask;
  3458. mutex_lock(&adev->grbm_idx_mutex);
  3459. for (i = 0; i < adev->gfx.config.max_shader_engines; i++) {
  3460. for (j = 0; j < adev->gfx.config.max_sh_per_se; j++) {
  3461. gfx_v8_0_select_se_sh(adev, i, j, 0xffffffff);
  3462. for (k = 0; k < adev->usec_timeout; k++) {
  3463. if (RREG32(mmRLC_SERDES_CU_MASTER_BUSY) == 0)
  3464. break;
  3465. udelay(1);
  3466. }
  3467. }
  3468. }
  3469. gfx_v8_0_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
  3470. mutex_unlock(&adev->grbm_idx_mutex);
  3471. mask = RLC_SERDES_NONCU_MASTER_BUSY__SE_MASTER_BUSY_MASK |
  3472. RLC_SERDES_NONCU_MASTER_BUSY__GC_MASTER_BUSY_MASK |
  3473. RLC_SERDES_NONCU_MASTER_BUSY__TC0_MASTER_BUSY_MASK |
  3474. RLC_SERDES_NONCU_MASTER_BUSY__TC1_MASTER_BUSY_MASK;
  3475. for (k = 0; k < adev->usec_timeout; k++) {
  3476. if ((RREG32(mmRLC_SERDES_NONCU_MASTER_BUSY) & mask) == 0)
  3477. break;
  3478. udelay(1);
  3479. }
  3480. }
  3481. static void gfx_v8_0_enable_gui_idle_interrupt(struct amdgpu_device *adev,
  3482. bool enable)
  3483. {
  3484. u32 tmp = RREG32(mmCP_INT_CNTL_RING0);
  3485. tmp = REG_SET_FIELD(tmp, CP_INT_CNTL_RING0, CNTX_BUSY_INT_ENABLE, enable ? 1 : 0);
  3486. tmp = REG_SET_FIELD(tmp, CP_INT_CNTL_RING0, CNTX_EMPTY_INT_ENABLE, enable ? 1 : 0);
  3487. tmp = REG_SET_FIELD(tmp, CP_INT_CNTL_RING0, CMP_BUSY_INT_ENABLE, enable ? 1 : 0);
  3488. tmp = REG_SET_FIELD(tmp, CP_INT_CNTL_RING0, GFX_IDLE_INT_ENABLE, enable ? 1 : 0);
  3489. WREG32(mmCP_INT_CNTL_RING0, tmp);
  3490. }
  3491. static void gfx_v8_0_init_csb(struct amdgpu_device *adev)
  3492. {
  3493. /* csib */
  3494. WREG32(mmRLC_CSIB_ADDR_HI,
  3495. adev->gfx.rlc.clear_state_gpu_addr >> 32);
  3496. WREG32(mmRLC_CSIB_ADDR_LO,
  3497. adev->gfx.rlc.clear_state_gpu_addr & 0xfffffffc);
  3498. WREG32(mmRLC_CSIB_LENGTH,
  3499. adev->gfx.rlc.clear_state_size);
  3500. }
  3501. static void gfx_v8_0_parse_ind_reg_list(int *register_list_format,
  3502. int ind_offset,
  3503. int list_size,
  3504. int *unique_indices,
  3505. int *indices_count,
  3506. int max_indices,
  3507. int *ind_start_offsets,
  3508. int *offset_count,
  3509. int max_offset)
  3510. {
  3511. int indices;
  3512. bool new_entry = true;
  3513. for (; ind_offset < list_size; ind_offset++) {
  3514. if (new_entry) {
  3515. new_entry = false;
  3516. ind_start_offsets[*offset_count] = ind_offset;
  3517. *offset_count = *offset_count + 1;
  3518. BUG_ON(*offset_count >= max_offset);
  3519. }
  3520. if (register_list_format[ind_offset] == 0xFFFFFFFF) {
  3521. new_entry = true;
  3522. continue;
  3523. }
  3524. ind_offset += 2;
  3525. /* look for the matching indice */
  3526. for (indices = 0;
  3527. indices < *indices_count;
  3528. indices++) {
  3529. if (unique_indices[indices] ==
  3530. register_list_format[ind_offset])
  3531. break;
  3532. }
  3533. if (indices >= *indices_count) {
  3534. unique_indices[*indices_count] =
  3535. register_list_format[ind_offset];
  3536. indices = *indices_count;
  3537. *indices_count = *indices_count + 1;
  3538. BUG_ON(*indices_count >= max_indices);
  3539. }
  3540. register_list_format[ind_offset] = indices;
  3541. }
  3542. }
  3543. static int gfx_v8_0_init_save_restore_list(struct amdgpu_device *adev)
  3544. {
  3545. int i, temp, data;
  3546. int unique_indices[] = {0, 0, 0, 0, 0, 0, 0, 0};
  3547. int indices_count = 0;
  3548. int indirect_start_offsets[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  3549. int offset_count = 0;
  3550. int list_size;
  3551. unsigned int *register_list_format =
  3552. kmalloc(adev->gfx.rlc.reg_list_format_size_bytes, GFP_KERNEL);
  3553. if (!register_list_format)
  3554. return -ENOMEM;
  3555. memcpy(register_list_format, adev->gfx.rlc.register_list_format,
  3556. adev->gfx.rlc.reg_list_format_size_bytes);
  3557. gfx_v8_0_parse_ind_reg_list(register_list_format,
  3558. RLC_FormatDirectRegListLength,
  3559. adev->gfx.rlc.reg_list_format_size_bytes >> 2,
  3560. unique_indices,
  3561. &indices_count,
  3562. sizeof(unique_indices) / sizeof(int),
  3563. indirect_start_offsets,
  3564. &offset_count,
  3565. sizeof(indirect_start_offsets)/sizeof(int));
  3566. /* save and restore list */
  3567. WREG32_FIELD(RLC_SRM_CNTL, AUTO_INCR_ADDR, 1);
  3568. WREG32(mmRLC_SRM_ARAM_ADDR, 0);
  3569. for (i = 0; i < adev->gfx.rlc.reg_list_size_bytes >> 2; i++)
  3570. WREG32(mmRLC_SRM_ARAM_DATA, adev->gfx.rlc.register_restore[i]);
  3571. /* indirect list */
  3572. WREG32(mmRLC_GPM_SCRATCH_ADDR, adev->gfx.rlc.reg_list_format_start);
  3573. for (i = 0; i < adev->gfx.rlc.reg_list_format_size_bytes >> 2; i++)
  3574. WREG32(mmRLC_GPM_SCRATCH_DATA, register_list_format[i]);
  3575. list_size = adev->gfx.rlc.reg_list_size_bytes >> 2;
  3576. list_size = list_size >> 1;
  3577. WREG32(mmRLC_GPM_SCRATCH_ADDR, adev->gfx.rlc.reg_restore_list_size);
  3578. WREG32(mmRLC_GPM_SCRATCH_DATA, list_size);
  3579. /* starting offsets starts */
  3580. WREG32(mmRLC_GPM_SCRATCH_ADDR,
  3581. adev->gfx.rlc.starting_offsets_start);
  3582. for (i = 0; i < sizeof(indirect_start_offsets)/sizeof(int); i++)
  3583. WREG32(mmRLC_GPM_SCRATCH_DATA,
  3584. indirect_start_offsets[i]);
  3585. /* unique indices */
  3586. temp = mmRLC_SRM_INDEX_CNTL_ADDR_0;
  3587. data = mmRLC_SRM_INDEX_CNTL_DATA_0;
  3588. for (i = 0; i < sizeof(unique_indices) / sizeof(int); i++) {
  3589. if (unique_indices[i] != 0) {
  3590. WREG32(temp + i, unique_indices[i] & 0x3FFFF);
  3591. WREG32(data + i, unique_indices[i] >> 20);
  3592. }
  3593. }
  3594. kfree(register_list_format);
  3595. return 0;
  3596. }
  3597. static void gfx_v8_0_enable_save_restore_machine(struct amdgpu_device *adev)
  3598. {
  3599. WREG32_FIELD(RLC_SRM_CNTL, SRM_ENABLE, 1);
  3600. }
  3601. static void gfx_v8_0_init_power_gating(struct amdgpu_device *adev)
  3602. {
  3603. uint32_t data;
  3604. WREG32_FIELD(CP_RB_WPTR_POLL_CNTL, IDLE_POLL_COUNT, 0x60);
  3605. data = REG_SET_FIELD(0, RLC_PG_DELAY, POWER_UP_DELAY, 0x10);
  3606. data = REG_SET_FIELD(data, RLC_PG_DELAY, POWER_DOWN_DELAY, 0x10);
  3607. data = REG_SET_FIELD(data, RLC_PG_DELAY, CMD_PROPAGATE_DELAY, 0x10);
  3608. data = REG_SET_FIELD(data, RLC_PG_DELAY, MEM_SLEEP_DELAY, 0x10);
  3609. WREG32(mmRLC_PG_DELAY, data);
  3610. WREG32_FIELD(RLC_PG_DELAY_2, SERDES_CMD_DELAY, 0x3);
  3611. WREG32_FIELD(RLC_AUTO_PG_CTRL, GRBM_REG_SAVE_GFX_IDLE_THRESHOLD, 0x55f0);
  3612. }
  3613. static void cz_enable_sck_slow_down_on_power_up(struct amdgpu_device *adev,
  3614. bool enable)
  3615. {
  3616. WREG32_FIELD(RLC_PG_CNTL, SMU_CLK_SLOWDOWN_ON_PU_ENABLE, enable ? 1 : 0);
  3617. }
  3618. static void cz_enable_sck_slow_down_on_power_down(struct amdgpu_device *adev,
  3619. bool enable)
  3620. {
  3621. WREG32_FIELD(RLC_PG_CNTL, SMU_CLK_SLOWDOWN_ON_PD_ENABLE, enable ? 1 : 0);
  3622. }
  3623. static void cz_enable_cp_power_gating(struct amdgpu_device *adev, bool enable)
  3624. {
  3625. WREG32_FIELD(RLC_PG_CNTL, CP_PG_DISABLE, enable ? 0 : 1);
  3626. }
  3627. static void gfx_v8_0_init_pg(struct amdgpu_device *adev)
  3628. {
  3629. if ((adev->asic_type == CHIP_CARRIZO) ||
  3630. (adev->asic_type == CHIP_STONEY)) {
  3631. gfx_v8_0_init_csb(adev);
  3632. gfx_v8_0_init_save_restore_list(adev);
  3633. gfx_v8_0_enable_save_restore_machine(adev);
  3634. WREG32(mmRLC_JUMP_TABLE_RESTORE, adev->gfx.rlc.cp_table_gpu_addr >> 8);
  3635. gfx_v8_0_init_power_gating(adev);
  3636. WREG32(mmRLC_PG_ALWAYS_ON_CU_MASK, adev->gfx.cu_info.ao_cu_mask);
  3637. } else if ((adev->asic_type == CHIP_POLARIS11) ||
  3638. (adev->asic_type == CHIP_POLARIS12)) {
  3639. gfx_v8_0_init_csb(adev);
  3640. gfx_v8_0_init_save_restore_list(adev);
  3641. gfx_v8_0_enable_save_restore_machine(adev);
  3642. gfx_v8_0_init_power_gating(adev);
  3643. }
  3644. }
  3645. static void gfx_v8_0_rlc_stop(struct amdgpu_device *adev)
  3646. {
  3647. WREG32_FIELD(RLC_CNTL, RLC_ENABLE_F32, 0);
  3648. gfx_v8_0_enable_gui_idle_interrupt(adev, false);
  3649. gfx_v8_0_wait_for_rlc_serdes(adev);
  3650. }
  3651. static void gfx_v8_0_rlc_reset(struct amdgpu_device *adev)
  3652. {
  3653. WREG32_FIELD(GRBM_SOFT_RESET, SOFT_RESET_RLC, 1);
  3654. udelay(50);
  3655. WREG32_FIELD(GRBM_SOFT_RESET, SOFT_RESET_RLC, 0);
  3656. udelay(50);
  3657. }
  3658. static void gfx_v8_0_rlc_start(struct amdgpu_device *adev)
  3659. {
  3660. WREG32_FIELD(RLC_CNTL, RLC_ENABLE_F32, 1);
  3661. /* carrizo do enable cp interrupt after cp inited */
  3662. if (!(adev->flags & AMD_IS_APU))
  3663. gfx_v8_0_enable_gui_idle_interrupt(adev, true);
  3664. udelay(50);
  3665. }
  3666. static int gfx_v8_0_rlc_load_microcode(struct amdgpu_device *adev)
  3667. {
  3668. const struct rlc_firmware_header_v2_0 *hdr;
  3669. const __le32 *fw_data;
  3670. unsigned i, fw_size;
  3671. if (!adev->gfx.rlc_fw)
  3672. return -EINVAL;
  3673. hdr = (const struct rlc_firmware_header_v2_0 *)adev->gfx.rlc_fw->data;
  3674. amdgpu_ucode_print_rlc_hdr(&hdr->header);
  3675. fw_data = (const __le32 *)(adev->gfx.rlc_fw->data +
  3676. le32_to_cpu(hdr->header.ucode_array_offset_bytes));
  3677. fw_size = le32_to_cpu(hdr->header.ucode_size_bytes) / 4;
  3678. WREG32(mmRLC_GPM_UCODE_ADDR, 0);
  3679. for (i = 0; i < fw_size; i++)
  3680. WREG32(mmRLC_GPM_UCODE_DATA, le32_to_cpup(fw_data++));
  3681. WREG32(mmRLC_GPM_UCODE_ADDR, adev->gfx.rlc_fw_version);
  3682. return 0;
  3683. }
  3684. static int gfx_v8_0_rlc_resume(struct amdgpu_device *adev)
  3685. {
  3686. int r;
  3687. u32 tmp;
  3688. gfx_v8_0_rlc_stop(adev);
  3689. /* disable CG */
  3690. tmp = RREG32(mmRLC_CGCG_CGLS_CTRL);
  3691. tmp &= ~(RLC_CGCG_CGLS_CTRL__CGCG_EN_MASK |
  3692. RLC_CGCG_CGLS_CTRL__CGLS_EN_MASK);
  3693. WREG32(mmRLC_CGCG_CGLS_CTRL, tmp);
  3694. if (adev->asic_type == CHIP_POLARIS11 ||
  3695. adev->asic_type == CHIP_POLARIS10 ||
  3696. adev->asic_type == CHIP_POLARIS12) {
  3697. tmp = RREG32(mmRLC_CGCG_CGLS_CTRL_3D);
  3698. tmp &= ~0x3;
  3699. WREG32(mmRLC_CGCG_CGLS_CTRL_3D, tmp);
  3700. }
  3701. /* disable PG */
  3702. WREG32(mmRLC_PG_CNTL, 0);
  3703. gfx_v8_0_rlc_reset(adev);
  3704. gfx_v8_0_init_pg(adev);
  3705. if (!adev->pp_enabled) {
  3706. if (adev->firmware.load_type != AMDGPU_FW_LOAD_SMU) {
  3707. /* legacy rlc firmware loading */
  3708. r = gfx_v8_0_rlc_load_microcode(adev);
  3709. if (r)
  3710. return r;
  3711. } else {
  3712. r = adev->smu.smumgr_funcs->check_fw_load_finish(adev,
  3713. AMDGPU_UCODE_ID_RLC_G);
  3714. if (r)
  3715. return -EINVAL;
  3716. }
  3717. }
  3718. gfx_v8_0_rlc_start(adev);
  3719. return 0;
  3720. }
  3721. static void gfx_v8_0_cp_gfx_enable(struct amdgpu_device *adev, bool enable)
  3722. {
  3723. int i;
  3724. u32 tmp = RREG32(mmCP_ME_CNTL);
  3725. if (enable) {
  3726. tmp = REG_SET_FIELD(tmp, CP_ME_CNTL, ME_HALT, 0);
  3727. tmp = REG_SET_FIELD(tmp, CP_ME_CNTL, PFP_HALT, 0);
  3728. tmp = REG_SET_FIELD(tmp, CP_ME_CNTL, CE_HALT, 0);
  3729. } else {
  3730. tmp = REG_SET_FIELD(tmp, CP_ME_CNTL, ME_HALT, 1);
  3731. tmp = REG_SET_FIELD(tmp, CP_ME_CNTL, PFP_HALT, 1);
  3732. tmp = REG_SET_FIELD(tmp, CP_ME_CNTL, CE_HALT, 1);
  3733. for (i = 0; i < adev->gfx.num_gfx_rings; i++)
  3734. adev->gfx.gfx_ring[i].ready = false;
  3735. }
  3736. WREG32(mmCP_ME_CNTL, tmp);
  3737. udelay(50);
  3738. }
  3739. static int gfx_v8_0_cp_gfx_load_microcode(struct amdgpu_device *adev)
  3740. {
  3741. const struct gfx_firmware_header_v1_0 *pfp_hdr;
  3742. const struct gfx_firmware_header_v1_0 *ce_hdr;
  3743. const struct gfx_firmware_header_v1_0 *me_hdr;
  3744. const __le32 *fw_data;
  3745. unsigned i, fw_size;
  3746. if (!adev->gfx.me_fw || !adev->gfx.pfp_fw || !adev->gfx.ce_fw)
  3747. return -EINVAL;
  3748. pfp_hdr = (const struct gfx_firmware_header_v1_0 *)
  3749. adev->gfx.pfp_fw->data;
  3750. ce_hdr = (const struct gfx_firmware_header_v1_0 *)
  3751. adev->gfx.ce_fw->data;
  3752. me_hdr = (const struct gfx_firmware_header_v1_0 *)
  3753. adev->gfx.me_fw->data;
  3754. amdgpu_ucode_print_gfx_hdr(&pfp_hdr->header);
  3755. amdgpu_ucode_print_gfx_hdr(&ce_hdr->header);
  3756. amdgpu_ucode_print_gfx_hdr(&me_hdr->header);
  3757. gfx_v8_0_cp_gfx_enable(adev, false);
  3758. /* PFP */
  3759. fw_data = (const __le32 *)
  3760. (adev->gfx.pfp_fw->data +
  3761. le32_to_cpu(pfp_hdr->header.ucode_array_offset_bytes));
  3762. fw_size = le32_to_cpu(pfp_hdr->header.ucode_size_bytes) / 4;
  3763. WREG32(mmCP_PFP_UCODE_ADDR, 0);
  3764. for (i = 0; i < fw_size; i++)
  3765. WREG32(mmCP_PFP_UCODE_DATA, le32_to_cpup(fw_data++));
  3766. WREG32(mmCP_PFP_UCODE_ADDR, adev->gfx.pfp_fw_version);
  3767. /* CE */
  3768. fw_data = (const __le32 *)
  3769. (adev->gfx.ce_fw->data +
  3770. le32_to_cpu(ce_hdr->header.ucode_array_offset_bytes));
  3771. fw_size = le32_to_cpu(ce_hdr->header.ucode_size_bytes) / 4;
  3772. WREG32(mmCP_CE_UCODE_ADDR, 0);
  3773. for (i = 0; i < fw_size; i++)
  3774. WREG32(mmCP_CE_UCODE_DATA, le32_to_cpup(fw_data++));
  3775. WREG32(mmCP_CE_UCODE_ADDR, adev->gfx.ce_fw_version);
  3776. /* ME */
  3777. fw_data = (const __le32 *)
  3778. (adev->gfx.me_fw->data +
  3779. le32_to_cpu(me_hdr->header.ucode_array_offset_bytes));
  3780. fw_size = le32_to_cpu(me_hdr->header.ucode_size_bytes) / 4;
  3781. WREG32(mmCP_ME_RAM_WADDR, 0);
  3782. for (i = 0; i < fw_size; i++)
  3783. WREG32(mmCP_ME_RAM_DATA, le32_to_cpup(fw_data++));
  3784. WREG32(mmCP_ME_RAM_WADDR, adev->gfx.me_fw_version);
  3785. return 0;
  3786. }
  3787. static u32 gfx_v8_0_get_csb_size(struct amdgpu_device *adev)
  3788. {
  3789. u32 count = 0;
  3790. const struct cs_section_def *sect = NULL;
  3791. const struct cs_extent_def *ext = NULL;
  3792. /* begin clear state */
  3793. count += 2;
  3794. /* context control state */
  3795. count += 3;
  3796. for (sect = vi_cs_data; sect->section != NULL; ++sect) {
  3797. for (ext = sect->section; ext->extent != NULL; ++ext) {
  3798. if (sect->id == SECT_CONTEXT)
  3799. count += 2 + ext->reg_count;
  3800. else
  3801. return 0;
  3802. }
  3803. }
  3804. /* pa_sc_raster_config/pa_sc_raster_config1 */
  3805. count += 4;
  3806. /* end clear state */
  3807. count += 2;
  3808. /* clear state */
  3809. count += 2;
  3810. return count;
  3811. }
  3812. static int gfx_v8_0_cp_gfx_start(struct amdgpu_device *adev)
  3813. {
  3814. struct amdgpu_ring *ring = &adev->gfx.gfx_ring[0];
  3815. const struct cs_section_def *sect = NULL;
  3816. const struct cs_extent_def *ext = NULL;
  3817. int r, i;
  3818. /* init the CP */
  3819. WREG32(mmCP_MAX_CONTEXT, adev->gfx.config.max_hw_contexts - 1);
  3820. WREG32(mmCP_ENDIAN_SWAP, 0);
  3821. WREG32(mmCP_DEVICE_ID, 1);
  3822. gfx_v8_0_cp_gfx_enable(adev, true);
  3823. r = amdgpu_ring_alloc(ring, gfx_v8_0_get_csb_size(adev) + 4);
  3824. if (r) {
  3825. DRM_ERROR("amdgpu: cp failed to lock ring (%d).\n", r);
  3826. return r;
  3827. }
  3828. /* clear state buffer */
  3829. amdgpu_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
  3830. amdgpu_ring_write(ring, PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);
  3831. amdgpu_ring_write(ring, PACKET3(PACKET3_CONTEXT_CONTROL, 1));
  3832. amdgpu_ring_write(ring, 0x80000000);
  3833. amdgpu_ring_write(ring, 0x80000000);
  3834. for (sect = vi_cs_data; sect->section != NULL; ++sect) {
  3835. for (ext = sect->section; ext->extent != NULL; ++ext) {
  3836. if (sect->id == SECT_CONTEXT) {
  3837. amdgpu_ring_write(ring,
  3838. PACKET3(PACKET3_SET_CONTEXT_REG,
  3839. ext->reg_count));
  3840. amdgpu_ring_write(ring,
  3841. ext->reg_index - PACKET3_SET_CONTEXT_REG_START);
  3842. for (i = 0; i < ext->reg_count; i++)
  3843. amdgpu_ring_write(ring, ext->extent[i]);
  3844. }
  3845. }
  3846. }
  3847. amdgpu_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 2));
  3848. amdgpu_ring_write(ring, mmPA_SC_RASTER_CONFIG - PACKET3_SET_CONTEXT_REG_START);
  3849. switch (adev->asic_type) {
  3850. case CHIP_TONGA:
  3851. case CHIP_POLARIS10:
  3852. amdgpu_ring_write(ring, 0x16000012);
  3853. amdgpu_ring_write(ring, 0x0000002A);
  3854. break;
  3855. case CHIP_POLARIS11:
  3856. case CHIP_POLARIS12:
  3857. amdgpu_ring_write(ring, 0x16000012);
  3858. amdgpu_ring_write(ring, 0x00000000);
  3859. break;
  3860. case CHIP_FIJI:
  3861. amdgpu_ring_write(ring, 0x3a00161a);
  3862. amdgpu_ring_write(ring, 0x0000002e);
  3863. break;
  3864. case CHIP_CARRIZO:
  3865. amdgpu_ring_write(ring, 0x00000002);
  3866. amdgpu_ring_write(ring, 0x00000000);
  3867. break;
  3868. case CHIP_TOPAZ:
  3869. amdgpu_ring_write(ring, adev->gfx.config.num_rbs == 1 ?
  3870. 0x00000000 : 0x00000002);
  3871. amdgpu_ring_write(ring, 0x00000000);
  3872. break;
  3873. case CHIP_STONEY:
  3874. amdgpu_ring_write(ring, 0x00000000);
  3875. amdgpu_ring_write(ring, 0x00000000);
  3876. break;
  3877. default:
  3878. BUG();
  3879. }
  3880. amdgpu_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
  3881. amdgpu_ring_write(ring, PACKET3_PREAMBLE_END_CLEAR_STATE);
  3882. amdgpu_ring_write(ring, PACKET3(PACKET3_CLEAR_STATE, 0));
  3883. amdgpu_ring_write(ring, 0);
  3884. /* init the CE partitions */
  3885. amdgpu_ring_write(ring, PACKET3(PACKET3_SET_BASE, 2));
  3886. amdgpu_ring_write(ring, PACKET3_BASE_INDEX(CE_PARTITION_BASE));
  3887. amdgpu_ring_write(ring, 0x8000);
  3888. amdgpu_ring_write(ring, 0x8000);
  3889. amdgpu_ring_commit(ring);
  3890. return 0;
  3891. }
  3892. static void gfx_v8_0_set_cpg_door_bell(struct amdgpu_device *adev, struct amdgpu_ring *ring)
  3893. {
  3894. u32 tmp;
  3895. /* no gfx doorbells on iceland */
  3896. if (adev->asic_type == CHIP_TOPAZ)
  3897. return;
  3898. tmp = RREG32(mmCP_RB_DOORBELL_CONTROL);
  3899. if (ring->use_doorbell) {
  3900. tmp = REG_SET_FIELD(tmp, CP_RB_DOORBELL_CONTROL,
  3901. DOORBELL_OFFSET, ring->doorbell_index);
  3902. tmp = REG_SET_FIELD(tmp, CP_RB_DOORBELL_CONTROL,
  3903. DOORBELL_HIT, 0);
  3904. tmp = REG_SET_FIELD(tmp, CP_RB_DOORBELL_CONTROL,
  3905. DOORBELL_EN, 1);
  3906. } else {
  3907. tmp = REG_SET_FIELD(tmp, CP_RB_DOORBELL_CONTROL, DOORBELL_EN, 0);
  3908. }
  3909. WREG32(mmCP_RB_DOORBELL_CONTROL, tmp);
  3910. if (adev->flags & AMD_IS_APU)
  3911. return;
  3912. tmp = REG_SET_FIELD(0, CP_RB_DOORBELL_RANGE_LOWER,
  3913. DOORBELL_RANGE_LOWER,
  3914. AMDGPU_DOORBELL_GFX_RING0);
  3915. WREG32(mmCP_RB_DOORBELL_RANGE_LOWER, tmp);
  3916. WREG32(mmCP_RB_DOORBELL_RANGE_UPPER,
  3917. CP_RB_DOORBELL_RANGE_UPPER__DOORBELL_RANGE_UPPER_MASK);
  3918. }
  3919. static int gfx_v8_0_cp_gfx_resume(struct amdgpu_device *adev)
  3920. {
  3921. struct amdgpu_ring *ring;
  3922. u32 tmp;
  3923. u32 rb_bufsz;
  3924. u64 rb_addr, rptr_addr, wptr_gpu_addr;
  3925. int r;
  3926. /* Set the write pointer delay */
  3927. WREG32(mmCP_RB_WPTR_DELAY, 0);
  3928. /* set the RB to use vmid 0 */
  3929. WREG32(mmCP_RB_VMID, 0);
  3930. /* Set ring buffer size */
  3931. ring = &adev->gfx.gfx_ring[0];
  3932. rb_bufsz = order_base_2(ring->ring_size / 8);
  3933. tmp = REG_SET_FIELD(0, CP_RB0_CNTL, RB_BUFSZ, rb_bufsz);
  3934. tmp = REG_SET_FIELD(tmp, CP_RB0_CNTL, RB_BLKSZ, rb_bufsz - 2);
  3935. tmp = REG_SET_FIELD(tmp, CP_RB0_CNTL, MTYPE, 3);
  3936. tmp = REG_SET_FIELD(tmp, CP_RB0_CNTL, MIN_IB_AVAILSZ, 1);
  3937. #ifdef __BIG_ENDIAN
  3938. tmp = REG_SET_FIELD(tmp, CP_RB0_CNTL, BUF_SWAP, 1);
  3939. #endif
  3940. WREG32(mmCP_RB0_CNTL, tmp);
  3941. /* Initialize the ring buffer's read and write pointers */
  3942. WREG32(mmCP_RB0_CNTL, tmp | CP_RB0_CNTL__RB_RPTR_WR_ENA_MASK);
  3943. ring->wptr = 0;
  3944. WREG32(mmCP_RB0_WPTR, lower_32_bits(ring->wptr));
  3945. /* set the wb address wether it's enabled or not */
  3946. rptr_addr = adev->wb.gpu_addr + (ring->rptr_offs * 4);
  3947. WREG32(mmCP_RB0_RPTR_ADDR, lower_32_bits(rptr_addr));
  3948. WREG32(mmCP_RB0_RPTR_ADDR_HI, upper_32_bits(rptr_addr) & 0xFF);
  3949. wptr_gpu_addr = adev->wb.gpu_addr + (ring->wptr_offs * 4);
  3950. WREG32(mmCP_RB_WPTR_POLL_ADDR_LO, lower_32_bits(wptr_gpu_addr));
  3951. WREG32(mmCP_RB_WPTR_POLL_ADDR_HI, upper_32_bits(wptr_gpu_addr));
  3952. mdelay(1);
  3953. WREG32(mmCP_RB0_CNTL, tmp);
  3954. rb_addr = ring->gpu_addr >> 8;
  3955. WREG32(mmCP_RB0_BASE, rb_addr);
  3956. WREG32(mmCP_RB0_BASE_HI, upper_32_bits(rb_addr));
  3957. gfx_v8_0_set_cpg_door_bell(adev, ring);
  3958. /* start the ring */
  3959. amdgpu_ring_clear_ring(ring);
  3960. gfx_v8_0_cp_gfx_start(adev);
  3961. ring->ready = true;
  3962. r = amdgpu_ring_test_ring(ring);
  3963. if (r)
  3964. ring->ready = false;
  3965. return r;
  3966. }
  3967. static void gfx_v8_0_cp_compute_enable(struct amdgpu_device *adev, bool enable)
  3968. {
  3969. int i;
  3970. if (enable) {
  3971. WREG32(mmCP_MEC_CNTL, 0);
  3972. } else {
  3973. WREG32(mmCP_MEC_CNTL, (CP_MEC_CNTL__MEC_ME1_HALT_MASK | CP_MEC_CNTL__MEC_ME2_HALT_MASK));
  3974. for (i = 0; i < adev->gfx.num_compute_rings; i++)
  3975. adev->gfx.compute_ring[i].ready = false;
  3976. adev->gfx.kiq.ring.ready = false;
  3977. }
  3978. udelay(50);
  3979. }
  3980. static int gfx_v8_0_cp_compute_load_microcode(struct amdgpu_device *adev)
  3981. {
  3982. const struct gfx_firmware_header_v1_0 *mec_hdr;
  3983. const __le32 *fw_data;
  3984. unsigned i, fw_size;
  3985. if (!adev->gfx.mec_fw)
  3986. return -EINVAL;
  3987. gfx_v8_0_cp_compute_enable(adev, false);
  3988. mec_hdr = (const struct gfx_firmware_header_v1_0 *)adev->gfx.mec_fw->data;
  3989. amdgpu_ucode_print_gfx_hdr(&mec_hdr->header);
  3990. fw_data = (const __le32 *)
  3991. (adev->gfx.mec_fw->data +
  3992. le32_to_cpu(mec_hdr->header.ucode_array_offset_bytes));
  3993. fw_size = le32_to_cpu(mec_hdr->header.ucode_size_bytes) / 4;
  3994. /* MEC1 */
  3995. WREG32(mmCP_MEC_ME1_UCODE_ADDR, 0);
  3996. for (i = 0; i < fw_size; i++)
  3997. WREG32(mmCP_MEC_ME1_UCODE_DATA, le32_to_cpup(fw_data+i));
  3998. WREG32(mmCP_MEC_ME1_UCODE_ADDR, adev->gfx.mec_fw_version);
  3999. /* Loading MEC2 firmware is only necessary if MEC2 should run different microcode than MEC1. */
  4000. if (adev->gfx.mec2_fw) {
  4001. const struct gfx_firmware_header_v1_0 *mec2_hdr;
  4002. mec2_hdr = (const struct gfx_firmware_header_v1_0 *)adev->gfx.mec2_fw->data;
  4003. amdgpu_ucode_print_gfx_hdr(&mec2_hdr->header);
  4004. fw_data = (const __le32 *)
  4005. (adev->gfx.mec2_fw->data +
  4006. le32_to_cpu(mec2_hdr->header.ucode_array_offset_bytes));
  4007. fw_size = le32_to_cpu(mec2_hdr->header.ucode_size_bytes) / 4;
  4008. WREG32(mmCP_MEC_ME2_UCODE_ADDR, 0);
  4009. for (i = 0; i < fw_size; i++)
  4010. WREG32(mmCP_MEC_ME2_UCODE_DATA, le32_to_cpup(fw_data+i));
  4011. WREG32(mmCP_MEC_ME2_UCODE_ADDR, adev->gfx.mec2_fw_version);
  4012. }
  4013. return 0;
  4014. }
  4015. /* KIQ functions */
  4016. static void gfx_v8_0_kiq_setting(struct amdgpu_ring *ring)
  4017. {
  4018. uint32_t tmp;
  4019. struct amdgpu_device *adev = ring->adev;
  4020. /* tell RLC which is KIQ queue */
  4021. tmp = RREG32(mmRLC_CP_SCHEDULERS);
  4022. tmp &= 0xffffff00;
  4023. tmp |= (ring->me << 5) | (ring->pipe << 3) | (ring->queue);
  4024. WREG32(mmRLC_CP_SCHEDULERS, tmp);
  4025. tmp |= 0x80;
  4026. WREG32(mmRLC_CP_SCHEDULERS, tmp);
  4027. }
  4028. static int gfx_v8_0_kiq_kcq_enable(struct amdgpu_device *adev)
  4029. {
  4030. struct amdgpu_ring *kiq_ring = &adev->gfx.kiq.ring;
  4031. uint32_t scratch, tmp = 0;
  4032. uint64_t queue_mask = 0;
  4033. int r, i;
  4034. for (i = 0; i < AMDGPU_MAX_COMPUTE_QUEUES; ++i) {
  4035. if (!test_bit(i, adev->gfx.mec.queue_bitmap))
  4036. continue;
  4037. /* This situation may be hit in the future if a new HW
  4038. * generation exposes more than 64 queues. If so, the
  4039. * definition of queue_mask needs updating */
  4040. if (WARN_ON(i >= (sizeof(queue_mask)*8))) {
  4041. DRM_ERROR("Invalid KCQ enabled: %d\n", i);
  4042. break;
  4043. }
  4044. queue_mask |= (1ull << i);
  4045. }
  4046. r = amdgpu_gfx_scratch_get(adev, &scratch);
  4047. if (r) {
  4048. DRM_ERROR("Failed to get scratch reg (%d).\n", r);
  4049. return r;
  4050. }
  4051. WREG32(scratch, 0xCAFEDEAD);
  4052. r = amdgpu_ring_alloc(kiq_ring, (8 * adev->gfx.num_compute_rings) + 11);
  4053. if (r) {
  4054. DRM_ERROR("Failed to lock KIQ (%d).\n", r);
  4055. amdgpu_gfx_scratch_free(adev, scratch);
  4056. return r;
  4057. }
  4058. /* set resources */
  4059. amdgpu_ring_write(kiq_ring, PACKET3(PACKET3_SET_RESOURCES, 6));
  4060. amdgpu_ring_write(kiq_ring, 0); /* vmid_mask:0 queue_type:0 (KIQ) */
  4061. amdgpu_ring_write(kiq_ring, lower_32_bits(queue_mask)); /* queue mask lo */
  4062. amdgpu_ring_write(kiq_ring, upper_32_bits(queue_mask)); /* queue mask hi */
  4063. amdgpu_ring_write(kiq_ring, 0); /* gws mask lo */
  4064. amdgpu_ring_write(kiq_ring, 0); /* gws mask hi */
  4065. amdgpu_ring_write(kiq_ring, 0); /* oac mask */
  4066. amdgpu_ring_write(kiq_ring, 0); /* gds heap base:0, gds heap size:0 */
  4067. for (i = 0; i < adev->gfx.num_compute_rings; i++) {
  4068. struct amdgpu_ring *ring = &adev->gfx.compute_ring[i];
  4069. uint64_t mqd_addr = amdgpu_bo_gpu_offset(ring->mqd_obj);
  4070. uint64_t wptr_addr = adev->wb.gpu_addr + (ring->wptr_offs * 4);
  4071. /* map queues */
  4072. amdgpu_ring_write(kiq_ring, PACKET3(PACKET3_MAP_QUEUES, 5));
  4073. /* Q_sel:0, vmid:0, vidmem: 1, engine:0, num_Q:1*/
  4074. amdgpu_ring_write(kiq_ring,
  4075. PACKET3_MAP_QUEUES_NUM_QUEUES(1));
  4076. amdgpu_ring_write(kiq_ring,
  4077. PACKET3_MAP_QUEUES_DOORBELL_OFFSET(ring->doorbell_index) |
  4078. PACKET3_MAP_QUEUES_QUEUE(ring->queue) |
  4079. PACKET3_MAP_QUEUES_PIPE(ring->pipe) |
  4080. PACKET3_MAP_QUEUES_ME(ring->me == 1 ? 0 : 1)); /* doorbell */
  4081. amdgpu_ring_write(kiq_ring, lower_32_bits(mqd_addr));
  4082. amdgpu_ring_write(kiq_ring, upper_32_bits(mqd_addr));
  4083. amdgpu_ring_write(kiq_ring, lower_32_bits(wptr_addr));
  4084. amdgpu_ring_write(kiq_ring, upper_32_bits(wptr_addr));
  4085. }
  4086. /* write to scratch for completion */
  4087. amdgpu_ring_write(kiq_ring, PACKET3(PACKET3_SET_UCONFIG_REG, 1));
  4088. amdgpu_ring_write(kiq_ring, (scratch - PACKET3_SET_UCONFIG_REG_START));
  4089. amdgpu_ring_write(kiq_ring, 0xDEADBEEF);
  4090. amdgpu_ring_commit(kiq_ring);
  4091. for (i = 0; i < adev->usec_timeout; i++) {
  4092. tmp = RREG32(scratch);
  4093. if (tmp == 0xDEADBEEF)
  4094. break;
  4095. DRM_UDELAY(1);
  4096. }
  4097. if (i >= adev->usec_timeout) {
  4098. DRM_ERROR("KCQ enable failed (scratch(0x%04X)=0x%08X)\n",
  4099. scratch, tmp);
  4100. r = -EINVAL;
  4101. }
  4102. amdgpu_gfx_scratch_free(adev, scratch);
  4103. return r;
  4104. }
  4105. static int gfx_v8_0_deactivate_hqd(struct amdgpu_device *adev, u32 req)
  4106. {
  4107. int i, r = 0;
  4108. if (RREG32(mmCP_HQD_ACTIVE) & CP_HQD_ACTIVE__ACTIVE_MASK) {
  4109. WREG32_FIELD(CP_HQD_DEQUEUE_REQUEST, DEQUEUE_REQ, req);
  4110. for (i = 0; i < adev->usec_timeout; i++) {
  4111. if (!(RREG32(mmCP_HQD_ACTIVE) & CP_HQD_ACTIVE__ACTIVE_MASK))
  4112. break;
  4113. udelay(1);
  4114. }
  4115. if (i == adev->usec_timeout)
  4116. r = -ETIMEDOUT;
  4117. }
  4118. WREG32(mmCP_HQD_DEQUEUE_REQUEST, 0);
  4119. WREG32(mmCP_HQD_PQ_RPTR, 0);
  4120. WREG32(mmCP_HQD_PQ_WPTR, 0);
  4121. return r;
  4122. }
  4123. static int gfx_v8_0_mqd_init(struct amdgpu_ring *ring)
  4124. {
  4125. struct amdgpu_device *adev = ring->adev;
  4126. struct vi_mqd *mqd = ring->mqd_ptr;
  4127. uint64_t hqd_gpu_addr, wb_gpu_addr, eop_base_addr;
  4128. uint32_t tmp;
  4129. mqd->header = 0xC0310800;
  4130. mqd->compute_pipelinestat_enable = 0x00000001;
  4131. mqd->compute_static_thread_mgmt_se0 = 0xffffffff;
  4132. mqd->compute_static_thread_mgmt_se1 = 0xffffffff;
  4133. mqd->compute_static_thread_mgmt_se2 = 0xffffffff;
  4134. mqd->compute_static_thread_mgmt_se3 = 0xffffffff;
  4135. mqd->compute_misc_reserved = 0x00000003;
  4136. if (!(adev->flags & AMD_IS_APU)) {
  4137. mqd->dynamic_cu_mask_addr_lo = lower_32_bits(ring->mqd_gpu_addr
  4138. + offsetof(struct vi_mqd_allocation, dynamic_cu_mask));
  4139. mqd->dynamic_cu_mask_addr_hi = upper_32_bits(ring->mqd_gpu_addr
  4140. + offsetof(struct vi_mqd_allocation, dynamic_cu_mask));
  4141. }
  4142. eop_base_addr = ring->eop_gpu_addr >> 8;
  4143. mqd->cp_hqd_eop_base_addr_lo = eop_base_addr;
  4144. mqd->cp_hqd_eop_base_addr_hi = upper_32_bits(eop_base_addr);
  4145. /* set the EOP size, register value is 2^(EOP_SIZE+1) dwords */
  4146. tmp = RREG32(mmCP_HQD_EOP_CONTROL);
  4147. tmp = REG_SET_FIELD(tmp, CP_HQD_EOP_CONTROL, EOP_SIZE,
  4148. (order_base_2(GFX8_MEC_HPD_SIZE / 4) - 1));
  4149. mqd->cp_hqd_eop_control = tmp;
  4150. /* enable doorbell? */
  4151. tmp = REG_SET_FIELD(RREG32(mmCP_HQD_PQ_DOORBELL_CONTROL),
  4152. CP_HQD_PQ_DOORBELL_CONTROL,
  4153. DOORBELL_EN,
  4154. ring->use_doorbell ? 1 : 0);
  4155. mqd->cp_hqd_pq_doorbell_control = tmp;
  4156. /* set the pointer to the MQD */
  4157. mqd->cp_mqd_base_addr_lo = ring->mqd_gpu_addr & 0xfffffffc;
  4158. mqd->cp_mqd_base_addr_hi = upper_32_bits(ring->mqd_gpu_addr);
  4159. /* set MQD vmid to 0 */
  4160. tmp = RREG32(mmCP_MQD_CONTROL);
  4161. tmp = REG_SET_FIELD(tmp, CP_MQD_CONTROL, VMID, 0);
  4162. mqd->cp_mqd_control = tmp;
  4163. /* set the pointer to the HQD, this is similar CP_RB0_BASE/_HI */
  4164. hqd_gpu_addr = ring->gpu_addr >> 8;
  4165. mqd->cp_hqd_pq_base_lo = hqd_gpu_addr;
  4166. mqd->cp_hqd_pq_base_hi = upper_32_bits(hqd_gpu_addr);
  4167. /* set up the HQD, this is similar to CP_RB0_CNTL */
  4168. tmp = RREG32(mmCP_HQD_PQ_CONTROL);
  4169. tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, QUEUE_SIZE,
  4170. (order_base_2(ring->ring_size / 4) - 1));
  4171. tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, RPTR_BLOCK_SIZE,
  4172. ((order_base_2(AMDGPU_GPU_PAGE_SIZE / 4) - 1) << 8));
  4173. #ifdef __BIG_ENDIAN
  4174. tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, ENDIAN_SWAP, 1);
  4175. #endif
  4176. tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, UNORD_DISPATCH, 0);
  4177. tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, ROQ_PQ_IB_FLIP, 0);
  4178. tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, PRIV_STATE, 1);
  4179. tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, KMD_QUEUE, 1);
  4180. mqd->cp_hqd_pq_control = tmp;
  4181. /* set the wb address whether it's enabled or not */
  4182. wb_gpu_addr = adev->wb.gpu_addr + (ring->rptr_offs * 4);
  4183. mqd->cp_hqd_pq_rptr_report_addr_lo = wb_gpu_addr & 0xfffffffc;
  4184. mqd->cp_hqd_pq_rptr_report_addr_hi =
  4185. upper_32_bits(wb_gpu_addr) & 0xffff;
  4186. /* only used if CP_PQ_WPTR_POLL_CNTL.CP_PQ_WPTR_POLL_CNTL__EN_MASK=1 */
  4187. wb_gpu_addr = adev->wb.gpu_addr + (ring->wptr_offs * 4);
  4188. mqd->cp_hqd_pq_wptr_poll_addr_lo = wb_gpu_addr & 0xfffffffc;
  4189. mqd->cp_hqd_pq_wptr_poll_addr_hi = upper_32_bits(wb_gpu_addr) & 0xffff;
  4190. tmp = 0;
  4191. /* enable the doorbell if requested */
  4192. if (ring->use_doorbell) {
  4193. tmp = RREG32(mmCP_HQD_PQ_DOORBELL_CONTROL);
  4194. tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_DOORBELL_CONTROL,
  4195. DOORBELL_OFFSET, ring->doorbell_index);
  4196. tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_DOORBELL_CONTROL,
  4197. DOORBELL_EN, 1);
  4198. tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_DOORBELL_CONTROL,
  4199. DOORBELL_SOURCE, 0);
  4200. tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_DOORBELL_CONTROL,
  4201. DOORBELL_HIT, 0);
  4202. }
  4203. mqd->cp_hqd_pq_doorbell_control = tmp;
  4204. /* reset read and write pointers, similar to CP_RB0_WPTR/_RPTR */
  4205. ring->wptr = 0;
  4206. mqd->cp_hqd_pq_wptr = ring->wptr;
  4207. mqd->cp_hqd_pq_rptr = RREG32(mmCP_HQD_PQ_RPTR);
  4208. /* set the vmid for the queue */
  4209. mqd->cp_hqd_vmid = 0;
  4210. tmp = RREG32(mmCP_HQD_PERSISTENT_STATE);
  4211. tmp = REG_SET_FIELD(tmp, CP_HQD_PERSISTENT_STATE, PRELOAD_SIZE, 0x53);
  4212. mqd->cp_hqd_persistent_state = tmp;
  4213. /* set MTYPE */
  4214. tmp = RREG32(mmCP_HQD_IB_CONTROL);
  4215. tmp = REG_SET_FIELD(tmp, CP_HQD_IB_CONTROL, MIN_IB_AVAIL_SIZE, 3);
  4216. tmp = REG_SET_FIELD(tmp, CP_HQD_IB_CONTROL, MTYPE, 3);
  4217. mqd->cp_hqd_ib_control = tmp;
  4218. tmp = RREG32(mmCP_HQD_IQ_TIMER);
  4219. tmp = REG_SET_FIELD(tmp, CP_HQD_IQ_TIMER, MTYPE, 3);
  4220. mqd->cp_hqd_iq_timer = tmp;
  4221. tmp = RREG32(mmCP_HQD_CTX_SAVE_CONTROL);
  4222. tmp = REG_SET_FIELD(tmp, CP_HQD_CTX_SAVE_CONTROL, MTYPE, 3);
  4223. mqd->cp_hqd_ctx_save_control = tmp;
  4224. /* defaults */
  4225. mqd->cp_hqd_eop_rptr = RREG32(mmCP_HQD_EOP_RPTR);
  4226. mqd->cp_hqd_eop_wptr = RREG32(mmCP_HQD_EOP_WPTR);
  4227. mqd->cp_hqd_pipe_priority = RREG32(mmCP_HQD_PIPE_PRIORITY);
  4228. mqd->cp_hqd_queue_priority = RREG32(mmCP_HQD_QUEUE_PRIORITY);
  4229. mqd->cp_hqd_quantum = RREG32(mmCP_HQD_QUANTUM);
  4230. mqd->cp_hqd_ctx_save_base_addr_lo = RREG32(mmCP_HQD_CTX_SAVE_BASE_ADDR_LO);
  4231. mqd->cp_hqd_ctx_save_base_addr_hi = RREG32(mmCP_HQD_CTX_SAVE_BASE_ADDR_HI);
  4232. mqd->cp_hqd_cntl_stack_offset = RREG32(mmCP_HQD_CNTL_STACK_OFFSET);
  4233. mqd->cp_hqd_cntl_stack_size = RREG32(mmCP_HQD_CNTL_STACK_SIZE);
  4234. mqd->cp_hqd_wg_state_offset = RREG32(mmCP_HQD_WG_STATE_OFFSET);
  4235. mqd->cp_hqd_ctx_save_size = RREG32(mmCP_HQD_CTX_SAVE_SIZE);
  4236. mqd->cp_hqd_eop_done_events = RREG32(mmCP_HQD_EOP_EVENTS);
  4237. mqd->cp_hqd_error = RREG32(mmCP_HQD_ERROR);
  4238. mqd->cp_hqd_eop_wptr_mem = RREG32(mmCP_HQD_EOP_WPTR_MEM);
  4239. mqd->cp_hqd_eop_dones = RREG32(mmCP_HQD_EOP_DONES);
  4240. /* activate the queue */
  4241. mqd->cp_hqd_active = 1;
  4242. return 0;
  4243. }
  4244. int gfx_v8_0_mqd_commit(struct amdgpu_device *adev,
  4245. struct vi_mqd *mqd)
  4246. {
  4247. uint32_t mqd_reg;
  4248. uint32_t *mqd_data;
  4249. /* HQD registers extend from mmCP_MQD_BASE_ADDR to mmCP_HQD_ERROR */
  4250. mqd_data = &mqd->cp_mqd_base_addr_lo;
  4251. /* disable wptr polling */
  4252. WREG32_FIELD(CP_PQ_WPTR_POLL_CNTL, EN, 0);
  4253. /* program all HQD registers */
  4254. for (mqd_reg = mmCP_HQD_VMID; mqd_reg <= mmCP_HQD_EOP_CONTROL; mqd_reg++)
  4255. WREG32(mqd_reg, mqd_data[mqd_reg - mmCP_MQD_BASE_ADDR]);
  4256. /* Tonga errata: EOP RPTR/WPTR should be left unmodified.
  4257. * This is safe since EOP RPTR==WPTR for any inactive HQD
  4258. * on ASICs that do not support context-save.
  4259. * EOP writes/reads can start anywhere in the ring.
  4260. */
  4261. if (adev->asic_type != CHIP_TONGA) {
  4262. WREG32(mmCP_HQD_EOP_RPTR, mqd->cp_hqd_eop_rptr);
  4263. WREG32(mmCP_HQD_EOP_WPTR, mqd->cp_hqd_eop_wptr);
  4264. WREG32(mmCP_HQD_EOP_WPTR_MEM, mqd->cp_hqd_eop_wptr_mem);
  4265. }
  4266. for (mqd_reg = mmCP_HQD_EOP_EVENTS; mqd_reg <= mmCP_HQD_ERROR; mqd_reg++)
  4267. WREG32(mqd_reg, mqd_data[mqd_reg - mmCP_MQD_BASE_ADDR]);
  4268. /* activate the HQD */
  4269. for (mqd_reg = mmCP_MQD_BASE_ADDR; mqd_reg <= mmCP_HQD_ACTIVE; mqd_reg++)
  4270. WREG32(mqd_reg, mqd_data[mqd_reg - mmCP_MQD_BASE_ADDR]);
  4271. return 0;
  4272. }
  4273. static int gfx_v8_0_kiq_init_queue(struct amdgpu_ring *ring)
  4274. {
  4275. struct amdgpu_device *adev = ring->adev;
  4276. struct vi_mqd *mqd = ring->mqd_ptr;
  4277. int mqd_idx = AMDGPU_MAX_COMPUTE_RINGS;
  4278. gfx_v8_0_kiq_setting(ring);
  4279. if (adev->gfx.in_reset) { /* for GPU_RESET case */
  4280. /* reset MQD to a clean status */
  4281. if (adev->gfx.mec.mqd_backup[mqd_idx])
  4282. memcpy(mqd, adev->gfx.mec.mqd_backup[mqd_idx], sizeof(struct vi_mqd_allocation));
  4283. /* reset ring buffer */
  4284. ring->wptr = 0;
  4285. amdgpu_ring_clear_ring(ring);
  4286. mutex_lock(&adev->srbm_mutex);
  4287. vi_srbm_select(adev, ring->me, ring->pipe, ring->queue, 0);
  4288. gfx_v8_0_mqd_commit(adev, mqd);
  4289. vi_srbm_select(adev, 0, 0, 0, 0);
  4290. mutex_unlock(&adev->srbm_mutex);
  4291. } else {
  4292. memset((void *)mqd, 0, sizeof(struct vi_mqd_allocation));
  4293. ((struct vi_mqd_allocation *)mqd)->dynamic_cu_mask = 0xFFFFFFFF;
  4294. ((struct vi_mqd_allocation *)mqd)->dynamic_rb_mask = 0xFFFFFFFF;
  4295. mutex_lock(&adev->srbm_mutex);
  4296. vi_srbm_select(adev, ring->me, ring->pipe, ring->queue, 0);
  4297. gfx_v8_0_mqd_init(ring);
  4298. gfx_v8_0_mqd_commit(adev, mqd);
  4299. vi_srbm_select(adev, 0, 0, 0, 0);
  4300. mutex_unlock(&adev->srbm_mutex);
  4301. if (adev->gfx.mec.mqd_backup[mqd_idx])
  4302. memcpy(adev->gfx.mec.mqd_backup[mqd_idx], mqd, sizeof(struct vi_mqd_allocation));
  4303. }
  4304. return 0;
  4305. }
  4306. static int gfx_v8_0_kcq_init_queue(struct amdgpu_ring *ring)
  4307. {
  4308. struct amdgpu_device *adev = ring->adev;
  4309. struct vi_mqd *mqd = ring->mqd_ptr;
  4310. int mqd_idx = ring - &adev->gfx.compute_ring[0];
  4311. if (!adev->gfx.in_reset && !adev->gfx.in_suspend) {
  4312. memset((void *)mqd, 0, sizeof(struct vi_mqd_allocation));
  4313. ((struct vi_mqd_allocation *)mqd)->dynamic_cu_mask = 0xFFFFFFFF;
  4314. ((struct vi_mqd_allocation *)mqd)->dynamic_rb_mask = 0xFFFFFFFF;
  4315. mutex_lock(&adev->srbm_mutex);
  4316. vi_srbm_select(adev, ring->me, ring->pipe, ring->queue, 0);
  4317. gfx_v8_0_mqd_init(ring);
  4318. vi_srbm_select(adev, 0, 0, 0, 0);
  4319. mutex_unlock(&adev->srbm_mutex);
  4320. if (adev->gfx.mec.mqd_backup[mqd_idx])
  4321. memcpy(adev->gfx.mec.mqd_backup[mqd_idx], mqd, sizeof(struct vi_mqd_allocation));
  4322. } else if (adev->gfx.in_reset) { /* for GPU_RESET case */
  4323. /* reset MQD to a clean status */
  4324. if (adev->gfx.mec.mqd_backup[mqd_idx])
  4325. memcpy(mqd, adev->gfx.mec.mqd_backup[mqd_idx], sizeof(struct vi_mqd_allocation));
  4326. /* reset ring buffer */
  4327. ring->wptr = 0;
  4328. amdgpu_ring_clear_ring(ring);
  4329. } else {
  4330. amdgpu_ring_clear_ring(ring);
  4331. }
  4332. return 0;
  4333. }
  4334. static void gfx_v8_0_set_mec_doorbell_range(struct amdgpu_device *adev)
  4335. {
  4336. if (adev->asic_type > CHIP_TONGA) {
  4337. WREG32(mmCP_MEC_DOORBELL_RANGE_LOWER, AMDGPU_DOORBELL_KIQ << 2);
  4338. WREG32(mmCP_MEC_DOORBELL_RANGE_UPPER, AMDGPU_DOORBELL_MEC_RING7 << 2);
  4339. }
  4340. /* enable doorbells */
  4341. WREG32_FIELD(CP_PQ_STATUS, DOORBELL_ENABLE, 1);
  4342. }
  4343. static int gfx_v8_0_kiq_resume(struct amdgpu_device *adev)
  4344. {
  4345. struct amdgpu_ring *ring = NULL;
  4346. int r = 0, i;
  4347. gfx_v8_0_cp_compute_enable(adev, true);
  4348. ring = &adev->gfx.kiq.ring;
  4349. r = amdgpu_bo_reserve(ring->mqd_obj, false);
  4350. if (unlikely(r != 0))
  4351. goto done;
  4352. r = amdgpu_bo_kmap(ring->mqd_obj, &ring->mqd_ptr);
  4353. if (!r) {
  4354. r = gfx_v8_0_kiq_init_queue(ring);
  4355. amdgpu_bo_kunmap(ring->mqd_obj);
  4356. ring->mqd_ptr = NULL;
  4357. }
  4358. amdgpu_bo_unreserve(ring->mqd_obj);
  4359. if (r)
  4360. goto done;
  4361. for (i = 0; i < adev->gfx.num_compute_rings; i++) {
  4362. ring = &adev->gfx.compute_ring[i];
  4363. r = amdgpu_bo_reserve(ring->mqd_obj, false);
  4364. if (unlikely(r != 0))
  4365. goto done;
  4366. r = amdgpu_bo_kmap(ring->mqd_obj, &ring->mqd_ptr);
  4367. if (!r) {
  4368. r = gfx_v8_0_kcq_init_queue(ring);
  4369. amdgpu_bo_kunmap(ring->mqd_obj);
  4370. ring->mqd_ptr = NULL;
  4371. }
  4372. amdgpu_bo_unreserve(ring->mqd_obj);
  4373. if (r)
  4374. goto done;
  4375. }
  4376. gfx_v8_0_set_mec_doorbell_range(adev);
  4377. r = gfx_v8_0_kiq_kcq_enable(adev);
  4378. if (r)
  4379. goto done;
  4380. /* Test KIQ */
  4381. ring = &adev->gfx.kiq.ring;
  4382. ring->ready = true;
  4383. r = amdgpu_ring_test_ring(ring);
  4384. if (r) {
  4385. ring->ready = false;
  4386. goto done;
  4387. }
  4388. /* Test KCQs */
  4389. for (i = 0; i < adev->gfx.num_compute_rings; i++) {
  4390. ring = &adev->gfx.compute_ring[i];
  4391. ring->ready = true;
  4392. r = amdgpu_ring_test_ring(ring);
  4393. if (r)
  4394. ring->ready = false;
  4395. }
  4396. done:
  4397. return r;
  4398. }
  4399. static int gfx_v8_0_cp_resume(struct amdgpu_device *adev)
  4400. {
  4401. int r;
  4402. if (!(adev->flags & AMD_IS_APU))
  4403. gfx_v8_0_enable_gui_idle_interrupt(adev, false);
  4404. if (!adev->pp_enabled) {
  4405. if (adev->firmware.load_type != AMDGPU_FW_LOAD_SMU) {
  4406. /* legacy firmware loading */
  4407. r = gfx_v8_0_cp_gfx_load_microcode(adev);
  4408. if (r)
  4409. return r;
  4410. r = gfx_v8_0_cp_compute_load_microcode(adev);
  4411. if (r)
  4412. return r;
  4413. } else {
  4414. r = adev->smu.smumgr_funcs->check_fw_load_finish(adev,
  4415. AMDGPU_UCODE_ID_CP_CE);
  4416. if (r)
  4417. return -EINVAL;
  4418. r = adev->smu.smumgr_funcs->check_fw_load_finish(adev,
  4419. AMDGPU_UCODE_ID_CP_PFP);
  4420. if (r)
  4421. return -EINVAL;
  4422. r = adev->smu.smumgr_funcs->check_fw_load_finish(adev,
  4423. AMDGPU_UCODE_ID_CP_ME);
  4424. if (r)
  4425. return -EINVAL;
  4426. if (adev->asic_type == CHIP_TOPAZ) {
  4427. r = gfx_v8_0_cp_compute_load_microcode(adev);
  4428. if (r)
  4429. return r;
  4430. } else {
  4431. r = adev->smu.smumgr_funcs->check_fw_load_finish(adev,
  4432. AMDGPU_UCODE_ID_CP_MEC1);
  4433. if (r)
  4434. return -EINVAL;
  4435. }
  4436. }
  4437. }
  4438. r = gfx_v8_0_cp_gfx_resume(adev);
  4439. if (r)
  4440. return r;
  4441. r = gfx_v8_0_kiq_resume(adev);
  4442. if (r)
  4443. return r;
  4444. gfx_v8_0_enable_gui_idle_interrupt(adev, true);
  4445. return 0;
  4446. }
  4447. static void gfx_v8_0_cp_enable(struct amdgpu_device *adev, bool enable)
  4448. {
  4449. gfx_v8_0_cp_gfx_enable(adev, enable);
  4450. gfx_v8_0_cp_compute_enable(adev, enable);
  4451. }
  4452. static int gfx_v8_0_hw_init(void *handle)
  4453. {
  4454. int r;
  4455. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  4456. gfx_v8_0_init_golden_registers(adev);
  4457. gfx_v8_0_gpu_init(adev);
  4458. r = gfx_v8_0_rlc_resume(adev);
  4459. if (r)
  4460. return r;
  4461. r = gfx_v8_0_cp_resume(adev);
  4462. return r;
  4463. }
  4464. static int gfx_v8_0_hw_fini(void *handle)
  4465. {
  4466. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  4467. amdgpu_irq_put(adev, &adev->gfx.priv_reg_irq, 0);
  4468. amdgpu_irq_put(adev, &adev->gfx.priv_inst_irq, 0);
  4469. if (amdgpu_sriov_vf(adev)) {
  4470. pr_debug("For SRIOV client, shouldn't do anything.\n");
  4471. return 0;
  4472. }
  4473. gfx_v8_0_cp_enable(adev, false);
  4474. gfx_v8_0_rlc_stop(adev);
  4475. amdgpu_set_powergating_state(adev,
  4476. AMD_IP_BLOCK_TYPE_GFX, AMD_PG_STATE_UNGATE);
  4477. return 0;
  4478. }
  4479. static int gfx_v8_0_suspend(void *handle)
  4480. {
  4481. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  4482. adev->gfx.in_suspend = true;
  4483. return gfx_v8_0_hw_fini(adev);
  4484. }
  4485. static int gfx_v8_0_resume(void *handle)
  4486. {
  4487. int r;
  4488. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  4489. r = gfx_v8_0_hw_init(adev);
  4490. adev->gfx.in_suspend = false;
  4491. return r;
  4492. }
  4493. static bool gfx_v8_0_is_idle(void *handle)
  4494. {
  4495. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  4496. if (REG_GET_FIELD(RREG32(mmGRBM_STATUS), GRBM_STATUS, GUI_ACTIVE))
  4497. return false;
  4498. else
  4499. return true;
  4500. }
  4501. static int gfx_v8_0_wait_for_idle(void *handle)
  4502. {
  4503. unsigned i;
  4504. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  4505. for (i = 0; i < adev->usec_timeout; i++) {
  4506. if (gfx_v8_0_is_idle(handle))
  4507. return 0;
  4508. udelay(1);
  4509. }
  4510. return -ETIMEDOUT;
  4511. }
  4512. static bool gfx_v8_0_check_soft_reset(void *handle)
  4513. {
  4514. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  4515. u32 grbm_soft_reset = 0, srbm_soft_reset = 0;
  4516. u32 tmp;
  4517. /* GRBM_STATUS */
  4518. tmp = RREG32(mmGRBM_STATUS);
  4519. if (tmp & (GRBM_STATUS__PA_BUSY_MASK | GRBM_STATUS__SC_BUSY_MASK |
  4520. GRBM_STATUS__BCI_BUSY_MASK | GRBM_STATUS__SX_BUSY_MASK |
  4521. GRBM_STATUS__TA_BUSY_MASK | GRBM_STATUS__VGT_BUSY_MASK |
  4522. GRBM_STATUS__DB_BUSY_MASK | GRBM_STATUS__CB_BUSY_MASK |
  4523. GRBM_STATUS__GDS_BUSY_MASK | GRBM_STATUS__SPI_BUSY_MASK |
  4524. GRBM_STATUS__IA_BUSY_MASK | GRBM_STATUS__IA_BUSY_NO_DMA_MASK |
  4525. GRBM_STATUS__CP_BUSY_MASK | GRBM_STATUS__CP_COHERENCY_BUSY_MASK)) {
  4526. grbm_soft_reset = REG_SET_FIELD(grbm_soft_reset,
  4527. GRBM_SOFT_RESET, SOFT_RESET_CP, 1);
  4528. grbm_soft_reset = REG_SET_FIELD(grbm_soft_reset,
  4529. GRBM_SOFT_RESET, SOFT_RESET_GFX, 1);
  4530. srbm_soft_reset = REG_SET_FIELD(srbm_soft_reset,
  4531. SRBM_SOFT_RESET, SOFT_RESET_GRBM, 1);
  4532. }
  4533. /* GRBM_STATUS2 */
  4534. tmp = RREG32(mmGRBM_STATUS2);
  4535. if (REG_GET_FIELD(tmp, GRBM_STATUS2, RLC_BUSY))
  4536. grbm_soft_reset = REG_SET_FIELD(grbm_soft_reset,
  4537. GRBM_SOFT_RESET, SOFT_RESET_RLC, 1);
  4538. if (REG_GET_FIELD(tmp, GRBM_STATUS2, CPF_BUSY) ||
  4539. REG_GET_FIELD(tmp, GRBM_STATUS2, CPC_BUSY) ||
  4540. REG_GET_FIELD(tmp, GRBM_STATUS2, CPG_BUSY)) {
  4541. grbm_soft_reset = REG_SET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET,
  4542. SOFT_RESET_CPF, 1);
  4543. grbm_soft_reset = REG_SET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET,
  4544. SOFT_RESET_CPC, 1);
  4545. grbm_soft_reset = REG_SET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET,
  4546. SOFT_RESET_CPG, 1);
  4547. srbm_soft_reset = REG_SET_FIELD(srbm_soft_reset, SRBM_SOFT_RESET,
  4548. SOFT_RESET_GRBM, 1);
  4549. }
  4550. /* SRBM_STATUS */
  4551. tmp = RREG32(mmSRBM_STATUS);
  4552. if (REG_GET_FIELD(tmp, SRBM_STATUS, GRBM_RQ_PENDING))
  4553. srbm_soft_reset = REG_SET_FIELD(srbm_soft_reset,
  4554. SRBM_SOFT_RESET, SOFT_RESET_GRBM, 1);
  4555. if (REG_GET_FIELD(tmp, SRBM_STATUS, SEM_BUSY))
  4556. srbm_soft_reset = REG_SET_FIELD(srbm_soft_reset,
  4557. SRBM_SOFT_RESET, SOFT_RESET_SEM, 1);
  4558. if (grbm_soft_reset || srbm_soft_reset) {
  4559. adev->gfx.grbm_soft_reset = grbm_soft_reset;
  4560. adev->gfx.srbm_soft_reset = srbm_soft_reset;
  4561. return true;
  4562. } else {
  4563. adev->gfx.grbm_soft_reset = 0;
  4564. adev->gfx.srbm_soft_reset = 0;
  4565. return false;
  4566. }
  4567. }
  4568. static int gfx_v8_0_pre_soft_reset(void *handle)
  4569. {
  4570. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  4571. u32 grbm_soft_reset = 0, srbm_soft_reset = 0;
  4572. if ((!adev->gfx.grbm_soft_reset) &&
  4573. (!adev->gfx.srbm_soft_reset))
  4574. return 0;
  4575. grbm_soft_reset = adev->gfx.grbm_soft_reset;
  4576. srbm_soft_reset = adev->gfx.srbm_soft_reset;
  4577. /* stop the rlc */
  4578. gfx_v8_0_rlc_stop(adev);
  4579. if (REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_CP) ||
  4580. REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_GFX))
  4581. /* Disable GFX parsing/prefetching */
  4582. gfx_v8_0_cp_gfx_enable(adev, false);
  4583. if (REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_CP) ||
  4584. REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_CPF) ||
  4585. REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_CPC) ||
  4586. REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_CPG)) {
  4587. int i;
  4588. for (i = 0; i < adev->gfx.num_compute_rings; i++) {
  4589. struct amdgpu_ring *ring = &adev->gfx.compute_ring[i];
  4590. mutex_lock(&adev->srbm_mutex);
  4591. vi_srbm_select(adev, ring->me, ring->pipe, ring->queue, 0);
  4592. gfx_v8_0_deactivate_hqd(adev, 2);
  4593. vi_srbm_select(adev, 0, 0, 0, 0);
  4594. mutex_unlock(&adev->srbm_mutex);
  4595. }
  4596. /* Disable MEC parsing/prefetching */
  4597. gfx_v8_0_cp_compute_enable(adev, false);
  4598. }
  4599. return 0;
  4600. }
  4601. static int gfx_v8_0_soft_reset(void *handle)
  4602. {
  4603. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  4604. u32 grbm_soft_reset = 0, srbm_soft_reset = 0;
  4605. u32 tmp;
  4606. if ((!adev->gfx.grbm_soft_reset) &&
  4607. (!adev->gfx.srbm_soft_reset))
  4608. return 0;
  4609. grbm_soft_reset = adev->gfx.grbm_soft_reset;
  4610. srbm_soft_reset = adev->gfx.srbm_soft_reset;
  4611. if (grbm_soft_reset || srbm_soft_reset) {
  4612. tmp = RREG32(mmGMCON_DEBUG);
  4613. tmp = REG_SET_FIELD(tmp, GMCON_DEBUG, GFX_STALL, 1);
  4614. tmp = REG_SET_FIELD(tmp, GMCON_DEBUG, GFX_CLEAR, 1);
  4615. WREG32(mmGMCON_DEBUG, tmp);
  4616. udelay(50);
  4617. }
  4618. if (grbm_soft_reset) {
  4619. tmp = RREG32(mmGRBM_SOFT_RESET);
  4620. tmp |= grbm_soft_reset;
  4621. dev_info(adev->dev, "GRBM_SOFT_RESET=0x%08X\n", tmp);
  4622. WREG32(mmGRBM_SOFT_RESET, tmp);
  4623. tmp = RREG32(mmGRBM_SOFT_RESET);
  4624. udelay(50);
  4625. tmp &= ~grbm_soft_reset;
  4626. WREG32(mmGRBM_SOFT_RESET, tmp);
  4627. tmp = RREG32(mmGRBM_SOFT_RESET);
  4628. }
  4629. if (srbm_soft_reset) {
  4630. tmp = RREG32(mmSRBM_SOFT_RESET);
  4631. tmp |= srbm_soft_reset;
  4632. dev_info(adev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
  4633. WREG32(mmSRBM_SOFT_RESET, tmp);
  4634. tmp = RREG32(mmSRBM_SOFT_RESET);
  4635. udelay(50);
  4636. tmp &= ~srbm_soft_reset;
  4637. WREG32(mmSRBM_SOFT_RESET, tmp);
  4638. tmp = RREG32(mmSRBM_SOFT_RESET);
  4639. }
  4640. if (grbm_soft_reset || srbm_soft_reset) {
  4641. tmp = RREG32(mmGMCON_DEBUG);
  4642. tmp = REG_SET_FIELD(tmp, GMCON_DEBUG, GFX_STALL, 0);
  4643. tmp = REG_SET_FIELD(tmp, GMCON_DEBUG, GFX_CLEAR, 0);
  4644. WREG32(mmGMCON_DEBUG, tmp);
  4645. }
  4646. /* Wait a little for things to settle down */
  4647. udelay(50);
  4648. return 0;
  4649. }
  4650. static int gfx_v8_0_post_soft_reset(void *handle)
  4651. {
  4652. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  4653. u32 grbm_soft_reset = 0, srbm_soft_reset = 0;
  4654. if ((!adev->gfx.grbm_soft_reset) &&
  4655. (!adev->gfx.srbm_soft_reset))
  4656. return 0;
  4657. grbm_soft_reset = adev->gfx.grbm_soft_reset;
  4658. srbm_soft_reset = adev->gfx.srbm_soft_reset;
  4659. if (REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_CP) ||
  4660. REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_GFX))
  4661. gfx_v8_0_cp_gfx_resume(adev);
  4662. if (REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_CP) ||
  4663. REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_CPF) ||
  4664. REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_CPC) ||
  4665. REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_CPG)) {
  4666. int i;
  4667. for (i = 0; i < adev->gfx.num_compute_rings; i++) {
  4668. struct amdgpu_ring *ring = &adev->gfx.compute_ring[i];
  4669. mutex_lock(&adev->srbm_mutex);
  4670. vi_srbm_select(adev, ring->me, ring->pipe, ring->queue, 0);
  4671. gfx_v8_0_deactivate_hqd(adev, 2);
  4672. vi_srbm_select(adev, 0, 0, 0, 0);
  4673. mutex_unlock(&adev->srbm_mutex);
  4674. }
  4675. gfx_v8_0_kiq_resume(adev);
  4676. }
  4677. gfx_v8_0_rlc_start(adev);
  4678. return 0;
  4679. }
  4680. /**
  4681. * gfx_v8_0_get_gpu_clock_counter - return GPU clock counter snapshot
  4682. *
  4683. * @adev: amdgpu_device pointer
  4684. *
  4685. * Fetches a GPU clock counter snapshot.
  4686. * Returns the 64 bit clock counter snapshot.
  4687. */
  4688. static uint64_t gfx_v8_0_get_gpu_clock_counter(struct amdgpu_device *adev)
  4689. {
  4690. uint64_t clock;
  4691. mutex_lock(&adev->gfx.gpu_clock_mutex);
  4692. WREG32(mmRLC_CAPTURE_GPU_CLOCK_COUNT, 1);
  4693. clock = (uint64_t)RREG32(mmRLC_GPU_CLOCK_COUNT_LSB) |
  4694. ((uint64_t)RREG32(mmRLC_GPU_CLOCK_COUNT_MSB) << 32ULL);
  4695. mutex_unlock(&adev->gfx.gpu_clock_mutex);
  4696. return clock;
  4697. }
  4698. static void gfx_v8_0_ring_emit_gds_switch(struct amdgpu_ring *ring,
  4699. uint32_t vmid,
  4700. uint32_t gds_base, uint32_t gds_size,
  4701. uint32_t gws_base, uint32_t gws_size,
  4702. uint32_t oa_base, uint32_t oa_size)
  4703. {
  4704. gds_base = gds_base >> AMDGPU_GDS_SHIFT;
  4705. gds_size = gds_size >> AMDGPU_GDS_SHIFT;
  4706. gws_base = gws_base >> AMDGPU_GWS_SHIFT;
  4707. gws_size = gws_size >> AMDGPU_GWS_SHIFT;
  4708. oa_base = oa_base >> AMDGPU_OA_SHIFT;
  4709. oa_size = oa_size >> AMDGPU_OA_SHIFT;
  4710. /* GDS Base */
  4711. amdgpu_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  4712. amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
  4713. WRITE_DATA_DST_SEL(0)));
  4714. amdgpu_ring_write(ring, amdgpu_gds_reg_offset[vmid].mem_base);
  4715. amdgpu_ring_write(ring, 0);
  4716. amdgpu_ring_write(ring, gds_base);
  4717. /* GDS Size */
  4718. amdgpu_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  4719. amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
  4720. WRITE_DATA_DST_SEL(0)));
  4721. amdgpu_ring_write(ring, amdgpu_gds_reg_offset[vmid].mem_size);
  4722. amdgpu_ring_write(ring, 0);
  4723. amdgpu_ring_write(ring, gds_size);
  4724. /* GWS */
  4725. amdgpu_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  4726. amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
  4727. WRITE_DATA_DST_SEL(0)));
  4728. amdgpu_ring_write(ring, amdgpu_gds_reg_offset[vmid].gws);
  4729. amdgpu_ring_write(ring, 0);
  4730. amdgpu_ring_write(ring, gws_size << GDS_GWS_VMID0__SIZE__SHIFT | gws_base);
  4731. /* OA */
  4732. amdgpu_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  4733. amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
  4734. WRITE_DATA_DST_SEL(0)));
  4735. amdgpu_ring_write(ring, amdgpu_gds_reg_offset[vmid].oa);
  4736. amdgpu_ring_write(ring, 0);
  4737. amdgpu_ring_write(ring, (1 << (oa_size + oa_base)) - (1 << oa_base));
  4738. }
  4739. static uint32_t wave_read_ind(struct amdgpu_device *adev, uint32_t simd, uint32_t wave, uint32_t address)
  4740. {
  4741. WREG32(mmSQ_IND_INDEX,
  4742. (wave << SQ_IND_INDEX__WAVE_ID__SHIFT) |
  4743. (simd << SQ_IND_INDEX__SIMD_ID__SHIFT) |
  4744. (address << SQ_IND_INDEX__INDEX__SHIFT) |
  4745. (SQ_IND_INDEX__FORCE_READ_MASK));
  4746. return RREG32(mmSQ_IND_DATA);
  4747. }
  4748. static void wave_read_regs(struct amdgpu_device *adev, uint32_t simd,
  4749. uint32_t wave, uint32_t thread,
  4750. uint32_t regno, uint32_t num, uint32_t *out)
  4751. {
  4752. WREG32(mmSQ_IND_INDEX,
  4753. (wave << SQ_IND_INDEX__WAVE_ID__SHIFT) |
  4754. (simd << SQ_IND_INDEX__SIMD_ID__SHIFT) |
  4755. (regno << SQ_IND_INDEX__INDEX__SHIFT) |
  4756. (thread << SQ_IND_INDEX__THREAD_ID__SHIFT) |
  4757. (SQ_IND_INDEX__FORCE_READ_MASK) |
  4758. (SQ_IND_INDEX__AUTO_INCR_MASK));
  4759. while (num--)
  4760. *(out++) = RREG32(mmSQ_IND_DATA);
  4761. }
  4762. static void gfx_v8_0_read_wave_data(struct amdgpu_device *adev, uint32_t simd, uint32_t wave, uint32_t *dst, int *no_fields)
  4763. {
  4764. /* type 0 wave data */
  4765. dst[(*no_fields)++] = 0;
  4766. dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_STATUS);
  4767. dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_PC_LO);
  4768. dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_PC_HI);
  4769. dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_EXEC_LO);
  4770. dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_EXEC_HI);
  4771. dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_HW_ID);
  4772. dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_INST_DW0);
  4773. dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_INST_DW1);
  4774. dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_GPR_ALLOC);
  4775. dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_LDS_ALLOC);
  4776. dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_TRAPSTS);
  4777. dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_IB_STS);
  4778. dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_TBA_LO);
  4779. dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_TBA_HI);
  4780. dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_TMA_LO);
  4781. dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_TMA_HI);
  4782. dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_IB_DBG0);
  4783. dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_M0);
  4784. }
  4785. static void gfx_v8_0_read_wave_sgprs(struct amdgpu_device *adev, uint32_t simd,
  4786. uint32_t wave, uint32_t start,
  4787. uint32_t size, uint32_t *dst)
  4788. {
  4789. wave_read_regs(
  4790. adev, simd, wave, 0,
  4791. start + SQIND_WAVE_SGPRS_OFFSET, size, dst);
  4792. }
  4793. static const struct amdgpu_gfx_funcs gfx_v8_0_gfx_funcs = {
  4794. .get_gpu_clock_counter = &gfx_v8_0_get_gpu_clock_counter,
  4795. .select_se_sh = &gfx_v8_0_select_se_sh,
  4796. .read_wave_data = &gfx_v8_0_read_wave_data,
  4797. .read_wave_sgprs = &gfx_v8_0_read_wave_sgprs,
  4798. };
  4799. static int gfx_v8_0_early_init(void *handle)
  4800. {
  4801. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  4802. adev->gfx.num_gfx_rings = GFX8_NUM_GFX_RINGS;
  4803. adev->gfx.num_compute_rings = AMDGPU_MAX_COMPUTE_RINGS;
  4804. adev->gfx.funcs = &gfx_v8_0_gfx_funcs;
  4805. gfx_v8_0_set_ring_funcs(adev);
  4806. gfx_v8_0_set_irq_funcs(adev);
  4807. gfx_v8_0_set_gds_init(adev);
  4808. gfx_v8_0_set_rlc_funcs(adev);
  4809. return 0;
  4810. }
  4811. static int gfx_v8_0_late_init(void *handle)
  4812. {
  4813. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  4814. int r;
  4815. r = amdgpu_irq_get(adev, &adev->gfx.priv_reg_irq, 0);
  4816. if (r)
  4817. return r;
  4818. r = amdgpu_irq_get(adev, &adev->gfx.priv_inst_irq, 0);
  4819. if (r)
  4820. return r;
  4821. /* requires IBs so do in late init after IB pool is initialized */
  4822. r = gfx_v8_0_do_edc_gpr_workarounds(adev);
  4823. if (r)
  4824. return r;
  4825. amdgpu_set_powergating_state(adev,
  4826. AMD_IP_BLOCK_TYPE_GFX, AMD_PG_STATE_GATE);
  4827. return 0;
  4828. }
  4829. static void gfx_v8_0_enable_gfx_static_mg_power_gating(struct amdgpu_device *adev,
  4830. bool enable)
  4831. {
  4832. if ((adev->asic_type == CHIP_POLARIS11) ||
  4833. (adev->asic_type == CHIP_POLARIS12))
  4834. /* Send msg to SMU via Powerplay */
  4835. amdgpu_set_powergating_state(adev,
  4836. AMD_IP_BLOCK_TYPE_SMC,
  4837. enable ?
  4838. AMD_PG_STATE_GATE : AMD_PG_STATE_UNGATE);
  4839. WREG32_FIELD(RLC_PG_CNTL, STATIC_PER_CU_PG_ENABLE, enable ? 1 : 0);
  4840. }
  4841. static void gfx_v8_0_enable_gfx_dynamic_mg_power_gating(struct amdgpu_device *adev,
  4842. bool enable)
  4843. {
  4844. WREG32_FIELD(RLC_PG_CNTL, DYN_PER_CU_PG_ENABLE, enable ? 1 : 0);
  4845. }
  4846. static void polaris11_enable_gfx_quick_mg_power_gating(struct amdgpu_device *adev,
  4847. bool enable)
  4848. {
  4849. WREG32_FIELD(RLC_PG_CNTL, QUICK_PG_ENABLE, enable ? 1 : 0);
  4850. }
  4851. static void cz_enable_gfx_cg_power_gating(struct amdgpu_device *adev,
  4852. bool enable)
  4853. {
  4854. WREG32_FIELD(RLC_PG_CNTL, GFX_POWER_GATING_ENABLE, enable ? 1 : 0);
  4855. }
  4856. static void cz_enable_gfx_pipeline_power_gating(struct amdgpu_device *adev,
  4857. bool enable)
  4858. {
  4859. WREG32_FIELD(RLC_PG_CNTL, GFX_PIPELINE_PG_ENABLE, enable ? 1 : 0);
  4860. /* Read any GFX register to wake up GFX. */
  4861. if (!enable)
  4862. RREG32(mmDB_RENDER_CONTROL);
  4863. }
  4864. static void cz_update_gfx_cg_power_gating(struct amdgpu_device *adev,
  4865. bool enable)
  4866. {
  4867. if ((adev->pg_flags & AMD_PG_SUPPORT_GFX_PG) && enable) {
  4868. cz_enable_gfx_cg_power_gating(adev, true);
  4869. if (adev->pg_flags & AMD_PG_SUPPORT_GFX_PIPELINE)
  4870. cz_enable_gfx_pipeline_power_gating(adev, true);
  4871. } else {
  4872. cz_enable_gfx_cg_power_gating(adev, false);
  4873. cz_enable_gfx_pipeline_power_gating(adev, false);
  4874. }
  4875. }
  4876. static int gfx_v8_0_set_powergating_state(void *handle,
  4877. enum amd_powergating_state state)
  4878. {
  4879. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  4880. bool enable = (state == AMD_PG_STATE_GATE);
  4881. if (amdgpu_sriov_vf(adev))
  4882. return 0;
  4883. if (adev->pg_flags & (AMD_PG_SUPPORT_GFX_SMG |
  4884. AMD_PG_SUPPORT_RLC_SMU_HS |
  4885. AMD_PG_SUPPORT_CP |
  4886. AMD_PG_SUPPORT_GFX_DMG))
  4887. adev->gfx.rlc.funcs->enter_safe_mode(adev);
  4888. switch (adev->asic_type) {
  4889. case CHIP_CARRIZO:
  4890. case CHIP_STONEY:
  4891. if (adev->pg_flags & AMD_PG_SUPPORT_RLC_SMU_HS) {
  4892. cz_enable_sck_slow_down_on_power_up(adev, true);
  4893. cz_enable_sck_slow_down_on_power_down(adev, true);
  4894. } else {
  4895. cz_enable_sck_slow_down_on_power_up(adev, false);
  4896. cz_enable_sck_slow_down_on_power_down(adev, false);
  4897. }
  4898. if (adev->pg_flags & AMD_PG_SUPPORT_CP)
  4899. cz_enable_cp_power_gating(adev, true);
  4900. else
  4901. cz_enable_cp_power_gating(adev, false);
  4902. cz_update_gfx_cg_power_gating(adev, enable);
  4903. if ((adev->pg_flags & AMD_PG_SUPPORT_GFX_SMG) && enable)
  4904. gfx_v8_0_enable_gfx_static_mg_power_gating(adev, true);
  4905. else
  4906. gfx_v8_0_enable_gfx_static_mg_power_gating(adev, false);
  4907. if ((adev->pg_flags & AMD_PG_SUPPORT_GFX_DMG) && enable)
  4908. gfx_v8_0_enable_gfx_dynamic_mg_power_gating(adev, true);
  4909. else
  4910. gfx_v8_0_enable_gfx_dynamic_mg_power_gating(adev, false);
  4911. break;
  4912. case CHIP_POLARIS11:
  4913. case CHIP_POLARIS12:
  4914. if ((adev->pg_flags & AMD_PG_SUPPORT_GFX_SMG) && enable)
  4915. gfx_v8_0_enable_gfx_static_mg_power_gating(adev, true);
  4916. else
  4917. gfx_v8_0_enable_gfx_static_mg_power_gating(adev, false);
  4918. if ((adev->pg_flags & AMD_PG_SUPPORT_GFX_DMG) && enable)
  4919. gfx_v8_0_enable_gfx_dynamic_mg_power_gating(adev, true);
  4920. else
  4921. gfx_v8_0_enable_gfx_dynamic_mg_power_gating(adev, false);
  4922. if ((adev->pg_flags & AMD_PG_SUPPORT_GFX_QUICK_MG) && enable)
  4923. polaris11_enable_gfx_quick_mg_power_gating(adev, true);
  4924. else
  4925. polaris11_enable_gfx_quick_mg_power_gating(adev, false);
  4926. break;
  4927. default:
  4928. break;
  4929. }
  4930. if (adev->pg_flags & (AMD_PG_SUPPORT_GFX_SMG |
  4931. AMD_PG_SUPPORT_RLC_SMU_HS |
  4932. AMD_PG_SUPPORT_CP |
  4933. AMD_PG_SUPPORT_GFX_DMG))
  4934. adev->gfx.rlc.funcs->exit_safe_mode(adev);
  4935. return 0;
  4936. }
  4937. static void gfx_v8_0_get_clockgating_state(void *handle, u32 *flags)
  4938. {
  4939. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  4940. int data;
  4941. if (amdgpu_sriov_vf(adev))
  4942. *flags = 0;
  4943. /* AMD_CG_SUPPORT_GFX_MGCG */
  4944. data = RREG32(mmRLC_CGTT_MGCG_OVERRIDE);
  4945. if (!(data & RLC_CGTT_MGCG_OVERRIDE__CPF_MASK))
  4946. *flags |= AMD_CG_SUPPORT_GFX_MGCG;
  4947. /* AMD_CG_SUPPORT_GFX_CGLG */
  4948. data = RREG32(mmRLC_CGCG_CGLS_CTRL);
  4949. if (data & RLC_CGCG_CGLS_CTRL__CGCG_EN_MASK)
  4950. *flags |= AMD_CG_SUPPORT_GFX_CGCG;
  4951. /* AMD_CG_SUPPORT_GFX_CGLS */
  4952. if (data & RLC_CGCG_CGLS_CTRL__CGLS_EN_MASK)
  4953. *flags |= AMD_CG_SUPPORT_GFX_CGLS;
  4954. /* AMD_CG_SUPPORT_GFX_CGTS */
  4955. data = RREG32(mmCGTS_SM_CTRL_REG);
  4956. if (!(data & CGTS_SM_CTRL_REG__OVERRIDE_MASK))
  4957. *flags |= AMD_CG_SUPPORT_GFX_CGTS;
  4958. /* AMD_CG_SUPPORT_GFX_CGTS_LS */
  4959. if (!(data & CGTS_SM_CTRL_REG__LS_OVERRIDE_MASK))
  4960. *flags |= AMD_CG_SUPPORT_GFX_CGTS_LS;
  4961. /* AMD_CG_SUPPORT_GFX_RLC_LS */
  4962. data = RREG32(mmRLC_MEM_SLP_CNTL);
  4963. if (data & RLC_MEM_SLP_CNTL__RLC_MEM_LS_EN_MASK)
  4964. *flags |= AMD_CG_SUPPORT_GFX_RLC_LS | AMD_CG_SUPPORT_GFX_MGLS;
  4965. /* AMD_CG_SUPPORT_GFX_CP_LS */
  4966. data = RREG32(mmCP_MEM_SLP_CNTL);
  4967. if (data & CP_MEM_SLP_CNTL__CP_MEM_LS_EN_MASK)
  4968. *flags |= AMD_CG_SUPPORT_GFX_CP_LS | AMD_CG_SUPPORT_GFX_MGLS;
  4969. }
  4970. static void gfx_v8_0_send_serdes_cmd(struct amdgpu_device *adev,
  4971. uint32_t reg_addr, uint32_t cmd)
  4972. {
  4973. uint32_t data;
  4974. gfx_v8_0_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
  4975. WREG32(mmRLC_SERDES_WR_CU_MASTER_MASK, 0xffffffff);
  4976. WREG32(mmRLC_SERDES_WR_NONCU_MASTER_MASK, 0xffffffff);
  4977. data = RREG32(mmRLC_SERDES_WR_CTRL);
  4978. if (adev->asic_type == CHIP_STONEY)
  4979. data &= ~(RLC_SERDES_WR_CTRL__WRITE_COMMAND_MASK |
  4980. RLC_SERDES_WR_CTRL__READ_COMMAND_MASK |
  4981. RLC_SERDES_WR_CTRL__P1_SELECT_MASK |
  4982. RLC_SERDES_WR_CTRL__P2_SELECT_MASK |
  4983. RLC_SERDES_WR_CTRL__RDDATA_RESET_MASK |
  4984. RLC_SERDES_WR_CTRL__POWER_DOWN_MASK |
  4985. RLC_SERDES_WR_CTRL__POWER_UP_MASK |
  4986. RLC_SERDES_WR_CTRL__SHORT_FORMAT_MASK |
  4987. RLC_SERDES_WR_CTRL__SRBM_OVERRIDE_MASK);
  4988. else
  4989. data &= ~(RLC_SERDES_WR_CTRL__WRITE_COMMAND_MASK |
  4990. RLC_SERDES_WR_CTRL__READ_COMMAND_MASK |
  4991. RLC_SERDES_WR_CTRL__P1_SELECT_MASK |
  4992. RLC_SERDES_WR_CTRL__P2_SELECT_MASK |
  4993. RLC_SERDES_WR_CTRL__RDDATA_RESET_MASK |
  4994. RLC_SERDES_WR_CTRL__POWER_DOWN_MASK |
  4995. RLC_SERDES_WR_CTRL__POWER_UP_MASK |
  4996. RLC_SERDES_WR_CTRL__SHORT_FORMAT_MASK |
  4997. RLC_SERDES_WR_CTRL__BPM_DATA_MASK |
  4998. RLC_SERDES_WR_CTRL__REG_ADDR_MASK |
  4999. RLC_SERDES_WR_CTRL__SRBM_OVERRIDE_MASK);
  5000. data |= (RLC_SERDES_WR_CTRL__RSVD_BPM_ADDR_MASK |
  5001. (cmd << RLC_SERDES_WR_CTRL__BPM_DATA__SHIFT) |
  5002. (reg_addr << RLC_SERDES_WR_CTRL__REG_ADDR__SHIFT) |
  5003. (0xff << RLC_SERDES_WR_CTRL__BPM_ADDR__SHIFT));
  5004. WREG32(mmRLC_SERDES_WR_CTRL, data);
  5005. }
  5006. #define MSG_ENTER_RLC_SAFE_MODE 1
  5007. #define MSG_EXIT_RLC_SAFE_MODE 0
  5008. #define RLC_GPR_REG2__REQ_MASK 0x00000001
  5009. #define RLC_GPR_REG2__REQ__SHIFT 0
  5010. #define RLC_GPR_REG2__MESSAGE__SHIFT 0x00000001
  5011. #define RLC_GPR_REG2__MESSAGE_MASK 0x0000001e
  5012. static void iceland_enter_rlc_safe_mode(struct amdgpu_device *adev)
  5013. {
  5014. u32 data;
  5015. unsigned i;
  5016. data = RREG32(mmRLC_CNTL);
  5017. if (!(data & RLC_CNTL__RLC_ENABLE_F32_MASK))
  5018. return;
  5019. if (adev->cg_flags & (AMD_CG_SUPPORT_GFX_CGCG | AMD_CG_SUPPORT_GFX_MGCG)) {
  5020. data |= RLC_SAFE_MODE__CMD_MASK;
  5021. data &= ~RLC_SAFE_MODE__MESSAGE_MASK;
  5022. data |= (1 << RLC_SAFE_MODE__MESSAGE__SHIFT);
  5023. WREG32(mmRLC_SAFE_MODE, data);
  5024. for (i = 0; i < adev->usec_timeout; i++) {
  5025. if ((RREG32(mmRLC_GPM_STAT) &
  5026. (RLC_GPM_STAT__GFX_CLOCK_STATUS_MASK |
  5027. RLC_GPM_STAT__GFX_POWER_STATUS_MASK)) ==
  5028. (RLC_GPM_STAT__GFX_CLOCK_STATUS_MASK |
  5029. RLC_GPM_STAT__GFX_POWER_STATUS_MASK))
  5030. break;
  5031. udelay(1);
  5032. }
  5033. for (i = 0; i < adev->usec_timeout; i++) {
  5034. if (!REG_GET_FIELD(RREG32(mmRLC_SAFE_MODE), RLC_SAFE_MODE, CMD))
  5035. break;
  5036. udelay(1);
  5037. }
  5038. adev->gfx.rlc.in_safe_mode = true;
  5039. }
  5040. }
  5041. static void iceland_exit_rlc_safe_mode(struct amdgpu_device *adev)
  5042. {
  5043. u32 data = 0;
  5044. unsigned i;
  5045. data = RREG32(mmRLC_CNTL);
  5046. if (!(data & RLC_CNTL__RLC_ENABLE_F32_MASK))
  5047. return;
  5048. if (adev->cg_flags & (AMD_CG_SUPPORT_GFX_CGCG | AMD_CG_SUPPORT_GFX_MGCG)) {
  5049. if (adev->gfx.rlc.in_safe_mode) {
  5050. data |= RLC_SAFE_MODE__CMD_MASK;
  5051. data &= ~RLC_SAFE_MODE__MESSAGE_MASK;
  5052. WREG32(mmRLC_SAFE_MODE, data);
  5053. adev->gfx.rlc.in_safe_mode = false;
  5054. }
  5055. }
  5056. for (i = 0; i < adev->usec_timeout; i++) {
  5057. if (!REG_GET_FIELD(RREG32(mmRLC_SAFE_MODE), RLC_SAFE_MODE, CMD))
  5058. break;
  5059. udelay(1);
  5060. }
  5061. }
  5062. static const struct amdgpu_rlc_funcs iceland_rlc_funcs = {
  5063. .enter_safe_mode = iceland_enter_rlc_safe_mode,
  5064. .exit_safe_mode = iceland_exit_rlc_safe_mode
  5065. };
  5066. static void gfx_v8_0_update_medium_grain_clock_gating(struct amdgpu_device *adev,
  5067. bool enable)
  5068. {
  5069. uint32_t temp, data;
  5070. adev->gfx.rlc.funcs->enter_safe_mode(adev);
  5071. /* It is disabled by HW by default */
  5072. if (enable && (adev->cg_flags & AMD_CG_SUPPORT_GFX_MGCG)) {
  5073. if (adev->cg_flags & AMD_CG_SUPPORT_GFX_MGLS) {
  5074. if (adev->cg_flags & AMD_CG_SUPPORT_GFX_RLC_LS)
  5075. /* 1 - RLC memory Light sleep */
  5076. WREG32_FIELD(RLC_MEM_SLP_CNTL, RLC_MEM_LS_EN, 1);
  5077. if (adev->cg_flags & AMD_CG_SUPPORT_GFX_CP_LS)
  5078. WREG32_FIELD(CP_MEM_SLP_CNTL, CP_MEM_LS_EN, 1);
  5079. }
  5080. /* 3 - RLC_CGTT_MGCG_OVERRIDE */
  5081. temp = data = RREG32(mmRLC_CGTT_MGCG_OVERRIDE);
  5082. if (adev->flags & AMD_IS_APU)
  5083. data &= ~(RLC_CGTT_MGCG_OVERRIDE__CPF_MASK |
  5084. RLC_CGTT_MGCG_OVERRIDE__RLC_MASK |
  5085. RLC_CGTT_MGCG_OVERRIDE__MGCG_MASK);
  5086. else
  5087. data &= ~(RLC_CGTT_MGCG_OVERRIDE__CPF_MASK |
  5088. RLC_CGTT_MGCG_OVERRIDE__RLC_MASK |
  5089. RLC_CGTT_MGCG_OVERRIDE__MGCG_MASK |
  5090. RLC_CGTT_MGCG_OVERRIDE__GRBM_MASK);
  5091. if (temp != data)
  5092. WREG32(mmRLC_CGTT_MGCG_OVERRIDE, data);
  5093. /* 4 - wait for RLC_SERDES_CU_MASTER & RLC_SERDES_NONCU_MASTER idle */
  5094. gfx_v8_0_wait_for_rlc_serdes(adev);
  5095. /* 5 - clear mgcg override */
  5096. gfx_v8_0_send_serdes_cmd(adev, BPM_REG_MGCG_OVERRIDE, CLE_BPM_SERDES_CMD);
  5097. if (adev->cg_flags & AMD_CG_SUPPORT_GFX_CGTS) {
  5098. /* 6 - Enable CGTS(Tree Shade) MGCG /MGLS */
  5099. temp = data = RREG32(mmCGTS_SM_CTRL_REG);
  5100. data &= ~(CGTS_SM_CTRL_REG__SM_MODE_MASK);
  5101. data |= (0x2 << CGTS_SM_CTRL_REG__SM_MODE__SHIFT);
  5102. data |= CGTS_SM_CTRL_REG__SM_MODE_ENABLE_MASK;
  5103. data &= ~CGTS_SM_CTRL_REG__OVERRIDE_MASK;
  5104. if ((adev->cg_flags & AMD_CG_SUPPORT_GFX_MGLS) &&
  5105. (adev->cg_flags & AMD_CG_SUPPORT_GFX_CGTS_LS))
  5106. data &= ~CGTS_SM_CTRL_REG__LS_OVERRIDE_MASK;
  5107. data |= CGTS_SM_CTRL_REG__ON_MONITOR_ADD_EN_MASK;
  5108. data |= (0x96 << CGTS_SM_CTRL_REG__ON_MONITOR_ADD__SHIFT);
  5109. if (temp != data)
  5110. WREG32(mmCGTS_SM_CTRL_REG, data);
  5111. }
  5112. udelay(50);
  5113. /* 7 - wait for RLC_SERDES_CU_MASTER & RLC_SERDES_NONCU_MASTER idle */
  5114. gfx_v8_0_wait_for_rlc_serdes(adev);
  5115. } else {
  5116. /* 1 - MGCG_OVERRIDE[0] for CP and MGCG_OVERRIDE[1] for RLC */
  5117. temp = data = RREG32(mmRLC_CGTT_MGCG_OVERRIDE);
  5118. data |= (RLC_CGTT_MGCG_OVERRIDE__CPF_MASK |
  5119. RLC_CGTT_MGCG_OVERRIDE__RLC_MASK |
  5120. RLC_CGTT_MGCG_OVERRIDE__MGCG_MASK |
  5121. RLC_CGTT_MGCG_OVERRIDE__GRBM_MASK);
  5122. if (temp != data)
  5123. WREG32(mmRLC_CGTT_MGCG_OVERRIDE, data);
  5124. /* 2 - disable MGLS in RLC */
  5125. data = RREG32(mmRLC_MEM_SLP_CNTL);
  5126. if (data & RLC_MEM_SLP_CNTL__RLC_MEM_LS_EN_MASK) {
  5127. data &= ~RLC_MEM_SLP_CNTL__RLC_MEM_LS_EN_MASK;
  5128. WREG32(mmRLC_MEM_SLP_CNTL, data);
  5129. }
  5130. /* 3 - disable MGLS in CP */
  5131. data = RREG32(mmCP_MEM_SLP_CNTL);
  5132. if (data & CP_MEM_SLP_CNTL__CP_MEM_LS_EN_MASK) {
  5133. data &= ~CP_MEM_SLP_CNTL__CP_MEM_LS_EN_MASK;
  5134. WREG32(mmCP_MEM_SLP_CNTL, data);
  5135. }
  5136. /* 4 - Disable CGTS(Tree Shade) MGCG and MGLS */
  5137. temp = data = RREG32(mmCGTS_SM_CTRL_REG);
  5138. data |= (CGTS_SM_CTRL_REG__OVERRIDE_MASK |
  5139. CGTS_SM_CTRL_REG__LS_OVERRIDE_MASK);
  5140. if (temp != data)
  5141. WREG32(mmCGTS_SM_CTRL_REG, data);
  5142. /* 5 - wait for RLC_SERDES_CU_MASTER & RLC_SERDES_NONCU_MASTER idle */
  5143. gfx_v8_0_wait_for_rlc_serdes(adev);
  5144. /* 6 - set mgcg override */
  5145. gfx_v8_0_send_serdes_cmd(adev, BPM_REG_MGCG_OVERRIDE, SET_BPM_SERDES_CMD);
  5146. udelay(50);
  5147. /* 7- wait for RLC_SERDES_CU_MASTER & RLC_SERDES_NONCU_MASTER idle */
  5148. gfx_v8_0_wait_for_rlc_serdes(adev);
  5149. }
  5150. adev->gfx.rlc.funcs->exit_safe_mode(adev);
  5151. }
  5152. static void gfx_v8_0_update_coarse_grain_clock_gating(struct amdgpu_device *adev,
  5153. bool enable)
  5154. {
  5155. uint32_t temp, temp1, data, data1;
  5156. temp = data = RREG32(mmRLC_CGCG_CGLS_CTRL);
  5157. adev->gfx.rlc.funcs->enter_safe_mode(adev);
  5158. if (enable && (adev->cg_flags & AMD_CG_SUPPORT_GFX_CGCG)) {
  5159. temp1 = data1 = RREG32(mmRLC_CGTT_MGCG_OVERRIDE);
  5160. data1 &= ~RLC_CGTT_MGCG_OVERRIDE__CGCG_MASK;
  5161. if (temp1 != data1)
  5162. WREG32(mmRLC_CGTT_MGCG_OVERRIDE, data1);
  5163. /* : wait for RLC_SERDES_CU_MASTER & RLC_SERDES_NONCU_MASTER idle */
  5164. gfx_v8_0_wait_for_rlc_serdes(adev);
  5165. /* 2 - clear cgcg override */
  5166. gfx_v8_0_send_serdes_cmd(adev, BPM_REG_CGCG_OVERRIDE, CLE_BPM_SERDES_CMD);
  5167. /* wait for RLC_SERDES_CU_MASTER & RLC_SERDES_NONCU_MASTER idle */
  5168. gfx_v8_0_wait_for_rlc_serdes(adev);
  5169. /* 3 - write cmd to set CGLS */
  5170. gfx_v8_0_send_serdes_cmd(adev, BPM_REG_CGLS_EN, SET_BPM_SERDES_CMD);
  5171. /* 4 - enable cgcg */
  5172. data |= RLC_CGCG_CGLS_CTRL__CGCG_EN_MASK;
  5173. if (adev->cg_flags & AMD_CG_SUPPORT_GFX_CGLS) {
  5174. /* enable cgls*/
  5175. data |= RLC_CGCG_CGLS_CTRL__CGLS_EN_MASK;
  5176. temp1 = data1 = RREG32(mmRLC_CGTT_MGCG_OVERRIDE);
  5177. data1 &= ~RLC_CGTT_MGCG_OVERRIDE__CGLS_MASK;
  5178. if (temp1 != data1)
  5179. WREG32(mmRLC_CGTT_MGCG_OVERRIDE, data1);
  5180. } else {
  5181. data &= ~RLC_CGCG_CGLS_CTRL__CGLS_EN_MASK;
  5182. }
  5183. if (temp != data)
  5184. WREG32(mmRLC_CGCG_CGLS_CTRL, data);
  5185. /* 5 enable cntx_empty_int_enable/cntx_busy_int_enable/
  5186. * Cmp_busy/GFX_Idle interrupts
  5187. */
  5188. gfx_v8_0_enable_gui_idle_interrupt(adev, true);
  5189. } else {
  5190. /* disable cntx_empty_int_enable & GFX Idle interrupt */
  5191. gfx_v8_0_enable_gui_idle_interrupt(adev, false);
  5192. /* TEST CGCG */
  5193. temp1 = data1 = RREG32(mmRLC_CGTT_MGCG_OVERRIDE);
  5194. data1 |= (RLC_CGTT_MGCG_OVERRIDE__CGCG_MASK |
  5195. RLC_CGTT_MGCG_OVERRIDE__CGLS_MASK);
  5196. if (temp1 != data1)
  5197. WREG32(mmRLC_CGTT_MGCG_OVERRIDE, data1);
  5198. /* read gfx register to wake up cgcg */
  5199. RREG32(mmCB_CGTT_SCLK_CTRL);
  5200. RREG32(mmCB_CGTT_SCLK_CTRL);
  5201. RREG32(mmCB_CGTT_SCLK_CTRL);
  5202. RREG32(mmCB_CGTT_SCLK_CTRL);
  5203. /* wait for RLC_SERDES_CU_MASTER & RLC_SERDES_NONCU_MASTER idle */
  5204. gfx_v8_0_wait_for_rlc_serdes(adev);
  5205. /* write cmd to Set CGCG Overrride */
  5206. gfx_v8_0_send_serdes_cmd(adev, BPM_REG_CGCG_OVERRIDE, SET_BPM_SERDES_CMD);
  5207. /* wait for RLC_SERDES_CU_MASTER & RLC_SERDES_NONCU_MASTER idle */
  5208. gfx_v8_0_wait_for_rlc_serdes(adev);
  5209. /* write cmd to Clear CGLS */
  5210. gfx_v8_0_send_serdes_cmd(adev, BPM_REG_CGLS_EN, CLE_BPM_SERDES_CMD);
  5211. /* disable cgcg, cgls should be disabled too. */
  5212. data &= ~(RLC_CGCG_CGLS_CTRL__CGCG_EN_MASK |
  5213. RLC_CGCG_CGLS_CTRL__CGLS_EN_MASK);
  5214. if (temp != data)
  5215. WREG32(mmRLC_CGCG_CGLS_CTRL, data);
  5216. /* enable interrupts again for PG */
  5217. gfx_v8_0_enable_gui_idle_interrupt(adev, true);
  5218. }
  5219. gfx_v8_0_wait_for_rlc_serdes(adev);
  5220. adev->gfx.rlc.funcs->exit_safe_mode(adev);
  5221. }
  5222. static int gfx_v8_0_update_gfx_clock_gating(struct amdgpu_device *adev,
  5223. bool enable)
  5224. {
  5225. if (enable) {
  5226. /* CGCG/CGLS should be enabled after MGCG/MGLS/TS(CG/LS)
  5227. * === MGCG + MGLS + TS(CG/LS) ===
  5228. */
  5229. gfx_v8_0_update_medium_grain_clock_gating(adev, enable);
  5230. gfx_v8_0_update_coarse_grain_clock_gating(adev, enable);
  5231. } else {
  5232. /* CGCG/CGLS should be disabled before MGCG/MGLS/TS(CG/LS)
  5233. * === CGCG + CGLS ===
  5234. */
  5235. gfx_v8_0_update_coarse_grain_clock_gating(adev, enable);
  5236. gfx_v8_0_update_medium_grain_clock_gating(adev, enable);
  5237. }
  5238. return 0;
  5239. }
  5240. static int gfx_v8_0_tonga_update_gfx_clock_gating(struct amdgpu_device *adev,
  5241. enum amd_clockgating_state state)
  5242. {
  5243. uint32_t msg_id, pp_state = 0;
  5244. uint32_t pp_support_state = 0;
  5245. void *pp_handle = adev->powerplay.pp_handle;
  5246. if (adev->cg_flags & (AMD_CG_SUPPORT_GFX_CGCG | AMD_CG_SUPPORT_GFX_CGLS)) {
  5247. if (adev->cg_flags & AMD_CG_SUPPORT_GFX_CGLS) {
  5248. pp_support_state = PP_STATE_SUPPORT_LS;
  5249. pp_state = PP_STATE_LS;
  5250. }
  5251. if (adev->cg_flags & AMD_CG_SUPPORT_GFX_CGCG) {
  5252. pp_support_state |= PP_STATE_SUPPORT_CG;
  5253. pp_state |= PP_STATE_CG;
  5254. }
  5255. if (state == AMD_CG_STATE_UNGATE)
  5256. pp_state = 0;
  5257. msg_id = PP_CG_MSG_ID(PP_GROUP_GFX,
  5258. PP_BLOCK_GFX_CG,
  5259. pp_support_state,
  5260. pp_state);
  5261. amd_set_clockgating_by_smu(pp_handle, msg_id);
  5262. }
  5263. if (adev->cg_flags & (AMD_CG_SUPPORT_GFX_MGCG | AMD_CG_SUPPORT_GFX_MGLS)) {
  5264. if (adev->cg_flags & AMD_CG_SUPPORT_GFX_MGLS) {
  5265. pp_support_state = PP_STATE_SUPPORT_LS;
  5266. pp_state = PP_STATE_LS;
  5267. }
  5268. if (adev->cg_flags & AMD_CG_SUPPORT_GFX_MGCG) {
  5269. pp_support_state |= PP_STATE_SUPPORT_CG;
  5270. pp_state |= PP_STATE_CG;
  5271. }
  5272. if (state == AMD_CG_STATE_UNGATE)
  5273. pp_state = 0;
  5274. msg_id = PP_CG_MSG_ID(PP_GROUP_GFX,
  5275. PP_BLOCK_GFX_MG,
  5276. pp_support_state,
  5277. pp_state);
  5278. amd_set_clockgating_by_smu(pp_handle, msg_id);
  5279. }
  5280. return 0;
  5281. }
  5282. static int gfx_v8_0_polaris_update_gfx_clock_gating(struct amdgpu_device *adev,
  5283. enum amd_clockgating_state state)
  5284. {
  5285. uint32_t msg_id, pp_state = 0;
  5286. uint32_t pp_support_state = 0;
  5287. void *pp_handle = adev->powerplay.pp_handle;
  5288. if (adev->cg_flags & (AMD_CG_SUPPORT_GFX_CGCG | AMD_CG_SUPPORT_GFX_CGLS)) {
  5289. if (adev->cg_flags & AMD_CG_SUPPORT_GFX_CGLS) {
  5290. pp_support_state = PP_STATE_SUPPORT_LS;
  5291. pp_state = PP_STATE_LS;
  5292. }
  5293. if (adev->cg_flags & AMD_CG_SUPPORT_GFX_CGCG) {
  5294. pp_support_state |= PP_STATE_SUPPORT_CG;
  5295. pp_state |= PP_STATE_CG;
  5296. }
  5297. if (state == AMD_CG_STATE_UNGATE)
  5298. pp_state = 0;
  5299. msg_id = PP_CG_MSG_ID(PP_GROUP_GFX,
  5300. PP_BLOCK_GFX_CG,
  5301. pp_support_state,
  5302. pp_state);
  5303. amd_set_clockgating_by_smu(pp_handle, msg_id);
  5304. }
  5305. if (adev->cg_flags & (AMD_CG_SUPPORT_GFX_3D_CGCG | AMD_CG_SUPPORT_GFX_3D_CGLS)) {
  5306. if (adev->cg_flags & AMD_CG_SUPPORT_GFX_3D_CGLS) {
  5307. pp_support_state = PP_STATE_SUPPORT_LS;
  5308. pp_state = PP_STATE_LS;
  5309. }
  5310. if (adev->cg_flags & AMD_CG_SUPPORT_GFX_3D_CGCG) {
  5311. pp_support_state |= PP_STATE_SUPPORT_CG;
  5312. pp_state |= PP_STATE_CG;
  5313. }
  5314. if (state == AMD_CG_STATE_UNGATE)
  5315. pp_state = 0;
  5316. msg_id = PP_CG_MSG_ID(PP_GROUP_GFX,
  5317. PP_BLOCK_GFX_3D,
  5318. pp_support_state,
  5319. pp_state);
  5320. amd_set_clockgating_by_smu(pp_handle, msg_id);
  5321. }
  5322. if (adev->cg_flags & (AMD_CG_SUPPORT_GFX_MGCG | AMD_CG_SUPPORT_GFX_MGLS)) {
  5323. if (adev->cg_flags & AMD_CG_SUPPORT_GFX_MGLS) {
  5324. pp_support_state = PP_STATE_SUPPORT_LS;
  5325. pp_state = PP_STATE_LS;
  5326. }
  5327. if (adev->cg_flags & AMD_CG_SUPPORT_GFX_MGCG) {
  5328. pp_support_state |= PP_STATE_SUPPORT_CG;
  5329. pp_state |= PP_STATE_CG;
  5330. }
  5331. if (state == AMD_CG_STATE_UNGATE)
  5332. pp_state = 0;
  5333. msg_id = PP_CG_MSG_ID(PP_GROUP_GFX,
  5334. PP_BLOCK_GFX_MG,
  5335. pp_support_state,
  5336. pp_state);
  5337. amd_set_clockgating_by_smu(pp_handle, msg_id);
  5338. }
  5339. if (adev->cg_flags & AMD_CG_SUPPORT_GFX_RLC_LS) {
  5340. pp_support_state = PP_STATE_SUPPORT_LS;
  5341. if (state == AMD_CG_STATE_UNGATE)
  5342. pp_state = 0;
  5343. else
  5344. pp_state = PP_STATE_LS;
  5345. msg_id = PP_CG_MSG_ID(PP_GROUP_GFX,
  5346. PP_BLOCK_GFX_RLC,
  5347. pp_support_state,
  5348. pp_state);
  5349. amd_set_clockgating_by_smu(pp_handle, msg_id);
  5350. }
  5351. if (adev->cg_flags & AMD_CG_SUPPORT_GFX_CP_LS) {
  5352. pp_support_state = PP_STATE_SUPPORT_LS;
  5353. if (state == AMD_CG_STATE_UNGATE)
  5354. pp_state = 0;
  5355. else
  5356. pp_state = PP_STATE_LS;
  5357. msg_id = PP_CG_MSG_ID(PP_GROUP_GFX,
  5358. PP_BLOCK_GFX_CP,
  5359. pp_support_state,
  5360. pp_state);
  5361. amd_set_clockgating_by_smu(pp_handle, msg_id);
  5362. }
  5363. return 0;
  5364. }
  5365. static int gfx_v8_0_set_clockgating_state(void *handle,
  5366. enum amd_clockgating_state state)
  5367. {
  5368. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  5369. if (amdgpu_sriov_vf(adev))
  5370. return 0;
  5371. switch (adev->asic_type) {
  5372. case CHIP_FIJI:
  5373. case CHIP_CARRIZO:
  5374. case CHIP_STONEY:
  5375. gfx_v8_0_update_gfx_clock_gating(adev,
  5376. state == AMD_CG_STATE_GATE);
  5377. break;
  5378. case CHIP_TONGA:
  5379. gfx_v8_0_tonga_update_gfx_clock_gating(adev, state);
  5380. break;
  5381. case CHIP_POLARIS10:
  5382. case CHIP_POLARIS11:
  5383. case CHIP_POLARIS12:
  5384. gfx_v8_0_polaris_update_gfx_clock_gating(adev, state);
  5385. break;
  5386. default:
  5387. break;
  5388. }
  5389. return 0;
  5390. }
  5391. static u64 gfx_v8_0_ring_get_rptr(struct amdgpu_ring *ring)
  5392. {
  5393. return ring->adev->wb.wb[ring->rptr_offs];
  5394. }
  5395. static u64 gfx_v8_0_ring_get_wptr_gfx(struct amdgpu_ring *ring)
  5396. {
  5397. struct amdgpu_device *adev = ring->adev;
  5398. if (ring->use_doorbell)
  5399. /* XXX check if swapping is necessary on BE */
  5400. return ring->adev->wb.wb[ring->wptr_offs];
  5401. else
  5402. return RREG32(mmCP_RB0_WPTR);
  5403. }
  5404. static void gfx_v8_0_ring_set_wptr_gfx(struct amdgpu_ring *ring)
  5405. {
  5406. struct amdgpu_device *adev = ring->adev;
  5407. if (ring->use_doorbell) {
  5408. /* XXX check if swapping is necessary on BE */
  5409. adev->wb.wb[ring->wptr_offs] = lower_32_bits(ring->wptr);
  5410. WDOORBELL32(ring->doorbell_index, lower_32_bits(ring->wptr));
  5411. } else {
  5412. WREG32(mmCP_RB0_WPTR, lower_32_bits(ring->wptr));
  5413. (void)RREG32(mmCP_RB0_WPTR);
  5414. }
  5415. }
  5416. static void gfx_v8_0_ring_emit_hdp_flush(struct amdgpu_ring *ring)
  5417. {
  5418. u32 ref_and_mask, reg_mem_engine;
  5419. if ((ring->funcs->type == AMDGPU_RING_TYPE_COMPUTE) ||
  5420. (ring->funcs->type == AMDGPU_RING_TYPE_KIQ)) {
  5421. switch (ring->me) {
  5422. case 1:
  5423. ref_and_mask = GPU_HDP_FLUSH_DONE__CP2_MASK << ring->pipe;
  5424. break;
  5425. case 2:
  5426. ref_and_mask = GPU_HDP_FLUSH_DONE__CP6_MASK << ring->pipe;
  5427. break;
  5428. default:
  5429. return;
  5430. }
  5431. reg_mem_engine = 0;
  5432. } else {
  5433. ref_and_mask = GPU_HDP_FLUSH_DONE__CP0_MASK;
  5434. reg_mem_engine = WAIT_REG_MEM_ENGINE(1); /* pfp */
  5435. }
  5436. amdgpu_ring_write(ring, PACKET3(PACKET3_WAIT_REG_MEM, 5));
  5437. amdgpu_ring_write(ring, (WAIT_REG_MEM_OPERATION(1) | /* write, wait, write */
  5438. WAIT_REG_MEM_FUNCTION(3) | /* == */
  5439. reg_mem_engine));
  5440. amdgpu_ring_write(ring, mmGPU_HDP_FLUSH_REQ);
  5441. amdgpu_ring_write(ring, mmGPU_HDP_FLUSH_DONE);
  5442. amdgpu_ring_write(ring, ref_and_mask);
  5443. amdgpu_ring_write(ring, ref_and_mask);
  5444. amdgpu_ring_write(ring, 0x20); /* poll interval */
  5445. }
  5446. static void gfx_v8_0_ring_emit_vgt_flush(struct amdgpu_ring *ring)
  5447. {
  5448. amdgpu_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE, 0));
  5449. amdgpu_ring_write(ring, EVENT_TYPE(VS_PARTIAL_FLUSH) |
  5450. EVENT_INDEX(4));
  5451. amdgpu_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE, 0));
  5452. amdgpu_ring_write(ring, EVENT_TYPE(VGT_FLUSH) |
  5453. EVENT_INDEX(0));
  5454. }
  5455. static void gfx_v8_0_ring_emit_hdp_invalidate(struct amdgpu_ring *ring)
  5456. {
  5457. amdgpu_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  5458. amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
  5459. WRITE_DATA_DST_SEL(0) |
  5460. WR_CONFIRM));
  5461. amdgpu_ring_write(ring, mmHDP_DEBUG0);
  5462. amdgpu_ring_write(ring, 0);
  5463. amdgpu_ring_write(ring, 1);
  5464. }
  5465. static void gfx_v8_0_ring_emit_ib_gfx(struct amdgpu_ring *ring,
  5466. struct amdgpu_ib *ib,
  5467. unsigned vm_id, bool ctx_switch)
  5468. {
  5469. u32 header, control = 0;
  5470. if (ib->flags & AMDGPU_IB_FLAG_CE)
  5471. header = PACKET3(PACKET3_INDIRECT_BUFFER_CONST, 2);
  5472. else
  5473. header = PACKET3(PACKET3_INDIRECT_BUFFER, 2);
  5474. control |= ib->length_dw | (vm_id << 24);
  5475. if (amdgpu_sriov_vf(ring->adev) && (ib->flags & AMDGPU_IB_FLAG_PREEMPT)) {
  5476. control |= INDIRECT_BUFFER_PRE_ENB(1);
  5477. if (!(ib->flags & AMDGPU_IB_FLAG_CE))
  5478. gfx_v8_0_ring_emit_de_meta(ring);
  5479. }
  5480. amdgpu_ring_write(ring, header);
  5481. amdgpu_ring_write(ring,
  5482. #ifdef __BIG_ENDIAN
  5483. (2 << 0) |
  5484. #endif
  5485. (ib->gpu_addr & 0xFFFFFFFC));
  5486. amdgpu_ring_write(ring, upper_32_bits(ib->gpu_addr) & 0xFFFF);
  5487. amdgpu_ring_write(ring, control);
  5488. }
  5489. static void gfx_v8_0_ring_emit_ib_compute(struct amdgpu_ring *ring,
  5490. struct amdgpu_ib *ib,
  5491. unsigned vm_id, bool ctx_switch)
  5492. {
  5493. u32 control = INDIRECT_BUFFER_VALID | ib->length_dw | (vm_id << 24);
  5494. amdgpu_ring_write(ring, PACKET3(PACKET3_INDIRECT_BUFFER, 2));
  5495. amdgpu_ring_write(ring,
  5496. #ifdef __BIG_ENDIAN
  5497. (2 << 0) |
  5498. #endif
  5499. (ib->gpu_addr & 0xFFFFFFFC));
  5500. amdgpu_ring_write(ring, upper_32_bits(ib->gpu_addr) & 0xFFFF);
  5501. amdgpu_ring_write(ring, control);
  5502. }
  5503. static void gfx_v8_0_ring_emit_fence_gfx(struct amdgpu_ring *ring, u64 addr,
  5504. u64 seq, unsigned flags)
  5505. {
  5506. bool write64bit = flags & AMDGPU_FENCE_FLAG_64BIT;
  5507. bool int_sel = flags & AMDGPU_FENCE_FLAG_INT;
  5508. /* EVENT_WRITE_EOP - flush caches, send int */
  5509. amdgpu_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE_EOP, 4));
  5510. amdgpu_ring_write(ring, (EOP_TCL1_ACTION_EN |
  5511. EOP_TC_ACTION_EN |
  5512. EOP_TC_WB_ACTION_EN |
  5513. EVENT_TYPE(CACHE_FLUSH_AND_INV_TS_EVENT) |
  5514. EVENT_INDEX(5)));
  5515. amdgpu_ring_write(ring, addr & 0xfffffffc);
  5516. amdgpu_ring_write(ring, (upper_32_bits(addr) & 0xffff) |
  5517. DATA_SEL(write64bit ? 2 : 1) | INT_SEL(int_sel ? 2 : 0));
  5518. amdgpu_ring_write(ring, lower_32_bits(seq));
  5519. amdgpu_ring_write(ring, upper_32_bits(seq));
  5520. }
  5521. static void gfx_v8_0_ring_emit_pipeline_sync(struct amdgpu_ring *ring)
  5522. {
  5523. int usepfp = (ring->funcs->type == AMDGPU_RING_TYPE_GFX);
  5524. uint32_t seq = ring->fence_drv.sync_seq;
  5525. uint64_t addr = ring->fence_drv.gpu_addr;
  5526. amdgpu_ring_write(ring, PACKET3(PACKET3_WAIT_REG_MEM, 5));
  5527. amdgpu_ring_write(ring, (WAIT_REG_MEM_MEM_SPACE(1) | /* memory */
  5528. WAIT_REG_MEM_FUNCTION(3) | /* equal */
  5529. WAIT_REG_MEM_ENGINE(usepfp))); /* pfp or me */
  5530. amdgpu_ring_write(ring, addr & 0xfffffffc);
  5531. amdgpu_ring_write(ring, upper_32_bits(addr) & 0xffffffff);
  5532. amdgpu_ring_write(ring, seq);
  5533. amdgpu_ring_write(ring, 0xffffffff);
  5534. amdgpu_ring_write(ring, 4); /* poll interval */
  5535. }
  5536. static void gfx_v8_0_ring_emit_vm_flush(struct amdgpu_ring *ring,
  5537. unsigned vm_id, uint64_t pd_addr)
  5538. {
  5539. int usepfp = (ring->funcs->type == AMDGPU_RING_TYPE_GFX);
  5540. amdgpu_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  5541. amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(usepfp) |
  5542. WRITE_DATA_DST_SEL(0)) |
  5543. WR_CONFIRM);
  5544. if (vm_id < 8) {
  5545. amdgpu_ring_write(ring,
  5546. (mmVM_CONTEXT0_PAGE_TABLE_BASE_ADDR + vm_id));
  5547. } else {
  5548. amdgpu_ring_write(ring,
  5549. (mmVM_CONTEXT8_PAGE_TABLE_BASE_ADDR + vm_id - 8));
  5550. }
  5551. amdgpu_ring_write(ring, 0);
  5552. amdgpu_ring_write(ring, pd_addr >> 12);
  5553. /* bits 0-15 are the VM contexts0-15 */
  5554. /* invalidate the cache */
  5555. amdgpu_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  5556. amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
  5557. WRITE_DATA_DST_SEL(0)));
  5558. amdgpu_ring_write(ring, mmVM_INVALIDATE_REQUEST);
  5559. amdgpu_ring_write(ring, 0);
  5560. amdgpu_ring_write(ring, 1 << vm_id);
  5561. /* wait for the invalidate to complete */
  5562. amdgpu_ring_write(ring, PACKET3(PACKET3_WAIT_REG_MEM, 5));
  5563. amdgpu_ring_write(ring, (WAIT_REG_MEM_OPERATION(0) | /* wait */
  5564. WAIT_REG_MEM_FUNCTION(0) | /* always */
  5565. WAIT_REG_MEM_ENGINE(0))); /* me */
  5566. amdgpu_ring_write(ring, mmVM_INVALIDATE_REQUEST);
  5567. amdgpu_ring_write(ring, 0);
  5568. amdgpu_ring_write(ring, 0); /* ref */
  5569. amdgpu_ring_write(ring, 0); /* mask */
  5570. amdgpu_ring_write(ring, 0x20); /* poll interval */
  5571. /* compute doesn't have PFP */
  5572. if (usepfp) {
  5573. /* sync PFP to ME, otherwise we might get invalid PFP reads */
  5574. amdgpu_ring_write(ring, PACKET3(PACKET3_PFP_SYNC_ME, 0));
  5575. amdgpu_ring_write(ring, 0x0);
  5576. }
  5577. }
  5578. static u64 gfx_v8_0_ring_get_wptr_compute(struct amdgpu_ring *ring)
  5579. {
  5580. return ring->adev->wb.wb[ring->wptr_offs];
  5581. }
  5582. static void gfx_v8_0_ring_set_wptr_compute(struct amdgpu_ring *ring)
  5583. {
  5584. struct amdgpu_device *adev = ring->adev;
  5585. /* XXX check if swapping is necessary on BE */
  5586. adev->wb.wb[ring->wptr_offs] = lower_32_bits(ring->wptr);
  5587. WDOORBELL32(ring->doorbell_index, lower_32_bits(ring->wptr));
  5588. }
  5589. static void gfx_v8_0_ring_emit_fence_compute(struct amdgpu_ring *ring,
  5590. u64 addr, u64 seq,
  5591. unsigned flags)
  5592. {
  5593. bool write64bit = flags & AMDGPU_FENCE_FLAG_64BIT;
  5594. bool int_sel = flags & AMDGPU_FENCE_FLAG_INT;
  5595. /* RELEASE_MEM - flush caches, send int */
  5596. amdgpu_ring_write(ring, PACKET3(PACKET3_RELEASE_MEM, 5));
  5597. amdgpu_ring_write(ring, (EOP_TCL1_ACTION_EN |
  5598. EOP_TC_ACTION_EN |
  5599. EOP_TC_WB_ACTION_EN |
  5600. EVENT_TYPE(CACHE_FLUSH_AND_INV_TS_EVENT) |
  5601. EVENT_INDEX(5)));
  5602. amdgpu_ring_write(ring, DATA_SEL(write64bit ? 2 : 1) | INT_SEL(int_sel ? 2 : 0));
  5603. amdgpu_ring_write(ring, addr & 0xfffffffc);
  5604. amdgpu_ring_write(ring, upper_32_bits(addr));
  5605. amdgpu_ring_write(ring, lower_32_bits(seq));
  5606. amdgpu_ring_write(ring, upper_32_bits(seq));
  5607. }
  5608. static void gfx_v8_0_ring_emit_fence_kiq(struct amdgpu_ring *ring, u64 addr,
  5609. u64 seq, unsigned int flags)
  5610. {
  5611. /* we only allocate 32bit for each seq wb address */
  5612. BUG_ON(flags & AMDGPU_FENCE_FLAG_64BIT);
  5613. /* write fence seq to the "addr" */
  5614. amdgpu_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  5615. amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
  5616. WRITE_DATA_DST_SEL(5) | WR_CONFIRM));
  5617. amdgpu_ring_write(ring, lower_32_bits(addr));
  5618. amdgpu_ring_write(ring, upper_32_bits(addr));
  5619. amdgpu_ring_write(ring, lower_32_bits(seq));
  5620. if (flags & AMDGPU_FENCE_FLAG_INT) {
  5621. /* set register to trigger INT */
  5622. amdgpu_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  5623. amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
  5624. WRITE_DATA_DST_SEL(0) | WR_CONFIRM));
  5625. amdgpu_ring_write(ring, mmCPC_INT_STATUS);
  5626. amdgpu_ring_write(ring, 0);
  5627. amdgpu_ring_write(ring, 0x20000000); /* src_id is 178 */
  5628. }
  5629. }
  5630. static void gfx_v8_ring_emit_sb(struct amdgpu_ring *ring)
  5631. {
  5632. amdgpu_ring_write(ring, PACKET3(PACKET3_SWITCH_BUFFER, 0));
  5633. amdgpu_ring_write(ring, 0);
  5634. }
  5635. static void gfx_v8_ring_emit_cntxcntl(struct amdgpu_ring *ring, uint32_t flags)
  5636. {
  5637. uint32_t dw2 = 0;
  5638. if (amdgpu_sriov_vf(ring->adev))
  5639. gfx_v8_0_ring_emit_ce_meta(ring);
  5640. dw2 |= 0x80000000; /* set load_enable otherwise this package is just NOPs */
  5641. if (flags & AMDGPU_HAVE_CTX_SWITCH) {
  5642. gfx_v8_0_ring_emit_vgt_flush(ring);
  5643. /* set load_global_config & load_global_uconfig */
  5644. dw2 |= 0x8001;
  5645. /* set load_cs_sh_regs */
  5646. dw2 |= 0x01000000;
  5647. /* set load_per_context_state & load_gfx_sh_regs for GFX */
  5648. dw2 |= 0x10002;
  5649. /* set load_ce_ram if preamble presented */
  5650. if (AMDGPU_PREAMBLE_IB_PRESENT & flags)
  5651. dw2 |= 0x10000000;
  5652. } else {
  5653. /* still load_ce_ram if this is the first time preamble presented
  5654. * although there is no context switch happens.
  5655. */
  5656. if (AMDGPU_PREAMBLE_IB_PRESENT_FIRST & flags)
  5657. dw2 |= 0x10000000;
  5658. }
  5659. amdgpu_ring_write(ring, PACKET3(PACKET3_CONTEXT_CONTROL, 1));
  5660. amdgpu_ring_write(ring, dw2);
  5661. amdgpu_ring_write(ring, 0);
  5662. }
  5663. static unsigned gfx_v8_0_ring_emit_init_cond_exec(struct amdgpu_ring *ring)
  5664. {
  5665. unsigned ret;
  5666. amdgpu_ring_write(ring, PACKET3(PACKET3_COND_EXEC, 3));
  5667. amdgpu_ring_write(ring, lower_32_bits(ring->cond_exe_gpu_addr));
  5668. amdgpu_ring_write(ring, upper_32_bits(ring->cond_exe_gpu_addr));
  5669. amdgpu_ring_write(ring, 0); /* discard following DWs if *cond_exec_gpu_addr==0 */
  5670. ret = ring->wptr & ring->buf_mask;
  5671. amdgpu_ring_write(ring, 0x55aa55aa); /* patch dummy value later */
  5672. return ret;
  5673. }
  5674. static void gfx_v8_0_ring_emit_patch_cond_exec(struct amdgpu_ring *ring, unsigned offset)
  5675. {
  5676. unsigned cur;
  5677. BUG_ON(offset > ring->buf_mask);
  5678. BUG_ON(ring->ring[offset] != 0x55aa55aa);
  5679. cur = (ring->wptr & ring->buf_mask) - 1;
  5680. if (likely(cur > offset))
  5681. ring->ring[offset] = cur - offset;
  5682. else
  5683. ring->ring[offset] = (ring->ring_size >> 2) - offset + cur;
  5684. }
  5685. static void gfx_v8_0_ring_emit_rreg(struct amdgpu_ring *ring, uint32_t reg)
  5686. {
  5687. struct amdgpu_device *adev = ring->adev;
  5688. amdgpu_ring_write(ring, PACKET3(PACKET3_COPY_DATA, 4));
  5689. amdgpu_ring_write(ring, 0 | /* src: register*/
  5690. (5 << 8) | /* dst: memory */
  5691. (1 << 20)); /* write confirm */
  5692. amdgpu_ring_write(ring, reg);
  5693. amdgpu_ring_write(ring, 0);
  5694. amdgpu_ring_write(ring, lower_32_bits(adev->wb.gpu_addr +
  5695. adev->virt.reg_val_offs * 4));
  5696. amdgpu_ring_write(ring, upper_32_bits(adev->wb.gpu_addr +
  5697. adev->virt.reg_val_offs * 4));
  5698. }
  5699. static void gfx_v8_0_ring_emit_wreg(struct amdgpu_ring *ring, uint32_t reg,
  5700. uint32_t val)
  5701. {
  5702. amdgpu_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  5703. amdgpu_ring_write(ring, (1 << 16)); /* no inc addr */
  5704. amdgpu_ring_write(ring, reg);
  5705. amdgpu_ring_write(ring, 0);
  5706. amdgpu_ring_write(ring, val);
  5707. }
  5708. static void gfx_v8_0_set_gfx_eop_interrupt_state(struct amdgpu_device *adev,
  5709. enum amdgpu_interrupt_state state)
  5710. {
  5711. WREG32_FIELD(CP_INT_CNTL_RING0, TIME_STAMP_INT_ENABLE,
  5712. state == AMDGPU_IRQ_STATE_DISABLE ? 0 : 1);
  5713. }
  5714. static void gfx_v8_0_set_compute_eop_interrupt_state(struct amdgpu_device *adev,
  5715. int me, int pipe,
  5716. enum amdgpu_interrupt_state state)
  5717. {
  5718. u32 mec_int_cntl, mec_int_cntl_reg;
  5719. /*
  5720. * amdgpu controls only the first MEC. That's why this function only
  5721. * handles the setting of interrupts for this specific MEC. All other
  5722. * pipes' interrupts are set by amdkfd.
  5723. */
  5724. if (me == 1) {
  5725. switch (pipe) {
  5726. case 0:
  5727. mec_int_cntl_reg = mmCP_ME1_PIPE0_INT_CNTL;
  5728. break;
  5729. case 1:
  5730. mec_int_cntl_reg = mmCP_ME1_PIPE1_INT_CNTL;
  5731. break;
  5732. case 2:
  5733. mec_int_cntl_reg = mmCP_ME1_PIPE2_INT_CNTL;
  5734. break;
  5735. case 3:
  5736. mec_int_cntl_reg = mmCP_ME1_PIPE3_INT_CNTL;
  5737. break;
  5738. default:
  5739. DRM_DEBUG("invalid pipe %d\n", pipe);
  5740. return;
  5741. }
  5742. } else {
  5743. DRM_DEBUG("invalid me %d\n", me);
  5744. return;
  5745. }
  5746. switch (state) {
  5747. case AMDGPU_IRQ_STATE_DISABLE:
  5748. mec_int_cntl = RREG32(mec_int_cntl_reg);
  5749. mec_int_cntl &= ~CP_INT_CNTL_RING0__TIME_STAMP_INT_ENABLE_MASK;
  5750. WREG32(mec_int_cntl_reg, mec_int_cntl);
  5751. break;
  5752. case AMDGPU_IRQ_STATE_ENABLE:
  5753. mec_int_cntl = RREG32(mec_int_cntl_reg);
  5754. mec_int_cntl |= CP_INT_CNTL_RING0__TIME_STAMP_INT_ENABLE_MASK;
  5755. WREG32(mec_int_cntl_reg, mec_int_cntl);
  5756. break;
  5757. default:
  5758. break;
  5759. }
  5760. }
  5761. static int gfx_v8_0_set_priv_reg_fault_state(struct amdgpu_device *adev,
  5762. struct amdgpu_irq_src *source,
  5763. unsigned type,
  5764. enum amdgpu_interrupt_state state)
  5765. {
  5766. WREG32_FIELD(CP_INT_CNTL_RING0, PRIV_REG_INT_ENABLE,
  5767. state == AMDGPU_IRQ_STATE_DISABLE ? 0 : 1);
  5768. return 0;
  5769. }
  5770. static int gfx_v8_0_set_priv_inst_fault_state(struct amdgpu_device *adev,
  5771. struct amdgpu_irq_src *source,
  5772. unsigned type,
  5773. enum amdgpu_interrupt_state state)
  5774. {
  5775. WREG32_FIELD(CP_INT_CNTL_RING0, PRIV_INSTR_INT_ENABLE,
  5776. state == AMDGPU_IRQ_STATE_DISABLE ? 0 : 1);
  5777. return 0;
  5778. }
  5779. static int gfx_v8_0_set_eop_interrupt_state(struct amdgpu_device *adev,
  5780. struct amdgpu_irq_src *src,
  5781. unsigned type,
  5782. enum amdgpu_interrupt_state state)
  5783. {
  5784. switch (type) {
  5785. case AMDGPU_CP_IRQ_GFX_EOP:
  5786. gfx_v8_0_set_gfx_eop_interrupt_state(adev, state);
  5787. break;
  5788. case AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP:
  5789. gfx_v8_0_set_compute_eop_interrupt_state(adev, 1, 0, state);
  5790. break;
  5791. case AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE1_EOP:
  5792. gfx_v8_0_set_compute_eop_interrupt_state(adev, 1, 1, state);
  5793. break;
  5794. case AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE2_EOP:
  5795. gfx_v8_0_set_compute_eop_interrupt_state(adev, 1, 2, state);
  5796. break;
  5797. case AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE3_EOP:
  5798. gfx_v8_0_set_compute_eop_interrupt_state(adev, 1, 3, state);
  5799. break;
  5800. case AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE0_EOP:
  5801. gfx_v8_0_set_compute_eop_interrupt_state(adev, 2, 0, state);
  5802. break;
  5803. case AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE1_EOP:
  5804. gfx_v8_0_set_compute_eop_interrupt_state(adev, 2, 1, state);
  5805. break;
  5806. case AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE2_EOP:
  5807. gfx_v8_0_set_compute_eop_interrupt_state(adev, 2, 2, state);
  5808. break;
  5809. case AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE3_EOP:
  5810. gfx_v8_0_set_compute_eop_interrupt_state(adev, 2, 3, state);
  5811. break;
  5812. default:
  5813. break;
  5814. }
  5815. return 0;
  5816. }
  5817. static int gfx_v8_0_eop_irq(struct amdgpu_device *adev,
  5818. struct amdgpu_irq_src *source,
  5819. struct amdgpu_iv_entry *entry)
  5820. {
  5821. int i;
  5822. u8 me_id, pipe_id, queue_id;
  5823. struct amdgpu_ring *ring;
  5824. DRM_DEBUG("IH: CP EOP\n");
  5825. me_id = (entry->ring_id & 0x0c) >> 2;
  5826. pipe_id = (entry->ring_id & 0x03) >> 0;
  5827. queue_id = (entry->ring_id & 0x70) >> 4;
  5828. switch (me_id) {
  5829. case 0:
  5830. amdgpu_fence_process(&adev->gfx.gfx_ring[0]);
  5831. break;
  5832. case 1:
  5833. case 2:
  5834. for (i = 0; i < adev->gfx.num_compute_rings; i++) {
  5835. ring = &adev->gfx.compute_ring[i];
  5836. /* Per-queue interrupt is supported for MEC starting from VI.
  5837. * The interrupt can only be enabled/disabled per pipe instead of per queue.
  5838. */
  5839. if ((ring->me == me_id) && (ring->pipe == pipe_id) && (ring->queue == queue_id))
  5840. amdgpu_fence_process(ring);
  5841. }
  5842. break;
  5843. }
  5844. return 0;
  5845. }
  5846. static int gfx_v8_0_priv_reg_irq(struct amdgpu_device *adev,
  5847. struct amdgpu_irq_src *source,
  5848. struct amdgpu_iv_entry *entry)
  5849. {
  5850. DRM_ERROR("Illegal register access in command stream\n");
  5851. schedule_work(&adev->reset_work);
  5852. return 0;
  5853. }
  5854. static int gfx_v8_0_priv_inst_irq(struct amdgpu_device *adev,
  5855. struct amdgpu_irq_src *source,
  5856. struct amdgpu_iv_entry *entry)
  5857. {
  5858. DRM_ERROR("Illegal instruction in command stream\n");
  5859. schedule_work(&adev->reset_work);
  5860. return 0;
  5861. }
  5862. static int gfx_v8_0_kiq_set_interrupt_state(struct amdgpu_device *adev,
  5863. struct amdgpu_irq_src *src,
  5864. unsigned int type,
  5865. enum amdgpu_interrupt_state state)
  5866. {
  5867. struct amdgpu_ring *ring = &(adev->gfx.kiq.ring);
  5868. switch (type) {
  5869. case AMDGPU_CP_KIQ_IRQ_DRIVER0:
  5870. WREG32_FIELD(CPC_INT_CNTL, GENERIC2_INT_ENABLE,
  5871. state == AMDGPU_IRQ_STATE_DISABLE ? 0 : 1);
  5872. if (ring->me == 1)
  5873. WREG32_FIELD_OFFSET(CP_ME1_PIPE0_INT_CNTL,
  5874. ring->pipe,
  5875. GENERIC2_INT_ENABLE,
  5876. state == AMDGPU_IRQ_STATE_DISABLE ? 0 : 1);
  5877. else
  5878. WREG32_FIELD_OFFSET(CP_ME2_PIPE0_INT_CNTL,
  5879. ring->pipe,
  5880. GENERIC2_INT_ENABLE,
  5881. state == AMDGPU_IRQ_STATE_DISABLE ? 0 : 1);
  5882. break;
  5883. default:
  5884. BUG(); /* kiq only support GENERIC2_INT now */
  5885. break;
  5886. }
  5887. return 0;
  5888. }
  5889. static int gfx_v8_0_kiq_irq(struct amdgpu_device *adev,
  5890. struct amdgpu_irq_src *source,
  5891. struct amdgpu_iv_entry *entry)
  5892. {
  5893. u8 me_id, pipe_id, queue_id;
  5894. struct amdgpu_ring *ring = &(adev->gfx.kiq.ring);
  5895. me_id = (entry->ring_id & 0x0c) >> 2;
  5896. pipe_id = (entry->ring_id & 0x03) >> 0;
  5897. queue_id = (entry->ring_id & 0x70) >> 4;
  5898. DRM_DEBUG("IH: CPC GENERIC2_INT, me:%d, pipe:%d, queue:%d\n",
  5899. me_id, pipe_id, queue_id);
  5900. amdgpu_fence_process(ring);
  5901. return 0;
  5902. }
  5903. static const struct amd_ip_funcs gfx_v8_0_ip_funcs = {
  5904. .name = "gfx_v8_0",
  5905. .early_init = gfx_v8_0_early_init,
  5906. .late_init = gfx_v8_0_late_init,
  5907. .sw_init = gfx_v8_0_sw_init,
  5908. .sw_fini = gfx_v8_0_sw_fini,
  5909. .hw_init = gfx_v8_0_hw_init,
  5910. .hw_fini = gfx_v8_0_hw_fini,
  5911. .suspend = gfx_v8_0_suspend,
  5912. .resume = gfx_v8_0_resume,
  5913. .is_idle = gfx_v8_0_is_idle,
  5914. .wait_for_idle = gfx_v8_0_wait_for_idle,
  5915. .check_soft_reset = gfx_v8_0_check_soft_reset,
  5916. .pre_soft_reset = gfx_v8_0_pre_soft_reset,
  5917. .soft_reset = gfx_v8_0_soft_reset,
  5918. .post_soft_reset = gfx_v8_0_post_soft_reset,
  5919. .set_clockgating_state = gfx_v8_0_set_clockgating_state,
  5920. .set_powergating_state = gfx_v8_0_set_powergating_state,
  5921. .get_clockgating_state = gfx_v8_0_get_clockgating_state,
  5922. };
  5923. static const struct amdgpu_ring_funcs gfx_v8_0_ring_funcs_gfx = {
  5924. .type = AMDGPU_RING_TYPE_GFX,
  5925. .align_mask = 0xff,
  5926. .nop = PACKET3(PACKET3_NOP, 0x3FFF),
  5927. .support_64bit_ptrs = false,
  5928. .get_rptr = gfx_v8_0_ring_get_rptr,
  5929. .get_wptr = gfx_v8_0_ring_get_wptr_gfx,
  5930. .set_wptr = gfx_v8_0_ring_set_wptr_gfx,
  5931. .emit_frame_size = /* maximum 215dw if count 16 IBs in */
  5932. 5 + /* COND_EXEC */
  5933. 7 + /* PIPELINE_SYNC */
  5934. 19 + /* VM_FLUSH */
  5935. 8 + /* FENCE for VM_FLUSH */
  5936. 20 + /* GDS switch */
  5937. 4 + /* double SWITCH_BUFFER,
  5938. the first COND_EXEC jump to the place just
  5939. prior to this double SWITCH_BUFFER */
  5940. 5 + /* COND_EXEC */
  5941. 7 + /* HDP_flush */
  5942. 4 + /* VGT_flush */
  5943. 14 + /* CE_META */
  5944. 31 + /* DE_META */
  5945. 3 + /* CNTX_CTRL */
  5946. 5 + /* HDP_INVL */
  5947. 8 + 8 + /* FENCE x2 */
  5948. 2, /* SWITCH_BUFFER */
  5949. .emit_ib_size = 4, /* gfx_v8_0_ring_emit_ib_gfx */
  5950. .emit_ib = gfx_v8_0_ring_emit_ib_gfx,
  5951. .emit_fence = gfx_v8_0_ring_emit_fence_gfx,
  5952. .emit_pipeline_sync = gfx_v8_0_ring_emit_pipeline_sync,
  5953. .emit_vm_flush = gfx_v8_0_ring_emit_vm_flush,
  5954. .emit_gds_switch = gfx_v8_0_ring_emit_gds_switch,
  5955. .emit_hdp_flush = gfx_v8_0_ring_emit_hdp_flush,
  5956. .emit_hdp_invalidate = gfx_v8_0_ring_emit_hdp_invalidate,
  5957. .test_ring = gfx_v8_0_ring_test_ring,
  5958. .test_ib = gfx_v8_0_ring_test_ib,
  5959. .insert_nop = amdgpu_ring_insert_nop,
  5960. .pad_ib = amdgpu_ring_generic_pad_ib,
  5961. .emit_switch_buffer = gfx_v8_ring_emit_sb,
  5962. .emit_cntxcntl = gfx_v8_ring_emit_cntxcntl,
  5963. .init_cond_exec = gfx_v8_0_ring_emit_init_cond_exec,
  5964. .patch_cond_exec = gfx_v8_0_ring_emit_patch_cond_exec,
  5965. };
  5966. static const struct amdgpu_ring_funcs gfx_v8_0_ring_funcs_compute = {
  5967. .type = AMDGPU_RING_TYPE_COMPUTE,
  5968. .align_mask = 0xff,
  5969. .nop = PACKET3(PACKET3_NOP, 0x3FFF),
  5970. .support_64bit_ptrs = false,
  5971. .get_rptr = gfx_v8_0_ring_get_rptr,
  5972. .get_wptr = gfx_v8_0_ring_get_wptr_compute,
  5973. .set_wptr = gfx_v8_0_ring_set_wptr_compute,
  5974. .emit_frame_size =
  5975. 20 + /* gfx_v8_0_ring_emit_gds_switch */
  5976. 7 + /* gfx_v8_0_ring_emit_hdp_flush */
  5977. 5 + /* gfx_v8_0_ring_emit_hdp_invalidate */
  5978. 7 + /* gfx_v8_0_ring_emit_pipeline_sync */
  5979. 17 + /* gfx_v8_0_ring_emit_vm_flush */
  5980. 7 + 7 + 7, /* gfx_v8_0_ring_emit_fence_compute x3 for user fence, vm fence */
  5981. .emit_ib_size = 4, /* gfx_v8_0_ring_emit_ib_compute */
  5982. .emit_ib = gfx_v8_0_ring_emit_ib_compute,
  5983. .emit_fence = gfx_v8_0_ring_emit_fence_compute,
  5984. .emit_pipeline_sync = gfx_v8_0_ring_emit_pipeline_sync,
  5985. .emit_vm_flush = gfx_v8_0_ring_emit_vm_flush,
  5986. .emit_gds_switch = gfx_v8_0_ring_emit_gds_switch,
  5987. .emit_hdp_flush = gfx_v8_0_ring_emit_hdp_flush,
  5988. .emit_hdp_invalidate = gfx_v8_0_ring_emit_hdp_invalidate,
  5989. .test_ring = gfx_v8_0_ring_test_ring,
  5990. .test_ib = gfx_v8_0_ring_test_ib,
  5991. .insert_nop = amdgpu_ring_insert_nop,
  5992. .pad_ib = amdgpu_ring_generic_pad_ib,
  5993. };
  5994. static const struct amdgpu_ring_funcs gfx_v8_0_ring_funcs_kiq = {
  5995. .type = AMDGPU_RING_TYPE_KIQ,
  5996. .align_mask = 0xff,
  5997. .nop = PACKET3(PACKET3_NOP, 0x3FFF),
  5998. .support_64bit_ptrs = false,
  5999. .get_rptr = gfx_v8_0_ring_get_rptr,
  6000. .get_wptr = gfx_v8_0_ring_get_wptr_compute,
  6001. .set_wptr = gfx_v8_0_ring_set_wptr_compute,
  6002. .emit_frame_size =
  6003. 20 + /* gfx_v8_0_ring_emit_gds_switch */
  6004. 7 + /* gfx_v8_0_ring_emit_hdp_flush */
  6005. 5 + /* gfx_v8_0_ring_emit_hdp_invalidate */
  6006. 7 + /* gfx_v8_0_ring_emit_pipeline_sync */
  6007. 17 + /* gfx_v8_0_ring_emit_vm_flush */
  6008. 7 + 7 + 7, /* gfx_v8_0_ring_emit_fence_kiq x3 for user fence, vm fence */
  6009. .emit_ib_size = 4, /* gfx_v8_0_ring_emit_ib_compute */
  6010. .emit_ib = gfx_v8_0_ring_emit_ib_compute,
  6011. .emit_fence = gfx_v8_0_ring_emit_fence_kiq,
  6012. .test_ring = gfx_v8_0_ring_test_ring,
  6013. .test_ib = gfx_v8_0_ring_test_ib,
  6014. .insert_nop = amdgpu_ring_insert_nop,
  6015. .pad_ib = amdgpu_ring_generic_pad_ib,
  6016. .emit_rreg = gfx_v8_0_ring_emit_rreg,
  6017. .emit_wreg = gfx_v8_0_ring_emit_wreg,
  6018. };
  6019. static void gfx_v8_0_set_ring_funcs(struct amdgpu_device *adev)
  6020. {
  6021. int i;
  6022. adev->gfx.kiq.ring.funcs = &gfx_v8_0_ring_funcs_kiq;
  6023. for (i = 0; i < adev->gfx.num_gfx_rings; i++)
  6024. adev->gfx.gfx_ring[i].funcs = &gfx_v8_0_ring_funcs_gfx;
  6025. for (i = 0; i < adev->gfx.num_compute_rings; i++)
  6026. adev->gfx.compute_ring[i].funcs = &gfx_v8_0_ring_funcs_compute;
  6027. }
  6028. static const struct amdgpu_irq_src_funcs gfx_v8_0_eop_irq_funcs = {
  6029. .set = gfx_v8_0_set_eop_interrupt_state,
  6030. .process = gfx_v8_0_eop_irq,
  6031. };
  6032. static const struct amdgpu_irq_src_funcs gfx_v8_0_priv_reg_irq_funcs = {
  6033. .set = gfx_v8_0_set_priv_reg_fault_state,
  6034. .process = gfx_v8_0_priv_reg_irq,
  6035. };
  6036. static const struct amdgpu_irq_src_funcs gfx_v8_0_priv_inst_irq_funcs = {
  6037. .set = gfx_v8_0_set_priv_inst_fault_state,
  6038. .process = gfx_v8_0_priv_inst_irq,
  6039. };
  6040. static const struct amdgpu_irq_src_funcs gfx_v8_0_kiq_irq_funcs = {
  6041. .set = gfx_v8_0_kiq_set_interrupt_state,
  6042. .process = gfx_v8_0_kiq_irq,
  6043. };
  6044. static void gfx_v8_0_set_irq_funcs(struct amdgpu_device *adev)
  6045. {
  6046. adev->gfx.eop_irq.num_types = AMDGPU_CP_IRQ_LAST;
  6047. adev->gfx.eop_irq.funcs = &gfx_v8_0_eop_irq_funcs;
  6048. adev->gfx.priv_reg_irq.num_types = 1;
  6049. adev->gfx.priv_reg_irq.funcs = &gfx_v8_0_priv_reg_irq_funcs;
  6050. adev->gfx.priv_inst_irq.num_types = 1;
  6051. adev->gfx.priv_inst_irq.funcs = &gfx_v8_0_priv_inst_irq_funcs;
  6052. adev->gfx.kiq.irq.num_types = AMDGPU_CP_KIQ_IRQ_LAST;
  6053. adev->gfx.kiq.irq.funcs = &gfx_v8_0_kiq_irq_funcs;
  6054. }
  6055. static void gfx_v8_0_set_rlc_funcs(struct amdgpu_device *adev)
  6056. {
  6057. adev->gfx.rlc.funcs = &iceland_rlc_funcs;
  6058. }
  6059. static void gfx_v8_0_set_gds_init(struct amdgpu_device *adev)
  6060. {
  6061. /* init asci gds info */
  6062. adev->gds.mem.total_size = RREG32(mmGDS_VMID0_SIZE);
  6063. adev->gds.gws.total_size = 64;
  6064. adev->gds.oa.total_size = 16;
  6065. if (adev->gds.mem.total_size == 64 * 1024) {
  6066. adev->gds.mem.gfx_partition_size = 4096;
  6067. adev->gds.mem.cs_partition_size = 4096;
  6068. adev->gds.gws.gfx_partition_size = 4;
  6069. adev->gds.gws.cs_partition_size = 4;
  6070. adev->gds.oa.gfx_partition_size = 4;
  6071. adev->gds.oa.cs_partition_size = 1;
  6072. } else {
  6073. adev->gds.mem.gfx_partition_size = 1024;
  6074. adev->gds.mem.cs_partition_size = 1024;
  6075. adev->gds.gws.gfx_partition_size = 16;
  6076. adev->gds.gws.cs_partition_size = 16;
  6077. adev->gds.oa.gfx_partition_size = 4;
  6078. adev->gds.oa.cs_partition_size = 4;
  6079. }
  6080. }
  6081. static void gfx_v8_0_set_user_cu_inactive_bitmap(struct amdgpu_device *adev,
  6082. u32 bitmap)
  6083. {
  6084. u32 data;
  6085. if (!bitmap)
  6086. return;
  6087. data = bitmap << GC_USER_SHADER_ARRAY_CONFIG__INACTIVE_CUS__SHIFT;
  6088. data &= GC_USER_SHADER_ARRAY_CONFIG__INACTIVE_CUS_MASK;
  6089. WREG32(mmGC_USER_SHADER_ARRAY_CONFIG, data);
  6090. }
  6091. static u32 gfx_v8_0_get_cu_active_bitmap(struct amdgpu_device *adev)
  6092. {
  6093. u32 data, mask;
  6094. data = RREG32(mmCC_GC_SHADER_ARRAY_CONFIG) |
  6095. RREG32(mmGC_USER_SHADER_ARRAY_CONFIG);
  6096. mask = amdgpu_gfx_create_bitmask(adev->gfx.config.max_cu_per_sh);
  6097. return ~REG_GET_FIELD(data, CC_GC_SHADER_ARRAY_CONFIG, INACTIVE_CUS) & mask;
  6098. }
  6099. static void gfx_v8_0_get_cu_info(struct amdgpu_device *adev)
  6100. {
  6101. int i, j, k, counter, active_cu_number = 0;
  6102. u32 mask, bitmap, ao_bitmap, ao_cu_mask = 0;
  6103. struct amdgpu_cu_info *cu_info = &adev->gfx.cu_info;
  6104. unsigned disable_masks[4 * 2];
  6105. u32 ao_cu_num;
  6106. memset(cu_info, 0, sizeof(*cu_info));
  6107. if (adev->flags & AMD_IS_APU)
  6108. ao_cu_num = 2;
  6109. else
  6110. ao_cu_num = adev->gfx.config.max_cu_per_sh;
  6111. amdgpu_gfx_parse_disable_cu(disable_masks, 4, 2);
  6112. mutex_lock(&adev->grbm_idx_mutex);
  6113. for (i = 0; i < adev->gfx.config.max_shader_engines; i++) {
  6114. for (j = 0; j < adev->gfx.config.max_sh_per_se; j++) {
  6115. mask = 1;
  6116. ao_bitmap = 0;
  6117. counter = 0;
  6118. gfx_v8_0_select_se_sh(adev, i, j, 0xffffffff);
  6119. if (i < 4 && j < 2)
  6120. gfx_v8_0_set_user_cu_inactive_bitmap(
  6121. adev, disable_masks[i * 2 + j]);
  6122. bitmap = gfx_v8_0_get_cu_active_bitmap(adev);
  6123. cu_info->bitmap[i][j] = bitmap;
  6124. for (k = 0; k < adev->gfx.config.max_cu_per_sh; k ++) {
  6125. if (bitmap & mask) {
  6126. if (counter < ao_cu_num)
  6127. ao_bitmap |= mask;
  6128. counter ++;
  6129. }
  6130. mask <<= 1;
  6131. }
  6132. active_cu_number += counter;
  6133. if (i < 2 && j < 2)
  6134. ao_cu_mask |= (ao_bitmap << (i * 16 + j * 8));
  6135. cu_info->ao_cu_bitmap[i][j] = ao_bitmap;
  6136. }
  6137. }
  6138. gfx_v8_0_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
  6139. mutex_unlock(&adev->grbm_idx_mutex);
  6140. cu_info->number = active_cu_number;
  6141. cu_info->ao_cu_mask = ao_cu_mask;
  6142. }
  6143. const struct amdgpu_ip_block_version gfx_v8_0_ip_block =
  6144. {
  6145. .type = AMD_IP_BLOCK_TYPE_GFX,
  6146. .major = 8,
  6147. .minor = 0,
  6148. .rev = 0,
  6149. .funcs = &gfx_v8_0_ip_funcs,
  6150. };
  6151. const struct amdgpu_ip_block_version gfx_v8_1_ip_block =
  6152. {
  6153. .type = AMD_IP_BLOCK_TYPE_GFX,
  6154. .major = 8,
  6155. .minor = 1,
  6156. .rev = 0,
  6157. .funcs = &gfx_v8_0_ip_funcs,
  6158. };
  6159. static void gfx_v8_0_ring_emit_ce_meta(struct amdgpu_ring *ring)
  6160. {
  6161. uint64_t ce_payload_addr;
  6162. int cnt_ce;
  6163. static union {
  6164. struct vi_ce_ib_state regular;
  6165. struct vi_ce_ib_state_chained_ib chained;
  6166. } ce_payload = {};
  6167. if (ring->adev->virt.chained_ib_support) {
  6168. ce_payload_addr = AMDGPU_VA_RESERVED_SIZE - 2 * 4096 +
  6169. offsetof(struct vi_gfx_meta_data_chained_ib, ce_payload);
  6170. cnt_ce = (sizeof(ce_payload.chained) >> 2) + 4 - 2;
  6171. } else {
  6172. ce_payload_addr = AMDGPU_VA_RESERVED_SIZE - 2 * 4096 +
  6173. offsetof(struct vi_gfx_meta_data, ce_payload);
  6174. cnt_ce = (sizeof(ce_payload.regular) >> 2) + 4 - 2;
  6175. }
  6176. amdgpu_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, cnt_ce));
  6177. amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(2) |
  6178. WRITE_DATA_DST_SEL(8) |
  6179. WR_CONFIRM) |
  6180. WRITE_DATA_CACHE_POLICY(0));
  6181. amdgpu_ring_write(ring, lower_32_bits(ce_payload_addr));
  6182. amdgpu_ring_write(ring, upper_32_bits(ce_payload_addr));
  6183. amdgpu_ring_write_multiple(ring, (void *)&ce_payload, cnt_ce - 2);
  6184. }
  6185. static void gfx_v8_0_ring_emit_de_meta(struct amdgpu_ring *ring)
  6186. {
  6187. uint64_t de_payload_addr, gds_addr, csa_addr;
  6188. int cnt_de;
  6189. static union {
  6190. struct vi_de_ib_state regular;
  6191. struct vi_de_ib_state_chained_ib chained;
  6192. } de_payload = {};
  6193. csa_addr = AMDGPU_VA_RESERVED_SIZE - 2 * 4096;
  6194. gds_addr = csa_addr + 4096;
  6195. if (ring->adev->virt.chained_ib_support) {
  6196. de_payload.chained.gds_backup_addrlo = lower_32_bits(gds_addr);
  6197. de_payload.chained.gds_backup_addrhi = upper_32_bits(gds_addr);
  6198. de_payload_addr = csa_addr + offsetof(struct vi_gfx_meta_data_chained_ib, de_payload);
  6199. cnt_de = (sizeof(de_payload.chained) >> 2) + 4 - 2;
  6200. } else {
  6201. de_payload.regular.gds_backup_addrlo = lower_32_bits(gds_addr);
  6202. de_payload.regular.gds_backup_addrhi = upper_32_bits(gds_addr);
  6203. de_payload_addr = csa_addr + offsetof(struct vi_gfx_meta_data, de_payload);
  6204. cnt_de = (sizeof(de_payload.regular) >> 2) + 4 - 2;
  6205. }
  6206. amdgpu_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, cnt_de));
  6207. amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(1) |
  6208. WRITE_DATA_DST_SEL(8) |
  6209. WR_CONFIRM) |
  6210. WRITE_DATA_CACHE_POLICY(0));
  6211. amdgpu_ring_write(ring, lower_32_bits(de_payload_addr));
  6212. amdgpu_ring_write(ring, upper_32_bits(de_payload_addr));
  6213. amdgpu_ring_write_multiple(ring, (void *)&de_payload, cnt_de - 2);
  6214. }