si.c 199 KB

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