si.c 200 KB

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