cik.c 246 KB

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