cik.c 283 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065
  1. /*
  2. * Copyright 2012 Advanced Micro Devices, Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * Authors: Alex Deucher
  23. */
  24. #include <linux/firmware.h>
  25. #include <linux/slab.h>
  26. #include <linux/module.h>
  27. #include "drmP.h"
  28. #include "radeon.h"
  29. #include "radeon_asic.h"
  30. #include "radeon_audio.h"
  31. #include "cikd.h"
  32. #include "atom.h"
  33. #include "cik_blit_shaders.h"
  34. #include "radeon_ucode.h"
  35. #include "clearstate_ci.h"
  36. #include "radeon_kfd.h"
  37. MODULE_FIRMWARE("radeon/BONAIRE_pfp.bin");
  38. MODULE_FIRMWARE("radeon/BONAIRE_me.bin");
  39. MODULE_FIRMWARE("radeon/BONAIRE_ce.bin");
  40. MODULE_FIRMWARE("radeon/BONAIRE_mec.bin");
  41. MODULE_FIRMWARE("radeon/BONAIRE_mc.bin");
  42. MODULE_FIRMWARE("radeon/BONAIRE_mc2.bin");
  43. MODULE_FIRMWARE("radeon/BONAIRE_rlc.bin");
  44. MODULE_FIRMWARE("radeon/BONAIRE_sdma.bin");
  45. MODULE_FIRMWARE("radeon/BONAIRE_smc.bin");
  46. MODULE_FIRMWARE("radeon/bonaire_pfp.bin");
  47. MODULE_FIRMWARE("radeon/bonaire_me.bin");
  48. MODULE_FIRMWARE("radeon/bonaire_ce.bin");
  49. MODULE_FIRMWARE("radeon/bonaire_mec.bin");
  50. MODULE_FIRMWARE("radeon/bonaire_mc.bin");
  51. MODULE_FIRMWARE("radeon/bonaire_rlc.bin");
  52. MODULE_FIRMWARE("radeon/bonaire_sdma.bin");
  53. MODULE_FIRMWARE("radeon/bonaire_smc.bin");
  54. MODULE_FIRMWARE("radeon/HAWAII_pfp.bin");
  55. MODULE_FIRMWARE("radeon/HAWAII_me.bin");
  56. MODULE_FIRMWARE("radeon/HAWAII_ce.bin");
  57. MODULE_FIRMWARE("radeon/HAWAII_mec.bin");
  58. MODULE_FIRMWARE("radeon/HAWAII_mc.bin");
  59. MODULE_FIRMWARE("radeon/HAWAII_mc2.bin");
  60. MODULE_FIRMWARE("radeon/HAWAII_rlc.bin");
  61. MODULE_FIRMWARE("radeon/HAWAII_sdma.bin");
  62. MODULE_FIRMWARE("radeon/HAWAII_smc.bin");
  63. MODULE_FIRMWARE("radeon/hawaii_pfp.bin");
  64. MODULE_FIRMWARE("radeon/hawaii_me.bin");
  65. MODULE_FIRMWARE("radeon/hawaii_ce.bin");
  66. MODULE_FIRMWARE("radeon/hawaii_mec.bin");
  67. MODULE_FIRMWARE("radeon/hawaii_mc.bin");
  68. MODULE_FIRMWARE("radeon/hawaii_rlc.bin");
  69. MODULE_FIRMWARE("radeon/hawaii_sdma.bin");
  70. MODULE_FIRMWARE("radeon/hawaii_smc.bin");
  71. MODULE_FIRMWARE("radeon/KAVERI_pfp.bin");
  72. MODULE_FIRMWARE("radeon/KAVERI_me.bin");
  73. MODULE_FIRMWARE("radeon/KAVERI_ce.bin");
  74. MODULE_FIRMWARE("radeon/KAVERI_mec.bin");
  75. MODULE_FIRMWARE("radeon/KAVERI_rlc.bin");
  76. MODULE_FIRMWARE("radeon/KAVERI_sdma.bin");
  77. MODULE_FIRMWARE("radeon/kaveri_pfp.bin");
  78. MODULE_FIRMWARE("radeon/kaveri_me.bin");
  79. MODULE_FIRMWARE("radeon/kaveri_ce.bin");
  80. MODULE_FIRMWARE("radeon/kaveri_mec.bin");
  81. MODULE_FIRMWARE("radeon/kaveri_mec2.bin");
  82. MODULE_FIRMWARE("radeon/kaveri_rlc.bin");
  83. MODULE_FIRMWARE("radeon/kaveri_sdma.bin");
  84. MODULE_FIRMWARE("radeon/KABINI_pfp.bin");
  85. MODULE_FIRMWARE("radeon/KABINI_me.bin");
  86. MODULE_FIRMWARE("radeon/KABINI_ce.bin");
  87. MODULE_FIRMWARE("radeon/KABINI_mec.bin");
  88. MODULE_FIRMWARE("radeon/KABINI_rlc.bin");
  89. MODULE_FIRMWARE("radeon/KABINI_sdma.bin");
  90. MODULE_FIRMWARE("radeon/kabini_pfp.bin");
  91. MODULE_FIRMWARE("radeon/kabini_me.bin");
  92. MODULE_FIRMWARE("radeon/kabini_ce.bin");
  93. MODULE_FIRMWARE("radeon/kabini_mec.bin");
  94. MODULE_FIRMWARE("radeon/kabini_rlc.bin");
  95. MODULE_FIRMWARE("radeon/kabini_sdma.bin");
  96. MODULE_FIRMWARE("radeon/MULLINS_pfp.bin");
  97. MODULE_FIRMWARE("radeon/MULLINS_me.bin");
  98. MODULE_FIRMWARE("radeon/MULLINS_ce.bin");
  99. MODULE_FIRMWARE("radeon/MULLINS_mec.bin");
  100. MODULE_FIRMWARE("radeon/MULLINS_rlc.bin");
  101. MODULE_FIRMWARE("radeon/MULLINS_sdma.bin");
  102. MODULE_FIRMWARE("radeon/mullins_pfp.bin");
  103. MODULE_FIRMWARE("radeon/mullins_me.bin");
  104. MODULE_FIRMWARE("radeon/mullins_ce.bin");
  105. MODULE_FIRMWARE("radeon/mullins_mec.bin");
  106. MODULE_FIRMWARE("radeon/mullins_rlc.bin");
  107. MODULE_FIRMWARE("radeon/mullins_sdma.bin");
  108. extern int r600_ih_ring_alloc(struct radeon_device *rdev);
  109. extern void r600_ih_ring_fini(struct radeon_device *rdev);
  110. extern void evergreen_mc_stop(struct radeon_device *rdev, struct evergreen_mc_save *save);
  111. extern void evergreen_mc_resume(struct radeon_device *rdev, struct evergreen_mc_save *save);
  112. extern bool evergreen_is_display_hung(struct radeon_device *rdev);
  113. extern void sumo_rlc_fini(struct radeon_device *rdev);
  114. extern int sumo_rlc_init(struct radeon_device *rdev);
  115. extern void si_vram_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc);
  116. extern void si_rlc_reset(struct radeon_device *rdev);
  117. extern void si_init_uvd_internal_cg(struct radeon_device *rdev);
  118. static u32 cik_get_cu_active_bitmap(struct radeon_device *rdev, u32 se, u32 sh);
  119. extern int cik_sdma_resume(struct radeon_device *rdev);
  120. extern void cik_sdma_enable(struct radeon_device *rdev, bool enable);
  121. extern void cik_sdma_fini(struct radeon_device *rdev);
  122. extern void vce_v2_0_enable_mgcg(struct radeon_device *rdev, bool enable);
  123. static void cik_rlc_stop(struct radeon_device *rdev);
  124. static void cik_pcie_gen3_enable(struct radeon_device *rdev);
  125. static void cik_program_aspm(struct radeon_device *rdev);
  126. static void cik_init_pg(struct radeon_device *rdev);
  127. static void cik_init_cg(struct radeon_device *rdev);
  128. static void cik_fini_pg(struct radeon_device *rdev);
  129. static void cik_fini_cg(struct radeon_device *rdev);
  130. static void cik_enable_gui_idle_interrupt(struct radeon_device *rdev,
  131. bool enable);
  132. /**
  133. * cik_get_allowed_info_register - fetch the register for the info ioctl
  134. *
  135. * @rdev: radeon_device pointer
  136. * @reg: register offset in bytes
  137. * @val: register value
  138. *
  139. * Returns 0 for success or -EINVAL for an invalid register
  140. *
  141. */
  142. int cik_get_allowed_info_register(struct radeon_device *rdev,
  143. u32 reg, u32 *val)
  144. {
  145. switch (reg) {
  146. case GRBM_STATUS:
  147. case GRBM_STATUS2:
  148. case GRBM_STATUS_SE0:
  149. case GRBM_STATUS_SE1:
  150. case GRBM_STATUS_SE2:
  151. case GRBM_STATUS_SE3:
  152. case SRBM_STATUS:
  153. case SRBM_STATUS2:
  154. case (SDMA0_STATUS_REG + SDMA0_REGISTER_OFFSET):
  155. case (SDMA0_STATUS_REG + SDMA1_REGISTER_OFFSET):
  156. case UVD_STATUS:
  157. /* TODO VCE */
  158. *val = RREG32(reg);
  159. return 0;
  160. default:
  161. return -EINVAL;
  162. }
  163. }
  164. /*
  165. * Indirect registers accessor
  166. */
  167. u32 cik_didt_rreg(struct radeon_device *rdev, u32 reg)
  168. {
  169. unsigned long flags;
  170. u32 r;
  171. spin_lock_irqsave(&rdev->didt_idx_lock, flags);
  172. WREG32(CIK_DIDT_IND_INDEX, (reg));
  173. r = RREG32(CIK_DIDT_IND_DATA);
  174. spin_unlock_irqrestore(&rdev->didt_idx_lock, flags);
  175. return r;
  176. }
  177. void cik_didt_wreg(struct radeon_device *rdev, u32 reg, u32 v)
  178. {
  179. unsigned long flags;
  180. spin_lock_irqsave(&rdev->didt_idx_lock, flags);
  181. WREG32(CIK_DIDT_IND_INDEX, (reg));
  182. WREG32(CIK_DIDT_IND_DATA, (v));
  183. spin_unlock_irqrestore(&rdev->didt_idx_lock, flags);
  184. }
  185. /* get temperature in millidegrees */
  186. int ci_get_temp(struct radeon_device *rdev)
  187. {
  188. u32 temp;
  189. int actual_temp = 0;
  190. temp = (RREG32_SMC(CG_MULT_THERMAL_STATUS) & CTF_TEMP_MASK) >>
  191. CTF_TEMP_SHIFT;
  192. if (temp & 0x200)
  193. actual_temp = 255;
  194. else
  195. actual_temp = temp & 0x1ff;
  196. actual_temp = actual_temp * 1000;
  197. return actual_temp;
  198. }
  199. /* get temperature in millidegrees */
  200. int kv_get_temp(struct radeon_device *rdev)
  201. {
  202. u32 temp;
  203. int actual_temp = 0;
  204. temp = RREG32_SMC(0xC0300E0C);
  205. if (temp)
  206. actual_temp = (temp / 8) - 49;
  207. else
  208. actual_temp = 0;
  209. actual_temp = actual_temp * 1000;
  210. return actual_temp;
  211. }
  212. /*
  213. * Indirect registers accessor
  214. */
  215. u32 cik_pciep_rreg(struct radeon_device *rdev, u32 reg)
  216. {
  217. unsigned long flags;
  218. u32 r;
  219. spin_lock_irqsave(&rdev->pciep_idx_lock, flags);
  220. WREG32(PCIE_INDEX, reg);
  221. (void)RREG32(PCIE_INDEX);
  222. r = RREG32(PCIE_DATA);
  223. spin_unlock_irqrestore(&rdev->pciep_idx_lock, flags);
  224. return r;
  225. }
  226. void cik_pciep_wreg(struct radeon_device *rdev, u32 reg, u32 v)
  227. {
  228. unsigned long flags;
  229. spin_lock_irqsave(&rdev->pciep_idx_lock, flags);
  230. WREG32(PCIE_INDEX, reg);
  231. (void)RREG32(PCIE_INDEX);
  232. WREG32(PCIE_DATA, v);
  233. (void)RREG32(PCIE_DATA);
  234. spin_unlock_irqrestore(&rdev->pciep_idx_lock, flags);
  235. }
  236. static const u32 spectre_rlc_save_restore_register_list[] =
  237. {
  238. (0x0e00 << 16) | (0xc12c >> 2),
  239. 0x00000000,
  240. (0x0e00 << 16) | (0xc140 >> 2),
  241. 0x00000000,
  242. (0x0e00 << 16) | (0xc150 >> 2),
  243. 0x00000000,
  244. (0x0e00 << 16) | (0xc15c >> 2),
  245. 0x00000000,
  246. (0x0e00 << 16) | (0xc168 >> 2),
  247. 0x00000000,
  248. (0x0e00 << 16) | (0xc170 >> 2),
  249. 0x00000000,
  250. (0x0e00 << 16) | (0xc178 >> 2),
  251. 0x00000000,
  252. (0x0e00 << 16) | (0xc204 >> 2),
  253. 0x00000000,
  254. (0x0e00 << 16) | (0xc2b4 >> 2),
  255. 0x00000000,
  256. (0x0e00 << 16) | (0xc2b8 >> 2),
  257. 0x00000000,
  258. (0x0e00 << 16) | (0xc2bc >> 2),
  259. 0x00000000,
  260. (0x0e00 << 16) | (0xc2c0 >> 2),
  261. 0x00000000,
  262. (0x0e00 << 16) | (0x8228 >> 2),
  263. 0x00000000,
  264. (0x0e00 << 16) | (0x829c >> 2),
  265. 0x00000000,
  266. (0x0e00 << 16) | (0x869c >> 2),
  267. 0x00000000,
  268. (0x0600 << 16) | (0x98f4 >> 2),
  269. 0x00000000,
  270. (0x0e00 << 16) | (0x98f8 >> 2),
  271. 0x00000000,
  272. (0x0e00 << 16) | (0x9900 >> 2),
  273. 0x00000000,
  274. (0x0e00 << 16) | (0xc260 >> 2),
  275. 0x00000000,
  276. (0x0e00 << 16) | (0x90e8 >> 2),
  277. 0x00000000,
  278. (0x0e00 << 16) | (0x3c000 >> 2),
  279. 0x00000000,
  280. (0x0e00 << 16) | (0x3c00c >> 2),
  281. 0x00000000,
  282. (0x0e00 << 16) | (0x8c1c >> 2),
  283. 0x00000000,
  284. (0x0e00 << 16) | (0x9700 >> 2),
  285. 0x00000000,
  286. (0x0e00 << 16) | (0xcd20 >> 2),
  287. 0x00000000,
  288. (0x4e00 << 16) | (0xcd20 >> 2),
  289. 0x00000000,
  290. (0x5e00 << 16) | (0xcd20 >> 2),
  291. 0x00000000,
  292. (0x6e00 << 16) | (0xcd20 >> 2),
  293. 0x00000000,
  294. (0x7e00 << 16) | (0xcd20 >> 2),
  295. 0x00000000,
  296. (0x8e00 << 16) | (0xcd20 >> 2),
  297. 0x00000000,
  298. (0x9e00 << 16) | (0xcd20 >> 2),
  299. 0x00000000,
  300. (0xae00 << 16) | (0xcd20 >> 2),
  301. 0x00000000,
  302. (0xbe00 << 16) | (0xcd20 >> 2),
  303. 0x00000000,
  304. (0x0e00 << 16) | (0x89bc >> 2),
  305. 0x00000000,
  306. (0x0e00 << 16) | (0x8900 >> 2),
  307. 0x00000000,
  308. 0x3,
  309. (0x0e00 << 16) | (0xc130 >> 2),
  310. 0x00000000,
  311. (0x0e00 << 16) | (0xc134 >> 2),
  312. 0x00000000,
  313. (0x0e00 << 16) | (0xc1fc >> 2),
  314. 0x00000000,
  315. (0x0e00 << 16) | (0xc208 >> 2),
  316. 0x00000000,
  317. (0x0e00 << 16) | (0xc264 >> 2),
  318. 0x00000000,
  319. (0x0e00 << 16) | (0xc268 >> 2),
  320. 0x00000000,
  321. (0x0e00 << 16) | (0xc26c >> 2),
  322. 0x00000000,
  323. (0x0e00 << 16) | (0xc270 >> 2),
  324. 0x00000000,
  325. (0x0e00 << 16) | (0xc274 >> 2),
  326. 0x00000000,
  327. (0x0e00 << 16) | (0xc278 >> 2),
  328. 0x00000000,
  329. (0x0e00 << 16) | (0xc27c >> 2),
  330. 0x00000000,
  331. (0x0e00 << 16) | (0xc280 >> 2),
  332. 0x00000000,
  333. (0x0e00 << 16) | (0xc284 >> 2),
  334. 0x00000000,
  335. (0x0e00 << 16) | (0xc288 >> 2),
  336. 0x00000000,
  337. (0x0e00 << 16) | (0xc28c >> 2),
  338. 0x00000000,
  339. (0x0e00 << 16) | (0xc290 >> 2),
  340. 0x00000000,
  341. (0x0e00 << 16) | (0xc294 >> 2),
  342. 0x00000000,
  343. (0x0e00 << 16) | (0xc298 >> 2),
  344. 0x00000000,
  345. (0x0e00 << 16) | (0xc29c >> 2),
  346. 0x00000000,
  347. (0x0e00 << 16) | (0xc2a0 >> 2),
  348. 0x00000000,
  349. (0x0e00 << 16) | (0xc2a4 >> 2),
  350. 0x00000000,
  351. (0x0e00 << 16) | (0xc2a8 >> 2),
  352. 0x00000000,
  353. (0x0e00 << 16) | (0xc2ac >> 2),
  354. 0x00000000,
  355. (0x0e00 << 16) | (0xc2b0 >> 2),
  356. 0x00000000,
  357. (0x0e00 << 16) | (0x301d0 >> 2),
  358. 0x00000000,
  359. (0x0e00 << 16) | (0x30238 >> 2),
  360. 0x00000000,
  361. (0x0e00 << 16) | (0x30250 >> 2),
  362. 0x00000000,
  363. (0x0e00 << 16) | (0x30254 >> 2),
  364. 0x00000000,
  365. (0x0e00 << 16) | (0x30258 >> 2),
  366. 0x00000000,
  367. (0x0e00 << 16) | (0x3025c >> 2),
  368. 0x00000000,
  369. (0x4e00 << 16) | (0xc900 >> 2),
  370. 0x00000000,
  371. (0x5e00 << 16) | (0xc900 >> 2),
  372. 0x00000000,
  373. (0x6e00 << 16) | (0xc900 >> 2),
  374. 0x00000000,
  375. (0x7e00 << 16) | (0xc900 >> 2),
  376. 0x00000000,
  377. (0x8e00 << 16) | (0xc900 >> 2),
  378. 0x00000000,
  379. (0x9e00 << 16) | (0xc900 >> 2),
  380. 0x00000000,
  381. (0xae00 << 16) | (0xc900 >> 2),
  382. 0x00000000,
  383. (0xbe00 << 16) | (0xc900 >> 2),
  384. 0x00000000,
  385. (0x4e00 << 16) | (0xc904 >> 2),
  386. 0x00000000,
  387. (0x5e00 << 16) | (0xc904 >> 2),
  388. 0x00000000,
  389. (0x6e00 << 16) | (0xc904 >> 2),
  390. 0x00000000,
  391. (0x7e00 << 16) | (0xc904 >> 2),
  392. 0x00000000,
  393. (0x8e00 << 16) | (0xc904 >> 2),
  394. 0x00000000,
  395. (0x9e00 << 16) | (0xc904 >> 2),
  396. 0x00000000,
  397. (0xae00 << 16) | (0xc904 >> 2),
  398. 0x00000000,
  399. (0xbe00 << 16) | (0xc904 >> 2),
  400. 0x00000000,
  401. (0x4e00 << 16) | (0xc908 >> 2),
  402. 0x00000000,
  403. (0x5e00 << 16) | (0xc908 >> 2),
  404. 0x00000000,
  405. (0x6e00 << 16) | (0xc908 >> 2),
  406. 0x00000000,
  407. (0x7e00 << 16) | (0xc908 >> 2),
  408. 0x00000000,
  409. (0x8e00 << 16) | (0xc908 >> 2),
  410. 0x00000000,
  411. (0x9e00 << 16) | (0xc908 >> 2),
  412. 0x00000000,
  413. (0xae00 << 16) | (0xc908 >> 2),
  414. 0x00000000,
  415. (0xbe00 << 16) | (0xc908 >> 2),
  416. 0x00000000,
  417. (0x4e00 << 16) | (0xc90c >> 2),
  418. 0x00000000,
  419. (0x5e00 << 16) | (0xc90c >> 2),
  420. 0x00000000,
  421. (0x6e00 << 16) | (0xc90c >> 2),
  422. 0x00000000,
  423. (0x7e00 << 16) | (0xc90c >> 2),
  424. 0x00000000,
  425. (0x8e00 << 16) | (0xc90c >> 2),
  426. 0x00000000,
  427. (0x9e00 << 16) | (0xc90c >> 2),
  428. 0x00000000,
  429. (0xae00 << 16) | (0xc90c >> 2),
  430. 0x00000000,
  431. (0xbe00 << 16) | (0xc90c >> 2),
  432. 0x00000000,
  433. (0x4e00 << 16) | (0xc910 >> 2),
  434. 0x00000000,
  435. (0x5e00 << 16) | (0xc910 >> 2),
  436. 0x00000000,
  437. (0x6e00 << 16) | (0xc910 >> 2),
  438. 0x00000000,
  439. (0x7e00 << 16) | (0xc910 >> 2),
  440. 0x00000000,
  441. (0x8e00 << 16) | (0xc910 >> 2),
  442. 0x00000000,
  443. (0x9e00 << 16) | (0xc910 >> 2),
  444. 0x00000000,
  445. (0xae00 << 16) | (0xc910 >> 2),
  446. 0x00000000,
  447. (0xbe00 << 16) | (0xc910 >> 2),
  448. 0x00000000,
  449. (0x0e00 << 16) | (0xc99c >> 2),
  450. 0x00000000,
  451. (0x0e00 << 16) | (0x9834 >> 2),
  452. 0x00000000,
  453. (0x0000 << 16) | (0x30f00 >> 2),
  454. 0x00000000,
  455. (0x0001 << 16) | (0x30f00 >> 2),
  456. 0x00000000,
  457. (0x0000 << 16) | (0x30f04 >> 2),
  458. 0x00000000,
  459. (0x0001 << 16) | (0x30f04 >> 2),
  460. 0x00000000,
  461. (0x0000 << 16) | (0x30f08 >> 2),
  462. 0x00000000,
  463. (0x0001 << 16) | (0x30f08 >> 2),
  464. 0x00000000,
  465. (0x0000 << 16) | (0x30f0c >> 2),
  466. 0x00000000,
  467. (0x0001 << 16) | (0x30f0c >> 2),
  468. 0x00000000,
  469. (0x0600 << 16) | (0x9b7c >> 2),
  470. 0x00000000,
  471. (0x0e00 << 16) | (0x8a14 >> 2),
  472. 0x00000000,
  473. (0x0e00 << 16) | (0x8a18 >> 2),
  474. 0x00000000,
  475. (0x0600 << 16) | (0x30a00 >> 2),
  476. 0x00000000,
  477. (0x0e00 << 16) | (0x8bf0 >> 2),
  478. 0x00000000,
  479. (0x0e00 << 16) | (0x8bcc >> 2),
  480. 0x00000000,
  481. (0x0e00 << 16) | (0x8b24 >> 2),
  482. 0x00000000,
  483. (0x0e00 << 16) | (0x30a04 >> 2),
  484. 0x00000000,
  485. (0x0600 << 16) | (0x30a10 >> 2),
  486. 0x00000000,
  487. (0x0600 << 16) | (0x30a14 >> 2),
  488. 0x00000000,
  489. (0x0600 << 16) | (0x30a18 >> 2),
  490. 0x00000000,
  491. (0x0600 << 16) | (0x30a2c >> 2),
  492. 0x00000000,
  493. (0x0e00 << 16) | (0xc700 >> 2),
  494. 0x00000000,
  495. (0x0e00 << 16) | (0xc704 >> 2),
  496. 0x00000000,
  497. (0x0e00 << 16) | (0xc708 >> 2),
  498. 0x00000000,
  499. (0x0e00 << 16) | (0xc768 >> 2),
  500. 0x00000000,
  501. (0x0400 << 16) | (0xc770 >> 2),
  502. 0x00000000,
  503. (0x0400 << 16) | (0xc774 >> 2),
  504. 0x00000000,
  505. (0x0400 << 16) | (0xc778 >> 2),
  506. 0x00000000,
  507. (0x0400 << 16) | (0xc77c >> 2),
  508. 0x00000000,
  509. (0x0400 << 16) | (0xc780 >> 2),
  510. 0x00000000,
  511. (0x0400 << 16) | (0xc784 >> 2),
  512. 0x00000000,
  513. (0x0400 << 16) | (0xc788 >> 2),
  514. 0x00000000,
  515. (0x0400 << 16) | (0xc78c >> 2),
  516. 0x00000000,
  517. (0x0400 << 16) | (0xc798 >> 2),
  518. 0x00000000,
  519. (0x0400 << 16) | (0xc79c >> 2),
  520. 0x00000000,
  521. (0x0400 << 16) | (0xc7a0 >> 2),
  522. 0x00000000,
  523. (0x0400 << 16) | (0xc7a4 >> 2),
  524. 0x00000000,
  525. (0x0400 << 16) | (0xc7a8 >> 2),
  526. 0x00000000,
  527. (0x0400 << 16) | (0xc7ac >> 2),
  528. 0x00000000,
  529. (0x0400 << 16) | (0xc7b0 >> 2),
  530. 0x00000000,
  531. (0x0400 << 16) | (0xc7b4 >> 2),
  532. 0x00000000,
  533. (0x0e00 << 16) | (0x9100 >> 2),
  534. 0x00000000,
  535. (0x0e00 << 16) | (0x3c010 >> 2),
  536. 0x00000000,
  537. (0x0e00 << 16) | (0x92a8 >> 2),
  538. 0x00000000,
  539. (0x0e00 << 16) | (0x92ac >> 2),
  540. 0x00000000,
  541. (0x0e00 << 16) | (0x92b4 >> 2),
  542. 0x00000000,
  543. (0x0e00 << 16) | (0x92b8 >> 2),
  544. 0x00000000,
  545. (0x0e00 << 16) | (0x92bc >> 2),
  546. 0x00000000,
  547. (0x0e00 << 16) | (0x92c0 >> 2),
  548. 0x00000000,
  549. (0x0e00 << 16) | (0x92c4 >> 2),
  550. 0x00000000,
  551. (0x0e00 << 16) | (0x92c8 >> 2),
  552. 0x00000000,
  553. (0x0e00 << 16) | (0x92cc >> 2),
  554. 0x00000000,
  555. (0x0e00 << 16) | (0x92d0 >> 2),
  556. 0x00000000,
  557. (0x0e00 << 16) | (0x8c00 >> 2),
  558. 0x00000000,
  559. (0x0e00 << 16) | (0x8c04 >> 2),
  560. 0x00000000,
  561. (0x0e00 << 16) | (0x8c20 >> 2),
  562. 0x00000000,
  563. (0x0e00 << 16) | (0x8c38 >> 2),
  564. 0x00000000,
  565. (0x0e00 << 16) | (0x8c3c >> 2),
  566. 0x00000000,
  567. (0x0e00 << 16) | (0xae00 >> 2),
  568. 0x00000000,
  569. (0x0e00 << 16) | (0x9604 >> 2),
  570. 0x00000000,
  571. (0x0e00 << 16) | (0xac08 >> 2),
  572. 0x00000000,
  573. (0x0e00 << 16) | (0xac0c >> 2),
  574. 0x00000000,
  575. (0x0e00 << 16) | (0xac10 >> 2),
  576. 0x00000000,
  577. (0x0e00 << 16) | (0xac14 >> 2),
  578. 0x00000000,
  579. (0x0e00 << 16) | (0xac58 >> 2),
  580. 0x00000000,
  581. (0x0e00 << 16) | (0xac68 >> 2),
  582. 0x00000000,
  583. (0x0e00 << 16) | (0xac6c >> 2),
  584. 0x00000000,
  585. (0x0e00 << 16) | (0xac70 >> 2),
  586. 0x00000000,
  587. (0x0e00 << 16) | (0xac74 >> 2),
  588. 0x00000000,
  589. (0x0e00 << 16) | (0xac78 >> 2),
  590. 0x00000000,
  591. (0x0e00 << 16) | (0xac7c >> 2),
  592. 0x00000000,
  593. (0x0e00 << 16) | (0xac80 >> 2),
  594. 0x00000000,
  595. (0x0e00 << 16) | (0xac84 >> 2),
  596. 0x00000000,
  597. (0x0e00 << 16) | (0xac88 >> 2),
  598. 0x00000000,
  599. (0x0e00 << 16) | (0xac8c >> 2),
  600. 0x00000000,
  601. (0x0e00 << 16) | (0x970c >> 2),
  602. 0x00000000,
  603. (0x0e00 << 16) | (0x9714 >> 2),
  604. 0x00000000,
  605. (0x0e00 << 16) | (0x9718 >> 2),
  606. 0x00000000,
  607. (0x0e00 << 16) | (0x971c >> 2),
  608. 0x00000000,
  609. (0x0e00 << 16) | (0x31068 >> 2),
  610. 0x00000000,
  611. (0x4e00 << 16) | (0x31068 >> 2),
  612. 0x00000000,
  613. (0x5e00 << 16) | (0x31068 >> 2),
  614. 0x00000000,
  615. (0x6e00 << 16) | (0x31068 >> 2),
  616. 0x00000000,
  617. (0x7e00 << 16) | (0x31068 >> 2),
  618. 0x00000000,
  619. (0x8e00 << 16) | (0x31068 >> 2),
  620. 0x00000000,
  621. (0x9e00 << 16) | (0x31068 >> 2),
  622. 0x00000000,
  623. (0xae00 << 16) | (0x31068 >> 2),
  624. 0x00000000,
  625. (0xbe00 << 16) | (0x31068 >> 2),
  626. 0x00000000,
  627. (0x0e00 << 16) | (0xcd10 >> 2),
  628. 0x00000000,
  629. (0x0e00 << 16) | (0xcd14 >> 2),
  630. 0x00000000,
  631. (0x0e00 << 16) | (0x88b0 >> 2),
  632. 0x00000000,
  633. (0x0e00 << 16) | (0x88b4 >> 2),
  634. 0x00000000,
  635. (0x0e00 << 16) | (0x88b8 >> 2),
  636. 0x00000000,
  637. (0x0e00 << 16) | (0x88bc >> 2),
  638. 0x00000000,
  639. (0x0400 << 16) | (0x89c0 >> 2),
  640. 0x00000000,
  641. (0x0e00 << 16) | (0x88c4 >> 2),
  642. 0x00000000,
  643. (0x0e00 << 16) | (0x88c8 >> 2),
  644. 0x00000000,
  645. (0x0e00 << 16) | (0x88d0 >> 2),
  646. 0x00000000,
  647. (0x0e00 << 16) | (0x88d4 >> 2),
  648. 0x00000000,
  649. (0x0e00 << 16) | (0x88d8 >> 2),
  650. 0x00000000,
  651. (0x0e00 << 16) | (0x8980 >> 2),
  652. 0x00000000,
  653. (0x0e00 << 16) | (0x30938 >> 2),
  654. 0x00000000,
  655. (0x0e00 << 16) | (0x3093c >> 2),
  656. 0x00000000,
  657. (0x0e00 << 16) | (0x30940 >> 2),
  658. 0x00000000,
  659. (0x0e00 << 16) | (0x89a0 >> 2),
  660. 0x00000000,
  661. (0x0e00 << 16) | (0x30900 >> 2),
  662. 0x00000000,
  663. (0x0e00 << 16) | (0x30904 >> 2),
  664. 0x00000000,
  665. (0x0e00 << 16) | (0x89b4 >> 2),
  666. 0x00000000,
  667. (0x0e00 << 16) | (0x3c210 >> 2),
  668. 0x00000000,
  669. (0x0e00 << 16) | (0x3c214 >> 2),
  670. 0x00000000,
  671. (0x0e00 << 16) | (0x3c218 >> 2),
  672. 0x00000000,
  673. (0x0e00 << 16) | (0x8904 >> 2),
  674. 0x00000000,
  675. 0x5,
  676. (0x0e00 << 16) | (0x8c28 >> 2),
  677. (0x0e00 << 16) | (0x8c2c >> 2),
  678. (0x0e00 << 16) | (0x8c30 >> 2),
  679. (0x0e00 << 16) | (0x8c34 >> 2),
  680. (0x0e00 << 16) | (0x9600 >> 2),
  681. };
  682. static const u32 kalindi_rlc_save_restore_register_list[] =
  683. {
  684. (0x0e00 << 16) | (0xc12c >> 2),
  685. 0x00000000,
  686. (0x0e00 << 16) | (0xc140 >> 2),
  687. 0x00000000,
  688. (0x0e00 << 16) | (0xc150 >> 2),
  689. 0x00000000,
  690. (0x0e00 << 16) | (0xc15c >> 2),
  691. 0x00000000,
  692. (0x0e00 << 16) | (0xc168 >> 2),
  693. 0x00000000,
  694. (0x0e00 << 16) | (0xc170 >> 2),
  695. 0x00000000,
  696. (0x0e00 << 16) | (0xc204 >> 2),
  697. 0x00000000,
  698. (0x0e00 << 16) | (0xc2b4 >> 2),
  699. 0x00000000,
  700. (0x0e00 << 16) | (0xc2b8 >> 2),
  701. 0x00000000,
  702. (0x0e00 << 16) | (0xc2bc >> 2),
  703. 0x00000000,
  704. (0x0e00 << 16) | (0xc2c0 >> 2),
  705. 0x00000000,
  706. (0x0e00 << 16) | (0x8228 >> 2),
  707. 0x00000000,
  708. (0x0e00 << 16) | (0x829c >> 2),
  709. 0x00000000,
  710. (0x0e00 << 16) | (0x869c >> 2),
  711. 0x00000000,
  712. (0x0600 << 16) | (0x98f4 >> 2),
  713. 0x00000000,
  714. (0x0e00 << 16) | (0x98f8 >> 2),
  715. 0x00000000,
  716. (0x0e00 << 16) | (0x9900 >> 2),
  717. 0x00000000,
  718. (0x0e00 << 16) | (0xc260 >> 2),
  719. 0x00000000,
  720. (0x0e00 << 16) | (0x90e8 >> 2),
  721. 0x00000000,
  722. (0x0e00 << 16) | (0x3c000 >> 2),
  723. 0x00000000,
  724. (0x0e00 << 16) | (0x3c00c >> 2),
  725. 0x00000000,
  726. (0x0e00 << 16) | (0x8c1c >> 2),
  727. 0x00000000,
  728. (0x0e00 << 16) | (0x9700 >> 2),
  729. 0x00000000,
  730. (0x0e00 << 16) | (0xcd20 >> 2),
  731. 0x00000000,
  732. (0x4e00 << 16) | (0xcd20 >> 2),
  733. 0x00000000,
  734. (0x5e00 << 16) | (0xcd20 >> 2),
  735. 0x00000000,
  736. (0x6e00 << 16) | (0xcd20 >> 2),
  737. 0x00000000,
  738. (0x7e00 << 16) | (0xcd20 >> 2),
  739. 0x00000000,
  740. (0x0e00 << 16) | (0x89bc >> 2),
  741. 0x00000000,
  742. (0x0e00 << 16) | (0x8900 >> 2),
  743. 0x00000000,
  744. 0x3,
  745. (0x0e00 << 16) | (0xc130 >> 2),
  746. 0x00000000,
  747. (0x0e00 << 16) | (0xc134 >> 2),
  748. 0x00000000,
  749. (0x0e00 << 16) | (0xc1fc >> 2),
  750. 0x00000000,
  751. (0x0e00 << 16) | (0xc208 >> 2),
  752. 0x00000000,
  753. (0x0e00 << 16) | (0xc264 >> 2),
  754. 0x00000000,
  755. (0x0e00 << 16) | (0xc268 >> 2),
  756. 0x00000000,
  757. (0x0e00 << 16) | (0xc26c >> 2),
  758. 0x00000000,
  759. (0x0e00 << 16) | (0xc270 >> 2),
  760. 0x00000000,
  761. (0x0e00 << 16) | (0xc274 >> 2),
  762. 0x00000000,
  763. (0x0e00 << 16) | (0xc28c >> 2),
  764. 0x00000000,
  765. (0x0e00 << 16) | (0xc290 >> 2),
  766. 0x00000000,
  767. (0x0e00 << 16) | (0xc294 >> 2),
  768. 0x00000000,
  769. (0x0e00 << 16) | (0xc298 >> 2),
  770. 0x00000000,
  771. (0x0e00 << 16) | (0xc2a0 >> 2),
  772. 0x00000000,
  773. (0x0e00 << 16) | (0xc2a4 >> 2),
  774. 0x00000000,
  775. (0x0e00 << 16) | (0xc2a8 >> 2),
  776. 0x00000000,
  777. (0x0e00 << 16) | (0xc2ac >> 2),
  778. 0x00000000,
  779. (0x0e00 << 16) | (0x301d0 >> 2),
  780. 0x00000000,
  781. (0x0e00 << 16) | (0x30238 >> 2),
  782. 0x00000000,
  783. (0x0e00 << 16) | (0x30250 >> 2),
  784. 0x00000000,
  785. (0x0e00 << 16) | (0x30254 >> 2),
  786. 0x00000000,
  787. (0x0e00 << 16) | (0x30258 >> 2),
  788. 0x00000000,
  789. (0x0e00 << 16) | (0x3025c >> 2),
  790. 0x00000000,
  791. (0x4e00 << 16) | (0xc900 >> 2),
  792. 0x00000000,
  793. (0x5e00 << 16) | (0xc900 >> 2),
  794. 0x00000000,
  795. (0x6e00 << 16) | (0xc900 >> 2),
  796. 0x00000000,
  797. (0x7e00 << 16) | (0xc900 >> 2),
  798. 0x00000000,
  799. (0x4e00 << 16) | (0xc904 >> 2),
  800. 0x00000000,
  801. (0x5e00 << 16) | (0xc904 >> 2),
  802. 0x00000000,
  803. (0x6e00 << 16) | (0xc904 >> 2),
  804. 0x00000000,
  805. (0x7e00 << 16) | (0xc904 >> 2),
  806. 0x00000000,
  807. (0x4e00 << 16) | (0xc908 >> 2),
  808. 0x00000000,
  809. (0x5e00 << 16) | (0xc908 >> 2),
  810. 0x00000000,
  811. (0x6e00 << 16) | (0xc908 >> 2),
  812. 0x00000000,
  813. (0x7e00 << 16) | (0xc908 >> 2),
  814. 0x00000000,
  815. (0x4e00 << 16) | (0xc90c >> 2),
  816. 0x00000000,
  817. (0x5e00 << 16) | (0xc90c >> 2),
  818. 0x00000000,
  819. (0x6e00 << 16) | (0xc90c >> 2),
  820. 0x00000000,
  821. (0x7e00 << 16) | (0xc90c >> 2),
  822. 0x00000000,
  823. (0x4e00 << 16) | (0xc910 >> 2),
  824. 0x00000000,
  825. (0x5e00 << 16) | (0xc910 >> 2),
  826. 0x00000000,
  827. (0x6e00 << 16) | (0xc910 >> 2),
  828. 0x00000000,
  829. (0x7e00 << 16) | (0xc910 >> 2),
  830. 0x00000000,
  831. (0x0e00 << 16) | (0xc99c >> 2),
  832. 0x00000000,
  833. (0x0e00 << 16) | (0x9834 >> 2),
  834. 0x00000000,
  835. (0x0000 << 16) | (0x30f00 >> 2),
  836. 0x00000000,
  837. (0x0000 << 16) | (0x30f04 >> 2),
  838. 0x00000000,
  839. (0x0000 << 16) | (0x30f08 >> 2),
  840. 0x00000000,
  841. (0x0000 << 16) | (0x30f0c >> 2),
  842. 0x00000000,
  843. (0x0600 << 16) | (0x9b7c >> 2),
  844. 0x00000000,
  845. (0x0e00 << 16) | (0x8a14 >> 2),
  846. 0x00000000,
  847. (0x0e00 << 16) | (0x8a18 >> 2),
  848. 0x00000000,
  849. (0x0600 << 16) | (0x30a00 >> 2),
  850. 0x00000000,
  851. (0x0e00 << 16) | (0x8bf0 >> 2),
  852. 0x00000000,
  853. (0x0e00 << 16) | (0x8bcc >> 2),
  854. 0x00000000,
  855. (0x0e00 << 16) | (0x8b24 >> 2),
  856. 0x00000000,
  857. (0x0e00 << 16) | (0x30a04 >> 2),
  858. 0x00000000,
  859. (0x0600 << 16) | (0x30a10 >> 2),
  860. 0x00000000,
  861. (0x0600 << 16) | (0x30a14 >> 2),
  862. 0x00000000,
  863. (0x0600 << 16) | (0x30a18 >> 2),
  864. 0x00000000,
  865. (0x0600 << 16) | (0x30a2c >> 2),
  866. 0x00000000,
  867. (0x0e00 << 16) | (0xc700 >> 2),
  868. 0x00000000,
  869. (0x0e00 << 16) | (0xc704 >> 2),
  870. 0x00000000,
  871. (0x0e00 << 16) | (0xc708 >> 2),
  872. 0x00000000,
  873. (0x0e00 << 16) | (0xc768 >> 2),
  874. 0x00000000,
  875. (0x0400 << 16) | (0xc770 >> 2),
  876. 0x00000000,
  877. (0x0400 << 16) | (0xc774 >> 2),
  878. 0x00000000,
  879. (0x0400 << 16) | (0xc798 >> 2),
  880. 0x00000000,
  881. (0x0400 << 16) | (0xc79c >> 2),
  882. 0x00000000,
  883. (0x0e00 << 16) | (0x9100 >> 2),
  884. 0x00000000,
  885. (0x0e00 << 16) | (0x3c010 >> 2),
  886. 0x00000000,
  887. (0x0e00 << 16) | (0x8c00 >> 2),
  888. 0x00000000,
  889. (0x0e00 << 16) | (0x8c04 >> 2),
  890. 0x00000000,
  891. (0x0e00 << 16) | (0x8c20 >> 2),
  892. 0x00000000,
  893. (0x0e00 << 16) | (0x8c38 >> 2),
  894. 0x00000000,
  895. (0x0e00 << 16) | (0x8c3c >> 2),
  896. 0x00000000,
  897. (0x0e00 << 16) | (0xae00 >> 2),
  898. 0x00000000,
  899. (0x0e00 << 16) | (0x9604 >> 2),
  900. 0x00000000,
  901. (0x0e00 << 16) | (0xac08 >> 2),
  902. 0x00000000,
  903. (0x0e00 << 16) | (0xac0c >> 2),
  904. 0x00000000,
  905. (0x0e00 << 16) | (0xac10 >> 2),
  906. 0x00000000,
  907. (0x0e00 << 16) | (0xac14 >> 2),
  908. 0x00000000,
  909. (0x0e00 << 16) | (0xac58 >> 2),
  910. 0x00000000,
  911. (0x0e00 << 16) | (0xac68 >> 2),
  912. 0x00000000,
  913. (0x0e00 << 16) | (0xac6c >> 2),
  914. 0x00000000,
  915. (0x0e00 << 16) | (0xac70 >> 2),
  916. 0x00000000,
  917. (0x0e00 << 16) | (0xac74 >> 2),
  918. 0x00000000,
  919. (0x0e00 << 16) | (0xac78 >> 2),
  920. 0x00000000,
  921. (0x0e00 << 16) | (0xac7c >> 2),
  922. 0x00000000,
  923. (0x0e00 << 16) | (0xac80 >> 2),
  924. 0x00000000,
  925. (0x0e00 << 16) | (0xac84 >> 2),
  926. 0x00000000,
  927. (0x0e00 << 16) | (0xac88 >> 2),
  928. 0x00000000,
  929. (0x0e00 << 16) | (0xac8c >> 2),
  930. 0x00000000,
  931. (0x0e00 << 16) | (0x970c >> 2),
  932. 0x00000000,
  933. (0x0e00 << 16) | (0x9714 >> 2),
  934. 0x00000000,
  935. (0x0e00 << 16) | (0x9718 >> 2),
  936. 0x00000000,
  937. (0x0e00 << 16) | (0x971c >> 2),
  938. 0x00000000,
  939. (0x0e00 << 16) | (0x31068 >> 2),
  940. 0x00000000,
  941. (0x4e00 << 16) | (0x31068 >> 2),
  942. 0x00000000,
  943. (0x5e00 << 16) | (0x31068 >> 2),
  944. 0x00000000,
  945. (0x6e00 << 16) | (0x31068 >> 2),
  946. 0x00000000,
  947. (0x7e00 << 16) | (0x31068 >> 2),
  948. 0x00000000,
  949. (0x0e00 << 16) | (0xcd10 >> 2),
  950. 0x00000000,
  951. (0x0e00 << 16) | (0xcd14 >> 2),
  952. 0x00000000,
  953. (0x0e00 << 16) | (0x88b0 >> 2),
  954. 0x00000000,
  955. (0x0e00 << 16) | (0x88b4 >> 2),
  956. 0x00000000,
  957. (0x0e00 << 16) | (0x88b8 >> 2),
  958. 0x00000000,
  959. (0x0e00 << 16) | (0x88bc >> 2),
  960. 0x00000000,
  961. (0x0400 << 16) | (0x89c0 >> 2),
  962. 0x00000000,
  963. (0x0e00 << 16) | (0x88c4 >> 2),
  964. 0x00000000,
  965. (0x0e00 << 16) | (0x88c8 >> 2),
  966. 0x00000000,
  967. (0x0e00 << 16) | (0x88d0 >> 2),
  968. 0x00000000,
  969. (0x0e00 << 16) | (0x88d4 >> 2),
  970. 0x00000000,
  971. (0x0e00 << 16) | (0x88d8 >> 2),
  972. 0x00000000,
  973. (0x0e00 << 16) | (0x8980 >> 2),
  974. 0x00000000,
  975. (0x0e00 << 16) | (0x30938 >> 2),
  976. 0x00000000,
  977. (0x0e00 << 16) | (0x3093c >> 2),
  978. 0x00000000,
  979. (0x0e00 << 16) | (0x30940 >> 2),
  980. 0x00000000,
  981. (0x0e00 << 16) | (0x89a0 >> 2),
  982. 0x00000000,
  983. (0x0e00 << 16) | (0x30900 >> 2),
  984. 0x00000000,
  985. (0x0e00 << 16) | (0x30904 >> 2),
  986. 0x00000000,
  987. (0x0e00 << 16) | (0x89b4 >> 2),
  988. 0x00000000,
  989. (0x0e00 << 16) | (0x3e1fc >> 2),
  990. 0x00000000,
  991. (0x0e00 << 16) | (0x3c210 >> 2),
  992. 0x00000000,
  993. (0x0e00 << 16) | (0x3c214 >> 2),
  994. 0x00000000,
  995. (0x0e00 << 16) | (0x3c218 >> 2),
  996. 0x00000000,
  997. (0x0e00 << 16) | (0x8904 >> 2),
  998. 0x00000000,
  999. 0x5,
  1000. (0x0e00 << 16) | (0x8c28 >> 2),
  1001. (0x0e00 << 16) | (0x8c2c >> 2),
  1002. (0x0e00 << 16) | (0x8c30 >> 2),
  1003. (0x0e00 << 16) | (0x8c34 >> 2),
  1004. (0x0e00 << 16) | (0x9600 >> 2),
  1005. };
  1006. static const u32 bonaire_golden_spm_registers[] =
  1007. {
  1008. 0x30800, 0xe0ffffff, 0xe0000000
  1009. };
  1010. static const u32 bonaire_golden_common_registers[] =
  1011. {
  1012. 0xc770, 0xffffffff, 0x00000800,
  1013. 0xc774, 0xffffffff, 0x00000800,
  1014. 0xc798, 0xffffffff, 0x00007fbf,
  1015. 0xc79c, 0xffffffff, 0x00007faf
  1016. };
  1017. static const u32 bonaire_golden_registers[] =
  1018. {
  1019. 0x3354, 0x00000333, 0x00000333,
  1020. 0x3350, 0x000c0fc0, 0x00040200,
  1021. 0x9a10, 0x00010000, 0x00058208,
  1022. 0x3c000, 0xffff1fff, 0x00140000,
  1023. 0x3c200, 0xfdfc0fff, 0x00000100,
  1024. 0x3c234, 0x40000000, 0x40000200,
  1025. 0x9830, 0xffffffff, 0x00000000,
  1026. 0x9834, 0xf00fffff, 0x00000400,
  1027. 0x9838, 0x0002021c, 0x00020200,
  1028. 0xc78, 0x00000080, 0x00000000,
  1029. 0x5bb0, 0x000000f0, 0x00000070,
  1030. 0x5bc0, 0xf0311fff, 0x80300000,
  1031. 0x98f8, 0x73773777, 0x12010001,
  1032. 0x350c, 0x00810000, 0x408af000,
  1033. 0x7030, 0x31000111, 0x00000011,
  1034. 0x2f48, 0x73773777, 0x12010001,
  1035. 0x220c, 0x00007fb6, 0x0021a1b1,
  1036. 0x2210, 0x00007fb6, 0x002021b1,
  1037. 0x2180, 0x00007fb6, 0x00002191,
  1038. 0x2218, 0x00007fb6, 0x002121b1,
  1039. 0x221c, 0x00007fb6, 0x002021b1,
  1040. 0x21dc, 0x00007fb6, 0x00002191,
  1041. 0x21e0, 0x00007fb6, 0x00002191,
  1042. 0x3628, 0x0000003f, 0x0000000a,
  1043. 0x362c, 0x0000003f, 0x0000000a,
  1044. 0x2ae4, 0x00073ffe, 0x000022a2,
  1045. 0x240c, 0x000007ff, 0x00000000,
  1046. 0x8a14, 0xf000003f, 0x00000007,
  1047. 0x8bf0, 0x00002001, 0x00000001,
  1048. 0x8b24, 0xffffffff, 0x00ffffff,
  1049. 0x30a04, 0x0000ff0f, 0x00000000,
  1050. 0x28a4c, 0x07ffffff, 0x06000000,
  1051. 0x4d8, 0x00000fff, 0x00000100,
  1052. 0x3e78, 0x00000001, 0x00000002,
  1053. 0x9100, 0x03000000, 0x0362c688,
  1054. 0x8c00, 0x000000ff, 0x00000001,
  1055. 0xe40, 0x00001fff, 0x00001fff,
  1056. 0x9060, 0x0000007f, 0x00000020,
  1057. 0x9508, 0x00010000, 0x00010000,
  1058. 0xac14, 0x000003ff, 0x000000f3,
  1059. 0xac0c, 0xffffffff, 0x00001032
  1060. };
  1061. static const u32 bonaire_mgcg_cgcg_init[] =
  1062. {
  1063. 0xc420, 0xffffffff, 0xfffffffc,
  1064. 0x30800, 0xffffffff, 0xe0000000,
  1065. 0x3c2a0, 0xffffffff, 0x00000100,
  1066. 0x3c208, 0xffffffff, 0x00000100,
  1067. 0x3c2c0, 0xffffffff, 0xc0000100,
  1068. 0x3c2c8, 0xffffffff, 0xc0000100,
  1069. 0x3c2c4, 0xffffffff, 0xc0000100,
  1070. 0x55e4, 0xffffffff, 0x00600100,
  1071. 0x3c280, 0xffffffff, 0x00000100,
  1072. 0x3c214, 0xffffffff, 0x06000100,
  1073. 0x3c220, 0xffffffff, 0x00000100,
  1074. 0x3c218, 0xffffffff, 0x06000100,
  1075. 0x3c204, 0xffffffff, 0x00000100,
  1076. 0x3c2e0, 0xffffffff, 0x00000100,
  1077. 0x3c224, 0xffffffff, 0x00000100,
  1078. 0x3c200, 0xffffffff, 0x00000100,
  1079. 0x3c230, 0xffffffff, 0x00000100,
  1080. 0x3c234, 0xffffffff, 0x00000100,
  1081. 0x3c250, 0xffffffff, 0x00000100,
  1082. 0x3c254, 0xffffffff, 0x00000100,
  1083. 0x3c258, 0xffffffff, 0x00000100,
  1084. 0x3c25c, 0xffffffff, 0x00000100,
  1085. 0x3c260, 0xffffffff, 0x00000100,
  1086. 0x3c27c, 0xffffffff, 0x00000100,
  1087. 0x3c278, 0xffffffff, 0x00000100,
  1088. 0x3c210, 0xffffffff, 0x06000100,
  1089. 0x3c290, 0xffffffff, 0x00000100,
  1090. 0x3c274, 0xffffffff, 0x00000100,
  1091. 0x3c2b4, 0xffffffff, 0x00000100,
  1092. 0x3c2b0, 0xffffffff, 0x00000100,
  1093. 0x3c270, 0xffffffff, 0x00000100,
  1094. 0x30800, 0xffffffff, 0xe0000000,
  1095. 0x3c020, 0xffffffff, 0x00010000,
  1096. 0x3c024, 0xffffffff, 0x00030002,
  1097. 0x3c028, 0xffffffff, 0x00040007,
  1098. 0x3c02c, 0xffffffff, 0x00060005,
  1099. 0x3c030, 0xffffffff, 0x00090008,
  1100. 0x3c034, 0xffffffff, 0x00010000,
  1101. 0x3c038, 0xffffffff, 0x00030002,
  1102. 0x3c03c, 0xffffffff, 0x00040007,
  1103. 0x3c040, 0xffffffff, 0x00060005,
  1104. 0x3c044, 0xffffffff, 0x00090008,
  1105. 0x3c048, 0xffffffff, 0x00010000,
  1106. 0x3c04c, 0xffffffff, 0x00030002,
  1107. 0x3c050, 0xffffffff, 0x00040007,
  1108. 0x3c054, 0xffffffff, 0x00060005,
  1109. 0x3c058, 0xffffffff, 0x00090008,
  1110. 0x3c05c, 0xffffffff, 0x00010000,
  1111. 0x3c060, 0xffffffff, 0x00030002,
  1112. 0x3c064, 0xffffffff, 0x00040007,
  1113. 0x3c068, 0xffffffff, 0x00060005,
  1114. 0x3c06c, 0xffffffff, 0x00090008,
  1115. 0x3c070, 0xffffffff, 0x00010000,
  1116. 0x3c074, 0xffffffff, 0x00030002,
  1117. 0x3c078, 0xffffffff, 0x00040007,
  1118. 0x3c07c, 0xffffffff, 0x00060005,
  1119. 0x3c080, 0xffffffff, 0x00090008,
  1120. 0x3c084, 0xffffffff, 0x00010000,
  1121. 0x3c088, 0xffffffff, 0x00030002,
  1122. 0x3c08c, 0xffffffff, 0x00040007,
  1123. 0x3c090, 0xffffffff, 0x00060005,
  1124. 0x3c094, 0xffffffff, 0x00090008,
  1125. 0x3c098, 0xffffffff, 0x00010000,
  1126. 0x3c09c, 0xffffffff, 0x00030002,
  1127. 0x3c0a0, 0xffffffff, 0x00040007,
  1128. 0x3c0a4, 0xffffffff, 0x00060005,
  1129. 0x3c0a8, 0xffffffff, 0x00090008,
  1130. 0x3c000, 0xffffffff, 0x96e00200,
  1131. 0x8708, 0xffffffff, 0x00900100,
  1132. 0xc424, 0xffffffff, 0x0020003f,
  1133. 0x38, 0xffffffff, 0x0140001c,
  1134. 0x3c, 0x000f0000, 0x000f0000,
  1135. 0x220, 0xffffffff, 0xC060000C,
  1136. 0x224, 0xc0000fff, 0x00000100,
  1137. 0xf90, 0xffffffff, 0x00000100,
  1138. 0xf98, 0x00000101, 0x00000000,
  1139. 0x20a8, 0xffffffff, 0x00000104,
  1140. 0x55e4, 0xff000fff, 0x00000100,
  1141. 0x30cc, 0xc0000fff, 0x00000104,
  1142. 0xc1e4, 0x00000001, 0x00000001,
  1143. 0xd00c, 0xff000ff0, 0x00000100,
  1144. 0xd80c, 0xff000ff0, 0x00000100
  1145. };
  1146. static const u32 spectre_golden_spm_registers[] =
  1147. {
  1148. 0x30800, 0xe0ffffff, 0xe0000000
  1149. };
  1150. static const u32 spectre_golden_common_registers[] =
  1151. {
  1152. 0xc770, 0xffffffff, 0x00000800,
  1153. 0xc774, 0xffffffff, 0x00000800,
  1154. 0xc798, 0xffffffff, 0x00007fbf,
  1155. 0xc79c, 0xffffffff, 0x00007faf
  1156. };
  1157. static const u32 spectre_golden_registers[] =
  1158. {
  1159. 0x3c000, 0xffff1fff, 0x96940200,
  1160. 0x3c00c, 0xffff0001, 0xff000000,
  1161. 0x3c200, 0xfffc0fff, 0x00000100,
  1162. 0x6ed8, 0x00010101, 0x00010000,
  1163. 0x9834, 0xf00fffff, 0x00000400,
  1164. 0x9838, 0xfffffffc, 0x00020200,
  1165. 0x5bb0, 0x000000f0, 0x00000070,
  1166. 0x5bc0, 0xf0311fff, 0x80300000,
  1167. 0x98f8, 0x73773777, 0x12010001,
  1168. 0x9b7c, 0x00ff0000, 0x00fc0000,
  1169. 0x2f48, 0x73773777, 0x12010001,
  1170. 0x8a14, 0xf000003f, 0x00000007,
  1171. 0x8b24, 0xffffffff, 0x00ffffff,
  1172. 0x28350, 0x3f3f3fff, 0x00000082,
  1173. 0x28354, 0x0000003f, 0x00000000,
  1174. 0x3e78, 0x00000001, 0x00000002,
  1175. 0x913c, 0xffff03df, 0x00000004,
  1176. 0xc768, 0x00000008, 0x00000008,
  1177. 0x8c00, 0x000008ff, 0x00000800,
  1178. 0x9508, 0x00010000, 0x00010000,
  1179. 0xac0c, 0xffffffff, 0x54763210,
  1180. 0x214f8, 0x01ff01ff, 0x00000002,
  1181. 0x21498, 0x007ff800, 0x00200000,
  1182. 0x2015c, 0xffffffff, 0x00000f40,
  1183. 0x30934, 0xffffffff, 0x00000001
  1184. };
  1185. static const u32 spectre_mgcg_cgcg_init[] =
  1186. {
  1187. 0xc420, 0xffffffff, 0xfffffffc,
  1188. 0x30800, 0xffffffff, 0xe0000000,
  1189. 0x3c2a0, 0xffffffff, 0x00000100,
  1190. 0x3c208, 0xffffffff, 0x00000100,
  1191. 0x3c2c0, 0xffffffff, 0x00000100,
  1192. 0x3c2c8, 0xffffffff, 0x00000100,
  1193. 0x3c2c4, 0xffffffff, 0x00000100,
  1194. 0x55e4, 0xffffffff, 0x00600100,
  1195. 0x3c280, 0xffffffff, 0x00000100,
  1196. 0x3c214, 0xffffffff, 0x06000100,
  1197. 0x3c220, 0xffffffff, 0x00000100,
  1198. 0x3c218, 0xffffffff, 0x06000100,
  1199. 0x3c204, 0xffffffff, 0x00000100,
  1200. 0x3c2e0, 0xffffffff, 0x00000100,
  1201. 0x3c224, 0xffffffff, 0x00000100,
  1202. 0x3c200, 0xffffffff, 0x00000100,
  1203. 0x3c230, 0xffffffff, 0x00000100,
  1204. 0x3c234, 0xffffffff, 0x00000100,
  1205. 0x3c250, 0xffffffff, 0x00000100,
  1206. 0x3c254, 0xffffffff, 0x00000100,
  1207. 0x3c258, 0xffffffff, 0x00000100,
  1208. 0x3c25c, 0xffffffff, 0x00000100,
  1209. 0x3c260, 0xffffffff, 0x00000100,
  1210. 0x3c27c, 0xffffffff, 0x00000100,
  1211. 0x3c278, 0xffffffff, 0x00000100,
  1212. 0x3c210, 0xffffffff, 0x06000100,
  1213. 0x3c290, 0xffffffff, 0x00000100,
  1214. 0x3c274, 0xffffffff, 0x00000100,
  1215. 0x3c2b4, 0xffffffff, 0x00000100,
  1216. 0x3c2b0, 0xffffffff, 0x00000100,
  1217. 0x3c270, 0xffffffff, 0x00000100,
  1218. 0x30800, 0xffffffff, 0xe0000000,
  1219. 0x3c020, 0xffffffff, 0x00010000,
  1220. 0x3c024, 0xffffffff, 0x00030002,
  1221. 0x3c028, 0xffffffff, 0x00040007,
  1222. 0x3c02c, 0xffffffff, 0x00060005,
  1223. 0x3c030, 0xffffffff, 0x00090008,
  1224. 0x3c034, 0xffffffff, 0x00010000,
  1225. 0x3c038, 0xffffffff, 0x00030002,
  1226. 0x3c03c, 0xffffffff, 0x00040007,
  1227. 0x3c040, 0xffffffff, 0x00060005,
  1228. 0x3c044, 0xffffffff, 0x00090008,
  1229. 0x3c048, 0xffffffff, 0x00010000,
  1230. 0x3c04c, 0xffffffff, 0x00030002,
  1231. 0x3c050, 0xffffffff, 0x00040007,
  1232. 0x3c054, 0xffffffff, 0x00060005,
  1233. 0x3c058, 0xffffffff, 0x00090008,
  1234. 0x3c05c, 0xffffffff, 0x00010000,
  1235. 0x3c060, 0xffffffff, 0x00030002,
  1236. 0x3c064, 0xffffffff, 0x00040007,
  1237. 0x3c068, 0xffffffff, 0x00060005,
  1238. 0x3c06c, 0xffffffff, 0x00090008,
  1239. 0x3c070, 0xffffffff, 0x00010000,
  1240. 0x3c074, 0xffffffff, 0x00030002,
  1241. 0x3c078, 0xffffffff, 0x00040007,
  1242. 0x3c07c, 0xffffffff, 0x00060005,
  1243. 0x3c080, 0xffffffff, 0x00090008,
  1244. 0x3c084, 0xffffffff, 0x00010000,
  1245. 0x3c088, 0xffffffff, 0x00030002,
  1246. 0x3c08c, 0xffffffff, 0x00040007,
  1247. 0x3c090, 0xffffffff, 0x00060005,
  1248. 0x3c094, 0xffffffff, 0x00090008,
  1249. 0x3c098, 0xffffffff, 0x00010000,
  1250. 0x3c09c, 0xffffffff, 0x00030002,
  1251. 0x3c0a0, 0xffffffff, 0x00040007,
  1252. 0x3c0a4, 0xffffffff, 0x00060005,
  1253. 0x3c0a8, 0xffffffff, 0x00090008,
  1254. 0x3c0ac, 0xffffffff, 0x00010000,
  1255. 0x3c0b0, 0xffffffff, 0x00030002,
  1256. 0x3c0b4, 0xffffffff, 0x00040007,
  1257. 0x3c0b8, 0xffffffff, 0x00060005,
  1258. 0x3c0bc, 0xffffffff, 0x00090008,
  1259. 0x3c000, 0xffffffff, 0x96e00200,
  1260. 0x8708, 0xffffffff, 0x00900100,
  1261. 0xc424, 0xffffffff, 0x0020003f,
  1262. 0x38, 0xffffffff, 0x0140001c,
  1263. 0x3c, 0x000f0000, 0x000f0000,
  1264. 0x220, 0xffffffff, 0xC060000C,
  1265. 0x224, 0xc0000fff, 0x00000100,
  1266. 0xf90, 0xffffffff, 0x00000100,
  1267. 0xf98, 0x00000101, 0x00000000,
  1268. 0x20a8, 0xffffffff, 0x00000104,
  1269. 0x55e4, 0xff000fff, 0x00000100,
  1270. 0x30cc, 0xc0000fff, 0x00000104,
  1271. 0xc1e4, 0x00000001, 0x00000001,
  1272. 0xd00c, 0xff000ff0, 0x00000100,
  1273. 0xd80c, 0xff000ff0, 0x00000100
  1274. };
  1275. static const u32 kalindi_golden_spm_registers[] =
  1276. {
  1277. 0x30800, 0xe0ffffff, 0xe0000000
  1278. };
  1279. static const u32 kalindi_golden_common_registers[] =
  1280. {
  1281. 0xc770, 0xffffffff, 0x00000800,
  1282. 0xc774, 0xffffffff, 0x00000800,
  1283. 0xc798, 0xffffffff, 0x00007fbf,
  1284. 0xc79c, 0xffffffff, 0x00007faf
  1285. };
  1286. static const u32 kalindi_golden_registers[] =
  1287. {
  1288. 0x3c000, 0xffffdfff, 0x6e944040,
  1289. 0x55e4, 0xff607fff, 0xfc000100,
  1290. 0x3c220, 0xff000fff, 0x00000100,
  1291. 0x3c224, 0xff000fff, 0x00000100,
  1292. 0x3c200, 0xfffc0fff, 0x00000100,
  1293. 0x6ed8, 0x00010101, 0x00010000,
  1294. 0x9830, 0xffffffff, 0x00000000,
  1295. 0x9834, 0xf00fffff, 0x00000400,
  1296. 0x5bb0, 0x000000f0, 0x00000070,
  1297. 0x5bc0, 0xf0311fff, 0x80300000,
  1298. 0x98f8, 0x73773777, 0x12010001,
  1299. 0x98fc, 0xffffffff, 0x00000010,
  1300. 0x9b7c, 0x00ff0000, 0x00fc0000,
  1301. 0x8030, 0x00001f0f, 0x0000100a,
  1302. 0x2f48, 0x73773777, 0x12010001,
  1303. 0x2408, 0x000fffff, 0x000c007f,
  1304. 0x8a14, 0xf000003f, 0x00000007,
  1305. 0x8b24, 0x3fff3fff, 0x00ffcfff,
  1306. 0x30a04, 0x0000ff0f, 0x00000000,
  1307. 0x28a4c, 0x07ffffff, 0x06000000,
  1308. 0x4d8, 0x00000fff, 0x00000100,
  1309. 0x3e78, 0x00000001, 0x00000002,
  1310. 0xc768, 0x00000008, 0x00000008,
  1311. 0x8c00, 0x000000ff, 0x00000003,
  1312. 0x214f8, 0x01ff01ff, 0x00000002,
  1313. 0x21498, 0x007ff800, 0x00200000,
  1314. 0x2015c, 0xffffffff, 0x00000f40,
  1315. 0x88c4, 0x001f3ae3, 0x00000082,
  1316. 0x88d4, 0x0000001f, 0x00000010,
  1317. 0x30934, 0xffffffff, 0x00000000
  1318. };
  1319. static const u32 kalindi_mgcg_cgcg_init[] =
  1320. {
  1321. 0xc420, 0xffffffff, 0xfffffffc,
  1322. 0x30800, 0xffffffff, 0xe0000000,
  1323. 0x3c2a0, 0xffffffff, 0x00000100,
  1324. 0x3c208, 0xffffffff, 0x00000100,
  1325. 0x3c2c0, 0xffffffff, 0x00000100,
  1326. 0x3c2c8, 0xffffffff, 0x00000100,
  1327. 0x3c2c4, 0xffffffff, 0x00000100,
  1328. 0x55e4, 0xffffffff, 0x00600100,
  1329. 0x3c280, 0xffffffff, 0x00000100,
  1330. 0x3c214, 0xffffffff, 0x06000100,
  1331. 0x3c220, 0xffffffff, 0x00000100,
  1332. 0x3c218, 0xffffffff, 0x06000100,
  1333. 0x3c204, 0xffffffff, 0x00000100,
  1334. 0x3c2e0, 0xffffffff, 0x00000100,
  1335. 0x3c224, 0xffffffff, 0x00000100,
  1336. 0x3c200, 0xffffffff, 0x00000100,
  1337. 0x3c230, 0xffffffff, 0x00000100,
  1338. 0x3c234, 0xffffffff, 0x00000100,
  1339. 0x3c250, 0xffffffff, 0x00000100,
  1340. 0x3c254, 0xffffffff, 0x00000100,
  1341. 0x3c258, 0xffffffff, 0x00000100,
  1342. 0x3c25c, 0xffffffff, 0x00000100,
  1343. 0x3c260, 0xffffffff, 0x00000100,
  1344. 0x3c27c, 0xffffffff, 0x00000100,
  1345. 0x3c278, 0xffffffff, 0x00000100,
  1346. 0x3c210, 0xffffffff, 0x06000100,
  1347. 0x3c290, 0xffffffff, 0x00000100,
  1348. 0x3c274, 0xffffffff, 0x00000100,
  1349. 0x3c2b4, 0xffffffff, 0x00000100,
  1350. 0x3c2b0, 0xffffffff, 0x00000100,
  1351. 0x3c270, 0xffffffff, 0x00000100,
  1352. 0x30800, 0xffffffff, 0xe0000000,
  1353. 0x3c020, 0xffffffff, 0x00010000,
  1354. 0x3c024, 0xffffffff, 0x00030002,
  1355. 0x3c028, 0xffffffff, 0x00040007,
  1356. 0x3c02c, 0xffffffff, 0x00060005,
  1357. 0x3c030, 0xffffffff, 0x00090008,
  1358. 0x3c034, 0xffffffff, 0x00010000,
  1359. 0x3c038, 0xffffffff, 0x00030002,
  1360. 0x3c03c, 0xffffffff, 0x00040007,
  1361. 0x3c040, 0xffffffff, 0x00060005,
  1362. 0x3c044, 0xffffffff, 0x00090008,
  1363. 0x3c000, 0xffffffff, 0x96e00200,
  1364. 0x8708, 0xffffffff, 0x00900100,
  1365. 0xc424, 0xffffffff, 0x0020003f,
  1366. 0x38, 0xffffffff, 0x0140001c,
  1367. 0x3c, 0x000f0000, 0x000f0000,
  1368. 0x220, 0xffffffff, 0xC060000C,
  1369. 0x224, 0xc0000fff, 0x00000100,
  1370. 0x20a8, 0xffffffff, 0x00000104,
  1371. 0x55e4, 0xff000fff, 0x00000100,
  1372. 0x30cc, 0xc0000fff, 0x00000104,
  1373. 0xc1e4, 0x00000001, 0x00000001,
  1374. 0xd00c, 0xff000ff0, 0x00000100,
  1375. 0xd80c, 0xff000ff0, 0x00000100
  1376. };
  1377. static const u32 hawaii_golden_spm_registers[] =
  1378. {
  1379. 0x30800, 0xe0ffffff, 0xe0000000
  1380. };
  1381. static const u32 hawaii_golden_common_registers[] =
  1382. {
  1383. 0x30800, 0xffffffff, 0xe0000000,
  1384. 0x28350, 0xffffffff, 0x3a00161a,
  1385. 0x28354, 0xffffffff, 0x0000002e,
  1386. 0x9a10, 0xffffffff, 0x00018208,
  1387. 0x98f8, 0xffffffff, 0x12011003
  1388. };
  1389. static const u32 hawaii_golden_registers[] =
  1390. {
  1391. 0x3354, 0x00000333, 0x00000333,
  1392. 0x9a10, 0x00010000, 0x00058208,
  1393. 0x9830, 0xffffffff, 0x00000000,
  1394. 0x9834, 0xf00fffff, 0x00000400,
  1395. 0x9838, 0x0002021c, 0x00020200,
  1396. 0xc78, 0x00000080, 0x00000000,
  1397. 0x5bb0, 0x000000f0, 0x00000070,
  1398. 0x5bc0, 0xf0311fff, 0x80300000,
  1399. 0x350c, 0x00810000, 0x408af000,
  1400. 0x7030, 0x31000111, 0x00000011,
  1401. 0x2f48, 0x73773777, 0x12010001,
  1402. 0x2120, 0x0000007f, 0x0000001b,
  1403. 0x21dc, 0x00007fb6, 0x00002191,
  1404. 0x3628, 0x0000003f, 0x0000000a,
  1405. 0x362c, 0x0000003f, 0x0000000a,
  1406. 0x2ae4, 0x00073ffe, 0x000022a2,
  1407. 0x240c, 0x000007ff, 0x00000000,
  1408. 0x8bf0, 0x00002001, 0x00000001,
  1409. 0x8b24, 0xffffffff, 0x00ffffff,
  1410. 0x30a04, 0x0000ff0f, 0x00000000,
  1411. 0x28a4c, 0x07ffffff, 0x06000000,
  1412. 0x3e78, 0x00000001, 0x00000002,
  1413. 0xc768, 0x00000008, 0x00000008,
  1414. 0xc770, 0x00000f00, 0x00000800,
  1415. 0xc774, 0x00000f00, 0x00000800,
  1416. 0xc798, 0x00ffffff, 0x00ff7fbf,
  1417. 0xc79c, 0x00ffffff, 0x00ff7faf,
  1418. 0x8c00, 0x000000ff, 0x00000800,
  1419. 0xe40, 0x00001fff, 0x00001fff,
  1420. 0x9060, 0x0000007f, 0x00000020,
  1421. 0x9508, 0x00010000, 0x00010000,
  1422. 0xae00, 0x00100000, 0x000ff07c,
  1423. 0xac14, 0x000003ff, 0x0000000f,
  1424. 0xac10, 0xffffffff, 0x7564fdec,
  1425. 0xac0c, 0xffffffff, 0x3120b9a8,
  1426. 0xac08, 0x20000000, 0x0f9c0000
  1427. };
  1428. static const u32 hawaii_mgcg_cgcg_init[] =
  1429. {
  1430. 0xc420, 0xffffffff, 0xfffffffd,
  1431. 0x30800, 0xffffffff, 0xe0000000,
  1432. 0x3c2a0, 0xffffffff, 0x00000100,
  1433. 0x3c208, 0xffffffff, 0x00000100,
  1434. 0x3c2c0, 0xffffffff, 0x00000100,
  1435. 0x3c2c8, 0xffffffff, 0x00000100,
  1436. 0x3c2c4, 0xffffffff, 0x00000100,
  1437. 0x55e4, 0xffffffff, 0x00200100,
  1438. 0x3c280, 0xffffffff, 0x00000100,
  1439. 0x3c214, 0xffffffff, 0x06000100,
  1440. 0x3c220, 0xffffffff, 0x00000100,
  1441. 0x3c218, 0xffffffff, 0x06000100,
  1442. 0x3c204, 0xffffffff, 0x00000100,
  1443. 0x3c2e0, 0xffffffff, 0x00000100,
  1444. 0x3c224, 0xffffffff, 0x00000100,
  1445. 0x3c200, 0xffffffff, 0x00000100,
  1446. 0x3c230, 0xffffffff, 0x00000100,
  1447. 0x3c234, 0xffffffff, 0x00000100,
  1448. 0x3c250, 0xffffffff, 0x00000100,
  1449. 0x3c254, 0xffffffff, 0x00000100,
  1450. 0x3c258, 0xffffffff, 0x00000100,
  1451. 0x3c25c, 0xffffffff, 0x00000100,
  1452. 0x3c260, 0xffffffff, 0x00000100,
  1453. 0x3c27c, 0xffffffff, 0x00000100,
  1454. 0x3c278, 0xffffffff, 0x00000100,
  1455. 0x3c210, 0xffffffff, 0x06000100,
  1456. 0x3c290, 0xffffffff, 0x00000100,
  1457. 0x3c274, 0xffffffff, 0x00000100,
  1458. 0x3c2b4, 0xffffffff, 0x00000100,
  1459. 0x3c2b0, 0xffffffff, 0x00000100,
  1460. 0x3c270, 0xffffffff, 0x00000100,
  1461. 0x30800, 0xffffffff, 0xe0000000,
  1462. 0x3c020, 0xffffffff, 0x00010000,
  1463. 0x3c024, 0xffffffff, 0x00030002,
  1464. 0x3c028, 0xffffffff, 0x00040007,
  1465. 0x3c02c, 0xffffffff, 0x00060005,
  1466. 0x3c030, 0xffffffff, 0x00090008,
  1467. 0x3c034, 0xffffffff, 0x00010000,
  1468. 0x3c038, 0xffffffff, 0x00030002,
  1469. 0x3c03c, 0xffffffff, 0x00040007,
  1470. 0x3c040, 0xffffffff, 0x00060005,
  1471. 0x3c044, 0xffffffff, 0x00090008,
  1472. 0x3c048, 0xffffffff, 0x00010000,
  1473. 0x3c04c, 0xffffffff, 0x00030002,
  1474. 0x3c050, 0xffffffff, 0x00040007,
  1475. 0x3c054, 0xffffffff, 0x00060005,
  1476. 0x3c058, 0xffffffff, 0x00090008,
  1477. 0x3c05c, 0xffffffff, 0x00010000,
  1478. 0x3c060, 0xffffffff, 0x00030002,
  1479. 0x3c064, 0xffffffff, 0x00040007,
  1480. 0x3c068, 0xffffffff, 0x00060005,
  1481. 0x3c06c, 0xffffffff, 0x00090008,
  1482. 0x3c070, 0xffffffff, 0x00010000,
  1483. 0x3c074, 0xffffffff, 0x00030002,
  1484. 0x3c078, 0xffffffff, 0x00040007,
  1485. 0x3c07c, 0xffffffff, 0x00060005,
  1486. 0x3c080, 0xffffffff, 0x00090008,
  1487. 0x3c084, 0xffffffff, 0x00010000,
  1488. 0x3c088, 0xffffffff, 0x00030002,
  1489. 0x3c08c, 0xffffffff, 0x00040007,
  1490. 0x3c090, 0xffffffff, 0x00060005,
  1491. 0x3c094, 0xffffffff, 0x00090008,
  1492. 0x3c098, 0xffffffff, 0x00010000,
  1493. 0x3c09c, 0xffffffff, 0x00030002,
  1494. 0x3c0a0, 0xffffffff, 0x00040007,
  1495. 0x3c0a4, 0xffffffff, 0x00060005,
  1496. 0x3c0a8, 0xffffffff, 0x00090008,
  1497. 0x3c0ac, 0xffffffff, 0x00010000,
  1498. 0x3c0b0, 0xffffffff, 0x00030002,
  1499. 0x3c0b4, 0xffffffff, 0x00040007,
  1500. 0x3c0b8, 0xffffffff, 0x00060005,
  1501. 0x3c0bc, 0xffffffff, 0x00090008,
  1502. 0x3c0c0, 0xffffffff, 0x00010000,
  1503. 0x3c0c4, 0xffffffff, 0x00030002,
  1504. 0x3c0c8, 0xffffffff, 0x00040007,
  1505. 0x3c0cc, 0xffffffff, 0x00060005,
  1506. 0x3c0d0, 0xffffffff, 0x00090008,
  1507. 0x3c0d4, 0xffffffff, 0x00010000,
  1508. 0x3c0d8, 0xffffffff, 0x00030002,
  1509. 0x3c0dc, 0xffffffff, 0x00040007,
  1510. 0x3c0e0, 0xffffffff, 0x00060005,
  1511. 0x3c0e4, 0xffffffff, 0x00090008,
  1512. 0x3c0e8, 0xffffffff, 0x00010000,
  1513. 0x3c0ec, 0xffffffff, 0x00030002,
  1514. 0x3c0f0, 0xffffffff, 0x00040007,
  1515. 0x3c0f4, 0xffffffff, 0x00060005,
  1516. 0x3c0f8, 0xffffffff, 0x00090008,
  1517. 0xc318, 0xffffffff, 0x00020200,
  1518. 0x3350, 0xffffffff, 0x00000200,
  1519. 0x15c0, 0xffffffff, 0x00000400,
  1520. 0x55e8, 0xffffffff, 0x00000000,
  1521. 0x2f50, 0xffffffff, 0x00000902,
  1522. 0x3c000, 0xffffffff, 0x96940200,
  1523. 0x8708, 0xffffffff, 0x00900100,
  1524. 0xc424, 0xffffffff, 0x0020003f,
  1525. 0x38, 0xffffffff, 0x0140001c,
  1526. 0x3c, 0x000f0000, 0x000f0000,
  1527. 0x220, 0xffffffff, 0xc060000c,
  1528. 0x224, 0xc0000fff, 0x00000100,
  1529. 0xf90, 0xffffffff, 0x00000100,
  1530. 0xf98, 0x00000101, 0x00000000,
  1531. 0x20a8, 0xffffffff, 0x00000104,
  1532. 0x55e4, 0xff000fff, 0x00000100,
  1533. 0x30cc, 0xc0000fff, 0x00000104,
  1534. 0xc1e4, 0x00000001, 0x00000001,
  1535. 0xd00c, 0xff000ff0, 0x00000100,
  1536. 0xd80c, 0xff000ff0, 0x00000100
  1537. };
  1538. static const u32 godavari_golden_registers[] =
  1539. {
  1540. 0x55e4, 0xff607fff, 0xfc000100,
  1541. 0x6ed8, 0x00010101, 0x00010000,
  1542. 0x9830, 0xffffffff, 0x00000000,
  1543. 0x98302, 0xf00fffff, 0x00000400,
  1544. 0x6130, 0xffffffff, 0x00010000,
  1545. 0x5bb0, 0x000000f0, 0x00000070,
  1546. 0x5bc0, 0xf0311fff, 0x80300000,
  1547. 0x98f8, 0x73773777, 0x12010001,
  1548. 0x98fc, 0xffffffff, 0x00000010,
  1549. 0x8030, 0x00001f0f, 0x0000100a,
  1550. 0x2f48, 0x73773777, 0x12010001,
  1551. 0x2408, 0x000fffff, 0x000c007f,
  1552. 0x8a14, 0xf000003f, 0x00000007,
  1553. 0x8b24, 0xffffffff, 0x00ff0fff,
  1554. 0x30a04, 0x0000ff0f, 0x00000000,
  1555. 0x28a4c, 0x07ffffff, 0x06000000,
  1556. 0x4d8, 0x00000fff, 0x00000100,
  1557. 0xd014, 0x00010000, 0x00810001,
  1558. 0xd814, 0x00010000, 0x00810001,
  1559. 0x3e78, 0x00000001, 0x00000002,
  1560. 0xc768, 0x00000008, 0x00000008,
  1561. 0xc770, 0x00000f00, 0x00000800,
  1562. 0xc774, 0x00000f00, 0x00000800,
  1563. 0xc798, 0x00ffffff, 0x00ff7fbf,
  1564. 0xc79c, 0x00ffffff, 0x00ff7faf,
  1565. 0x8c00, 0x000000ff, 0x00000001,
  1566. 0x214f8, 0x01ff01ff, 0x00000002,
  1567. 0x21498, 0x007ff800, 0x00200000,
  1568. 0x2015c, 0xffffffff, 0x00000f40,
  1569. 0x88c4, 0x001f3ae3, 0x00000082,
  1570. 0x88d4, 0x0000001f, 0x00000010,
  1571. 0x30934, 0xffffffff, 0x00000000
  1572. };
  1573. static void cik_init_golden_registers(struct radeon_device *rdev)
  1574. {
  1575. /* Some of the registers might be dependent on GRBM_GFX_INDEX */
  1576. mutex_lock(&rdev->grbm_idx_mutex);
  1577. switch (rdev->family) {
  1578. case CHIP_BONAIRE:
  1579. radeon_program_register_sequence(rdev,
  1580. bonaire_mgcg_cgcg_init,
  1581. (const u32)ARRAY_SIZE(bonaire_mgcg_cgcg_init));
  1582. radeon_program_register_sequence(rdev,
  1583. bonaire_golden_registers,
  1584. (const u32)ARRAY_SIZE(bonaire_golden_registers));
  1585. radeon_program_register_sequence(rdev,
  1586. bonaire_golden_common_registers,
  1587. (const u32)ARRAY_SIZE(bonaire_golden_common_registers));
  1588. radeon_program_register_sequence(rdev,
  1589. bonaire_golden_spm_registers,
  1590. (const u32)ARRAY_SIZE(bonaire_golden_spm_registers));
  1591. break;
  1592. case CHIP_KABINI:
  1593. radeon_program_register_sequence(rdev,
  1594. kalindi_mgcg_cgcg_init,
  1595. (const u32)ARRAY_SIZE(kalindi_mgcg_cgcg_init));
  1596. radeon_program_register_sequence(rdev,
  1597. kalindi_golden_registers,
  1598. (const u32)ARRAY_SIZE(kalindi_golden_registers));
  1599. radeon_program_register_sequence(rdev,
  1600. kalindi_golden_common_registers,
  1601. (const u32)ARRAY_SIZE(kalindi_golden_common_registers));
  1602. radeon_program_register_sequence(rdev,
  1603. kalindi_golden_spm_registers,
  1604. (const u32)ARRAY_SIZE(kalindi_golden_spm_registers));
  1605. break;
  1606. case CHIP_MULLINS:
  1607. radeon_program_register_sequence(rdev,
  1608. kalindi_mgcg_cgcg_init,
  1609. (const u32)ARRAY_SIZE(kalindi_mgcg_cgcg_init));
  1610. radeon_program_register_sequence(rdev,
  1611. godavari_golden_registers,
  1612. (const u32)ARRAY_SIZE(godavari_golden_registers));
  1613. radeon_program_register_sequence(rdev,
  1614. kalindi_golden_common_registers,
  1615. (const u32)ARRAY_SIZE(kalindi_golden_common_registers));
  1616. radeon_program_register_sequence(rdev,
  1617. kalindi_golden_spm_registers,
  1618. (const u32)ARRAY_SIZE(kalindi_golden_spm_registers));
  1619. break;
  1620. case CHIP_KAVERI:
  1621. radeon_program_register_sequence(rdev,
  1622. spectre_mgcg_cgcg_init,
  1623. (const u32)ARRAY_SIZE(spectre_mgcg_cgcg_init));
  1624. radeon_program_register_sequence(rdev,
  1625. spectre_golden_registers,
  1626. (const u32)ARRAY_SIZE(spectre_golden_registers));
  1627. radeon_program_register_sequence(rdev,
  1628. spectre_golden_common_registers,
  1629. (const u32)ARRAY_SIZE(spectre_golden_common_registers));
  1630. radeon_program_register_sequence(rdev,
  1631. spectre_golden_spm_registers,
  1632. (const u32)ARRAY_SIZE(spectre_golden_spm_registers));
  1633. break;
  1634. case CHIP_HAWAII:
  1635. radeon_program_register_sequence(rdev,
  1636. hawaii_mgcg_cgcg_init,
  1637. (const u32)ARRAY_SIZE(hawaii_mgcg_cgcg_init));
  1638. radeon_program_register_sequence(rdev,
  1639. hawaii_golden_registers,
  1640. (const u32)ARRAY_SIZE(hawaii_golden_registers));
  1641. radeon_program_register_sequence(rdev,
  1642. hawaii_golden_common_registers,
  1643. (const u32)ARRAY_SIZE(hawaii_golden_common_registers));
  1644. radeon_program_register_sequence(rdev,
  1645. hawaii_golden_spm_registers,
  1646. (const u32)ARRAY_SIZE(hawaii_golden_spm_registers));
  1647. break;
  1648. default:
  1649. break;
  1650. }
  1651. mutex_unlock(&rdev->grbm_idx_mutex);
  1652. }
  1653. /**
  1654. * cik_get_xclk - get the xclk
  1655. *
  1656. * @rdev: radeon_device pointer
  1657. *
  1658. * Returns the reference clock used by the gfx engine
  1659. * (CIK).
  1660. */
  1661. u32 cik_get_xclk(struct radeon_device *rdev)
  1662. {
  1663. u32 reference_clock = rdev->clock.spll.reference_freq;
  1664. if (rdev->flags & RADEON_IS_IGP) {
  1665. if (RREG32_SMC(GENERAL_PWRMGT) & GPU_COUNTER_CLK)
  1666. return reference_clock / 2;
  1667. } else {
  1668. if (RREG32_SMC(CG_CLKPIN_CNTL) & XTALIN_DIVIDE)
  1669. return reference_clock / 4;
  1670. }
  1671. return reference_clock;
  1672. }
  1673. /**
  1674. * cik_mm_rdoorbell - read a doorbell dword
  1675. *
  1676. * @rdev: radeon_device pointer
  1677. * @index: doorbell index
  1678. *
  1679. * Returns the value in the doorbell aperture at the
  1680. * requested doorbell index (CIK).
  1681. */
  1682. u32 cik_mm_rdoorbell(struct radeon_device *rdev, u32 index)
  1683. {
  1684. if (index < rdev->doorbell.num_doorbells) {
  1685. return readl(rdev->doorbell.ptr + index);
  1686. } else {
  1687. DRM_ERROR("reading beyond doorbell aperture: 0x%08x!\n", index);
  1688. return 0;
  1689. }
  1690. }
  1691. /**
  1692. * cik_mm_wdoorbell - write a doorbell dword
  1693. *
  1694. * @rdev: radeon_device pointer
  1695. * @index: doorbell index
  1696. * @v: value to write
  1697. *
  1698. * Writes @v to the doorbell aperture at the
  1699. * requested doorbell index (CIK).
  1700. */
  1701. void cik_mm_wdoorbell(struct radeon_device *rdev, u32 index, u32 v)
  1702. {
  1703. if (index < rdev->doorbell.num_doorbells) {
  1704. writel(v, rdev->doorbell.ptr + index);
  1705. } else {
  1706. DRM_ERROR("writing beyond doorbell aperture: 0x%08x!\n", index);
  1707. }
  1708. }
  1709. #define BONAIRE_IO_MC_REGS_SIZE 36
  1710. static const u32 bonaire_io_mc_regs[BONAIRE_IO_MC_REGS_SIZE][2] =
  1711. {
  1712. {0x00000070, 0x04400000},
  1713. {0x00000071, 0x80c01803},
  1714. {0x00000072, 0x00004004},
  1715. {0x00000073, 0x00000100},
  1716. {0x00000074, 0x00ff0000},
  1717. {0x00000075, 0x34000000},
  1718. {0x00000076, 0x08000014},
  1719. {0x00000077, 0x00cc08ec},
  1720. {0x00000078, 0x00000400},
  1721. {0x00000079, 0x00000000},
  1722. {0x0000007a, 0x04090000},
  1723. {0x0000007c, 0x00000000},
  1724. {0x0000007e, 0x4408a8e8},
  1725. {0x0000007f, 0x00000304},
  1726. {0x00000080, 0x00000000},
  1727. {0x00000082, 0x00000001},
  1728. {0x00000083, 0x00000002},
  1729. {0x00000084, 0xf3e4f400},
  1730. {0x00000085, 0x052024e3},
  1731. {0x00000087, 0x00000000},
  1732. {0x00000088, 0x01000000},
  1733. {0x0000008a, 0x1c0a0000},
  1734. {0x0000008b, 0xff010000},
  1735. {0x0000008d, 0xffffefff},
  1736. {0x0000008e, 0xfff3efff},
  1737. {0x0000008f, 0xfff3efbf},
  1738. {0x00000092, 0xf7ffffff},
  1739. {0x00000093, 0xffffff7f},
  1740. {0x00000095, 0x00101101},
  1741. {0x00000096, 0x00000fff},
  1742. {0x00000097, 0x00116fff},
  1743. {0x00000098, 0x60010000},
  1744. {0x00000099, 0x10010000},
  1745. {0x0000009a, 0x00006000},
  1746. {0x0000009b, 0x00001000},
  1747. {0x0000009f, 0x00b48000}
  1748. };
  1749. #define HAWAII_IO_MC_REGS_SIZE 22
  1750. static const u32 hawaii_io_mc_regs[HAWAII_IO_MC_REGS_SIZE][2] =
  1751. {
  1752. {0x0000007d, 0x40000000},
  1753. {0x0000007e, 0x40180304},
  1754. {0x0000007f, 0x0000ff00},
  1755. {0x00000081, 0x00000000},
  1756. {0x00000083, 0x00000800},
  1757. {0x00000086, 0x00000000},
  1758. {0x00000087, 0x00000100},
  1759. {0x00000088, 0x00020100},
  1760. {0x00000089, 0x00000000},
  1761. {0x0000008b, 0x00040000},
  1762. {0x0000008c, 0x00000100},
  1763. {0x0000008e, 0xff010000},
  1764. {0x00000090, 0xffffefff},
  1765. {0x00000091, 0xfff3efff},
  1766. {0x00000092, 0xfff3efbf},
  1767. {0x00000093, 0xf7ffffff},
  1768. {0x00000094, 0xffffff7f},
  1769. {0x00000095, 0x00000fff},
  1770. {0x00000096, 0x00116fff},
  1771. {0x00000097, 0x60010000},
  1772. {0x00000098, 0x10010000},
  1773. {0x0000009f, 0x00c79000}
  1774. };
  1775. /**
  1776. * cik_srbm_select - select specific register instances
  1777. *
  1778. * @rdev: radeon_device pointer
  1779. * @me: selected ME (micro engine)
  1780. * @pipe: pipe
  1781. * @queue: queue
  1782. * @vmid: VMID
  1783. *
  1784. * Switches the currently active registers instances. Some
  1785. * registers are instanced per VMID, others are instanced per
  1786. * me/pipe/queue combination.
  1787. */
  1788. static void cik_srbm_select(struct radeon_device *rdev,
  1789. u32 me, u32 pipe, u32 queue, u32 vmid)
  1790. {
  1791. u32 srbm_gfx_cntl = (PIPEID(pipe & 0x3) |
  1792. MEID(me & 0x3) |
  1793. VMID(vmid & 0xf) |
  1794. QUEUEID(queue & 0x7));
  1795. WREG32(SRBM_GFX_CNTL, srbm_gfx_cntl);
  1796. }
  1797. /* ucode loading */
  1798. /**
  1799. * ci_mc_load_microcode - load MC ucode into the hw
  1800. *
  1801. * @rdev: radeon_device pointer
  1802. *
  1803. * Load the GDDR MC ucode into the hw (CIK).
  1804. * Returns 0 on success, error on failure.
  1805. */
  1806. int ci_mc_load_microcode(struct radeon_device *rdev)
  1807. {
  1808. const __be32 *fw_data = NULL;
  1809. const __le32 *new_fw_data = NULL;
  1810. u32 running, blackout = 0, tmp;
  1811. u32 *io_mc_regs = NULL;
  1812. const __le32 *new_io_mc_regs = NULL;
  1813. int i, regs_size, ucode_size;
  1814. if (!rdev->mc_fw)
  1815. return -EINVAL;
  1816. if (rdev->new_fw) {
  1817. const struct mc_firmware_header_v1_0 *hdr =
  1818. (const struct mc_firmware_header_v1_0 *)rdev->mc_fw->data;
  1819. radeon_ucode_print_mc_hdr(&hdr->header);
  1820. regs_size = le32_to_cpu(hdr->io_debug_size_bytes) / (4 * 2);
  1821. new_io_mc_regs = (const __le32 *)
  1822. (rdev->mc_fw->data + le32_to_cpu(hdr->io_debug_array_offset_bytes));
  1823. ucode_size = le32_to_cpu(hdr->header.ucode_size_bytes) / 4;
  1824. new_fw_data = (const __le32 *)
  1825. (rdev->mc_fw->data + le32_to_cpu(hdr->header.ucode_array_offset_bytes));
  1826. } else {
  1827. ucode_size = rdev->mc_fw->size / 4;
  1828. switch (rdev->family) {
  1829. case CHIP_BONAIRE:
  1830. io_mc_regs = (u32 *)&bonaire_io_mc_regs;
  1831. regs_size = BONAIRE_IO_MC_REGS_SIZE;
  1832. break;
  1833. case CHIP_HAWAII:
  1834. io_mc_regs = (u32 *)&hawaii_io_mc_regs;
  1835. regs_size = HAWAII_IO_MC_REGS_SIZE;
  1836. break;
  1837. default:
  1838. return -EINVAL;
  1839. }
  1840. fw_data = (const __be32 *)rdev->mc_fw->data;
  1841. }
  1842. running = RREG32(MC_SEQ_SUP_CNTL) & RUN_MASK;
  1843. if (running == 0) {
  1844. if (running) {
  1845. blackout = RREG32(MC_SHARED_BLACKOUT_CNTL);
  1846. WREG32(MC_SHARED_BLACKOUT_CNTL, blackout | 1);
  1847. }
  1848. /* reset the engine and set to writable */
  1849. WREG32(MC_SEQ_SUP_CNTL, 0x00000008);
  1850. WREG32(MC_SEQ_SUP_CNTL, 0x00000010);
  1851. /* load mc io regs */
  1852. for (i = 0; i < regs_size; i++) {
  1853. if (rdev->new_fw) {
  1854. WREG32(MC_SEQ_IO_DEBUG_INDEX, le32_to_cpup(new_io_mc_regs++));
  1855. WREG32(MC_SEQ_IO_DEBUG_DATA, le32_to_cpup(new_io_mc_regs++));
  1856. } else {
  1857. WREG32(MC_SEQ_IO_DEBUG_INDEX, io_mc_regs[(i << 1)]);
  1858. WREG32(MC_SEQ_IO_DEBUG_DATA, io_mc_regs[(i << 1) + 1]);
  1859. }
  1860. }
  1861. tmp = RREG32(MC_SEQ_MISC0);
  1862. if ((rdev->pdev->device == 0x6649) && ((tmp & 0xff00) == 0x5600)) {
  1863. WREG32(MC_SEQ_IO_DEBUG_INDEX, 5);
  1864. WREG32(MC_SEQ_IO_DEBUG_DATA, 0x00000023);
  1865. WREG32(MC_SEQ_IO_DEBUG_INDEX, 9);
  1866. WREG32(MC_SEQ_IO_DEBUG_DATA, 0x000001f0);
  1867. }
  1868. /* load the MC ucode */
  1869. for (i = 0; i < ucode_size; i++) {
  1870. if (rdev->new_fw)
  1871. WREG32(MC_SEQ_SUP_PGM, le32_to_cpup(new_fw_data++));
  1872. else
  1873. WREG32(MC_SEQ_SUP_PGM, be32_to_cpup(fw_data++));
  1874. }
  1875. /* put the engine back into the active state */
  1876. WREG32(MC_SEQ_SUP_CNTL, 0x00000008);
  1877. WREG32(MC_SEQ_SUP_CNTL, 0x00000004);
  1878. WREG32(MC_SEQ_SUP_CNTL, 0x00000001);
  1879. /* wait for training to complete */
  1880. for (i = 0; i < rdev->usec_timeout; i++) {
  1881. if (RREG32(MC_SEQ_TRAIN_WAKEUP_CNTL) & TRAIN_DONE_D0)
  1882. break;
  1883. udelay(1);
  1884. }
  1885. for (i = 0; i < rdev->usec_timeout; i++) {
  1886. if (RREG32(MC_SEQ_TRAIN_WAKEUP_CNTL) & TRAIN_DONE_D1)
  1887. break;
  1888. udelay(1);
  1889. }
  1890. if (running)
  1891. WREG32(MC_SHARED_BLACKOUT_CNTL, blackout);
  1892. }
  1893. return 0;
  1894. }
  1895. /**
  1896. * cik_init_microcode - load ucode images from disk
  1897. *
  1898. * @rdev: radeon_device pointer
  1899. *
  1900. * Use the firmware interface to load the ucode images into
  1901. * the driver (not loaded into hw).
  1902. * Returns 0 on success, error on failure.
  1903. */
  1904. static int cik_init_microcode(struct radeon_device *rdev)
  1905. {
  1906. const char *chip_name;
  1907. const char *new_chip_name;
  1908. size_t pfp_req_size, me_req_size, ce_req_size,
  1909. mec_req_size, rlc_req_size, mc_req_size = 0,
  1910. sdma_req_size, smc_req_size = 0, mc2_req_size = 0;
  1911. char fw_name[30];
  1912. int new_fw = 0;
  1913. int err;
  1914. int num_fw;
  1915. DRM_DEBUG("\n");
  1916. switch (rdev->family) {
  1917. case CHIP_BONAIRE:
  1918. chip_name = "BONAIRE";
  1919. new_chip_name = "bonaire";
  1920. pfp_req_size = CIK_PFP_UCODE_SIZE * 4;
  1921. me_req_size = CIK_ME_UCODE_SIZE * 4;
  1922. ce_req_size = CIK_CE_UCODE_SIZE * 4;
  1923. mec_req_size = CIK_MEC_UCODE_SIZE * 4;
  1924. rlc_req_size = BONAIRE_RLC_UCODE_SIZE * 4;
  1925. mc_req_size = BONAIRE_MC_UCODE_SIZE * 4;
  1926. mc2_req_size = BONAIRE_MC2_UCODE_SIZE * 4;
  1927. sdma_req_size = CIK_SDMA_UCODE_SIZE * 4;
  1928. smc_req_size = ALIGN(BONAIRE_SMC_UCODE_SIZE, 4);
  1929. num_fw = 8;
  1930. break;
  1931. case CHIP_HAWAII:
  1932. chip_name = "HAWAII";
  1933. new_chip_name = "hawaii";
  1934. pfp_req_size = CIK_PFP_UCODE_SIZE * 4;
  1935. me_req_size = CIK_ME_UCODE_SIZE * 4;
  1936. ce_req_size = CIK_CE_UCODE_SIZE * 4;
  1937. mec_req_size = CIK_MEC_UCODE_SIZE * 4;
  1938. rlc_req_size = BONAIRE_RLC_UCODE_SIZE * 4;
  1939. mc_req_size = HAWAII_MC_UCODE_SIZE * 4;
  1940. mc2_req_size = HAWAII_MC2_UCODE_SIZE * 4;
  1941. sdma_req_size = CIK_SDMA_UCODE_SIZE * 4;
  1942. smc_req_size = ALIGN(HAWAII_SMC_UCODE_SIZE, 4);
  1943. num_fw = 8;
  1944. break;
  1945. case CHIP_KAVERI:
  1946. chip_name = "KAVERI";
  1947. new_chip_name = "kaveri";
  1948. pfp_req_size = CIK_PFP_UCODE_SIZE * 4;
  1949. me_req_size = CIK_ME_UCODE_SIZE * 4;
  1950. ce_req_size = CIK_CE_UCODE_SIZE * 4;
  1951. mec_req_size = CIK_MEC_UCODE_SIZE * 4;
  1952. rlc_req_size = KV_RLC_UCODE_SIZE * 4;
  1953. sdma_req_size = CIK_SDMA_UCODE_SIZE * 4;
  1954. num_fw = 7;
  1955. break;
  1956. case CHIP_KABINI:
  1957. chip_name = "KABINI";
  1958. new_chip_name = "kabini";
  1959. pfp_req_size = CIK_PFP_UCODE_SIZE * 4;
  1960. me_req_size = CIK_ME_UCODE_SIZE * 4;
  1961. ce_req_size = CIK_CE_UCODE_SIZE * 4;
  1962. mec_req_size = CIK_MEC_UCODE_SIZE * 4;
  1963. rlc_req_size = KB_RLC_UCODE_SIZE * 4;
  1964. sdma_req_size = CIK_SDMA_UCODE_SIZE * 4;
  1965. num_fw = 6;
  1966. break;
  1967. case CHIP_MULLINS:
  1968. chip_name = "MULLINS";
  1969. new_chip_name = "mullins";
  1970. pfp_req_size = CIK_PFP_UCODE_SIZE * 4;
  1971. me_req_size = CIK_ME_UCODE_SIZE * 4;
  1972. ce_req_size = CIK_CE_UCODE_SIZE * 4;
  1973. mec_req_size = CIK_MEC_UCODE_SIZE * 4;
  1974. rlc_req_size = ML_RLC_UCODE_SIZE * 4;
  1975. sdma_req_size = CIK_SDMA_UCODE_SIZE * 4;
  1976. num_fw = 6;
  1977. break;
  1978. default: BUG();
  1979. }
  1980. DRM_INFO("Loading %s Microcode\n", new_chip_name);
  1981. snprintf(fw_name, sizeof(fw_name), "radeon/%s_pfp.bin", new_chip_name);
  1982. err = request_firmware(&rdev->pfp_fw, fw_name, rdev->dev);
  1983. if (err) {
  1984. snprintf(fw_name, sizeof(fw_name), "radeon/%s_pfp.bin", chip_name);
  1985. err = request_firmware(&rdev->pfp_fw, fw_name, rdev->dev);
  1986. if (err)
  1987. goto out;
  1988. if (rdev->pfp_fw->size != pfp_req_size) {
  1989. printk(KERN_ERR
  1990. "cik_cp: Bogus length %zu in firmware \"%s\"\n",
  1991. rdev->pfp_fw->size, fw_name);
  1992. err = -EINVAL;
  1993. goto out;
  1994. }
  1995. } else {
  1996. err = radeon_ucode_validate(rdev->pfp_fw);
  1997. if (err) {
  1998. printk(KERN_ERR
  1999. "cik_fw: validation failed for firmware \"%s\"\n",
  2000. fw_name);
  2001. goto out;
  2002. } else {
  2003. new_fw++;
  2004. }
  2005. }
  2006. snprintf(fw_name, sizeof(fw_name), "radeon/%s_me.bin", new_chip_name);
  2007. err = request_firmware(&rdev->me_fw, fw_name, rdev->dev);
  2008. if (err) {
  2009. snprintf(fw_name, sizeof(fw_name), "radeon/%s_me.bin", chip_name);
  2010. err = request_firmware(&rdev->me_fw, fw_name, rdev->dev);
  2011. if (err)
  2012. goto out;
  2013. if (rdev->me_fw->size != me_req_size) {
  2014. printk(KERN_ERR
  2015. "cik_cp: Bogus length %zu in firmware \"%s\"\n",
  2016. rdev->me_fw->size, fw_name);
  2017. err = -EINVAL;
  2018. }
  2019. } else {
  2020. err = radeon_ucode_validate(rdev->me_fw);
  2021. if (err) {
  2022. printk(KERN_ERR
  2023. "cik_fw: validation failed for firmware \"%s\"\n",
  2024. fw_name);
  2025. goto out;
  2026. } else {
  2027. new_fw++;
  2028. }
  2029. }
  2030. snprintf(fw_name, sizeof(fw_name), "radeon/%s_ce.bin", new_chip_name);
  2031. err = request_firmware(&rdev->ce_fw, fw_name, rdev->dev);
  2032. if (err) {
  2033. snprintf(fw_name, sizeof(fw_name), "radeon/%s_ce.bin", chip_name);
  2034. err = request_firmware(&rdev->ce_fw, fw_name, rdev->dev);
  2035. if (err)
  2036. goto out;
  2037. if (rdev->ce_fw->size != ce_req_size) {
  2038. printk(KERN_ERR
  2039. "cik_cp: Bogus length %zu in firmware \"%s\"\n",
  2040. rdev->ce_fw->size, fw_name);
  2041. err = -EINVAL;
  2042. }
  2043. } else {
  2044. err = radeon_ucode_validate(rdev->ce_fw);
  2045. if (err) {
  2046. printk(KERN_ERR
  2047. "cik_fw: validation failed for firmware \"%s\"\n",
  2048. fw_name);
  2049. goto out;
  2050. } else {
  2051. new_fw++;
  2052. }
  2053. }
  2054. snprintf(fw_name, sizeof(fw_name), "radeon/%s_mec.bin", new_chip_name);
  2055. err = request_firmware(&rdev->mec_fw, fw_name, rdev->dev);
  2056. if (err) {
  2057. snprintf(fw_name, sizeof(fw_name), "radeon/%s_mec.bin", chip_name);
  2058. err = request_firmware(&rdev->mec_fw, fw_name, rdev->dev);
  2059. if (err)
  2060. goto out;
  2061. if (rdev->mec_fw->size != mec_req_size) {
  2062. printk(KERN_ERR
  2063. "cik_cp: Bogus length %zu in firmware \"%s\"\n",
  2064. rdev->mec_fw->size, fw_name);
  2065. err = -EINVAL;
  2066. }
  2067. } else {
  2068. err = radeon_ucode_validate(rdev->mec_fw);
  2069. if (err) {
  2070. printk(KERN_ERR
  2071. "cik_fw: validation failed for firmware \"%s\"\n",
  2072. fw_name);
  2073. goto out;
  2074. } else {
  2075. new_fw++;
  2076. }
  2077. }
  2078. if (rdev->family == CHIP_KAVERI) {
  2079. snprintf(fw_name, sizeof(fw_name), "radeon/%s_mec2.bin", new_chip_name);
  2080. err = request_firmware(&rdev->mec2_fw, fw_name, rdev->dev);
  2081. if (err) {
  2082. goto out;
  2083. } else {
  2084. err = radeon_ucode_validate(rdev->mec2_fw);
  2085. if (err) {
  2086. goto out;
  2087. } else {
  2088. new_fw++;
  2089. }
  2090. }
  2091. }
  2092. snprintf(fw_name, sizeof(fw_name), "radeon/%s_rlc.bin", new_chip_name);
  2093. err = request_firmware(&rdev->rlc_fw, fw_name, rdev->dev);
  2094. if (err) {
  2095. snprintf(fw_name, sizeof(fw_name), "radeon/%s_rlc.bin", chip_name);
  2096. err = request_firmware(&rdev->rlc_fw, fw_name, rdev->dev);
  2097. if (err)
  2098. goto out;
  2099. if (rdev->rlc_fw->size != rlc_req_size) {
  2100. printk(KERN_ERR
  2101. "cik_rlc: Bogus length %zu in firmware \"%s\"\n",
  2102. rdev->rlc_fw->size, fw_name);
  2103. err = -EINVAL;
  2104. }
  2105. } else {
  2106. err = radeon_ucode_validate(rdev->rlc_fw);
  2107. if (err) {
  2108. printk(KERN_ERR
  2109. "cik_fw: validation failed for firmware \"%s\"\n",
  2110. fw_name);
  2111. goto out;
  2112. } else {
  2113. new_fw++;
  2114. }
  2115. }
  2116. snprintf(fw_name, sizeof(fw_name), "radeon/%s_sdma.bin", new_chip_name);
  2117. err = request_firmware(&rdev->sdma_fw, fw_name, rdev->dev);
  2118. if (err) {
  2119. snprintf(fw_name, sizeof(fw_name), "radeon/%s_sdma.bin", chip_name);
  2120. err = request_firmware(&rdev->sdma_fw, fw_name, rdev->dev);
  2121. if (err)
  2122. goto out;
  2123. if (rdev->sdma_fw->size != sdma_req_size) {
  2124. printk(KERN_ERR
  2125. "cik_sdma: Bogus length %zu in firmware \"%s\"\n",
  2126. rdev->sdma_fw->size, fw_name);
  2127. err = -EINVAL;
  2128. }
  2129. } else {
  2130. err = radeon_ucode_validate(rdev->sdma_fw);
  2131. if (err) {
  2132. printk(KERN_ERR
  2133. "cik_fw: validation failed for firmware \"%s\"\n",
  2134. fw_name);
  2135. goto out;
  2136. } else {
  2137. new_fw++;
  2138. }
  2139. }
  2140. /* No SMC, MC ucode on APUs */
  2141. if (!(rdev->flags & RADEON_IS_IGP)) {
  2142. snprintf(fw_name, sizeof(fw_name), "radeon/%s_mc.bin", new_chip_name);
  2143. err = request_firmware(&rdev->mc_fw, fw_name, rdev->dev);
  2144. if (err) {
  2145. snprintf(fw_name, sizeof(fw_name), "radeon/%s_mc2.bin", chip_name);
  2146. err = request_firmware(&rdev->mc_fw, fw_name, rdev->dev);
  2147. if (err) {
  2148. snprintf(fw_name, sizeof(fw_name), "radeon/%s_mc.bin", chip_name);
  2149. err = request_firmware(&rdev->mc_fw, fw_name, rdev->dev);
  2150. if (err)
  2151. goto out;
  2152. }
  2153. if ((rdev->mc_fw->size != mc_req_size) &&
  2154. (rdev->mc_fw->size != mc2_req_size)){
  2155. printk(KERN_ERR
  2156. "cik_mc: Bogus length %zu in firmware \"%s\"\n",
  2157. rdev->mc_fw->size, fw_name);
  2158. err = -EINVAL;
  2159. }
  2160. DRM_INFO("%s: %zu bytes\n", fw_name, rdev->mc_fw->size);
  2161. } else {
  2162. err = radeon_ucode_validate(rdev->mc_fw);
  2163. if (err) {
  2164. printk(KERN_ERR
  2165. "cik_fw: validation failed for firmware \"%s\"\n",
  2166. fw_name);
  2167. goto out;
  2168. } else {
  2169. new_fw++;
  2170. }
  2171. }
  2172. snprintf(fw_name, sizeof(fw_name), "radeon/%s_smc.bin", new_chip_name);
  2173. err = request_firmware(&rdev->smc_fw, fw_name, rdev->dev);
  2174. if (err) {
  2175. snprintf(fw_name, sizeof(fw_name), "radeon/%s_smc.bin", chip_name);
  2176. err = request_firmware(&rdev->smc_fw, fw_name, rdev->dev);
  2177. if (err) {
  2178. printk(KERN_ERR
  2179. "smc: error loading firmware \"%s\"\n",
  2180. fw_name);
  2181. release_firmware(rdev->smc_fw);
  2182. rdev->smc_fw = NULL;
  2183. err = 0;
  2184. } else if (rdev->smc_fw->size != smc_req_size) {
  2185. printk(KERN_ERR
  2186. "cik_smc: Bogus length %zu in firmware \"%s\"\n",
  2187. rdev->smc_fw->size, fw_name);
  2188. err = -EINVAL;
  2189. }
  2190. } else {
  2191. err = radeon_ucode_validate(rdev->smc_fw);
  2192. if (err) {
  2193. printk(KERN_ERR
  2194. "cik_fw: validation failed for firmware \"%s\"\n",
  2195. fw_name);
  2196. goto out;
  2197. } else {
  2198. new_fw++;
  2199. }
  2200. }
  2201. }
  2202. if (new_fw == 0) {
  2203. rdev->new_fw = false;
  2204. } else if (new_fw < num_fw) {
  2205. printk(KERN_ERR "ci_fw: mixing new and old firmware!\n");
  2206. err = -EINVAL;
  2207. } else {
  2208. rdev->new_fw = true;
  2209. }
  2210. out:
  2211. if (err) {
  2212. if (err != -EINVAL)
  2213. printk(KERN_ERR
  2214. "cik_cp: Failed to load firmware \"%s\"\n",
  2215. fw_name);
  2216. release_firmware(rdev->pfp_fw);
  2217. rdev->pfp_fw = NULL;
  2218. release_firmware(rdev->me_fw);
  2219. rdev->me_fw = NULL;
  2220. release_firmware(rdev->ce_fw);
  2221. rdev->ce_fw = NULL;
  2222. release_firmware(rdev->mec_fw);
  2223. rdev->mec_fw = NULL;
  2224. release_firmware(rdev->mec2_fw);
  2225. rdev->mec2_fw = NULL;
  2226. release_firmware(rdev->rlc_fw);
  2227. rdev->rlc_fw = NULL;
  2228. release_firmware(rdev->sdma_fw);
  2229. rdev->sdma_fw = NULL;
  2230. release_firmware(rdev->mc_fw);
  2231. rdev->mc_fw = NULL;
  2232. release_firmware(rdev->smc_fw);
  2233. rdev->smc_fw = NULL;
  2234. }
  2235. return err;
  2236. }
  2237. /*
  2238. * Core functions
  2239. */
  2240. /**
  2241. * cik_tiling_mode_table_init - init the hw tiling table
  2242. *
  2243. * @rdev: radeon_device pointer
  2244. *
  2245. * Starting with SI, the tiling setup is done globally in a
  2246. * set of 32 tiling modes. Rather than selecting each set of
  2247. * parameters per surface as on older asics, we just select
  2248. * which index in the tiling table we want to use, and the
  2249. * surface uses those parameters (CIK).
  2250. */
  2251. static void cik_tiling_mode_table_init(struct radeon_device *rdev)
  2252. {
  2253. const u32 num_tile_mode_states = 32;
  2254. const u32 num_secondary_tile_mode_states = 16;
  2255. u32 reg_offset, gb_tile_moden, split_equal_to_row_size;
  2256. u32 num_pipe_configs;
  2257. u32 num_rbs = rdev->config.cik.max_backends_per_se *
  2258. rdev->config.cik.max_shader_engines;
  2259. switch (rdev->config.cik.mem_row_size_in_kb) {
  2260. case 1:
  2261. split_equal_to_row_size = ADDR_SURF_TILE_SPLIT_1KB;
  2262. break;
  2263. case 2:
  2264. default:
  2265. split_equal_to_row_size = ADDR_SURF_TILE_SPLIT_2KB;
  2266. break;
  2267. case 4:
  2268. split_equal_to_row_size = ADDR_SURF_TILE_SPLIT_4KB;
  2269. break;
  2270. }
  2271. num_pipe_configs = rdev->config.cik.max_tile_pipes;
  2272. if (num_pipe_configs > 8)
  2273. num_pipe_configs = 16;
  2274. if (num_pipe_configs == 16) {
  2275. for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++) {
  2276. switch (reg_offset) {
  2277. case 0:
  2278. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2279. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  2280. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  2281. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B));
  2282. break;
  2283. case 1:
  2284. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2285. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  2286. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  2287. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B));
  2288. break;
  2289. case 2:
  2290. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2291. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  2292. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  2293. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
  2294. break;
  2295. case 3:
  2296. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2297. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  2298. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  2299. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B));
  2300. break;
  2301. case 4:
  2302. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2303. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  2304. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  2305. TILE_SPLIT(split_equal_to_row_size));
  2306. break;
  2307. case 5:
  2308. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2309. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  2310. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  2311. break;
  2312. case 6:
  2313. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
  2314. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  2315. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  2316. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
  2317. break;
  2318. case 7:
  2319. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
  2320. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  2321. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  2322. TILE_SPLIT(split_equal_to_row_size));
  2323. break;
  2324. case 8:
  2325. gb_tile_moden = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
  2326. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16));
  2327. break;
  2328. case 9:
  2329. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2330. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  2331. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING));
  2332. break;
  2333. case 10:
  2334. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2335. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2336. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  2337. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2338. break;
  2339. case 11:
  2340. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2341. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2342. PIPE_CONFIG(ADDR_SURF_P16_32x32_8x16) |
  2343. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2344. break;
  2345. case 12:
  2346. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
  2347. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2348. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  2349. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2350. break;
  2351. case 13:
  2352. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2353. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  2354. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING));
  2355. break;
  2356. case 14:
  2357. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2358. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2359. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  2360. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2361. break;
  2362. case 16:
  2363. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2364. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2365. PIPE_CONFIG(ADDR_SURF_P16_32x32_8x16) |
  2366. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2367. break;
  2368. case 17:
  2369. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
  2370. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2371. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  2372. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2373. break;
  2374. case 27:
  2375. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2376. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  2377. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING));
  2378. break;
  2379. case 28:
  2380. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2381. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  2382. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  2383. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2384. break;
  2385. case 29:
  2386. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2387. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  2388. PIPE_CONFIG(ADDR_SURF_P16_32x32_8x16) |
  2389. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2390. break;
  2391. case 30:
  2392. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
  2393. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  2394. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  2395. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2396. break;
  2397. default:
  2398. gb_tile_moden = 0;
  2399. break;
  2400. }
  2401. rdev->config.cik.tile_mode_array[reg_offset] = gb_tile_moden;
  2402. WREG32(GB_TILE_MODE0 + (reg_offset * 4), gb_tile_moden);
  2403. }
  2404. for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++) {
  2405. switch (reg_offset) {
  2406. case 0:
  2407. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2408. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2409. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  2410. NUM_BANKS(ADDR_SURF_16_BANK));
  2411. break;
  2412. case 1:
  2413. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2414. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2415. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  2416. NUM_BANKS(ADDR_SURF_16_BANK));
  2417. break;
  2418. case 2:
  2419. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2420. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2421. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  2422. NUM_BANKS(ADDR_SURF_16_BANK));
  2423. break;
  2424. case 3:
  2425. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2426. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2427. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  2428. NUM_BANKS(ADDR_SURF_16_BANK));
  2429. break;
  2430. case 4:
  2431. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2432. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2433. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  2434. NUM_BANKS(ADDR_SURF_8_BANK));
  2435. break;
  2436. case 5:
  2437. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2438. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2439. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  2440. NUM_BANKS(ADDR_SURF_4_BANK));
  2441. break;
  2442. case 6:
  2443. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2444. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2445. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  2446. NUM_BANKS(ADDR_SURF_2_BANK));
  2447. break;
  2448. case 8:
  2449. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2450. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2451. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  2452. NUM_BANKS(ADDR_SURF_16_BANK));
  2453. break;
  2454. case 9:
  2455. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2456. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2457. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  2458. NUM_BANKS(ADDR_SURF_16_BANK));
  2459. break;
  2460. case 10:
  2461. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2462. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2463. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  2464. NUM_BANKS(ADDR_SURF_16_BANK));
  2465. break;
  2466. case 11:
  2467. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2468. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2469. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  2470. NUM_BANKS(ADDR_SURF_8_BANK));
  2471. break;
  2472. case 12:
  2473. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2474. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2475. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  2476. NUM_BANKS(ADDR_SURF_4_BANK));
  2477. break;
  2478. case 13:
  2479. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2480. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2481. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  2482. NUM_BANKS(ADDR_SURF_2_BANK));
  2483. break;
  2484. case 14:
  2485. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2486. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2487. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  2488. NUM_BANKS(ADDR_SURF_2_BANK));
  2489. break;
  2490. default:
  2491. gb_tile_moden = 0;
  2492. break;
  2493. }
  2494. rdev->config.cik.macrotile_mode_array[reg_offset] = gb_tile_moden;
  2495. WREG32(GB_MACROTILE_MODE0 + (reg_offset * 4), gb_tile_moden);
  2496. }
  2497. } else if (num_pipe_configs == 8) {
  2498. for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++) {
  2499. switch (reg_offset) {
  2500. case 0:
  2501. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2502. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  2503. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2504. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B));
  2505. break;
  2506. case 1:
  2507. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2508. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  2509. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2510. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B));
  2511. break;
  2512. case 2:
  2513. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2514. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  2515. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2516. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
  2517. break;
  2518. case 3:
  2519. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2520. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  2521. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2522. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B));
  2523. break;
  2524. case 4:
  2525. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2526. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  2527. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2528. TILE_SPLIT(split_equal_to_row_size));
  2529. break;
  2530. case 5:
  2531. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2532. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2533. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  2534. break;
  2535. case 6:
  2536. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
  2537. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  2538. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2539. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
  2540. break;
  2541. case 7:
  2542. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
  2543. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  2544. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2545. TILE_SPLIT(split_equal_to_row_size));
  2546. break;
  2547. case 8:
  2548. gb_tile_moden = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
  2549. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16));
  2550. break;
  2551. case 9:
  2552. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2553. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2554. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING));
  2555. break;
  2556. case 10:
  2557. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2558. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2559. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2560. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2561. break;
  2562. case 11:
  2563. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2564. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2565. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2566. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2567. break;
  2568. case 12:
  2569. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
  2570. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2571. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2572. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2573. break;
  2574. case 13:
  2575. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2576. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2577. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING));
  2578. break;
  2579. case 14:
  2580. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2581. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2582. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2583. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2584. break;
  2585. case 16:
  2586. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2587. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2588. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2589. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2590. break;
  2591. case 17:
  2592. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
  2593. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2594. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2595. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2596. break;
  2597. case 27:
  2598. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2599. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2600. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING));
  2601. break;
  2602. case 28:
  2603. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2604. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  2605. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2606. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2607. break;
  2608. case 29:
  2609. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2610. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  2611. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2612. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2613. break;
  2614. case 30:
  2615. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
  2616. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  2617. PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
  2618. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2619. break;
  2620. default:
  2621. gb_tile_moden = 0;
  2622. break;
  2623. }
  2624. rdev->config.cik.tile_mode_array[reg_offset] = gb_tile_moden;
  2625. WREG32(GB_TILE_MODE0 + (reg_offset * 4), gb_tile_moden);
  2626. }
  2627. for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++) {
  2628. switch (reg_offset) {
  2629. case 0:
  2630. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2631. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2632. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2633. NUM_BANKS(ADDR_SURF_16_BANK));
  2634. break;
  2635. case 1:
  2636. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2637. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2638. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  2639. NUM_BANKS(ADDR_SURF_16_BANK));
  2640. break;
  2641. case 2:
  2642. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2643. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2644. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  2645. NUM_BANKS(ADDR_SURF_16_BANK));
  2646. break;
  2647. case 3:
  2648. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2649. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2650. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  2651. NUM_BANKS(ADDR_SURF_16_BANK));
  2652. break;
  2653. case 4:
  2654. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2655. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2656. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  2657. NUM_BANKS(ADDR_SURF_8_BANK));
  2658. break;
  2659. case 5:
  2660. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2661. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2662. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  2663. NUM_BANKS(ADDR_SURF_4_BANK));
  2664. break;
  2665. case 6:
  2666. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2667. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2668. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  2669. NUM_BANKS(ADDR_SURF_2_BANK));
  2670. break;
  2671. case 8:
  2672. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2673. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
  2674. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2675. NUM_BANKS(ADDR_SURF_16_BANK));
  2676. break;
  2677. case 9:
  2678. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2679. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2680. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2681. NUM_BANKS(ADDR_SURF_16_BANK));
  2682. break;
  2683. case 10:
  2684. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2685. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2686. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  2687. NUM_BANKS(ADDR_SURF_16_BANK));
  2688. break;
  2689. case 11:
  2690. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2691. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2692. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  2693. NUM_BANKS(ADDR_SURF_16_BANK));
  2694. break;
  2695. case 12:
  2696. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2697. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2698. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  2699. NUM_BANKS(ADDR_SURF_8_BANK));
  2700. break;
  2701. case 13:
  2702. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2703. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2704. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  2705. NUM_BANKS(ADDR_SURF_4_BANK));
  2706. break;
  2707. case 14:
  2708. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2709. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2710. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  2711. NUM_BANKS(ADDR_SURF_2_BANK));
  2712. break;
  2713. default:
  2714. gb_tile_moden = 0;
  2715. break;
  2716. }
  2717. rdev->config.cik.macrotile_mode_array[reg_offset] = gb_tile_moden;
  2718. WREG32(GB_MACROTILE_MODE0 + (reg_offset * 4), gb_tile_moden);
  2719. }
  2720. } else if (num_pipe_configs == 4) {
  2721. if (num_rbs == 4) {
  2722. for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++) {
  2723. switch (reg_offset) {
  2724. case 0:
  2725. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2726. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  2727. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2728. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B));
  2729. break;
  2730. case 1:
  2731. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2732. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  2733. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2734. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B));
  2735. break;
  2736. case 2:
  2737. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2738. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  2739. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2740. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
  2741. break;
  2742. case 3:
  2743. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2744. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  2745. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2746. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B));
  2747. break;
  2748. case 4:
  2749. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2750. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  2751. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2752. TILE_SPLIT(split_equal_to_row_size));
  2753. break;
  2754. case 5:
  2755. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2756. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2757. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  2758. break;
  2759. case 6:
  2760. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
  2761. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  2762. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2763. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
  2764. break;
  2765. case 7:
  2766. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
  2767. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  2768. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2769. TILE_SPLIT(split_equal_to_row_size));
  2770. break;
  2771. case 8:
  2772. gb_tile_moden = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
  2773. PIPE_CONFIG(ADDR_SURF_P4_16x16));
  2774. break;
  2775. case 9:
  2776. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2777. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2778. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING));
  2779. break;
  2780. case 10:
  2781. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2782. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2783. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2784. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2785. break;
  2786. case 11:
  2787. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2788. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2789. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2790. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2791. break;
  2792. case 12:
  2793. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
  2794. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2795. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2796. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2797. break;
  2798. case 13:
  2799. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2800. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2801. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING));
  2802. break;
  2803. case 14:
  2804. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2805. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2806. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2807. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2808. break;
  2809. case 16:
  2810. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2811. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2812. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2813. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2814. break;
  2815. case 17:
  2816. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
  2817. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2818. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2819. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2820. break;
  2821. case 27:
  2822. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2823. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2824. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING));
  2825. break;
  2826. case 28:
  2827. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
  2828. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  2829. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2830. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2831. break;
  2832. case 29:
  2833. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2834. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  2835. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2836. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2837. break;
  2838. case 30:
  2839. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
  2840. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  2841. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  2842. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2843. break;
  2844. default:
  2845. gb_tile_moden = 0;
  2846. break;
  2847. }
  2848. rdev->config.cik.tile_mode_array[reg_offset] = gb_tile_moden;
  2849. WREG32(GB_TILE_MODE0 + (reg_offset * 4), gb_tile_moden);
  2850. }
  2851. } else if (num_rbs < 4) {
  2852. for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++) {
  2853. switch (reg_offset) {
  2854. case 0:
  2855. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2856. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  2857. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2858. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B));
  2859. break;
  2860. case 1:
  2861. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2862. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  2863. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2864. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B));
  2865. break;
  2866. case 2:
  2867. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2868. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  2869. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2870. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
  2871. break;
  2872. case 3:
  2873. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2874. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  2875. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2876. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B));
  2877. break;
  2878. case 4:
  2879. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2880. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  2881. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2882. TILE_SPLIT(split_equal_to_row_size));
  2883. break;
  2884. case 5:
  2885. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2886. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2887. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  2888. break;
  2889. case 6:
  2890. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
  2891. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  2892. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2893. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
  2894. break;
  2895. case 7:
  2896. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
  2897. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  2898. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2899. TILE_SPLIT(split_equal_to_row_size));
  2900. break;
  2901. case 8:
  2902. gb_tile_moden = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
  2903. PIPE_CONFIG(ADDR_SURF_P4_8x16));
  2904. break;
  2905. case 9:
  2906. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2907. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2908. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING));
  2909. break;
  2910. case 10:
  2911. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2912. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2913. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2914. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2915. break;
  2916. case 11:
  2917. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2918. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2919. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2920. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2921. break;
  2922. case 12:
  2923. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
  2924. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2925. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2926. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2927. break;
  2928. case 13:
  2929. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2930. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2931. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING));
  2932. break;
  2933. case 14:
  2934. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2935. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2936. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2937. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2938. break;
  2939. case 16:
  2940. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2941. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2942. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2943. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2944. break;
  2945. case 17:
  2946. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
  2947. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  2948. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2949. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2950. break;
  2951. case 27:
  2952. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2953. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2954. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING));
  2955. break;
  2956. case 28:
  2957. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
  2958. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  2959. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2960. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2961. break;
  2962. case 29:
  2963. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  2964. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  2965. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2966. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2967. break;
  2968. case 30:
  2969. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
  2970. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  2971. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2972. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  2973. break;
  2974. default:
  2975. gb_tile_moden = 0;
  2976. break;
  2977. }
  2978. rdev->config.cik.tile_mode_array[reg_offset] = gb_tile_moden;
  2979. WREG32(GB_TILE_MODE0 + (reg_offset * 4), gb_tile_moden);
  2980. }
  2981. }
  2982. for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++) {
  2983. switch (reg_offset) {
  2984. case 0:
  2985. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2986. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2987. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2988. NUM_BANKS(ADDR_SURF_16_BANK));
  2989. break;
  2990. case 1:
  2991. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2992. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2993. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  2994. NUM_BANKS(ADDR_SURF_16_BANK));
  2995. break;
  2996. case 2:
  2997. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2998. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2999. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  3000. NUM_BANKS(ADDR_SURF_16_BANK));
  3001. break;
  3002. case 3:
  3003. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  3004. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  3005. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  3006. NUM_BANKS(ADDR_SURF_16_BANK));
  3007. break;
  3008. case 4:
  3009. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  3010. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  3011. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  3012. NUM_BANKS(ADDR_SURF_16_BANK));
  3013. break;
  3014. case 5:
  3015. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  3016. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  3017. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  3018. NUM_BANKS(ADDR_SURF_8_BANK));
  3019. break;
  3020. case 6:
  3021. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  3022. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  3023. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  3024. NUM_BANKS(ADDR_SURF_4_BANK));
  3025. break;
  3026. case 8:
  3027. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
  3028. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
  3029. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  3030. NUM_BANKS(ADDR_SURF_16_BANK));
  3031. break;
  3032. case 9:
  3033. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
  3034. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  3035. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  3036. NUM_BANKS(ADDR_SURF_16_BANK));
  3037. break;
  3038. case 10:
  3039. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  3040. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  3041. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  3042. NUM_BANKS(ADDR_SURF_16_BANK));
  3043. break;
  3044. case 11:
  3045. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  3046. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  3047. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  3048. NUM_BANKS(ADDR_SURF_16_BANK));
  3049. break;
  3050. case 12:
  3051. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  3052. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  3053. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  3054. NUM_BANKS(ADDR_SURF_16_BANK));
  3055. break;
  3056. case 13:
  3057. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  3058. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  3059. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  3060. NUM_BANKS(ADDR_SURF_8_BANK));
  3061. break;
  3062. case 14:
  3063. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  3064. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  3065. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  3066. NUM_BANKS(ADDR_SURF_4_BANK));
  3067. break;
  3068. default:
  3069. gb_tile_moden = 0;
  3070. break;
  3071. }
  3072. rdev->config.cik.macrotile_mode_array[reg_offset] = gb_tile_moden;
  3073. WREG32(GB_MACROTILE_MODE0 + (reg_offset * 4), gb_tile_moden);
  3074. }
  3075. } else if (num_pipe_configs == 2) {
  3076. for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++) {
  3077. switch (reg_offset) {
  3078. case 0:
  3079. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  3080. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  3081. PIPE_CONFIG(ADDR_SURF_P2) |
  3082. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B));
  3083. break;
  3084. case 1:
  3085. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  3086. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  3087. PIPE_CONFIG(ADDR_SURF_P2) |
  3088. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B));
  3089. break;
  3090. case 2:
  3091. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  3092. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  3093. PIPE_CONFIG(ADDR_SURF_P2) |
  3094. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
  3095. break;
  3096. case 3:
  3097. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  3098. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  3099. PIPE_CONFIG(ADDR_SURF_P2) |
  3100. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B));
  3101. break;
  3102. case 4:
  3103. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  3104. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  3105. PIPE_CONFIG(ADDR_SURF_P2) |
  3106. TILE_SPLIT(split_equal_to_row_size));
  3107. break;
  3108. case 5:
  3109. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  3110. PIPE_CONFIG(ADDR_SURF_P2) |
  3111. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  3112. break;
  3113. case 6:
  3114. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
  3115. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  3116. PIPE_CONFIG(ADDR_SURF_P2) |
  3117. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
  3118. break;
  3119. case 7:
  3120. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
  3121. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  3122. PIPE_CONFIG(ADDR_SURF_P2) |
  3123. TILE_SPLIT(split_equal_to_row_size));
  3124. break;
  3125. case 8:
  3126. gb_tile_moden = ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
  3127. PIPE_CONFIG(ADDR_SURF_P2);
  3128. break;
  3129. case 9:
  3130. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  3131. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  3132. PIPE_CONFIG(ADDR_SURF_P2));
  3133. break;
  3134. case 10:
  3135. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  3136. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  3137. PIPE_CONFIG(ADDR_SURF_P2) |
  3138. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  3139. break;
  3140. case 11:
  3141. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  3142. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  3143. PIPE_CONFIG(ADDR_SURF_P2) |
  3144. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  3145. break;
  3146. case 12:
  3147. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
  3148. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  3149. PIPE_CONFIG(ADDR_SURF_P2) |
  3150. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  3151. break;
  3152. case 13:
  3153. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  3154. PIPE_CONFIG(ADDR_SURF_P2) |
  3155. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING));
  3156. break;
  3157. case 14:
  3158. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  3159. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  3160. PIPE_CONFIG(ADDR_SURF_P2) |
  3161. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  3162. break;
  3163. case 16:
  3164. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  3165. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  3166. PIPE_CONFIG(ADDR_SURF_P2) |
  3167. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  3168. break;
  3169. case 17:
  3170. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
  3171. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  3172. PIPE_CONFIG(ADDR_SURF_P2) |
  3173. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  3174. break;
  3175. case 27:
  3176. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  3177. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  3178. PIPE_CONFIG(ADDR_SURF_P2));
  3179. break;
  3180. case 28:
  3181. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
  3182. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  3183. PIPE_CONFIG(ADDR_SURF_P2) |
  3184. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  3185. break;
  3186. case 29:
  3187. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  3188. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  3189. PIPE_CONFIG(ADDR_SURF_P2) |
  3190. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  3191. break;
  3192. case 30:
  3193. gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
  3194. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  3195. PIPE_CONFIG(ADDR_SURF_P2) |
  3196. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  3197. break;
  3198. default:
  3199. gb_tile_moden = 0;
  3200. break;
  3201. }
  3202. rdev->config.cik.tile_mode_array[reg_offset] = gb_tile_moden;
  3203. WREG32(GB_TILE_MODE0 + (reg_offset * 4), gb_tile_moden);
  3204. }
  3205. for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++) {
  3206. switch (reg_offset) {
  3207. case 0:
  3208. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
  3209. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  3210. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  3211. NUM_BANKS(ADDR_SURF_16_BANK));
  3212. break;
  3213. case 1:
  3214. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
  3215. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  3216. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  3217. NUM_BANKS(ADDR_SURF_16_BANK));
  3218. break;
  3219. case 2:
  3220. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  3221. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  3222. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  3223. NUM_BANKS(ADDR_SURF_16_BANK));
  3224. break;
  3225. case 3:
  3226. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  3227. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  3228. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  3229. NUM_BANKS(ADDR_SURF_16_BANK));
  3230. break;
  3231. case 4:
  3232. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  3233. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  3234. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  3235. NUM_BANKS(ADDR_SURF_16_BANK));
  3236. break;
  3237. case 5:
  3238. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  3239. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  3240. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  3241. NUM_BANKS(ADDR_SURF_16_BANK));
  3242. break;
  3243. case 6:
  3244. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  3245. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  3246. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  3247. NUM_BANKS(ADDR_SURF_8_BANK));
  3248. break;
  3249. case 8:
  3250. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_4) |
  3251. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
  3252. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  3253. NUM_BANKS(ADDR_SURF_16_BANK));
  3254. break;
  3255. case 9:
  3256. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_4) |
  3257. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  3258. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  3259. NUM_BANKS(ADDR_SURF_16_BANK));
  3260. break;
  3261. case 10:
  3262. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
  3263. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  3264. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  3265. NUM_BANKS(ADDR_SURF_16_BANK));
  3266. break;
  3267. case 11:
  3268. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
  3269. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  3270. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  3271. NUM_BANKS(ADDR_SURF_16_BANK));
  3272. break;
  3273. case 12:
  3274. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  3275. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  3276. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  3277. NUM_BANKS(ADDR_SURF_16_BANK));
  3278. break;
  3279. case 13:
  3280. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  3281. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  3282. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  3283. NUM_BANKS(ADDR_SURF_16_BANK));
  3284. break;
  3285. case 14:
  3286. gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  3287. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  3288. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  3289. NUM_BANKS(ADDR_SURF_8_BANK));
  3290. break;
  3291. default:
  3292. gb_tile_moden = 0;
  3293. break;
  3294. }
  3295. rdev->config.cik.macrotile_mode_array[reg_offset] = gb_tile_moden;
  3296. WREG32(GB_MACROTILE_MODE0 + (reg_offset * 4), gb_tile_moden);
  3297. }
  3298. } else
  3299. DRM_ERROR("unknown num pipe config: 0x%x\n", num_pipe_configs);
  3300. }
  3301. /**
  3302. * cik_select_se_sh - select which SE, SH to address
  3303. *
  3304. * @rdev: radeon_device pointer
  3305. * @se_num: shader engine to address
  3306. * @sh_num: sh block to address
  3307. *
  3308. * Select which SE, SH combinations to address. Certain
  3309. * registers are instanced per SE or SH. 0xffffffff means
  3310. * broadcast to all SEs or SHs (CIK).
  3311. */
  3312. static void cik_select_se_sh(struct radeon_device *rdev,
  3313. u32 se_num, u32 sh_num)
  3314. {
  3315. u32 data = INSTANCE_BROADCAST_WRITES;
  3316. if ((se_num == 0xffffffff) && (sh_num == 0xffffffff))
  3317. data |= SH_BROADCAST_WRITES | SE_BROADCAST_WRITES;
  3318. else if (se_num == 0xffffffff)
  3319. data |= SE_BROADCAST_WRITES | SH_INDEX(sh_num);
  3320. else if (sh_num == 0xffffffff)
  3321. data |= SH_BROADCAST_WRITES | SE_INDEX(se_num);
  3322. else
  3323. data |= SH_INDEX(sh_num) | SE_INDEX(se_num);
  3324. WREG32(GRBM_GFX_INDEX, data);
  3325. }
  3326. /**
  3327. * cik_create_bitmask - create a bitmask
  3328. *
  3329. * @bit_width: length of the mask
  3330. *
  3331. * create a variable length bit mask (CIK).
  3332. * Returns the bitmask.
  3333. */
  3334. static u32 cik_create_bitmask(u32 bit_width)
  3335. {
  3336. u32 i, mask = 0;
  3337. for (i = 0; i < bit_width; i++) {
  3338. mask <<= 1;
  3339. mask |= 1;
  3340. }
  3341. return mask;
  3342. }
  3343. /**
  3344. * cik_get_rb_disabled - computes the mask of disabled RBs
  3345. *
  3346. * @rdev: radeon_device pointer
  3347. * @max_rb_num: max RBs (render backends) for the asic
  3348. * @se_num: number of SEs (shader engines) for the asic
  3349. * @sh_per_se: number of SH blocks per SE for the asic
  3350. *
  3351. * Calculates the bitmask of disabled RBs (CIK).
  3352. * Returns the disabled RB bitmask.
  3353. */
  3354. static u32 cik_get_rb_disabled(struct radeon_device *rdev,
  3355. u32 max_rb_num_per_se,
  3356. u32 sh_per_se)
  3357. {
  3358. u32 data, mask;
  3359. data = RREG32(CC_RB_BACKEND_DISABLE);
  3360. if (data & 1)
  3361. data &= BACKEND_DISABLE_MASK;
  3362. else
  3363. data = 0;
  3364. data |= RREG32(GC_USER_RB_BACKEND_DISABLE);
  3365. data >>= BACKEND_DISABLE_SHIFT;
  3366. mask = cik_create_bitmask(max_rb_num_per_se / sh_per_se);
  3367. return data & mask;
  3368. }
  3369. /**
  3370. * cik_setup_rb - setup the RBs on the asic
  3371. *
  3372. * @rdev: radeon_device pointer
  3373. * @se_num: number of SEs (shader engines) for the asic
  3374. * @sh_per_se: number of SH blocks per SE for the asic
  3375. * @max_rb_num: max RBs (render backends) for the asic
  3376. *
  3377. * Configures per-SE/SH RB registers (CIK).
  3378. */
  3379. static void cik_setup_rb(struct radeon_device *rdev,
  3380. u32 se_num, u32 sh_per_se,
  3381. u32 max_rb_num_per_se)
  3382. {
  3383. int i, j;
  3384. u32 data, mask;
  3385. u32 disabled_rbs = 0;
  3386. u32 enabled_rbs = 0;
  3387. mutex_lock(&rdev->grbm_idx_mutex);
  3388. for (i = 0; i < se_num; i++) {
  3389. for (j = 0; j < sh_per_se; j++) {
  3390. cik_select_se_sh(rdev, i, j);
  3391. data = cik_get_rb_disabled(rdev, max_rb_num_per_se, sh_per_se);
  3392. if (rdev->family == CHIP_HAWAII)
  3393. disabled_rbs |= data << ((i * sh_per_se + j) * HAWAII_RB_BITMAP_WIDTH_PER_SH);
  3394. else
  3395. disabled_rbs |= data << ((i * sh_per_se + j) * CIK_RB_BITMAP_WIDTH_PER_SH);
  3396. }
  3397. }
  3398. cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
  3399. mutex_unlock(&rdev->grbm_idx_mutex);
  3400. mask = 1;
  3401. for (i = 0; i < max_rb_num_per_se * se_num; i++) {
  3402. if (!(disabled_rbs & mask))
  3403. enabled_rbs |= mask;
  3404. mask <<= 1;
  3405. }
  3406. rdev->config.cik.backend_enable_mask = enabled_rbs;
  3407. mutex_lock(&rdev->grbm_idx_mutex);
  3408. for (i = 0; i < se_num; i++) {
  3409. cik_select_se_sh(rdev, i, 0xffffffff);
  3410. data = 0;
  3411. for (j = 0; j < sh_per_se; j++) {
  3412. switch (enabled_rbs & 3) {
  3413. case 0:
  3414. if (j == 0)
  3415. data |= PKR_MAP(RASTER_CONFIG_RB_MAP_3);
  3416. else
  3417. data |= PKR_MAP(RASTER_CONFIG_RB_MAP_0);
  3418. break;
  3419. case 1:
  3420. data |= (RASTER_CONFIG_RB_MAP_0 << (i * sh_per_se + j) * 2);
  3421. break;
  3422. case 2:
  3423. data |= (RASTER_CONFIG_RB_MAP_3 << (i * sh_per_se + j) * 2);
  3424. break;
  3425. case 3:
  3426. default:
  3427. data |= (RASTER_CONFIG_RB_MAP_2 << (i * sh_per_se + j) * 2);
  3428. break;
  3429. }
  3430. enabled_rbs >>= 2;
  3431. }
  3432. WREG32(PA_SC_RASTER_CONFIG, data);
  3433. }
  3434. cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
  3435. mutex_unlock(&rdev->grbm_idx_mutex);
  3436. }
  3437. /**
  3438. * cik_gpu_init - setup the 3D engine
  3439. *
  3440. * @rdev: radeon_device pointer
  3441. *
  3442. * Configures the 3D engine and tiling configuration
  3443. * registers so that the 3D engine is usable.
  3444. */
  3445. static void cik_gpu_init(struct radeon_device *rdev)
  3446. {
  3447. u32 gb_addr_config = RREG32(GB_ADDR_CONFIG);
  3448. u32 mc_shared_chmap, mc_arb_ramcfg;
  3449. u32 hdp_host_path_cntl;
  3450. u32 tmp;
  3451. int i, j;
  3452. switch (rdev->family) {
  3453. case CHIP_BONAIRE:
  3454. rdev->config.cik.max_shader_engines = 2;
  3455. rdev->config.cik.max_tile_pipes = 4;
  3456. rdev->config.cik.max_cu_per_sh = 7;
  3457. rdev->config.cik.max_sh_per_se = 1;
  3458. rdev->config.cik.max_backends_per_se = 2;
  3459. rdev->config.cik.max_texture_channel_caches = 4;
  3460. rdev->config.cik.max_gprs = 256;
  3461. rdev->config.cik.max_gs_threads = 32;
  3462. rdev->config.cik.max_hw_contexts = 8;
  3463. rdev->config.cik.sc_prim_fifo_size_frontend = 0x20;
  3464. rdev->config.cik.sc_prim_fifo_size_backend = 0x100;
  3465. rdev->config.cik.sc_hiz_tile_fifo_size = 0x30;
  3466. rdev->config.cik.sc_earlyz_tile_fifo_size = 0x130;
  3467. gb_addr_config = BONAIRE_GB_ADDR_CONFIG_GOLDEN;
  3468. break;
  3469. case CHIP_HAWAII:
  3470. rdev->config.cik.max_shader_engines = 4;
  3471. rdev->config.cik.max_tile_pipes = 16;
  3472. rdev->config.cik.max_cu_per_sh = 11;
  3473. rdev->config.cik.max_sh_per_se = 1;
  3474. rdev->config.cik.max_backends_per_se = 4;
  3475. rdev->config.cik.max_texture_channel_caches = 16;
  3476. rdev->config.cik.max_gprs = 256;
  3477. rdev->config.cik.max_gs_threads = 32;
  3478. rdev->config.cik.max_hw_contexts = 8;
  3479. rdev->config.cik.sc_prim_fifo_size_frontend = 0x20;
  3480. rdev->config.cik.sc_prim_fifo_size_backend = 0x100;
  3481. rdev->config.cik.sc_hiz_tile_fifo_size = 0x30;
  3482. rdev->config.cik.sc_earlyz_tile_fifo_size = 0x130;
  3483. gb_addr_config = HAWAII_GB_ADDR_CONFIG_GOLDEN;
  3484. break;
  3485. case CHIP_KAVERI:
  3486. rdev->config.cik.max_shader_engines = 1;
  3487. rdev->config.cik.max_tile_pipes = 4;
  3488. rdev->config.cik.max_cu_per_sh = 8;
  3489. rdev->config.cik.max_backends_per_se = 2;
  3490. rdev->config.cik.max_sh_per_se = 1;
  3491. rdev->config.cik.max_texture_channel_caches = 4;
  3492. rdev->config.cik.max_gprs = 256;
  3493. rdev->config.cik.max_gs_threads = 16;
  3494. rdev->config.cik.max_hw_contexts = 8;
  3495. rdev->config.cik.sc_prim_fifo_size_frontend = 0x20;
  3496. rdev->config.cik.sc_prim_fifo_size_backend = 0x100;
  3497. rdev->config.cik.sc_hiz_tile_fifo_size = 0x30;
  3498. rdev->config.cik.sc_earlyz_tile_fifo_size = 0x130;
  3499. gb_addr_config = BONAIRE_GB_ADDR_CONFIG_GOLDEN;
  3500. break;
  3501. case CHIP_KABINI:
  3502. case CHIP_MULLINS:
  3503. default:
  3504. rdev->config.cik.max_shader_engines = 1;
  3505. rdev->config.cik.max_tile_pipes = 2;
  3506. rdev->config.cik.max_cu_per_sh = 2;
  3507. rdev->config.cik.max_sh_per_se = 1;
  3508. rdev->config.cik.max_backends_per_se = 1;
  3509. rdev->config.cik.max_texture_channel_caches = 2;
  3510. rdev->config.cik.max_gprs = 256;
  3511. rdev->config.cik.max_gs_threads = 16;
  3512. rdev->config.cik.max_hw_contexts = 8;
  3513. rdev->config.cik.sc_prim_fifo_size_frontend = 0x20;
  3514. rdev->config.cik.sc_prim_fifo_size_backend = 0x100;
  3515. rdev->config.cik.sc_hiz_tile_fifo_size = 0x30;
  3516. rdev->config.cik.sc_earlyz_tile_fifo_size = 0x130;
  3517. gb_addr_config = BONAIRE_GB_ADDR_CONFIG_GOLDEN;
  3518. break;
  3519. }
  3520. /* Initialize HDP */
  3521. for (i = 0, j = 0; i < 32; i++, j += 0x18) {
  3522. WREG32((0x2c14 + j), 0x00000000);
  3523. WREG32((0x2c18 + j), 0x00000000);
  3524. WREG32((0x2c1c + j), 0x00000000);
  3525. WREG32((0x2c20 + j), 0x00000000);
  3526. WREG32((0x2c24 + j), 0x00000000);
  3527. }
  3528. WREG32(GRBM_CNTL, GRBM_READ_TIMEOUT(0xff));
  3529. WREG32(SRBM_INT_CNTL, 0x1);
  3530. WREG32(SRBM_INT_ACK, 0x1);
  3531. WREG32(BIF_FB_EN, FB_READ_EN | FB_WRITE_EN);
  3532. mc_shared_chmap = RREG32(MC_SHARED_CHMAP);
  3533. mc_arb_ramcfg = RREG32(MC_ARB_RAMCFG);
  3534. rdev->config.cik.num_tile_pipes = rdev->config.cik.max_tile_pipes;
  3535. rdev->config.cik.mem_max_burst_length_bytes = 256;
  3536. tmp = (mc_arb_ramcfg & NOOFCOLS_MASK) >> NOOFCOLS_SHIFT;
  3537. rdev->config.cik.mem_row_size_in_kb = (4 * (1 << (8 + tmp))) / 1024;
  3538. if (rdev->config.cik.mem_row_size_in_kb > 4)
  3539. rdev->config.cik.mem_row_size_in_kb = 4;
  3540. /* XXX use MC settings? */
  3541. rdev->config.cik.shader_engine_tile_size = 32;
  3542. rdev->config.cik.num_gpus = 1;
  3543. rdev->config.cik.multi_gpu_tile_size = 64;
  3544. /* fix up row size */
  3545. gb_addr_config &= ~ROW_SIZE_MASK;
  3546. switch (rdev->config.cik.mem_row_size_in_kb) {
  3547. case 1:
  3548. default:
  3549. gb_addr_config |= ROW_SIZE(0);
  3550. break;
  3551. case 2:
  3552. gb_addr_config |= ROW_SIZE(1);
  3553. break;
  3554. case 4:
  3555. gb_addr_config |= ROW_SIZE(2);
  3556. break;
  3557. }
  3558. /* setup tiling info dword. gb_addr_config is not adequate since it does
  3559. * not have bank info, so create a custom tiling dword.
  3560. * bits 3:0 num_pipes
  3561. * bits 7:4 num_banks
  3562. * bits 11:8 group_size
  3563. * bits 15:12 row_size
  3564. */
  3565. rdev->config.cik.tile_config = 0;
  3566. switch (rdev->config.cik.num_tile_pipes) {
  3567. case 1:
  3568. rdev->config.cik.tile_config |= (0 << 0);
  3569. break;
  3570. case 2:
  3571. rdev->config.cik.tile_config |= (1 << 0);
  3572. break;
  3573. case 4:
  3574. rdev->config.cik.tile_config |= (2 << 0);
  3575. break;
  3576. case 8:
  3577. default:
  3578. /* XXX what about 12? */
  3579. rdev->config.cik.tile_config |= (3 << 0);
  3580. break;
  3581. }
  3582. rdev->config.cik.tile_config |=
  3583. ((mc_arb_ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT) << 4;
  3584. rdev->config.cik.tile_config |=
  3585. ((gb_addr_config & PIPE_INTERLEAVE_SIZE_MASK) >> PIPE_INTERLEAVE_SIZE_SHIFT) << 8;
  3586. rdev->config.cik.tile_config |=
  3587. ((gb_addr_config & ROW_SIZE_MASK) >> ROW_SIZE_SHIFT) << 12;
  3588. WREG32(GB_ADDR_CONFIG, gb_addr_config);
  3589. WREG32(HDP_ADDR_CONFIG, gb_addr_config);
  3590. WREG32(DMIF_ADDR_CALC, gb_addr_config);
  3591. WREG32(SDMA0_TILING_CONFIG + SDMA0_REGISTER_OFFSET, gb_addr_config & 0x70);
  3592. WREG32(SDMA0_TILING_CONFIG + SDMA1_REGISTER_OFFSET, gb_addr_config & 0x70);
  3593. WREG32(UVD_UDEC_ADDR_CONFIG, gb_addr_config);
  3594. WREG32(UVD_UDEC_DB_ADDR_CONFIG, gb_addr_config);
  3595. WREG32(UVD_UDEC_DBW_ADDR_CONFIG, gb_addr_config);
  3596. cik_tiling_mode_table_init(rdev);
  3597. cik_setup_rb(rdev, rdev->config.cik.max_shader_engines,
  3598. rdev->config.cik.max_sh_per_se,
  3599. rdev->config.cik.max_backends_per_se);
  3600. rdev->config.cik.active_cus = 0;
  3601. for (i = 0; i < rdev->config.cik.max_shader_engines; i++) {
  3602. for (j = 0; j < rdev->config.cik.max_sh_per_se; j++) {
  3603. rdev->config.cik.active_cus +=
  3604. hweight32(cik_get_cu_active_bitmap(rdev, i, j));
  3605. }
  3606. }
  3607. /* set HW defaults for 3D engine */
  3608. WREG32(CP_MEQ_THRESHOLDS, MEQ1_START(0x30) | MEQ2_START(0x60));
  3609. mutex_lock(&rdev->grbm_idx_mutex);
  3610. /*
  3611. * making sure that the following register writes will be broadcasted
  3612. * to all the shaders
  3613. */
  3614. cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
  3615. WREG32(SX_DEBUG_1, 0x20);
  3616. WREG32(TA_CNTL_AUX, 0x00010000);
  3617. tmp = RREG32(SPI_CONFIG_CNTL);
  3618. tmp |= 0x03000000;
  3619. WREG32(SPI_CONFIG_CNTL, tmp);
  3620. WREG32(SQ_CONFIG, 1);
  3621. WREG32(DB_DEBUG, 0);
  3622. tmp = RREG32(DB_DEBUG2) & ~0xf00fffff;
  3623. tmp |= 0x00000400;
  3624. WREG32(DB_DEBUG2, tmp);
  3625. tmp = RREG32(DB_DEBUG3) & ~0x0002021c;
  3626. tmp |= 0x00020200;
  3627. WREG32(DB_DEBUG3, tmp);
  3628. tmp = RREG32(CB_HW_CONTROL) & ~0x00010000;
  3629. tmp |= 0x00018208;
  3630. WREG32(CB_HW_CONTROL, tmp);
  3631. WREG32(SPI_CONFIG_CNTL_1, VTX_DONE_DELAY(4));
  3632. WREG32(PA_SC_FIFO_SIZE, (SC_FRONTEND_PRIM_FIFO_SIZE(rdev->config.cik.sc_prim_fifo_size_frontend) |
  3633. SC_BACKEND_PRIM_FIFO_SIZE(rdev->config.cik.sc_prim_fifo_size_backend) |
  3634. SC_HIZ_TILE_FIFO_SIZE(rdev->config.cik.sc_hiz_tile_fifo_size) |
  3635. SC_EARLYZ_TILE_FIFO_SIZE(rdev->config.cik.sc_earlyz_tile_fifo_size)));
  3636. WREG32(VGT_NUM_INSTANCES, 1);
  3637. WREG32(CP_PERFMON_CNTL, 0);
  3638. WREG32(SQ_CONFIG, 0);
  3639. WREG32(PA_SC_FORCE_EOV_MAX_CNTS, (FORCE_EOV_MAX_CLK_CNT(4095) |
  3640. FORCE_EOV_MAX_REZ_CNT(255)));
  3641. WREG32(VGT_CACHE_INVALIDATION, CACHE_INVALIDATION(VC_AND_TC) |
  3642. AUTO_INVLD_EN(ES_AND_GS_AUTO));
  3643. WREG32(VGT_GS_VERTEX_REUSE, 16);
  3644. WREG32(PA_SC_LINE_STIPPLE_STATE, 0);
  3645. tmp = RREG32(HDP_MISC_CNTL);
  3646. tmp |= HDP_FLUSH_INVALIDATE_CACHE;
  3647. WREG32(HDP_MISC_CNTL, tmp);
  3648. hdp_host_path_cntl = RREG32(HDP_HOST_PATH_CNTL);
  3649. WREG32(HDP_HOST_PATH_CNTL, hdp_host_path_cntl);
  3650. WREG32(PA_CL_ENHANCE, CLIP_VTX_REORDER_ENA | NUM_CLIP_SEQ(3));
  3651. WREG32(PA_SC_ENHANCE, ENABLE_PA_SC_OUT_OF_ORDER);
  3652. mutex_unlock(&rdev->grbm_idx_mutex);
  3653. udelay(50);
  3654. }
  3655. /*
  3656. * GPU scratch registers helpers function.
  3657. */
  3658. /**
  3659. * cik_scratch_init - setup driver info for CP scratch regs
  3660. *
  3661. * @rdev: radeon_device pointer
  3662. *
  3663. * Set up the number and offset of the CP scratch registers.
  3664. * NOTE: use of CP scratch registers is a legacy inferface and
  3665. * is not used by default on newer asics (r6xx+). On newer asics,
  3666. * memory buffers are used for fences rather than scratch regs.
  3667. */
  3668. static void cik_scratch_init(struct radeon_device *rdev)
  3669. {
  3670. int i;
  3671. rdev->scratch.num_reg = 7;
  3672. rdev->scratch.reg_base = SCRATCH_REG0;
  3673. for (i = 0; i < rdev->scratch.num_reg; i++) {
  3674. rdev->scratch.free[i] = true;
  3675. rdev->scratch.reg[i] = rdev->scratch.reg_base + (i * 4);
  3676. }
  3677. }
  3678. /**
  3679. * cik_ring_test - basic gfx ring test
  3680. *
  3681. * @rdev: radeon_device pointer
  3682. * @ring: radeon_ring structure holding ring information
  3683. *
  3684. * Allocate a scratch register and write to it using the gfx ring (CIK).
  3685. * Provides a basic gfx ring test to verify that the ring is working.
  3686. * Used by cik_cp_gfx_resume();
  3687. * Returns 0 on success, error on failure.
  3688. */
  3689. int cik_ring_test(struct radeon_device *rdev, struct radeon_ring *ring)
  3690. {
  3691. uint32_t scratch;
  3692. uint32_t tmp = 0;
  3693. unsigned i;
  3694. int r;
  3695. r = radeon_scratch_get(rdev, &scratch);
  3696. if (r) {
  3697. DRM_ERROR("radeon: cp failed to get scratch reg (%d).\n", r);
  3698. return r;
  3699. }
  3700. WREG32(scratch, 0xCAFEDEAD);
  3701. r = radeon_ring_lock(rdev, ring, 3);
  3702. if (r) {
  3703. DRM_ERROR("radeon: cp failed to lock ring %d (%d).\n", ring->idx, r);
  3704. radeon_scratch_free(rdev, scratch);
  3705. return r;
  3706. }
  3707. radeon_ring_write(ring, PACKET3(PACKET3_SET_UCONFIG_REG, 1));
  3708. radeon_ring_write(ring, ((scratch - PACKET3_SET_UCONFIG_REG_START) >> 2));
  3709. radeon_ring_write(ring, 0xDEADBEEF);
  3710. radeon_ring_unlock_commit(rdev, ring, false);
  3711. for (i = 0; i < rdev->usec_timeout; i++) {
  3712. tmp = RREG32(scratch);
  3713. if (tmp == 0xDEADBEEF)
  3714. break;
  3715. DRM_UDELAY(1);
  3716. }
  3717. if (i < rdev->usec_timeout) {
  3718. DRM_INFO("ring test on %d succeeded in %d usecs\n", ring->idx, i);
  3719. } else {
  3720. DRM_ERROR("radeon: ring %d test failed (scratch(0x%04X)=0x%08X)\n",
  3721. ring->idx, scratch, tmp);
  3722. r = -EINVAL;
  3723. }
  3724. radeon_scratch_free(rdev, scratch);
  3725. return r;
  3726. }
  3727. /**
  3728. * cik_hdp_flush_cp_ring_emit - emit an hdp flush on the cp
  3729. *
  3730. * @rdev: radeon_device pointer
  3731. * @ridx: radeon ring index
  3732. *
  3733. * Emits an hdp flush on the cp.
  3734. */
  3735. static void cik_hdp_flush_cp_ring_emit(struct radeon_device *rdev,
  3736. int ridx)
  3737. {
  3738. struct radeon_ring *ring = &rdev->ring[ridx];
  3739. u32 ref_and_mask;
  3740. switch (ring->idx) {
  3741. case CAYMAN_RING_TYPE_CP1_INDEX:
  3742. case CAYMAN_RING_TYPE_CP2_INDEX:
  3743. default:
  3744. switch (ring->me) {
  3745. case 0:
  3746. ref_and_mask = CP2 << ring->pipe;
  3747. break;
  3748. case 1:
  3749. ref_and_mask = CP6 << ring->pipe;
  3750. break;
  3751. default:
  3752. return;
  3753. }
  3754. break;
  3755. case RADEON_RING_TYPE_GFX_INDEX:
  3756. ref_and_mask = CP0;
  3757. break;
  3758. }
  3759. radeon_ring_write(ring, PACKET3(PACKET3_WAIT_REG_MEM, 5));
  3760. radeon_ring_write(ring, (WAIT_REG_MEM_OPERATION(1) | /* write, wait, write */
  3761. WAIT_REG_MEM_FUNCTION(3) | /* == */
  3762. WAIT_REG_MEM_ENGINE(1))); /* pfp */
  3763. radeon_ring_write(ring, GPU_HDP_FLUSH_REQ >> 2);
  3764. radeon_ring_write(ring, GPU_HDP_FLUSH_DONE >> 2);
  3765. radeon_ring_write(ring, ref_and_mask);
  3766. radeon_ring_write(ring, ref_and_mask);
  3767. radeon_ring_write(ring, 0x20); /* poll interval */
  3768. }
  3769. /**
  3770. * cik_fence_gfx_ring_emit - emit a fence on the gfx ring
  3771. *
  3772. * @rdev: radeon_device pointer
  3773. * @fence: radeon fence object
  3774. *
  3775. * Emits a fence sequnce number on the gfx ring and flushes
  3776. * GPU caches.
  3777. */
  3778. void cik_fence_gfx_ring_emit(struct radeon_device *rdev,
  3779. struct radeon_fence *fence)
  3780. {
  3781. struct radeon_ring *ring = &rdev->ring[fence->ring];
  3782. u64 addr = rdev->fence_drv[fence->ring].gpu_addr;
  3783. /* Workaround for cache flush problems. First send a dummy EOP
  3784. * event down the pipe with seq one below.
  3785. */
  3786. radeon_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE_EOP, 4));
  3787. radeon_ring_write(ring, (EOP_TCL1_ACTION_EN |
  3788. EOP_TC_ACTION_EN |
  3789. EVENT_TYPE(CACHE_FLUSH_AND_INV_TS_EVENT) |
  3790. EVENT_INDEX(5)));
  3791. radeon_ring_write(ring, addr & 0xfffffffc);
  3792. radeon_ring_write(ring, (upper_32_bits(addr) & 0xffff) |
  3793. DATA_SEL(1) | INT_SEL(0));
  3794. radeon_ring_write(ring, fence->seq - 1);
  3795. radeon_ring_write(ring, 0);
  3796. /* Then send the real EOP event down the pipe. */
  3797. radeon_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE_EOP, 4));
  3798. radeon_ring_write(ring, (EOP_TCL1_ACTION_EN |
  3799. EOP_TC_ACTION_EN |
  3800. EVENT_TYPE(CACHE_FLUSH_AND_INV_TS_EVENT) |
  3801. EVENT_INDEX(5)));
  3802. radeon_ring_write(ring, addr & 0xfffffffc);
  3803. radeon_ring_write(ring, (upper_32_bits(addr) & 0xffff) | DATA_SEL(1) | INT_SEL(2));
  3804. radeon_ring_write(ring, fence->seq);
  3805. radeon_ring_write(ring, 0);
  3806. }
  3807. /**
  3808. * cik_fence_compute_ring_emit - emit a fence on the compute ring
  3809. *
  3810. * @rdev: radeon_device pointer
  3811. * @fence: radeon fence object
  3812. *
  3813. * Emits a fence sequnce number on the compute ring and flushes
  3814. * GPU caches.
  3815. */
  3816. void cik_fence_compute_ring_emit(struct radeon_device *rdev,
  3817. struct radeon_fence *fence)
  3818. {
  3819. struct radeon_ring *ring = &rdev->ring[fence->ring];
  3820. u64 addr = rdev->fence_drv[fence->ring].gpu_addr;
  3821. /* RELEASE_MEM - flush caches, send int */
  3822. radeon_ring_write(ring, PACKET3(PACKET3_RELEASE_MEM, 5));
  3823. radeon_ring_write(ring, (EOP_TCL1_ACTION_EN |
  3824. EOP_TC_ACTION_EN |
  3825. EVENT_TYPE(CACHE_FLUSH_AND_INV_TS_EVENT) |
  3826. EVENT_INDEX(5)));
  3827. radeon_ring_write(ring, DATA_SEL(1) | INT_SEL(2));
  3828. radeon_ring_write(ring, addr & 0xfffffffc);
  3829. radeon_ring_write(ring, upper_32_bits(addr));
  3830. radeon_ring_write(ring, fence->seq);
  3831. radeon_ring_write(ring, 0);
  3832. }
  3833. /**
  3834. * cik_semaphore_ring_emit - emit a semaphore on the CP ring
  3835. *
  3836. * @rdev: radeon_device pointer
  3837. * @ring: radeon ring buffer object
  3838. * @semaphore: radeon semaphore object
  3839. * @emit_wait: Is this a sempahore wait?
  3840. *
  3841. * Emits a semaphore signal/wait packet to the CP ring and prevents the PFP
  3842. * from running ahead of semaphore waits.
  3843. */
  3844. bool cik_semaphore_ring_emit(struct radeon_device *rdev,
  3845. struct radeon_ring *ring,
  3846. struct radeon_semaphore *semaphore,
  3847. bool emit_wait)
  3848. {
  3849. uint64_t addr = semaphore->gpu_addr;
  3850. unsigned sel = emit_wait ? PACKET3_SEM_SEL_WAIT : PACKET3_SEM_SEL_SIGNAL;
  3851. radeon_ring_write(ring, PACKET3(PACKET3_MEM_SEMAPHORE, 1));
  3852. radeon_ring_write(ring, lower_32_bits(addr));
  3853. radeon_ring_write(ring, (upper_32_bits(addr) & 0xffff) | sel);
  3854. if (emit_wait && ring->idx == RADEON_RING_TYPE_GFX_INDEX) {
  3855. /* Prevent the PFP from running ahead of the semaphore wait */
  3856. radeon_ring_write(ring, PACKET3(PACKET3_PFP_SYNC_ME, 0));
  3857. radeon_ring_write(ring, 0x0);
  3858. }
  3859. return true;
  3860. }
  3861. /**
  3862. * cik_copy_cpdma - copy pages using the CP DMA engine
  3863. *
  3864. * @rdev: radeon_device pointer
  3865. * @src_offset: src GPU address
  3866. * @dst_offset: dst GPU address
  3867. * @num_gpu_pages: number of GPU pages to xfer
  3868. * @resv: reservation object to sync to
  3869. *
  3870. * Copy GPU paging using the CP DMA engine (CIK+).
  3871. * Used by the radeon ttm implementation to move pages if
  3872. * registered as the asic copy callback.
  3873. */
  3874. struct radeon_fence *cik_copy_cpdma(struct radeon_device *rdev,
  3875. uint64_t src_offset, uint64_t dst_offset,
  3876. unsigned num_gpu_pages,
  3877. struct reservation_object *resv)
  3878. {
  3879. struct radeon_fence *fence;
  3880. struct radeon_sync sync;
  3881. int ring_index = rdev->asic->copy.blit_ring_index;
  3882. struct radeon_ring *ring = &rdev->ring[ring_index];
  3883. u32 size_in_bytes, cur_size_in_bytes, control;
  3884. int i, num_loops;
  3885. int r = 0;
  3886. radeon_sync_create(&sync);
  3887. size_in_bytes = (num_gpu_pages << RADEON_GPU_PAGE_SHIFT);
  3888. num_loops = DIV_ROUND_UP(size_in_bytes, 0x1fffff);
  3889. r = radeon_ring_lock(rdev, ring, num_loops * 7 + 18);
  3890. if (r) {
  3891. DRM_ERROR("radeon: moving bo (%d).\n", r);
  3892. radeon_sync_free(rdev, &sync, NULL);
  3893. return ERR_PTR(r);
  3894. }
  3895. radeon_sync_resv(rdev, &sync, resv, false);
  3896. radeon_sync_rings(rdev, &sync, ring->idx);
  3897. for (i = 0; i < num_loops; i++) {
  3898. cur_size_in_bytes = size_in_bytes;
  3899. if (cur_size_in_bytes > 0x1fffff)
  3900. cur_size_in_bytes = 0x1fffff;
  3901. size_in_bytes -= cur_size_in_bytes;
  3902. control = 0;
  3903. if (size_in_bytes == 0)
  3904. control |= PACKET3_DMA_DATA_CP_SYNC;
  3905. radeon_ring_write(ring, PACKET3(PACKET3_DMA_DATA, 5));
  3906. radeon_ring_write(ring, control);
  3907. radeon_ring_write(ring, lower_32_bits(src_offset));
  3908. radeon_ring_write(ring, upper_32_bits(src_offset));
  3909. radeon_ring_write(ring, lower_32_bits(dst_offset));
  3910. radeon_ring_write(ring, upper_32_bits(dst_offset));
  3911. radeon_ring_write(ring, cur_size_in_bytes);
  3912. src_offset += cur_size_in_bytes;
  3913. dst_offset += cur_size_in_bytes;
  3914. }
  3915. r = radeon_fence_emit(rdev, &fence, ring->idx);
  3916. if (r) {
  3917. radeon_ring_unlock_undo(rdev, ring);
  3918. radeon_sync_free(rdev, &sync, NULL);
  3919. return ERR_PTR(r);
  3920. }
  3921. radeon_ring_unlock_commit(rdev, ring, false);
  3922. radeon_sync_free(rdev, &sync, fence);
  3923. return fence;
  3924. }
  3925. /*
  3926. * IB stuff
  3927. */
  3928. /**
  3929. * cik_ring_ib_execute - emit an IB (Indirect Buffer) on the gfx ring
  3930. *
  3931. * @rdev: radeon_device pointer
  3932. * @ib: radeon indirect buffer object
  3933. *
  3934. * Emits an DE (drawing engine) or CE (constant engine) IB
  3935. * on the gfx ring. IBs are usually generated by userspace
  3936. * acceleration drivers and submitted to the kernel for
  3937. * sheduling on the ring. This function schedules the IB
  3938. * on the gfx ring for execution by the GPU.
  3939. */
  3940. void cik_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib)
  3941. {
  3942. struct radeon_ring *ring = &rdev->ring[ib->ring];
  3943. unsigned vm_id = ib->vm ? ib->vm->ids[ib->ring].id : 0;
  3944. u32 header, control = INDIRECT_BUFFER_VALID;
  3945. if (ib->is_const_ib) {
  3946. /* set switch buffer packet before const IB */
  3947. radeon_ring_write(ring, PACKET3(PACKET3_SWITCH_BUFFER, 0));
  3948. radeon_ring_write(ring, 0);
  3949. header = PACKET3(PACKET3_INDIRECT_BUFFER_CONST, 2);
  3950. } else {
  3951. u32 next_rptr;
  3952. if (ring->rptr_save_reg) {
  3953. next_rptr = ring->wptr + 3 + 4;
  3954. radeon_ring_write(ring, PACKET3(PACKET3_SET_UCONFIG_REG, 1));
  3955. radeon_ring_write(ring, ((ring->rptr_save_reg -
  3956. PACKET3_SET_UCONFIG_REG_START) >> 2));
  3957. radeon_ring_write(ring, next_rptr);
  3958. } else if (rdev->wb.enabled) {
  3959. next_rptr = ring->wptr + 5 + 4;
  3960. radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  3961. radeon_ring_write(ring, WRITE_DATA_DST_SEL(1));
  3962. radeon_ring_write(ring, ring->next_rptr_gpu_addr & 0xfffffffc);
  3963. radeon_ring_write(ring, upper_32_bits(ring->next_rptr_gpu_addr));
  3964. radeon_ring_write(ring, next_rptr);
  3965. }
  3966. header = PACKET3(PACKET3_INDIRECT_BUFFER, 2);
  3967. }
  3968. control |= ib->length_dw | (vm_id << 24);
  3969. radeon_ring_write(ring, header);
  3970. radeon_ring_write(ring, (ib->gpu_addr & 0xFFFFFFFC));
  3971. radeon_ring_write(ring, upper_32_bits(ib->gpu_addr) & 0xFFFF);
  3972. radeon_ring_write(ring, control);
  3973. }
  3974. /**
  3975. * cik_ib_test - basic gfx ring IB test
  3976. *
  3977. * @rdev: radeon_device pointer
  3978. * @ring: radeon_ring structure holding ring information
  3979. *
  3980. * Allocate an IB and execute it on the gfx ring (CIK).
  3981. * Provides a basic gfx ring test to verify that IBs are working.
  3982. * Returns 0 on success, error on failure.
  3983. */
  3984. int cik_ib_test(struct radeon_device *rdev, struct radeon_ring *ring)
  3985. {
  3986. struct radeon_ib ib;
  3987. uint32_t scratch;
  3988. uint32_t tmp = 0;
  3989. unsigned i;
  3990. int r;
  3991. r = radeon_scratch_get(rdev, &scratch);
  3992. if (r) {
  3993. DRM_ERROR("radeon: failed to get scratch reg (%d).\n", r);
  3994. return r;
  3995. }
  3996. WREG32(scratch, 0xCAFEDEAD);
  3997. r = radeon_ib_get(rdev, ring->idx, &ib, NULL, 256);
  3998. if (r) {
  3999. DRM_ERROR("radeon: failed to get ib (%d).\n", r);
  4000. radeon_scratch_free(rdev, scratch);
  4001. return r;
  4002. }
  4003. ib.ptr[0] = PACKET3(PACKET3_SET_UCONFIG_REG, 1);
  4004. ib.ptr[1] = ((scratch - PACKET3_SET_UCONFIG_REG_START) >> 2);
  4005. ib.ptr[2] = 0xDEADBEEF;
  4006. ib.length_dw = 3;
  4007. r = radeon_ib_schedule(rdev, &ib, NULL, false);
  4008. if (r) {
  4009. radeon_scratch_free(rdev, scratch);
  4010. radeon_ib_free(rdev, &ib);
  4011. DRM_ERROR("radeon: failed to schedule ib (%d).\n", r);
  4012. return r;
  4013. }
  4014. r = radeon_fence_wait(ib.fence, false);
  4015. if (r) {
  4016. DRM_ERROR("radeon: fence wait failed (%d).\n", r);
  4017. radeon_scratch_free(rdev, scratch);
  4018. radeon_ib_free(rdev, &ib);
  4019. return r;
  4020. }
  4021. for (i = 0; i < rdev->usec_timeout; i++) {
  4022. tmp = RREG32(scratch);
  4023. if (tmp == 0xDEADBEEF)
  4024. break;
  4025. DRM_UDELAY(1);
  4026. }
  4027. if (i < rdev->usec_timeout) {
  4028. DRM_INFO("ib test on ring %d succeeded in %u usecs\n", ib.fence->ring, i);
  4029. } else {
  4030. DRM_ERROR("radeon: ib test failed (scratch(0x%04X)=0x%08X)\n",
  4031. scratch, tmp);
  4032. r = -EINVAL;
  4033. }
  4034. radeon_scratch_free(rdev, scratch);
  4035. radeon_ib_free(rdev, &ib);
  4036. return r;
  4037. }
  4038. /*
  4039. * CP.
  4040. * On CIK, gfx and compute now have independant command processors.
  4041. *
  4042. * GFX
  4043. * Gfx consists of a single ring and can process both gfx jobs and
  4044. * compute jobs. The gfx CP consists of three microengines (ME):
  4045. * PFP - Pre-Fetch Parser
  4046. * ME - Micro Engine
  4047. * CE - Constant Engine
  4048. * The PFP and ME make up what is considered the Drawing Engine (DE).
  4049. * The CE is an asynchronous engine used for updating buffer desciptors
  4050. * used by the DE so that they can be loaded into cache in parallel
  4051. * while the DE is processing state update packets.
  4052. *
  4053. * Compute
  4054. * The compute CP consists of two microengines (ME):
  4055. * MEC1 - Compute MicroEngine 1
  4056. * MEC2 - Compute MicroEngine 2
  4057. * Each MEC supports 4 compute pipes and each pipe supports 8 queues.
  4058. * The queues are exposed to userspace and are programmed directly
  4059. * by the compute runtime.
  4060. */
  4061. /**
  4062. * cik_cp_gfx_enable - enable/disable the gfx CP MEs
  4063. *
  4064. * @rdev: radeon_device pointer
  4065. * @enable: enable or disable the MEs
  4066. *
  4067. * Halts or unhalts the gfx MEs.
  4068. */
  4069. static void cik_cp_gfx_enable(struct radeon_device *rdev, bool enable)
  4070. {
  4071. if (enable)
  4072. WREG32(CP_ME_CNTL, 0);
  4073. else {
  4074. if (rdev->asic->copy.copy_ring_index == RADEON_RING_TYPE_GFX_INDEX)
  4075. radeon_ttm_set_active_vram_size(rdev, rdev->mc.visible_vram_size);
  4076. WREG32(CP_ME_CNTL, (CP_ME_HALT | CP_PFP_HALT | CP_CE_HALT));
  4077. rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false;
  4078. }
  4079. udelay(50);
  4080. }
  4081. /**
  4082. * cik_cp_gfx_load_microcode - load the gfx CP ME ucode
  4083. *
  4084. * @rdev: radeon_device pointer
  4085. *
  4086. * Loads the gfx PFP, ME, and CE ucode.
  4087. * Returns 0 for success, -EINVAL if the ucode is not available.
  4088. */
  4089. static int cik_cp_gfx_load_microcode(struct radeon_device *rdev)
  4090. {
  4091. int i;
  4092. if (!rdev->me_fw || !rdev->pfp_fw || !rdev->ce_fw)
  4093. return -EINVAL;
  4094. cik_cp_gfx_enable(rdev, false);
  4095. if (rdev->new_fw) {
  4096. const struct gfx_firmware_header_v1_0 *pfp_hdr =
  4097. (const struct gfx_firmware_header_v1_0 *)rdev->pfp_fw->data;
  4098. const struct gfx_firmware_header_v1_0 *ce_hdr =
  4099. (const struct gfx_firmware_header_v1_0 *)rdev->ce_fw->data;
  4100. const struct gfx_firmware_header_v1_0 *me_hdr =
  4101. (const struct gfx_firmware_header_v1_0 *)rdev->me_fw->data;
  4102. const __le32 *fw_data;
  4103. u32 fw_size;
  4104. radeon_ucode_print_gfx_hdr(&pfp_hdr->header);
  4105. radeon_ucode_print_gfx_hdr(&ce_hdr->header);
  4106. radeon_ucode_print_gfx_hdr(&me_hdr->header);
  4107. /* PFP */
  4108. fw_data = (const __le32 *)
  4109. (rdev->pfp_fw->data + le32_to_cpu(pfp_hdr->header.ucode_array_offset_bytes));
  4110. fw_size = le32_to_cpu(pfp_hdr->header.ucode_size_bytes) / 4;
  4111. WREG32(CP_PFP_UCODE_ADDR, 0);
  4112. for (i = 0; i < fw_size; i++)
  4113. WREG32(CP_PFP_UCODE_DATA, le32_to_cpup(fw_data++));
  4114. WREG32(CP_PFP_UCODE_ADDR, le32_to_cpu(pfp_hdr->header.ucode_version));
  4115. /* CE */
  4116. fw_data = (const __le32 *)
  4117. (rdev->ce_fw->data + le32_to_cpu(ce_hdr->header.ucode_array_offset_bytes));
  4118. fw_size = le32_to_cpu(ce_hdr->header.ucode_size_bytes) / 4;
  4119. WREG32(CP_CE_UCODE_ADDR, 0);
  4120. for (i = 0; i < fw_size; i++)
  4121. WREG32(CP_CE_UCODE_DATA, le32_to_cpup(fw_data++));
  4122. WREG32(CP_CE_UCODE_ADDR, le32_to_cpu(ce_hdr->header.ucode_version));
  4123. /* ME */
  4124. fw_data = (const __be32 *)
  4125. (rdev->me_fw->data + le32_to_cpu(me_hdr->header.ucode_array_offset_bytes));
  4126. fw_size = le32_to_cpu(me_hdr->header.ucode_size_bytes) / 4;
  4127. WREG32(CP_ME_RAM_WADDR, 0);
  4128. for (i = 0; i < fw_size; i++)
  4129. WREG32(CP_ME_RAM_DATA, le32_to_cpup(fw_data++));
  4130. WREG32(CP_ME_RAM_WADDR, le32_to_cpu(me_hdr->header.ucode_version));
  4131. WREG32(CP_ME_RAM_RADDR, le32_to_cpu(me_hdr->header.ucode_version));
  4132. } else {
  4133. const __be32 *fw_data;
  4134. /* PFP */
  4135. fw_data = (const __be32 *)rdev->pfp_fw->data;
  4136. WREG32(CP_PFP_UCODE_ADDR, 0);
  4137. for (i = 0; i < CIK_PFP_UCODE_SIZE; i++)
  4138. WREG32(CP_PFP_UCODE_DATA, be32_to_cpup(fw_data++));
  4139. WREG32(CP_PFP_UCODE_ADDR, 0);
  4140. /* CE */
  4141. fw_data = (const __be32 *)rdev->ce_fw->data;
  4142. WREG32(CP_CE_UCODE_ADDR, 0);
  4143. for (i = 0; i < CIK_CE_UCODE_SIZE; i++)
  4144. WREG32(CP_CE_UCODE_DATA, be32_to_cpup(fw_data++));
  4145. WREG32(CP_CE_UCODE_ADDR, 0);
  4146. /* ME */
  4147. fw_data = (const __be32 *)rdev->me_fw->data;
  4148. WREG32(CP_ME_RAM_WADDR, 0);
  4149. for (i = 0; i < CIK_ME_UCODE_SIZE; i++)
  4150. WREG32(CP_ME_RAM_DATA, be32_to_cpup(fw_data++));
  4151. WREG32(CP_ME_RAM_WADDR, 0);
  4152. }
  4153. return 0;
  4154. }
  4155. /**
  4156. * cik_cp_gfx_start - start the gfx ring
  4157. *
  4158. * @rdev: radeon_device pointer
  4159. *
  4160. * Enables the ring and loads the clear state context and other
  4161. * packets required to init the ring.
  4162. * Returns 0 for success, error for failure.
  4163. */
  4164. static int cik_cp_gfx_start(struct radeon_device *rdev)
  4165. {
  4166. struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  4167. int r, i;
  4168. /* init the CP */
  4169. WREG32(CP_MAX_CONTEXT, rdev->config.cik.max_hw_contexts - 1);
  4170. WREG32(CP_ENDIAN_SWAP, 0);
  4171. WREG32(CP_DEVICE_ID, 1);
  4172. cik_cp_gfx_enable(rdev, true);
  4173. r = radeon_ring_lock(rdev, ring, cik_default_size + 17);
  4174. if (r) {
  4175. DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
  4176. return r;
  4177. }
  4178. /* init the CE partitions. CE only used for gfx on CIK */
  4179. radeon_ring_write(ring, PACKET3(PACKET3_SET_BASE, 2));
  4180. radeon_ring_write(ring, PACKET3_BASE_INDEX(CE_PARTITION_BASE));
  4181. radeon_ring_write(ring, 0x8000);
  4182. radeon_ring_write(ring, 0x8000);
  4183. /* setup clear context state */
  4184. radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
  4185. radeon_ring_write(ring, PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);
  4186. radeon_ring_write(ring, PACKET3(PACKET3_CONTEXT_CONTROL, 1));
  4187. radeon_ring_write(ring, 0x80000000);
  4188. radeon_ring_write(ring, 0x80000000);
  4189. for (i = 0; i < cik_default_size; i++)
  4190. radeon_ring_write(ring, cik_default_state[i]);
  4191. radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
  4192. radeon_ring_write(ring, PACKET3_PREAMBLE_END_CLEAR_STATE);
  4193. /* set clear context state */
  4194. radeon_ring_write(ring, PACKET3(PACKET3_CLEAR_STATE, 0));
  4195. radeon_ring_write(ring, 0);
  4196. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 2));
  4197. radeon_ring_write(ring, 0x00000316);
  4198. radeon_ring_write(ring, 0x0000000e); /* VGT_VERTEX_REUSE_BLOCK_CNTL */
  4199. radeon_ring_write(ring, 0x00000010); /* VGT_OUT_DEALLOC_CNTL */
  4200. radeon_ring_unlock_commit(rdev, ring, false);
  4201. return 0;
  4202. }
  4203. /**
  4204. * cik_cp_gfx_fini - stop the gfx ring
  4205. *
  4206. * @rdev: radeon_device pointer
  4207. *
  4208. * Stop the gfx ring and tear down the driver ring
  4209. * info.
  4210. */
  4211. static void cik_cp_gfx_fini(struct radeon_device *rdev)
  4212. {
  4213. cik_cp_gfx_enable(rdev, false);
  4214. radeon_ring_fini(rdev, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]);
  4215. }
  4216. /**
  4217. * cik_cp_gfx_resume - setup the gfx ring buffer registers
  4218. *
  4219. * @rdev: radeon_device pointer
  4220. *
  4221. * Program the location and size of the gfx ring buffer
  4222. * and test it to make sure it's working.
  4223. * Returns 0 for success, error for failure.
  4224. */
  4225. static int cik_cp_gfx_resume(struct radeon_device *rdev)
  4226. {
  4227. struct radeon_ring *ring;
  4228. u32 tmp;
  4229. u32 rb_bufsz;
  4230. u64 rb_addr;
  4231. int r;
  4232. WREG32(CP_SEM_WAIT_TIMER, 0x0);
  4233. if (rdev->family != CHIP_HAWAII)
  4234. WREG32(CP_SEM_INCOMPLETE_TIMER_CNTL, 0x0);
  4235. /* Set the write pointer delay */
  4236. WREG32(CP_RB_WPTR_DELAY, 0);
  4237. /* set the RB to use vmid 0 */
  4238. WREG32(CP_RB_VMID, 0);
  4239. WREG32(SCRATCH_ADDR, ((rdev->wb.gpu_addr + RADEON_WB_SCRATCH_OFFSET) >> 8) & 0xFFFFFFFF);
  4240. /* ring 0 - compute and gfx */
  4241. /* Set ring buffer size */
  4242. ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  4243. rb_bufsz = order_base_2(ring->ring_size / 8);
  4244. tmp = (order_base_2(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
  4245. #ifdef __BIG_ENDIAN
  4246. tmp |= BUF_SWAP_32BIT;
  4247. #endif
  4248. WREG32(CP_RB0_CNTL, tmp);
  4249. /* Initialize the ring buffer's read and write pointers */
  4250. WREG32(CP_RB0_CNTL, tmp | RB_RPTR_WR_ENA);
  4251. ring->wptr = 0;
  4252. WREG32(CP_RB0_WPTR, ring->wptr);
  4253. /* set the wb address wether it's enabled or not */
  4254. WREG32(CP_RB0_RPTR_ADDR, (rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFFFFFFFC);
  4255. WREG32(CP_RB0_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFF);
  4256. /* scratch register shadowing is no longer supported */
  4257. WREG32(SCRATCH_UMSK, 0);
  4258. if (!rdev->wb.enabled)
  4259. tmp |= RB_NO_UPDATE;
  4260. mdelay(1);
  4261. WREG32(CP_RB0_CNTL, tmp);
  4262. rb_addr = ring->gpu_addr >> 8;
  4263. WREG32(CP_RB0_BASE, rb_addr);
  4264. WREG32(CP_RB0_BASE_HI, upper_32_bits(rb_addr));
  4265. /* start the ring */
  4266. cik_cp_gfx_start(rdev);
  4267. rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = true;
  4268. r = radeon_ring_test(rdev, RADEON_RING_TYPE_GFX_INDEX, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]);
  4269. if (r) {
  4270. rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false;
  4271. return r;
  4272. }
  4273. if (rdev->asic->copy.copy_ring_index == RADEON_RING_TYPE_GFX_INDEX)
  4274. radeon_ttm_set_active_vram_size(rdev, rdev->mc.real_vram_size);
  4275. return 0;
  4276. }
  4277. u32 cik_gfx_get_rptr(struct radeon_device *rdev,
  4278. struct radeon_ring *ring)
  4279. {
  4280. u32 rptr;
  4281. if (rdev->wb.enabled)
  4282. rptr = rdev->wb.wb[ring->rptr_offs/4];
  4283. else
  4284. rptr = RREG32(CP_RB0_RPTR);
  4285. return rptr;
  4286. }
  4287. u32 cik_gfx_get_wptr(struct radeon_device *rdev,
  4288. struct radeon_ring *ring)
  4289. {
  4290. u32 wptr;
  4291. wptr = RREG32(CP_RB0_WPTR);
  4292. return wptr;
  4293. }
  4294. void cik_gfx_set_wptr(struct radeon_device *rdev,
  4295. struct radeon_ring *ring)
  4296. {
  4297. WREG32(CP_RB0_WPTR, ring->wptr);
  4298. (void)RREG32(CP_RB0_WPTR);
  4299. }
  4300. u32 cik_compute_get_rptr(struct radeon_device *rdev,
  4301. struct radeon_ring *ring)
  4302. {
  4303. u32 rptr;
  4304. if (rdev->wb.enabled) {
  4305. rptr = rdev->wb.wb[ring->rptr_offs/4];
  4306. } else {
  4307. mutex_lock(&rdev->srbm_mutex);
  4308. cik_srbm_select(rdev, ring->me, ring->pipe, ring->queue, 0);
  4309. rptr = RREG32(CP_HQD_PQ_RPTR);
  4310. cik_srbm_select(rdev, 0, 0, 0, 0);
  4311. mutex_unlock(&rdev->srbm_mutex);
  4312. }
  4313. return rptr;
  4314. }
  4315. u32 cik_compute_get_wptr(struct radeon_device *rdev,
  4316. struct radeon_ring *ring)
  4317. {
  4318. u32 wptr;
  4319. if (rdev->wb.enabled) {
  4320. /* XXX check if swapping is necessary on BE */
  4321. wptr = rdev->wb.wb[ring->wptr_offs/4];
  4322. } else {
  4323. mutex_lock(&rdev->srbm_mutex);
  4324. cik_srbm_select(rdev, ring->me, ring->pipe, ring->queue, 0);
  4325. wptr = RREG32(CP_HQD_PQ_WPTR);
  4326. cik_srbm_select(rdev, 0, 0, 0, 0);
  4327. mutex_unlock(&rdev->srbm_mutex);
  4328. }
  4329. return wptr;
  4330. }
  4331. void cik_compute_set_wptr(struct radeon_device *rdev,
  4332. struct radeon_ring *ring)
  4333. {
  4334. /* XXX check if swapping is necessary on BE */
  4335. rdev->wb.wb[ring->wptr_offs/4] = ring->wptr;
  4336. WDOORBELL32(ring->doorbell_index, ring->wptr);
  4337. }
  4338. static void cik_compute_stop(struct radeon_device *rdev,
  4339. struct radeon_ring *ring)
  4340. {
  4341. u32 j, tmp;
  4342. cik_srbm_select(rdev, ring->me, ring->pipe, ring->queue, 0);
  4343. /* Disable wptr polling. */
  4344. tmp = RREG32(CP_PQ_WPTR_POLL_CNTL);
  4345. tmp &= ~WPTR_POLL_EN;
  4346. WREG32(CP_PQ_WPTR_POLL_CNTL, tmp);
  4347. /* Disable HQD. */
  4348. if (RREG32(CP_HQD_ACTIVE) & 1) {
  4349. WREG32(CP_HQD_DEQUEUE_REQUEST, 1);
  4350. for (j = 0; j < rdev->usec_timeout; j++) {
  4351. if (!(RREG32(CP_HQD_ACTIVE) & 1))
  4352. break;
  4353. udelay(1);
  4354. }
  4355. WREG32(CP_HQD_DEQUEUE_REQUEST, 0);
  4356. WREG32(CP_HQD_PQ_RPTR, 0);
  4357. WREG32(CP_HQD_PQ_WPTR, 0);
  4358. }
  4359. cik_srbm_select(rdev, 0, 0, 0, 0);
  4360. }
  4361. /**
  4362. * cik_cp_compute_enable - enable/disable the compute CP MEs
  4363. *
  4364. * @rdev: radeon_device pointer
  4365. * @enable: enable or disable the MEs
  4366. *
  4367. * Halts or unhalts the compute MEs.
  4368. */
  4369. static void cik_cp_compute_enable(struct radeon_device *rdev, bool enable)
  4370. {
  4371. if (enable)
  4372. WREG32(CP_MEC_CNTL, 0);
  4373. else {
  4374. /*
  4375. * To make hibernation reliable we need to clear compute ring
  4376. * configuration before halting the compute ring.
  4377. */
  4378. mutex_lock(&rdev->srbm_mutex);
  4379. cik_compute_stop(rdev,&rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX]);
  4380. cik_compute_stop(rdev,&rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX]);
  4381. mutex_unlock(&rdev->srbm_mutex);
  4382. WREG32(CP_MEC_CNTL, (MEC_ME1_HALT | MEC_ME2_HALT));
  4383. rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX].ready = false;
  4384. rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX].ready = false;
  4385. }
  4386. udelay(50);
  4387. }
  4388. /**
  4389. * cik_cp_compute_load_microcode - load the compute CP ME ucode
  4390. *
  4391. * @rdev: radeon_device pointer
  4392. *
  4393. * Loads the compute MEC1&2 ucode.
  4394. * Returns 0 for success, -EINVAL if the ucode is not available.
  4395. */
  4396. static int cik_cp_compute_load_microcode(struct radeon_device *rdev)
  4397. {
  4398. int i;
  4399. if (!rdev->mec_fw)
  4400. return -EINVAL;
  4401. cik_cp_compute_enable(rdev, false);
  4402. if (rdev->new_fw) {
  4403. const struct gfx_firmware_header_v1_0 *mec_hdr =
  4404. (const struct gfx_firmware_header_v1_0 *)rdev->mec_fw->data;
  4405. const __le32 *fw_data;
  4406. u32 fw_size;
  4407. radeon_ucode_print_gfx_hdr(&mec_hdr->header);
  4408. /* MEC1 */
  4409. fw_data = (const __le32 *)
  4410. (rdev->mec_fw->data + le32_to_cpu(mec_hdr->header.ucode_array_offset_bytes));
  4411. fw_size = le32_to_cpu(mec_hdr->header.ucode_size_bytes) / 4;
  4412. WREG32(CP_MEC_ME1_UCODE_ADDR, 0);
  4413. for (i = 0; i < fw_size; i++)
  4414. WREG32(CP_MEC_ME1_UCODE_DATA, le32_to_cpup(fw_data++));
  4415. WREG32(CP_MEC_ME1_UCODE_ADDR, le32_to_cpu(mec_hdr->header.ucode_version));
  4416. /* MEC2 */
  4417. if (rdev->family == CHIP_KAVERI) {
  4418. const struct gfx_firmware_header_v1_0 *mec2_hdr =
  4419. (const struct gfx_firmware_header_v1_0 *)rdev->mec2_fw->data;
  4420. fw_data = (const __le32 *)
  4421. (rdev->mec2_fw->data +
  4422. le32_to_cpu(mec2_hdr->header.ucode_array_offset_bytes));
  4423. fw_size = le32_to_cpu(mec2_hdr->header.ucode_size_bytes) / 4;
  4424. WREG32(CP_MEC_ME2_UCODE_ADDR, 0);
  4425. for (i = 0; i < fw_size; i++)
  4426. WREG32(CP_MEC_ME2_UCODE_DATA, le32_to_cpup(fw_data++));
  4427. WREG32(CP_MEC_ME2_UCODE_ADDR, le32_to_cpu(mec2_hdr->header.ucode_version));
  4428. }
  4429. } else {
  4430. const __be32 *fw_data;
  4431. /* MEC1 */
  4432. fw_data = (const __be32 *)rdev->mec_fw->data;
  4433. WREG32(CP_MEC_ME1_UCODE_ADDR, 0);
  4434. for (i = 0; i < CIK_MEC_UCODE_SIZE; i++)
  4435. WREG32(CP_MEC_ME1_UCODE_DATA, be32_to_cpup(fw_data++));
  4436. WREG32(CP_MEC_ME1_UCODE_ADDR, 0);
  4437. if (rdev->family == CHIP_KAVERI) {
  4438. /* MEC2 */
  4439. fw_data = (const __be32 *)rdev->mec_fw->data;
  4440. WREG32(CP_MEC_ME2_UCODE_ADDR, 0);
  4441. for (i = 0; i < CIK_MEC_UCODE_SIZE; i++)
  4442. WREG32(CP_MEC_ME2_UCODE_DATA, be32_to_cpup(fw_data++));
  4443. WREG32(CP_MEC_ME2_UCODE_ADDR, 0);
  4444. }
  4445. }
  4446. return 0;
  4447. }
  4448. /**
  4449. * cik_cp_compute_start - start the compute queues
  4450. *
  4451. * @rdev: radeon_device pointer
  4452. *
  4453. * Enable the compute queues.
  4454. * Returns 0 for success, error for failure.
  4455. */
  4456. static int cik_cp_compute_start(struct radeon_device *rdev)
  4457. {
  4458. cik_cp_compute_enable(rdev, true);
  4459. return 0;
  4460. }
  4461. /**
  4462. * cik_cp_compute_fini - stop the compute queues
  4463. *
  4464. * @rdev: radeon_device pointer
  4465. *
  4466. * Stop the compute queues and tear down the driver queue
  4467. * info.
  4468. */
  4469. static void cik_cp_compute_fini(struct radeon_device *rdev)
  4470. {
  4471. int i, idx, r;
  4472. cik_cp_compute_enable(rdev, false);
  4473. for (i = 0; i < 2; i++) {
  4474. if (i == 0)
  4475. idx = CAYMAN_RING_TYPE_CP1_INDEX;
  4476. else
  4477. idx = CAYMAN_RING_TYPE_CP2_INDEX;
  4478. if (rdev->ring[idx].mqd_obj) {
  4479. r = radeon_bo_reserve(rdev->ring[idx].mqd_obj, false);
  4480. if (unlikely(r != 0))
  4481. dev_warn(rdev->dev, "(%d) reserve MQD bo failed\n", r);
  4482. radeon_bo_unpin(rdev->ring[idx].mqd_obj);
  4483. radeon_bo_unreserve(rdev->ring[idx].mqd_obj);
  4484. radeon_bo_unref(&rdev->ring[idx].mqd_obj);
  4485. rdev->ring[idx].mqd_obj = NULL;
  4486. }
  4487. }
  4488. }
  4489. static void cik_mec_fini(struct radeon_device *rdev)
  4490. {
  4491. int r;
  4492. if (rdev->mec.hpd_eop_obj) {
  4493. r = radeon_bo_reserve(rdev->mec.hpd_eop_obj, false);
  4494. if (unlikely(r != 0))
  4495. dev_warn(rdev->dev, "(%d) reserve HPD EOP bo failed\n", r);
  4496. radeon_bo_unpin(rdev->mec.hpd_eop_obj);
  4497. radeon_bo_unreserve(rdev->mec.hpd_eop_obj);
  4498. radeon_bo_unref(&rdev->mec.hpd_eop_obj);
  4499. rdev->mec.hpd_eop_obj = NULL;
  4500. }
  4501. }
  4502. #define MEC_HPD_SIZE 2048
  4503. static int cik_mec_init(struct radeon_device *rdev)
  4504. {
  4505. int r;
  4506. u32 *hpd;
  4507. /*
  4508. * KV: 2 MEC, 4 Pipes/MEC, 8 Queues/Pipe - 64 Queues total
  4509. * CI/KB: 1 MEC, 4 Pipes/MEC, 8 Queues/Pipe - 32 Queues total
  4510. * Nonetheless, we assign only 1 pipe because all other pipes will
  4511. * be handled by KFD
  4512. */
  4513. rdev->mec.num_mec = 1;
  4514. rdev->mec.num_pipe = 1;
  4515. rdev->mec.num_queue = rdev->mec.num_mec * rdev->mec.num_pipe * 8;
  4516. if (rdev->mec.hpd_eop_obj == NULL) {
  4517. r = radeon_bo_create(rdev,
  4518. rdev->mec.num_mec *rdev->mec.num_pipe * MEC_HPD_SIZE * 2,
  4519. PAGE_SIZE, true,
  4520. RADEON_GEM_DOMAIN_GTT, 0, NULL, NULL,
  4521. &rdev->mec.hpd_eop_obj);
  4522. if (r) {
  4523. dev_warn(rdev->dev, "(%d) create HDP EOP bo failed\n", r);
  4524. return r;
  4525. }
  4526. }
  4527. r = radeon_bo_reserve(rdev->mec.hpd_eop_obj, false);
  4528. if (unlikely(r != 0)) {
  4529. cik_mec_fini(rdev);
  4530. return r;
  4531. }
  4532. r = radeon_bo_pin(rdev->mec.hpd_eop_obj, RADEON_GEM_DOMAIN_GTT,
  4533. &rdev->mec.hpd_eop_gpu_addr);
  4534. if (r) {
  4535. dev_warn(rdev->dev, "(%d) pin HDP EOP bo failed\n", r);
  4536. cik_mec_fini(rdev);
  4537. return r;
  4538. }
  4539. r = radeon_bo_kmap(rdev->mec.hpd_eop_obj, (void **)&hpd);
  4540. if (r) {
  4541. dev_warn(rdev->dev, "(%d) map HDP EOP bo failed\n", r);
  4542. cik_mec_fini(rdev);
  4543. return r;
  4544. }
  4545. /* clear memory. Not sure if this is required or not */
  4546. memset(hpd, 0, rdev->mec.num_mec *rdev->mec.num_pipe * MEC_HPD_SIZE * 2);
  4547. radeon_bo_kunmap(rdev->mec.hpd_eop_obj);
  4548. radeon_bo_unreserve(rdev->mec.hpd_eop_obj);
  4549. return 0;
  4550. }
  4551. struct hqd_registers
  4552. {
  4553. u32 cp_mqd_base_addr;
  4554. u32 cp_mqd_base_addr_hi;
  4555. u32 cp_hqd_active;
  4556. u32 cp_hqd_vmid;
  4557. u32 cp_hqd_persistent_state;
  4558. u32 cp_hqd_pipe_priority;
  4559. u32 cp_hqd_queue_priority;
  4560. u32 cp_hqd_quantum;
  4561. u32 cp_hqd_pq_base;
  4562. u32 cp_hqd_pq_base_hi;
  4563. u32 cp_hqd_pq_rptr;
  4564. u32 cp_hqd_pq_rptr_report_addr;
  4565. u32 cp_hqd_pq_rptr_report_addr_hi;
  4566. u32 cp_hqd_pq_wptr_poll_addr;
  4567. u32 cp_hqd_pq_wptr_poll_addr_hi;
  4568. u32 cp_hqd_pq_doorbell_control;
  4569. u32 cp_hqd_pq_wptr;
  4570. u32 cp_hqd_pq_control;
  4571. u32 cp_hqd_ib_base_addr;
  4572. u32 cp_hqd_ib_base_addr_hi;
  4573. u32 cp_hqd_ib_rptr;
  4574. u32 cp_hqd_ib_control;
  4575. u32 cp_hqd_iq_timer;
  4576. u32 cp_hqd_iq_rptr;
  4577. u32 cp_hqd_dequeue_request;
  4578. u32 cp_hqd_dma_offload;
  4579. u32 cp_hqd_sema_cmd;
  4580. u32 cp_hqd_msg_type;
  4581. u32 cp_hqd_atomic0_preop_lo;
  4582. u32 cp_hqd_atomic0_preop_hi;
  4583. u32 cp_hqd_atomic1_preop_lo;
  4584. u32 cp_hqd_atomic1_preop_hi;
  4585. u32 cp_hqd_hq_scheduler0;
  4586. u32 cp_hqd_hq_scheduler1;
  4587. u32 cp_mqd_control;
  4588. };
  4589. struct bonaire_mqd
  4590. {
  4591. u32 header;
  4592. u32 dispatch_initiator;
  4593. u32 dimensions[3];
  4594. u32 start_idx[3];
  4595. u32 num_threads[3];
  4596. u32 pipeline_stat_enable;
  4597. u32 perf_counter_enable;
  4598. u32 pgm[2];
  4599. u32 tba[2];
  4600. u32 tma[2];
  4601. u32 pgm_rsrc[2];
  4602. u32 vmid;
  4603. u32 resource_limits;
  4604. u32 static_thread_mgmt01[2];
  4605. u32 tmp_ring_size;
  4606. u32 static_thread_mgmt23[2];
  4607. u32 restart[3];
  4608. u32 thread_trace_enable;
  4609. u32 reserved1;
  4610. u32 user_data[16];
  4611. u32 vgtcs_invoke_count[2];
  4612. struct hqd_registers queue_state;
  4613. u32 dequeue_cntr;
  4614. u32 interrupt_queue[64];
  4615. };
  4616. /**
  4617. * cik_cp_compute_resume - setup the compute queue registers
  4618. *
  4619. * @rdev: radeon_device pointer
  4620. *
  4621. * Program the compute queues and test them to make sure they
  4622. * are working.
  4623. * Returns 0 for success, error for failure.
  4624. */
  4625. static int cik_cp_compute_resume(struct radeon_device *rdev)
  4626. {
  4627. int r, i, j, idx;
  4628. u32 tmp;
  4629. bool use_doorbell = true;
  4630. u64 hqd_gpu_addr;
  4631. u64 mqd_gpu_addr;
  4632. u64 eop_gpu_addr;
  4633. u64 wb_gpu_addr;
  4634. u32 *buf;
  4635. struct bonaire_mqd *mqd;
  4636. r = cik_cp_compute_start(rdev);
  4637. if (r)
  4638. return r;
  4639. /* fix up chicken bits */
  4640. tmp = RREG32(CP_CPF_DEBUG);
  4641. tmp |= (1 << 23);
  4642. WREG32(CP_CPF_DEBUG, tmp);
  4643. /* init the pipes */
  4644. mutex_lock(&rdev->srbm_mutex);
  4645. eop_gpu_addr = rdev->mec.hpd_eop_gpu_addr;
  4646. cik_srbm_select(rdev, 0, 0, 0, 0);
  4647. /* write the EOP addr */
  4648. WREG32(CP_HPD_EOP_BASE_ADDR, eop_gpu_addr >> 8);
  4649. WREG32(CP_HPD_EOP_BASE_ADDR_HI, upper_32_bits(eop_gpu_addr) >> 8);
  4650. /* set the VMID assigned */
  4651. WREG32(CP_HPD_EOP_VMID, 0);
  4652. /* set the EOP size, register value is 2^(EOP_SIZE+1) dwords */
  4653. tmp = RREG32(CP_HPD_EOP_CONTROL);
  4654. tmp &= ~EOP_SIZE_MASK;
  4655. tmp |= order_base_2(MEC_HPD_SIZE / 8);
  4656. WREG32(CP_HPD_EOP_CONTROL, tmp);
  4657. mutex_unlock(&rdev->srbm_mutex);
  4658. /* init the queues. Just two for now. */
  4659. for (i = 0; i < 2; i++) {
  4660. if (i == 0)
  4661. idx = CAYMAN_RING_TYPE_CP1_INDEX;
  4662. else
  4663. idx = CAYMAN_RING_TYPE_CP2_INDEX;
  4664. if (rdev->ring[idx].mqd_obj == NULL) {
  4665. r = radeon_bo_create(rdev,
  4666. sizeof(struct bonaire_mqd),
  4667. PAGE_SIZE, true,
  4668. RADEON_GEM_DOMAIN_GTT, 0, NULL,
  4669. NULL, &rdev->ring[idx].mqd_obj);
  4670. if (r) {
  4671. dev_warn(rdev->dev, "(%d) create MQD bo failed\n", r);
  4672. return r;
  4673. }
  4674. }
  4675. r = radeon_bo_reserve(rdev->ring[idx].mqd_obj, false);
  4676. if (unlikely(r != 0)) {
  4677. cik_cp_compute_fini(rdev);
  4678. return r;
  4679. }
  4680. r = radeon_bo_pin(rdev->ring[idx].mqd_obj, RADEON_GEM_DOMAIN_GTT,
  4681. &mqd_gpu_addr);
  4682. if (r) {
  4683. dev_warn(rdev->dev, "(%d) pin MQD bo failed\n", r);
  4684. cik_cp_compute_fini(rdev);
  4685. return r;
  4686. }
  4687. r = radeon_bo_kmap(rdev->ring[idx].mqd_obj, (void **)&buf);
  4688. if (r) {
  4689. dev_warn(rdev->dev, "(%d) map MQD bo failed\n", r);
  4690. cik_cp_compute_fini(rdev);
  4691. return r;
  4692. }
  4693. /* init the mqd struct */
  4694. memset(buf, 0, sizeof(struct bonaire_mqd));
  4695. mqd = (struct bonaire_mqd *)buf;
  4696. mqd->header = 0xC0310800;
  4697. mqd->static_thread_mgmt01[0] = 0xffffffff;
  4698. mqd->static_thread_mgmt01[1] = 0xffffffff;
  4699. mqd->static_thread_mgmt23[0] = 0xffffffff;
  4700. mqd->static_thread_mgmt23[1] = 0xffffffff;
  4701. mutex_lock(&rdev->srbm_mutex);
  4702. cik_srbm_select(rdev, rdev->ring[idx].me,
  4703. rdev->ring[idx].pipe,
  4704. rdev->ring[idx].queue, 0);
  4705. /* disable wptr polling */
  4706. tmp = RREG32(CP_PQ_WPTR_POLL_CNTL);
  4707. tmp &= ~WPTR_POLL_EN;
  4708. WREG32(CP_PQ_WPTR_POLL_CNTL, tmp);
  4709. /* enable doorbell? */
  4710. mqd->queue_state.cp_hqd_pq_doorbell_control =
  4711. RREG32(CP_HQD_PQ_DOORBELL_CONTROL);
  4712. if (use_doorbell)
  4713. mqd->queue_state.cp_hqd_pq_doorbell_control |= DOORBELL_EN;
  4714. else
  4715. mqd->queue_state.cp_hqd_pq_doorbell_control &= ~DOORBELL_EN;
  4716. WREG32(CP_HQD_PQ_DOORBELL_CONTROL,
  4717. mqd->queue_state.cp_hqd_pq_doorbell_control);
  4718. /* disable the queue if it's active */
  4719. mqd->queue_state.cp_hqd_dequeue_request = 0;
  4720. mqd->queue_state.cp_hqd_pq_rptr = 0;
  4721. mqd->queue_state.cp_hqd_pq_wptr= 0;
  4722. if (RREG32(CP_HQD_ACTIVE) & 1) {
  4723. WREG32(CP_HQD_DEQUEUE_REQUEST, 1);
  4724. for (j = 0; j < rdev->usec_timeout; j++) {
  4725. if (!(RREG32(CP_HQD_ACTIVE) & 1))
  4726. break;
  4727. udelay(1);
  4728. }
  4729. WREG32(CP_HQD_DEQUEUE_REQUEST, mqd->queue_state.cp_hqd_dequeue_request);
  4730. WREG32(CP_HQD_PQ_RPTR, mqd->queue_state.cp_hqd_pq_rptr);
  4731. WREG32(CP_HQD_PQ_WPTR, mqd->queue_state.cp_hqd_pq_wptr);
  4732. }
  4733. /* set the pointer to the MQD */
  4734. mqd->queue_state.cp_mqd_base_addr = mqd_gpu_addr & 0xfffffffc;
  4735. mqd->queue_state.cp_mqd_base_addr_hi = upper_32_bits(mqd_gpu_addr);
  4736. WREG32(CP_MQD_BASE_ADDR, mqd->queue_state.cp_mqd_base_addr);
  4737. WREG32(CP_MQD_BASE_ADDR_HI, mqd->queue_state.cp_mqd_base_addr_hi);
  4738. /* set MQD vmid to 0 */
  4739. mqd->queue_state.cp_mqd_control = RREG32(CP_MQD_CONTROL);
  4740. mqd->queue_state.cp_mqd_control &= ~MQD_VMID_MASK;
  4741. WREG32(CP_MQD_CONTROL, mqd->queue_state.cp_mqd_control);
  4742. /* set the pointer to the HQD, this is similar CP_RB0_BASE/_HI */
  4743. hqd_gpu_addr = rdev->ring[idx].gpu_addr >> 8;
  4744. mqd->queue_state.cp_hqd_pq_base = hqd_gpu_addr;
  4745. mqd->queue_state.cp_hqd_pq_base_hi = upper_32_bits(hqd_gpu_addr);
  4746. WREG32(CP_HQD_PQ_BASE, mqd->queue_state.cp_hqd_pq_base);
  4747. WREG32(CP_HQD_PQ_BASE_HI, mqd->queue_state.cp_hqd_pq_base_hi);
  4748. /* set up the HQD, this is similar to CP_RB0_CNTL */
  4749. mqd->queue_state.cp_hqd_pq_control = RREG32(CP_HQD_PQ_CONTROL);
  4750. mqd->queue_state.cp_hqd_pq_control &=
  4751. ~(QUEUE_SIZE_MASK | RPTR_BLOCK_SIZE_MASK);
  4752. mqd->queue_state.cp_hqd_pq_control |=
  4753. order_base_2(rdev->ring[idx].ring_size / 8);
  4754. mqd->queue_state.cp_hqd_pq_control |=
  4755. (order_base_2(RADEON_GPU_PAGE_SIZE/8) << 8);
  4756. #ifdef __BIG_ENDIAN
  4757. mqd->queue_state.cp_hqd_pq_control |= BUF_SWAP_32BIT;
  4758. #endif
  4759. mqd->queue_state.cp_hqd_pq_control &=
  4760. ~(UNORD_DISPATCH | ROQ_PQ_IB_FLIP | PQ_VOLATILE);
  4761. mqd->queue_state.cp_hqd_pq_control |=
  4762. PRIV_STATE | KMD_QUEUE; /* assuming kernel queue control */
  4763. WREG32(CP_HQD_PQ_CONTROL, mqd->queue_state.cp_hqd_pq_control);
  4764. /* only used if CP_PQ_WPTR_POLL_CNTL.WPTR_POLL_EN=1 */
  4765. if (i == 0)
  4766. wb_gpu_addr = rdev->wb.gpu_addr + CIK_WB_CP1_WPTR_OFFSET;
  4767. else
  4768. wb_gpu_addr = rdev->wb.gpu_addr + CIK_WB_CP2_WPTR_OFFSET;
  4769. mqd->queue_state.cp_hqd_pq_wptr_poll_addr = wb_gpu_addr & 0xfffffffc;
  4770. mqd->queue_state.cp_hqd_pq_wptr_poll_addr_hi = upper_32_bits(wb_gpu_addr) & 0xffff;
  4771. WREG32(CP_HQD_PQ_WPTR_POLL_ADDR, mqd->queue_state.cp_hqd_pq_wptr_poll_addr);
  4772. WREG32(CP_HQD_PQ_WPTR_POLL_ADDR_HI,
  4773. mqd->queue_state.cp_hqd_pq_wptr_poll_addr_hi);
  4774. /* set the wb address wether it's enabled or not */
  4775. if (i == 0)
  4776. wb_gpu_addr = rdev->wb.gpu_addr + RADEON_WB_CP1_RPTR_OFFSET;
  4777. else
  4778. wb_gpu_addr = rdev->wb.gpu_addr + RADEON_WB_CP2_RPTR_OFFSET;
  4779. mqd->queue_state.cp_hqd_pq_rptr_report_addr = wb_gpu_addr & 0xfffffffc;
  4780. mqd->queue_state.cp_hqd_pq_rptr_report_addr_hi =
  4781. upper_32_bits(wb_gpu_addr) & 0xffff;
  4782. WREG32(CP_HQD_PQ_RPTR_REPORT_ADDR,
  4783. mqd->queue_state.cp_hqd_pq_rptr_report_addr);
  4784. WREG32(CP_HQD_PQ_RPTR_REPORT_ADDR_HI,
  4785. mqd->queue_state.cp_hqd_pq_rptr_report_addr_hi);
  4786. /* enable the doorbell if requested */
  4787. if (use_doorbell) {
  4788. mqd->queue_state.cp_hqd_pq_doorbell_control =
  4789. RREG32(CP_HQD_PQ_DOORBELL_CONTROL);
  4790. mqd->queue_state.cp_hqd_pq_doorbell_control &= ~DOORBELL_OFFSET_MASK;
  4791. mqd->queue_state.cp_hqd_pq_doorbell_control |=
  4792. DOORBELL_OFFSET(rdev->ring[idx].doorbell_index);
  4793. mqd->queue_state.cp_hqd_pq_doorbell_control |= DOORBELL_EN;
  4794. mqd->queue_state.cp_hqd_pq_doorbell_control &=
  4795. ~(DOORBELL_SOURCE | DOORBELL_HIT);
  4796. } else {
  4797. mqd->queue_state.cp_hqd_pq_doorbell_control = 0;
  4798. }
  4799. WREG32(CP_HQD_PQ_DOORBELL_CONTROL,
  4800. mqd->queue_state.cp_hqd_pq_doorbell_control);
  4801. /* read and write pointers, similar to CP_RB0_WPTR/_RPTR */
  4802. rdev->ring[idx].wptr = 0;
  4803. mqd->queue_state.cp_hqd_pq_wptr = rdev->ring[idx].wptr;
  4804. WREG32(CP_HQD_PQ_WPTR, mqd->queue_state.cp_hqd_pq_wptr);
  4805. mqd->queue_state.cp_hqd_pq_rptr = RREG32(CP_HQD_PQ_RPTR);
  4806. /* set the vmid for the queue */
  4807. mqd->queue_state.cp_hqd_vmid = 0;
  4808. WREG32(CP_HQD_VMID, mqd->queue_state.cp_hqd_vmid);
  4809. /* activate the queue */
  4810. mqd->queue_state.cp_hqd_active = 1;
  4811. WREG32(CP_HQD_ACTIVE, mqd->queue_state.cp_hqd_active);
  4812. cik_srbm_select(rdev, 0, 0, 0, 0);
  4813. mutex_unlock(&rdev->srbm_mutex);
  4814. radeon_bo_kunmap(rdev->ring[idx].mqd_obj);
  4815. radeon_bo_unreserve(rdev->ring[idx].mqd_obj);
  4816. rdev->ring[idx].ready = true;
  4817. r = radeon_ring_test(rdev, idx, &rdev->ring[idx]);
  4818. if (r)
  4819. rdev->ring[idx].ready = false;
  4820. }
  4821. return 0;
  4822. }
  4823. static void cik_cp_enable(struct radeon_device *rdev, bool enable)
  4824. {
  4825. cik_cp_gfx_enable(rdev, enable);
  4826. cik_cp_compute_enable(rdev, enable);
  4827. }
  4828. static int cik_cp_load_microcode(struct radeon_device *rdev)
  4829. {
  4830. int r;
  4831. r = cik_cp_gfx_load_microcode(rdev);
  4832. if (r)
  4833. return r;
  4834. r = cik_cp_compute_load_microcode(rdev);
  4835. if (r)
  4836. return r;
  4837. return 0;
  4838. }
  4839. static void cik_cp_fini(struct radeon_device *rdev)
  4840. {
  4841. cik_cp_gfx_fini(rdev);
  4842. cik_cp_compute_fini(rdev);
  4843. }
  4844. static int cik_cp_resume(struct radeon_device *rdev)
  4845. {
  4846. int r;
  4847. cik_enable_gui_idle_interrupt(rdev, false);
  4848. r = cik_cp_load_microcode(rdev);
  4849. if (r)
  4850. return r;
  4851. r = cik_cp_gfx_resume(rdev);
  4852. if (r)
  4853. return r;
  4854. r = cik_cp_compute_resume(rdev);
  4855. if (r)
  4856. return r;
  4857. cik_enable_gui_idle_interrupt(rdev, true);
  4858. return 0;
  4859. }
  4860. static void cik_print_gpu_status_regs(struct radeon_device *rdev)
  4861. {
  4862. dev_info(rdev->dev, " GRBM_STATUS=0x%08X\n",
  4863. RREG32(GRBM_STATUS));
  4864. dev_info(rdev->dev, " GRBM_STATUS2=0x%08X\n",
  4865. RREG32(GRBM_STATUS2));
  4866. dev_info(rdev->dev, " GRBM_STATUS_SE0=0x%08X\n",
  4867. RREG32(GRBM_STATUS_SE0));
  4868. dev_info(rdev->dev, " GRBM_STATUS_SE1=0x%08X\n",
  4869. RREG32(GRBM_STATUS_SE1));
  4870. dev_info(rdev->dev, " GRBM_STATUS_SE2=0x%08X\n",
  4871. RREG32(GRBM_STATUS_SE2));
  4872. dev_info(rdev->dev, " GRBM_STATUS_SE3=0x%08X\n",
  4873. RREG32(GRBM_STATUS_SE3));
  4874. dev_info(rdev->dev, " SRBM_STATUS=0x%08X\n",
  4875. RREG32(SRBM_STATUS));
  4876. dev_info(rdev->dev, " SRBM_STATUS2=0x%08X\n",
  4877. RREG32(SRBM_STATUS2));
  4878. dev_info(rdev->dev, " SDMA0_STATUS_REG = 0x%08X\n",
  4879. RREG32(SDMA0_STATUS_REG + SDMA0_REGISTER_OFFSET));
  4880. dev_info(rdev->dev, " SDMA1_STATUS_REG = 0x%08X\n",
  4881. RREG32(SDMA0_STATUS_REG + SDMA1_REGISTER_OFFSET));
  4882. dev_info(rdev->dev, " CP_STAT = 0x%08x\n", RREG32(CP_STAT));
  4883. dev_info(rdev->dev, " CP_STALLED_STAT1 = 0x%08x\n",
  4884. RREG32(CP_STALLED_STAT1));
  4885. dev_info(rdev->dev, " CP_STALLED_STAT2 = 0x%08x\n",
  4886. RREG32(CP_STALLED_STAT2));
  4887. dev_info(rdev->dev, " CP_STALLED_STAT3 = 0x%08x\n",
  4888. RREG32(CP_STALLED_STAT3));
  4889. dev_info(rdev->dev, " CP_CPF_BUSY_STAT = 0x%08x\n",
  4890. RREG32(CP_CPF_BUSY_STAT));
  4891. dev_info(rdev->dev, " CP_CPF_STALLED_STAT1 = 0x%08x\n",
  4892. RREG32(CP_CPF_STALLED_STAT1));
  4893. dev_info(rdev->dev, " CP_CPF_STATUS = 0x%08x\n", RREG32(CP_CPF_STATUS));
  4894. dev_info(rdev->dev, " CP_CPC_BUSY_STAT = 0x%08x\n", RREG32(CP_CPC_BUSY_STAT));
  4895. dev_info(rdev->dev, " CP_CPC_STALLED_STAT1 = 0x%08x\n",
  4896. RREG32(CP_CPC_STALLED_STAT1));
  4897. dev_info(rdev->dev, " CP_CPC_STATUS = 0x%08x\n", RREG32(CP_CPC_STATUS));
  4898. }
  4899. /**
  4900. * cik_gpu_check_soft_reset - check which blocks are busy
  4901. *
  4902. * @rdev: radeon_device pointer
  4903. *
  4904. * Check which blocks are busy and return the relevant reset
  4905. * mask to be used by cik_gpu_soft_reset().
  4906. * Returns a mask of the blocks to be reset.
  4907. */
  4908. u32 cik_gpu_check_soft_reset(struct radeon_device *rdev)
  4909. {
  4910. u32 reset_mask = 0;
  4911. u32 tmp;
  4912. /* GRBM_STATUS */
  4913. tmp = RREG32(GRBM_STATUS);
  4914. if (tmp & (PA_BUSY | SC_BUSY |
  4915. BCI_BUSY | SX_BUSY |
  4916. TA_BUSY | VGT_BUSY |
  4917. DB_BUSY | CB_BUSY |
  4918. GDS_BUSY | SPI_BUSY |
  4919. IA_BUSY | IA_BUSY_NO_DMA))
  4920. reset_mask |= RADEON_RESET_GFX;
  4921. if (tmp & (CP_BUSY | CP_COHERENCY_BUSY))
  4922. reset_mask |= RADEON_RESET_CP;
  4923. /* GRBM_STATUS2 */
  4924. tmp = RREG32(GRBM_STATUS2);
  4925. if (tmp & RLC_BUSY)
  4926. reset_mask |= RADEON_RESET_RLC;
  4927. /* SDMA0_STATUS_REG */
  4928. tmp = RREG32(SDMA0_STATUS_REG + SDMA0_REGISTER_OFFSET);
  4929. if (!(tmp & SDMA_IDLE))
  4930. reset_mask |= RADEON_RESET_DMA;
  4931. /* SDMA1_STATUS_REG */
  4932. tmp = RREG32(SDMA0_STATUS_REG + SDMA1_REGISTER_OFFSET);
  4933. if (!(tmp & SDMA_IDLE))
  4934. reset_mask |= RADEON_RESET_DMA1;
  4935. /* SRBM_STATUS2 */
  4936. tmp = RREG32(SRBM_STATUS2);
  4937. if (tmp & SDMA_BUSY)
  4938. reset_mask |= RADEON_RESET_DMA;
  4939. if (tmp & SDMA1_BUSY)
  4940. reset_mask |= RADEON_RESET_DMA1;
  4941. /* SRBM_STATUS */
  4942. tmp = RREG32(SRBM_STATUS);
  4943. if (tmp & IH_BUSY)
  4944. reset_mask |= RADEON_RESET_IH;
  4945. if (tmp & SEM_BUSY)
  4946. reset_mask |= RADEON_RESET_SEM;
  4947. if (tmp & GRBM_RQ_PENDING)
  4948. reset_mask |= RADEON_RESET_GRBM;
  4949. if (tmp & VMC_BUSY)
  4950. reset_mask |= RADEON_RESET_VMC;
  4951. if (tmp & (MCB_BUSY | MCB_NON_DISPLAY_BUSY |
  4952. MCC_BUSY | MCD_BUSY))
  4953. reset_mask |= RADEON_RESET_MC;
  4954. if (evergreen_is_display_hung(rdev))
  4955. reset_mask |= RADEON_RESET_DISPLAY;
  4956. /* Skip MC reset as it's mostly likely not hung, just busy */
  4957. if (reset_mask & RADEON_RESET_MC) {
  4958. DRM_DEBUG("MC busy: 0x%08X, clearing.\n", reset_mask);
  4959. reset_mask &= ~RADEON_RESET_MC;
  4960. }
  4961. return reset_mask;
  4962. }
  4963. /**
  4964. * cik_gpu_soft_reset - soft reset GPU
  4965. *
  4966. * @rdev: radeon_device pointer
  4967. * @reset_mask: mask of which blocks to reset
  4968. *
  4969. * Soft reset the blocks specified in @reset_mask.
  4970. */
  4971. static void cik_gpu_soft_reset(struct radeon_device *rdev, u32 reset_mask)
  4972. {
  4973. struct evergreen_mc_save save;
  4974. u32 grbm_soft_reset = 0, srbm_soft_reset = 0;
  4975. u32 tmp;
  4976. if (reset_mask == 0)
  4977. return;
  4978. dev_info(rdev->dev, "GPU softreset: 0x%08X\n", reset_mask);
  4979. cik_print_gpu_status_regs(rdev);
  4980. dev_info(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_ADDR 0x%08X\n",
  4981. RREG32(VM_CONTEXT1_PROTECTION_FAULT_ADDR));
  4982. dev_info(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_STATUS 0x%08X\n",
  4983. RREG32(VM_CONTEXT1_PROTECTION_FAULT_STATUS));
  4984. /* disable CG/PG */
  4985. cik_fini_pg(rdev);
  4986. cik_fini_cg(rdev);
  4987. /* stop the rlc */
  4988. cik_rlc_stop(rdev);
  4989. /* Disable GFX parsing/prefetching */
  4990. WREG32(CP_ME_CNTL, CP_ME_HALT | CP_PFP_HALT | CP_CE_HALT);
  4991. /* Disable MEC parsing/prefetching */
  4992. WREG32(CP_MEC_CNTL, MEC_ME1_HALT | MEC_ME2_HALT);
  4993. if (reset_mask & RADEON_RESET_DMA) {
  4994. /* sdma0 */
  4995. tmp = RREG32(SDMA0_ME_CNTL + SDMA0_REGISTER_OFFSET);
  4996. tmp |= SDMA_HALT;
  4997. WREG32(SDMA0_ME_CNTL + SDMA0_REGISTER_OFFSET, tmp);
  4998. }
  4999. if (reset_mask & RADEON_RESET_DMA1) {
  5000. /* sdma1 */
  5001. tmp = RREG32(SDMA0_ME_CNTL + SDMA1_REGISTER_OFFSET);
  5002. tmp |= SDMA_HALT;
  5003. WREG32(SDMA0_ME_CNTL + SDMA1_REGISTER_OFFSET, tmp);
  5004. }
  5005. evergreen_mc_stop(rdev, &save);
  5006. if (evergreen_mc_wait_for_idle(rdev)) {
  5007. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  5008. }
  5009. if (reset_mask & (RADEON_RESET_GFX | RADEON_RESET_COMPUTE | RADEON_RESET_CP))
  5010. grbm_soft_reset = SOFT_RESET_CP | SOFT_RESET_GFX;
  5011. if (reset_mask & RADEON_RESET_CP) {
  5012. grbm_soft_reset |= SOFT_RESET_CP;
  5013. srbm_soft_reset |= SOFT_RESET_GRBM;
  5014. }
  5015. if (reset_mask & RADEON_RESET_DMA)
  5016. srbm_soft_reset |= SOFT_RESET_SDMA;
  5017. if (reset_mask & RADEON_RESET_DMA1)
  5018. srbm_soft_reset |= SOFT_RESET_SDMA1;
  5019. if (reset_mask & RADEON_RESET_DISPLAY)
  5020. srbm_soft_reset |= SOFT_RESET_DC;
  5021. if (reset_mask & RADEON_RESET_RLC)
  5022. grbm_soft_reset |= SOFT_RESET_RLC;
  5023. if (reset_mask & RADEON_RESET_SEM)
  5024. srbm_soft_reset |= SOFT_RESET_SEM;
  5025. if (reset_mask & RADEON_RESET_IH)
  5026. srbm_soft_reset |= SOFT_RESET_IH;
  5027. if (reset_mask & RADEON_RESET_GRBM)
  5028. srbm_soft_reset |= SOFT_RESET_GRBM;
  5029. if (reset_mask & RADEON_RESET_VMC)
  5030. srbm_soft_reset |= SOFT_RESET_VMC;
  5031. if (!(rdev->flags & RADEON_IS_IGP)) {
  5032. if (reset_mask & RADEON_RESET_MC)
  5033. srbm_soft_reset |= SOFT_RESET_MC;
  5034. }
  5035. if (grbm_soft_reset) {
  5036. tmp = RREG32(GRBM_SOFT_RESET);
  5037. tmp |= grbm_soft_reset;
  5038. dev_info(rdev->dev, "GRBM_SOFT_RESET=0x%08X\n", tmp);
  5039. WREG32(GRBM_SOFT_RESET, tmp);
  5040. tmp = RREG32(GRBM_SOFT_RESET);
  5041. udelay(50);
  5042. tmp &= ~grbm_soft_reset;
  5043. WREG32(GRBM_SOFT_RESET, tmp);
  5044. tmp = RREG32(GRBM_SOFT_RESET);
  5045. }
  5046. if (srbm_soft_reset) {
  5047. tmp = RREG32(SRBM_SOFT_RESET);
  5048. tmp |= srbm_soft_reset;
  5049. dev_info(rdev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
  5050. WREG32(SRBM_SOFT_RESET, tmp);
  5051. tmp = RREG32(SRBM_SOFT_RESET);
  5052. udelay(50);
  5053. tmp &= ~srbm_soft_reset;
  5054. WREG32(SRBM_SOFT_RESET, tmp);
  5055. tmp = RREG32(SRBM_SOFT_RESET);
  5056. }
  5057. /* Wait a little for things to settle down */
  5058. udelay(50);
  5059. evergreen_mc_resume(rdev, &save);
  5060. udelay(50);
  5061. cik_print_gpu_status_regs(rdev);
  5062. }
  5063. struct kv_reset_save_regs {
  5064. u32 gmcon_reng_execute;
  5065. u32 gmcon_misc;
  5066. u32 gmcon_misc3;
  5067. };
  5068. static void kv_save_regs_for_reset(struct radeon_device *rdev,
  5069. struct kv_reset_save_regs *save)
  5070. {
  5071. save->gmcon_reng_execute = RREG32(GMCON_RENG_EXECUTE);
  5072. save->gmcon_misc = RREG32(GMCON_MISC);
  5073. save->gmcon_misc3 = RREG32(GMCON_MISC3);
  5074. WREG32(GMCON_RENG_EXECUTE, save->gmcon_reng_execute & ~RENG_EXECUTE_ON_PWR_UP);
  5075. WREG32(GMCON_MISC, save->gmcon_misc & ~(RENG_EXECUTE_ON_REG_UPDATE |
  5076. STCTRL_STUTTER_EN));
  5077. }
  5078. static void kv_restore_regs_for_reset(struct radeon_device *rdev,
  5079. struct kv_reset_save_regs *save)
  5080. {
  5081. int i;
  5082. WREG32(GMCON_PGFSM_WRITE, 0);
  5083. WREG32(GMCON_PGFSM_CONFIG, 0x200010ff);
  5084. for (i = 0; i < 5; i++)
  5085. WREG32(GMCON_PGFSM_WRITE, 0);
  5086. WREG32(GMCON_PGFSM_WRITE, 0);
  5087. WREG32(GMCON_PGFSM_CONFIG, 0x300010ff);
  5088. for (i = 0; i < 5; i++)
  5089. WREG32(GMCON_PGFSM_WRITE, 0);
  5090. WREG32(GMCON_PGFSM_WRITE, 0x210000);
  5091. WREG32(GMCON_PGFSM_CONFIG, 0xa00010ff);
  5092. for (i = 0; i < 5; i++)
  5093. WREG32(GMCON_PGFSM_WRITE, 0);
  5094. WREG32(GMCON_PGFSM_WRITE, 0x21003);
  5095. WREG32(GMCON_PGFSM_CONFIG, 0xb00010ff);
  5096. for (i = 0; i < 5; i++)
  5097. WREG32(GMCON_PGFSM_WRITE, 0);
  5098. WREG32(GMCON_PGFSM_WRITE, 0x2b00);
  5099. WREG32(GMCON_PGFSM_CONFIG, 0xc00010ff);
  5100. for (i = 0; i < 5; i++)
  5101. WREG32(GMCON_PGFSM_WRITE, 0);
  5102. WREG32(GMCON_PGFSM_WRITE, 0);
  5103. WREG32(GMCON_PGFSM_CONFIG, 0xd00010ff);
  5104. for (i = 0; i < 5; i++)
  5105. WREG32(GMCON_PGFSM_WRITE, 0);
  5106. WREG32(GMCON_PGFSM_WRITE, 0x420000);
  5107. WREG32(GMCON_PGFSM_CONFIG, 0x100010ff);
  5108. for (i = 0; i < 5; i++)
  5109. WREG32(GMCON_PGFSM_WRITE, 0);
  5110. WREG32(GMCON_PGFSM_WRITE, 0x120202);
  5111. WREG32(GMCON_PGFSM_CONFIG, 0x500010ff);
  5112. for (i = 0; i < 5; i++)
  5113. WREG32(GMCON_PGFSM_WRITE, 0);
  5114. WREG32(GMCON_PGFSM_WRITE, 0x3e3e36);
  5115. WREG32(GMCON_PGFSM_CONFIG, 0x600010ff);
  5116. for (i = 0; i < 5; i++)
  5117. WREG32(GMCON_PGFSM_WRITE, 0);
  5118. WREG32(GMCON_PGFSM_WRITE, 0x373f3e);
  5119. WREG32(GMCON_PGFSM_CONFIG, 0x700010ff);
  5120. for (i = 0; i < 5; i++)
  5121. WREG32(GMCON_PGFSM_WRITE, 0);
  5122. WREG32(GMCON_PGFSM_WRITE, 0x3e1332);
  5123. WREG32(GMCON_PGFSM_CONFIG, 0xe00010ff);
  5124. WREG32(GMCON_MISC3, save->gmcon_misc3);
  5125. WREG32(GMCON_MISC, save->gmcon_misc);
  5126. WREG32(GMCON_RENG_EXECUTE, save->gmcon_reng_execute);
  5127. }
  5128. static void cik_gpu_pci_config_reset(struct radeon_device *rdev)
  5129. {
  5130. struct evergreen_mc_save save;
  5131. struct kv_reset_save_regs kv_save = { 0 };
  5132. u32 tmp, i;
  5133. dev_info(rdev->dev, "GPU pci config reset\n");
  5134. /* disable dpm? */
  5135. /* disable cg/pg */
  5136. cik_fini_pg(rdev);
  5137. cik_fini_cg(rdev);
  5138. /* Disable GFX parsing/prefetching */
  5139. WREG32(CP_ME_CNTL, CP_ME_HALT | CP_PFP_HALT | CP_CE_HALT);
  5140. /* Disable MEC parsing/prefetching */
  5141. WREG32(CP_MEC_CNTL, MEC_ME1_HALT | MEC_ME2_HALT);
  5142. /* sdma0 */
  5143. tmp = RREG32(SDMA0_ME_CNTL + SDMA0_REGISTER_OFFSET);
  5144. tmp |= SDMA_HALT;
  5145. WREG32(SDMA0_ME_CNTL + SDMA0_REGISTER_OFFSET, tmp);
  5146. /* sdma1 */
  5147. tmp = RREG32(SDMA0_ME_CNTL + SDMA1_REGISTER_OFFSET);
  5148. tmp |= SDMA_HALT;
  5149. WREG32(SDMA0_ME_CNTL + SDMA1_REGISTER_OFFSET, tmp);
  5150. /* XXX other engines? */
  5151. /* halt the rlc, disable cp internal ints */
  5152. cik_rlc_stop(rdev);
  5153. udelay(50);
  5154. /* disable mem access */
  5155. evergreen_mc_stop(rdev, &save);
  5156. if (evergreen_mc_wait_for_idle(rdev)) {
  5157. dev_warn(rdev->dev, "Wait for MC idle timed out !\n");
  5158. }
  5159. if (rdev->flags & RADEON_IS_IGP)
  5160. kv_save_regs_for_reset(rdev, &kv_save);
  5161. /* disable BM */
  5162. pci_clear_master(rdev->pdev);
  5163. /* reset */
  5164. radeon_pci_config_reset(rdev);
  5165. udelay(100);
  5166. /* wait for asic to come out of reset */
  5167. for (i = 0; i < rdev->usec_timeout; i++) {
  5168. if (RREG32(CONFIG_MEMSIZE) != 0xffffffff)
  5169. break;
  5170. udelay(1);
  5171. }
  5172. /* does asic init need to be run first??? */
  5173. if (rdev->flags & RADEON_IS_IGP)
  5174. kv_restore_regs_for_reset(rdev, &kv_save);
  5175. }
  5176. /**
  5177. * cik_asic_reset - soft reset GPU
  5178. *
  5179. * @rdev: radeon_device pointer
  5180. *
  5181. * Look up which blocks are hung and attempt
  5182. * to reset them.
  5183. * Returns 0 for success.
  5184. */
  5185. int cik_asic_reset(struct radeon_device *rdev)
  5186. {
  5187. u32 reset_mask;
  5188. reset_mask = cik_gpu_check_soft_reset(rdev);
  5189. if (reset_mask)
  5190. r600_set_bios_scratch_engine_hung(rdev, true);
  5191. /* try soft reset */
  5192. cik_gpu_soft_reset(rdev, reset_mask);
  5193. reset_mask = cik_gpu_check_soft_reset(rdev);
  5194. /* try pci config reset */
  5195. if (reset_mask && radeon_hard_reset)
  5196. cik_gpu_pci_config_reset(rdev);
  5197. reset_mask = cik_gpu_check_soft_reset(rdev);
  5198. if (!reset_mask)
  5199. r600_set_bios_scratch_engine_hung(rdev, false);
  5200. return 0;
  5201. }
  5202. /**
  5203. * cik_gfx_is_lockup - check if the 3D engine is locked up
  5204. *
  5205. * @rdev: radeon_device pointer
  5206. * @ring: radeon_ring structure holding ring information
  5207. *
  5208. * Check if the 3D engine is locked up (CIK).
  5209. * Returns true if the engine is locked, false if not.
  5210. */
  5211. bool cik_gfx_is_lockup(struct radeon_device *rdev, struct radeon_ring *ring)
  5212. {
  5213. u32 reset_mask = cik_gpu_check_soft_reset(rdev);
  5214. if (!(reset_mask & (RADEON_RESET_GFX |
  5215. RADEON_RESET_COMPUTE |
  5216. RADEON_RESET_CP))) {
  5217. radeon_ring_lockup_update(rdev, ring);
  5218. return false;
  5219. }
  5220. return radeon_ring_test_lockup(rdev, ring);
  5221. }
  5222. /* MC */
  5223. /**
  5224. * cik_mc_program - program the GPU memory controller
  5225. *
  5226. * @rdev: radeon_device pointer
  5227. *
  5228. * Set the location of vram, gart, and AGP in the GPU's
  5229. * physical address space (CIK).
  5230. */
  5231. static void cik_mc_program(struct radeon_device *rdev)
  5232. {
  5233. struct evergreen_mc_save save;
  5234. u32 tmp;
  5235. int i, j;
  5236. /* Initialize HDP */
  5237. for (i = 0, j = 0; i < 32; i++, j += 0x18) {
  5238. WREG32((0x2c14 + j), 0x00000000);
  5239. WREG32((0x2c18 + j), 0x00000000);
  5240. WREG32((0x2c1c + j), 0x00000000);
  5241. WREG32((0x2c20 + j), 0x00000000);
  5242. WREG32((0x2c24 + j), 0x00000000);
  5243. }
  5244. WREG32(HDP_REG_COHERENCY_FLUSH_CNTL, 0);
  5245. evergreen_mc_stop(rdev, &save);
  5246. if (radeon_mc_wait_for_idle(rdev)) {
  5247. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  5248. }
  5249. /* Lockout access through VGA aperture*/
  5250. WREG32(VGA_HDP_CONTROL, VGA_MEMORY_DISABLE);
  5251. /* Update configuration */
  5252. WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
  5253. rdev->mc.vram_start >> 12);
  5254. WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
  5255. rdev->mc.vram_end >> 12);
  5256. WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR,
  5257. rdev->vram_scratch.gpu_addr >> 12);
  5258. tmp = ((rdev->mc.vram_end >> 24) & 0xFFFF) << 16;
  5259. tmp |= ((rdev->mc.vram_start >> 24) & 0xFFFF);
  5260. WREG32(MC_VM_FB_LOCATION, tmp);
  5261. /* XXX double check these! */
  5262. WREG32(HDP_NONSURFACE_BASE, (rdev->mc.vram_start >> 8));
  5263. WREG32(HDP_NONSURFACE_INFO, (2 << 7) | (1 << 30));
  5264. WREG32(HDP_NONSURFACE_SIZE, 0x3FFFFFFF);
  5265. WREG32(MC_VM_AGP_BASE, 0);
  5266. WREG32(MC_VM_AGP_TOP, 0x0FFFFFFF);
  5267. WREG32(MC_VM_AGP_BOT, 0x0FFFFFFF);
  5268. if (radeon_mc_wait_for_idle(rdev)) {
  5269. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  5270. }
  5271. evergreen_mc_resume(rdev, &save);
  5272. /* we need to own VRAM, so turn off the VGA renderer here
  5273. * to stop it overwriting our objects */
  5274. rv515_vga_render_disable(rdev);
  5275. }
  5276. /**
  5277. * cik_mc_init - initialize the memory controller driver params
  5278. *
  5279. * @rdev: radeon_device pointer
  5280. *
  5281. * Look up the amount of vram, vram width, and decide how to place
  5282. * vram and gart within the GPU's physical address space (CIK).
  5283. * Returns 0 for success.
  5284. */
  5285. static int cik_mc_init(struct radeon_device *rdev)
  5286. {
  5287. u32 tmp;
  5288. int chansize, numchan;
  5289. /* Get VRAM informations */
  5290. rdev->mc.vram_is_ddr = true;
  5291. tmp = RREG32(MC_ARB_RAMCFG);
  5292. if (tmp & CHANSIZE_MASK) {
  5293. chansize = 64;
  5294. } else {
  5295. chansize = 32;
  5296. }
  5297. tmp = RREG32(MC_SHARED_CHMAP);
  5298. switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
  5299. case 0:
  5300. default:
  5301. numchan = 1;
  5302. break;
  5303. case 1:
  5304. numchan = 2;
  5305. break;
  5306. case 2:
  5307. numchan = 4;
  5308. break;
  5309. case 3:
  5310. numchan = 8;
  5311. break;
  5312. case 4:
  5313. numchan = 3;
  5314. break;
  5315. case 5:
  5316. numchan = 6;
  5317. break;
  5318. case 6:
  5319. numchan = 10;
  5320. break;
  5321. case 7:
  5322. numchan = 12;
  5323. break;
  5324. case 8:
  5325. numchan = 16;
  5326. break;
  5327. }
  5328. rdev->mc.vram_width = numchan * chansize;
  5329. /* Could aper size report 0 ? */
  5330. rdev->mc.aper_base = pci_resource_start(rdev->pdev, 0);
  5331. rdev->mc.aper_size = pci_resource_len(rdev->pdev, 0);
  5332. /* size in MB on si */
  5333. rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE) * 1024ULL * 1024ULL;
  5334. rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE) * 1024ULL * 1024ULL;
  5335. rdev->mc.visible_vram_size = rdev->mc.aper_size;
  5336. si_vram_gtt_location(rdev, &rdev->mc);
  5337. radeon_update_bandwidth_info(rdev);
  5338. return 0;
  5339. }
  5340. /*
  5341. * GART
  5342. * VMID 0 is the physical GPU addresses as used by the kernel.
  5343. * VMIDs 1-15 are used for userspace clients and are handled
  5344. * by the radeon vm/hsa code.
  5345. */
  5346. /**
  5347. * cik_pcie_gart_tlb_flush - gart tlb flush callback
  5348. *
  5349. * @rdev: radeon_device pointer
  5350. *
  5351. * Flush the TLB for the VMID 0 page table (CIK).
  5352. */
  5353. void cik_pcie_gart_tlb_flush(struct radeon_device *rdev)
  5354. {
  5355. /* flush hdp cache */
  5356. WREG32(HDP_MEM_COHERENCY_FLUSH_CNTL, 0);
  5357. /* bits 0-15 are the VM contexts0-15 */
  5358. WREG32(VM_INVALIDATE_REQUEST, 0x1);
  5359. }
  5360. static void cik_pcie_init_compute_vmid(struct radeon_device *rdev)
  5361. {
  5362. int i;
  5363. uint32_t sh_mem_bases, sh_mem_config;
  5364. sh_mem_bases = 0x6000 | 0x6000 << 16;
  5365. sh_mem_config = ALIGNMENT_MODE(SH_MEM_ALIGNMENT_MODE_UNALIGNED);
  5366. sh_mem_config |= DEFAULT_MTYPE(MTYPE_NONCACHED);
  5367. mutex_lock(&rdev->srbm_mutex);
  5368. for (i = 8; i < 16; i++) {
  5369. cik_srbm_select(rdev, 0, 0, 0, i);
  5370. /* CP and shaders */
  5371. WREG32(SH_MEM_CONFIG, sh_mem_config);
  5372. WREG32(SH_MEM_APE1_BASE, 1);
  5373. WREG32(SH_MEM_APE1_LIMIT, 0);
  5374. WREG32(SH_MEM_BASES, sh_mem_bases);
  5375. }
  5376. cik_srbm_select(rdev, 0, 0, 0, 0);
  5377. mutex_unlock(&rdev->srbm_mutex);
  5378. }
  5379. /**
  5380. * cik_pcie_gart_enable - gart enable
  5381. *
  5382. * @rdev: radeon_device pointer
  5383. *
  5384. * This sets up the TLBs, programs the page tables for VMID0,
  5385. * sets up the hw for VMIDs 1-15 which are allocated on
  5386. * demand, and sets up the global locations for the LDS, GDS,
  5387. * and GPUVM for FSA64 clients (CIK).
  5388. * Returns 0 for success, errors for failure.
  5389. */
  5390. static int cik_pcie_gart_enable(struct radeon_device *rdev)
  5391. {
  5392. int r, i;
  5393. if (rdev->gart.robj == NULL) {
  5394. dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
  5395. return -EINVAL;
  5396. }
  5397. r = radeon_gart_table_vram_pin(rdev);
  5398. if (r)
  5399. return r;
  5400. /* Setup TLB control */
  5401. WREG32(MC_VM_MX_L1_TLB_CNTL,
  5402. (0xA << 7) |
  5403. ENABLE_L1_TLB |
  5404. ENABLE_L1_FRAGMENT_PROCESSING |
  5405. SYSTEM_ACCESS_MODE_NOT_IN_SYS |
  5406. ENABLE_ADVANCED_DRIVER_MODEL |
  5407. SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU);
  5408. /* Setup L2 cache */
  5409. WREG32(VM_L2_CNTL, ENABLE_L2_CACHE |
  5410. ENABLE_L2_FRAGMENT_PROCESSING |
  5411. ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
  5412. ENABLE_L2_PDE0_CACHE_LRU_UPDATE_BY_WRITE |
  5413. EFFECTIVE_L2_QUEUE_SIZE(7) |
  5414. CONTEXT1_IDENTITY_ACCESS_MODE(1));
  5415. WREG32(VM_L2_CNTL2, INVALIDATE_ALL_L1_TLBS | INVALIDATE_L2_CACHE);
  5416. WREG32(VM_L2_CNTL3, L2_CACHE_BIGK_ASSOCIATIVITY |
  5417. BANK_SELECT(4) |
  5418. L2_CACHE_BIGK_FRAGMENT_SIZE(4));
  5419. /* setup context0 */
  5420. WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR, rdev->mc.gtt_start >> 12);
  5421. WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR, rdev->mc.gtt_end >> 12);
  5422. WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, rdev->gart.table_addr >> 12);
  5423. WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR,
  5424. (u32)(rdev->dummy_page.addr >> 12));
  5425. WREG32(VM_CONTEXT0_CNTL2, 0);
  5426. WREG32(VM_CONTEXT0_CNTL, (ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) |
  5427. RANGE_PROTECTION_FAULT_ENABLE_DEFAULT));
  5428. WREG32(0x15D4, 0);
  5429. WREG32(0x15D8, 0);
  5430. WREG32(0x15DC, 0);
  5431. /* restore context1-15 */
  5432. /* set vm size, must be a multiple of 4 */
  5433. WREG32(VM_CONTEXT1_PAGE_TABLE_START_ADDR, 0);
  5434. WREG32(VM_CONTEXT1_PAGE_TABLE_END_ADDR, rdev->vm_manager.max_pfn - 1);
  5435. for (i = 1; i < 16; i++) {
  5436. if (i < 8)
  5437. WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (i << 2),
  5438. rdev->vm_manager.saved_table_addr[i]);
  5439. else
  5440. WREG32(VM_CONTEXT8_PAGE_TABLE_BASE_ADDR + ((i - 8) << 2),
  5441. rdev->vm_manager.saved_table_addr[i]);
  5442. }
  5443. /* enable context1-15 */
  5444. WREG32(VM_CONTEXT1_PROTECTION_FAULT_DEFAULT_ADDR,
  5445. (u32)(rdev->dummy_page.addr >> 12));
  5446. WREG32(VM_CONTEXT1_CNTL2, 4);
  5447. WREG32(VM_CONTEXT1_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(1) |
  5448. PAGE_TABLE_BLOCK_SIZE(radeon_vm_block_size - 9) |
  5449. RANGE_PROTECTION_FAULT_ENABLE_INTERRUPT |
  5450. RANGE_PROTECTION_FAULT_ENABLE_DEFAULT |
  5451. DUMMY_PAGE_PROTECTION_FAULT_ENABLE_INTERRUPT |
  5452. DUMMY_PAGE_PROTECTION_FAULT_ENABLE_DEFAULT |
  5453. PDE0_PROTECTION_FAULT_ENABLE_INTERRUPT |
  5454. PDE0_PROTECTION_FAULT_ENABLE_DEFAULT |
  5455. VALID_PROTECTION_FAULT_ENABLE_INTERRUPT |
  5456. VALID_PROTECTION_FAULT_ENABLE_DEFAULT |
  5457. READ_PROTECTION_FAULT_ENABLE_INTERRUPT |
  5458. READ_PROTECTION_FAULT_ENABLE_DEFAULT |
  5459. WRITE_PROTECTION_FAULT_ENABLE_INTERRUPT |
  5460. WRITE_PROTECTION_FAULT_ENABLE_DEFAULT);
  5461. if (rdev->family == CHIP_KAVERI) {
  5462. u32 tmp = RREG32(CHUB_CONTROL);
  5463. tmp &= ~BYPASS_VM;
  5464. WREG32(CHUB_CONTROL, tmp);
  5465. }
  5466. /* XXX SH_MEM regs */
  5467. /* where to put LDS, scratch, GPUVM in FSA64 space */
  5468. mutex_lock(&rdev->srbm_mutex);
  5469. for (i = 0; i < 16; i++) {
  5470. cik_srbm_select(rdev, 0, 0, 0, i);
  5471. /* CP and shaders */
  5472. WREG32(SH_MEM_CONFIG, 0);
  5473. WREG32(SH_MEM_APE1_BASE, 1);
  5474. WREG32(SH_MEM_APE1_LIMIT, 0);
  5475. WREG32(SH_MEM_BASES, 0);
  5476. /* SDMA GFX */
  5477. WREG32(SDMA0_GFX_VIRTUAL_ADDR + SDMA0_REGISTER_OFFSET, 0);
  5478. WREG32(SDMA0_GFX_APE1_CNTL + SDMA0_REGISTER_OFFSET, 0);
  5479. WREG32(SDMA0_GFX_VIRTUAL_ADDR + SDMA1_REGISTER_OFFSET, 0);
  5480. WREG32(SDMA0_GFX_APE1_CNTL + SDMA1_REGISTER_OFFSET, 0);
  5481. /* XXX SDMA RLC - todo */
  5482. }
  5483. cik_srbm_select(rdev, 0, 0, 0, 0);
  5484. mutex_unlock(&rdev->srbm_mutex);
  5485. cik_pcie_init_compute_vmid(rdev);
  5486. cik_pcie_gart_tlb_flush(rdev);
  5487. DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
  5488. (unsigned)(rdev->mc.gtt_size >> 20),
  5489. (unsigned long long)rdev->gart.table_addr);
  5490. rdev->gart.ready = true;
  5491. return 0;
  5492. }
  5493. /**
  5494. * cik_pcie_gart_disable - gart disable
  5495. *
  5496. * @rdev: radeon_device pointer
  5497. *
  5498. * This disables all VM page table (CIK).
  5499. */
  5500. static void cik_pcie_gart_disable(struct radeon_device *rdev)
  5501. {
  5502. unsigned i;
  5503. for (i = 1; i < 16; ++i) {
  5504. uint32_t reg;
  5505. if (i < 8)
  5506. reg = VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (i << 2);
  5507. else
  5508. reg = VM_CONTEXT8_PAGE_TABLE_BASE_ADDR + ((i - 8) << 2);
  5509. rdev->vm_manager.saved_table_addr[i] = RREG32(reg);
  5510. }
  5511. /* Disable all tables */
  5512. WREG32(VM_CONTEXT0_CNTL, 0);
  5513. WREG32(VM_CONTEXT1_CNTL, 0);
  5514. /* Setup TLB control */
  5515. WREG32(MC_VM_MX_L1_TLB_CNTL, SYSTEM_ACCESS_MODE_NOT_IN_SYS |
  5516. SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU);
  5517. /* Setup L2 cache */
  5518. WREG32(VM_L2_CNTL,
  5519. ENABLE_L2_FRAGMENT_PROCESSING |
  5520. ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
  5521. ENABLE_L2_PDE0_CACHE_LRU_UPDATE_BY_WRITE |
  5522. EFFECTIVE_L2_QUEUE_SIZE(7) |
  5523. CONTEXT1_IDENTITY_ACCESS_MODE(1));
  5524. WREG32(VM_L2_CNTL2, 0);
  5525. WREG32(VM_L2_CNTL3, L2_CACHE_BIGK_ASSOCIATIVITY |
  5526. L2_CACHE_BIGK_FRAGMENT_SIZE(6));
  5527. radeon_gart_table_vram_unpin(rdev);
  5528. }
  5529. /**
  5530. * cik_pcie_gart_fini - vm fini callback
  5531. *
  5532. * @rdev: radeon_device pointer
  5533. *
  5534. * Tears down the driver GART/VM setup (CIK).
  5535. */
  5536. static void cik_pcie_gart_fini(struct radeon_device *rdev)
  5537. {
  5538. cik_pcie_gart_disable(rdev);
  5539. radeon_gart_table_vram_free(rdev);
  5540. radeon_gart_fini(rdev);
  5541. }
  5542. /* vm parser */
  5543. /**
  5544. * cik_ib_parse - vm ib_parse callback
  5545. *
  5546. * @rdev: radeon_device pointer
  5547. * @ib: indirect buffer pointer
  5548. *
  5549. * CIK uses hw IB checking so this is a nop (CIK).
  5550. */
  5551. int cik_ib_parse(struct radeon_device *rdev, struct radeon_ib *ib)
  5552. {
  5553. return 0;
  5554. }
  5555. /*
  5556. * vm
  5557. * VMID 0 is the physical GPU addresses as used by the kernel.
  5558. * VMIDs 1-15 are used for userspace clients and are handled
  5559. * by the radeon vm/hsa code.
  5560. */
  5561. /**
  5562. * cik_vm_init - cik vm init callback
  5563. *
  5564. * @rdev: radeon_device pointer
  5565. *
  5566. * Inits cik specific vm parameters (number of VMs, base of vram for
  5567. * VMIDs 1-15) (CIK).
  5568. * Returns 0 for success.
  5569. */
  5570. int cik_vm_init(struct radeon_device *rdev)
  5571. {
  5572. /*
  5573. * number of VMs
  5574. * VMID 0 is reserved for System
  5575. * radeon graphics/compute will use VMIDs 1-7
  5576. * amdkfd will use VMIDs 8-15
  5577. */
  5578. rdev->vm_manager.nvm = RADEON_NUM_OF_VMIDS;
  5579. /* base offset of vram pages */
  5580. if (rdev->flags & RADEON_IS_IGP) {
  5581. u64 tmp = RREG32(MC_VM_FB_OFFSET);
  5582. tmp <<= 22;
  5583. rdev->vm_manager.vram_base_offset = tmp;
  5584. } else
  5585. rdev->vm_manager.vram_base_offset = 0;
  5586. return 0;
  5587. }
  5588. /**
  5589. * cik_vm_fini - cik vm fini callback
  5590. *
  5591. * @rdev: radeon_device pointer
  5592. *
  5593. * Tear down any asic specific VM setup (CIK).
  5594. */
  5595. void cik_vm_fini(struct radeon_device *rdev)
  5596. {
  5597. }
  5598. /**
  5599. * cik_vm_decode_fault - print human readable fault info
  5600. *
  5601. * @rdev: radeon_device pointer
  5602. * @status: VM_CONTEXT1_PROTECTION_FAULT_STATUS register value
  5603. * @addr: VM_CONTEXT1_PROTECTION_FAULT_ADDR register value
  5604. *
  5605. * Print human readable fault information (CIK).
  5606. */
  5607. static void cik_vm_decode_fault(struct radeon_device *rdev,
  5608. u32 status, u32 addr, u32 mc_client)
  5609. {
  5610. u32 mc_id;
  5611. u32 vmid = (status & FAULT_VMID_MASK) >> FAULT_VMID_SHIFT;
  5612. u32 protections = (status & PROTECTIONS_MASK) >> PROTECTIONS_SHIFT;
  5613. char block[5] = { mc_client >> 24, (mc_client >> 16) & 0xff,
  5614. (mc_client >> 8) & 0xff, mc_client & 0xff, 0 };
  5615. if (rdev->family == CHIP_HAWAII)
  5616. mc_id = (status & HAWAII_MEMORY_CLIENT_ID_MASK) >> MEMORY_CLIENT_ID_SHIFT;
  5617. else
  5618. mc_id = (status & MEMORY_CLIENT_ID_MASK) >> MEMORY_CLIENT_ID_SHIFT;
  5619. printk("VM fault (0x%02x, vmid %d) at page %u, %s from '%s' (0x%08x) (%d)\n",
  5620. protections, vmid, addr,
  5621. (status & MEMORY_CLIENT_RW_MASK) ? "write" : "read",
  5622. block, mc_client, mc_id);
  5623. }
  5624. /**
  5625. * cik_vm_flush - cik vm flush using the CP
  5626. *
  5627. * @rdev: radeon_device pointer
  5628. *
  5629. * Update the page table base and flush the VM TLB
  5630. * using the CP (CIK).
  5631. */
  5632. void cik_vm_flush(struct radeon_device *rdev, struct radeon_ring *ring,
  5633. unsigned vm_id, uint64_t pd_addr)
  5634. {
  5635. int usepfp = (ring->idx == RADEON_RING_TYPE_GFX_INDEX);
  5636. radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  5637. radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(usepfp) |
  5638. WRITE_DATA_DST_SEL(0)));
  5639. if (vm_id < 8) {
  5640. radeon_ring_write(ring,
  5641. (VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (vm_id << 2)) >> 2);
  5642. } else {
  5643. radeon_ring_write(ring,
  5644. (VM_CONTEXT8_PAGE_TABLE_BASE_ADDR + ((vm_id - 8) << 2)) >> 2);
  5645. }
  5646. radeon_ring_write(ring, 0);
  5647. radeon_ring_write(ring, pd_addr >> 12);
  5648. /* update SH_MEM_* regs */
  5649. radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  5650. radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(usepfp) |
  5651. WRITE_DATA_DST_SEL(0)));
  5652. radeon_ring_write(ring, SRBM_GFX_CNTL >> 2);
  5653. radeon_ring_write(ring, 0);
  5654. radeon_ring_write(ring, VMID(vm_id));
  5655. radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 6));
  5656. radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(usepfp) |
  5657. WRITE_DATA_DST_SEL(0)));
  5658. radeon_ring_write(ring, SH_MEM_BASES >> 2);
  5659. radeon_ring_write(ring, 0);
  5660. radeon_ring_write(ring, 0); /* SH_MEM_BASES */
  5661. radeon_ring_write(ring, 0); /* SH_MEM_CONFIG */
  5662. radeon_ring_write(ring, 1); /* SH_MEM_APE1_BASE */
  5663. radeon_ring_write(ring, 0); /* SH_MEM_APE1_LIMIT */
  5664. radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  5665. radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(usepfp) |
  5666. WRITE_DATA_DST_SEL(0)));
  5667. radeon_ring_write(ring, SRBM_GFX_CNTL >> 2);
  5668. radeon_ring_write(ring, 0);
  5669. radeon_ring_write(ring, VMID(0));
  5670. /* HDP flush */
  5671. cik_hdp_flush_cp_ring_emit(rdev, ring->idx);
  5672. /* bits 0-15 are the VM contexts0-15 */
  5673. radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  5674. radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(usepfp) |
  5675. WRITE_DATA_DST_SEL(0)));
  5676. radeon_ring_write(ring, VM_INVALIDATE_REQUEST >> 2);
  5677. radeon_ring_write(ring, 0);
  5678. radeon_ring_write(ring, 1 << vm_id);
  5679. /* wait for the invalidate to complete */
  5680. radeon_ring_write(ring, PACKET3(PACKET3_WAIT_REG_MEM, 5));
  5681. radeon_ring_write(ring, (WAIT_REG_MEM_OPERATION(0) | /* wait */
  5682. WAIT_REG_MEM_FUNCTION(0) | /* always */
  5683. WAIT_REG_MEM_ENGINE(0))); /* me */
  5684. radeon_ring_write(ring, VM_INVALIDATE_REQUEST >> 2);
  5685. radeon_ring_write(ring, 0);
  5686. radeon_ring_write(ring, 0); /* ref */
  5687. radeon_ring_write(ring, 0); /* mask */
  5688. radeon_ring_write(ring, 0x20); /* poll interval */
  5689. /* compute doesn't have PFP */
  5690. if (usepfp) {
  5691. /* sync PFP to ME, otherwise we might get invalid PFP reads */
  5692. radeon_ring_write(ring, PACKET3(PACKET3_PFP_SYNC_ME, 0));
  5693. radeon_ring_write(ring, 0x0);
  5694. }
  5695. }
  5696. /*
  5697. * RLC
  5698. * The RLC is a multi-purpose microengine that handles a
  5699. * variety of functions, the most important of which is
  5700. * the interrupt controller.
  5701. */
  5702. static void cik_enable_gui_idle_interrupt(struct radeon_device *rdev,
  5703. bool enable)
  5704. {
  5705. u32 tmp = RREG32(CP_INT_CNTL_RING0);
  5706. if (enable)
  5707. tmp |= (CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
  5708. else
  5709. tmp &= ~(CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
  5710. WREG32(CP_INT_CNTL_RING0, tmp);
  5711. }
  5712. static void cik_enable_lbpw(struct radeon_device *rdev, bool enable)
  5713. {
  5714. u32 tmp;
  5715. tmp = RREG32(RLC_LB_CNTL);
  5716. if (enable)
  5717. tmp |= LOAD_BALANCE_ENABLE;
  5718. else
  5719. tmp &= ~LOAD_BALANCE_ENABLE;
  5720. WREG32(RLC_LB_CNTL, tmp);
  5721. }
  5722. static void cik_wait_for_rlc_serdes(struct radeon_device *rdev)
  5723. {
  5724. u32 i, j, k;
  5725. u32 mask;
  5726. mutex_lock(&rdev->grbm_idx_mutex);
  5727. for (i = 0; i < rdev->config.cik.max_shader_engines; i++) {
  5728. for (j = 0; j < rdev->config.cik.max_sh_per_se; j++) {
  5729. cik_select_se_sh(rdev, i, j);
  5730. for (k = 0; k < rdev->usec_timeout; k++) {
  5731. if (RREG32(RLC_SERDES_CU_MASTER_BUSY) == 0)
  5732. break;
  5733. udelay(1);
  5734. }
  5735. }
  5736. }
  5737. cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
  5738. mutex_unlock(&rdev->grbm_idx_mutex);
  5739. mask = SE_MASTER_BUSY_MASK | GC_MASTER_BUSY | TC0_MASTER_BUSY | TC1_MASTER_BUSY;
  5740. for (k = 0; k < rdev->usec_timeout; k++) {
  5741. if ((RREG32(RLC_SERDES_NONCU_MASTER_BUSY) & mask) == 0)
  5742. break;
  5743. udelay(1);
  5744. }
  5745. }
  5746. static void cik_update_rlc(struct radeon_device *rdev, u32 rlc)
  5747. {
  5748. u32 tmp;
  5749. tmp = RREG32(RLC_CNTL);
  5750. if (tmp != rlc)
  5751. WREG32(RLC_CNTL, rlc);
  5752. }
  5753. static u32 cik_halt_rlc(struct radeon_device *rdev)
  5754. {
  5755. u32 data, orig;
  5756. orig = data = RREG32(RLC_CNTL);
  5757. if (data & RLC_ENABLE) {
  5758. u32 i;
  5759. data &= ~RLC_ENABLE;
  5760. WREG32(RLC_CNTL, data);
  5761. for (i = 0; i < rdev->usec_timeout; i++) {
  5762. if ((RREG32(RLC_GPM_STAT) & RLC_GPM_BUSY) == 0)
  5763. break;
  5764. udelay(1);
  5765. }
  5766. cik_wait_for_rlc_serdes(rdev);
  5767. }
  5768. return orig;
  5769. }
  5770. void cik_enter_rlc_safe_mode(struct radeon_device *rdev)
  5771. {
  5772. u32 tmp, i, mask;
  5773. tmp = REQ | MESSAGE(MSG_ENTER_RLC_SAFE_MODE);
  5774. WREG32(RLC_GPR_REG2, tmp);
  5775. mask = GFX_POWER_STATUS | GFX_CLOCK_STATUS;
  5776. for (i = 0; i < rdev->usec_timeout; i++) {
  5777. if ((RREG32(RLC_GPM_STAT) & mask) == mask)
  5778. break;
  5779. udelay(1);
  5780. }
  5781. for (i = 0; i < rdev->usec_timeout; i++) {
  5782. if ((RREG32(RLC_GPR_REG2) & REQ) == 0)
  5783. break;
  5784. udelay(1);
  5785. }
  5786. }
  5787. void cik_exit_rlc_safe_mode(struct radeon_device *rdev)
  5788. {
  5789. u32 tmp;
  5790. tmp = REQ | MESSAGE(MSG_EXIT_RLC_SAFE_MODE);
  5791. WREG32(RLC_GPR_REG2, tmp);
  5792. }
  5793. /**
  5794. * cik_rlc_stop - stop the RLC ME
  5795. *
  5796. * @rdev: radeon_device pointer
  5797. *
  5798. * Halt the RLC ME (MicroEngine) (CIK).
  5799. */
  5800. static void cik_rlc_stop(struct radeon_device *rdev)
  5801. {
  5802. WREG32(RLC_CNTL, 0);
  5803. cik_enable_gui_idle_interrupt(rdev, false);
  5804. cik_wait_for_rlc_serdes(rdev);
  5805. }
  5806. /**
  5807. * cik_rlc_start - start the RLC ME
  5808. *
  5809. * @rdev: radeon_device pointer
  5810. *
  5811. * Unhalt the RLC ME (MicroEngine) (CIK).
  5812. */
  5813. static void cik_rlc_start(struct radeon_device *rdev)
  5814. {
  5815. WREG32(RLC_CNTL, RLC_ENABLE);
  5816. cik_enable_gui_idle_interrupt(rdev, true);
  5817. udelay(50);
  5818. }
  5819. /**
  5820. * cik_rlc_resume - setup the RLC hw
  5821. *
  5822. * @rdev: radeon_device pointer
  5823. *
  5824. * Initialize the RLC registers, load the ucode,
  5825. * and start the RLC (CIK).
  5826. * Returns 0 for success, -EINVAL if the ucode is not available.
  5827. */
  5828. static int cik_rlc_resume(struct radeon_device *rdev)
  5829. {
  5830. u32 i, size, tmp;
  5831. if (!rdev->rlc_fw)
  5832. return -EINVAL;
  5833. cik_rlc_stop(rdev);
  5834. /* disable CG */
  5835. tmp = RREG32(RLC_CGCG_CGLS_CTRL) & 0xfffffffc;
  5836. WREG32(RLC_CGCG_CGLS_CTRL, tmp);
  5837. si_rlc_reset(rdev);
  5838. cik_init_pg(rdev);
  5839. cik_init_cg(rdev);
  5840. WREG32(RLC_LB_CNTR_INIT, 0);
  5841. WREG32(RLC_LB_CNTR_MAX, 0x00008000);
  5842. mutex_lock(&rdev->grbm_idx_mutex);
  5843. cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
  5844. WREG32(RLC_LB_INIT_CU_MASK, 0xffffffff);
  5845. WREG32(RLC_LB_PARAMS, 0x00600408);
  5846. WREG32(RLC_LB_CNTL, 0x80000004);
  5847. mutex_unlock(&rdev->grbm_idx_mutex);
  5848. WREG32(RLC_MC_CNTL, 0);
  5849. WREG32(RLC_UCODE_CNTL, 0);
  5850. if (rdev->new_fw) {
  5851. const struct rlc_firmware_header_v1_0 *hdr =
  5852. (const struct rlc_firmware_header_v1_0 *)rdev->rlc_fw->data;
  5853. const __le32 *fw_data = (const __le32 *)
  5854. (rdev->rlc_fw->data + le32_to_cpu(hdr->header.ucode_array_offset_bytes));
  5855. radeon_ucode_print_rlc_hdr(&hdr->header);
  5856. size = le32_to_cpu(hdr->header.ucode_size_bytes) / 4;
  5857. WREG32(RLC_GPM_UCODE_ADDR, 0);
  5858. for (i = 0; i < size; i++)
  5859. WREG32(RLC_GPM_UCODE_DATA, le32_to_cpup(fw_data++));
  5860. WREG32(RLC_GPM_UCODE_ADDR, le32_to_cpu(hdr->header.ucode_version));
  5861. } else {
  5862. const __be32 *fw_data;
  5863. switch (rdev->family) {
  5864. case CHIP_BONAIRE:
  5865. case CHIP_HAWAII:
  5866. default:
  5867. size = BONAIRE_RLC_UCODE_SIZE;
  5868. break;
  5869. case CHIP_KAVERI:
  5870. size = KV_RLC_UCODE_SIZE;
  5871. break;
  5872. case CHIP_KABINI:
  5873. size = KB_RLC_UCODE_SIZE;
  5874. break;
  5875. case CHIP_MULLINS:
  5876. size = ML_RLC_UCODE_SIZE;
  5877. break;
  5878. }
  5879. fw_data = (const __be32 *)rdev->rlc_fw->data;
  5880. WREG32(RLC_GPM_UCODE_ADDR, 0);
  5881. for (i = 0; i < size; i++)
  5882. WREG32(RLC_GPM_UCODE_DATA, be32_to_cpup(fw_data++));
  5883. WREG32(RLC_GPM_UCODE_ADDR, 0);
  5884. }
  5885. /* XXX - find out what chips support lbpw */
  5886. cik_enable_lbpw(rdev, false);
  5887. if (rdev->family == CHIP_BONAIRE)
  5888. WREG32(RLC_DRIVER_DMA_STATUS, 0);
  5889. cik_rlc_start(rdev);
  5890. return 0;
  5891. }
  5892. static void cik_enable_cgcg(struct radeon_device *rdev, bool enable)
  5893. {
  5894. u32 data, orig, tmp, tmp2;
  5895. orig = data = RREG32(RLC_CGCG_CGLS_CTRL);
  5896. if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_GFX_CGCG)) {
  5897. cik_enable_gui_idle_interrupt(rdev, true);
  5898. tmp = cik_halt_rlc(rdev);
  5899. mutex_lock(&rdev->grbm_idx_mutex);
  5900. cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
  5901. WREG32(RLC_SERDES_WR_CU_MASTER_MASK, 0xffffffff);
  5902. WREG32(RLC_SERDES_WR_NONCU_MASTER_MASK, 0xffffffff);
  5903. tmp2 = BPM_ADDR_MASK | CGCG_OVERRIDE_0 | CGLS_ENABLE;
  5904. WREG32(RLC_SERDES_WR_CTRL, tmp2);
  5905. mutex_unlock(&rdev->grbm_idx_mutex);
  5906. cik_update_rlc(rdev, tmp);
  5907. data |= CGCG_EN | CGLS_EN;
  5908. } else {
  5909. cik_enable_gui_idle_interrupt(rdev, false);
  5910. RREG32(CB_CGTT_SCLK_CTRL);
  5911. RREG32(CB_CGTT_SCLK_CTRL);
  5912. RREG32(CB_CGTT_SCLK_CTRL);
  5913. RREG32(CB_CGTT_SCLK_CTRL);
  5914. data &= ~(CGCG_EN | CGLS_EN);
  5915. }
  5916. if (orig != data)
  5917. WREG32(RLC_CGCG_CGLS_CTRL, data);
  5918. }
  5919. static void cik_enable_mgcg(struct radeon_device *rdev, bool enable)
  5920. {
  5921. u32 data, orig, tmp = 0;
  5922. if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_GFX_MGCG)) {
  5923. if (rdev->cg_flags & RADEON_CG_SUPPORT_GFX_MGLS) {
  5924. if (rdev->cg_flags & RADEON_CG_SUPPORT_GFX_CP_LS) {
  5925. orig = data = RREG32(CP_MEM_SLP_CNTL);
  5926. data |= CP_MEM_LS_EN;
  5927. if (orig != data)
  5928. WREG32(CP_MEM_SLP_CNTL, data);
  5929. }
  5930. }
  5931. orig = data = RREG32(RLC_CGTT_MGCG_OVERRIDE);
  5932. data |= 0x00000001;
  5933. data &= 0xfffffffd;
  5934. if (orig != data)
  5935. WREG32(RLC_CGTT_MGCG_OVERRIDE, data);
  5936. tmp = cik_halt_rlc(rdev);
  5937. mutex_lock(&rdev->grbm_idx_mutex);
  5938. cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
  5939. WREG32(RLC_SERDES_WR_CU_MASTER_MASK, 0xffffffff);
  5940. WREG32(RLC_SERDES_WR_NONCU_MASTER_MASK, 0xffffffff);
  5941. data = BPM_ADDR_MASK | MGCG_OVERRIDE_0;
  5942. WREG32(RLC_SERDES_WR_CTRL, data);
  5943. mutex_unlock(&rdev->grbm_idx_mutex);
  5944. cik_update_rlc(rdev, tmp);
  5945. if (rdev->cg_flags & RADEON_CG_SUPPORT_GFX_CGTS) {
  5946. orig = data = RREG32(CGTS_SM_CTRL_REG);
  5947. data &= ~SM_MODE_MASK;
  5948. data |= SM_MODE(0x2);
  5949. data |= SM_MODE_ENABLE;
  5950. data &= ~CGTS_OVERRIDE;
  5951. if ((rdev->cg_flags & RADEON_CG_SUPPORT_GFX_MGLS) &&
  5952. (rdev->cg_flags & RADEON_CG_SUPPORT_GFX_CGTS_LS))
  5953. data &= ~CGTS_LS_OVERRIDE;
  5954. data &= ~ON_MONITOR_ADD_MASK;
  5955. data |= ON_MONITOR_ADD_EN;
  5956. data |= ON_MONITOR_ADD(0x96);
  5957. if (orig != data)
  5958. WREG32(CGTS_SM_CTRL_REG, data);
  5959. }
  5960. } else {
  5961. orig = data = RREG32(RLC_CGTT_MGCG_OVERRIDE);
  5962. data |= 0x00000003;
  5963. if (orig != data)
  5964. WREG32(RLC_CGTT_MGCG_OVERRIDE, data);
  5965. data = RREG32(RLC_MEM_SLP_CNTL);
  5966. if (data & RLC_MEM_LS_EN) {
  5967. data &= ~RLC_MEM_LS_EN;
  5968. WREG32(RLC_MEM_SLP_CNTL, data);
  5969. }
  5970. data = RREG32(CP_MEM_SLP_CNTL);
  5971. if (data & CP_MEM_LS_EN) {
  5972. data &= ~CP_MEM_LS_EN;
  5973. WREG32(CP_MEM_SLP_CNTL, data);
  5974. }
  5975. orig = data = RREG32(CGTS_SM_CTRL_REG);
  5976. data |= CGTS_OVERRIDE | CGTS_LS_OVERRIDE;
  5977. if (orig != data)
  5978. WREG32(CGTS_SM_CTRL_REG, data);
  5979. tmp = cik_halt_rlc(rdev);
  5980. mutex_lock(&rdev->grbm_idx_mutex);
  5981. cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
  5982. WREG32(RLC_SERDES_WR_CU_MASTER_MASK, 0xffffffff);
  5983. WREG32(RLC_SERDES_WR_NONCU_MASTER_MASK, 0xffffffff);
  5984. data = BPM_ADDR_MASK | MGCG_OVERRIDE_1;
  5985. WREG32(RLC_SERDES_WR_CTRL, data);
  5986. mutex_unlock(&rdev->grbm_idx_mutex);
  5987. cik_update_rlc(rdev, tmp);
  5988. }
  5989. }
  5990. static const u32 mc_cg_registers[] =
  5991. {
  5992. MC_HUB_MISC_HUB_CG,
  5993. MC_HUB_MISC_SIP_CG,
  5994. MC_HUB_MISC_VM_CG,
  5995. MC_XPB_CLK_GAT,
  5996. ATC_MISC_CG,
  5997. MC_CITF_MISC_WR_CG,
  5998. MC_CITF_MISC_RD_CG,
  5999. MC_CITF_MISC_VM_CG,
  6000. VM_L2_CG,
  6001. };
  6002. static void cik_enable_mc_ls(struct radeon_device *rdev,
  6003. bool enable)
  6004. {
  6005. int i;
  6006. u32 orig, data;
  6007. for (i = 0; i < ARRAY_SIZE(mc_cg_registers); i++) {
  6008. orig = data = RREG32(mc_cg_registers[i]);
  6009. if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_MC_LS))
  6010. data |= MC_LS_ENABLE;
  6011. else
  6012. data &= ~MC_LS_ENABLE;
  6013. if (data != orig)
  6014. WREG32(mc_cg_registers[i], data);
  6015. }
  6016. }
  6017. static void cik_enable_mc_mgcg(struct radeon_device *rdev,
  6018. bool enable)
  6019. {
  6020. int i;
  6021. u32 orig, data;
  6022. for (i = 0; i < ARRAY_SIZE(mc_cg_registers); i++) {
  6023. orig = data = RREG32(mc_cg_registers[i]);
  6024. if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_MC_MGCG))
  6025. data |= MC_CG_ENABLE;
  6026. else
  6027. data &= ~MC_CG_ENABLE;
  6028. if (data != orig)
  6029. WREG32(mc_cg_registers[i], data);
  6030. }
  6031. }
  6032. static void cik_enable_sdma_mgcg(struct radeon_device *rdev,
  6033. bool enable)
  6034. {
  6035. u32 orig, data;
  6036. if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_SDMA_MGCG)) {
  6037. WREG32(SDMA0_CLK_CTRL + SDMA0_REGISTER_OFFSET, 0x00000100);
  6038. WREG32(SDMA0_CLK_CTRL + SDMA1_REGISTER_OFFSET, 0x00000100);
  6039. } else {
  6040. orig = data = RREG32(SDMA0_CLK_CTRL + SDMA0_REGISTER_OFFSET);
  6041. data |= 0xff000000;
  6042. if (data != orig)
  6043. WREG32(SDMA0_CLK_CTRL + SDMA0_REGISTER_OFFSET, data);
  6044. orig = data = RREG32(SDMA0_CLK_CTRL + SDMA1_REGISTER_OFFSET);
  6045. data |= 0xff000000;
  6046. if (data != orig)
  6047. WREG32(SDMA0_CLK_CTRL + SDMA1_REGISTER_OFFSET, data);
  6048. }
  6049. }
  6050. static void cik_enable_sdma_mgls(struct radeon_device *rdev,
  6051. bool enable)
  6052. {
  6053. u32 orig, data;
  6054. if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_SDMA_LS)) {
  6055. orig = data = RREG32(SDMA0_POWER_CNTL + SDMA0_REGISTER_OFFSET);
  6056. data |= 0x100;
  6057. if (orig != data)
  6058. WREG32(SDMA0_POWER_CNTL + SDMA0_REGISTER_OFFSET, data);
  6059. orig = data = RREG32(SDMA0_POWER_CNTL + SDMA1_REGISTER_OFFSET);
  6060. data |= 0x100;
  6061. if (orig != data)
  6062. WREG32(SDMA0_POWER_CNTL + SDMA1_REGISTER_OFFSET, data);
  6063. } else {
  6064. orig = data = RREG32(SDMA0_POWER_CNTL + SDMA0_REGISTER_OFFSET);
  6065. data &= ~0x100;
  6066. if (orig != data)
  6067. WREG32(SDMA0_POWER_CNTL + SDMA0_REGISTER_OFFSET, data);
  6068. orig = data = RREG32(SDMA0_POWER_CNTL + SDMA1_REGISTER_OFFSET);
  6069. data &= ~0x100;
  6070. if (orig != data)
  6071. WREG32(SDMA0_POWER_CNTL + SDMA1_REGISTER_OFFSET, data);
  6072. }
  6073. }
  6074. static void cik_enable_uvd_mgcg(struct radeon_device *rdev,
  6075. bool enable)
  6076. {
  6077. u32 orig, data;
  6078. if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_UVD_MGCG)) {
  6079. data = RREG32_UVD_CTX(UVD_CGC_MEM_CTRL);
  6080. data = 0xfff;
  6081. WREG32_UVD_CTX(UVD_CGC_MEM_CTRL, data);
  6082. orig = data = RREG32(UVD_CGC_CTRL);
  6083. data |= DCM;
  6084. if (orig != data)
  6085. WREG32(UVD_CGC_CTRL, data);
  6086. } else {
  6087. data = RREG32_UVD_CTX(UVD_CGC_MEM_CTRL);
  6088. data &= ~0xfff;
  6089. WREG32_UVD_CTX(UVD_CGC_MEM_CTRL, data);
  6090. orig = data = RREG32(UVD_CGC_CTRL);
  6091. data &= ~DCM;
  6092. if (orig != data)
  6093. WREG32(UVD_CGC_CTRL, data);
  6094. }
  6095. }
  6096. static void cik_enable_bif_mgls(struct radeon_device *rdev,
  6097. bool enable)
  6098. {
  6099. u32 orig, data;
  6100. orig = data = RREG32_PCIE_PORT(PCIE_CNTL2);
  6101. if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_BIF_LS))
  6102. data |= SLV_MEM_LS_EN | MST_MEM_LS_EN |
  6103. REPLAY_MEM_LS_EN | SLV_MEM_AGGRESSIVE_LS_EN;
  6104. else
  6105. data &= ~(SLV_MEM_LS_EN | MST_MEM_LS_EN |
  6106. REPLAY_MEM_LS_EN | SLV_MEM_AGGRESSIVE_LS_EN);
  6107. if (orig != data)
  6108. WREG32_PCIE_PORT(PCIE_CNTL2, data);
  6109. }
  6110. static void cik_enable_hdp_mgcg(struct radeon_device *rdev,
  6111. bool enable)
  6112. {
  6113. u32 orig, data;
  6114. orig = data = RREG32(HDP_HOST_PATH_CNTL);
  6115. if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_HDP_MGCG))
  6116. data &= ~CLOCK_GATING_DIS;
  6117. else
  6118. data |= CLOCK_GATING_DIS;
  6119. if (orig != data)
  6120. WREG32(HDP_HOST_PATH_CNTL, data);
  6121. }
  6122. static void cik_enable_hdp_ls(struct radeon_device *rdev,
  6123. bool enable)
  6124. {
  6125. u32 orig, data;
  6126. orig = data = RREG32(HDP_MEM_POWER_LS);
  6127. if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_HDP_LS))
  6128. data |= HDP_LS_ENABLE;
  6129. else
  6130. data &= ~HDP_LS_ENABLE;
  6131. if (orig != data)
  6132. WREG32(HDP_MEM_POWER_LS, data);
  6133. }
  6134. void cik_update_cg(struct radeon_device *rdev,
  6135. u32 block, bool enable)
  6136. {
  6137. if (block & RADEON_CG_BLOCK_GFX) {
  6138. cik_enable_gui_idle_interrupt(rdev, false);
  6139. /* order matters! */
  6140. if (enable) {
  6141. cik_enable_mgcg(rdev, true);
  6142. cik_enable_cgcg(rdev, true);
  6143. } else {
  6144. cik_enable_cgcg(rdev, false);
  6145. cik_enable_mgcg(rdev, false);
  6146. }
  6147. cik_enable_gui_idle_interrupt(rdev, true);
  6148. }
  6149. if (block & RADEON_CG_BLOCK_MC) {
  6150. if (!(rdev->flags & RADEON_IS_IGP)) {
  6151. cik_enable_mc_mgcg(rdev, enable);
  6152. cik_enable_mc_ls(rdev, enable);
  6153. }
  6154. }
  6155. if (block & RADEON_CG_BLOCK_SDMA) {
  6156. cik_enable_sdma_mgcg(rdev, enable);
  6157. cik_enable_sdma_mgls(rdev, enable);
  6158. }
  6159. if (block & RADEON_CG_BLOCK_BIF) {
  6160. cik_enable_bif_mgls(rdev, enable);
  6161. }
  6162. if (block & RADEON_CG_BLOCK_UVD) {
  6163. if (rdev->has_uvd)
  6164. cik_enable_uvd_mgcg(rdev, enable);
  6165. }
  6166. if (block & RADEON_CG_BLOCK_HDP) {
  6167. cik_enable_hdp_mgcg(rdev, enable);
  6168. cik_enable_hdp_ls(rdev, enable);
  6169. }
  6170. if (block & RADEON_CG_BLOCK_VCE) {
  6171. vce_v2_0_enable_mgcg(rdev, enable);
  6172. }
  6173. }
  6174. static void cik_init_cg(struct radeon_device *rdev)
  6175. {
  6176. cik_update_cg(rdev, RADEON_CG_BLOCK_GFX, true);
  6177. if (rdev->has_uvd)
  6178. si_init_uvd_internal_cg(rdev);
  6179. cik_update_cg(rdev, (RADEON_CG_BLOCK_MC |
  6180. RADEON_CG_BLOCK_SDMA |
  6181. RADEON_CG_BLOCK_BIF |
  6182. RADEON_CG_BLOCK_UVD |
  6183. RADEON_CG_BLOCK_HDP), true);
  6184. }
  6185. static void cik_fini_cg(struct radeon_device *rdev)
  6186. {
  6187. cik_update_cg(rdev, (RADEON_CG_BLOCK_MC |
  6188. RADEON_CG_BLOCK_SDMA |
  6189. RADEON_CG_BLOCK_BIF |
  6190. RADEON_CG_BLOCK_UVD |
  6191. RADEON_CG_BLOCK_HDP), false);
  6192. cik_update_cg(rdev, RADEON_CG_BLOCK_GFX, false);
  6193. }
  6194. static void cik_enable_sck_slowdown_on_pu(struct radeon_device *rdev,
  6195. bool enable)
  6196. {
  6197. u32 data, orig;
  6198. orig = data = RREG32(RLC_PG_CNTL);
  6199. if (enable && (rdev->pg_flags & RADEON_PG_SUPPORT_RLC_SMU_HS))
  6200. data |= SMU_CLK_SLOWDOWN_ON_PU_ENABLE;
  6201. else
  6202. data &= ~SMU_CLK_SLOWDOWN_ON_PU_ENABLE;
  6203. if (orig != data)
  6204. WREG32(RLC_PG_CNTL, data);
  6205. }
  6206. static void cik_enable_sck_slowdown_on_pd(struct radeon_device *rdev,
  6207. bool enable)
  6208. {
  6209. u32 data, orig;
  6210. orig = data = RREG32(RLC_PG_CNTL);
  6211. if (enable && (rdev->pg_flags & RADEON_PG_SUPPORT_RLC_SMU_HS))
  6212. data |= SMU_CLK_SLOWDOWN_ON_PD_ENABLE;
  6213. else
  6214. data &= ~SMU_CLK_SLOWDOWN_ON_PD_ENABLE;
  6215. if (orig != data)
  6216. WREG32(RLC_PG_CNTL, data);
  6217. }
  6218. static void cik_enable_cp_pg(struct radeon_device *rdev, bool enable)
  6219. {
  6220. u32 data, orig;
  6221. orig = data = RREG32(RLC_PG_CNTL);
  6222. if (enable && (rdev->pg_flags & RADEON_PG_SUPPORT_CP))
  6223. data &= ~DISABLE_CP_PG;
  6224. else
  6225. data |= DISABLE_CP_PG;
  6226. if (orig != data)
  6227. WREG32(RLC_PG_CNTL, data);
  6228. }
  6229. static void cik_enable_gds_pg(struct radeon_device *rdev, bool enable)
  6230. {
  6231. u32 data, orig;
  6232. orig = data = RREG32(RLC_PG_CNTL);
  6233. if (enable && (rdev->pg_flags & RADEON_PG_SUPPORT_GDS))
  6234. data &= ~DISABLE_GDS_PG;
  6235. else
  6236. data |= DISABLE_GDS_PG;
  6237. if (orig != data)
  6238. WREG32(RLC_PG_CNTL, data);
  6239. }
  6240. #define CP_ME_TABLE_SIZE 96
  6241. #define CP_ME_TABLE_OFFSET 2048
  6242. #define CP_MEC_TABLE_OFFSET 4096
  6243. void cik_init_cp_pg_table(struct radeon_device *rdev)
  6244. {
  6245. volatile u32 *dst_ptr;
  6246. int me, i, max_me = 4;
  6247. u32 bo_offset = 0;
  6248. u32 table_offset, table_size;
  6249. if (rdev->family == CHIP_KAVERI)
  6250. max_me = 5;
  6251. if (rdev->rlc.cp_table_ptr == NULL)
  6252. return;
  6253. /* write the cp table buffer */
  6254. dst_ptr = rdev->rlc.cp_table_ptr;
  6255. for (me = 0; me < max_me; me++) {
  6256. if (rdev->new_fw) {
  6257. const __le32 *fw_data;
  6258. const struct gfx_firmware_header_v1_0 *hdr;
  6259. if (me == 0) {
  6260. hdr = (const struct gfx_firmware_header_v1_0 *)rdev->ce_fw->data;
  6261. fw_data = (const __le32 *)
  6262. (rdev->ce_fw->data + le32_to_cpu(hdr->header.ucode_array_offset_bytes));
  6263. table_offset = le32_to_cpu(hdr->jt_offset);
  6264. table_size = le32_to_cpu(hdr->jt_size);
  6265. } else if (me == 1) {
  6266. hdr = (const struct gfx_firmware_header_v1_0 *)rdev->pfp_fw->data;
  6267. fw_data = (const __le32 *)
  6268. (rdev->pfp_fw->data + le32_to_cpu(hdr->header.ucode_array_offset_bytes));
  6269. table_offset = le32_to_cpu(hdr->jt_offset);
  6270. table_size = le32_to_cpu(hdr->jt_size);
  6271. } else if (me == 2) {
  6272. hdr = (const struct gfx_firmware_header_v1_0 *)rdev->me_fw->data;
  6273. fw_data = (const __le32 *)
  6274. (rdev->me_fw->data + le32_to_cpu(hdr->header.ucode_array_offset_bytes));
  6275. table_offset = le32_to_cpu(hdr->jt_offset);
  6276. table_size = le32_to_cpu(hdr->jt_size);
  6277. } else if (me == 3) {
  6278. hdr = (const struct gfx_firmware_header_v1_0 *)rdev->mec_fw->data;
  6279. fw_data = (const __le32 *)
  6280. (rdev->mec_fw->data + le32_to_cpu(hdr->header.ucode_array_offset_bytes));
  6281. table_offset = le32_to_cpu(hdr->jt_offset);
  6282. table_size = le32_to_cpu(hdr->jt_size);
  6283. } else {
  6284. hdr = (const struct gfx_firmware_header_v1_0 *)rdev->mec2_fw->data;
  6285. fw_data = (const __le32 *)
  6286. (rdev->mec2_fw->data + le32_to_cpu(hdr->header.ucode_array_offset_bytes));
  6287. table_offset = le32_to_cpu(hdr->jt_offset);
  6288. table_size = le32_to_cpu(hdr->jt_size);
  6289. }
  6290. for (i = 0; i < table_size; i ++) {
  6291. dst_ptr[bo_offset + i] =
  6292. cpu_to_le32(le32_to_cpu(fw_data[table_offset + i]));
  6293. }
  6294. bo_offset += table_size;
  6295. } else {
  6296. const __be32 *fw_data;
  6297. table_size = CP_ME_TABLE_SIZE;
  6298. if (me == 0) {
  6299. fw_data = (const __be32 *)rdev->ce_fw->data;
  6300. table_offset = CP_ME_TABLE_OFFSET;
  6301. } else if (me == 1) {
  6302. fw_data = (const __be32 *)rdev->pfp_fw->data;
  6303. table_offset = CP_ME_TABLE_OFFSET;
  6304. } else if (me == 2) {
  6305. fw_data = (const __be32 *)rdev->me_fw->data;
  6306. table_offset = CP_ME_TABLE_OFFSET;
  6307. } else {
  6308. fw_data = (const __be32 *)rdev->mec_fw->data;
  6309. table_offset = CP_MEC_TABLE_OFFSET;
  6310. }
  6311. for (i = 0; i < table_size; i ++) {
  6312. dst_ptr[bo_offset + i] =
  6313. cpu_to_le32(be32_to_cpu(fw_data[table_offset + i]));
  6314. }
  6315. bo_offset += table_size;
  6316. }
  6317. }
  6318. }
  6319. static void cik_enable_gfx_cgpg(struct radeon_device *rdev,
  6320. bool enable)
  6321. {
  6322. u32 data, orig;
  6323. if (enable && (rdev->pg_flags & RADEON_PG_SUPPORT_GFX_PG)) {
  6324. orig = data = RREG32(RLC_PG_CNTL);
  6325. data |= GFX_PG_ENABLE;
  6326. if (orig != data)
  6327. WREG32(RLC_PG_CNTL, data);
  6328. orig = data = RREG32(RLC_AUTO_PG_CTRL);
  6329. data |= AUTO_PG_EN;
  6330. if (orig != data)
  6331. WREG32(RLC_AUTO_PG_CTRL, data);
  6332. } else {
  6333. orig = data = RREG32(RLC_PG_CNTL);
  6334. data &= ~GFX_PG_ENABLE;
  6335. if (orig != data)
  6336. WREG32(RLC_PG_CNTL, data);
  6337. orig = data = RREG32(RLC_AUTO_PG_CTRL);
  6338. data &= ~AUTO_PG_EN;
  6339. if (orig != data)
  6340. WREG32(RLC_AUTO_PG_CTRL, data);
  6341. data = RREG32(DB_RENDER_CONTROL);
  6342. }
  6343. }
  6344. static u32 cik_get_cu_active_bitmap(struct radeon_device *rdev, u32 se, u32 sh)
  6345. {
  6346. u32 mask = 0, tmp, tmp1;
  6347. int i;
  6348. mutex_lock(&rdev->grbm_idx_mutex);
  6349. cik_select_se_sh(rdev, se, sh);
  6350. tmp = RREG32(CC_GC_SHADER_ARRAY_CONFIG);
  6351. tmp1 = RREG32(GC_USER_SHADER_ARRAY_CONFIG);
  6352. cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
  6353. mutex_unlock(&rdev->grbm_idx_mutex);
  6354. tmp &= 0xffff0000;
  6355. tmp |= tmp1;
  6356. tmp >>= 16;
  6357. for (i = 0; i < rdev->config.cik.max_cu_per_sh; i ++) {
  6358. mask <<= 1;
  6359. mask |= 1;
  6360. }
  6361. return (~tmp) & mask;
  6362. }
  6363. static void cik_init_ao_cu_mask(struct radeon_device *rdev)
  6364. {
  6365. u32 i, j, k, active_cu_number = 0;
  6366. u32 mask, counter, cu_bitmap;
  6367. u32 tmp = 0;
  6368. for (i = 0; i < rdev->config.cik.max_shader_engines; i++) {
  6369. for (j = 0; j < rdev->config.cik.max_sh_per_se; j++) {
  6370. mask = 1;
  6371. cu_bitmap = 0;
  6372. counter = 0;
  6373. for (k = 0; k < rdev->config.cik.max_cu_per_sh; k ++) {
  6374. if (cik_get_cu_active_bitmap(rdev, i, j) & mask) {
  6375. if (counter < 2)
  6376. cu_bitmap |= mask;
  6377. counter ++;
  6378. }
  6379. mask <<= 1;
  6380. }
  6381. active_cu_number += counter;
  6382. tmp |= (cu_bitmap << (i * 16 + j * 8));
  6383. }
  6384. }
  6385. WREG32(RLC_PG_AO_CU_MASK, tmp);
  6386. tmp = RREG32(RLC_MAX_PG_CU);
  6387. tmp &= ~MAX_PU_CU_MASK;
  6388. tmp |= MAX_PU_CU(active_cu_number);
  6389. WREG32(RLC_MAX_PG_CU, tmp);
  6390. }
  6391. static void cik_enable_gfx_static_mgpg(struct radeon_device *rdev,
  6392. bool enable)
  6393. {
  6394. u32 data, orig;
  6395. orig = data = RREG32(RLC_PG_CNTL);
  6396. if (enable && (rdev->pg_flags & RADEON_PG_SUPPORT_GFX_SMG))
  6397. data |= STATIC_PER_CU_PG_ENABLE;
  6398. else
  6399. data &= ~STATIC_PER_CU_PG_ENABLE;
  6400. if (orig != data)
  6401. WREG32(RLC_PG_CNTL, data);
  6402. }
  6403. static void cik_enable_gfx_dynamic_mgpg(struct radeon_device *rdev,
  6404. bool enable)
  6405. {
  6406. u32 data, orig;
  6407. orig = data = RREG32(RLC_PG_CNTL);
  6408. if (enable && (rdev->pg_flags & RADEON_PG_SUPPORT_GFX_DMG))
  6409. data |= DYN_PER_CU_PG_ENABLE;
  6410. else
  6411. data &= ~DYN_PER_CU_PG_ENABLE;
  6412. if (orig != data)
  6413. WREG32(RLC_PG_CNTL, data);
  6414. }
  6415. #define RLC_SAVE_AND_RESTORE_STARTING_OFFSET 0x90
  6416. #define RLC_CLEAR_STATE_DESCRIPTOR_OFFSET 0x3D
  6417. static void cik_init_gfx_cgpg(struct radeon_device *rdev)
  6418. {
  6419. u32 data, orig;
  6420. u32 i;
  6421. if (rdev->rlc.cs_data) {
  6422. WREG32(RLC_GPM_SCRATCH_ADDR, RLC_CLEAR_STATE_DESCRIPTOR_OFFSET);
  6423. WREG32(RLC_GPM_SCRATCH_DATA, upper_32_bits(rdev->rlc.clear_state_gpu_addr));
  6424. WREG32(RLC_GPM_SCRATCH_DATA, lower_32_bits(rdev->rlc.clear_state_gpu_addr));
  6425. WREG32(RLC_GPM_SCRATCH_DATA, rdev->rlc.clear_state_size);
  6426. } else {
  6427. WREG32(RLC_GPM_SCRATCH_ADDR, RLC_CLEAR_STATE_DESCRIPTOR_OFFSET);
  6428. for (i = 0; i < 3; i++)
  6429. WREG32(RLC_GPM_SCRATCH_DATA, 0);
  6430. }
  6431. if (rdev->rlc.reg_list) {
  6432. WREG32(RLC_GPM_SCRATCH_ADDR, RLC_SAVE_AND_RESTORE_STARTING_OFFSET);
  6433. for (i = 0; i < rdev->rlc.reg_list_size; i++)
  6434. WREG32(RLC_GPM_SCRATCH_DATA, rdev->rlc.reg_list[i]);
  6435. }
  6436. orig = data = RREG32(RLC_PG_CNTL);
  6437. data |= GFX_PG_SRC;
  6438. if (orig != data)
  6439. WREG32(RLC_PG_CNTL, data);
  6440. WREG32(RLC_SAVE_AND_RESTORE_BASE, rdev->rlc.save_restore_gpu_addr >> 8);
  6441. WREG32(RLC_CP_TABLE_RESTORE, rdev->rlc.cp_table_gpu_addr >> 8);
  6442. data = RREG32(CP_RB_WPTR_POLL_CNTL);
  6443. data &= ~IDLE_POLL_COUNT_MASK;
  6444. data |= IDLE_POLL_COUNT(0x60);
  6445. WREG32(CP_RB_WPTR_POLL_CNTL, data);
  6446. data = 0x10101010;
  6447. WREG32(RLC_PG_DELAY, data);
  6448. data = RREG32(RLC_PG_DELAY_2);
  6449. data &= ~0xff;
  6450. data |= 0x3;
  6451. WREG32(RLC_PG_DELAY_2, data);
  6452. data = RREG32(RLC_AUTO_PG_CTRL);
  6453. data &= ~GRBM_REG_SGIT_MASK;
  6454. data |= GRBM_REG_SGIT(0x700);
  6455. WREG32(RLC_AUTO_PG_CTRL, data);
  6456. }
  6457. static void cik_update_gfx_pg(struct radeon_device *rdev, bool enable)
  6458. {
  6459. cik_enable_gfx_cgpg(rdev, enable);
  6460. cik_enable_gfx_static_mgpg(rdev, enable);
  6461. cik_enable_gfx_dynamic_mgpg(rdev, enable);
  6462. }
  6463. u32 cik_get_csb_size(struct radeon_device *rdev)
  6464. {
  6465. u32 count = 0;
  6466. const struct cs_section_def *sect = NULL;
  6467. const struct cs_extent_def *ext = NULL;
  6468. if (rdev->rlc.cs_data == NULL)
  6469. return 0;
  6470. /* begin clear state */
  6471. count += 2;
  6472. /* context control state */
  6473. count += 3;
  6474. for (sect = rdev->rlc.cs_data; sect->section != NULL; ++sect) {
  6475. for (ext = sect->section; ext->extent != NULL; ++ext) {
  6476. if (sect->id == SECT_CONTEXT)
  6477. count += 2 + ext->reg_count;
  6478. else
  6479. return 0;
  6480. }
  6481. }
  6482. /* pa_sc_raster_config/pa_sc_raster_config1 */
  6483. count += 4;
  6484. /* end clear state */
  6485. count += 2;
  6486. /* clear state */
  6487. count += 2;
  6488. return count;
  6489. }
  6490. void cik_get_csb_buffer(struct radeon_device *rdev, volatile u32 *buffer)
  6491. {
  6492. u32 count = 0, i;
  6493. const struct cs_section_def *sect = NULL;
  6494. const struct cs_extent_def *ext = NULL;
  6495. if (rdev->rlc.cs_data == NULL)
  6496. return;
  6497. if (buffer == NULL)
  6498. return;
  6499. buffer[count++] = cpu_to_le32(PACKET3(PACKET3_PREAMBLE_CNTL, 0));
  6500. buffer[count++] = cpu_to_le32(PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);
  6501. buffer[count++] = cpu_to_le32(PACKET3(PACKET3_CONTEXT_CONTROL, 1));
  6502. buffer[count++] = cpu_to_le32(0x80000000);
  6503. buffer[count++] = cpu_to_le32(0x80000000);
  6504. for (sect = rdev->rlc.cs_data; sect->section != NULL; ++sect) {
  6505. for (ext = sect->section; ext->extent != NULL; ++ext) {
  6506. if (sect->id == SECT_CONTEXT) {
  6507. buffer[count++] =
  6508. cpu_to_le32(PACKET3(PACKET3_SET_CONTEXT_REG, ext->reg_count));
  6509. buffer[count++] = cpu_to_le32(ext->reg_index - 0xa000);
  6510. for (i = 0; i < ext->reg_count; i++)
  6511. buffer[count++] = cpu_to_le32(ext->extent[i]);
  6512. } else {
  6513. return;
  6514. }
  6515. }
  6516. }
  6517. buffer[count++] = cpu_to_le32(PACKET3(PACKET3_SET_CONTEXT_REG, 2));
  6518. buffer[count++] = cpu_to_le32(PA_SC_RASTER_CONFIG - PACKET3_SET_CONTEXT_REG_START);
  6519. switch (rdev->family) {
  6520. case CHIP_BONAIRE:
  6521. buffer[count++] = cpu_to_le32(0x16000012);
  6522. buffer[count++] = cpu_to_le32(0x00000000);
  6523. break;
  6524. case CHIP_KAVERI:
  6525. buffer[count++] = cpu_to_le32(0x00000000); /* XXX */
  6526. buffer[count++] = cpu_to_le32(0x00000000);
  6527. break;
  6528. case CHIP_KABINI:
  6529. case CHIP_MULLINS:
  6530. buffer[count++] = cpu_to_le32(0x00000000); /* XXX */
  6531. buffer[count++] = cpu_to_le32(0x00000000);
  6532. break;
  6533. case CHIP_HAWAII:
  6534. buffer[count++] = cpu_to_le32(0x3a00161a);
  6535. buffer[count++] = cpu_to_le32(0x0000002e);
  6536. break;
  6537. default:
  6538. buffer[count++] = cpu_to_le32(0x00000000);
  6539. buffer[count++] = cpu_to_le32(0x00000000);
  6540. break;
  6541. }
  6542. buffer[count++] = cpu_to_le32(PACKET3(PACKET3_PREAMBLE_CNTL, 0));
  6543. buffer[count++] = cpu_to_le32(PACKET3_PREAMBLE_END_CLEAR_STATE);
  6544. buffer[count++] = cpu_to_le32(PACKET3(PACKET3_CLEAR_STATE, 0));
  6545. buffer[count++] = cpu_to_le32(0);
  6546. }
  6547. static void cik_init_pg(struct radeon_device *rdev)
  6548. {
  6549. if (rdev->pg_flags) {
  6550. cik_enable_sck_slowdown_on_pu(rdev, true);
  6551. cik_enable_sck_slowdown_on_pd(rdev, true);
  6552. if (rdev->pg_flags & RADEON_PG_SUPPORT_GFX_PG) {
  6553. cik_init_gfx_cgpg(rdev);
  6554. cik_enable_cp_pg(rdev, true);
  6555. cik_enable_gds_pg(rdev, true);
  6556. }
  6557. cik_init_ao_cu_mask(rdev);
  6558. cik_update_gfx_pg(rdev, true);
  6559. }
  6560. }
  6561. static void cik_fini_pg(struct radeon_device *rdev)
  6562. {
  6563. if (rdev->pg_flags) {
  6564. cik_update_gfx_pg(rdev, false);
  6565. if (rdev->pg_flags & RADEON_PG_SUPPORT_GFX_PG) {
  6566. cik_enable_cp_pg(rdev, false);
  6567. cik_enable_gds_pg(rdev, false);
  6568. }
  6569. }
  6570. }
  6571. /*
  6572. * Interrupts
  6573. * Starting with r6xx, interrupts are handled via a ring buffer.
  6574. * Ring buffers are areas of GPU accessible memory that the GPU
  6575. * writes interrupt vectors into and the host reads vectors out of.
  6576. * There is a rptr (read pointer) that determines where the
  6577. * host is currently reading, and a wptr (write pointer)
  6578. * which determines where the GPU has written. When the
  6579. * pointers are equal, the ring is idle. When the GPU
  6580. * writes vectors to the ring buffer, it increments the
  6581. * wptr. When there is an interrupt, the host then starts
  6582. * fetching commands and processing them until the pointers are
  6583. * equal again at which point it updates the rptr.
  6584. */
  6585. /**
  6586. * cik_enable_interrupts - Enable the interrupt ring buffer
  6587. *
  6588. * @rdev: radeon_device pointer
  6589. *
  6590. * Enable the interrupt ring buffer (CIK).
  6591. */
  6592. static void cik_enable_interrupts(struct radeon_device *rdev)
  6593. {
  6594. u32 ih_cntl = RREG32(IH_CNTL);
  6595. u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
  6596. ih_cntl |= ENABLE_INTR;
  6597. ih_rb_cntl |= IH_RB_ENABLE;
  6598. WREG32(IH_CNTL, ih_cntl);
  6599. WREG32(IH_RB_CNTL, ih_rb_cntl);
  6600. rdev->ih.enabled = true;
  6601. }
  6602. /**
  6603. * cik_disable_interrupts - Disable the interrupt ring buffer
  6604. *
  6605. * @rdev: radeon_device pointer
  6606. *
  6607. * Disable the interrupt ring buffer (CIK).
  6608. */
  6609. static void cik_disable_interrupts(struct radeon_device *rdev)
  6610. {
  6611. u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
  6612. u32 ih_cntl = RREG32(IH_CNTL);
  6613. ih_rb_cntl &= ~IH_RB_ENABLE;
  6614. ih_cntl &= ~ENABLE_INTR;
  6615. WREG32(IH_RB_CNTL, ih_rb_cntl);
  6616. WREG32(IH_CNTL, ih_cntl);
  6617. /* set rptr, wptr to 0 */
  6618. WREG32(IH_RB_RPTR, 0);
  6619. WREG32(IH_RB_WPTR, 0);
  6620. rdev->ih.enabled = false;
  6621. rdev->ih.rptr = 0;
  6622. }
  6623. /**
  6624. * cik_disable_interrupt_state - Disable all interrupt sources
  6625. *
  6626. * @rdev: radeon_device pointer
  6627. *
  6628. * Clear all interrupt enable bits used by the driver (CIK).
  6629. */
  6630. static void cik_disable_interrupt_state(struct radeon_device *rdev)
  6631. {
  6632. u32 tmp;
  6633. /* gfx ring */
  6634. tmp = RREG32(CP_INT_CNTL_RING0) &
  6635. (CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
  6636. WREG32(CP_INT_CNTL_RING0, tmp);
  6637. /* sdma */
  6638. tmp = RREG32(SDMA0_CNTL + SDMA0_REGISTER_OFFSET) & ~TRAP_ENABLE;
  6639. WREG32(SDMA0_CNTL + SDMA0_REGISTER_OFFSET, tmp);
  6640. tmp = RREG32(SDMA0_CNTL + SDMA1_REGISTER_OFFSET) & ~TRAP_ENABLE;
  6641. WREG32(SDMA0_CNTL + SDMA1_REGISTER_OFFSET, tmp);
  6642. /* compute queues */
  6643. WREG32(CP_ME1_PIPE0_INT_CNTL, 0);
  6644. WREG32(CP_ME1_PIPE1_INT_CNTL, 0);
  6645. WREG32(CP_ME1_PIPE2_INT_CNTL, 0);
  6646. WREG32(CP_ME1_PIPE3_INT_CNTL, 0);
  6647. WREG32(CP_ME2_PIPE0_INT_CNTL, 0);
  6648. WREG32(CP_ME2_PIPE1_INT_CNTL, 0);
  6649. WREG32(CP_ME2_PIPE2_INT_CNTL, 0);
  6650. WREG32(CP_ME2_PIPE3_INT_CNTL, 0);
  6651. /* grbm */
  6652. WREG32(GRBM_INT_CNTL, 0);
  6653. /* SRBM */
  6654. WREG32(SRBM_INT_CNTL, 0);
  6655. /* vline/vblank, etc. */
  6656. WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC0_REGISTER_OFFSET, 0);
  6657. WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC1_REGISTER_OFFSET, 0);
  6658. if (rdev->num_crtc >= 4) {
  6659. WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC2_REGISTER_OFFSET, 0);
  6660. WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC3_REGISTER_OFFSET, 0);
  6661. }
  6662. if (rdev->num_crtc >= 6) {
  6663. WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC4_REGISTER_OFFSET, 0);
  6664. WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC5_REGISTER_OFFSET, 0);
  6665. }
  6666. /* pflip */
  6667. if (rdev->num_crtc >= 2) {
  6668. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET, 0);
  6669. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET, 0);
  6670. }
  6671. if (rdev->num_crtc >= 4) {
  6672. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET, 0);
  6673. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET, 0);
  6674. }
  6675. if (rdev->num_crtc >= 6) {
  6676. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET, 0);
  6677. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET, 0);
  6678. }
  6679. /* dac hotplug */
  6680. WREG32(DAC_AUTODETECT_INT_CONTROL, 0);
  6681. /* digital hotplug */
  6682. tmp = RREG32(DC_HPD1_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  6683. WREG32(DC_HPD1_INT_CONTROL, tmp);
  6684. tmp = RREG32(DC_HPD2_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  6685. WREG32(DC_HPD2_INT_CONTROL, tmp);
  6686. tmp = RREG32(DC_HPD3_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  6687. WREG32(DC_HPD3_INT_CONTROL, tmp);
  6688. tmp = RREG32(DC_HPD4_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  6689. WREG32(DC_HPD4_INT_CONTROL, tmp);
  6690. tmp = RREG32(DC_HPD5_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  6691. WREG32(DC_HPD5_INT_CONTROL, tmp);
  6692. tmp = RREG32(DC_HPD6_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  6693. WREG32(DC_HPD6_INT_CONTROL, tmp);
  6694. }
  6695. /**
  6696. * cik_irq_init - init and enable the interrupt ring
  6697. *
  6698. * @rdev: radeon_device pointer
  6699. *
  6700. * Allocate a ring buffer for the interrupt controller,
  6701. * enable the RLC, disable interrupts, enable the IH
  6702. * ring buffer and enable it (CIK).
  6703. * Called at device load and reume.
  6704. * Returns 0 for success, errors for failure.
  6705. */
  6706. static int cik_irq_init(struct radeon_device *rdev)
  6707. {
  6708. int ret = 0;
  6709. int rb_bufsz;
  6710. u32 interrupt_cntl, ih_cntl, ih_rb_cntl;
  6711. /* allocate ring */
  6712. ret = r600_ih_ring_alloc(rdev);
  6713. if (ret)
  6714. return ret;
  6715. /* disable irqs */
  6716. cik_disable_interrupts(rdev);
  6717. /* init rlc */
  6718. ret = cik_rlc_resume(rdev);
  6719. if (ret) {
  6720. r600_ih_ring_fini(rdev);
  6721. return ret;
  6722. }
  6723. /* setup interrupt control */
  6724. /* XXX this should actually be a bus address, not an MC address. same on older asics */
  6725. WREG32(INTERRUPT_CNTL2, rdev->ih.gpu_addr >> 8);
  6726. interrupt_cntl = RREG32(INTERRUPT_CNTL);
  6727. /* IH_DUMMY_RD_OVERRIDE=0 - dummy read disabled with msi, enabled without msi
  6728. * IH_DUMMY_RD_OVERRIDE=1 - dummy read controlled by IH_DUMMY_RD_EN
  6729. */
  6730. interrupt_cntl &= ~IH_DUMMY_RD_OVERRIDE;
  6731. /* IH_REQ_NONSNOOP_EN=1 if ring is in non-cacheable memory, e.g., vram */
  6732. interrupt_cntl &= ~IH_REQ_NONSNOOP_EN;
  6733. WREG32(INTERRUPT_CNTL, interrupt_cntl);
  6734. WREG32(IH_RB_BASE, rdev->ih.gpu_addr >> 8);
  6735. rb_bufsz = order_base_2(rdev->ih.ring_size / 4);
  6736. ih_rb_cntl = (IH_WPTR_OVERFLOW_ENABLE |
  6737. IH_WPTR_OVERFLOW_CLEAR |
  6738. (rb_bufsz << 1));
  6739. if (rdev->wb.enabled)
  6740. ih_rb_cntl |= IH_WPTR_WRITEBACK_ENABLE;
  6741. /* set the writeback address whether it's enabled or not */
  6742. WREG32(IH_RB_WPTR_ADDR_LO, (rdev->wb.gpu_addr + R600_WB_IH_WPTR_OFFSET) & 0xFFFFFFFC);
  6743. WREG32(IH_RB_WPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + R600_WB_IH_WPTR_OFFSET) & 0xFF);
  6744. WREG32(IH_RB_CNTL, ih_rb_cntl);
  6745. /* set rptr, wptr to 0 */
  6746. WREG32(IH_RB_RPTR, 0);
  6747. WREG32(IH_RB_WPTR, 0);
  6748. /* Default settings for IH_CNTL (disabled at first) */
  6749. ih_cntl = MC_WRREQ_CREDIT(0x10) | MC_WR_CLEAN_CNT(0x10) | MC_VMID(0);
  6750. /* RPTR_REARM only works if msi's are enabled */
  6751. if (rdev->msi_enabled)
  6752. ih_cntl |= RPTR_REARM;
  6753. WREG32(IH_CNTL, ih_cntl);
  6754. /* force the active interrupt state to all disabled */
  6755. cik_disable_interrupt_state(rdev);
  6756. pci_set_master(rdev->pdev);
  6757. /* enable irqs */
  6758. cik_enable_interrupts(rdev);
  6759. return ret;
  6760. }
  6761. /**
  6762. * cik_irq_set - enable/disable interrupt sources
  6763. *
  6764. * @rdev: radeon_device pointer
  6765. *
  6766. * Enable interrupt sources on the GPU (vblanks, hpd,
  6767. * etc.) (CIK).
  6768. * Returns 0 for success, errors for failure.
  6769. */
  6770. int cik_irq_set(struct radeon_device *rdev)
  6771. {
  6772. u32 cp_int_cntl;
  6773. u32 cp_m1p0;
  6774. u32 crtc1 = 0, crtc2 = 0, crtc3 = 0, crtc4 = 0, crtc5 = 0, crtc6 = 0;
  6775. u32 hpd1, hpd2, hpd3, hpd4, hpd5, hpd6;
  6776. u32 grbm_int_cntl = 0;
  6777. u32 dma_cntl, dma_cntl1;
  6778. if (!rdev->irq.installed) {
  6779. WARN(1, "Can't enable IRQ/MSI because no handler is installed\n");
  6780. return -EINVAL;
  6781. }
  6782. /* don't enable anything if the ih is disabled */
  6783. if (!rdev->ih.enabled) {
  6784. cik_disable_interrupts(rdev);
  6785. /* force the active interrupt state to all disabled */
  6786. cik_disable_interrupt_state(rdev);
  6787. return 0;
  6788. }
  6789. cp_int_cntl = RREG32(CP_INT_CNTL_RING0) &
  6790. (CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
  6791. cp_int_cntl |= PRIV_INSTR_INT_ENABLE | PRIV_REG_INT_ENABLE;
  6792. hpd1 = RREG32(DC_HPD1_INT_CONTROL) & ~(DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN);
  6793. hpd2 = RREG32(DC_HPD2_INT_CONTROL) & ~(DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN);
  6794. hpd3 = RREG32(DC_HPD3_INT_CONTROL) & ~(DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN);
  6795. hpd4 = RREG32(DC_HPD4_INT_CONTROL) & ~(DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN);
  6796. hpd5 = RREG32(DC_HPD5_INT_CONTROL) & ~(DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN);
  6797. hpd6 = RREG32(DC_HPD6_INT_CONTROL) & ~(DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN);
  6798. dma_cntl = RREG32(SDMA0_CNTL + SDMA0_REGISTER_OFFSET) & ~TRAP_ENABLE;
  6799. dma_cntl1 = RREG32(SDMA0_CNTL + SDMA1_REGISTER_OFFSET) & ~TRAP_ENABLE;
  6800. cp_m1p0 = RREG32(CP_ME1_PIPE0_INT_CNTL) & ~TIME_STAMP_INT_ENABLE;
  6801. /* enable CP interrupts on all rings */
  6802. if (atomic_read(&rdev->irq.ring_int[RADEON_RING_TYPE_GFX_INDEX])) {
  6803. DRM_DEBUG("cik_irq_set: sw int gfx\n");
  6804. cp_int_cntl |= TIME_STAMP_INT_ENABLE;
  6805. }
  6806. if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_CP1_INDEX])) {
  6807. struct radeon_ring *ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
  6808. DRM_DEBUG("si_irq_set: sw int cp1\n");
  6809. if (ring->me == 1) {
  6810. switch (ring->pipe) {
  6811. case 0:
  6812. cp_m1p0 |= TIME_STAMP_INT_ENABLE;
  6813. break;
  6814. default:
  6815. DRM_DEBUG("si_irq_set: sw int cp1 invalid pipe %d\n", ring->pipe);
  6816. break;
  6817. }
  6818. } else {
  6819. DRM_DEBUG("si_irq_set: sw int cp1 invalid me %d\n", ring->me);
  6820. }
  6821. }
  6822. if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_CP2_INDEX])) {
  6823. struct radeon_ring *ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
  6824. DRM_DEBUG("si_irq_set: sw int cp2\n");
  6825. if (ring->me == 1) {
  6826. switch (ring->pipe) {
  6827. case 0:
  6828. cp_m1p0 |= TIME_STAMP_INT_ENABLE;
  6829. break;
  6830. default:
  6831. DRM_DEBUG("si_irq_set: sw int cp2 invalid pipe %d\n", ring->pipe);
  6832. break;
  6833. }
  6834. } else {
  6835. DRM_DEBUG("si_irq_set: sw int cp2 invalid me %d\n", ring->me);
  6836. }
  6837. }
  6838. if (atomic_read(&rdev->irq.ring_int[R600_RING_TYPE_DMA_INDEX])) {
  6839. DRM_DEBUG("cik_irq_set: sw int dma\n");
  6840. dma_cntl |= TRAP_ENABLE;
  6841. }
  6842. if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_DMA1_INDEX])) {
  6843. DRM_DEBUG("cik_irq_set: sw int dma1\n");
  6844. dma_cntl1 |= TRAP_ENABLE;
  6845. }
  6846. if (rdev->irq.crtc_vblank_int[0] ||
  6847. atomic_read(&rdev->irq.pflip[0])) {
  6848. DRM_DEBUG("cik_irq_set: vblank 0\n");
  6849. crtc1 |= VBLANK_INTERRUPT_MASK;
  6850. }
  6851. if (rdev->irq.crtc_vblank_int[1] ||
  6852. atomic_read(&rdev->irq.pflip[1])) {
  6853. DRM_DEBUG("cik_irq_set: vblank 1\n");
  6854. crtc2 |= VBLANK_INTERRUPT_MASK;
  6855. }
  6856. if (rdev->irq.crtc_vblank_int[2] ||
  6857. atomic_read(&rdev->irq.pflip[2])) {
  6858. DRM_DEBUG("cik_irq_set: vblank 2\n");
  6859. crtc3 |= VBLANK_INTERRUPT_MASK;
  6860. }
  6861. if (rdev->irq.crtc_vblank_int[3] ||
  6862. atomic_read(&rdev->irq.pflip[3])) {
  6863. DRM_DEBUG("cik_irq_set: vblank 3\n");
  6864. crtc4 |= VBLANK_INTERRUPT_MASK;
  6865. }
  6866. if (rdev->irq.crtc_vblank_int[4] ||
  6867. atomic_read(&rdev->irq.pflip[4])) {
  6868. DRM_DEBUG("cik_irq_set: vblank 4\n");
  6869. crtc5 |= VBLANK_INTERRUPT_MASK;
  6870. }
  6871. if (rdev->irq.crtc_vblank_int[5] ||
  6872. atomic_read(&rdev->irq.pflip[5])) {
  6873. DRM_DEBUG("cik_irq_set: vblank 5\n");
  6874. crtc6 |= VBLANK_INTERRUPT_MASK;
  6875. }
  6876. if (rdev->irq.hpd[0]) {
  6877. DRM_DEBUG("cik_irq_set: hpd 1\n");
  6878. hpd1 |= DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN;
  6879. }
  6880. if (rdev->irq.hpd[1]) {
  6881. DRM_DEBUG("cik_irq_set: hpd 2\n");
  6882. hpd2 |= DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN;
  6883. }
  6884. if (rdev->irq.hpd[2]) {
  6885. DRM_DEBUG("cik_irq_set: hpd 3\n");
  6886. hpd3 |= DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN;
  6887. }
  6888. if (rdev->irq.hpd[3]) {
  6889. DRM_DEBUG("cik_irq_set: hpd 4\n");
  6890. hpd4 |= DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN;
  6891. }
  6892. if (rdev->irq.hpd[4]) {
  6893. DRM_DEBUG("cik_irq_set: hpd 5\n");
  6894. hpd5 |= DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN;
  6895. }
  6896. if (rdev->irq.hpd[5]) {
  6897. DRM_DEBUG("cik_irq_set: hpd 6\n");
  6898. hpd6 |= DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN;
  6899. }
  6900. WREG32(CP_INT_CNTL_RING0, cp_int_cntl);
  6901. WREG32(SDMA0_CNTL + SDMA0_REGISTER_OFFSET, dma_cntl);
  6902. WREG32(SDMA0_CNTL + SDMA1_REGISTER_OFFSET, dma_cntl1);
  6903. WREG32(CP_ME1_PIPE0_INT_CNTL, cp_m1p0);
  6904. WREG32(GRBM_INT_CNTL, grbm_int_cntl);
  6905. WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC0_REGISTER_OFFSET, crtc1);
  6906. WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC1_REGISTER_OFFSET, crtc2);
  6907. if (rdev->num_crtc >= 4) {
  6908. WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC2_REGISTER_OFFSET, crtc3);
  6909. WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC3_REGISTER_OFFSET, crtc4);
  6910. }
  6911. if (rdev->num_crtc >= 6) {
  6912. WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC4_REGISTER_OFFSET, crtc5);
  6913. WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC5_REGISTER_OFFSET, crtc6);
  6914. }
  6915. if (rdev->num_crtc >= 2) {
  6916. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET,
  6917. GRPH_PFLIP_INT_MASK);
  6918. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET,
  6919. GRPH_PFLIP_INT_MASK);
  6920. }
  6921. if (rdev->num_crtc >= 4) {
  6922. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET,
  6923. GRPH_PFLIP_INT_MASK);
  6924. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET,
  6925. GRPH_PFLIP_INT_MASK);
  6926. }
  6927. if (rdev->num_crtc >= 6) {
  6928. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET,
  6929. GRPH_PFLIP_INT_MASK);
  6930. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET,
  6931. GRPH_PFLIP_INT_MASK);
  6932. }
  6933. WREG32(DC_HPD1_INT_CONTROL, hpd1);
  6934. WREG32(DC_HPD2_INT_CONTROL, hpd2);
  6935. WREG32(DC_HPD3_INT_CONTROL, hpd3);
  6936. WREG32(DC_HPD4_INT_CONTROL, hpd4);
  6937. WREG32(DC_HPD5_INT_CONTROL, hpd5);
  6938. WREG32(DC_HPD6_INT_CONTROL, hpd6);
  6939. /* posting read */
  6940. RREG32(SRBM_STATUS);
  6941. return 0;
  6942. }
  6943. /**
  6944. * cik_irq_ack - ack interrupt sources
  6945. *
  6946. * @rdev: radeon_device pointer
  6947. *
  6948. * Ack interrupt sources on the GPU (vblanks, hpd,
  6949. * etc.) (CIK). Certain interrupts sources are sw
  6950. * generated and do not require an explicit ack.
  6951. */
  6952. static inline void cik_irq_ack(struct radeon_device *rdev)
  6953. {
  6954. u32 tmp;
  6955. rdev->irq.stat_regs.cik.disp_int = RREG32(DISP_INTERRUPT_STATUS);
  6956. rdev->irq.stat_regs.cik.disp_int_cont = RREG32(DISP_INTERRUPT_STATUS_CONTINUE);
  6957. rdev->irq.stat_regs.cik.disp_int_cont2 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE2);
  6958. rdev->irq.stat_regs.cik.disp_int_cont3 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE3);
  6959. rdev->irq.stat_regs.cik.disp_int_cont4 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE4);
  6960. rdev->irq.stat_regs.cik.disp_int_cont5 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE5);
  6961. rdev->irq.stat_regs.cik.disp_int_cont6 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE6);
  6962. rdev->irq.stat_regs.cik.d1grph_int = RREG32(GRPH_INT_STATUS +
  6963. EVERGREEN_CRTC0_REGISTER_OFFSET);
  6964. rdev->irq.stat_regs.cik.d2grph_int = RREG32(GRPH_INT_STATUS +
  6965. EVERGREEN_CRTC1_REGISTER_OFFSET);
  6966. if (rdev->num_crtc >= 4) {
  6967. rdev->irq.stat_regs.cik.d3grph_int = RREG32(GRPH_INT_STATUS +
  6968. EVERGREEN_CRTC2_REGISTER_OFFSET);
  6969. rdev->irq.stat_regs.cik.d4grph_int = RREG32(GRPH_INT_STATUS +
  6970. EVERGREEN_CRTC3_REGISTER_OFFSET);
  6971. }
  6972. if (rdev->num_crtc >= 6) {
  6973. rdev->irq.stat_regs.cik.d5grph_int = RREG32(GRPH_INT_STATUS +
  6974. EVERGREEN_CRTC4_REGISTER_OFFSET);
  6975. rdev->irq.stat_regs.cik.d6grph_int = RREG32(GRPH_INT_STATUS +
  6976. EVERGREEN_CRTC5_REGISTER_OFFSET);
  6977. }
  6978. if (rdev->irq.stat_regs.cik.d1grph_int & GRPH_PFLIP_INT_OCCURRED)
  6979. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET,
  6980. GRPH_PFLIP_INT_CLEAR);
  6981. if (rdev->irq.stat_regs.cik.d2grph_int & GRPH_PFLIP_INT_OCCURRED)
  6982. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET,
  6983. GRPH_PFLIP_INT_CLEAR);
  6984. if (rdev->irq.stat_regs.cik.disp_int & LB_D1_VBLANK_INTERRUPT)
  6985. WREG32(LB_VBLANK_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, VBLANK_ACK);
  6986. if (rdev->irq.stat_regs.cik.disp_int & LB_D1_VLINE_INTERRUPT)
  6987. WREG32(LB_VLINE_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, VLINE_ACK);
  6988. if (rdev->irq.stat_regs.cik.disp_int_cont & LB_D2_VBLANK_INTERRUPT)
  6989. WREG32(LB_VBLANK_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, VBLANK_ACK);
  6990. if (rdev->irq.stat_regs.cik.disp_int_cont & LB_D2_VLINE_INTERRUPT)
  6991. WREG32(LB_VLINE_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, VLINE_ACK);
  6992. if (rdev->num_crtc >= 4) {
  6993. if (rdev->irq.stat_regs.cik.d3grph_int & GRPH_PFLIP_INT_OCCURRED)
  6994. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET,
  6995. GRPH_PFLIP_INT_CLEAR);
  6996. if (rdev->irq.stat_regs.cik.d4grph_int & GRPH_PFLIP_INT_OCCURRED)
  6997. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET,
  6998. GRPH_PFLIP_INT_CLEAR);
  6999. if (rdev->irq.stat_regs.cik.disp_int_cont2 & LB_D3_VBLANK_INTERRUPT)
  7000. WREG32(LB_VBLANK_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, VBLANK_ACK);
  7001. if (rdev->irq.stat_regs.cik.disp_int_cont2 & LB_D3_VLINE_INTERRUPT)
  7002. WREG32(LB_VLINE_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, VLINE_ACK);
  7003. if (rdev->irq.stat_regs.cik.disp_int_cont3 & LB_D4_VBLANK_INTERRUPT)
  7004. WREG32(LB_VBLANK_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, VBLANK_ACK);
  7005. if (rdev->irq.stat_regs.cik.disp_int_cont3 & LB_D4_VLINE_INTERRUPT)
  7006. WREG32(LB_VLINE_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, VLINE_ACK);
  7007. }
  7008. if (rdev->num_crtc >= 6) {
  7009. if (rdev->irq.stat_regs.cik.d5grph_int & GRPH_PFLIP_INT_OCCURRED)
  7010. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET,
  7011. GRPH_PFLIP_INT_CLEAR);
  7012. if (rdev->irq.stat_regs.cik.d6grph_int & GRPH_PFLIP_INT_OCCURRED)
  7013. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET,
  7014. GRPH_PFLIP_INT_CLEAR);
  7015. if (rdev->irq.stat_regs.cik.disp_int_cont4 & LB_D5_VBLANK_INTERRUPT)
  7016. WREG32(LB_VBLANK_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, VBLANK_ACK);
  7017. if (rdev->irq.stat_regs.cik.disp_int_cont4 & LB_D5_VLINE_INTERRUPT)
  7018. WREG32(LB_VLINE_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, VLINE_ACK);
  7019. if (rdev->irq.stat_regs.cik.disp_int_cont5 & LB_D6_VBLANK_INTERRUPT)
  7020. WREG32(LB_VBLANK_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, VBLANK_ACK);
  7021. if (rdev->irq.stat_regs.cik.disp_int_cont5 & LB_D6_VLINE_INTERRUPT)
  7022. WREG32(LB_VLINE_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, VLINE_ACK);
  7023. }
  7024. if (rdev->irq.stat_regs.cik.disp_int & DC_HPD1_INTERRUPT) {
  7025. tmp = RREG32(DC_HPD1_INT_CONTROL);
  7026. tmp |= DC_HPDx_INT_ACK;
  7027. WREG32(DC_HPD1_INT_CONTROL, tmp);
  7028. }
  7029. if (rdev->irq.stat_regs.cik.disp_int_cont & DC_HPD2_INTERRUPT) {
  7030. tmp = RREG32(DC_HPD2_INT_CONTROL);
  7031. tmp |= DC_HPDx_INT_ACK;
  7032. WREG32(DC_HPD2_INT_CONTROL, tmp);
  7033. }
  7034. if (rdev->irq.stat_regs.cik.disp_int_cont2 & DC_HPD3_INTERRUPT) {
  7035. tmp = RREG32(DC_HPD3_INT_CONTROL);
  7036. tmp |= DC_HPDx_INT_ACK;
  7037. WREG32(DC_HPD3_INT_CONTROL, tmp);
  7038. }
  7039. if (rdev->irq.stat_regs.cik.disp_int_cont3 & DC_HPD4_INTERRUPT) {
  7040. tmp = RREG32(DC_HPD4_INT_CONTROL);
  7041. tmp |= DC_HPDx_INT_ACK;
  7042. WREG32(DC_HPD4_INT_CONTROL, tmp);
  7043. }
  7044. if (rdev->irq.stat_regs.cik.disp_int_cont4 & DC_HPD5_INTERRUPT) {
  7045. tmp = RREG32(DC_HPD5_INT_CONTROL);
  7046. tmp |= DC_HPDx_INT_ACK;
  7047. WREG32(DC_HPD5_INT_CONTROL, tmp);
  7048. }
  7049. if (rdev->irq.stat_regs.cik.disp_int_cont5 & DC_HPD6_INTERRUPT) {
  7050. tmp = RREG32(DC_HPD6_INT_CONTROL);
  7051. tmp |= DC_HPDx_INT_ACK;
  7052. WREG32(DC_HPD6_INT_CONTROL, tmp);
  7053. }
  7054. if (rdev->irq.stat_regs.cik.disp_int & DC_HPD1_RX_INTERRUPT) {
  7055. tmp = RREG32(DC_HPD1_INT_CONTROL);
  7056. tmp |= DC_HPDx_RX_INT_ACK;
  7057. WREG32(DC_HPD1_INT_CONTROL, tmp);
  7058. }
  7059. if (rdev->irq.stat_regs.cik.disp_int_cont & DC_HPD2_RX_INTERRUPT) {
  7060. tmp = RREG32(DC_HPD2_INT_CONTROL);
  7061. tmp |= DC_HPDx_RX_INT_ACK;
  7062. WREG32(DC_HPD2_INT_CONTROL, tmp);
  7063. }
  7064. if (rdev->irq.stat_regs.cik.disp_int_cont2 & DC_HPD3_RX_INTERRUPT) {
  7065. tmp = RREG32(DC_HPD3_INT_CONTROL);
  7066. tmp |= DC_HPDx_RX_INT_ACK;
  7067. WREG32(DC_HPD3_INT_CONTROL, tmp);
  7068. }
  7069. if (rdev->irq.stat_regs.cik.disp_int_cont3 & DC_HPD4_RX_INTERRUPT) {
  7070. tmp = RREG32(DC_HPD4_INT_CONTROL);
  7071. tmp |= DC_HPDx_RX_INT_ACK;
  7072. WREG32(DC_HPD4_INT_CONTROL, tmp);
  7073. }
  7074. if (rdev->irq.stat_regs.cik.disp_int_cont4 & DC_HPD5_RX_INTERRUPT) {
  7075. tmp = RREG32(DC_HPD5_INT_CONTROL);
  7076. tmp |= DC_HPDx_RX_INT_ACK;
  7077. WREG32(DC_HPD5_INT_CONTROL, tmp);
  7078. }
  7079. if (rdev->irq.stat_regs.cik.disp_int_cont5 & DC_HPD6_RX_INTERRUPT) {
  7080. tmp = RREG32(DC_HPD6_INT_CONTROL);
  7081. tmp |= DC_HPDx_RX_INT_ACK;
  7082. WREG32(DC_HPD6_INT_CONTROL, tmp);
  7083. }
  7084. }
  7085. /**
  7086. * cik_irq_disable - disable interrupts
  7087. *
  7088. * @rdev: radeon_device pointer
  7089. *
  7090. * Disable interrupts on the hw (CIK).
  7091. */
  7092. static void cik_irq_disable(struct radeon_device *rdev)
  7093. {
  7094. cik_disable_interrupts(rdev);
  7095. /* Wait and acknowledge irq */
  7096. mdelay(1);
  7097. cik_irq_ack(rdev);
  7098. cik_disable_interrupt_state(rdev);
  7099. }
  7100. /**
  7101. * cik_irq_disable - disable interrupts for suspend
  7102. *
  7103. * @rdev: radeon_device pointer
  7104. *
  7105. * Disable interrupts and stop the RLC (CIK).
  7106. * Used for suspend.
  7107. */
  7108. static void cik_irq_suspend(struct radeon_device *rdev)
  7109. {
  7110. cik_irq_disable(rdev);
  7111. cik_rlc_stop(rdev);
  7112. }
  7113. /**
  7114. * cik_irq_fini - tear down interrupt support
  7115. *
  7116. * @rdev: radeon_device pointer
  7117. *
  7118. * Disable interrupts on the hw and free the IH ring
  7119. * buffer (CIK).
  7120. * Used for driver unload.
  7121. */
  7122. static void cik_irq_fini(struct radeon_device *rdev)
  7123. {
  7124. cik_irq_suspend(rdev);
  7125. r600_ih_ring_fini(rdev);
  7126. }
  7127. /**
  7128. * cik_get_ih_wptr - get the IH ring buffer wptr
  7129. *
  7130. * @rdev: radeon_device pointer
  7131. *
  7132. * Get the IH ring buffer wptr from either the register
  7133. * or the writeback memory buffer (CIK). Also check for
  7134. * ring buffer overflow and deal with it.
  7135. * Used by cik_irq_process().
  7136. * Returns the value of the wptr.
  7137. */
  7138. static inline u32 cik_get_ih_wptr(struct radeon_device *rdev)
  7139. {
  7140. u32 wptr, tmp;
  7141. if (rdev->wb.enabled)
  7142. wptr = le32_to_cpu(rdev->wb.wb[R600_WB_IH_WPTR_OFFSET/4]);
  7143. else
  7144. wptr = RREG32(IH_RB_WPTR);
  7145. if (wptr & RB_OVERFLOW) {
  7146. wptr &= ~RB_OVERFLOW;
  7147. /* When a ring buffer overflow happen start parsing interrupt
  7148. * from the last not overwritten vector (wptr + 16). Hopefully
  7149. * this should allow us to catchup.
  7150. */
  7151. dev_warn(rdev->dev, "IH ring buffer overflow (0x%08X, 0x%08X, 0x%08X)\n",
  7152. wptr, rdev->ih.rptr, (wptr + 16) & rdev->ih.ptr_mask);
  7153. rdev->ih.rptr = (wptr + 16) & rdev->ih.ptr_mask;
  7154. tmp = RREG32(IH_RB_CNTL);
  7155. tmp |= IH_WPTR_OVERFLOW_CLEAR;
  7156. WREG32(IH_RB_CNTL, tmp);
  7157. }
  7158. return (wptr & rdev->ih.ptr_mask);
  7159. }
  7160. /* CIK IV Ring
  7161. * Each IV ring entry is 128 bits:
  7162. * [7:0] - interrupt source id
  7163. * [31:8] - reserved
  7164. * [59:32] - interrupt source data
  7165. * [63:60] - reserved
  7166. * [71:64] - RINGID
  7167. * CP:
  7168. * ME_ID [1:0], PIPE_ID[1:0], QUEUE_ID[2:0]
  7169. * QUEUE_ID - for compute, which of the 8 queues owned by the dispatcher
  7170. * - for gfx, hw shader state (0=PS...5=LS, 6=CS)
  7171. * ME_ID - 0 = gfx, 1 = first 4 CS pipes, 2 = second 4 CS pipes
  7172. * PIPE_ID - ME0 0=3D
  7173. * - ME1&2 compute dispatcher (4 pipes each)
  7174. * SDMA:
  7175. * INSTANCE_ID [1:0], QUEUE_ID[1:0]
  7176. * INSTANCE_ID - 0 = sdma0, 1 = sdma1
  7177. * QUEUE_ID - 0 = gfx, 1 = rlc0, 2 = rlc1
  7178. * [79:72] - VMID
  7179. * [95:80] - PASID
  7180. * [127:96] - reserved
  7181. */
  7182. /**
  7183. * cik_irq_process - interrupt handler
  7184. *
  7185. * @rdev: radeon_device pointer
  7186. *
  7187. * Interrupt hander (CIK). Walk the IH ring,
  7188. * ack interrupts and schedule work to handle
  7189. * interrupt events.
  7190. * Returns irq process return code.
  7191. */
  7192. int cik_irq_process(struct radeon_device *rdev)
  7193. {
  7194. struct radeon_ring *cp1_ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
  7195. struct radeon_ring *cp2_ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
  7196. u32 wptr;
  7197. u32 rptr;
  7198. u32 src_id, src_data, ring_id;
  7199. u8 me_id, pipe_id, queue_id;
  7200. u32 ring_index;
  7201. bool queue_hotplug = false;
  7202. bool queue_dp = false;
  7203. bool queue_reset = false;
  7204. u32 addr, status, mc_client;
  7205. bool queue_thermal = false;
  7206. if (!rdev->ih.enabled || rdev->shutdown)
  7207. return IRQ_NONE;
  7208. wptr = cik_get_ih_wptr(rdev);
  7209. restart_ih:
  7210. /* is somebody else already processing irqs? */
  7211. if (atomic_xchg(&rdev->ih.lock, 1))
  7212. return IRQ_NONE;
  7213. rptr = rdev->ih.rptr;
  7214. DRM_DEBUG("cik_irq_process start: rptr %d, wptr %d\n", rptr, wptr);
  7215. /* Order reading of wptr vs. reading of IH ring data */
  7216. rmb();
  7217. /* display interrupts */
  7218. cik_irq_ack(rdev);
  7219. while (rptr != wptr) {
  7220. /* wptr/rptr are in bytes! */
  7221. ring_index = rptr / 4;
  7222. radeon_kfd_interrupt(rdev,
  7223. (const void *) &rdev->ih.ring[ring_index]);
  7224. src_id = le32_to_cpu(rdev->ih.ring[ring_index]) & 0xff;
  7225. src_data = le32_to_cpu(rdev->ih.ring[ring_index + 1]) & 0xfffffff;
  7226. ring_id = le32_to_cpu(rdev->ih.ring[ring_index + 2]) & 0xff;
  7227. switch (src_id) {
  7228. case 1: /* D1 vblank/vline */
  7229. switch (src_data) {
  7230. case 0: /* D1 vblank */
  7231. if (!(rdev->irq.stat_regs.cik.disp_int & LB_D1_VBLANK_INTERRUPT))
  7232. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  7233. if (rdev->irq.crtc_vblank_int[0]) {
  7234. drm_handle_vblank(rdev->ddev, 0);
  7235. rdev->pm.vblank_sync = true;
  7236. wake_up(&rdev->irq.vblank_queue);
  7237. }
  7238. if (atomic_read(&rdev->irq.pflip[0]))
  7239. radeon_crtc_handle_vblank(rdev, 0);
  7240. rdev->irq.stat_regs.cik.disp_int &= ~LB_D1_VBLANK_INTERRUPT;
  7241. DRM_DEBUG("IH: D1 vblank\n");
  7242. break;
  7243. case 1: /* D1 vline */
  7244. if (!(rdev->irq.stat_regs.cik.disp_int & LB_D1_VLINE_INTERRUPT))
  7245. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  7246. rdev->irq.stat_regs.cik.disp_int &= ~LB_D1_VLINE_INTERRUPT;
  7247. DRM_DEBUG("IH: D1 vline\n");
  7248. break;
  7249. default:
  7250. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  7251. break;
  7252. }
  7253. break;
  7254. case 2: /* D2 vblank/vline */
  7255. switch (src_data) {
  7256. case 0: /* D2 vblank */
  7257. if (!(rdev->irq.stat_regs.cik.disp_int_cont & LB_D2_VBLANK_INTERRUPT))
  7258. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  7259. if (rdev->irq.crtc_vblank_int[1]) {
  7260. drm_handle_vblank(rdev->ddev, 1);
  7261. rdev->pm.vblank_sync = true;
  7262. wake_up(&rdev->irq.vblank_queue);
  7263. }
  7264. if (atomic_read(&rdev->irq.pflip[1]))
  7265. radeon_crtc_handle_vblank(rdev, 1);
  7266. rdev->irq.stat_regs.cik.disp_int_cont &= ~LB_D2_VBLANK_INTERRUPT;
  7267. DRM_DEBUG("IH: D2 vblank\n");
  7268. break;
  7269. case 1: /* D2 vline */
  7270. if (!(rdev->irq.stat_regs.cik.disp_int_cont & LB_D2_VLINE_INTERRUPT))
  7271. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  7272. rdev->irq.stat_regs.cik.disp_int_cont &= ~LB_D2_VLINE_INTERRUPT;
  7273. DRM_DEBUG("IH: D2 vline\n");
  7274. break;
  7275. default:
  7276. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  7277. break;
  7278. }
  7279. break;
  7280. case 3: /* D3 vblank/vline */
  7281. switch (src_data) {
  7282. case 0: /* D3 vblank */
  7283. if (!(rdev->irq.stat_regs.cik.disp_int_cont2 & LB_D3_VBLANK_INTERRUPT))
  7284. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  7285. if (rdev->irq.crtc_vblank_int[2]) {
  7286. drm_handle_vblank(rdev->ddev, 2);
  7287. rdev->pm.vblank_sync = true;
  7288. wake_up(&rdev->irq.vblank_queue);
  7289. }
  7290. if (atomic_read(&rdev->irq.pflip[2]))
  7291. radeon_crtc_handle_vblank(rdev, 2);
  7292. rdev->irq.stat_regs.cik.disp_int_cont2 &= ~LB_D3_VBLANK_INTERRUPT;
  7293. DRM_DEBUG("IH: D3 vblank\n");
  7294. break;
  7295. case 1: /* D3 vline */
  7296. if (!(rdev->irq.stat_regs.cik.disp_int_cont2 & LB_D3_VLINE_INTERRUPT))
  7297. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  7298. rdev->irq.stat_regs.cik.disp_int_cont2 &= ~LB_D3_VLINE_INTERRUPT;
  7299. DRM_DEBUG("IH: D3 vline\n");
  7300. break;
  7301. default:
  7302. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  7303. break;
  7304. }
  7305. break;
  7306. case 4: /* D4 vblank/vline */
  7307. switch (src_data) {
  7308. case 0: /* D4 vblank */
  7309. if (!(rdev->irq.stat_regs.cik.disp_int_cont3 & LB_D4_VBLANK_INTERRUPT))
  7310. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  7311. if (rdev->irq.crtc_vblank_int[3]) {
  7312. drm_handle_vblank(rdev->ddev, 3);
  7313. rdev->pm.vblank_sync = true;
  7314. wake_up(&rdev->irq.vblank_queue);
  7315. }
  7316. if (atomic_read(&rdev->irq.pflip[3]))
  7317. radeon_crtc_handle_vblank(rdev, 3);
  7318. rdev->irq.stat_regs.cik.disp_int_cont3 &= ~LB_D4_VBLANK_INTERRUPT;
  7319. DRM_DEBUG("IH: D4 vblank\n");
  7320. break;
  7321. case 1: /* D4 vline */
  7322. if (!(rdev->irq.stat_regs.cik.disp_int_cont3 & LB_D4_VLINE_INTERRUPT))
  7323. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  7324. rdev->irq.stat_regs.cik.disp_int_cont3 &= ~LB_D4_VLINE_INTERRUPT;
  7325. DRM_DEBUG("IH: D4 vline\n");
  7326. break;
  7327. default:
  7328. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  7329. break;
  7330. }
  7331. break;
  7332. case 5: /* D5 vblank/vline */
  7333. switch (src_data) {
  7334. case 0: /* D5 vblank */
  7335. if (!(rdev->irq.stat_regs.cik.disp_int_cont4 & LB_D5_VBLANK_INTERRUPT))
  7336. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  7337. if (rdev->irq.crtc_vblank_int[4]) {
  7338. drm_handle_vblank(rdev->ddev, 4);
  7339. rdev->pm.vblank_sync = true;
  7340. wake_up(&rdev->irq.vblank_queue);
  7341. }
  7342. if (atomic_read(&rdev->irq.pflip[4]))
  7343. radeon_crtc_handle_vblank(rdev, 4);
  7344. rdev->irq.stat_regs.cik.disp_int_cont4 &= ~LB_D5_VBLANK_INTERRUPT;
  7345. DRM_DEBUG("IH: D5 vblank\n");
  7346. break;
  7347. case 1: /* D5 vline */
  7348. if (!(rdev->irq.stat_regs.cik.disp_int_cont4 & LB_D5_VLINE_INTERRUPT))
  7349. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  7350. rdev->irq.stat_regs.cik.disp_int_cont4 &= ~LB_D5_VLINE_INTERRUPT;
  7351. DRM_DEBUG("IH: D5 vline\n");
  7352. break;
  7353. default:
  7354. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  7355. break;
  7356. }
  7357. break;
  7358. case 6: /* D6 vblank/vline */
  7359. switch (src_data) {
  7360. case 0: /* D6 vblank */
  7361. if (!(rdev->irq.stat_regs.cik.disp_int_cont5 & LB_D6_VBLANK_INTERRUPT))
  7362. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  7363. if (rdev->irq.crtc_vblank_int[5]) {
  7364. drm_handle_vblank(rdev->ddev, 5);
  7365. rdev->pm.vblank_sync = true;
  7366. wake_up(&rdev->irq.vblank_queue);
  7367. }
  7368. if (atomic_read(&rdev->irq.pflip[5]))
  7369. radeon_crtc_handle_vblank(rdev, 5);
  7370. rdev->irq.stat_regs.cik.disp_int_cont5 &= ~LB_D6_VBLANK_INTERRUPT;
  7371. DRM_DEBUG("IH: D6 vblank\n");
  7372. break;
  7373. case 1: /* D6 vline */
  7374. if (!(rdev->irq.stat_regs.cik.disp_int_cont5 & LB_D6_VLINE_INTERRUPT))
  7375. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  7376. rdev->irq.stat_regs.cik.disp_int_cont5 &= ~LB_D6_VLINE_INTERRUPT;
  7377. DRM_DEBUG("IH: D6 vline\n");
  7378. break;
  7379. default:
  7380. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  7381. break;
  7382. }
  7383. break;
  7384. case 8: /* D1 page flip */
  7385. case 10: /* D2 page flip */
  7386. case 12: /* D3 page flip */
  7387. case 14: /* D4 page flip */
  7388. case 16: /* D5 page flip */
  7389. case 18: /* D6 page flip */
  7390. DRM_DEBUG("IH: D%d flip\n", ((src_id - 8) >> 1) + 1);
  7391. if (radeon_use_pflipirq > 0)
  7392. radeon_crtc_handle_flip(rdev, (src_id - 8) >> 1);
  7393. break;
  7394. case 42: /* HPD hotplug */
  7395. switch (src_data) {
  7396. case 0:
  7397. if (!(rdev->irq.stat_regs.cik.disp_int & DC_HPD1_INTERRUPT))
  7398. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  7399. rdev->irq.stat_regs.cik.disp_int &= ~DC_HPD1_INTERRUPT;
  7400. queue_hotplug = true;
  7401. DRM_DEBUG("IH: HPD1\n");
  7402. break;
  7403. case 1:
  7404. if (!(rdev->irq.stat_regs.cik.disp_int_cont & DC_HPD2_INTERRUPT))
  7405. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  7406. rdev->irq.stat_regs.cik.disp_int_cont &= ~DC_HPD2_INTERRUPT;
  7407. queue_hotplug = true;
  7408. DRM_DEBUG("IH: HPD2\n");
  7409. break;
  7410. case 2:
  7411. if (!(rdev->irq.stat_regs.cik.disp_int_cont2 & DC_HPD3_INTERRUPT))
  7412. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  7413. rdev->irq.stat_regs.cik.disp_int_cont2 &= ~DC_HPD3_INTERRUPT;
  7414. queue_hotplug = true;
  7415. DRM_DEBUG("IH: HPD3\n");
  7416. break;
  7417. case 3:
  7418. if (!(rdev->irq.stat_regs.cik.disp_int_cont3 & DC_HPD4_INTERRUPT))
  7419. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  7420. rdev->irq.stat_regs.cik.disp_int_cont3 &= ~DC_HPD4_INTERRUPT;
  7421. queue_hotplug = true;
  7422. DRM_DEBUG("IH: HPD4\n");
  7423. break;
  7424. case 4:
  7425. if (!(rdev->irq.stat_regs.cik.disp_int_cont4 & DC_HPD5_INTERRUPT))
  7426. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  7427. rdev->irq.stat_regs.cik.disp_int_cont4 &= ~DC_HPD5_INTERRUPT;
  7428. queue_hotplug = true;
  7429. DRM_DEBUG("IH: HPD5\n");
  7430. break;
  7431. case 5:
  7432. if (!(rdev->irq.stat_regs.cik.disp_int_cont5 & DC_HPD6_INTERRUPT))
  7433. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  7434. rdev->irq.stat_regs.cik.disp_int_cont5 &= ~DC_HPD6_INTERRUPT;
  7435. queue_hotplug = true;
  7436. DRM_DEBUG("IH: HPD6\n");
  7437. break;
  7438. case 6:
  7439. if (!(rdev->irq.stat_regs.cik.disp_int & DC_HPD1_RX_INTERRUPT))
  7440. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  7441. rdev->irq.stat_regs.cik.disp_int &= ~DC_HPD1_RX_INTERRUPT;
  7442. queue_dp = true;
  7443. DRM_DEBUG("IH: HPD_RX 1\n");
  7444. break;
  7445. case 7:
  7446. if (!(rdev->irq.stat_regs.cik.disp_int_cont & DC_HPD2_RX_INTERRUPT))
  7447. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  7448. rdev->irq.stat_regs.cik.disp_int_cont &= ~DC_HPD2_RX_INTERRUPT;
  7449. queue_dp = true;
  7450. DRM_DEBUG("IH: HPD_RX 2\n");
  7451. break;
  7452. case 8:
  7453. if (!(rdev->irq.stat_regs.cik.disp_int_cont2 & DC_HPD3_RX_INTERRUPT))
  7454. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  7455. rdev->irq.stat_regs.cik.disp_int_cont2 &= ~DC_HPD3_RX_INTERRUPT;
  7456. queue_dp = true;
  7457. DRM_DEBUG("IH: HPD_RX 3\n");
  7458. break;
  7459. case 9:
  7460. if (!(rdev->irq.stat_regs.cik.disp_int_cont3 & DC_HPD4_RX_INTERRUPT))
  7461. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  7462. rdev->irq.stat_regs.cik.disp_int_cont3 &= ~DC_HPD4_RX_INTERRUPT;
  7463. queue_dp = true;
  7464. DRM_DEBUG("IH: HPD_RX 4\n");
  7465. break;
  7466. case 10:
  7467. if (!(rdev->irq.stat_regs.cik.disp_int_cont4 & DC_HPD5_RX_INTERRUPT))
  7468. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  7469. rdev->irq.stat_regs.cik.disp_int_cont4 &= ~DC_HPD5_RX_INTERRUPT;
  7470. queue_dp = true;
  7471. DRM_DEBUG("IH: HPD_RX 5\n");
  7472. break;
  7473. case 11:
  7474. if (!(rdev->irq.stat_regs.cik.disp_int_cont5 & DC_HPD6_RX_INTERRUPT))
  7475. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  7476. rdev->irq.stat_regs.cik.disp_int_cont5 &= ~DC_HPD6_RX_INTERRUPT;
  7477. queue_dp = true;
  7478. DRM_DEBUG("IH: HPD_RX 6\n");
  7479. break;
  7480. default:
  7481. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  7482. break;
  7483. }
  7484. break;
  7485. case 96:
  7486. DRM_ERROR("SRBM_READ_ERROR: 0x%x\n", RREG32(SRBM_READ_ERROR));
  7487. WREG32(SRBM_INT_ACK, 0x1);
  7488. break;
  7489. case 124: /* UVD */
  7490. DRM_DEBUG("IH: UVD int: 0x%08x\n", src_data);
  7491. radeon_fence_process(rdev, R600_RING_TYPE_UVD_INDEX);
  7492. break;
  7493. case 146:
  7494. case 147:
  7495. addr = RREG32(VM_CONTEXT1_PROTECTION_FAULT_ADDR);
  7496. status = RREG32(VM_CONTEXT1_PROTECTION_FAULT_STATUS);
  7497. mc_client = RREG32(VM_CONTEXT1_PROTECTION_FAULT_MCCLIENT);
  7498. /* reset addr and status */
  7499. WREG32_P(VM_CONTEXT1_CNTL2, 1, ~1);
  7500. if (addr == 0x0 && status == 0x0)
  7501. break;
  7502. dev_err(rdev->dev, "GPU fault detected: %d 0x%08x\n", src_id, src_data);
  7503. dev_err(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_ADDR 0x%08X\n",
  7504. addr);
  7505. dev_err(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_STATUS 0x%08X\n",
  7506. status);
  7507. cik_vm_decode_fault(rdev, status, addr, mc_client);
  7508. break;
  7509. case 167: /* VCE */
  7510. DRM_DEBUG("IH: VCE int: 0x%08x\n", src_data);
  7511. switch (src_data) {
  7512. case 0:
  7513. radeon_fence_process(rdev, TN_RING_TYPE_VCE1_INDEX);
  7514. break;
  7515. case 1:
  7516. radeon_fence_process(rdev, TN_RING_TYPE_VCE2_INDEX);
  7517. break;
  7518. default:
  7519. DRM_ERROR("Unhandled interrupt: %d %d\n", src_id, src_data);
  7520. break;
  7521. }
  7522. break;
  7523. case 176: /* GFX RB CP_INT */
  7524. case 177: /* GFX IB CP_INT */
  7525. radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
  7526. break;
  7527. case 181: /* CP EOP event */
  7528. DRM_DEBUG("IH: CP EOP\n");
  7529. /* XXX check the bitfield order! */
  7530. me_id = (ring_id & 0x60) >> 5;
  7531. pipe_id = (ring_id & 0x18) >> 3;
  7532. queue_id = (ring_id & 0x7) >> 0;
  7533. switch (me_id) {
  7534. case 0:
  7535. radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
  7536. break;
  7537. case 1:
  7538. case 2:
  7539. if ((cp1_ring->me == me_id) & (cp1_ring->pipe == pipe_id))
  7540. radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP1_INDEX);
  7541. if ((cp2_ring->me == me_id) & (cp2_ring->pipe == pipe_id))
  7542. radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP2_INDEX);
  7543. break;
  7544. }
  7545. break;
  7546. case 184: /* CP Privileged reg access */
  7547. DRM_ERROR("Illegal register access in command stream\n");
  7548. /* XXX check the bitfield order! */
  7549. me_id = (ring_id & 0x60) >> 5;
  7550. pipe_id = (ring_id & 0x18) >> 3;
  7551. queue_id = (ring_id & 0x7) >> 0;
  7552. switch (me_id) {
  7553. case 0:
  7554. /* This results in a full GPU reset, but all we need to do is soft
  7555. * reset the CP for gfx
  7556. */
  7557. queue_reset = true;
  7558. break;
  7559. case 1:
  7560. /* XXX compute */
  7561. queue_reset = true;
  7562. break;
  7563. case 2:
  7564. /* XXX compute */
  7565. queue_reset = true;
  7566. break;
  7567. }
  7568. break;
  7569. case 185: /* CP Privileged inst */
  7570. DRM_ERROR("Illegal instruction in command stream\n");
  7571. /* XXX check the bitfield order! */
  7572. me_id = (ring_id & 0x60) >> 5;
  7573. pipe_id = (ring_id & 0x18) >> 3;
  7574. queue_id = (ring_id & 0x7) >> 0;
  7575. switch (me_id) {
  7576. case 0:
  7577. /* This results in a full GPU reset, but all we need to do is soft
  7578. * reset the CP for gfx
  7579. */
  7580. queue_reset = true;
  7581. break;
  7582. case 1:
  7583. /* XXX compute */
  7584. queue_reset = true;
  7585. break;
  7586. case 2:
  7587. /* XXX compute */
  7588. queue_reset = true;
  7589. break;
  7590. }
  7591. break;
  7592. case 224: /* SDMA trap event */
  7593. /* XXX check the bitfield order! */
  7594. me_id = (ring_id & 0x3) >> 0;
  7595. queue_id = (ring_id & 0xc) >> 2;
  7596. DRM_DEBUG("IH: SDMA trap\n");
  7597. switch (me_id) {
  7598. case 0:
  7599. switch (queue_id) {
  7600. case 0:
  7601. radeon_fence_process(rdev, R600_RING_TYPE_DMA_INDEX);
  7602. break;
  7603. case 1:
  7604. /* XXX compute */
  7605. break;
  7606. case 2:
  7607. /* XXX compute */
  7608. break;
  7609. }
  7610. break;
  7611. case 1:
  7612. switch (queue_id) {
  7613. case 0:
  7614. radeon_fence_process(rdev, CAYMAN_RING_TYPE_DMA1_INDEX);
  7615. break;
  7616. case 1:
  7617. /* XXX compute */
  7618. break;
  7619. case 2:
  7620. /* XXX compute */
  7621. break;
  7622. }
  7623. break;
  7624. }
  7625. break;
  7626. case 230: /* thermal low to high */
  7627. DRM_DEBUG("IH: thermal low to high\n");
  7628. rdev->pm.dpm.thermal.high_to_low = false;
  7629. queue_thermal = true;
  7630. break;
  7631. case 231: /* thermal high to low */
  7632. DRM_DEBUG("IH: thermal high to low\n");
  7633. rdev->pm.dpm.thermal.high_to_low = true;
  7634. queue_thermal = true;
  7635. break;
  7636. case 233: /* GUI IDLE */
  7637. DRM_DEBUG("IH: GUI idle\n");
  7638. break;
  7639. case 241: /* SDMA Privileged inst */
  7640. case 247: /* SDMA Privileged inst */
  7641. DRM_ERROR("Illegal instruction in SDMA command stream\n");
  7642. /* XXX check the bitfield order! */
  7643. me_id = (ring_id & 0x3) >> 0;
  7644. queue_id = (ring_id & 0xc) >> 2;
  7645. switch (me_id) {
  7646. case 0:
  7647. switch (queue_id) {
  7648. case 0:
  7649. queue_reset = true;
  7650. break;
  7651. case 1:
  7652. /* XXX compute */
  7653. queue_reset = true;
  7654. break;
  7655. case 2:
  7656. /* XXX compute */
  7657. queue_reset = true;
  7658. break;
  7659. }
  7660. break;
  7661. case 1:
  7662. switch (queue_id) {
  7663. case 0:
  7664. queue_reset = true;
  7665. break;
  7666. case 1:
  7667. /* XXX compute */
  7668. queue_reset = true;
  7669. break;
  7670. case 2:
  7671. /* XXX compute */
  7672. queue_reset = true;
  7673. break;
  7674. }
  7675. break;
  7676. }
  7677. break;
  7678. default:
  7679. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  7680. break;
  7681. }
  7682. /* wptr/rptr are in bytes! */
  7683. rptr += 16;
  7684. rptr &= rdev->ih.ptr_mask;
  7685. WREG32(IH_RB_RPTR, rptr);
  7686. }
  7687. if (queue_dp)
  7688. schedule_work(&rdev->dp_work);
  7689. if (queue_hotplug)
  7690. schedule_delayed_work(&rdev->hotplug_work, 0);
  7691. if (queue_reset) {
  7692. rdev->needs_reset = true;
  7693. wake_up_all(&rdev->fence_queue);
  7694. }
  7695. if (queue_thermal)
  7696. schedule_work(&rdev->pm.dpm.thermal.work);
  7697. rdev->ih.rptr = rptr;
  7698. atomic_set(&rdev->ih.lock, 0);
  7699. /* make sure wptr hasn't changed while processing */
  7700. wptr = cik_get_ih_wptr(rdev);
  7701. if (wptr != rptr)
  7702. goto restart_ih;
  7703. return IRQ_HANDLED;
  7704. }
  7705. /*
  7706. * startup/shutdown callbacks
  7707. */
  7708. /**
  7709. * cik_startup - program the asic to a functional state
  7710. *
  7711. * @rdev: radeon_device pointer
  7712. *
  7713. * Programs the asic to a functional state (CIK).
  7714. * Called by cik_init() and cik_resume().
  7715. * Returns 0 for success, error for failure.
  7716. */
  7717. static int cik_startup(struct radeon_device *rdev)
  7718. {
  7719. struct radeon_ring *ring;
  7720. u32 nop;
  7721. int r;
  7722. /* enable pcie gen2/3 link */
  7723. cik_pcie_gen3_enable(rdev);
  7724. /* enable aspm */
  7725. cik_program_aspm(rdev);
  7726. /* scratch needs to be initialized before MC */
  7727. r = r600_vram_scratch_init(rdev);
  7728. if (r)
  7729. return r;
  7730. cik_mc_program(rdev);
  7731. if (!(rdev->flags & RADEON_IS_IGP) && !rdev->pm.dpm_enabled) {
  7732. r = ci_mc_load_microcode(rdev);
  7733. if (r) {
  7734. DRM_ERROR("Failed to load MC firmware!\n");
  7735. return r;
  7736. }
  7737. }
  7738. r = cik_pcie_gart_enable(rdev);
  7739. if (r)
  7740. return r;
  7741. cik_gpu_init(rdev);
  7742. /* allocate rlc buffers */
  7743. if (rdev->flags & RADEON_IS_IGP) {
  7744. if (rdev->family == CHIP_KAVERI) {
  7745. rdev->rlc.reg_list = spectre_rlc_save_restore_register_list;
  7746. rdev->rlc.reg_list_size =
  7747. (u32)ARRAY_SIZE(spectre_rlc_save_restore_register_list);
  7748. } else {
  7749. rdev->rlc.reg_list = kalindi_rlc_save_restore_register_list;
  7750. rdev->rlc.reg_list_size =
  7751. (u32)ARRAY_SIZE(kalindi_rlc_save_restore_register_list);
  7752. }
  7753. }
  7754. rdev->rlc.cs_data = ci_cs_data;
  7755. rdev->rlc.cp_table_size = CP_ME_TABLE_SIZE * 5 * 4;
  7756. r = sumo_rlc_init(rdev);
  7757. if (r) {
  7758. DRM_ERROR("Failed to init rlc BOs!\n");
  7759. return r;
  7760. }
  7761. /* allocate wb buffer */
  7762. r = radeon_wb_init(rdev);
  7763. if (r)
  7764. return r;
  7765. /* allocate mec buffers */
  7766. r = cik_mec_init(rdev);
  7767. if (r) {
  7768. DRM_ERROR("Failed to init MEC BOs!\n");
  7769. return r;
  7770. }
  7771. r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX);
  7772. if (r) {
  7773. dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
  7774. return r;
  7775. }
  7776. r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_CP1_INDEX);
  7777. if (r) {
  7778. dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
  7779. return r;
  7780. }
  7781. r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_CP2_INDEX);
  7782. if (r) {
  7783. dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
  7784. return r;
  7785. }
  7786. r = radeon_fence_driver_start_ring(rdev, R600_RING_TYPE_DMA_INDEX);
  7787. if (r) {
  7788. dev_err(rdev->dev, "failed initializing DMA fences (%d).\n", r);
  7789. return r;
  7790. }
  7791. r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_DMA1_INDEX);
  7792. if (r) {
  7793. dev_err(rdev->dev, "failed initializing DMA fences (%d).\n", r);
  7794. return r;
  7795. }
  7796. r = radeon_uvd_resume(rdev);
  7797. if (!r) {
  7798. r = uvd_v4_2_resume(rdev);
  7799. if (!r) {
  7800. r = radeon_fence_driver_start_ring(rdev,
  7801. R600_RING_TYPE_UVD_INDEX);
  7802. if (r)
  7803. dev_err(rdev->dev, "UVD fences init error (%d).\n", r);
  7804. }
  7805. }
  7806. if (r)
  7807. rdev->ring[R600_RING_TYPE_UVD_INDEX].ring_size = 0;
  7808. r = radeon_vce_resume(rdev);
  7809. if (!r) {
  7810. r = vce_v2_0_resume(rdev);
  7811. if (!r)
  7812. r = radeon_fence_driver_start_ring(rdev,
  7813. TN_RING_TYPE_VCE1_INDEX);
  7814. if (!r)
  7815. r = radeon_fence_driver_start_ring(rdev,
  7816. TN_RING_TYPE_VCE2_INDEX);
  7817. }
  7818. if (r) {
  7819. dev_err(rdev->dev, "VCE init error (%d).\n", r);
  7820. rdev->ring[TN_RING_TYPE_VCE1_INDEX].ring_size = 0;
  7821. rdev->ring[TN_RING_TYPE_VCE2_INDEX].ring_size = 0;
  7822. }
  7823. /* Enable IRQ */
  7824. if (!rdev->irq.installed) {
  7825. r = radeon_irq_kms_init(rdev);
  7826. if (r)
  7827. return r;
  7828. }
  7829. r = cik_irq_init(rdev);
  7830. if (r) {
  7831. DRM_ERROR("radeon: IH init failed (%d).\n", r);
  7832. radeon_irq_kms_fini(rdev);
  7833. return r;
  7834. }
  7835. cik_irq_set(rdev);
  7836. if (rdev->family == CHIP_HAWAII) {
  7837. if (rdev->new_fw)
  7838. nop = PACKET3(PACKET3_NOP, 0x3FFF);
  7839. else
  7840. nop = RADEON_CP_PACKET2;
  7841. } else {
  7842. nop = PACKET3(PACKET3_NOP, 0x3FFF);
  7843. }
  7844. ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  7845. r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP_RPTR_OFFSET,
  7846. nop);
  7847. if (r)
  7848. return r;
  7849. /* set up the compute queues */
  7850. /* type-2 packets are deprecated on MEC, use type-3 instead */
  7851. ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
  7852. r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP1_RPTR_OFFSET,
  7853. nop);
  7854. if (r)
  7855. return r;
  7856. ring->me = 1; /* first MEC */
  7857. ring->pipe = 0; /* first pipe */
  7858. ring->queue = 0; /* first queue */
  7859. ring->wptr_offs = CIK_WB_CP1_WPTR_OFFSET;
  7860. /* type-2 packets are deprecated on MEC, use type-3 instead */
  7861. ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
  7862. r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP2_RPTR_OFFSET,
  7863. nop);
  7864. if (r)
  7865. return r;
  7866. /* dGPU only have 1 MEC */
  7867. ring->me = 1; /* first MEC */
  7868. ring->pipe = 0; /* first pipe */
  7869. ring->queue = 1; /* second queue */
  7870. ring->wptr_offs = CIK_WB_CP2_WPTR_OFFSET;
  7871. ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
  7872. r = radeon_ring_init(rdev, ring, ring->ring_size, R600_WB_DMA_RPTR_OFFSET,
  7873. SDMA_PACKET(SDMA_OPCODE_NOP, 0, 0));
  7874. if (r)
  7875. return r;
  7876. ring = &rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX];
  7877. r = radeon_ring_init(rdev, ring, ring->ring_size, CAYMAN_WB_DMA1_RPTR_OFFSET,
  7878. SDMA_PACKET(SDMA_OPCODE_NOP, 0, 0));
  7879. if (r)
  7880. return r;
  7881. r = cik_cp_resume(rdev);
  7882. if (r)
  7883. return r;
  7884. r = cik_sdma_resume(rdev);
  7885. if (r)
  7886. return r;
  7887. ring = &rdev->ring[R600_RING_TYPE_UVD_INDEX];
  7888. if (ring->ring_size) {
  7889. r = radeon_ring_init(rdev, ring, ring->ring_size, 0,
  7890. RADEON_CP_PACKET2);
  7891. if (!r)
  7892. r = uvd_v1_0_init(rdev);
  7893. if (r)
  7894. DRM_ERROR("radeon: failed initializing UVD (%d).\n", r);
  7895. }
  7896. r = -ENOENT;
  7897. ring = &rdev->ring[TN_RING_TYPE_VCE1_INDEX];
  7898. if (ring->ring_size)
  7899. r = radeon_ring_init(rdev, ring, ring->ring_size, 0,
  7900. VCE_CMD_NO_OP);
  7901. ring = &rdev->ring[TN_RING_TYPE_VCE2_INDEX];
  7902. if (ring->ring_size)
  7903. r = radeon_ring_init(rdev, ring, ring->ring_size, 0,
  7904. VCE_CMD_NO_OP);
  7905. if (!r)
  7906. r = vce_v1_0_init(rdev);
  7907. else if (r != -ENOENT)
  7908. DRM_ERROR("radeon: failed initializing VCE (%d).\n", r);
  7909. r = radeon_ib_pool_init(rdev);
  7910. if (r) {
  7911. dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
  7912. return r;
  7913. }
  7914. r = radeon_vm_manager_init(rdev);
  7915. if (r) {
  7916. dev_err(rdev->dev, "vm manager initialization failed (%d).\n", r);
  7917. return r;
  7918. }
  7919. r = radeon_audio_init(rdev);
  7920. if (r)
  7921. return r;
  7922. r = radeon_kfd_resume(rdev);
  7923. if (r)
  7924. return r;
  7925. return 0;
  7926. }
  7927. /**
  7928. * cik_resume - resume the asic to a functional state
  7929. *
  7930. * @rdev: radeon_device pointer
  7931. *
  7932. * Programs the asic to a functional state (CIK).
  7933. * Called at resume.
  7934. * Returns 0 for success, error for failure.
  7935. */
  7936. int cik_resume(struct radeon_device *rdev)
  7937. {
  7938. int r;
  7939. /* post card */
  7940. atom_asic_init(rdev->mode_info.atom_context);
  7941. /* init golden registers */
  7942. cik_init_golden_registers(rdev);
  7943. if (rdev->pm.pm_method == PM_METHOD_DPM)
  7944. radeon_pm_resume(rdev);
  7945. rdev->accel_working = true;
  7946. r = cik_startup(rdev);
  7947. if (r) {
  7948. DRM_ERROR("cik startup failed on resume\n");
  7949. rdev->accel_working = false;
  7950. return r;
  7951. }
  7952. return r;
  7953. }
  7954. /**
  7955. * cik_suspend - suspend the asic
  7956. *
  7957. * @rdev: radeon_device pointer
  7958. *
  7959. * Bring the chip into a state suitable for suspend (CIK).
  7960. * Called at suspend.
  7961. * Returns 0 for success.
  7962. */
  7963. int cik_suspend(struct radeon_device *rdev)
  7964. {
  7965. radeon_kfd_suspend(rdev);
  7966. radeon_pm_suspend(rdev);
  7967. radeon_audio_fini(rdev);
  7968. radeon_vm_manager_fini(rdev);
  7969. cik_cp_enable(rdev, false);
  7970. cik_sdma_enable(rdev, false);
  7971. uvd_v1_0_fini(rdev);
  7972. radeon_uvd_suspend(rdev);
  7973. radeon_vce_suspend(rdev);
  7974. cik_fini_pg(rdev);
  7975. cik_fini_cg(rdev);
  7976. cik_irq_suspend(rdev);
  7977. radeon_wb_disable(rdev);
  7978. cik_pcie_gart_disable(rdev);
  7979. return 0;
  7980. }
  7981. /* Plan is to move initialization in that function and use
  7982. * helper function so that radeon_device_init pretty much
  7983. * do nothing more than calling asic specific function. This
  7984. * should also allow to remove a bunch of callback function
  7985. * like vram_info.
  7986. */
  7987. /**
  7988. * cik_init - asic specific driver and hw init
  7989. *
  7990. * @rdev: radeon_device pointer
  7991. *
  7992. * Setup asic specific driver variables and program the hw
  7993. * to a functional state (CIK).
  7994. * Called at driver startup.
  7995. * Returns 0 for success, errors for failure.
  7996. */
  7997. int cik_init(struct radeon_device *rdev)
  7998. {
  7999. struct radeon_ring *ring;
  8000. int r;
  8001. /* Read BIOS */
  8002. if (!radeon_get_bios(rdev)) {
  8003. if (ASIC_IS_AVIVO(rdev))
  8004. return -EINVAL;
  8005. }
  8006. /* Must be an ATOMBIOS */
  8007. if (!rdev->is_atom_bios) {
  8008. dev_err(rdev->dev, "Expecting atombios for cayman GPU\n");
  8009. return -EINVAL;
  8010. }
  8011. r = radeon_atombios_init(rdev);
  8012. if (r)
  8013. return r;
  8014. /* Post card if necessary */
  8015. if (!radeon_card_posted(rdev)) {
  8016. if (!rdev->bios) {
  8017. dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n");
  8018. return -EINVAL;
  8019. }
  8020. DRM_INFO("GPU not posted. posting now...\n");
  8021. atom_asic_init(rdev->mode_info.atom_context);
  8022. }
  8023. /* init golden registers */
  8024. cik_init_golden_registers(rdev);
  8025. /* Initialize scratch registers */
  8026. cik_scratch_init(rdev);
  8027. /* Initialize surface registers */
  8028. radeon_surface_init(rdev);
  8029. /* Initialize clocks */
  8030. radeon_get_clock_info(rdev->ddev);
  8031. /* Fence driver */
  8032. r = radeon_fence_driver_init(rdev);
  8033. if (r)
  8034. return r;
  8035. /* initialize memory controller */
  8036. r = cik_mc_init(rdev);
  8037. if (r)
  8038. return r;
  8039. /* Memory manager */
  8040. r = radeon_bo_init(rdev);
  8041. if (r)
  8042. return r;
  8043. if (rdev->flags & RADEON_IS_IGP) {
  8044. if (!rdev->me_fw || !rdev->pfp_fw || !rdev->ce_fw ||
  8045. !rdev->mec_fw || !rdev->sdma_fw || !rdev->rlc_fw) {
  8046. r = cik_init_microcode(rdev);
  8047. if (r) {
  8048. DRM_ERROR("Failed to load firmware!\n");
  8049. return r;
  8050. }
  8051. }
  8052. } else {
  8053. if (!rdev->me_fw || !rdev->pfp_fw || !rdev->ce_fw ||
  8054. !rdev->mec_fw || !rdev->sdma_fw || !rdev->rlc_fw ||
  8055. !rdev->mc_fw) {
  8056. r = cik_init_microcode(rdev);
  8057. if (r) {
  8058. DRM_ERROR("Failed to load firmware!\n");
  8059. return r;
  8060. }
  8061. }
  8062. }
  8063. /* Initialize power management */
  8064. radeon_pm_init(rdev);
  8065. ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  8066. ring->ring_obj = NULL;
  8067. r600_ring_init(rdev, ring, 1024 * 1024);
  8068. ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
  8069. ring->ring_obj = NULL;
  8070. r600_ring_init(rdev, ring, 1024 * 1024);
  8071. r = radeon_doorbell_get(rdev, &ring->doorbell_index);
  8072. if (r)
  8073. return r;
  8074. ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
  8075. ring->ring_obj = NULL;
  8076. r600_ring_init(rdev, ring, 1024 * 1024);
  8077. r = radeon_doorbell_get(rdev, &ring->doorbell_index);
  8078. if (r)
  8079. return r;
  8080. ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
  8081. ring->ring_obj = NULL;
  8082. r600_ring_init(rdev, ring, 256 * 1024);
  8083. ring = &rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX];
  8084. ring->ring_obj = NULL;
  8085. r600_ring_init(rdev, ring, 256 * 1024);
  8086. r = radeon_uvd_init(rdev);
  8087. if (!r) {
  8088. ring = &rdev->ring[R600_RING_TYPE_UVD_INDEX];
  8089. ring->ring_obj = NULL;
  8090. r600_ring_init(rdev, ring, 4096);
  8091. }
  8092. r = radeon_vce_init(rdev);
  8093. if (!r) {
  8094. ring = &rdev->ring[TN_RING_TYPE_VCE1_INDEX];
  8095. ring->ring_obj = NULL;
  8096. r600_ring_init(rdev, ring, 4096);
  8097. ring = &rdev->ring[TN_RING_TYPE_VCE2_INDEX];
  8098. ring->ring_obj = NULL;
  8099. r600_ring_init(rdev, ring, 4096);
  8100. }
  8101. rdev->ih.ring_obj = NULL;
  8102. r600_ih_ring_init(rdev, 64 * 1024);
  8103. r = r600_pcie_gart_init(rdev);
  8104. if (r)
  8105. return r;
  8106. rdev->accel_working = true;
  8107. r = cik_startup(rdev);
  8108. if (r) {
  8109. dev_err(rdev->dev, "disabling GPU acceleration\n");
  8110. cik_cp_fini(rdev);
  8111. cik_sdma_fini(rdev);
  8112. cik_irq_fini(rdev);
  8113. sumo_rlc_fini(rdev);
  8114. cik_mec_fini(rdev);
  8115. radeon_wb_fini(rdev);
  8116. radeon_ib_pool_fini(rdev);
  8117. radeon_vm_manager_fini(rdev);
  8118. radeon_irq_kms_fini(rdev);
  8119. cik_pcie_gart_fini(rdev);
  8120. rdev->accel_working = false;
  8121. }
  8122. /* Don't start up if the MC ucode is missing.
  8123. * The default clocks and voltages before the MC ucode
  8124. * is loaded are not suffient for advanced operations.
  8125. */
  8126. if (!rdev->mc_fw && !(rdev->flags & RADEON_IS_IGP)) {
  8127. DRM_ERROR("radeon: MC ucode required for NI+.\n");
  8128. return -EINVAL;
  8129. }
  8130. return 0;
  8131. }
  8132. /**
  8133. * cik_fini - asic specific driver and hw fini
  8134. *
  8135. * @rdev: radeon_device pointer
  8136. *
  8137. * Tear down the asic specific driver variables and program the hw
  8138. * to an idle state (CIK).
  8139. * Called at driver unload.
  8140. */
  8141. void cik_fini(struct radeon_device *rdev)
  8142. {
  8143. radeon_pm_fini(rdev);
  8144. cik_cp_fini(rdev);
  8145. cik_sdma_fini(rdev);
  8146. cik_fini_pg(rdev);
  8147. cik_fini_cg(rdev);
  8148. cik_irq_fini(rdev);
  8149. sumo_rlc_fini(rdev);
  8150. cik_mec_fini(rdev);
  8151. radeon_wb_fini(rdev);
  8152. radeon_vm_manager_fini(rdev);
  8153. radeon_ib_pool_fini(rdev);
  8154. radeon_irq_kms_fini(rdev);
  8155. uvd_v1_0_fini(rdev);
  8156. radeon_uvd_fini(rdev);
  8157. radeon_vce_fini(rdev);
  8158. cik_pcie_gart_fini(rdev);
  8159. r600_vram_scratch_fini(rdev);
  8160. radeon_gem_fini(rdev);
  8161. radeon_fence_driver_fini(rdev);
  8162. radeon_bo_fini(rdev);
  8163. radeon_atombios_fini(rdev);
  8164. kfree(rdev->bios);
  8165. rdev->bios = NULL;
  8166. }
  8167. void dce8_program_fmt(struct drm_encoder *encoder)
  8168. {
  8169. struct drm_device *dev = encoder->dev;
  8170. struct radeon_device *rdev = dev->dev_private;
  8171. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  8172. struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
  8173. struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
  8174. int bpc = 0;
  8175. u32 tmp = 0;
  8176. enum radeon_connector_dither dither = RADEON_FMT_DITHER_DISABLE;
  8177. if (connector) {
  8178. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  8179. bpc = radeon_get_monitor_bpc(connector);
  8180. dither = radeon_connector->dither;
  8181. }
  8182. /* LVDS/eDP FMT is set up by atom */
  8183. if (radeon_encoder->devices & ATOM_DEVICE_LCD_SUPPORT)
  8184. return;
  8185. /* not needed for analog */
  8186. if ((radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1) ||
  8187. (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2))
  8188. return;
  8189. if (bpc == 0)
  8190. return;
  8191. switch (bpc) {
  8192. case 6:
  8193. if (dither == RADEON_FMT_DITHER_ENABLE)
  8194. /* XXX sort out optimal dither settings */
  8195. tmp |= (FMT_FRAME_RANDOM_ENABLE | FMT_HIGHPASS_RANDOM_ENABLE |
  8196. FMT_SPATIAL_DITHER_EN | FMT_SPATIAL_DITHER_DEPTH(0));
  8197. else
  8198. tmp |= (FMT_TRUNCATE_EN | FMT_TRUNCATE_DEPTH(0));
  8199. break;
  8200. case 8:
  8201. if (dither == RADEON_FMT_DITHER_ENABLE)
  8202. /* XXX sort out optimal dither settings */
  8203. tmp |= (FMT_FRAME_RANDOM_ENABLE | FMT_HIGHPASS_RANDOM_ENABLE |
  8204. FMT_RGB_RANDOM_ENABLE |
  8205. FMT_SPATIAL_DITHER_EN | FMT_SPATIAL_DITHER_DEPTH(1));
  8206. else
  8207. tmp |= (FMT_TRUNCATE_EN | FMT_TRUNCATE_DEPTH(1));
  8208. break;
  8209. case 10:
  8210. if (dither == RADEON_FMT_DITHER_ENABLE)
  8211. /* XXX sort out optimal dither settings */
  8212. tmp |= (FMT_FRAME_RANDOM_ENABLE | FMT_HIGHPASS_RANDOM_ENABLE |
  8213. FMT_RGB_RANDOM_ENABLE |
  8214. FMT_SPATIAL_DITHER_EN | FMT_SPATIAL_DITHER_DEPTH(2));
  8215. else
  8216. tmp |= (FMT_TRUNCATE_EN | FMT_TRUNCATE_DEPTH(2));
  8217. break;
  8218. default:
  8219. /* not needed */
  8220. break;
  8221. }
  8222. WREG32(FMT_BIT_DEPTH_CONTROL + radeon_crtc->crtc_offset, tmp);
  8223. }
  8224. /* display watermark setup */
  8225. /**
  8226. * dce8_line_buffer_adjust - Set up the line buffer
  8227. *
  8228. * @rdev: radeon_device pointer
  8229. * @radeon_crtc: the selected display controller
  8230. * @mode: the current display mode on the selected display
  8231. * controller
  8232. *
  8233. * Setup up the line buffer allocation for
  8234. * the selected display controller (CIK).
  8235. * Returns the line buffer size in pixels.
  8236. */
  8237. static u32 dce8_line_buffer_adjust(struct radeon_device *rdev,
  8238. struct radeon_crtc *radeon_crtc,
  8239. struct drm_display_mode *mode)
  8240. {
  8241. u32 tmp, buffer_alloc, i;
  8242. u32 pipe_offset = radeon_crtc->crtc_id * 0x20;
  8243. /*
  8244. * Line Buffer Setup
  8245. * There are 6 line buffers, one for each display controllers.
  8246. * There are 3 partitions per LB. Select the number of partitions
  8247. * to enable based on the display width. For display widths larger
  8248. * than 4096, you need use to use 2 display controllers and combine
  8249. * them using the stereo blender.
  8250. */
  8251. if (radeon_crtc->base.enabled && mode) {
  8252. if (mode->crtc_hdisplay < 1920) {
  8253. tmp = 1;
  8254. buffer_alloc = 2;
  8255. } else if (mode->crtc_hdisplay < 2560) {
  8256. tmp = 2;
  8257. buffer_alloc = 2;
  8258. } else if (mode->crtc_hdisplay < 4096) {
  8259. tmp = 0;
  8260. buffer_alloc = (rdev->flags & RADEON_IS_IGP) ? 2 : 4;
  8261. } else {
  8262. DRM_DEBUG_KMS("Mode too big for LB!\n");
  8263. tmp = 0;
  8264. buffer_alloc = (rdev->flags & RADEON_IS_IGP) ? 2 : 4;
  8265. }
  8266. } else {
  8267. tmp = 1;
  8268. buffer_alloc = 0;
  8269. }
  8270. WREG32(LB_MEMORY_CTRL + radeon_crtc->crtc_offset,
  8271. LB_MEMORY_CONFIG(tmp) | LB_MEMORY_SIZE(0x6B0));
  8272. WREG32(PIPE0_DMIF_BUFFER_CONTROL + pipe_offset,
  8273. DMIF_BUFFERS_ALLOCATED(buffer_alloc));
  8274. for (i = 0; i < rdev->usec_timeout; i++) {
  8275. if (RREG32(PIPE0_DMIF_BUFFER_CONTROL + pipe_offset) &
  8276. DMIF_BUFFERS_ALLOCATED_COMPLETED)
  8277. break;
  8278. udelay(1);
  8279. }
  8280. if (radeon_crtc->base.enabled && mode) {
  8281. switch (tmp) {
  8282. case 0:
  8283. default:
  8284. return 4096 * 2;
  8285. case 1:
  8286. return 1920 * 2;
  8287. case 2:
  8288. return 2560 * 2;
  8289. }
  8290. }
  8291. /* controller not enabled, so no lb used */
  8292. return 0;
  8293. }
  8294. /**
  8295. * cik_get_number_of_dram_channels - get the number of dram channels
  8296. *
  8297. * @rdev: radeon_device pointer
  8298. *
  8299. * Look up the number of video ram channels (CIK).
  8300. * Used for display watermark bandwidth calculations
  8301. * Returns the number of dram channels
  8302. */
  8303. static u32 cik_get_number_of_dram_channels(struct radeon_device *rdev)
  8304. {
  8305. u32 tmp = RREG32(MC_SHARED_CHMAP);
  8306. switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
  8307. case 0:
  8308. default:
  8309. return 1;
  8310. case 1:
  8311. return 2;
  8312. case 2:
  8313. return 4;
  8314. case 3:
  8315. return 8;
  8316. case 4:
  8317. return 3;
  8318. case 5:
  8319. return 6;
  8320. case 6:
  8321. return 10;
  8322. case 7:
  8323. return 12;
  8324. case 8:
  8325. return 16;
  8326. }
  8327. }
  8328. struct dce8_wm_params {
  8329. u32 dram_channels; /* number of dram channels */
  8330. u32 yclk; /* bandwidth per dram data pin in kHz */
  8331. u32 sclk; /* engine clock in kHz */
  8332. u32 disp_clk; /* display clock in kHz */
  8333. u32 src_width; /* viewport width */
  8334. u32 active_time; /* active display time in ns */
  8335. u32 blank_time; /* blank time in ns */
  8336. bool interlaced; /* mode is interlaced */
  8337. fixed20_12 vsc; /* vertical scale ratio */
  8338. u32 num_heads; /* number of active crtcs */
  8339. u32 bytes_per_pixel; /* bytes per pixel display + overlay */
  8340. u32 lb_size; /* line buffer allocated to pipe */
  8341. u32 vtaps; /* vertical scaler taps */
  8342. };
  8343. /**
  8344. * dce8_dram_bandwidth - get the dram bandwidth
  8345. *
  8346. * @wm: watermark calculation data
  8347. *
  8348. * Calculate the raw dram bandwidth (CIK).
  8349. * Used for display watermark bandwidth calculations
  8350. * Returns the dram bandwidth in MBytes/s
  8351. */
  8352. static u32 dce8_dram_bandwidth(struct dce8_wm_params *wm)
  8353. {
  8354. /* Calculate raw DRAM Bandwidth */
  8355. fixed20_12 dram_efficiency; /* 0.7 */
  8356. fixed20_12 yclk, dram_channels, bandwidth;
  8357. fixed20_12 a;
  8358. a.full = dfixed_const(1000);
  8359. yclk.full = dfixed_const(wm->yclk);
  8360. yclk.full = dfixed_div(yclk, a);
  8361. dram_channels.full = dfixed_const(wm->dram_channels * 4);
  8362. a.full = dfixed_const(10);
  8363. dram_efficiency.full = dfixed_const(7);
  8364. dram_efficiency.full = dfixed_div(dram_efficiency, a);
  8365. bandwidth.full = dfixed_mul(dram_channels, yclk);
  8366. bandwidth.full = dfixed_mul(bandwidth, dram_efficiency);
  8367. return dfixed_trunc(bandwidth);
  8368. }
  8369. /**
  8370. * dce8_dram_bandwidth_for_display - get the dram bandwidth for display
  8371. *
  8372. * @wm: watermark calculation data
  8373. *
  8374. * Calculate the dram bandwidth used for display (CIK).
  8375. * Used for display watermark bandwidth calculations
  8376. * Returns the dram bandwidth for display in MBytes/s
  8377. */
  8378. static u32 dce8_dram_bandwidth_for_display(struct dce8_wm_params *wm)
  8379. {
  8380. /* Calculate DRAM Bandwidth and the part allocated to display. */
  8381. fixed20_12 disp_dram_allocation; /* 0.3 to 0.7 */
  8382. fixed20_12 yclk, dram_channels, bandwidth;
  8383. fixed20_12 a;
  8384. a.full = dfixed_const(1000);
  8385. yclk.full = dfixed_const(wm->yclk);
  8386. yclk.full = dfixed_div(yclk, a);
  8387. dram_channels.full = dfixed_const(wm->dram_channels * 4);
  8388. a.full = dfixed_const(10);
  8389. disp_dram_allocation.full = dfixed_const(3); /* XXX worse case value 0.3 */
  8390. disp_dram_allocation.full = dfixed_div(disp_dram_allocation, a);
  8391. bandwidth.full = dfixed_mul(dram_channels, yclk);
  8392. bandwidth.full = dfixed_mul(bandwidth, disp_dram_allocation);
  8393. return dfixed_trunc(bandwidth);
  8394. }
  8395. /**
  8396. * dce8_data_return_bandwidth - get the data return bandwidth
  8397. *
  8398. * @wm: watermark calculation data
  8399. *
  8400. * Calculate the data return bandwidth used for display (CIK).
  8401. * Used for display watermark bandwidth calculations
  8402. * Returns the data return bandwidth in MBytes/s
  8403. */
  8404. static u32 dce8_data_return_bandwidth(struct dce8_wm_params *wm)
  8405. {
  8406. /* Calculate the display Data return Bandwidth */
  8407. fixed20_12 return_efficiency; /* 0.8 */
  8408. fixed20_12 sclk, bandwidth;
  8409. fixed20_12 a;
  8410. a.full = dfixed_const(1000);
  8411. sclk.full = dfixed_const(wm->sclk);
  8412. sclk.full = dfixed_div(sclk, a);
  8413. a.full = dfixed_const(10);
  8414. return_efficiency.full = dfixed_const(8);
  8415. return_efficiency.full = dfixed_div(return_efficiency, a);
  8416. a.full = dfixed_const(32);
  8417. bandwidth.full = dfixed_mul(a, sclk);
  8418. bandwidth.full = dfixed_mul(bandwidth, return_efficiency);
  8419. return dfixed_trunc(bandwidth);
  8420. }
  8421. /**
  8422. * dce8_dmif_request_bandwidth - get the dmif bandwidth
  8423. *
  8424. * @wm: watermark calculation data
  8425. *
  8426. * Calculate the dmif bandwidth used for display (CIK).
  8427. * Used for display watermark bandwidth calculations
  8428. * Returns the dmif bandwidth in MBytes/s
  8429. */
  8430. static u32 dce8_dmif_request_bandwidth(struct dce8_wm_params *wm)
  8431. {
  8432. /* Calculate the DMIF Request Bandwidth */
  8433. fixed20_12 disp_clk_request_efficiency; /* 0.8 */
  8434. fixed20_12 disp_clk, bandwidth;
  8435. fixed20_12 a, b;
  8436. a.full = dfixed_const(1000);
  8437. disp_clk.full = dfixed_const(wm->disp_clk);
  8438. disp_clk.full = dfixed_div(disp_clk, a);
  8439. a.full = dfixed_const(32);
  8440. b.full = dfixed_mul(a, disp_clk);
  8441. a.full = dfixed_const(10);
  8442. disp_clk_request_efficiency.full = dfixed_const(8);
  8443. disp_clk_request_efficiency.full = dfixed_div(disp_clk_request_efficiency, a);
  8444. bandwidth.full = dfixed_mul(b, disp_clk_request_efficiency);
  8445. return dfixed_trunc(bandwidth);
  8446. }
  8447. /**
  8448. * dce8_available_bandwidth - get the min available bandwidth
  8449. *
  8450. * @wm: watermark calculation data
  8451. *
  8452. * Calculate the min available bandwidth used for display (CIK).
  8453. * Used for display watermark bandwidth calculations
  8454. * Returns the min available bandwidth in MBytes/s
  8455. */
  8456. static u32 dce8_available_bandwidth(struct dce8_wm_params *wm)
  8457. {
  8458. /* Calculate the Available bandwidth. Display can use this temporarily but not in average. */
  8459. u32 dram_bandwidth = dce8_dram_bandwidth(wm);
  8460. u32 data_return_bandwidth = dce8_data_return_bandwidth(wm);
  8461. u32 dmif_req_bandwidth = dce8_dmif_request_bandwidth(wm);
  8462. return min(dram_bandwidth, min(data_return_bandwidth, dmif_req_bandwidth));
  8463. }
  8464. /**
  8465. * dce8_average_bandwidth - get the average available bandwidth
  8466. *
  8467. * @wm: watermark calculation data
  8468. *
  8469. * Calculate the average available bandwidth used for display (CIK).
  8470. * Used for display watermark bandwidth calculations
  8471. * Returns the average available bandwidth in MBytes/s
  8472. */
  8473. static u32 dce8_average_bandwidth(struct dce8_wm_params *wm)
  8474. {
  8475. /* Calculate the display mode Average Bandwidth
  8476. * DisplayMode should contain the source and destination dimensions,
  8477. * timing, etc.
  8478. */
  8479. fixed20_12 bpp;
  8480. fixed20_12 line_time;
  8481. fixed20_12 src_width;
  8482. fixed20_12 bandwidth;
  8483. fixed20_12 a;
  8484. a.full = dfixed_const(1000);
  8485. line_time.full = dfixed_const(wm->active_time + wm->blank_time);
  8486. line_time.full = dfixed_div(line_time, a);
  8487. bpp.full = dfixed_const(wm->bytes_per_pixel);
  8488. src_width.full = dfixed_const(wm->src_width);
  8489. bandwidth.full = dfixed_mul(src_width, bpp);
  8490. bandwidth.full = dfixed_mul(bandwidth, wm->vsc);
  8491. bandwidth.full = dfixed_div(bandwidth, line_time);
  8492. return dfixed_trunc(bandwidth);
  8493. }
  8494. /**
  8495. * dce8_latency_watermark - get the latency watermark
  8496. *
  8497. * @wm: watermark calculation data
  8498. *
  8499. * Calculate the latency watermark (CIK).
  8500. * Used for display watermark bandwidth calculations
  8501. * Returns the latency watermark in ns
  8502. */
  8503. static u32 dce8_latency_watermark(struct dce8_wm_params *wm)
  8504. {
  8505. /* First calculate the latency in ns */
  8506. u32 mc_latency = 2000; /* 2000 ns. */
  8507. u32 available_bandwidth = dce8_available_bandwidth(wm);
  8508. u32 worst_chunk_return_time = (512 * 8 * 1000) / available_bandwidth;
  8509. u32 cursor_line_pair_return_time = (128 * 4 * 1000) / available_bandwidth;
  8510. u32 dc_latency = 40000000 / wm->disp_clk; /* dc pipe latency */
  8511. u32 other_heads_data_return_time = ((wm->num_heads + 1) * worst_chunk_return_time) +
  8512. (wm->num_heads * cursor_line_pair_return_time);
  8513. u32 latency = mc_latency + other_heads_data_return_time + dc_latency;
  8514. u32 max_src_lines_per_dst_line, lb_fill_bw, line_fill_time;
  8515. u32 tmp, dmif_size = 12288;
  8516. fixed20_12 a, b, c;
  8517. if (wm->num_heads == 0)
  8518. return 0;
  8519. a.full = dfixed_const(2);
  8520. b.full = dfixed_const(1);
  8521. if ((wm->vsc.full > a.full) ||
  8522. ((wm->vsc.full > b.full) && (wm->vtaps >= 3)) ||
  8523. (wm->vtaps >= 5) ||
  8524. ((wm->vsc.full >= a.full) && wm->interlaced))
  8525. max_src_lines_per_dst_line = 4;
  8526. else
  8527. max_src_lines_per_dst_line = 2;
  8528. a.full = dfixed_const(available_bandwidth);
  8529. b.full = dfixed_const(wm->num_heads);
  8530. a.full = dfixed_div(a, b);
  8531. b.full = dfixed_const(mc_latency + 512);
  8532. c.full = dfixed_const(wm->disp_clk);
  8533. b.full = dfixed_div(b, c);
  8534. c.full = dfixed_const(dmif_size);
  8535. b.full = dfixed_div(c, b);
  8536. tmp = min(dfixed_trunc(a), dfixed_trunc(b));
  8537. b.full = dfixed_const(1000);
  8538. c.full = dfixed_const(wm->disp_clk);
  8539. b.full = dfixed_div(c, b);
  8540. c.full = dfixed_const(wm->bytes_per_pixel);
  8541. b.full = dfixed_mul(b, c);
  8542. lb_fill_bw = min(tmp, dfixed_trunc(b));
  8543. a.full = dfixed_const(max_src_lines_per_dst_line * wm->src_width * wm->bytes_per_pixel);
  8544. b.full = dfixed_const(1000);
  8545. c.full = dfixed_const(lb_fill_bw);
  8546. b.full = dfixed_div(c, b);
  8547. a.full = dfixed_div(a, b);
  8548. line_fill_time = dfixed_trunc(a);
  8549. if (line_fill_time < wm->active_time)
  8550. return latency;
  8551. else
  8552. return latency + (line_fill_time - wm->active_time);
  8553. }
  8554. /**
  8555. * dce8_average_bandwidth_vs_dram_bandwidth_for_display - check
  8556. * average and available dram bandwidth
  8557. *
  8558. * @wm: watermark calculation data
  8559. *
  8560. * Check if the display average bandwidth fits in the display
  8561. * dram bandwidth (CIK).
  8562. * Used for display watermark bandwidth calculations
  8563. * Returns true if the display fits, false if not.
  8564. */
  8565. static bool dce8_average_bandwidth_vs_dram_bandwidth_for_display(struct dce8_wm_params *wm)
  8566. {
  8567. if (dce8_average_bandwidth(wm) <=
  8568. (dce8_dram_bandwidth_for_display(wm) / wm->num_heads))
  8569. return true;
  8570. else
  8571. return false;
  8572. }
  8573. /**
  8574. * dce8_average_bandwidth_vs_available_bandwidth - check
  8575. * average and available bandwidth
  8576. *
  8577. * @wm: watermark calculation data
  8578. *
  8579. * Check if the display average bandwidth fits in the display
  8580. * available bandwidth (CIK).
  8581. * Used for display watermark bandwidth calculations
  8582. * Returns true if the display fits, false if not.
  8583. */
  8584. static bool dce8_average_bandwidth_vs_available_bandwidth(struct dce8_wm_params *wm)
  8585. {
  8586. if (dce8_average_bandwidth(wm) <=
  8587. (dce8_available_bandwidth(wm) / wm->num_heads))
  8588. return true;
  8589. else
  8590. return false;
  8591. }
  8592. /**
  8593. * dce8_check_latency_hiding - check latency hiding
  8594. *
  8595. * @wm: watermark calculation data
  8596. *
  8597. * Check latency hiding (CIK).
  8598. * Used for display watermark bandwidth calculations
  8599. * Returns true if the display fits, false if not.
  8600. */
  8601. static bool dce8_check_latency_hiding(struct dce8_wm_params *wm)
  8602. {
  8603. u32 lb_partitions = wm->lb_size / wm->src_width;
  8604. u32 line_time = wm->active_time + wm->blank_time;
  8605. u32 latency_tolerant_lines;
  8606. u32 latency_hiding;
  8607. fixed20_12 a;
  8608. a.full = dfixed_const(1);
  8609. if (wm->vsc.full > a.full)
  8610. latency_tolerant_lines = 1;
  8611. else {
  8612. if (lb_partitions <= (wm->vtaps + 1))
  8613. latency_tolerant_lines = 1;
  8614. else
  8615. latency_tolerant_lines = 2;
  8616. }
  8617. latency_hiding = (latency_tolerant_lines * line_time + wm->blank_time);
  8618. if (dce8_latency_watermark(wm) <= latency_hiding)
  8619. return true;
  8620. else
  8621. return false;
  8622. }
  8623. /**
  8624. * dce8_program_watermarks - program display watermarks
  8625. *
  8626. * @rdev: radeon_device pointer
  8627. * @radeon_crtc: the selected display controller
  8628. * @lb_size: line buffer size
  8629. * @num_heads: number of display controllers in use
  8630. *
  8631. * Calculate and program the display watermarks for the
  8632. * selected display controller (CIK).
  8633. */
  8634. static void dce8_program_watermarks(struct radeon_device *rdev,
  8635. struct radeon_crtc *radeon_crtc,
  8636. u32 lb_size, u32 num_heads)
  8637. {
  8638. struct drm_display_mode *mode = &radeon_crtc->base.mode;
  8639. struct dce8_wm_params wm_low, wm_high;
  8640. u32 pixel_period;
  8641. u32 line_time = 0;
  8642. u32 latency_watermark_a = 0, latency_watermark_b = 0;
  8643. u32 tmp, wm_mask;
  8644. if (radeon_crtc->base.enabled && num_heads && mode) {
  8645. pixel_period = 1000000 / (u32)mode->clock;
  8646. line_time = min((u32)mode->crtc_htotal * pixel_period, (u32)65535);
  8647. /* watermark for high clocks */
  8648. if ((rdev->pm.pm_method == PM_METHOD_DPM) &&
  8649. rdev->pm.dpm_enabled) {
  8650. wm_high.yclk =
  8651. radeon_dpm_get_mclk(rdev, false) * 10;
  8652. wm_high.sclk =
  8653. radeon_dpm_get_sclk(rdev, false) * 10;
  8654. } else {
  8655. wm_high.yclk = rdev->pm.current_mclk * 10;
  8656. wm_high.sclk = rdev->pm.current_sclk * 10;
  8657. }
  8658. wm_high.disp_clk = mode->clock;
  8659. wm_high.src_width = mode->crtc_hdisplay;
  8660. wm_high.active_time = mode->crtc_hdisplay * pixel_period;
  8661. wm_high.blank_time = line_time - wm_high.active_time;
  8662. wm_high.interlaced = false;
  8663. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  8664. wm_high.interlaced = true;
  8665. wm_high.vsc = radeon_crtc->vsc;
  8666. wm_high.vtaps = 1;
  8667. if (radeon_crtc->rmx_type != RMX_OFF)
  8668. wm_high.vtaps = 2;
  8669. wm_high.bytes_per_pixel = 4; /* XXX: get this from fb config */
  8670. wm_high.lb_size = lb_size;
  8671. wm_high.dram_channels = cik_get_number_of_dram_channels(rdev);
  8672. wm_high.num_heads = num_heads;
  8673. /* set for high clocks */
  8674. latency_watermark_a = min(dce8_latency_watermark(&wm_high), (u32)65535);
  8675. /* possibly force display priority to high */
  8676. /* should really do this at mode validation time... */
  8677. if (!dce8_average_bandwidth_vs_dram_bandwidth_for_display(&wm_high) ||
  8678. !dce8_average_bandwidth_vs_available_bandwidth(&wm_high) ||
  8679. !dce8_check_latency_hiding(&wm_high) ||
  8680. (rdev->disp_priority == 2)) {
  8681. DRM_DEBUG_KMS("force priority to high\n");
  8682. }
  8683. /* watermark for low clocks */
  8684. if ((rdev->pm.pm_method == PM_METHOD_DPM) &&
  8685. rdev->pm.dpm_enabled) {
  8686. wm_low.yclk =
  8687. radeon_dpm_get_mclk(rdev, true) * 10;
  8688. wm_low.sclk =
  8689. radeon_dpm_get_sclk(rdev, true) * 10;
  8690. } else {
  8691. wm_low.yclk = rdev->pm.current_mclk * 10;
  8692. wm_low.sclk = rdev->pm.current_sclk * 10;
  8693. }
  8694. wm_low.disp_clk = mode->clock;
  8695. wm_low.src_width = mode->crtc_hdisplay;
  8696. wm_low.active_time = mode->crtc_hdisplay * pixel_period;
  8697. wm_low.blank_time = line_time - wm_low.active_time;
  8698. wm_low.interlaced = false;
  8699. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  8700. wm_low.interlaced = true;
  8701. wm_low.vsc = radeon_crtc->vsc;
  8702. wm_low.vtaps = 1;
  8703. if (radeon_crtc->rmx_type != RMX_OFF)
  8704. wm_low.vtaps = 2;
  8705. wm_low.bytes_per_pixel = 4; /* XXX: get this from fb config */
  8706. wm_low.lb_size = lb_size;
  8707. wm_low.dram_channels = cik_get_number_of_dram_channels(rdev);
  8708. wm_low.num_heads = num_heads;
  8709. /* set for low clocks */
  8710. latency_watermark_b = min(dce8_latency_watermark(&wm_low), (u32)65535);
  8711. /* possibly force display priority to high */
  8712. /* should really do this at mode validation time... */
  8713. if (!dce8_average_bandwidth_vs_dram_bandwidth_for_display(&wm_low) ||
  8714. !dce8_average_bandwidth_vs_available_bandwidth(&wm_low) ||
  8715. !dce8_check_latency_hiding(&wm_low) ||
  8716. (rdev->disp_priority == 2)) {
  8717. DRM_DEBUG_KMS("force priority to high\n");
  8718. }
  8719. /* Save number of lines the linebuffer leads before the scanout */
  8720. radeon_crtc->lb_vblank_lead_lines = DIV_ROUND_UP(lb_size, mode->crtc_hdisplay);
  8721. }
  8722. /* select wm A */
  8723. wm_mask = RREG32(DPG_WATERMARK_MASK_CONTROL + radeon_crtc->crtc_offset);
  8724. tmp = wm_mask;
  8725. tmp &= ~LATENCY_WATERMARK_MASK(3);
  8726. tmp |= LATENCY_WATERMARK_MASK(1);
  8727. WREG32(DPG_WATERMARK_MASK_CONTROL + radeon_crtc->crtc_offset, tmp);
  8728. WREG32(DPG_PIPE_LATENCY_CONTROL + radeon_crtc->crtc_offset,
  8729. (LATENCY_LOW_WATERMARK(latency_watermark_a) |
  8730. LATENCY_HIGH_WATERMARK(line_time)));
  8731. /* select wm B */
  8732. tmp = RREG32(DPG_WATERMARK_MASK_CONTROL + radeon_crtc->crtc_offset);
  8733. tmp &= ~LATENCY_WATERMARK_MASK(3);
  8734. tmp |= LATENCY_WATERMARK_MASK(2);
  8735. WREG32(DPG_WATERMARK_MASK_CONTROL + radeon_crtc->crtc_offset, tmp);
  8736. WREG32(DPG_PIPE_LATENCY_CONTROL + radeon_crtc->crtc_offset,
  8737. (LATENCY_LOW_WATERMARK(latency_watermark_b) |
  8738. LATENCY_HIGH_WATERMARK(line_time)));
  8739. /* restore original selection */
  8740. WREG32(DPG_WATERMARK_MASK_CONTROL + radeon_crtc->crtc_offset, wm_mask);
  8741. /* save values for DPM */
  8742. radeon_crtc->line_time = line_time;
  8743. radeon_crtc->wm_high = latency_watermark_a;
  8744. radeon_crtc->wm_low = latency_watermark_b;
  8745. }
  8746. /**
  8747. * dce8_bandwidth_update - program display watermarks
  8748. *
  8749. * @rdev: radeon_device pointer
  8750. *
  8751. * Calculate and program the display watermarks and line
  8752. * buffer allocation (CIK).
  8753. */
  8754. void dce8_bandwidth_update(struct radeon_device *rdev)
  8755. {
  8756. struct drm_display_mode *mode = NULL;
  8757. u32 num_heads = 0, lb_size;
  8758. int i;
  8759. if (!rdev->mode_info.mode_config_initialized)
  8760. return;
  8761. radeon_update_display_priority(rdev);
  8762. for (i = 0; i < rdev->num_crtc; i++) {
  8763. if (rdev->mode_info.crtcs[i]->base.enabled)
  8764. num_heads++;
  8765. }
  8766. for (i = 0; i < rdev->num_crtc; i++) {
  8767. mode = &rdev->mode_info.crtcs[i]->base.mode;
  8768. lb_size = dce8_line_buffer_adjust(rdev, rdev->mode_info.crtcs[i], mode);
  8769. dce8_program_watermarks(rdev, rdev->mode_info.crtcs[i], lb_size, num_heads);
  8770. }
  8771. }
  8772. /**
  8773. * cik_get_gpu_clock_counter - return GPU clock counter snapshot
  8774. *
  8775. * @rdev: radeon_device pointer
  8776. *
  8777. * Fetches a GPU clock counter snapshot (SI).
  8778. * Returns the 64 bit clock counter snapshot.
  8779. */
  8780. uint64_t cik_get_gpu_clock_counter(struct radeon_device *rdev)
  8781. {
  8782. uint64_t clock;
  8783. mutex_lock(&rdev->gpu_clock_mutex);
  8784. WREG32(RLC_CAPTURE_GPU_CLOCK_COUNT, 1);
  8785. clock = (uint64_t)RREG32(RLC_GPU_CLOCK_COUNT_LSB) |
  8786. ((uint64_t)RREG32(RLC_GPU_CLOCK_COUNT_MSB) << 32ULL);
  8787. mutex_unlock(&rdev->gpu_clock_mutex);
  8788. return clock;
  8789. }
  8790. static int cik_set_uvd_clock(struct radeon_device *rdev, u32 clock,
  8791. u32 cntl_reg, u32 status_reg)
  8792. {
  8793. int r, i;
  8794. struct atom_clock_dividers dividers;
  8795. uint32_t tmp;
  8796. r = radeon_atom_get_clock_dividers(rdev, COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK,
  8797. clock, false, &dividers);
  8798. if (r)
  8799. return r;
  8800. tmp = RREG32_SMC(cntl_reg);
  8801. tmp &= ~(DCLK_DIR_CNTL_EN|DCLK_DIVIDER_MASK);
  8802. tmp |= dividers.post_divider;
  8803. WREG32_SMC(cntl_reg, tmp);
  8804. for (i = 0; i < 100; i++) {
  8805. if (RREG32_SMC(status_reg) & DCLK_STATUS)
  8806. break;
  8807. mdelay(10);
  8808. }
  8809. if (i == 100)
  8810. return -ETIMEDOUT;
  8811. return 0;
  8812. }
  8813. int cik_set_uvd_clocks(struct radeon_device *rdev, u32 vclk, u32 dclk)
  8814. {
  8815. int r = 0;
  8816. r = cik_set_uvd_clock(rdev, vclk, CG_VCLK_CNTL, CG_VCLK_STATUS);
  8817. if (r)
  8818. return r;
  8819. r = cik_set_uvd_clock(rdev, dclk, CG_DCLK_CNTL, CG_DCLK_STATUS);
  8820. return r;
  8821. }
  8822. int cik_set_vce_clocks(struct radeon_device *rdev, u32 evclk, u32 ecclk)
  8823. {
  8824. int r, i;
  8825. struct atom_clock_dividers dividers;
  8826. u32 tmp;
  8827. r = radeon_atom_get_clock_dividers(rdev, COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK,
  8828. ecclk, false, &dividers);
  8829. if (r)
  8830. return r;
  8831. for (i = 0; i < 100; i++) {
  8832. if (RREG32_SMC(CG_ECLK_STATUS) & ECLK_STATUS)
  8833. break;
  8834. mdelay(10);
  8835. }
  8836. if (i == 100)
  8837. return -ETIMEDOUT;
  8838. tmp = RREG32_SMC(CG_ECLK_CNTL);
  8839. tmp &= ~(ECLK_DIR_CNTL_EN|ECLK_DIVIDER_MASK);
  8840. tmp |= dividers.post_divider;
  8841. WREG32_SMC(CG_ECLK_CNTL, tmp);
  8842. for (i = 0; i < 100; i++) {
  8843. if (RREG32_SMC(CG_ECLK_STATUS) & ECLK_STATUS)
  8844. break;
  8845. mdelay(10);
  8846. }
  8847. if (i == 100)
  8848. return -ETIMEDOUT;
  8849. return 0;
  8850. }
  8851. static void cik_pcie_gen3_enable(struct radeon_device *rdev)
  8852. {
  8853. struct pci_dev *root = rdev->pdev->bus->self;
  8854. int bridge_pos, gpu_pos;
  8855. u32 speed_cntl, mask, current_data_rate;
  8856. int ret, i;
  8857. u16 tmp16;
  8858. if (pci_is_root_bus(rdev->pdev->bus))
  8859. return;
  8860. if (radeon_pcie_gen2 == 0)
  8861. return;
  8862. if (rdev->flags & RADEON_IS_IGP)
  8863. return;
  8864. if (!(rdev->flags & RADEON_IS_PCIE))
  8865. return;
  8866. ret = drm_pcie_get_speed_cap_mask(rdev->ddev, &mask);
  8867. if (ret != 0)
  8868. return;
  8869. if (!(mask & (DRM_PCIE_SPEED_50 | DRM_PCIE_SPEED_80)))
  8870. return;
  8871. speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  8872. current_data_rate = (speed_cntl & LC_CURRENT_DATA_RATE_MASK) >>
  8873. LC_CURRENT_DATA_RATE_SHIFT;
  8874. if (mask & DRM_PCIE_SPEED_80) {
  8875. if (current_data_rate == 2) {
  8876. DRM_INFO("PCIE gen 3 link speeds already enabled\n");
  8877. return;
  8878. }
  8879. DRM_INFO("enabling PCIE gen 3 link speeds, disable with radeon.pcie_gen2=0\n");
  8880. } else if (mask & DRM_PCIE_SPEED_50) {
  8881. if (current_data_rate == 1) {
  8882. DRM_INFO("PCIE gen 2 link speeds already enabled\n");
  8883. return;
  8884. }
  8885. DRM_INFO("enabling PCIE gen 2 link speeds, disable with radeon.pcie_gen2=0\n");
  8886. }
  8887. bridge_pos = pci_pcie_cap(root);
  8888. if (!bridge_pos)
  8889. return;
  8890. gpu_pos = pci_pcie_cap(rdev->pdev);
  8891. if (!gpu_pos)
  8892. return;
  8893. if (mask & DRM_PCIE_SPEED_80) {
  8894. /* re-try equalization if gen3 is not already enabled */
  8895. if (current_data_rate != 2) {
  8896. u16 bridge_cfg, gpu_cfg;
  8897. u16 bridge_cfg2, gpu_cfg2;
  8898. u32 max_lw, current_lw, tmp;
  8899. pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL, &bridge_cfg);
  8900. pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, &gpu_cfg);
  8901. tmp16 = bridge_cfg | PCI_EXP_LNKCTL_HAWD;
  8902. pci_write_config_word(root, bridge_pos + PCI_EXP_LNKCTL, tmp16);
  8903. tmp16 = gpu_cfg | PCI_EXP_LNKCTL_HAWD;
  8904. pci_write_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, tmp16);
  8905. tmp = RREG32_PCIE_PORT(PCIE_LC_STATUS1);
  8906. max_lw = (tmp & LC_DETECTED_LINK_WIDTH_MASK) >> LC_DETECTED_LINK_WIDTH_SHIFT;
  8907. current_lw = (tmp & LC_OPERATING_LINK_WIDTH_MASK) >> LC_OPERATING_LINK_WIDTH_SHIFT;
  8908. if (current_lw < max_lw) {
  8909. tmp = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
  8910. if (tmp & LC_RENEGOTIATION_SUPPORT) {
  8911. tmp &= ~(LC_LINK_WIDTH_MASK | LC_UPCONFIGURE_DIS);
  8912. tmp |= (max_lw << LC_LINK_WIDTH_SHIFT);
  8913. tmp |= LC_UPCONFIGURE_SUPPORT | LC_RENEGOTIATE_EN | LC_RECONFIG_NOW;
  8914. WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, tmp);
  8915. }
  8916. }
  8917. for (i = 0; i < 10; i++) {
  8918. /* check status */
  8919. pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_DEVSTA, &tmp16);
  8920. if (tmp16 & PCI_EXP_DEVSTA_TRPND)
  8921. break;
  8922. pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL, &bridge_cfg);
  8923. pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, &gpu_cfg);
  8924. pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL2, &bridge_cfg2);
  8925. pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, &gpu_cfg2);
  8926. tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL4);
  8927. tmp |= LC_SET_QUIESCE;
  8928. WREG32_PCIE_PORT(PCIE_LC_CNTL4, tmp);
  8929. tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL4);
  8930. tmp |= LC_REDO_EQ;
  8931. WREG32_PCIE_PORT(PCIE_LC_CNTL4, tmp);
  8932. mdelay(100);
  8933. /* linkctl */
  8934. pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL, &tmp16);
  8935. tmp16 &= ~PCI_EXP_LNKCTL_HAWD;
  8936. tmp16 |= (bridge_cfg & PCI_EXP_LNKCTL_HAWD);
  8937. pci_write_config_word(root, bridge_pos + PCI_EXP_LNKCTL, tmp16);
  8938. pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, &tmp16);
  8939. tmp16 &= ~PCI_EXP_LNKCTL_HAWD;
  8940. tmp16 |= (gpu_cfg & PCI_EXP_LNKCTL_HAWD);
  8941. pci_write_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, tmp16);
  8942. /* linkctl2 */
  8943. pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL2, &tmp16);
  8944. tmp16 &= ~((1 << 4) | (7 << 9));
  8945. tmp16 |= (bridge_cfg2 & ((1 << 4) | (7 << 9)));
  8946. pci_write_config_word(root, bridge_pos + PCI_EXP_LNKCTL2, tmp16);
  8947. pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, &tmp16);
  8948. tmp16 &= ~((1 << 4) | (7 << 9));
  8949. tmp16 |= (gpu_cfg2 & ((1 << 4) | (7 << 9)));
  8950. pci_write_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, tmp16);
  8951. tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL4);
  8952. tmp &= ~LC_SET_QUIESCE;
  8953. WREG32_PCIE_PORT(PCIE_LC_CNTL4, tmp);
  8954. }
  8955. }
  8956. }
  8957. /* set the link speed */
  8958. speed_cntl |= LC_FORCE_EN_SW_SPEED_CHANGE | LC_FORCE_DIS_HW_SPEED_CHANGE;
  8959. speed_cntl &= ~LC_FORCE_DIS_SW_SPEED_CHANGE;
  8960. WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
  8961. pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, &tmp16);
  8962. tmp16 &= ~0xf;
  8963. if (mask & DRM_PCIE_SPEED_80)
  8964. tmp16 |= 3; /* gen3 */
  8965. else if (mask & DRM_PCIE_SPEED_50)
  8966. tmp16 |= 2; /* gen2 */
  8967. else
  8968. tmp16 |= 1; /* gen1 */
  8969. pci_write_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, tmp16);
  8970. speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  8971. speed_cntl |= LC_INITIATE_LINK_SPEED_CHANGE;
  8972. WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
  8973. for (i = 0; i < rdev->usec_timeout; i++) {
  8974. speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  8975. if ((speed_cntl & LC_INITIATE_LINK_SPEED_CHANGE) == 0)
  8976. break;
  8977. udelay(1);
  8978. }
  8979. }
  8980. static void cik_program_aspm(struct radeon_device *rdev)
  8981. {
  8982. u32 data, orig;
  8983. bool disable_l0s = false, disable_l1 = false, disable_plloff_in_l1 = false;
  8984. bool disable_clkreq = false;
  8985. if (radeon_aspm == 0)
  8986. return;
  8987. /* XXX double check IGPs */
  8988. if (rdev->flags & RADEON_IS_IGP)
  8989. return;
  8990. if (!(rdev->flags & RADEON_IS_PCIE))
  8991. return;
  8992. orig = data = RREG32_PCIE_PORT(PCIE_LC_N_FTS_CNTL);
  8993. data &= ~LC_XMIT_N_FTS_MASK;
  8994. data |= LC_XMIT_N_FTS(0x24) | LC_XMIT_N_FTS_OVERRIDE_EN;
  8995. if (orig != data)
  8996. WREG32_PCIE_PORT(PCIE_LC_N_FTS_CNTL, data);
  8997. orig = data = RREG32_PCIE_PORT(PCIE_LC_CNTL3);
  8998. data |= LC_GO_TO_RECOVERY;
  8999. if (orig != data)
  9000. WREG32_PCIE_PORT(PCIE_LC_CNTL3, data);
  9001. orig = data = RREG32_PCIE_PORT(PCIE_P_CNTL);
  9002. data |= P_IGNORE_EDB_ERR;
  9003. if (orig != data)
  9004. WREG32_PCIE_PORT(PCIE_P_CNTL, data);
  9005. orig = data = RREG32_PCIE_PORT(PCIE_LC_CNTL);
  9006. data &= ~(LC_L0S_INACTIVITY_MASK | LC_L1_INACTIVITY_MASK);
  9007. data |= LC_PMI_TO_L1_DIS;
  9008. if (!disable_l0s)
  9009. data |= LC_L0S_INACTIVITY(7);
  9010. if (!disable_l1) {
  9011. data |= LC_L1_INACTIVITY(7);
  9012. data &= ~LC_PMI_TO_L1_DIS;
  9013. if (orig != data)
  9014. WREG32_PCIE_PORT(PCIE_LC_CNTL, data);
  9015. if (!disable_plloff_in_l1) {
  9016. bool clk_req_support;
  9017. orig = data = RREG32_PCIE_PORT(PB0_PIF_PWRDOWN_0);
  9018. data &= ~(PLL_POWER_STATE_IN_OFF_0_MASK | PLL_POWER_STATE_IN_TXS2_0_MASK);
  9019. data |= PLL_POWER_STATE_IN_OFF_0(7) | PLL_POWER_STATE_IN_TXS2_0(7);
  9020. if (orig != data)
  9021. WREG32_PCIE_PORT(PB0_PIF_PWRDOWN_0, data);
  9022. orig = data = RREG32_PCIE_PORT(PB0_PIF_PWRDOWN_1);
  9023. data &= ~(PLL_POWER_STATE_IN_OFF_1_MASK | PLL_POWER_STATE_IN_TXS2_1_MASK);
  9024. data |= PLL_POWER_STATE_IN_OFF_1(7) | PLL_POWER_STATE_IN_TXS2_1(7);
  9025. if (orig != data)
  9026. WREG32_PCIE_PORT(PB0_PIF_PWRDOWN_1, data);
  9027. orig = data = RREG32_PCIE_PORT(PB1_PIF_PWRDOWN_0);
  9028. data &= ~(PLL_POWER_STATE_IN_OFF_0_MASK | PLL_POWER_STATE_IN_TXS2_0_MASK);
  9029. data |= PLL_POWER_STATE_IN_OFF_0(7) | PLL_POWER_STATE_IN_TXS2_0(7);
  9030. if (orig != data)
  9031. WREG32_PCIE_PORT(PB1_PIF_PWRDOWN_0, data);
  9032. orig = data = RREG32_PCIE_PORT(PB1_PIF_PWRDOWN_1);
  9033. data &= ~(PLL_POWER_STATE_IN_OFF_1_MASK | PLL_POWER_STATE_IN_TXS2_1_MASK);
  9034. data |= PLL_POWER_STATE_IN_OFF_1(7) | PLL_POWER_STATE_IN_TXS2_1(7);
  9035. if (orig != data)
  9036. WREG32_PCIE_PORT(PB1_PIF_PWRDOWN_1, data);
  9037. orig = data = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
  9038. data &= ~LC_DYN_LANES_PWR_STATE_MASK;
  9039. data |= LC_DYN_LANES_PWR_STATE(3);
  9040. if (orig != data)
  9041. WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, data);
  9042. if (!disable_clkreq &&
  9043. !pci_is_root_bus(rdev->pdev->bus)) {
  9044. struct pci_dev *root = rdev->pdev->bus->self;
  9045. u32 lnkcap;
  9046. clk_req_support = false;
  9047. pcie_capability_read_dword(root, PCI_EXP_LNKCAP, &lnkcap);
  9048. if (lnkcap & PCI_EXP_LNKCAP_CLKPM)
  9049. clk_req_support = true;
  9050. } else {
  9051. clk_req_support = false;
  9052. }
  9053. if (clk_req_support) {
  9054. orig = data = RREG32_PCIE_PORT(PCIE_LC_CNTL2);
  9055. data |= LC_ALLOW_PDWN_IN_L1 | LC_ALLOW_PDWN_IN_L23;
  9056. if (orig != data)
  9057. WREG32_PCIE_PORT(PCIE_LC_CNTL2, data);
  9058. orig = data = RREG32_SMC(THM_CLK_CNTL);
  9059. data &= ~(CMON_CLK_SEL_MASK | TMON_CLK_SEL_MASK);
  9060. data |= CMON_CLK_SEL(1) | TMON_CLK_SEL(1);
  9061. if (orig != data)
  9062. WREG32_SMC(THM_CLK_CNTL, data);
  9063. orig = data = RREG32_SMC(MISC_CLK_CTRL);
  9064. data &= ~(DEEP_SLEEP_CLK_SEL_MASK | ZCLK_SEL_MASK);
  9065. data |= DEEP_SLEEP_CLK_SEL(1) | ZCLK_SEL(1);
  9066. if (orig != data)
  9067. WREG32_SMC(MISC_CLK_CTRL, data);
  9068. orig = data = RREG32_SMC(CG_CLKPIN_CNTL);
  9069. data &= ~BCLK_AS_XCLK;
  9070. if (orig != data)
  9071. WREG32_SMC(CG_CLKPIN_CNTL, data);
  9072. orig = data = RREG32_SMC(CG_CLKPIN_CNTL_2);
  9073. data &= ~FORCE_BIF_REFCLK_EN;
  9074. if (orig != data)
  9075. WREG32_SMC(CG_CLKPIN_CNTL_2, data);
  9076. orig = data = RREG32_SMC(MPLL_BYPASSCLK_SEL);
  9077. data &= ~MPLL_CLKOUT_SEL_MASK;
  9078. data |= MPLL_CLKOUT_SEL(4);
  9079. if (orig != data)
  9080. WREG32_SMC(MPLL_BYPASSCLK_SEL, data);
  9081. }
  9082. }
  9083. } else {
  9084. if (orig != data)
  9085. WREG32_PCIE_PORT(PCIE_LC_CNTL, data);
  9086. }
  9087. orig = data = RREG32_PCIE_PORT(PCIE_CNTL2);
  9088. data |= SLV_MEM_LS_EN | MST_MEM_LS_EN | REPLAY_MEM_LS_EN;
  9089. if (orig != data)
  9090. WREG32_PCIE_PORT(PCIE_CNTL2, data);
  9091. if (!disable_l0s) {
  9092. data = RREG32_PCIE_PORT(PCIE_LC_N_FTS_CNTL);
  9093. if((data & LC_N_FTS_MASK) == LC_N_FTS_MASK) {
  9094. data = RREG32_PCIE_PORT(PCIE_LC_STATUS1);
  9095. if ((data & LC_REVERSE_XMIT) && (data & LC_REVERSE_RCVR)) {
  9096. orig = data = RREG32_PCIE_PORT(PCIE_LC_CNTL);
  9097. data &= ~LC_L0S_INACTIVITY_MASK;
  9098. if (orig != data)
  9099. WREG32_PCIE_PORT(PCIE_LC_CNTL, data);
  9100. }
  9101. }
  9102. }
  9103. }