si.c 201 KB

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