si.c 206 KB

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