evergreen.c 178 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904
  1. /*
  2. * Copyright 2010 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 <drm/drmP.h>
  27. #include "radeon.h"
  28. #include "radeon_asic.h"
  29. #include "radeon_audio.h"
  30. #include <drm/radeon_drm.h>
  31. #include "evergreend.h"
  32. #include "atom.h"
  33. #include "avivod.h"
  34. #include "evergreen_reg.h"
  35. #include "evergreen_blit_shaders.h"
  36. #include "radeon_ucode.h"
  37. /*
  38. * Indirect registers accessor
  39. */
  40. u32 eg_cg_rreg(struct radeon_device *rdev, u32 reg)
  41. {
  42. unsigned long flags;
  43. u32 r;
  44. spin_lock_irqsave(&rdev->cg_idx_lock, flags);
  45. WREG32(EVERGREEN_CG_IND_ADDR, ((reg) & 0xffff));
  46. r = RREG32(EVERGREEN_CG_IND_DATA);
  47. spin_unlock_irqrestore(&rdev->cg_idx_lock, flags);
  48. return r;
  49. }
  50. void eg_cg_wreg(struct radeon_device *rdev, u32 reg, u32 v)
  51. {
  52. unsigned long flags;
  53. spin_lock_irqsave(&rdev->cg_idx_lock, flags);
  54. WREG32(EVERGREEN_CG_IND_ADDR, ((reg) & 0xffff));
  55. WREG32(EVERGREEN_CG_IND_DATA, (v));
  56. spin_unlock_irqrestore(&rdev->cg_idx_lock, flags);
  57. }
  58. u32 eg_pif_phy0_rreg(struct radeon_device *rdev, u32 reg)
  59. {
  60. unsigned long flags;
  61. u32 r;
  62. spin_lock_irqsave(&rdev->pif_idx_lock, flags);
  63. WREG32(EVERGREEN_PIF_PHY0_INDEX, ((reg) & 0xffff));
  64. r = RREG32(EVERGREEN_PIF_PHY0_DATA);
  65. spin_unlock_irqrestore(&rdev->pif_idx_lock, flags);
  66. return r;
  67. }
  68. void eg_pif_phy0_wreg(struct radeon_device *rdev, u32 reg, u32 v)
  69. {
  70. unsigned long flags;
  71. spin_lock_irqsave(&rdev->pif_idx_lock, flags);
  72. WREG32(EVERGREEN_PIF_PHY0_INDEX, ((reg) & 0xffff));
  73. WREG32(EVERGREEN_PIF_PHY0_DATA, (v));
  74. spin_unlock_irqrestore(&rdev->pif_idx_lock, flags);
  75. }
  76. u32 eg_pif_phy1_rreg(struct radeon_device *rdev, u32 reg)
  77. {
  78. unsigned long flags;
  79. u32 r;
  80. spin_lock_irqsave(&rdev->pif_idx_lock, flags);
  81. WREG32(EVERGREEN_PIF_PHY1_INDEX, ((reg) & 0xffff));
  82. r = RREG32(EVERGREEN_PIF_PHY1_DATA);
  83. spin_unlock_irqrestore(&rdev->pif_idx_lock, flags);
  84. return r;
  85. }
  86. void eg_pif_phy1_wreg(struct radeon_device *rdev, u32 reg, u32 v)
  87. {
  88. unsigned long flags;
  89. spin_lock_irqsave(&rdev->pif_idx_lock, flags);
  90. WREG32(EVERGREEN_PIF_PHY1_INDEX, ((reg) & 0xffff));
  91. WREG32(EVERGREEN_PIF_PHY1_DATA, (v));
  92. spin_unlock_irqrestore(&rdev->pif_idx_lock, flags);
  93. }
  94. static const u32 crtc_offsets[6] =
  95. {
  96. EVERGREEN_CRTC0_REGISTER_OFFSET,
  97. EVERGREEN_CRTC1_REGISTER_OFFSET,
  98. EVERGREEN_CRTC2_REGISTER_OFFSET,
  99. EVERGREEN_CRTC3_REGISTER_OFFSET,
  100. EVERGREEN_CRTC4_REGISTER_OFFSET,
  101. EVERGREEN_CRTC5_REGISTER_OFFSET
  102. };
  103. #include "clearstate_evergreen.h"
  104. static const u32 sumo_rlc_save_restore_register_list[] =
  105. {
  106. 0x98fc,
  107. 0x9830,
  108. 0x9834,
  109. 0x9838,
  110. 0x9870,
  111. 0x9874,
  112. 0x8a14,
  113. 0x8b24,
  114. 0x8bcc,
  115. 0x8b10,
  116. 0x8d00,
  117. 0x8d04,
  118. 0x8c00,
  119. 0x8c04,
  120. 0x8c08,
  121. 0x8c0c,
  122. 0x8d8c,
  123. 0x8c20,
  124. 0x8c24,
  125. 0x8c28,
  126. 0x8c18,
  127. 0x8c1c,
  128. 0x8cf0,
  129. 0x8e2c,
  130. 0x8e38,
  131. 0x8c30,
  132. 0x9508,
  133. 0x9688,
  134. 0x9608,
  135. 0x960c,
  136. 0x9610,
  137. 0x9614,
  138. 0x88c4,
  139. 0x88d4,
  140. 0xa008,
  141. 0x900c,
  142. 0x9100,
  143. 0x913c,
  144. 0x98f8,
  145. 0x98f4,
  146. 0x9b7c,
  147. 0x3f8c,
  148. 0x8950,
  149. 0x8954,
  150. 0x8a18,
  151. 0x8b28,
  152. 0x9144,
  153. 0x9148,
  154. 0x914c,
  155. 0x3f90,
  156. 0x3f94,
  157. 0x915c,
  158. 0x9160,
  159. 0x9178,
  160. 0x917c,
  161. 0x9180,
  162. 0x918c,
  163. 0x9190,
  164. 0x9194,
  165. 0x9198,
  166. 0x919c,
  167. 0x91a8,
  168. 0x91ac,
  169. 0x91b0,
  170. 0x91b4,
  171. 0x91b8,
  172. 0x91c4,
  173. 0x91c8,
  174. 0x91cc,
  175. 0x91d0,
  176. 0x91d4,
  177. 0x91e0,
  178. 0x91e4,
  179. 0x91ec,
  180. 0x91f0,
  181. 0x91f4,
  182. 0x9200,
  183. 0x9204,
  184. 0x929c,
  185. 0x9150,
  186. 0x802c,
  187. };
  188. static void evergreen_gpu_init(struct radeon_device *rdev);
  189. void evergreen_fini(struct radeon_device *rdev);
  190. void evergreen_pcie_gen2_enable(struct radeon_device *rdev);
  191. void evergreen_program_aspm(struct radeon_device *rdev);
  192. extern void cayman_cp_int_cntl_setup(struct radeon_device *rdev,
  193. int ring, u32 cp_int_cntl);
  194. extern void cayman_vm_decode_fault(struct radeon_device *rdev,
  195. u32 status, u32 addr);
  196. void cik_init_cp_pg_table(struct radeon_device *rdev);
  197. extern u32 si_get_csb_size(struct radeon_device *rdev);
  198. extern void si_get_csb_buffer(struct radeon_device *rdev, volatile u32 *buffer);
  199. extern u32 cik_get_csb_size(struct radeon_device *rdev);
  200. extern void cik_get_csb_buffer(struct radeon_device *rdev, volatile u32 *buffer);
  201. extern void rv770_set_clk_bypass_mode(struct radeon_device *rdev);
  202. static const u32 evergreen_golden_registers[] =
  203. {
  204. 0x3f90, 0xffff0000, 0xff000000,
  205. 0x9148, 0xffff0000, 0xff000000,
  206. 0x3f94, 0xffff0000, 0xff000000,
  207. 0x914c, 0xffff0000, 0xff000000,
  208. 0x9b7c, 0xffffffff, 0x00000000,
  209. 0x8a14, 0xffffffff, 0x00000007,
  210. 0x8b10, 0xffffffff, 0x00000000,
  211. 0x960c, 0xffffffff, 0x54763210,
  212. 0x88c4, 0xffffffff, 0x000000c2,
  213. 0x88d4, 0xffffffff, 0x00000010,
  214. 0x8974, 0xffffffff, 0x00000000,
  215. 0xc78, 0x00000080, 0x00000080,
  216. 0x5eb4, 0xffffffff, 0x00000002,
  217. 0x5e78, 0xffffffff, 0x001000f0,
  218. 0x6104, 0x01000300, 0x00000000,
  219. 0x5bc0, 0x00300000, 0x00000000,
  220. 0x7030, 0xffffffff, 0x00000011,
  221. 0x7c30, 0xffffffff, 0x00000011,
  222. 0x10830, 0xffffffff, 0x00000011,
  223. 0x11430, 0xffffffff, 0x00000011,
  224. 0x12030, 0xffffffff, 0x00000011,
  225. 0x12c30, 0xffffffff, 0x00000011,
  226. 0xd02c, 0xffffffff, 0x08421000,
  227. 0x240c, 0xffffffff, 0x00000380,
  228. 0x8b24, 0xffffffff, 0x00ff0fff,
  229. 0x28a4c, 0x06000000, 0x06000000,
  230. 0x10c, 0x00000001, 0x00000001,
  231. 0x8d00, 0xffffffff, 0x100e4848,
  232. 0x8d04, 0xffffffff, 0x00164745,
  233. 0x8c00, 0xffffffff, 0xe4000003,
  234. 0x8c04, 0xffffffff, 0x40600060,
  235. 0x8c08, 0xffffffff, 0x001c001c,
  236. 0x8cf0, 0xffffffff, 0x08e00620,
  237. 0x8c20, 0xffffffff, 0x00800080,
  238. 0x8c24, 0xffffffff, 0x00800080,
  239. 0x8c18, 0xffffffff, 0x20202078,
  240. 0x8c1c, 0xffffffff, 0x00001010,
  241. 0x28350, 0xffffffff, 0x00000000,
  242. 0xa008, 0xffffffff, 0x00010000,
  243. 0x5c4, 0xffffffff, 0x00000001,
  244. 0x9508, 0xffffffff, 0x00000002,
  245. 0x913c, 0x0000000f, 0x0000000a
  246. };
  247. static const u32 evergreen_golden_registers2[] =
  248. {
  249. 0x2f4c, 0xffffffff, 0x00000000,
  250. 0x54f4, 0xffffffff, 0x00000000,
  251. 0x54f0, 0xffffffff, 0x00000000,
  252. 0x5498, 0xffffffff, 0x00000000,
  253. 0x549c, 0xffffffff, 0x00000000,
  254. 0x5494, 0xffffffff, 0x00000000,
  255. 0x53cc, 0xffffffff, 0x00000000,
  256. 0x53c8, 0xffffffff, 0x00000000,
  257. 0x53c4, 0xffffffff, 0x00000000,
  258. 0x53c0, 0xffffffff, 0x00000000,
  259. 0x53bc, 0xffffffff, 0x00000000,
  260. 0x53b8, 0xffffffff, 0x00000000,
  261. 0x53b4, 0xffffffff, 0x00000000,
  262. 0x53b0, 0xffffffff, 0x00000000
  263. };
  264. static const u32 cypress_mgcg_init[] =
  265. {
  266. 0x802c, 0xffffffff, 0xc0000000,
  267. 0x5448, 0xffffffff, 0x00000100,
  268. 0x55e4, 0xffffffff, 0x00000100,
  269. 0x160c, 0xffffffff, 0x00000100,
  270. 0x5644, 0xffffffff, 0x00000100,
  271. 0xc164, 0xffffffff, 0x00000100,
  272. 0x8a18, 0xffffffff, 0x00000100,
  273. 0x897c, 0xffffffff, 0x06000100,
  274. 0x8b28, 0xffffffff, 0x00000100,
  275. 0x9144, 0xffffffff, 0x00000100,
  276. 0x9a60, 0xffffffff, 0x00000100,
  277. 0x9868, 0xffffffff, 0x00000100,
  278. 0x8d58, 0xffffffff, 0x00000100,
  279. 0x9510, 0xffffffff, 0x00000100,
  280. 0x949c, 0xffffffff, 0x00000100,
  281. 0x9654, 0xffffffff, 0x00000100,
  282. 0x9030, 0xffffffff, 0x00000100,
  283. 0x9034, 0xffffffff, 0x00000100,
  284. 0x9038, 0xffffffff, 0x00000100,
  285. 0x903c, 0xffffffff, 0x00000100,
  286. 0x9040, 0xffffffff, 0x00000100,
  287. 0xa200, 0xffffffff, 0x00000100,
  288. 0xa204, 0xffffffff, 0x00000100,
  289. 0xa208, 0xffffffff, 0x00000100,
  290. 0xa20c, 0xffffffff, 0x00000100,
  291. 0x971c, 0xffffffff, 0x00000100,
  292. 0x977c, 0xffffffff, 0x00000100,
  293. 0x3f80, 0xffffffff, 0x00000100,
  294. 0xa210, 0xffffffff, 0x00000100,
  295. 0xa214, 0xffffffff, 0x00000100,
  296. 0x4d8, 0xffffffff, 0x00000100,
  297. 0x9784, 0xffffffff, 0x00000100,
  298. 0x9698, 0xffffffff, 0x00000100,
  299. 0x4d4, 0xffffffff, 0x00000200,
  300. 0x30cc, 0xffffffff, 0x00000100,
  301. 0xd0c0, 0xffffffff, 0xff000100,
  302. 0x802c, 0xffffffff, 0x40000000,
  303. 0x915c, 0xffffffff, 0x00010000,
  304. 0x9160, 0xffffffff, 0x00030002,
  305. 0x9178, 0xffffffff, 0x00070000,
  306. 0x917c, 0xffffffff, 0x00030002,
  307. 0x9180, 0xffffffff, 0x00050004,
  308. 0x918c, 0xffffffff, 0x00010006,
  309. 0x9190, 0xffffffff, 0x00090008,
  310. 0x9194, 0xffffffff, 0x00070000,
  311. 0x9198, 0xffffffff, 0x00030002,
  312. 0x919c, 0xffffffff, 0x00050004,
  313. 0x91a8, 0xffffffff, 0x00010006,
  314. 0x91ac, 0xffffffff, 0x00090008,
  315. 0x91b0, 0xffffffff, 0x00070000,
  316. 0x91b4, 0xffffffff, 0x00030002,
  317. 0x91b8, 0xffffffff, 0x00050004,
  318. 0x91c4, 0xffffffff, 0x00010006,
  319. 0x91c8, 0xffffffff, 0x00090008,
  320. 0x91cc, 0xffffffff, 0x00070000,
  321. 0x91d0, 0xffffffff, 0x00030002,
  322. 0x91d4, 0xffffffff, 0x00050004,
  323. 0x91e0, 0xffffffff, 0x00010006,
  324. 0x91e4, 0xffffffff, 0x00090008,
  325. 0x91e8, 0xffffffff, 0x00000000,
  326. 0x91ec, 0xffffffff, 0x00070000,
  327. 0x91f0, 0xffffffff, 0x00030002,
  328. 0x91f4, 0xffffffff, 0x00050004,
  329. 0x9200, 0xffffffff, 0x00010006,
  330. 0x9204, 0xffffffff, 0x00090008,
  331. 0x9208, 0xffffffff, 0x00070000,
  332. 0x920c, 0xffffffff, 0x00030002,
  333. 0x9210, 0xffffffff, 0x00050004,
  334. 0x921c, 0xffffffff, 0x00010006,
  335. 0x9220, 0xffffffff, 0x00090008,
  336. 0x9224, 0xffffffff, 0x00070000,
  337. 0x9228, 0xffffffff, 0x00030002,
  338. 0x922c, 0xffffffff, 0x00050004,
  339. 0x9238, 0xffffffff, 0x00010006,
  340. 0x923c, 0xffffffff, 0x00090008,
  341. 0x9240, 0xffffffff, 0x00070000,
  342. 0x9244, 0xffffffff, 0x00030002,
  343. 0x9248, 0xffffffff, 0x00050004,
  344. 0x9254, 0xffffffff, 0x00010006,
  345. 0x9258, 0xffffffff, 0x00090008,
  346. 0x925c, 0xffffffff, 0x00070000,
  347. 0x9260, 0xffffffff, 0x00030002,
  348. 0x9264, 0xffffffff, 0x00050004,
  349. 0x9270, 0xffffffff, 0x00010006,
  350. 0x9274, 0xffffffff, 0x00090008,
  351. 0x9278, 0xffffffff, 0x00070000,
  352. 0x927c, 0xffffffff, 0x00030002,
  353. 0x9280, 0xffffffff, 0x00050004,
  354. 0x928c, 0xffffffff, 0x00010006,
  355. 0x9290, 0xffffffff, 0x00090008,
  356. 0x9294, 0xffffffff, 0x00000000,
  357. 0x929c, 0xffffffff, 0x00000001,
  358. 0x802c, 0xffffffff, 0x40010000,
  359. 0x915c, 0xffffffff, 0x00010000,
  360. 0x9160, 0xffffffff, 0x00030002,
  361. 0x9178, 0xffffffff, 0x00070000,
  362. 0x917c, 0xffffffff, 0x00030002,
  363. 0x9180, 0xffffffff, 0x00050004,
  364. 0x918c, 0xffffffff, 0x00010006,
  365. 0x9190, 0xffffffff, 0x00090008,
  366. 0x9194, 0xffffffff, 0x00070000,
  367. 0x9198, 0xffffffff, 0x00030002,
  368. 0x919c, 0xffffffff, 0x00050004,
  369. 0x91a8, 0xffffffff, 0x00010006,
  370. 0x91ac, 0xffffffff, 0x00090008,
  371. 0x91b0, 0xffffffff, 0x00070000,
  372. 0x91b4, 0xffffffff, 0x00030002,
  373. 0x91b8, 0xffffffff, 0x00050004,
  374. 0x91c4, 0xffffffff, 0x00010006,
  375. 0x91c8, 0xffffffff, 0x00090008,
  376. 0x91cc, 0xffffffff, 0x00070000,
  377. 0x91d0, 0xffffffff, 0x00030002,
  378. 0x91d4, 0xffffffff, 0x00050004,
  379. 0x91e0, 0xffffffff, 0x00010006,
  380. 0x91e4, 0xffffffff, 0x00090008,
  381. 0x91e8, 0xffffffff, 0x00000000,
  382. 0x91ec, 0xffffffff, 0x00070000,
  383. 0x91f0, 0xffffffff, 0x00030002,
  384. 0x91f4, 0xffffffff, 0x00050004,
  385. 0x9200, 0xffffffff, 0x00010006,
  386. 0x9204, 0xffffffff, 0x00090008,
  387. 0x9208, 0xffffffff, 0x00070000,
  388. 0x920c, 0xffffffff, 0x00030002,
  389. 0x9210, 0xffffffff, 0x00050004,
  390. 0x921c, 0xffffffff, 0x00010006,
  391. 0x9220, 0xffffffff, 0x00090008,
  392. 0x9224, 0xffffffff, 0x00070000,
  393. 0x9228, 0xffffffff, 0x00030002,
  394. 0x922c, 0xffffffff, 0x00050004,
  395. 0x9238, 0xffffffff, 0x00010006,
  396. 0x923c, 0xffffffff, 0x00090008,
  397. 0x9240, 0xffffffff, 0x00070000,
  398. 0x9244, 0xffffffff, 0x00030002,
  399. 0x9248, 0xffffffff, 0x00050004,
  400. 0x9254, 0xffffffff, 0x00010006,
  401. 0x9258, 0xffffffff, 0x00090008,
  402. 0x925c, 0xffffffff, 0x00070000,
  403. 0x9260, 0xffffffff, 0x00030002,
  404. 0x9264, 0xffffffff, 0x00050004,
  405. 0x9270, 0xffffffff, 0x00010006,
  406. 0x9274, 0xffffffff, 0x00090008,
  407. 0x9278, 0xffffffff, 0x00070000,
  408. 0x927c, 0xffffffff, 0x00030002,
  409. 0x9280, 0xffffffff, 0x00050004,
  410. 0x928c, 0xffffffff, 0x00010006,
  411. 0x9290, 0xffffffff, 0x00090008,
  412. 0x9294, 0xffffffff, 0x00000000,
  413. 0x929c, 0xffffffff, 0x00000001,
  414. 0x802c, 0xffffffff, 0xc0000000
  415. };
  416. static const u32 redwood_mgcg_init[] =
  417. {
  418. 0x802c, 0xffffffff, 0xc0000000,
  419. 0x5448, 0xffffffff, 0x00000100,
  420. 0x55e4, 0xffffffff, 0x00000100,
  421. 0x160c, 0xffffffff, 0x00000100,
  422. 0x5644, 0xffffffff, 0x00000100,
  423. 0xc164, 0xffffffff, 0x00000100,
  424. 0x8a18, 0xffffffff, 0x00000100,
  425. 0x897c, 0xffffffff, 0x06000100,
  426. 0x8b28, 0xffffffff, 0x00000100,
  427. 0x9144, 0xffffffff, 0x00000100,
  428. 0x9a60, 0xffffffff, 0x00000100,
  429. 0x9868, 0xffffffff, 0x00000100,
  430. 0x8d58, 0xffffffff, 0x00000100,
  431. 0x9510, 0xffffffff, 0x00000100,
  432. 0x949c, 0xffffffff, 0x00000100,
  433. 0x9654, 0xffffffff, 0x00000100,
  434. 0x9030, 0xffffffff, 0x00000100,
  435. 0x9034, 0xffffffff, 0x00000100,
  436. 0x9038, 0xffffffff, 0x00000100,
  437. 0x903c, 0xffffffff, 0x00000100,
  438. 0x9040, 0xffffffff, 0x00000100,
  439. 0xa200, 0xffffffff, 0x00000100,
  440. 0xa204, 0xffffffff, 0x00000100,
  441. 0xa208, 0xffffffff, 0x00000100,
  442. 0xa20c, 0xffffffff, 0x00000100,
  443. 0x971c, 0xffffffff, 0x00000100,
  444. 0x977c, 0xffffffff, 0x00000100,
  445. 0x3f80, 0xffffffff, 0x00000100,
  446. 0xa210, 0xffffffff, 0x00000100,
  447. 0xa214, 0xffffffff, 0x00000100,
  448. 0x4d8, 0xffffffff, 0x00000100,
  449. 0x9784, 0xffffffff, 0x00000100,
  450. 0x9698, 0xffffffff, 0x00000100,
  451. 0x4d4, 0xffffffff, 0x00000200,
  452. 0x30cc, 0xffffffff, 0x00000100,
  453. 0xd0c0, 0xffffffff, 0xff000100,
  454. 0x802c, 0xffffffff, 0x40000000,
  455. 0x915c, 0xffffffff, 0x00010000,
  456. 0x9160, 0xffffffff, 0x00030002,
  457. 0x9178, 0xffffffff, 0x00070000,
  458. 0x917c, 0xffffffff, 0x00030002,
  459. 0x9180, 0xffffffff, 0x00050004,
  460. 0x918c, 0xffffffff, 0x00010006,
  461. 0x9190, 0xffffffff, 0x00090008,
  462. 0x9194, 0xffffffff, 0x00070000,
  463. 0x9198, 0xffffffff, 0x00030002,
  464. 0x919c, 0xffffffff, 0x00050004,
  465. 0x91a8, 0xffffffff, 0x00010006,
  466. 0x91ac, 0xffffffff, 0x00090008,
  467. 0x91b0, 0xffffffff, 0x00070000,
  468. 0x91b4, 0xffffffff, 0x00030002,
  469. 0x91b8, 0xffffffff, 0x00050004,
  470. 0x91c4, 0xffffffff, 0x00010006,
  471. 0x91c8, 0xffffffff, 0x00090008,
  472. 0x91cc, 0xffffffff, 0x00070000,
  473. 0x91d0, 0xffffffff, 0x00030002,
  474. 0x91d4, 0xffffffff, 0x00050004,
  475. 0x91e0, 0xffffffff, 0x00010006,
  476. 0x91e4, 0xffffffff, 0x00090008,
  477. 0x91e8, 0xffffffff, 0x00000000,
  478. 0x91ec, 0xffffffff, 0x00070000,
  479. 0x91f0, 0xffffffff, 0x00030002,
  480. 0x91f4, 0xffffffff, 0x00050004,
  481. 0x9200, 0xffffffff, 0x00010006,
  482. 0x9204, 0xffffffff, 0x00090008,
  483. 0x9294, 0xffffffff, 0x00000000,
  484. 0x929c, 0xffffffff, 0x00000001,
  485. 0x802c, 0xffffffff, 0xc0000000
  486. };
  487. static const u32 cedar_golden_registers[] =
  488. {
  489. 0x3f90, 0xffff0000, 0xff000000,
  490. 0x9148, 0xffff0000, 0xff000000,
  491. 0x3f94, 0xffff0000, 0xff000000,
  492. 0x914c, 0xffff0000, 0xff000000,
  493. 0x9b7c, 0xffffffff, 0x00000000,
  494. 0x8a14, 0xffffffff, 0x00000007,
  495. 0x8b10, 0xffffffff, 0x00000000,
  496. 0x960c, 0xffffffff, 0x54763210,
  497. 0x88c4, 0xffffffff, 0x000000c2,
  498. 0x88d4, 0xffffffff, 0x00000000,
  499. 0x8974, 0xffffffff, 0x00000000,
  500. 0xc78, 0x00000080, 0x00000080,
  501. 0x5eb4, 0xffffffff, 0x00000002,
  502. 0x5e78, 0xffffffff, 0x001000f0,
  503. 0x6104, 0x01000300, 0x00000000,
  504. 0x5bc0, 0x00300000, 0x00000000,
  505. 0x7030, 0xffffffff, 0x00000011,
  506. 0x7c30, 0xffffffff, 0x00000011,
  507. 0x10830, 0xffffffff, 0x00000011,
  508. 0x11430, 0xffffffff, 0x00000011,
  509. 0xd02c, 0xffffffff, 0x08421000,
  510. 0x240c, 0xffffffff, 0x00000380,
  511. 0x8b24, 0xffffffff, 0x00ff0fff,
  512. 0x28a4c, 0x06000000, 0x06000000,
  513. 0x10c, 0x00000001, 0x00000001,
  514. 0x8d00, 0xffffffff, 0x100e4848,
  515. 0x8d04, 0xffffffff, 0x00164745,
  516. 0x8c00, 0xffffffff, 0xe4000003,
  517. 0x8c04, 0xffffffff, 0x40600060,
  518. 0x8c08, 0xffffffff, 0x001c001c,
  519. 0x8cf0, 0xffffffff, 0x08e00410,
  520. 0x8c20, 0xffffffff, 0x00800080,
  521. 0x8c24, 0xffffffff, 0x00800080,
  522. 0x8c18, 0xffffffff, 0x20202078,
  523. 0x8c1c, 0xffffffff, 0x00001010,
  524. 0x28350, 0xffffffff, 0x00000000,
  525. 0xa008, 0xffffffff, 0x00010000,
  526. 0x5c4, 0xffffffff, 0x00000001,
  527. 0x9508, 0xffffffff, 0x00000002
  528. };
  529. static const u32 cedar_mgcg_init[] =
  530. {
  531. 0x802c, 0xffffffff, 0xc0000000,
  532. 0x5448, 0xffffffff, 0x00000100,
  533. 0x55e4, 0xffffffff, 0x00000100,
  534. 0x160c, 0xffffffff, 0x00000100,
  535. 0x5644, 0xffffffff, 0x00000100,
  536. 0xc164, 0xffffffff, 0x00000100,
  537. 0x8a18, 0xffffffff, 0x00000100,
  538. 0x897c, 0xffffffff, 0x06000100,
  539. 0x8b28, 0xffffffff, 0x00000100,
  540. 0x9144, 0xffffffff, 0x00000100,
  541. 0x9a60, 0xffffffff, 0x00000100,
  542. 0x9868, 0xffffffff, 0x00000100,
  543. 0x8d58, 0xffffffff, 0x00000100,
  544. 0x9510, 0xffffffff, 0x00000100,
  545. 0x949c, 0xffffffff, 0x00000100,
  546. 0x9654, 0xffffffff, 0x00000100,
  547. 0x9030, 0xffffffff, 0x00000100,
  548. 0x9034, 0xffffffff, 0x00000100,
  549. 0x9038, 0xffffffff, 0x00000100,
  550. 0x903c, 0xffffffff, 0x00000100,
  551. 0x9040, 0xffffffff, 0x00000100,
  552. 0xa200, 0xffffffff, 0x00000100,
  553. 0xa204, 0xffffffff, 0x00000100,
  554. 0xa208, 0xffffffff, 0x00000100,
  555. 0xa20c, 0xffffffff, 0x00000100,
  556. 0x971c, 0xffffffff, 0x00000100,
  557. 0x977c, 0xffffffff, 0x00000100,
  558. 0x3f80, 0xffffffff, 0x00000100,
  559. 0xa210, 0xffffffff, 0x00000100,
  560. 0xa214, 0xffffffff, 0x00000100,
  561. 0x4d8, 0xffffffff, 0x00000100,
  562. 0x9784, 0xffffffff, 0x00000100,
  563. 0x9698, 0xffffffff, 0x00000100,
  564. 0x4d4, 0xffffffff, 0x00000200,
  565. 0x30cc, 0xffffffff, 0x00000100,
  566. 0xd0c0, 0xffffffff, 0xff000100,
  567. 0x802c, 0xffffffff, 0x40000000,
  568. 0x915c, 0xffffffff, 0x00010000,
  569. 0x9178, 0xffffffff, 0x00050000,
  570. 0x917c, 0xffffffff, 0x00030002,
  571. 0x918c, 0xffffffff, 0x00010004,
  572. 0x9190, 0xffffffff, 0x00070006,
  573. 0x9194, 0xffffffff, 0x00050000,
  574. 0x9198, 0xffffffff, 0x00030002,
  575. 0x91a8, 0xffffffff, 0x00010004,
  576. 0x91ac, 0xffffffff, 0x00070006,
  577. 0x91e8, 0xffffffff, 0x00000000,
  578. 0x9294, 0xffffffff, 0x00000000,
  579. 0x929c, 0xffffffff, 0x00000001,
  580. 0x802c, 0xffffffff, 0xc0000000
  581. };
  582. static const u32 juniper_mgcg_init[] =
  583. {
  584. 0x802c, 0xffffffff, 0xc0000000,
  585. 0x5448, 0xffffffff, 0x00000100,
  586. 0x55e4, 0xffffffff, 0x00000100,
  587. 0x160c, 0xffffffff, 0x00000100,
  588. 0x5644, 0xffffffff, 0x00000100,
  589. 0xc164, 0xffffffff, 0x00000100,
  590. 0x8a18, 0xffffffff, 0x00000100,
  591. 0x897c, 0xffffffff, 0x06000100,
  592. 0x8b28, 0xffffffff, 0x00000100,
  593. 0x9144, 0xffffffff, 0x00000100,
  594. 0x9a60, 0xffffffff, 0x00000100,
  595. 0x9868, 0xffffffff, 0x00000100,
  596. 0x8d58, 0xffffffff, 0x00000100,
  597. 0x9510, 0xffffffff, 0x00000100,
  598. 0x949c, 0xffffffff, 0x00000100,
  599. 0x9654, 0xffffffff, 0x00000100,
  600. 0x9030, 0xffffffff, 0x00000100,
  601. 0x9034, 0xffffffff, 0x00000100,
  602. 0x9038, 0xffffffff, 0x00000100,
  603. 0x903c, 0xffffffff, 0x00000100,
  604. 0x9040, 0xffffffff, 0x00000100,
  605. 0xa200, 0xffffffff, 0x00000100,
  606. 0xa204, 0xffffffff, 0x00000100,
  607. 0xa208, 0xffffffff, 0x00000100,
  608. 0xa20c, 0xffffffff, 0x00000100,
  609. 0x971c, 0xffffffff, 0x00000100,
  610. 0xd0c0, 0xffffffff, 0xff000100,
  611. 0x802c, 0xffffffff, 0x40000000,
  612. 0x915c, 0xffffffff, 0x00010000,
  613. 0x9160, 0xffffffff, 0x00030002,
  614. 0x9178, 0xffffffff, 0x00070000,
  615. 0x917c, 0xffffffff, 0x00030002,
  616. 0x9180, 0xffffffff, 0x00050004,
  617. 0x918c, 0xffffffff, 0x00010006,
  618. 0x9190, 0xffffffff, 0x00090008,
  619. 0x9194, 0xffffffff, 0x00070000,
  620. 0x9198, 0xffffffff, 0x00030002,
  621. 0x919c, 0xffffffff, 0x00050004,
  622. 0x91a8, 0xffffffff, 0x00010006,
  623. 0x91ac, 0xffffffff, 0x00090008,
  624. 0x91b0, 0xffffffff, 0x00070000,
  625. 0x91b4, 0xffffffff, 0x00030002,
  626. 0x91b8, 0xffffffff, 0x00050004,
  627. 0x91c4, 0xffffffff, 0x00010006,
  628. 0x91c8, 0xffffffff, 0x00090008,
  629. 0x91cc, 0xffffffff, 0x00070000,
  630. 0x91d0, 0xffffffff, 0x00030002,
  631. 0x91d4, 0xffffffff, 0x00050004,
  632. 0x91e0, 0xffffffff, 0x00010006,
  633. 0x91e4, 0xffffffff, 0x00090008,
  634. 0x91e8, 0xffffffff, 0x00000000,
  635. 0x91ec, 0xffffffff, 0x00070000,
  636. 0x91f0, 0xffffffff, 0x00030002,
  637. 0x91f4, 0xffffffff, 0x00050004,
  638. 0x9200, 0xffffffff, 0x00010006,
  639. 0x9204, 0xffffffff, 0x00090008,
  640. 0x9208, 0xffffffff, 0x00070000,
  641. 0x920c, 0xffffffff, 0x00030002,
  642. 0x9210, 0xffffffff, 0x00050004,
  643. 0x921c, 0xffffffff, 0x00010006,
  644. 0x9220, 0xffffffff, 0x00090008,
  645. 0x9224, 0xffffffff, 0x00070000,
  646. 0x9228, 0xffffffff, 0x00030002,
  647. 0x922c, 0xffffffff, 0x00050004,
  648. 0x9238, 0xffffffff, 0x00010006,
  649. 0x923c, 0xffffffff, 0x00090008,
  650. 0x9240, 0xffffffff, 0x00070000,
  651. 0x9244, 0xffffffff, 0x00030002,
  652. 0x9248, 0xffffffff, 0x00050004,
  653. 0x9254, 0xffffffff, 0x00010006,
  654. 0x9258, 0xffffffff, 0x00090008,
  655. 0x925c, 0xffffffff, 0x00070000,
  656. 0x9260, 0xffffffff, 0x00030002,
  657. 0x9264, 0xffffffff, 0x00050004,
  658. 0x9270, 0xffffffff, 0x00010006,
  659. 0x9274, 0xffffffff, 0x00090008,
  660. 0x9278, 0xffffffff, 0x00070000,
  661. 0x927c, 0xffffffff, 0x00030002,
  662. 0x9280, 0xffffffff, 0x00050004,
  663. 0x928c, 0xffffffff, 0x00010006,
  664. 0x9290, 0xffffffff, 0x00090008,
  665. 0x9294, 0xffffffff, 0x00000000,
  666. 0x929c, 0xffffffff, 0x00000001,
  667. 0x802c, 0xffffffff, 0xc0000000,
  668. 0x977c, 0xffffffff, 0x00000100,
  669. 0x3f80, 0xffffffff, 0x00000100,
  670. 0xa210, 0xffffffff, 0x00000100,
  671. 0xa214, 0xffffffff, 0x00000100,
  672. 0x4d8, 0xffffffff, 0x00000100,
  673. 0x9784, 0xffffffff, 0x00000100,
  674. 0x9698, 0xffffffff, 0x00000100,
  675. 0x4d4, 0xffffffff, 0x00000200,
  676. 0x30cc, 0xffffffff, 0x00000100,
  677. 0x802c, 0xffffffff, 0xc0000000
  678. };
  679. static const u32 supersumo_golden_registers[] =
  680. {
  681. 0x5eb4, 0xffffffff, 0x00000002,
  682. 0x5c4, 0xffffffff, 0x00000001,
  683. 0x7030, 0xffffffff, 0x00000011,
  684. 0x7c30, 0xffffffff, 0x00000011,
  685. 0x6104, 0x01000300, 0x00000000,
  686. 0x5bc0, 0x00300000, 0x00000000,
  687. 0x8c04, 0xffffffff, 0x40600060,
  688. 0x8c08, 0xffffffff, 0x001c001c,
  689. 0x8c20, 0xffffffff, 0x00800080,
  690. 0x8c24, 0xffffffff, 0x00800080,
  691. 0x8c18, 0xffffffff, 0x20202078,
  692. 0x8c1c, 0xffffffff, 0x00001010,
  693. 0x918c, 0xffffffff, 0x00010006,
  694. 0x91a8, 0xffffffff, 0x00010006,
  695. 0x91c4, 0xffffffff, 0x00010006,
  696. 0x91e0, 0xffffffff, 0x00010006,
  697. 0x9200, 0xffffffff, 0x00010006,
  698. 0x9150, 0xffffffff, 0x6e944040,
  699. 0x917c, 0xffffffff, 0x00030002,
  700. 0x9180, 0xffffffff, 0x00050004,
  701. 0x9198, 0xffffffff, 0x00030002,
  702. 0x919c, 0xffffffff, 0x00050004,
  703. 0x91b4, 0xffffffff, 0x00030002,
  704. 0x91b8, 0xffffffff, 0x00050004,
  705. 0x91d0, 0xffffffff, 0x00030002,
  706. 0x91d4, 0xffffffff, 0x00050004,
  707. 0x91f0, 0xffffffff, 0x00030002,
  708. 0x91f4, 0xffffffff, 0x00050004,
  709. 0x915c, 0xffffffff, 0x00010000,
  710. 0x9160, 0xffffffff, 0x00030002,
  711. 0x3f90, 0xffff0000, 0xff000000,
  712. 0x9178, 0xffffffff, 0x00070000,
  713. 0x9194, 0xffffffff, 0x00070000,
  714. 0x91b0, 0xffffffff, 0x00070000,
  715. 0x91cc, 0xffffffff, 0x00070000,
  716. 0x91ec, 0xffffffff, 0x00070000,
  717. 0x9148, 0xffff0000, 0xff000000,
  718. 0x9190, 0xffffffff, 0x00090008,
  719. 0x91ac, 0xffffffff, 0x00090008,
  720. 0x91c8, 0xffffffff, 0x00090008,
  721. 0x91e4, 0xffffffff, 0x00090008,
  722. 0x9204, 0xffffffff, 0x00090008,
  723. 0x3f94, 0xffff0000, 0xff000000,
  724. 0x914c, 0xffff0000, 0xff000000,
  725. 0x929c, 0xffffffff, 0x00000001,
  726. 0x8a18, 0xffffffff, 0x00000100,
  727. 0x8b28, 0xffffffff, 0x00000100,
  728. 0x9144, 0xffffffff, 0x00000100,
  729. 0x5644, 0xffffffff, 0x00000100,
  730. 0x9b7c, 0xffffffff, 0x00000000,
  731. 0x8030, 0xffffffff, 0x0000100a,
  732. 0x8a14, 0xffffffff, 0x00000007,
  733. 0x8b24, 0xffffffff, 0x00ff0fff,
  734. 0x8b10, 0xffffffff, 0x00000000,
  735. 0x28a4c, 0x06000000, 0x06000000,
  736. 0x4d8, 0xffffffff, 0x00000100,
  737. 0x913c, 0xffff000f, 0x0100000a,
  738. 0x960c, 0xffffffff, 0x54763210,
  739. 0x88c4, 0xffffffff, 0x000000c2,
  740. 0x88d4, 0xffffffff, 0x00000010,
  741. 0x8974, 0xffffffff, 0x00000000,
  742. 0xc78, 0x00000080, 0x00000080,
  743. 0x5e78, 0xffffffff, 0x001000f0,
  744. 0xd02c, 0xffffffff, 0x08421000,
  745. 0xa008, 0xffffffff, 0x00010000,
  746. 0x8d00, 0xffffffff, 0x100e4848,
  747. 0x8d04, 0xffffffff, 0x00164745,
  748. 0x8c00, 0xffffffff, 0xe4000003,
  749. 0x8cf0, 0x1fffffff, 0x08e00620,
  750. 0x28350, 0xffffffff, 0x00000000,
  751. 0x9508, 0xffffffff, 0x00000002
  752. };
  753. static const u32 sumo_golden_registers[] =
  754. {
  755. 0x900c, 0x00ffffff, 0x0017071f,
  756. 0x8c18, 0xffffffff, 0x10101060,
  757. 0x8c1c, 0xffffffff, 0x00001010,
  758. 0x8c30, 0x0000000f, 0x00000005,
  759. 0x9688, 0x0000000f, 0x00000007
  760. };
  761. static const u32 wrestler_golden_registers[] =
  762. {
  763. 0x5eb4, 0xffffffff, 0x00000002,
  764. 0x5c4, 0xffffffff, 0x00000001,
  765. 0x7030, 0xffffffff, 0x00000011,
  766. 0x7c30, 0xffffffff, 0x00000011,
  767. 0x6104, 0x01000300, 0x00000000,
  768. 0x5bc0, 0x00300000, 0x00000000,
  769. 0x918c, 0xffffffff, 0x00010006,
  770. 0x91a8, 0xffffffff, 0x00010006,
  771. 0x9150, 0xffffffff, 0x6e944040,
  772. 0x917c, 0xffffffff, 0x00030002,
  773. 0x9198, 0xffffffff, 0x00030002,
  774. 0x915c, 0xffffffff, 0x00010000,
  775. 0x3f90, 0xffff0000, 0xff000000,
  776. 0x9178, 0xffffffff, 0x00070000,
  777. 0x9194, 0xffffffff, 0x00070000,
  778. 0x9148, 0xffff0000, 0xff000000,
  779. 0x9190, 0xffffffff, 0x00090008,
  780. 0x91ac, 0xffffffff, 0x00090008,
  781. 0x3f94, 0xffff0000, 0xff000000,
  782. 0x914c, 0xffff0000, 0xff000000,
  783. 0x929c, 0xffffffff, 0x00000001,
  784. 0x8a18, 0xffffffff, 0x00000100,
  785. 0x8b28, 0xffffffff, 0x00000100,
  786. 0x9144, 0xffffffff, 0x00000100,
  787. 0x9b7c, 0xffffffff, 0x00000000,
  788. 0x8030, 0xffffffff, 0x0000100a,
  789. 0x8a14, 0xffffffff, 0x00000001,
  790. 0x8b24, 0xffffffff, 0x00ff0fff,
  791. 0x8b10, 0xffffffff, 0x00000000,
  792. 0x28a4c, 0x06000000, 0x06000000,
  793. 0x4d8, 0xffffffff, 0x00000100,
  794. 0x913c, 0xffff000f, 0x0100000a,
  795. 0x960c, 0xffffffff, 0x54763210,
  796. 0x88c4, 0xffffffff, 0x000000c2,
  797. 0x88d4, 0xffffffff, 0x00000010,
  798. 0x8974, 0xffffffff, 0x00000000,
  799. 0xc78, 0x00000080, 0x00000080,
  800. 0x5e78, 0xffffffff, 0x001000f0,
  801. 0xd02c, 0xffffffff, 0x08421000,
  802. 0xa008, 0xffffffff, 0x00010000,
  803. 0x8d00, 0xffffffff, 0x100e4848,
  804. 0x8d04, 0xffffffff, 0x00164745,
  805. 0x8c00, 0xffffffff, 0xe4000003,
  806. 0x8cf0, 0x1fffffff, 0x08e00410,
  807. 0x28350, 0xffffffff, 0x00000000,
  808. 0x9508, 0xffffffff, 0x00000002,
  809. 0x900c, 0xffffffff, 0x0017071f,
  810. 0x8c18, 0xffffffff, 0x10101060,
  811. 0x8c1c, 0xffffffff, 0x00001010
  812. };
  813. static const u32 barts_golden_registers[] =
  814. {
  815. 0x5eb4, 0xffffffff, 0x00000002,
  816. 0x5e78, 0x8f311ff1, 0x001000f0,
  817. 0x3f90, 0xffff0000, 0xff000000,
  818. 0x9148, 0xffff0000, 0xff000000,
  819. 0x3f94, 0xffff0000, 0xff000000,
  820. 0x914c, 0xffff0000, 0xff000000,
  821. 0xc78, 0x00000080, 0x00000080,
  822. 0xbd4, 0x70073777, 0x00010001,
  823. 0xd02c, 0xbfffff1f, 0x08421000,
  824. 0xd0b8, 0x03773777, 0x02011003,
  825. 0x5bc0, 0x00200000, 0x50100000,
  826. 0x98f8, 0x33773777, 0x02011003,
  827. 0x98fc, 0xffffffff, 0x76543210,
  828. 0x7030, 0x31000311, 0x00000011,
  829. 0x2f48, 0x00000007, 0x02011003,
  830. 0x6b28, 0x00000010, 0x00000012,
  831. 0x7728, 0x00000010, 0x00000012,
  832. 0x10328, 0x00000010, 0x00000012,
  833. 0x10f28, 0x00000010, 0x00000012,
  834. 0x11b28, 0x00000010, 0x00000012,
  835. 0x12728, 0x00000010, 0x00000012,
  836. 0x240c, 0x000007ff, 0x00000380,
  837. 0x8a14, 0xf000001f, 0x00000007,
  838. 0x8b24, 0x3fff3fff, 0x00ff0fff,
  839. 0x8b10, 0x0000ff0f, 0x00000000,
  840. 0x28a4c, 0x07ffffff, 0x06000000,
  841. 0x10c, 0x00000001, 0x00010003,
  842. 0xa02c, 0xffffffff, 0x0000009b,
  843. 0x913c, 0x0000000f, 0x0100000a,
  844. 0x8d00, 0xffff7f7f, 0x100e4848,
  845. 0x8d04, 0x00ffffff, 0x00164745,
  846. 0x8c00, 0xfffc0003, 0xe4000003,
  847. 0x8c04, 0xf8ff00ff, 0x40600060,
  848. 0x8c08, 0x00ff00ff, 0x001c001c,
  849. 0x8cf0, 0x1fff1fff, 0x08e00620,
  850. 0x8c20, 0x0fff0fff, 0x00800080,
  851. 0x8c24, 0x0fff0fff, 0x00800080,
  852. 0x8c18, 0xffffffff, 0x20202078,
  853. 0x8c1c, 0x0000ffff, 0x00001010,
  854. 0x28350, 0x00000f01, 0x00000000,
  855. 0x9508, 0x3700001f, 0x00000002,
  856. 0x960c, 0xffffffff, 0x54763210,
  857. 0x88c4, 0x001f3ae3, 0x000000c2,
  858. 0x88d4, 0x0000001f, 0x00000010,
  859. 0x8974, 0xffffffff, 0x00000000
  860. };
  861. static const u32 turks_golden_registers[] =
  862. {
  863. 0x5eb4, 0xffffffff, 0x00000002,
  864. 0x5e78, 0x8f311ff1, 0x001000f0,
  865. 0x8c8, 0x00003000, 0x00001070,
  866. 0x8cc, 0x000fffff, 0x00040035,
  867. 0x3f90, 0xffff0000, 0xfff00000,
  868. 0x9148, 0xffff0000, 0xfff00000,
  869. 0x3f94, 0xffff0000, 0xfff00000,
  870. 0x914c, 0xffff0000, 0xfff00000,
  871. 0xc78, 0x00000080, 0x00000080,
  872. 0xbd4, 0x00073007, 0x00010002,
  873. 0xd02c, 0xbfffff1f, 0x08421000,
  874. 0xd0b8, 0x03773777, 0x02010002,
  875. 0x5bc0, 0x00200000, 0x50100000,
  876. 0x98f8, 0x33773777, 0x00010002,
  877. 0x98fc, 0xffffffff, 0x33221100,
  878. 0x7030, 0x31000311, 0x00000011,
  879. 0x2f48, 0x33773777, 0x00010002,
  880. 0x6b28, 0x00000010, 0x00000012,
  881. 0x7728, 0x00000010, 0x00000012,
  882. 0x10328, 0x00000010, 0x00000012,
  883. 0x10f28, 0x00000010, 0x00000012,
  884. 0x11b28, 0x00000010, 0x00000012,
  885. 0x12728, 0x00000010, 0x00000012,
  886. 0x240c, 0x000007ff, 0x00000380,
  887. 0x8a14, 0xf000001f, 0x00000007,
  888. 0x8b24, 0x3fff3fff, 0x00ff0fff,
  889. 0x8b10, 0x0000ff0f, 0x00000000,
  890. 0x28a4c, 0x07ffffff, 0x06000000,
  891. 0x10c, 0x00000001, 0x00010003,
  892. 0xa02c, 0xffffffff, 0x0000009b,
  893. 0x913c, 0x0000000f, 0x0100000a,
  894. 0x8d00, 0xffff7f7f, 0x100e4848,
  895. 0x8d04, 0x00ffffff, 0x00164745,
  896. 0x8c00, 0xfffc0003, 0xe4000003,
  897. 0x8c04, 0xf8ff00ff, 0x40600060,
  898. 0x8c08, 0x00ff00ff, 0x001c001c,
  899. 0x8cf0, 0x1fff1fff, 0x08e00410,
  900. 0x8c20, 0x0fff0fff, 0x00800080,
  901. 0x8c24, 0x0fff0fff, 0x00800080,
  902. 0x8c18, 0xffffffff, 0x20202078,
  903. 0x8c1c, 0x0000ffff, 0x00001010,
  904. 0x28350, 0x00000f01, 0x00000000,
  905. 0x9508, 0x3700001f, 0x00000002,
  906. 0x960c, 0xffffffff, 0x54763210,
  907. 0x88c4, 0x001f3ae3, 0x000000c2,
  908. 0x88d4, 0x0000001f, 0x00000010,
  909. 0x8974, 0xffffffff, 0x00000000
  910. };
  911. static const u32 caicos_golden_registers[] =
  912. {
  913. 0x5eb4, 0xffffffff, 0x00000002,
  914. 0x5e78, 0x8f311ff1, 0x001000f0,
  915. 0x8c8, 0x00003420, 0x00001450,
  916. 0x8cc, 0x000fffff, 0x00040035,
  917. 0x3f90, 0xffff0000, 0xfffc0000,
  918. 0x9148, 0xffff0000, 0xfffc0000,
  919. 0x3f94, 0xffff0000, 0xfffc0000,
  920. 0x914c, 0xffff0000, 0xfffc0000,
  921. 0xc78, 0x00000080, 0x00000080,
  922. 0xbd4, 0x00073007, 0x00010001,
  923. 0xd02c, 0xbfffff1f, 0x08421000,
  924. 0xd0b8, 0x03773777, 0x02010001,
  925. 0x5bc0, 0x00200000, 0x50100000,
  926. 0x98f8, 0x33773777, 0x02010001,
  927. 0x98fc, 0xffffffff, 0x33221100,
  928. 0x7030, 0x31000311, 0x00000011,
  929. 0x2f48, 0x33773777, 0x02010001,
  930. 0x6b28, 0x00000010, 0x00000012,
  931. 0x7728, 0x00000010, 0x00000012,
  932. 0x10328, 0x00000010, 0x00000012,
  933. 0x10f28, 0x00000010, 0x00000012,
  934. 0x11b28, 0x00000010, 0x00000012,
  935. 0x12728, 0x00000010, 0x00000012,
  936. 0x240c, 0x000007ff, 0x00000380,
  937. 0x8a14, 0xf000001f, 0x00000001,
  938. 0x8b24, 0x3fff3fff, 0x00ff0fff,
  939. 0x8b10, 0x0000ff0f, 0x00000000,
  940. 0x28a4c, 0x07ffffff, 0x06000000,
  941. 0x10c, 0x00000001, 0x00010003,
  942. 0xa02c, 0xffffffff, 0x0000009b,
  943. 0x913c, 0x0000000f, 0x0100000a,
  944. 0x8d00, 0xffff7f7f, 0x100e4848,
  945. 0x8d04, 0x00ffffff, 0x00164745,
  946. 0x8c00, 0xfffc0003, 0xe4000003,
  947. 0x8c04, 0xf8ff00ff, 0x40600060,
  948. 0x8c08, 0x00ff00ff, 0x001c001c,
  949. 0x8cf0, 0x1fff1fff, 0x08e00410,
  950. 0x8c20, 0x0fff0fff, 0x00800080,
  951. 0x8c24, 0x0fff0fff, 0x00800080,
  952. 0x8c18, 0xffffffff, 0x20202078,
  953. 0x8c1c, 0x0000ffff, 0x00001010,
  954. 0x28350, 0x00000f01, 0x00000000,
  955. 0x9508, 0x3700001f, 0x00000002,
  956. 0x960c, 0xffffffff, 0x54763210,
  957. 0x88c4, 0x001f3ae3, 0x000000c2,
  958. 0x88d4, 0x0000001f, 0x00000010,
  959. 0x8974, 0xffffffff, 0x00000000
  960. };
  961. static void evergreen_init_golden_registers(struct radeon_device *rdev)
  962. {
  963. switch (rdev->family) {
  964. case CHIP_CYPRESS:
  965. case CHIP_HEMLOCK:
  966. radeon_program_register_sequence(rdev,
  967. evergreen_golden_registers,
  968. (const u32)ARRAY_SIZE(evergreen_golden_registers));
  969. radeon_program_register_sequence(rdev,
  970. evergreen_golden_registers2,
  971. (const u32)ARRAY_SIZE(evergreen_golden_registers2));
  972. radeon_program_register_sequence(rdev,
  973. cypress_mgcg_init,
  974. (const u32)ARRAY_SIZE(cypress_mgcg_init));
  975. break;
  976. case CHIP_JUNIPER:
  977. radeon_program_register_sequence(rdev,
  978. evergreen_golden_registers,
  979. (const u32)ARRAY_SIZE(evergreen_golden_registers));
  980. radeon_program_register_sequence(rdev,
  981. evergreen_golden_registers2,
  982. (const u32)ARRAY_SIZE(evergreen_golden_registers2));
  983. radeon_program_register_sequence(rdev,
  984. juniper_mgcg_init,
  985. (const u32)ARRAY_SIZE(juniper_mgcg_init));
  986. break;
  987. case CHIP_REDWOOD:
  988. radeon_program_register_sequence(rdev,
  989. evergreen_golden_registers,
  990. (const u32)ARRAY_SIZE(evergreen_golden_registers));
  991. radeon_program_register_sequence(rdev,
  992. evergreen_golden_registers2,
  993. (const u32)ARRAY_SIZE(evergreen_golden_registers2));
  994. radeon_program_register_sequence(rdev,
  995. redwood_mgcg_init,
  996. (const u32)ARRAY_SIZE(redwood_mgcg_init));
  997. break;
  998. case CHIP_CEDAR:
  999. radeon_program_register_sequence(rdev,
  1000. cedar_golden_registers,
  1001. (const u32)ARRAY_SIZE(cedar_golden_registers));
  1002. radeon_program_register_sequence(rdev,
  1003. evergreen_golden_registers2,
  1004. (const u32)ARRAY_SIZE(evergreen_golden_registers2));
  1005. radeon_program_register_sequence(rdev,
  1006. cedar_mgcg_init,
  1007. (const u32)ARRAY_SIZE(cedar_mgcg_init));
  1008. break;
  1009. case CHIP_PALM:
  1010. radeon_program_register_sequence(rdev,
  1011. wrestler_golden_registers,
  1012. (const u32)ARRAY_SIZE(wrestler_golden_registers));
  1013. break;
  1014. case CHIP_SUMO:
  1015. radeon_program_register_sequence(rdev,
  1016. supersumo_golden_registers,
  1017. (const u32)ARRAY_SIZE(supersumo_golden_registers));
  1018. break;
  1019. case CHIP_SUMO2:
  1020. radeon_program_register_sequence(rdev,
  1021. supersumo_golden_registers,
  1022. (const u32)ARRAY_SIZE(supersumo_golden_registers));
  1023. radeon_program_register_sequence(rdev,
  1024. sumo_golden_registers,
  1025. (const u32)ARRAY_SIZE(sumo_golden_registers));
  1026. break;
  1027. case CHIP_BARTS:
  1028. radeon_program_register_sequence(rdev,
  1029. barts_golden_registers,
  1030. (const u32)ARRAY_SIZE(barts_golden_registers));
  1031. break;
  1032. case CHIP_TURKS:
  1033. radeon_program_register_sequence(rdev,
  1034. turks_golden_registers,
  1035. (const u32)ARRAY_SIZE(turks_golden_registers));
  1036. break;
  1037. case CHIP_CAICOS:
  1038. radeon_program_register_sequence(rdev,
  1039. caicos_golden_registers,
  1040. (const u32)ARRAY_SIZE(caicos_golden_registers));
  1041. break;
  1042. default:
  1043. break;
  1044. }
  1045. }
  1046. /**
  1047. * evergreen_get_allowed_info_register - fetch the register for the info ioctl
  1048. *
  1049. * @rdev: radeon_device pointer
  1050. * @reg: register offset in bytes
  1051. * @val: register value
  1052. *
  1053. * Returns 0 for success or -EINVAL for an invalid register
  1054. *
  1055. */
  1056. int evergreen_get_allowed_info_register(struct radeon_device *rdev,
  1057. u32 reg, u32 *val)
  1058. {
  1059. switch (reg) {
  1060. case GRBM_STATUS:
  1061. case GRBM_STATUS_SE0:
  1062. case GRBM_STATUS_SE1:
  1063. case SRBM_STATUS:
  1064. case SRBM_STATUS2:
  1065. case DMA_STATUS_REG:
  1066. case UVD_STATUS:
  1067. *val = RREG32(reg);
  1068. return 0;
  1069. default:
  1070. return -EINVAL;
  1071. }
  1072. }
  1073. void evergreen_tiling_fields(unsigned tiling_flags, unsigned *bankw,
  1074. unsigned *bankh, unsigned *mtaspect,
  1075. unsigned *tile_split)
  1076. {
  1077. *bankw = (tiling_flags >> RADEON_TILING_EG_BANKW_SHIFT) & RADEON_TILING_EG_BANKW_MASK;
  1078. *bankh = (tiling_flags >> RADEON_TILING_EG_BANKH_SHIFT) & RADEON_TILING_EG_BANKH_MASK;
  1079. *mtaspect = (tiling_flags >> RADEON_TILING_EG_MACRO_TILE_ASPECT_SHIFT) & RADEON_TILING_EG_MACRO_TILE_ASPECT_MASK;
  1080. *tile_split = (tiling_flags >> RADEON_TILING_EG_TILE_SPLIT_SHIFT) & RADEON_TILING_EG_TILE_SPLIT_MASK;
  1081. switch (*bankw) {
  1082. default:
  1083. case 1: *bankw = EVERGREEN_ADDR_SURF_BANK_WIDTH_1; break;
  1084. case 2: *bankw = EVERGREEN_ADDR_SURF_BANK_WIDTH_2; break;
  1085. case 4: *bankw = EVERGREEN_ADDR_SURF_BANK_WIDTH_4; break;
  1086. case 8: *bankw = EVERGREEN_ADDR_SURF_BANK_WIDTH_8; break;
  1087. }
  1088. switch (*bankh) {
  1089. default:
  1090. case 1: *bankh = EVERGREEN_ADDR_SURF_BANK_HEIGHT_1; break;
  1091. case 2: *bankh = EVERGREEN_ADDR_SURF_BANK_HEIGHT_2; break;
  1092. case 4: *bankh = EVERGREEN_ADDR_SURF_BANK_HEIGHT_4; break;
  1093. case 8: *bankh = EVERGREEN_ADDR_SURF_BANK_HEIGHT_8; break;
  1094. }
  1095. switch (*mtaspect) {
  1096. default:
  1097. case 1: *mtaspect = EVERGREEN_ADDR_SURF_MACRO_TILE_ASPECT_1; break;
  1098. case 2: *mtaspect = EVERGREEN_ADDR_SURF_MACRO_TILE_ASPECT_2; break;
  1099. case 4: *mtaspect = EVERGREEN_ADDR_SURF_MACRO_TILE_ASPECT_4; break;
  1100. case 8: *mtaspect = EVERGREEN_ADDR_SURF_MACRO_TILE_ASPECT_8; break;
  1101. }
  1102. }
  1103. static int sumo_set_uvd_clock(struct radeon_device *rdev, u32 clock,
  1104. u32 cntl_reg, u32 status_reg)
  1105. {
  1106. int r, i;
  1107. struct atom_clock_dividers dividers;
  1108. r = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM,
  1109. clock, false, &dividers);
  1110. if (r)
  1111. return r;
  1112. WREG32_P(cntl_reg, dividers.post_div, ~(DCLK_DIR_CNTL_EN|DCLK_DIVIDER_MASK));
  1113. for (i = 0; i < 100; i++) {
  1114. if (RREG32(status_reg) & DCLK_STATUS)
  1115. break;
  1116. mdelay(10);
  1117. }
  1118. if (i == 100)
  1119. return -ETIMEDOUT;
  1120. return 0;
  1121. }
  1122. int sumo_set_uvd_clocks(struct radeon_device *rdev, u32 vclk, u32 dclk)
  1123. {
  1124. int r = 0;
  1125. u32 cg_scratch = RREG32(CG_SCRATCH1);
  1126. r = sumo_set_uvd_clock(rdev, vclk, CG_VCLK_CNTL, CG_VCLK_STATUS);
  1127. if (r)
  1128. goto done;
  1129. cg_scratch &= 0xffff0000;
  1130. cg_scratch |= vclk / 100; /* Mhz */
  1131. r = sumo_set_uvd_clock(rdev, dclk, CG_DCLK_CNTL, CG_DCLK_STATUS);
  1132. if (r)
  1133. goto done;
  1134. cg_scratch &= 0x0000ffff;
  1135. cg_scratch |= (dclk / 100) << 16; /* Mhz */
  1136. done:
  1137. WREG32(CG_SCRATCH1, cg_scratch);
  1138. return r;
  1139. }
  1140. int evergreen_set_uvd_clocks(struct radeon_device *rdev, u32 vclk, u32 dclk)
  1141. {
  1142. /* start off with something large */
  1143. unsigned fb_div = 0, vclk_div = 0, dclk_div = 0;
  1144. int r;
  1145. /* bypass vclk and dclk with bclk */
  1146. WREG32_P(CG_UPLL_FUNC_CNTL_2,
  1147. VCLK_SRC_SEL(1) | DCLK_SRC_SEL(1),
  1148. ~(VCLK_SRC_SEL_MASK | DCLK_SRC_SEL_MASK));
  1149. /* put PLL in bypass mode */
  1150. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_BYPASS_EN_MASK, ~UPLL_BYPASS_EN_MASK);
  1151. if (!vclk || !dclk) {
  1152. /* keep the Bypass mode, put PLL to sleep */
  1153. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_SLEEP_MASK, ~UPLL_SLEEP_MASK);
  1154. return 0;
  1155. }
  1156. r = radeon_uvd_calc_upll_dividers(rdev, vclk, dclk, 125000, 250000,
  1157. 16384, 0x03FFFFFF, 0, 128, 5,
  1158. &fb_div, &vclk_div, &dclk_div);
  1159. if (r)
  1160. return r;
  1161. /* set VCO_MODE to 1 */
  1162. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_VCO_MODE_MASK, ~UPLL_VCO_MODE_MASK);
  1163. /* toggle UPLL_SLEEP to 1 then back to 0 */
  1164. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_SLEEP_MASK, ~UPLL_SLEEP_MASK);
  1165. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_SLEEP_MASK);
  1166. /* deassert UPLL_RESET */
  1167. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_RESET_MASK);
  1168. mdelay(1);
  1169. r = radeon_uvd_send_upll_ctlreq(rdev, CG_UPLL_FUNC_CNTL);
  1170. if (r)
  1171. return r;
  1172. /* assert UPLL_RESET again */
  1173. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_RESET_MASK, ~UPLL_RESET_MASK);
  1174. /* disable spread spectrum. */
  1175. WREG32_P(CG_UPLL_SPREAD_SPECTRUM, 0, ~SSEN_MASK);
  1176. /* set feedback divider */
  1177. WREG32_P(CG_UPLL_FUNC_CNTL_3, UPLL_FB_DIV(fb_div), ~UPLL_FB_DIV_MASK);
  1178. /* set ref divider to 0 */
  1179. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_REF_DIV_MASK);
  1180. if (fb_div < 307200)
  1181. WREG32_P(CG_UPLL_FUNC_CNTL_4, 0, ~UPLL_SPARE_ISPARE9);
  1182. else
  1183. WREG32_P(CG_UPLL_FUNC_CNTL_4, UPLL_SPARE_ISPARE9, ~UPLL_SPARE_ISPARE9);
  1184. /* set PDIV_A and PDIV_B */
  1185. WREG32_P(CG_UPLL_FUNC_CNTL_2,
  1186. UPLL_PDIV_A(vclk_div) | UPLL_PDIV_B(dclk_div),
  1187. ~(UPLL_PDIV_A_MASK | UPLL_PDIV_B_MASK));
  1188. /* give the PLL some time to settle */
  1189. mdelay(15);
  1190. /* deassert PLL_RESET */
  1191. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_RESET_MASK);
  1192. mdelay(15);
  1193. /* switch from bypass mode to normal mode */
  1194. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_BYPASS_EN_MASK);
  1195. r = radeon_uvd_send_upll_ctlreq(rdev, CG_UPLL_FUNC_CNTL);
  1196. if (r)
  1197. return r;
  1198. /* switch VCLK and DCLK selection */
  1199. WREG32_P(CG_UPLL_FUNC_CNTL_2,
  1200. VCLK_SRC_SEL(2) | DCLK_SRC_SEL(2),
  1201. ~(VCLK_SRC_SEL_MASK | DCLK_SRC_SEL_MASK));
  1202. mdelay(100);
  1203. return 0;
  1204. }
  1205. void evergreen_fix_pci_max_read_req_size(struct radeon_device *rdev)
  1206. {
  1207. int readrq;
  1208. u16 v;
  1209. readrq = pcie_get_readrq(rdev->pdev);
  1210. v = ffs(readrq) - 8;
  1211. /* if bios or OS sets MAX_READ_REQUEST_SIZE to an invalid value, fix it
  1212. * to avoid hangs or perfomance issues
  1213. */
  1214. if ((v == 0) || (v == 6) || (v == 7))
  1215. pcie_set_readrq(rdev->pdev, 512);
  1216. }
  1217. void dce4_program_fmt(struct drm_encoder *encoder)
  1218. {
  1219. struct drm_device *dev = encoder->dev;
  1220. struct radeon_device *rdev = dev->dev_private;
  1221. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  1222. struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
  1223. struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
  1224. int bpc = 0;
  1225. u32 tmp = 0;
  1226. enum radeon_connector_dither dither = RADEON_FMT_DITHER_DISABLE;
  1227. if (connector) {
  1228. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  1229. bpc = radeon_get_monitor_bpc(connector);
  1230. dither = radeon_connector->dither;
  1231. }
  1232. /* LVDS/eDP FMT is set up by atom */
  1233. if (radeon_encoder->devices & ATOM_DEVICE_LCD_SUPPORT)
  1234. return;
  1235. /* not needed for analog */
  1236. if ((radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1) ||
  1237. (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2))
  1238. return;
  1239. if (bpc == 0)
  1240. return;
  1241. switch (bpc) {
  1242. case 6:
  1243. if (dither == RADEON_FMT_DITHER_ENABLE)
  1244. /* XXX sort out optimal dither settings */
  1245. tmp |= (FMT_FRAME_RANDOM_ENABLE | FMT_HIGHPASS_RANDOM_ENABLE |
  1246. FMT_SPATIAL_DITHER_EN);
  1247. else
  1248. tmp |= FMT_TRUNCATE_EN;
  1249. break;
  1250. case 8:
  1251. if (dither == RADEON_FMT_DITHER_ENABLE)
  1252. /* XXX sort out optimal dither settings */
  1253. tmp |= (FMT_FRAME_RANDOM_ENABLE | FMT_HIGHPASS_RANDOM_ENABLE |
  1254. FMT_RGB_RANDOM_ENABLE |
  1255. FMT_SPATIAL_DITHER_EN | FMT_SPATIAL_DITHER_DEPTH);
  1256. else
  1257. tmp |= (FMT_TRUNCATE_EN | FMT_TRUNCATE_DEPTH);
  1258. break;
  1259. case 10:
  1260. default:
  1261. /* not needed */
  1262. break;
  1263. }
  1264. WREG32(FMT_BIT_DEPTH_CONTROL + radeon_crtc->crtc_offset, tmp);
  1265. }
  1266. static bool dce4_is_in_vblank(struct radeon_device *rdev, int crtc)
  1267. {
  1268. if (RREG32(EVERGREEN_CRTC_STATUS + crtc_offsets[crtc]) & EVERGREEN_CRTC_V_BLANK)
  1269. return true;
  1270. else
  1271. return false;
  1272. }
  1273. static bool dce4_is_counter_moving(struct radeon_device *rdev, int crtc)
  1274. {
  1275. u32 pos1, pos2;
  1276. pos1 = RREG32(EVERGREEN_CRTC_STATUS_POSITION + crtc_offsets[crtc]);
  1277. pos2 = RREG32(EVERGREEN_CRTC_STATUS_POSITION + crtc_offsets[crtc]);
  1278. if (pos1 != pos2)
  1279. return true;
  1280. else
  1281. return false;
  1282. }
  1283. /**
  1284. * dce4_wait_for_vblank - vblank wait asic callback.
  1285. *
  1286. * @rdev: radeon_device pointer
  1287. * @crtc: crtc to wait for vblank on
  1288. *
  1289. * Wait for vblank on the requested crtc (evergreen+).
  1290. */
  1291. void dce4_wait_for_vblank(struct radeon_device *rdev, int crtc)
  1292. {
  1293. unsigned i = 0;
  1294. if (crtc >= rdev->num_crtc)
  1295. return;
  1296. if (!(RREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[crtc]) & EVERGREEN_CRTC_MASTER_EN))
  1297. return;
  1298. /* depending on when we hit vblank, we may be close to active; if so,
  1299. * wait for another frame.
  1300. */
  1301. while (dce4_is_in_vblank(rdev, crtc)) {
  1302. if (i++ % 100 == 0) {
  1303. if (!dce4_is_counter_moving(rdev, crtc))
  1304. break;
  1305. }
  1306. }
  1307. while (!dce4_is_in_vblank(rdev, crtc)) {
  1308. if (i++ % 100 == 0) {
  1309. if (!dce4_is_counter_moving(rdev, crtc))
  1310. break;
  1311. }
  1312. }
  1313. }
  1314. /**
  1315. * evergreen_page_flip - pageflip callback.
  1316. *
  1317. * @rdev: radeon_device pointer
  1318. * @crtc_id: crtc to cleanup pageflip on
  1319. * @crtc_base: new address of the crtc (GPU MC address)
  1320. *
  1321. * Does the actual pageflip (evergreen+).
  1322. * During vblank we take the crtc lock and wait for the update_pending
  1323. * bit to go high, when it does, we release the lock, and allow the
  1324. * double buffered update to take place.
  1325. * Returns the current update pending status.
  1326. */
  1327. void evergreen_page_flip(struct radeon_device *rdev, int crtc_id, u64 crtc_base)
  1328. {
  1329. struct radeon_crtc *radeon_crtc = rdev->mode_info.crtcs[crtc_id];
  1330. u32 tmp = RREG32(EVERGREEN_GRPH_UPDATE + radeon_crtc->crtc_offset);
  1331. int i;
  1332. /* Lock the graphics update lock */
  1333. tmp |= EVERGREEN_GRPH_UPDATE_LOCK;
  1334. WREG32(EVERGREEN_GRPH_UPDATE + radeon_crtc->crtc_offset, tmp);
  1335. /* update the scanout addresses */
  1336. WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS_HIGH + radeon_crtc->crtc_offset,
  1337. upper_32_bits(crtc_base));
  1338. WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS + radeon_crtc->crtc_offset,
  1339. (u32)crtc_base);
  1340. WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS_HIGH + radeon_crtc->crtc_offset,
  1341. upper_32_bits(crtc_base));
  1342. WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS + radeon_crtc->crtc_offset,
  1343. (u32)crtc_base);
  1344. /* Wait for update_pending to go high. */
  1345. for (i = 0; i < rdev->usec_timeout; i++) {
  1346. if (RREG32(EVERGREEN_GRPH_UPDATE + radeon_crtc->crtc_offset) & EVERGREEN_GRPH_SURFACE_UPDATE_PENDING)
  1347. break;
  1348. udelay(1);
  1349. }
  1350. DRM_DEBUG("Update pending now high. Unlocking vupdate_lock.\n");
  1351. /* Unlock the lock, so double-buffering can take place inside vblank */
  1352. tmp &= ~EVERGREEN_GRPH_UPDATE_LOCK;
  1353. WREG32(EVERGREEN_GRPH_UPDATE + radeon_crtc->crtc_offset, tmp);
  1354. }
  1355. /**
  1356. * evergreen_page_flip_pending - check if page flip is still pending
  1357. *
  1358. * @rdev: radeon_device pointer
  1359. * @crtc_id: crtc to check
  1360. *
  1361. * Returns the current update pending status.
  1362. */
  1363. bool evergreen_page_flip_pending(struct radeon_device *rdev, int crtc_id)
  1364. {
  1365. struct radeon_crtc *radeon_crtc = rdev->mode_info.crtcs[crtc_id];
  1366. /* Return current update_pending status: */
  1367. return !!(RREG32(EVERGREEN_GRPH_UPDATE + radeon_crtc->crtc_offset) &
  1368. EVERGREEN_GRPH_SURFACE_UPDATE_PENDING);
  1369. }
  1370. /* get temperature in millidegrees */
  1371. int evergreen_get_temp(struct radeon_device *rdev)
  1372. {
  1373. u32 temp, toffset;
  1374. int actual_temp = 0;
  1375. if (rdev->family == CHIP_JUNIPER) {
  1376. toffset = (RREG32(CG_THERMAL_CTRL) & TOFFSET_MASK) >>
  1377. TOFFSET_SHIFT;
  1378. temp = (RREG32(CG_TS0_STATUS) & TS0_ADC_DOUT_MASK) >>
  1379. TS0_ADC_DOUT_SHIFT;
  1380. if (toffset & 0x100)
  1381. actual_temp = temp / 2 - (0x200 - toffset);
  1382. else
  1383. actual_temp = temp / 2 + toffset;
  1384. actual_temp = actual_temp * 1000;
  1385. } else {
  1386. temp = (RREG32(CG_MULT_THERMAL_STATUS) & ASIC_T_MASK) >>
  1387. ASIC_T_SHIFT;
  1388. if (temp & 0x400)
  1389. actual_temp = -256;
  1390. else if (temp & 0x200)
  1391. actual_temp = 255;
  1392. else if (temp & 0x100) {
  1393. actual_temp = temp & 0x1ff;
  1394. actual_temp |= ~0x1ff;
  1395. } else
  1396. actual_temp = temp & 0xff;
  1397. actual_temp = (actual_temp * 1000) / 2;
  1398. }
  1399. return actual_temp;
  1400. }
  1401. int sumo_get_temp(struct radeon_device *rdev)
  1402. {
  1403. u32 temp = RREG32(CG_THERMAL_STATUS) & 0xff;
  1404. int actual_temp = temp - 49;
  1405. return actual_temp * 1000;
  1406. }
  1407. /**
  1408. * sumo_pm_init_profile - Initialize power profiles callback.
  1409. *
  1410. * @rdev: radeon_device pointer
  1411. *
  1412. * Initialize the power states used in profile mode
  1413. * (sumo, trinity, SI).
  1414. * Used for profile mode only.
  1415. */
  1416. void sumo_pm_init_profile(struct radeon_device *rdev)
  1417. {
  1418. int idx;
  1419. /* default */
  1420. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
  1421. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
  1422. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
  1423. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0;
  1424. /* low,mid sh/mh */
  1425. if (rdev->flags & RADEON_IS_MOBILITY)
  1426. idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 0);
  1427. else
  1428. idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
  1429. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = idx;
  1430. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = idx;
  1431. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
  1432. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
  1433. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = idx;
  1434. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = idx;
  1435. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
  1436. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
  1437. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = idx;
  1438. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = idx;
  1439. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
  1440. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0;
  1441. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = idx;
  1442. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = idx;
  1443. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
  1444. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0;
  1445. /* high sh/mh */
  1446. idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
  1447. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = idx;
  1448. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = idx;
  1449. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
  1450. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx =
  1451. rdev->pm.power_state[idx].num_clock_modes - 1;
  1452. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = idx;
  1453. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = idx;
  1454. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
  1455. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx =
  1456. rdev->pm.power_state[idx].num_clock_modes - 1;
  1457. }
  1458. /**
  1459. * btc_pm_init_profile - Initialize power profiles callback.
  1460. *
  1461. * @rdev: radeon_device pointer
  1462. *
  1463. * Initialize the power states used in profile mode
  1464. * (BTC, cayman).
  1465. * Used for profile mode only.
  1466. */
  1467. void btc_pm_init_profile(struct radeon_device *rdev)
  1468. {
  1469. int idx;
  1470. /* default */
  1471. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
  1472. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
  1473. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
  1474. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 2;
  1475. /* starting with BTC, there is one state that is used for both
  1476. * MH and SH. Difference is that we always use the high clock index for
  1477. * mclk.
  1478. */
  1479. if (rdev->flags & RADEON_IS_MOBILITY)
  1480. idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 0);
  1481. else
  1482. idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
  1483. /* low sh */
  1484. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = idx;
  1485. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = idx;
  1486. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
  1487. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
  1488. /* mid sh */
  1489. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = idx;
  1490. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = idx;
  1491. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
  1492. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 1;
  1493. /* high sh */
  1494. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = idx;
  1495. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = idx;
  1496. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
  1497. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 2;
  1498. /* low mh */
  1499. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = idx;
  1500. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = idx;
  1501. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
  1502. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
  1503. /* mid mh */
  1504. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = idx;
  1505. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = idx;
  1506. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
  1507. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 1;
  1508. /* high mh */
  1509. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = idx;
  1510. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = idx;
  1511. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
  1512. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 2;
  1513. }
  1514. /**
  1515. * evergreen_pm_misc - set additional pm hw parameters callback.
  1516. *
  1517. * @rdev: radeon_device pointer
  1518. *
  1519. * Set non-clock parameters associated with a power state
  1520. * (voltage, etc.) (evergreen+).
  1521. */
  1522. void evergreen_pm_misc(struct radeon_device *rdev)
  1523. {
  1524. int req_ps_idx = rdev->pm.requested_power_state_index;
  1525. int req_cm_idx = rdev->pm.requested_clock_mode_index;
  1526. struct radeon_power_state *ps = &rdev->pm.power_state[req_ps_idx];
  1527. struct radeon_voltage *voltage = &ps->clock_info[req_cm_idx].voltage;
  1528. if (voltage->type == VOLTAGE_SW) {
  1529. /* 0xff0x are flags rather then an actual voltage */
  1530. if ((voltage->voltage & 0xff00) == 0xff00)
  1531. return;
  1532. if (voltage->voltage && (voltage->voltage != rdev->pm.current_vddc)) {
  1533. radeon_atom_set_voltage(rdev, voltage->voltage, SET_VOLTAGE_TYPE_ASIC_VDDC);
  1534. rdev->pm.current_vddc = voltage->voltage;
  1535. DRM_DEBUG("Setting: vddc: %d\n", voltage->voltage);
  1536. }
  1537. /* starting with BTC, there is one state that is used for both
  1538. * MH and SH. Difference is that we always use the high clock index for
  1539. * mclk and vddci.
  1540. */
  1541. if ((rdev->pm.pm_method == PM_METHOD_PROFILE) &&
  1542. (rdev->family >= CHIP_BARTS) &&
  1543. rdev->pm.active_crtc_count &&
  1544. ((rdev->pm.profile_index == PM_PROFILE_MID_MH_IDX) ||
  1545. (rdev->pm.profile_index == PM_PROFILE_LOW_MH_IDX)))
  1546. voltage = &rdev->pm.power_state[req_ps_idx].
  1547. clock_info[rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx].voltage;
  1548. /* 0xff0x are flags rather then an actual voltage */
  1549. if ((voltage->vddci & 0xff00) == 0xff00)
  1550. return;
  1551. if (voltage->vddci && (voltage->vddci != rdev->pm.current_vddci)) {
  1552. radeon_atom_set_voltage(rdev, voltage->vddci, SET_VOLTAGE_TYPE_ASIC_VDDCI);
  1553. rdev->pm.current_vddci = voltage->vddci;
  1554. DRM_DEBUG("Setting: vddci: %d\n", voltage->vddci);
  1555. }
  1556. }
  1557. }
  1558. /**
  1559. * evergreen_pm_prepare - pre-power state change callback.
  1560. *
  1561. * @rdev: radeon_device pointer
  1562. *
  1563. * Prepare for a power state change (evergreen+).
  1564. */
  1565. void evergreen_pm_prepare(struct radeon_device *rdev)
  1566. {
  1567. struct drm_device *ddev = rdev->ddev;
  1568. struct drm_crtc *crtc;
  1569. struct radeon_crtc *radeon_crtc;
  1570. u32 tmp;
  1571. /* disable any active CRTCs */
  1572. list_for_each_entry(crtc, &ddev->mode_config.crtc_list, head) {
  1573. radeon_crtc = to_radeon_crtc(crtc);
  1574. if (radeon_crtc->enabled) {
  1575. tmp = RREG32(EVERGREEN_CRTC_CONTROL + radeon_crtc->crtc_offset);
  1576. tmp |= EVERGREEN_CRTC_DISP_READ_REQUEST_DISABLE;
  1577. WREG32(EVERGREEN_CRTC_CONTROL + radeon_crtc->crtc_offset, tmp);
  1578. }
  1579. }
  1580. }
  1581. /**
  1582. * evergreen_pm_finish - post-power state change callback.
  1583. *
  1584. * @rdev: radeon_device pointer
  1585. *
  1586. * Clean up after a power state change (evergreen+).
  1587. */
  1588. void evergreen_pm_finish(struct radeon_device *rdev)
  1589. {
  1590. struct drm_device *ddev = rdev->ddev;
  1591. struct drm_crtc *crtc;
  1592. struct radeon_crtc *radeon_crtc;
  1593. u32 tmp;
  1594. /* enable any active CRTCs */
  1595. list_for_each_entry(crtc, &ddev->mode_config.crtc_list, head) {
  1596. radeon_crtc = to_radeon_crtc(crtc);
  1597. if (radeon_crtc->enabled) {
  1598. tmp = RREG32(EVERGREEN_CRTC_CONTROL + radeon_crtc->crtc_offset);
  1599. tmp &= ~EVERGREEN_CRTC_DISP_READ_REQUEST_DISABLE;
  1600. WREG32(EVERGREEN_CRTC_CONTROL + radeon_crtc->crtc_offset, tmp);
  1601. }
  1602. }
  1603. }
  1604. /**
  1605. * evergreen_hpd_sense - hpd sense callback.
  1606. *
  1607. * @rdev: radeon_device pointer
  1608. * @hpd: hpd (hotplug detect) pin
  1609. *
  1610. * Checks if a digital monitor is connected (evergreen+).
  1611. * Returns true if connected, false if not connected.
  1612. */
  1613. bool evergreen_hpd_sense(struct radeon_device *rdev, enum radeon_hpd_id hpd)
  1614. {
  1615. bool connected = false;
  1616. switch (hpd) {
  1617. case RADEON_HPD_1:
  1618. if (RREG32(DC_HPD1_INT_STATUS) & DC_HPDx_SENSE)
  1619. connected = true;
  1620. break;
  1621. case RADEON_HPD_2:
  1622. if (RREG32(DC_HPD2_INT_STATUS) & DC_HPDx_SENSE)
  1623. connected = true;
  1624. break;
  1625. case RADEON_HPD_3:
  1626. if (RREG32(DC_HPD3_INT_STATUS) & DC_HPDx_SENSE)
  1627. connected = true;
  1628. break;
  1629. case RADEON_HPD_4:
  1630. if (RREG32(DC_HPD4_INT_STATUS) & DC_HPDx_SENSE)
  1631. connected = true;
  1632. break;
  1633. case RADEON_HPD_5:
  1634. if (RREG32(DC_HPD5_INT_STATUS) & DC_HPDx_SENSE)
  1635. connected = true;
  1636. break;
  1637. case RADEON_HPD_6:
  1638. if (RREG32(DC_HPD6_INT_STATUS) & DC_HPDx_SENSE)
  1639. connected = true;
  1640. break;
  1641. default:
  1642. break;
  1643. }
  1644. return connected;
  1645. }
  1646. /**
  1647. * evergreen_hpd_set_polarity - hpd set polarity callback.
  1648. *
  1649. * @rdev: radeon_device pointer
  1650. * @hpd: hpd (hotplug detect) pin
  1651. *
  1652. * Set the polarity of the hpd pin (evergreen+).
  1653. */
  1654. void evergreen_hpd_set_polarity(struct radeon_device *rdev,
  1655. enum radeon_hpd_id hpd)
  1656. {
  1657. u32 tmp;
  1658. bool connected = evergreen_hpd_sense(rdev, hpd);
  1659. switch (hpd) {
  1660. case RADEON_HPD_1:
  1661. tmp = RREG32(DC_HPD1_INT_CONTROL);
  1662. if (connected)
  1663. tmp &= ~DC_HPDx_INT_POLARITY;
  1664. else
  1665. tmp |= DC_HPDx_INT_POLARITY;
  1666. WREG32(DC_HPD1_INT_CONTROL, tmp);
  1667. break;
  1668. case RADEON_HPD_2:
  1669. tmp = RREG32(DC_HPD2_INT_CONTROL);
  1670. if (connected)
  1671. tmp &= ~DC_HPDx_INT_POLARITY;
  1672. else
  1673. tmp |= DC_HPDx_INT_POLARITY;
  1674. WREG32(DC_HPD2_INT_CONTROL, tmp);
  1675. break;
  1676. case RADEON_HPD_3:
  1677. tmp = RREG32(DC_HPD3_INT_CONTROL);
  1678. if (connected)
  1679. tmp &= ~DC_HPDx_INT_POLARITY;
  1680. else
  1681. tmp |= DC_HPDx_INT_POLARITY;
  1682. WREG32(DC_HPD3_INT_CONTROL, tmp);
  1683. break;
  1684. case RADEON_HPD_4:
  1685. tmp = RREG32(DC_HPD4_INT_CONTROL);
  1686. if (connected)
  1687. tmp &= ~DC_HPDx_INT_POLARITY;
  1688. else
  1689. tmp |= DC_HPDx_INT_POLARITY;
  1690. WREG32(DC_HPD4_INT_CONTROL, tmp);
  1691. break;
  1692. case RADEON_HPD_5:
  1693. tmp = RREG32(DC_HPD5_INT_CONTROL);
  1694. if (connected)
  1695. tmp &= ~DC_HPDx_INT_POLARITY;
  1696. else
  1697. tmp |= DC_HPDx_INT_POLARITY;
  1698. WREG32(DC_HPD5_INT_CONTROL, tmp);
  1699. break;
  1700. case RADEON_HPD_6:
  1701. tmp = RREG32(DC_HPD6_INT_CONTROL);
  1702. if (connected)
  1703. tmp &= ~DC_HPDx_INT_POLARITY;
  1704. else
  1705. tmp |= DC_HPDx_INT_POLARITY;
  1706. WREG32(DC_HPD6_INT_CONTROL, tmp);
  1707. break;
  1708. default:
  1709. break;
  1710. }
  1711. }
  1712. /**
  1713. * evergreen_hpd_init - hpd setup callback.
  1714. *
  1715. * @rdev: radeon_device pointer
  1716. *
  1717. * Setup the hpd pins used by the card (evergreen+).
  1718. * Enable the pin, set the polarity, and enable the hpd interrupts.
  1719. */
  1720. void evergreen_hpd_init(struct radeon_device *rdev)
  1721. {
  1722. struct drm_device *dev = rdev->ddev;
  1723. struct drm_connector *connector;
  1724. unsigned enabled = 0;
  1725. u32 tmp = DC_HPDx_CONNECTION_TIMER(0x9c4) |
  1726. DC_HPDx_RX_INT_TIMER(0xfa) | DC_HPDx_EN;
  1727. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  1728. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  1729. if (connector->connector_type == DRM_MODE_CONNECTOR_eDP ||
  1730. connector->connector_type == DRM_MODE_CONNECTOR_LVDS) {
  1731. /* don't try to enable hpd on eDP or LVDS avoid breaking the
  1732. * aux dp channel on imac and help (but not completely fix)
  1733. * https://bugzilla.redhat.com/show_bug.cgi?id=726143
  1734. * also avoid interrupt storms during dpms.
  1735. */
  1736. continue;
  1737. }
  1738. switch (radeon_connector->hpd.hpd) {
  1739. case RADEON_HPD_1:
  1740. WREG32(DC_HPD1_CONTROL, tmp);
  1741. break;
  1742. case RADEON_HPD_2:
  1743. WREG32(DC_HPD2_CONTROL, tmp);
  1744. break;
  1745. case RADEON_HPD_3:
  1746. WREG32(DC_HPD3_CONTROL, tmp);
  1747. break;
  1748. case RADEON_HPD_4:
  1749. WREG32(DC_HPD4_CONTROL, tmp);
  1750. break;
  1751. case RADEON_HPD_5:
  1752. WREG32(DC_HPD5_CONTROL, tmp);
  1753. break;
  1754. case RADEON_HPD_6:
  1755. WREG32(DC_HPD6_CONTROL, tmp);
  1756. break;
  1757. default:
  1758. break;
  1759. }
  1760. radeon_hpd_set_polarity(rdev, radeon_connector->hpd.hpd);
  1761. enabled |= 1 << radeon_connector->hpd.hpd;
  1762. }
  1763. radeon_irq_kms_enable_hpd(rdev, enabled);
  1764. }
  1765. /**
  1766. * evergreen_hpd_fini - hpd tear down callback.
  1767. *
  1768. * @rdev: radeon_device pointer
  1769. *
  1770. * Tear down the hpd pins used by the card (evergreen+).
  1771. * Disable the hpd interrupts.
  1772. */
  1773. void evergreen_hpd_fini(struct radeon_device *rdev)
  1774. {
  1775. struct drm_device *dev = rdev->ddev;
  1776. struct drm_connector *connector;
  1777. unsigned disabled = 0;
  1778. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  1779. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  1780. switch (radeon_connector->hpd.hpd) {
  1781. case RADEON_HPD_1:
  1782. WREG32(DC_HPD1_CONTROL, 0);
  1783. break;
  1784. case RADEON_HPD_2:
  1785. WREG32(DC_HPD2_CONTROL, 0);
  1786. break;
  1787. case RADEON_HPD_3:
  1788. WREG32(DC_HPD3_CONTROL, 0);
  1789. break;
  1790. case RADEON_HPD_4:
  1791. WREG32(DC_HPD4_CONTROL, 0);
  1792. break;
  1793. case RADEON_HPD_5:
  1794. WREG32(DC_HPD5_CONTROL, 0);
  1795. break;
  1796. case RADEON_HPD_6:
  1797. WREG32(DC_HPD6_CONTROL, 0);
  1798. break;
  1799. default:
  1800. break;
  1801. }
  1802. disabled |= 1 << radeon_connector->hpd.hpd;
  1803. }
  1804. radeon_irq_kms_disable_hpd(rdev, disabled);
  1805. }
  1806. /* watermark setup */
  1807. static u32 evergreen_line_buffer_adjust(struct radeon_device *rdev,
  1808. struct radeon_crtc *radeon_crtc,
  1809. struct drm_display_mode *mode,
  1810. struct drm_display_mode *other_mode)
  1811. {
  1812. u32 tmp, buffer_alloc, i;
  1813. u32 pipe_offset = radeon_crtc->crtc_id * 0x20;
  1814. /*
  1815. * Line Buffer Setup
  1816. * There are 3 line buffers, each one shared by 2 display controllers.
  1817. * DC_LB_MEMORY_SPLIT controls how that line buffer is shared between
  1818. * the display controllers. The paritioning is done via one of four
  1819. * preset allocations specified in bits 2:0:
  1820. * first display controller
  1821. * 0 - first half of lb (3840 * 2)
  1822. * 1 - first 3/4 of lb (5760 * 2)
  1823. * 2 - whole lb (7680 * 2), other crtc must be disabled
  1824. * 3 - first 1/4 of lb (1920 * 2)
  1825. * second display controller
  1826. * 4 - second half of lb (3840 * 2)
  1827. * 5 - second 3/4 of lb (5760 * 2)
  1828. * 6 - whole lb (7680 * 2), other crtc must be disabled
  1829. * 7 - last 1/4 of lb (1920 * 2)
  1830. */
  1831. /* this can get tricky if we have two large displays on a paired group
  1832. * of crtcs. Ideally for multiple large displays we'd assign them to
  1833. * non-linked crtcs for maximum line buffer allocation.
  1834. */
  1835. if (radeon_crtc->base.enabled && mode) {
  1836. if (other_mode) {
  1837. tmp = 0; /* 1/2 */
  1838. buffer_alloc = 1;
  1839. } else {
  1840. tmp = 2; /* whole */
  1841. buffer_alloc = 2;
  1842. }
  1843. } else {
  1844. tmp = 0;
  1845. buffer_alloc = 0;
  1846. }
  1847. /* second controller of the pair uses second half of the lb */
  1848. if (radeon_crtc->crtc_id % 2)
  1849. tmp += 4;
  1850. WREG32(DC_LB_MEMORY_SPLIT + radeon_crtc->crtc_offset, tmp);
  1851. if (ASIC_IS_DCE41(rdev) || ASIC_IS_DCE5(rdev)) {
  1852. WREG32(PIPE0_DMIF_BUFFER_CONTROL + pipe_offset,
  1853. DMIF_BUFFERS_ALLOCATED(buffer_alloc));
  1854. for (i = 0; i < rdev->usec_timeout; i++) {
  1855. if (RREG32(PIPE0_DMIF_BUFFER_CONTROL + pipe_offset) &
  1856. DMIF_BUFFERS_ALLOCATED_COMPLETED)
  1857. break;
  1858. udelay(1);
  1859. }
  1860. }
  1861. if (radeon_crtc->base.enabled && mode) {
  1862. switch (tmp) {
  1863. case 0:
  1864. case 4:
  1865. default:
  1866. if (ASIC_IS_DCE5(rdev))
  1867. return 4096 * 2;
  1868. else
  1869. return 3840 * 2;
  1870. case 1:
  1871. case 5:
  1872. if (ASIC_IS_DCE5(rdev))
  1873. return 6144 * 2;
  1874. else
  1875. return 5760 * 2;
  1876. case 2:
  1877. case 6:
  1878. if (ASIC_IS_DCE5(rdev))
  1879. return 8192 * 2;
  1880. else
  1881. return 7680 * 2;
  1882. case 3:
  1883. case 7:
  1884. if (ASIC_IS_DCE5(rdev))
  1885. return 2048 * 2;
  1886. else
  1887. return 1920 * 2;
  1888. }
  1889. }
  1890. /* controller not enabled, so no lb used */
  1891. return 0;
  1892. }
  1893. u32 evergreen_get_number_of_dram_channels(struct radeon_device *rdev)
  1894. {
  1895. u32 tmp = RREG32(MC_SHARED_CHMAP);
  1896. switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
  1897. case 0:
  1898. default:
  1899. return 1;
  1900. case 1:
  1901. return 2;
  1902. case 2:
  1903. return 4;
  1904. case 3:
  1905. return 8;
  1906. }
  1907. }
  1908. struct evergreen_wm_params {
  1909. u32 dram_channels; /* number of dram channels */
  1910. u32 yclk; /* bandwidth per dram data pin in kHz */
  1911. u32 sclk; /* engine clock in kHz */
  1912. u32 disp_clk; /* display clock in kHz */
  1913. u32 src_width; /* viewport width */
  1914. u32 active_time; /* active display time in ns */
  1915. u32 blank_time; /* blank time in ns */
  1916. bool interlaced; /* mode is interlaced */
  1917. fixed20_12 vsc; /* vertical scale ratio */
  1918. u32 num_heads; /* number of active crtcs */
  1919. u32 bytes_per_pixel; /* bytes per pixel display + overlay */
  1920. u32 lb_size; /* line buffer allocated to pipe */
  1921. u32 vtaps; /* vertical scaler taps */
  1922. };
  1923. static u32 evergreen_dram_bandwidth(struct evergreen_wm_params *wm)
  1924. {
  1925. /* Calculate DRAM Bandwidth and the part allocated to display. */
  1926. fixed20_12 dram_efficiency; /* 0.7 */
  1927. fixed20_12 yclk, dram_channels, bandwidth;
  1928. fixed20_12 a;
  1929. a.full = dfixed_const(1000);
  1930. yclk.full = dfixed_const(wm->yclk);
  1931. yclk.full = dfixed_div(yclk, a);
  1932. dram_channels.full = dfixed_const(wm->dram_channels * 4);
  1933. a.full = dfixed_const(10);
  1934. dram_efficiency.full = dfixed_const(7);
  1935. dram_efficiency.full = dfixed_div(dram_efficiency, a);
  1936. bandwidth.full = dfixed_mul(dram_channels, yclk);
  1937. bandwidth.full = dfixed_mul(bandwidth, dram_efficiency);
  1938. return dfixed_trunc(bandwidth);
  1939. }
  1940. static u32 evergreen_dram_bandwidth_for_display(struct evergreen_wm_params *wm)
  1941. {
  1942. /* Calculate DRAM Bandwidth and the part allocated to display. */
  1943. fixed20_12 disp_dram_allocation; /* 0.3 to 0.7 */
  1944. fixed20_12 yclk, dram_channels, bandwidth;
  1945. fixed20_12 a;
  1946. a.full = dfixed_const(1000);
  1947. yclk.full = dfixed_const(wm->yclk);
  1948. yclk.full = dfixed_div(yclk, a);
  1949. dram_channels.full = dfixed_const(wm->dram_channels * 4);
  1950. a.full = dfixed_const(10);
  1951. disp_dram_allocation.full = dfixed_const(3); /* XXX worse case value 0.3 */
  1952. disp_dram_allocation.full = dfixed_div(disp_dram_allocation, a);
  1953. bandwidth.full = dfixed_mul(dram_channels, yclk);
  1954. bandwidth.full = dfixed_mul(bandwidth, disp_dram_allocation);
  1955. return dfixed_trunc(bandwidth);
  1956. }
  1957. static u32 evergreen_data_return_bandwidth(struct evergreen_wm_params *wm)
  1958. {
  1959. /* Calculate the display Data return Bandwidth */
  1960. fixed20_12 return_efficiency; /* 0.8 */
  1961. fixed20_12 sclk, bandwidth;
  1962. fixed20_12 a;
  1963. a.full = dfixed_const(1000);
  1964. sclk.full = dfixed_const(wm->sclk);
  1965. sclk.full = dfixed_div(sclk, a);
  1966. a.full = dfixed_const(10);
  1967. return_efficiency.full = dfixed_const(8);
  1968. return_efficiency.full = dfixed_div(return_efficiency, a);
  1969. a.full = dfixed_const(32);
  1970. bandwidth.full = dfixed_mul(a, sclk);
  1971. bandwidth.full = dfixed_mul(bandwidth, return_efficiency);
  1972. return dfixed_trunc(bandwidth);
  1973. }
  1974. static u32 evergreen_dmif_request_bandwidth(struct evergreen_wm_params *wm)
  1975. {
  1976. /* Calculate the DMIF Request Bandwidth */
  1977. fixed20_12 disp_clk_request_efficiency; /* 0.8 */
  1978. fixed20_12 disp_clk, bandwidth;
  1979. fixed20_12 a;
  1980. a.full = dfixed_const(1000);
  1981. disp_clk.full = dfixed_const(wm->disp_clk);
  1982. disp_clk.full = dfixed_div(disp_clk, a);
  1983. a.full = dfixed_const(10);
  1984. disp_clk_request_efficiency.full = dfixed_const(8);
  1985. disp_clk_request_efficiency.full = dfixed_div(disp_clk_request_efficiency, a);
  1986. a.full = dfixed_const(32);
  1987. bandwidth.full = dfixed_mul(a, disp_clk);
  1988. bandwidth.full = dfixed_mul(bandwidth, disp_clk_request_efficiency);
  1989. return dfixed_trunc(bandwidth);
  1990. }
  1991. static u32 evergreen_available_bandwidth(struct evergreen_wm_params *wm)
  1992. {
  1993. /* Calculate the Available bandwidth. Display can use this temporarily but not in average. */
  1994. u32 dram_bandwidth = evergreen_dram_bandwidth(wm);
  1995. u32 data_return_bandwidth = evergreen_data_return_bandwidth(wm);
  1996. u32 dmif_req_bandwidth = evergreen_dmif_request_bandwidth(wm);
  1997. return min(dram_bandwidth, min(data_return_bandwidth, dmif_req_bandwidth));
  1998. }
  1999. static u32 evergreen_average_bandwidth(struct evergreen_wm_params *wm)
  2000. {
  2001. /* Calculate the display mode Average Bandwidth
  2002. * DisplayMode should contain the source and destination dimensions,
  2003. * timing, etc.
  2004. */
  2005. fixed20_12 bpp;
  2006. fixed20_12 line_time;
  2007. fixed20_12 src_width;
  2008. fixed20_12 bandwidth;
  2009. fixed20_12 a;
  2010. a.full = dfixed_const(1000);
  2011. line_time.full = dfixed_const(wm->active_time + wm->blank_time);
  2012. line_time.full = dfixed_div(line_time, a);
  2013. bpp.full = dfixed_const(wm->bytes_per_pixel);
  2014. src_width.full = dfixed_const(wm->src_width);
  2015. bandwidth.full = dfixed_mul(src_width, bpp);
  2016. bandwidth.full = dfixed_mul(bandwidth, wm->vsc);
  2017. bandwidth.full = dfixed_div(bandwidth, line_time);
  2018. return dfixed_trunc(bandwidth);
  2019. }
  2020. static u32 evergreen_latency_watermark(struct evergreen_wm_params *wm)
  2021. {
  2022. /* First calcualte the latency in ns */
  2023. u32 mc_latency = 2000; /* 2000 ns. */
  2024. u32 available_bandwidth = evergreen_available_bandwidth(wm);
  2025. u32 worst_chunk_return_time = (512 * 8 * 1000) / available_bandwidth;
  2026. u32 cursor_line_pair_return_time = (128 * 4 * 1000) / available_bandwidth;
  2027. u32 dc_latency = 40000000 / wm->disp_clk; /* dc pipe latency */
  2028. u32 other_heads_data_return_time = ((wm->num_heads + 1) * worst_chunk_return_time) +
  2029. (wm->num_heads * cursor_line_pair_return_time);
  2030. u32 latency = mc_latency + other_heads_data_return_time + dc_latency;
  2031. u32 max_src_lines_per_dst_line, lb_fill_bw, line_fill_time;
  2032. fixed20_12 a, b, c;
  2033. if (wm->num_heads == 0)
  2034. return 0;
  2035. a.full = dfixed_const(2);
  2036. b.full = dfixed_const(1);
  2037. if ((wm->vsc.full > a.full) ||
  2038. ((wm->vsc.full > b.full) && (wm->vtaps >= 3)) ||
  2039. (wm->vtaps >= 5) ||
  2040. ((wm->vsc.full >= a.full) && wm->interlaced))
  2041. max_src_lines_per_dst_line = 4;
  2042. else
  2043. max_src_lines_per_dst_line = 2;
  2044. a.full = dfixed_const(available_bandwidth);
  2045. b.full = dfixed_const(wm->num_heads);
  2046. a.full = dfixed_div(a, b);
  2047. b.full = dfixed_const(1000);
  2048. c.full = dfixed_const(wm->disp_clk);
  2049. b.full = dfixed_div(c, b);
  2050. c.full = dfixed_const(wm->bytes_per_pixel);
  2051. b.full = dfixed_mul(b, c);
  2052. lb_fill_bw = min(dfixed_trunc(a), dfixed_trunc(b));
  2053. a.full = dfixed_const(max_src_lines_per_dst_line * wm->src_width * wm->bytes_per_pixel);
  2054. b.full = dfixed_const(1000);
  2055. c.full = dfixed_const(lb_fill_bw);
  2056. b.full = dfixed_div(c, b);
  2057. a.full = dfixed_div(a, b);
  2058. line_fill_time = dfixed_trunc(a);
  2059. if (line_fill_time < wm->active_time)
  2060. return latency;
  2061. else
  2062. return latency + (line_fill_time - wm->active_time);
  2063. }
  2064. static bool evergreen_average_bandwidth_vs_dram_bandwidth_for_display(struct evergreen_wm_params *wm)
  2065. {
  2066. if (evergreen_average_bandwidth(wm) <=
  2067. (evergreen_dram_bandwidth_for_display(wm) / wm->num_heads))
  2068. return true;
  2069. else
  2070. return false;
  2071. };
  2072. static bool evergreen_average_bandwidth_vs_available_bandwidth(struct evergreen_wm_params *wm)
  2073. {
  2074. if (evergreen_average_bandwidth(wm) <=
  2075. (evergreen_available_bandwidth(wm) / wm->num_heads))
  2076. return true;
  2077. else
  2078. return false;
  2079. };
  2080. static bool evergreen_check_latency_hiding(struct evergreen_wm_params *wm)
  2081. {
  2082. u32 lb_partitions = wm->lb_size / wm->src_width;
  2083. u32 line_time = wm->active_time + wm->blank_time;
  2084. u32 latency_tolerant_lines;
  2085. u32 latency_hiding;
  2086. fixed20_12 a;
  2087. a.full = dfixed_const(1);
  2088. if (wm->vsc.full > a.full)
  2089. latency_tolerant_lines = 1;
  2090. else {
  2091. if (lb_partitions <= (wm->vtaps + 1))
  2092. latency_tolerant_lines = 1;
  2093. else
  2094. latency_tolerant_lines = 2;
  2095. }
  2096. latency_hiding = (latency_tolerant_lines * line_time + wm->blank_time);
  2097. if (evergreen_latency_watermark(wm) <= latency_hiding)
  2098. return true;
  2099. else
  2100. return false;
  2101. }
  2102. static void evergreen_program_watermarks(struct radeon_device *rdev,
  2103. struct radeon_crtc *radeon_crtc,
  2104. u32 lb_size, u32 num_heads)
  2105. {
  2106. struct drm_display_mode *mode = &radeon_crtc->base.mode;
  2107. struct evergreen_wm_params wm_low, wm_high;
  2108. u32 dram_channels;
  2109. u32 pixel_period;
  2110. u32 line_time = 0;
  2111. u32 latency_watermark_a = 0, latency_watermark_b = 0;
  2112. u32 priority_a_mark = 0, priority_b_mark = 0;
  2113. u32 priority_a_cnt = PRIORITY_OFF;
  2114. u32 priority_b_cnt = PRIORITY_OFF;
  2115. u32 pipe_offset = radeon_crtc->crtc_id * 16;
  2116. u32 tmp, arb_control3;
  2117. fixed20_12 a, b, c;
  2118. if (radeon_crtc->base.enabled && num_heads && mode) {
  2119. pixel_period = 1000000 / (u32)mode->clock;
  2120. line_time = min((u32)mode->crtc_htotal * pixel_period, (u32)65535);
  2121. priority_a_cnt = 0;
  2122. priority_b_cnt = 0;
  2123. dram_channels = evergreen_get_number_of_dram_channels(rdev);
  2124. /* watermark for high clocks */
  2125. if ((rdev->pm.pm_method == PM_METHOD_DPM) && rdev->pm.dpm_enabled) {
  2126. wm_high.yclk =
  2127. radeon_dpm_get_mclk(rdev, false) * 10;
  2128. wm_high.sclk =
  2129. radeon_dpm_get_sclk(rdev, false) * 10;
  2130. } else {
  2131. wm_high.yclk = rdev->pm.current_mclk * 10;
  2132. wm_high.sclk = rdev->pm.current_sclk * 10;
  2133. }
  2134. wm_high.disp_clk = mode->clock;
  2135. wm_high.src_width = mode->crtc_hdisplay;
  2136. wm_high.active_time = mode->crtc_hdisplay * pixel_period;
  2137. wm_high.blank_time = line_time - wm_high.active_time;
  2138. wm_high.interlaced = false;
  2139. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  2140. wm_high.interlaced = true;
  2141. wm_high.vsc = radeon_crtc->vsc;
  2142. wm_high.vtaps = 1;
  2143. if (radeon_crtc->rmx_type != RMX_OFF)
  2144. wm_high.vtaps = 2;
  2145. wm_high.bytes_per_pixel = 4; /* XXX: get this from fb config */
  2146. wm_high.lb_size = lb_size;
  2147. wm_high.dram_channels = dram_channels;
  2148. wm_high.num_heads = num_heads;
  2149. /* watermark for low clocks */
  2150. if ((rdev->pm.pm_method == PM_METHOD_DPM) && rdev->pm.dpm_enabled) {
  2151. wm_low.yclk =
  2152. radeon_dpm_get_mclk(rdev, true) * 10;
  2153. wm_low.sclk =
  2154. radeon_dpm_get_sclk(rdev, true) * 10;
  2155. } else {
  2156. wm_low.yclk = rdev->pm.current_mclk * 10;
  2157. wm_low.sclk = rdev->pm.current_sclk * 10;
  2158. }
  2159. wm_low.disp_clk = mode->clock;
  2160. wm_low.src_width = mode->crtc_hdisplay;
  2161. wm_low.active_time = mode->crtc_hdisplay * pixel_period;
  2162. wm_low.blank_time = line_time - wm_low.active_time;
  2163. wm_low.interlaced = false;
  2164. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  2165. wm_low.interlaced = true;
  2166. wm_low.vsc = radeon_crtc->vsc;
  2167. wm_low.vtaps = 1;
  2168. if (radeon_crtc->rmx_type != RMX_OFF)
  2169. wm_low.vtaps = 2;
  2170. wm_low.bytes_per_pixel = 4; /* XXX: get this from fb config */
  2171. wm_low.lb_size = lb_size;
  2172. wm_low.dram_channels = dram_channels;
  2173. wm_low.num_heads = num_heads;
  2174. /* set for high clocks */
  2175. latency_watermark_a = min(evergreen_latency_watermark(&wm_high), (u32)65535);
  2176. /* set for low clocks */
  2177. latency_watermark_b = min(evergreen_latency_watermark(&wm_low), (u32)65535);
  2178. /* possibly force display priority to high */
  2179. /* should really do this at mode validation time... */
  2180. if (!evergreen_average_bandwidth_vs_dram_bandwidth_for_display(&wm_high) ||
  2181. !evergreen_average_bandwidth_vs_available_bandwidth(&wm_high) ||
  2182. !evergreen_check_latency_hiding(&wm_high) ||
  2183. (rdev->disp_priority == 2)) {
  2184. DRM_DEBUG_KMS("force priority a to high\n");
  2185. priority_a_cnt |= PRIORITY_ALWAYS_ON;
  2186. }
  2187. if (!evergreen_average_bandwidth_vs_dram_bandwidth_for_display(&wm_low) ||
  2188. !evergreen_average_bandwidth_vs_available_bandwidth(&wm_low) ||
  2189. !evergreen_check_latency_hiding(&wm_low) ||
  2190. (rdev->disp_priority == 2)) {
  2191. DRM_DEBUG_KMS("force priority b to high\n");
  2192. priority_b_cnt |= PRIORITY_ALWAYS_ON;
  2193. }
  2194. a.full = dfixed_const(1000);
  2195. b.full = dfixed_const(mode->clock);
  2196. b.full = dfixed_div(b, a);
  2197. c.full = dfixed_const(latency_watermark_a);
  2198. c.full = dfixed_mul(c, b);
  2199. c.full = dfixed_mul(c, radeon_crtc->hsc);
  2200. c.full = dfixed_div(c, a);
  2201. a.full = dfixed_const(16);
  2202. c.full = dfixed_div(c, a);
  2203. priority_a_mark = dfixed_trunc(c);
  2204. priority_a_cnt |= priority_a_mark & PRIORITY_MARK_MASK;
  2205. a.full = dfixed_const(1000);
  2206. b.full = dfixed_const(mode->clock);
  2207. b.full = dfixed_div(b, a);
  2208. c.full = dfixed_const(latency_watermark_b);
  2209. c.full = dfixed_mul(c, b);
  2210. c.full = dfixed_mul(c, radeon_crtc->hsc);
  2211. c.full = dfixed_div(c, a);
  2212. a.full = dfixed_const(16);
  2213. c.full = dfixed_div(c, a);
  2214. priority_b_mark = dfixed_trunc(c);
  2215. priority_b_cnt |= priority_b_mark & PRIORITY_MARK_MASK;
  2216. }
  2217. /* select wm A */
  2218. arb_control3 = RREG32(PIPE0_ARBITRATION_CONTROL3 + pipe_offset);
  2219. tmp = arb_control3;
  2220. tmp &= ~LATENCY_WATERMARK_MASK(3);
  2221. tmp |= LATENCY_WATERMARK_MASK(1);
  2222. WREG32(PIPE0_ARBITRATION_CONTROL3 + pipe_offset, tmp);
  2223. WREG32(PIPE0_LATENCY_CONTROL + pipe_offset,
  2224. (LATENCY_LOW_WATERMARK(latency_watermark_a) |
  2225. LATENCY_HIGH_WATERMARK(line_time)));
  2226. /* select wm B */
  2227. tmp = RREG32(PIPE0_ARBITRATION_CONTROL3 + pipe_offset);
  2228. tmp &= ~LATENCY_WATERMARK_MASK(3);
  2229. tmp |= LATENCY_WATERMARK_MASK(2);
  2230. WREG32(PIPE0_ARBITRATION_CONTROL3 + pipe_offset, tmp);
  2231. WREG32(PIPE0_LATENCY_CONTROL + pipe_offset,
  2232. (LATENCY_LOW_WATERMARK(latency_watermark_b) |
  2233. LATENCY_HIGH_WATERMARK(line_time)));
  2234. /* restore original selection */
  2235. WREG32(PIPE0_ARBITRATION_CONTROL3 + pipe_offset, arb_control3);
  2236. /* write the priority marks */
  2237. WREG32(PRIORITY_A_CNT + radeon_crtc->crtc_offset, priority_a_cnt);
  2238. WREG32(PRIORITY_B_CNT + radeon_crtc->crtc_offset, priority_b_cnt);
  2239. /* save values for DPM */
  2240. radeon_crtc->line_time = line_time;
  2241. radeon_crtc->wm_high = latency_watermark_a;
  2242. radeon_crtc->wm_low = latency_watermark_b;
  2243. }
  2244. /**
  2245. * evergreen_bandwidth_update - update display watermarks callback.
  2246. *
  2247. * @rdev: radeon_device pointer
  2248. *
  2249. * Update the display watermarks based on the requested mode(s)
  2250. * (evergreen+).
  2251. */
  2252. void evergreen_bandwidth_update(struct radeon_device *rdev)
  2253. {
  2254. struct drm_display_mode *mode0 = NULL;
  2255. struct drm_display_mode *mode1 = NULL;
  2256. u32 num_heads = 0, lb_size;
  2257. int i;
  2258. if (!rdev->mode_info.mode_config_initialized)
  2259. return;
  2260. radeon_update_display_priority(rdev);
  2261. for (i = 0; i < rdev->num_crtc; i++) {
  2262. if (rdev->mode_info.crtcs[i]->base.enabled)
  2263. num_heads++;
  2264. }
  2265. for (i = 0; i < rdev->num_crtc; i += 2) {
  2266. mode0 = &rdev->mode_info.crtcs[i]->base.mode;
  2267. mode1 = &rdev->mode_info.crtcs[i+1]->base.mode;
  2268. lb_size = evergreen_line_buffer_adjust(rdev, rdev->mode_info.crtcs[i], mode0, mode1);
  2269. evergreen_program_watermarks(rdev, rdev->mode_info.crtcs[i], lb_size, num_heads);
  2270. lb_size = evergreen_line_buffer_adjust(rdev, rdev->mode_info.crtcs[i+1], mode1, mode0);
  2271. evergreen_program_watermarks(rdev, rdev->mode_info.crtcs[i+1], lb_size, num_heads);
  2272. }
  2273. }
  2274. /**
  2275. * evergreen_mc_wait_for_idle - wait for MC idle callback.
  2276. *
  2277. * @rdev: radeon_device pointer
  2278. *
  2279. * Wait for the MC (memory controller) to be idle.
  2280. * (evergreen+).
  2281. * Returns 0 if the MC is idle, -1 if not.
  2282. */
  2283. int evergreen_mc_wait_for_idle(struct radeon_device *rdev)
  2284. {
  2285. unsigned i;
  2286. u32 tmp;
  2287. for (i = 0; i < rdev->usec_timeout; i++) {
  2288. /* read MC_STATUS */
  2289. tmp = RREG32(SRBM_STATUS) & 0x1F00;
  2290. if (!tmp)
  2291. return 0;
  2292. udelay(1);
  2293. }
  2294. return -1;
  2295. }
  2296. /*
  2297. * GART
  2298. */
  2299. void evergreen_pcie_gart_tlb_flush(struct radeon_device *rdev)
  2300. {
  2301. unsigned i;
  2302. u32 tmp;
  2303. WREG32(HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1);
  2304. WREG32(VM_CONTEXT0_REQUEST_RESPONSE, REQUEST_TYPE(1));
  2305. for (i = 0; i < rdev->usec_timeout; i++) {
  2306. /* read MC_STATUS */
  2307. tmp = RREG32(VM_CONTEXT0_REQUEST_RESPONSE);
  2308. tmp = (tmp & RESPONSE_TYPE_MASK) >> RESPONSE_TYPE_SHIFT;
  2309. if (tmp == 2) {
  2310. printk(KERN_WARNING "[drm] r600 flush TLB failed\n");
  2311. return;
  2312. }
  2313. if (tmp) {
  2314. return;
  2315. }
  2316. udelay(1);
  2317. }
  2318. }
  2319. static int evergreen_pcie_gart_enable(struct radeon_device *rdev)
  2320. {
  2321. u32 tmp;
  2322. int r;
  2323. if (rdev->gart.robj == NULL) {
  2324. dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
  2325. return -EINVAL;
  2326. }
  2327. r = radeon_gart_table_vram_pin(rdev);
  2328. if (r)
  2329. return r;
  2330. /* Setup L2 cache */
  2331. WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING |
  2332. ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
  2333. EFFECTIVE_L2_QUEUE_SIZE(7));
  2334. WREG32(VM_L2_CNTL2, 0);
  2335. WREG32(VM_L2_CNTL3, BANK_SELECT(0) | CACHE_UPDATE_MODE(2));
  2336. /* Setup TLB control */
  2337. tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING |
  2338. SYSTEM_ACCESS_MODE_NOT_IN_SYS |
  2339. SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU |
  2340. EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5);
  2341. if (rdev->flags & RADEON_IS_IGP) {
  2342. WREG32(FUS_MC_VM_MD_L1_TLB0_CNTL, tmp);
  2343. WREG32(FUS_MC_VM_MD_L1_TLB1_CNTL, tmp);
  2344. WREG32(FUS_MC_VM_MD_L1_TLB2_CNTL, tmp);
  2345. } else {
  2346. WREG32(MC_VM_MD_L1_TLB0_CNTL, tmp);
  2347. WREG32(MC_VM_MD_L1_TLB1_CNTL, tmp);
  2348. WREG32(MC_VM_MD_L1_TLB2_CNTL, tmp);
  2349. if ((rdev->family == CHIP_JUNIPER) ||
  2350. (rdev->family == CHIP_CYPRESS) ||
  2351. (rdev->family == CHIP_HEMLOCK) ||
  2352. (rdev->family == CHIP_BARTS))
  2353. WREG32(MC_VM_MD_L1_TLB3_CNTL, tmp);
  2354. }
  2355. WREG32(MC_VM_MB_L1_TLB0_CNTL, tmp);
  2356. WREG32(MC_VM_MB_L1_TLB1_CNTL, tmp);
  2357. WREG32(MC_VM_MB_L1_TLB2_CNTL, tmp);
  2358. WREG32(MC_VM_MB_L1_TLB3_CNTL, tmp);
  2359. WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR, rdev->mc.gtt_start >> 12);
  2360. WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR, rdev->mc.gtt_end >> 12);
  2361. WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, rdev->gart.table_addr >> 12);
  2362. WREG32(VM_CONTEXT0_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) |
  2363. RANGE_PROTECTION_FAULT_ENABLE_DEFAULT);
  2364. WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR,
  2365. (u32)(rdev->dummy_page.addr >> 12));
  2366. WREG32(VM_CONTEXT1_CNTL, 0);
  2367. evergreen_pcie_gart_tlb_flush(rdev);
  2368. DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
  2369. (unsigned)(rdev->mc.gtt_size >> 20),
  2370. (unsigned long long)rdev->gart.table_addr);
  2371. rdev->gart.ready = true;
  2372. return 0;
  2373. }
  2374. static void evergreen_pcie_gart_disable(struct radeon_device *rdev)
  2375. {
  2376. u32 tmp;
  2377. /* Disable all tables */
  2378. WREG32(VM_CONTEXT0_CNTL, 0);
  2379. WREG32(VM_CONTEXT1_CNTL, 0);
  2380. /* Setup L2 cache */
  2381. WREG32(VM_L2_CNTL, ENABLE_L2_FRAGMENT_PROCESSING |
  2382. EFFECTIVE_L2_QUEUE_SIZE(7));
  2383. WREG32(VM_L2_CNTL2, 0);
  2384. WREG32(VM_L2_CNTL3, BANK_SELECT(0) | CACHE_UPDATE_MODE(2));
  2385. /* Setup TLB control */
  2386. tmp = EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5);
  2387. WREG32(MC_VM_MD_L1_TLB0_CNTL, tmp);
  2388. WREG32(MC_VM_MD_L1_TLB1_CNTL, tmp);
  2389. WREG32(MC_VM_MD_L1_TLB2_CNTL, tmp);
  2390. WREG32(MC_VM_MB_L1_TLB0_CNTL, tmp);
  2391. WREG32(MC_VM_MB_L1_TLB1_CNTL, tmp);
  2392. WREG32(MC_VM_MB_L1_TLB2_CNTL, tmp);
  2393. WREG32(MC_VM_MB_L1_TLB3_CNTL, tmp);
  2394. radeon_gart_table_vram_unpin(rdev);
  2395. }
  2396. static void evergreen_pcie_gart_fini(struct radeon_device *rdev)
  2397. {
  2398. evergreen_pcie_gart_disable(rdev);
  2399. radeon_gart_table_vram_free(rdev);
  2400. radeon_gart_fini(rdev);
  2401. }
  2402. static void evergreen_agp_enable(struct radeon_device *rdev)
  2403. {
  2404. u32 tmp;
  2405. /* Setup L2 cache */
  2406. WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING |
  2407. ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
  2408. EFFECTIVE_L2_QUEUE_SIZE(7));
  2409. WREG32(VM_L2_CNTL2, 0);
  2410. WREG32(VM_L2_CNTL3, BANK_SELECT(0) | CACHE_UPDATE_MODE(2));
  2411. /* Setup TLB control */
  2412. tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING |
  2413. SYSTEM_ACCESS_MODE_NOT_IN_SYS |
  2414. SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU |
  2415. EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5);
  2416. WREG32(MC_VM_MD_L1_TLB0_CNTL, tmp);
  2417. WREG32(MC_VM_MD_L1_TLB1_CNTL, tmp);
  2418. WREG32(MC_VM_MD_L1_TLB2_CNTL, tmp);
  2419. WREG32(MC_VM_MB_L1_TLB0_CNTL, tmp);
  2420. WREG32(MC_VM_MB_L1_TLB1_CNTL, tmp);
  2421. WREG32(MC_VM_MB_L1_TLB2_CNTL, tmp);
  2422. WREG32(MC_VM_MB_L1_TLB3_CNTL, tmp);
  2423. WREG32(VM_CONTEXT0_CNTL, 0);
  2424. WREG32(VM_CONTEXT1_CNTL, 0);
  2425. }
  2426. void evergreen_mc_stop(struct radeon_device *rdev, struct evergreen_mc_save *save)
  2427. {
  2428. u32 crtc_enabled, tmp, frame_count, blackout;
  2429. int i, j;
  2430. if (!ASIC_IS_NODCE(rdev)) {
  2431. save->vga_render_control = RREG32(VGA_RENDER_CONTROL);
  2432. save->vga_hdp_control = RREG32(VGA_HDP_CONTROL);
  2433. /* disable VGA render */
  2434. WREG32(VGA_RENDER_CONTROL, 0);
  2435. }
  2436. /* blank the display controllers */
  2437. for (i = 0; i < rdev->num_crtc; i++) {
  2438. crtc_enabled = RREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i]) & EVERGREEN_CRTC_MASTER_EN;
  2439. if (crtc_enabled) {
  2440. save->crtc_enabled[i] = true;
  2441. if (ASIC_IS_DCE6(rdev)) {
  2442. tmp = RREG32(EVERGREEN_CRTC_BLANK_CONTROL + crtc_offsets[i]);
  2443. if (!(tmp & EVERGREEN_CRTC_BLANK_DATA_EN)) {
  2444. radeon_wait_for_vblank(rdev, i);
  2445. WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 1);
  2446. tmp |= EVERGREEN_CRTC_BLANK_DATA_EN;
  2447. WREG32(EVERGREEN_CRTC_BLANK_CONTROL + crtc_offsets[i], tmp);
  2448. WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 0);
  2449. }
  2450. } else {
  2451. tmp = RREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i]);
  2452. if (!(tmp & EVERGREEN_CRTC_DISP_READ_REQUEST_DISABLE)) {
  2453. radeon_wait_for_vblank(rdev, i);
  2454. WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 1);
  2455. tmp |= EVERGREEN_CRTC_DISP_READ_REQUEST_DISABLE;
  2456. WREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i], tmp);
  2457. WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 0);
  2458. }
  2459. }
  2460. /* wait for the next frame */
  2461. frame_count = radeon_get_vblank_counter(rdev, i);
  2462. for (j = 0; j < rdev->usec_timeout; j++) {
  2463. if (radeon_get_vblank_counter(rdev, i) != frame_count)
  2464. break;
  2465. udelay(1);
  2466. }
  2467. /* XXX this is a hack to avoid strange behavior with EFI on certain systems */
  2468. WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 1);
  2469. tmp = RREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i]);
  2470. tmp &= ~EVERGREEN_CRTC_MASTER_EN;
  2471. WREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i], tmp);
  2472. WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 0);
  2473. save->crtc_enabled[i] = false;
  2474. /* ***** */
  2475. } else {
  2476. save->crtc_enabled[i] = false;
  2477. }
  2478. }
  2479. radeon_mc_wait_for_idle(rdev);
  2480. blackout = RREG32(MC_SHARED_BLACKOUT_CNTL);
  2481. if ((blackout & BLACKOUT_MODE_MASK) != 1) {
  2482. /* Block CPU access */
  2483. WREG32(BIF_FB_EN, 0);
  2484. /* blackout the MC */
  2485. blackout &= ~BLACKOUT_MODE_MASK;
  2486. WREG32(MC_SHARED_BLACKOUT_CNTL, blackout | 1);
  2487. }
  2488. /* wait for the MC to settle */
  2489. udelay(100);
  2490. /* lock double buffered regs */
  2491. for (i = 0; i < rdev->num_crtc; i++) {
  2492. if (save->crtc_enabled[i]) {
  2493. tmp = RREG32(EVERGREEN_GRPH_UPDATE + crtc_offsets[i]);
  2494. if (!(tmp & EVERGREEN_GRPH_UPDATE_LOCK)) {
  2495. tmp |= EVERGREEN_GRPH_UPDATE_LOCK;
  2496. WREG32(EVERGREEN_GRPH_UPDATE + crtc_offsets[i], tmp);
  2497. }
  2498. tmp = RREG32(EVERGREEN_MASTER_UPDATE_LOCK + crtc_offsets[i]);
  2499. if (!(tmp & 1)) {
  2500. tmp |= 1;
  2501. WREG32(EVERGREEN_MASTER_UPDATE_LOCK + crtc_offsets[i], tmp);
  2502. }
  2503. }
  2504. }
  2505. }
  2506. void evergreen_mc_resume(struct radeon_device *rdev, struct evergreen_mc_save *save)
  2507. {
  2508. u32 tmp, frame_count;
  2509. int i, j;
  2510. /* update crtc base addresses */
  2511. for (i = 0; i < rdev->num_crtc; i++) {
  2512. WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS_HIGH + crtc_offsets[i],
  2513. upper_32_bits(rdev->mc.vram_start));
  2514. WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS_HIGH + crtc_offsets[i],
  2515. upper_32_bits(rdev->mc.vram_start));
  2516. WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS + crtc_offsets[i],
  2517. (u32)rdev->mc.vram_start);
  2518. WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS + crtc_offsets[i],
  2519. (u32)rdev->mc.vram_start);
  2520. }
  2521. if (!ASIC_IS_NODCE(rdev)) {
  2522. WREG32(EVERGREEN_VGA_MEMORY_BASE_ADDRESS_HIGH, upper_32_bits(rdev->mc.vram_start));
  2523. WREG32(EVERGREEN_VGA_MEMORY_BASE_ADDRESS, (u32)rdev->mc.vram_start);
  2524. }
  2525. /* unlock regs and wait for update */
  2526. for (i = 0; i < rdev->num_crtc; i++) {
  2527. if (save->crtc_enabled[i]) {
  2528. tmp = RREG32(EVERGREEN_MASTER_UPDATE_MODE + crtc_offsets[i]);
  2529. if ((tmp & 0x7) != 3) {
  2530. tmp &= ~0x7;
  2531. tmp |= 0x3;
  2532. WREG32(EVERGREEN_MASTER_UPDATE_MODE + crtc_offsets[i], tmp);
  2533. }
  2534. tmp = RREG32(EVERGREEN_GRPH_UPDATE + crtc_offsets[i]);
  2535. if (tmp & EVERGREEN_GRPH_UPDATE_LOCK) {
  2536. tmp &= ~EVERGREEN_GRPH_UPDATE_LOCK;
  2537. WREG32(EVERGREEN_GRPH_UPDATE + crtc_offsets[i], tmp);
  2538. }
  2539. tmp = RREG32(EVERGREEN_MASTER_UPDATE_LOCK + crtc_offsets[i]);
  2540. if (tmp & 1) {
  2541. tmp &= ~1;
  2542. WREG32(EVERGREEN_MASTER_UPDATE_LOCK + crtc_offsets[i], tmp);
  2543. }
  2544. for (j = 0; j < rdev->usec_timeout; j++) {
  2545. tmp = RREG32(EVERGREEN_GRPH_UPDATE + crtc_offsets[i]);
  2546. if ((tmp & EVERGREEN_GRPH_SURFACE_UPDATE_PENDING) == 0)
  2547. break;
  2548. udelay(1);
  2549. }
  2550. }
  2551. }
  2552. /* unblackout the MC */
  2553. tmp = RREG32(MC_SHARED_BLACKOUT_CNTL);
  2554. tmp &= ~BLACKOUT_MODE_MASK;
  2555. WREG32(MC_SHARED_BLACKOUT_CNTL, tmp);
  2556. /* allow CPU access */
  2557. WREG32(BIF_FB_EN, FB_READ_EN | FB_WRITE_EN);
  2558. for (i = 0; i < rdev->num_crtc; i++) {
  2559. if (save->crtc_enabled[i]) {
  2560. if (ASIC_IS_DCE6(rdev)) {
  2561. tmp = RREG32(EVERGREEN_CRTC_BLANK_CONTROL + crtc_offsets[i]);
  2562. tmp &= ~EVERGREEN_CRTC_BLANK_DATA_EN;
  2563. WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 1);
  2564. WREG32(EVERGREEN_CRTC_BLANK_CONTROL + crtc_offsets[i], tmp);
  2565. WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 0);
  2566. } else {
  2567. tmp = RREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i]);
  2568. tmp &= ~EVERGREEN_CRTC_DISP_READ_REQUEST_DISABLE;
  2569. WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 1);
  2570. WREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i], tmp);
  2571. WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 0);
  2572. }
  2573. /* wait for the next frame */
  2574. frame_count = radeon_get_vblank_counter(rdev, i);
  2575. for (j = 0; j < rdev->usec_timeout; j++) {
  2576. if (radeon_get_vblank_counter(rdev, i) != frame_count)
  2577. break;
  2578. udelay(1);
  2579. }
  2580. }
  2581. }
  2582. if (!ASIC_IS_NODCE(rdev)) {
  2583. /* Unlock vga access */
  2584. WREG32(VGA_HDP_CONTROL, save->vga_hdp_control);
  2585. mdelay(1);
  2586. WREG32(VGA_RENDER_CONTROL, save->vga_render_control);
  2587. }
  2588. }
  2589. void evergreen_mc_program(struct radeon_device *rdev)
  2590. {
  2591. struct evergreen_mc_save save;
  2592. u32 tmp;
  2593. int i, j;
  2594. /* Initialize HDP */
  2595. for (i = 0, j = 0; i < 32; i++, j += 0x18) {
  2596. WREG32((0x2c14 + j), 0x00000000);
  2597. WREG32((0x2c18 + j), 0x00000000);
  2598. WREG32((0x2c1c + j), 0x00000000);
  2599. WREG32((0x2c20 + j), 0x00000000);
  2600. WREG32((0x2c24 + j), 0x00000000);
  2601. }
  2602. WREG32(HDP_REG_COHERENCY_FLUSH_CNTL, 0);
  2603. evergreen_mc_stop(rdev, &save);
  2604. if (evergreen_mc_wait_for_idle(rdev)) {
  2605. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  2606. }
  2607. /* Lockout access through VGA aperture*/
  2608. WREG32(VGA_HDP_CONTROL, VGA_MEMORY_DISABLE);
  2609. /* Update configuration */
  2610. if (rdev->flags & RADEON_IS_AGP) {
  2611. if (rdev->mc.vram_start < rdev->mc.gtt_start) {
  2612. /* VRAM before AGP */
  2613. WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
  2614. rdev->mc.vram_start >> 12);
  2615. WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
  2616. rdev->mc.gtt_end >> 12);
  2617. } else {
  2618. /* VRAM after AGP */
  2619. WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
  2620. rdev->mc.gtt_start >> 12);
  2621. WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
  2622. rdev->mc.vram_end >> 12);
  2623. }
  2624. } else {
  2625. WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
  2626. rdev->mc.vram_start >> 12);
  2627. WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
  2628. rdev->mc.vram_end >> 12);
  2629. }
  2630. WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR, rdev->vram_scratch.gpu_addr >> 12);
  2631. /* llano/ontario only */
  2632. if ((rdev->family == CHIP_PALM) ||
  2633. (rdev->family == CHIP_SUMO) ||
  2634. (rdev->family == CHIP_SUMO2)) {
  2635. tmp = RREG32(MC_FUS_VM_FB_OFFSET) & 0x000FFFFF;
  2636. tmp |= ((rdev->mc.vram_end >> 20) & 0xF) << 24;
  2637. tmp |= ((rdev->mc.vram_start >> 20) & 0xF) << 20;
  2638. WREG32(MC_FUS_VM_FB_OFFSET, tmp);
  2639. }
  2640. tmp = ((rdev->mc.vram_end >> 24) & 0xFFFF) << 16;
  2641. tmp |= ((rdev->mc.vram_start >> 24) & 0xFFFF);
  2642. WREG32(MC_VM_FB_LOCATION, tmp);
  2643. WREG32(HDP_NONSURFACE_BASE, (rdev->mc.vram_start >> 8));
  2644. WREG32(HDP_NONSURFACE_INFO, (2 << 7) | (1 << 30));
  2645. WREG32(HDP_NONSURFACE_SIZE, 0x3FFFFFFF);
  2646. if (rdev->flags & RADEON_IS_AGP) {
  2647. WREG32(MC_VM_AGP_TOP, rdev->mc.gtt_end >> 16);
  2648. WREG32(MC_VM_AGP_BOT, rdev->mc.gtt_start >> 16);
  2649. WREG32(MC_VM_AGP_BASE, rdev->mc.agp_base >> 22);
  2650. } else {
  2651. WREG32(MC_VM_AGP_BASE, 0);
  2652. WREG32(MC_VM_AGP_TOP, 0x0FFFFFFF);
  2653. WREG32(MC_VM_AGP_BOT, 0x0FFFFFFF);
  2654. }
  2655. if (evergreen_mc_wait_for_idle(rdev)) {
  2656. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  2657. }
  2658. evergreen_mc_resume(rdev, &save);
  2659. /* we need to own VRAM, so turn off the VGA renderer here
  2660. * to stop it overwriting our objects */
  2661. rv515_vga_render_disable(rdev);
  2662. }
  2663. /*
  2664. * CP.
  2665. */
  2666. void evergreen_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib)
  2667. {
  2668. struct radeon_ring *ring = &rdev->ring[ib->ring];
  2669. u32 next_rptr;
  2670. /* set to DX10/11 mode */
  2671. radeon_ring_write(ring, PACKET3(PACKET3_MODE_CONTROL, 0));
  2672. radeon_ring_write(ring, 1);
  2673. if (ring->rptr_save_reg) {
  2674. next_rptr = ring->wptr + 3 + 4;
  2675. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
  2676. radeon_ring_write(ring, ((ring->rptr_save_reg -
  2677. PACKET3_SET_CONFIG_REG_START) >> 2));
  2678. radeon_ring_write(ring, next_rptr);
  2679. } else if (rdev->wb.enabled) {
  2680. next_rptr = ring->wptr + 5 + 4;
  2681. radeon_ring_write(ring, PACKET3(PACKET3_MEM_WRITE, 3));
  2682. radeon_ring_write(ring, ring->next_rptr_gpu_addr & 0xfffffffc);
  2683. radeon_ring_write(ring, (upper_32_bits(ring->next_rptr_gpu_addr) & 0xff) | (1 << 18));
  2684. radeon_ring_write(ring, next_rptr);
  2685. radeon_ring_write(ring, 0);
  2686. }
  2687. radeon_ring_write(ring, PACKET3(PACKET3_INDIRECT_BUFFER, 2));
  2688. radeon_ring_write(ring,
  2689. #ifdef __BIG_ENDIAN
  2690. (2 << 0) |
  2691. #endif
  2692. (ib->gpu_addr & 0xFFFFFFFC));
  2693. radeon_ring_write(ring, upper_32_bits(ib->gpu_addr) & 0xFF);
  2694. radeon_ring_write(ring, ib->length_dw);
  2695. }
  2696. static int evergreen_cp_load_microcode(struct radeon_device *rdev)
  2697. {
  2698. const __be32 *fw_data;
  2699. int i;
  2700. if (!rdev->me_fw || !rdev->pfp_fw)
  2701. return -EINVAL;
  2702. r700_cp_stop(rdev);
  2703. WREG32(CP_RB_CNTL,
  2704. #ifdef __BIG_ENDIAN
  2705. BUF_SWAP_32BIT |
  2706. #endif
  2707. RB_NO_UPDATE | RB_BLKSZ(15) | RB_BUFSZ(3));
  2708. fw_data = (const __be32 *)rdev->pfp_fw->data;
  2709. WREG32(CP_PFP_UCODE_ADDR, 0);
  2710. for (i = 0; i < EVERGREEN_PFP_UCODE_SIZE; i++)
  2711. WREG32(CP_PFP_UCODE_DATA, be32_to_cpup(fw_data++));
  2712. WREG32(CP_PFP_UCODE_ADDR, 0);
  2713. fw_data = (const __be32 *)rdev->me_fw->data;
  2714. WREG32(CP_ME_RAM_WADDR, 0);
  2715. for (i = 0; i < EVERGREEN_PM4_UCODE_SIZE; i++)
  2716. WREG32(CP_ME_RAM_DATA, be32_to_cpup(fw_data++));
  2717. WREG32(CP_PFP_UCODE_ADDR, 0);
  2718. WREG32(CP_ME_RAM_WADDR, 0);
  2719. WREG32(CP_ME_RAM_RADDR, 0);
  2720. return 0;
  2721. }
  2722. static int evergreen_cp_start(struct radeon_device *rdev)
  2723. {
  2724. struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  2725. int r, i;
  2726. uint32_t cp_me;
  2727. r = radeon_ring_lock(rdev, ring, 7);
  2728. if (r) {
  2729. DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
  2730. return r;
  2731. }
  2732. radeon_ring_write(ring, PACKET3(PACKET3_ME_INITIALIZE, 5));
  2733. radeon_ring_write(ring, 0x1);
  2734. radeon_ring_write(ring, 0x0);
  2735. radeon_ring_write(ring, rdev->config.evergreen.max_hw_contexts - 1);
  2736. radeon_ring_write(ring, PACKET3_ME_INITIALIZE_DEVICE_ID(1));
  2737. radeon_ring_write(ring, 0);
  2738. radeon_ring_write(ring, 0);
  2739. radeon_ring_unlock_commit(rdev, ring, false);
  2740. cp_me = 0xff;
  2741. WREG32(CP_ME_CNTL, cp_me);
  2742. r = radeon_ring_lock(rdev, ring, evergreen_default_size + 19);
  2743. if (r) {
  2744. DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
  2745. return r;
  2746. }
  2747. /* setup clear context state */
  2748. radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
  2749. radeon_ring_write(ring, PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);
  2750. for (i = 0; i < evergreen_default_size; i++)
  2751. radeon_ring_write(ring, evergreen_default_state[i]);
  2752. radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
  2753. radeon_ring_write(ring, PACKET3_PREAMBLE_END_CLEAR_STATE);
  2754. /* set clear context state */
  2755. radeon_ring_write(ring, PACKET3(PACKET3_CLEAR_STATE, 0));
  2756. radeon_ring_write(ring, 0);
  2757. /* SQ_VTX_BASE_VTX_LOC */
  2758. radeon_ring_write(ring, 0xc0026f00);
  2759. radeon_ring_write(ring, 0x00000000);
  2760. radeon_ring_write(ring, 0x00000000);
  2761. radeon_ring_write(ring, 0x00000000);
  2762. /* Clear consts */
  2763. radeon_ring_write(ring, 0xc0036f00);
  2764. radeon_ring_write(ring, 0x00000bc4);
  2765. radeon_ring_write(ring, 0xffffffff);
  2766. radeon_ring_write(ring, 0xffffffff);
  2767. radeon_ring_write(ring, 0xffffffff);
  2768. radeon_ring_write(ring, 0xc0026900);
  2769. radeon_ring_write(ring, 0x00000316);
  2770. radeon_ring_write(ring, 0x0000000e); /* VGT_VERTEX_REUSE_BLOCK_CNTL */
  2771. radeon_ring_write(ring, 0x00000010); /* */
  2772. radeon_ring_unlock_commit(rdev, ring, false);
  2773. return 0;
  2774. }
  2775. static int evergreen_cp_resume(struct radeon_device *rdev)
  2776. {
  2777. struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  2778. u32 tmp;
  2779. u32 rb_bufsz;
  2780. int r;
  2781. /* Reset cp; if cp is reset, then PA, SH, VGT also need to be reset */
  2782. WREG32(GRBM_SOFT_RESET, (SOFT_RESET_CP |
  2783. SOFT_RESET_PA |
  2784. SOFT_RESET_SH |
  2785. SOFT_RESET_VGT |
  2786. SOFT_RESET_SPI |
  2787. SOFT_RESET_SX));
  2788. RREG32(GRBM_SOFT_RESET);
  2789. mdelay(15);
  2790. WREG32(GRBM_SOFT_RESET, 0);
  2791. RREG32(GRBM_SOFT_RESET);
  2792. /* Set ring buffer size */
  2793. rb_bufsz = order_base_2(ring->ring_size / 8);
  2794. tmp = (order_base_2(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
  2795. #ifdef __BIG_ENDIAN
  2796. tmp |= BUF_SWAP_32BIT;
  2797. #endif
  2798. WREG32(CP_RB_CNTL, tmp);
  2799. WREG32(CP_SEM_WAIT_TIMER, 0x0);
  2800. WREG32(CP_SEM_INCOMPLETE_TIMER_CNTL, 0x0);
  2801. /* Set the write pointer delay */
  2802. WREG32(CP_RB_WPTR_DELAY, 0);
  2803. /* Initialize the ring buffer's read and write pointers */
  2804. WREG32(CP_RB_CNTL, tmp | RB_RPTR_WR_ENA);
  2805. WREG32(CP_RB_RPTR_WR, 0);
  2806. ring->wptr = 0;
  2807. WREG32(CP_RB_WPTR, ring->wptr);
  2808. /* set the wb address whether it's enabled or not */
  2809. WREG32(CP_RB_RPTR_ADDR,
  2810. ((rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFFFFFFFC));
  2811. WREG32(CP_RB_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFF);
  2812. WREG32(SCRATCH_ADDR, ((rdev->wb.gpu_addr + RADEON_WB_SCRATCH_OFFSET) >> 8) & 0xFFFFFFFF);
  2813. if (rdev->wb.enabled)
  2814. WREG32(SCRATCH_UMSK, 0xff);
  2815. else {
  2816. tmp |= RB_NO_UPDATE;
  2817. WREG32(SCRATCH_UMSK, 0);
  2818. }
  2819. mdelay(1);
  2820. WREG32(CP_RB_CNTL, tmp);
  2821. WREG32(CP_RB_BASE, ring->gpu_addr >> 8);
  2822. WREG32(CP_DEBUG, (1 << 27) | (1 << 28));
  2823. evergreen_cp_start(rdev);
  2824. ring->ready = true;
  2825. r = radeon_ring_test(rdev, RADEON_RING_TYPE_GFX_INDEX, ring);
  2826. if (r) {
  2827. ring->ready = false;
  2828. return r;
  2829. }
  2830. return 0;
  2831. }
  2832. /*
  2833. * Core functions
  2834. */
  2835. static void evergreen_gpu_init(struct radeon_device *rdev)
  2836. {
  2837. u32 gb_addr_config;
  2838. u32 mc_shared_chmap, mc_arb_ramcfg;
  2839. u32 sx_debug_1;
  2840. u32 smx_dc_ctl0;
  2841. u32 sq_config;
  2842. u32 sq_lds_resource_mgmt;
  2843. u32 sq_gpr_resource_mgmt_1;
  2844. u32 sq_gpr_resource_mgmt_2;
  2845. u32 sq_gpr_resource_mgmt_3;
  2846. u32 sq_thread_resource_mgmt;
  2847. u32 sq_thread_resource_mgmt_2;
  2848. u32 sq_stack_resource_mgmt_1;
  2849. u32 sq_stack_resource_mgmt_2;
  2850. u32 sq_stack_resource_mgmt_3;
  2851. u32 vgt_cache_invalidation;
  2852. u32 hdp_host_path_cntl, tmp;
  2853. u32 disabled_rb_mask;
  2854. int i, j, ps_thread_count;
  2855. switch (rdev->family) {
  2856. case CHIP_CYPRESS:
  2857. case CHIP_HEMLOCK:
  2858. rdev->config.evergreen.num_ses = 2;
  2859. rdev->config.evergreen.max_pipes = 4;
  2860. rdev->config.evergreen.max_tile_pipes = 8;
  2861. rdev->config.evergreen.max_simds = 10;
  2862. rdev->config.evergreen.max_backends = 4 * rdev->config.evergreen.num_ses;
  2863. rdev->config.evergreen.max_gprs = 256;
  2864. rdev->config.evergreen.max_threads = 248;
  2865. rdev->config.evergreen.max_gs_threads = 32;
  2866. rdev->config.evergreen.max_stack_entries = 512;
  2867. rdev->config.evergreen.sx_num_of_sets = 4;
  2868. rdev->config.evergreen.sx_max_export_size = 256;
  2869. rdev->config.evergreen.sx_max_export_pos_size = 64;
  2870. rdev->config.evergreen.sx_max_export_smx_size = 192;
  2871. rdev->config.evergreen.max_hw_contexts = 8;
  2872. rdev->config.evergreen.sq_num_cf_insts = 2;
  2873. rdev->config.evergreen.sc_prim_fifo_size = 0x100;
  2874. rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
  2875. rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
  2876. gb_addr_config = CYPRESS_GB_ADDR_CONFIG_GOLDEN;
  2877. break;
  2878. case CHIP_JUNIPER:
  2879. rdev->config.evergreen.num_ses = 1;
  2880. rdev->config.evergreen.max_pipes = 4;
  2881. rdev->config.evergreen.max_tile_pipes = 4;
  2882. rdev->config.evergreen.max_simds = 10;
  2883. rdev->config.evergreen.max_backends = 4 * rdev->config.evergreen.num_ses;
  2884. rdev->config.evergreen.max_gprs = 256;
  2885. rdev->config.evergreen.max_threads = 248;
  2886. rdev->config.evergreen.max_gs_threads = 32;
  2887. rdev->config.evergreen.max_stack_entries = 512;
  2888. rdev->config.evergreen.sx_num_of_sets = 4;
  2889. rdev->config.evergreen.sx_max_export_size = 256;
  2890. rdev->config.evergreen.sx_max_export_pos_size = 64;
  2891. rdev->config.evergreen.sx_max_export_smx_size = 192;
  2892. rdev->config.evergreen.max_hw_contexts = 8;
  2893. rdev->config.evergreen.sq_num_cf_insts = 2;
  2894. rdev->config.evergreen.sc_prim_fifo_size = 0x100;
  2895. rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
  2896. rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
  2897. gb_addr_config = JUNIPER_GB_ADDR_CONFIG_GOLDEN;
  2898. break;
  2899. case CHIP_REDWOOD:
  2900. rdev->config.evergreen.num_ses = 1;
  2901. rdev->config.evergreen.max_pipes = 4;
  2902. rdev->config.evergreen.max_tile_pipes = 4;
  2903. rdev->config.evergreen.max_simds = 5;
  2904. rdev->config.evergreen.max_backends = 2 * rdev->config.evergreen.num_ses;
  2905. rdev->config.evergreen.max_gprs = 256;
  2906. rdev->config.evergreen.max_threads = 248;
  2907. rdev->config.evergreen.max_gs_threads = 32;
  2908. rdev->config.evergreen.max_stack_entries = 256;
  2909. rdev->config.evergreen.sx_num_of_sets = 4;
  2910. rdev->config.evergreen.sx_max_export_size = 256;
  2911. rdev->config.evergreen.sx_max_export_pos_size = 64;
  2912. rdev->config.evergreen.sx_max_export_smx_size = 192;
  2913. rdev->config.evergreen.max_hw_contexts = 8;
  2914. rdev->config.evergreen.sq_num_cf_insts = 2;
  2915. rdev->config.evergreen.sc_prim_fifo_size = 0x100;
  2916. rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
  2917. rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
  2918. gb_addr_config = REDWOOD_GB_ADDR_CONFIG_GOLDEN;
  2919. break;
  2920. case CHIP_CEDAR:
  2921. default:
  2922. rdev->config.evergreen.num_ses = 1;
  2923. rdev->config.evergreen.max_pipes = 2;
  2924. rdev->config.evergreen.max_tile_pipes = 2;
  2925. rdev->config.evergreen.max_simds = 2;
  2926. rdev->config.evergreen.max_backends = 1 * rdev->config.evergreen.num_ses;
  2927. rdev->config.evergreen.max_gprs = 256;
  2928. rdev->config.evergreen.max_threads = 192;
  2929. rdev->config.evergreen.max_gs_threads = 16;
  2930. rdev->config.evergreen.max_stack_entries = 256;
  2931. rdev->config.evergreen.sx_num_of_sets = 4;
  2932. rdev->config.evergreen.sx_max_export_size = 128;
  2933. rdev->config.evergreen.sx_max_export_pos_size = 32;
  2934. rdev->config.evergreen.sx_max_export_smx_size = 96;
  2935. rdev->config.evergreen.max_hw_contexts = 4;
  2936. rdev->config.evergreen.sq_num_cf_insts = 1;
  2937. rdev->config.evergreen.sc_prim_fifo_size = 0x40;
  2938. rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
  2939. rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
  2940. gb_addr_config = CEDAR_GB_ADDR_CONFIG_GOLDEN;
  2941. break;
  2942. case CHIP_PALM:
  2943. rdev->config.evergreen.num_ses = 1;
  2944. rdev->config.evergreen.max_pipes = 2;
  2945. rdev->config.evergreen.max_tile_pipes = 2;
  2946. rdev->config.evergreen.max_simds = 2;
  2947. rdev->config.evergreen.max_backends = 1 * rdev->config.evergreen.num_ses;
  2948. rdev->config.evergreen.max_gprs = 256;
  2949. rdev->config.evergreen.max_threads = 192;
  2950. rdev->config.evergreen.max_gs_threads = 16;
  2951. rdev->config.evergreen.max_stack_entries = 256;
  2952. rdev->config.evergreen.sx_num_of_sets = 4;
  2953. rdev->config.evergreen.sx_max_export_size = 128;
  2954. rdev->config.evergreen.sx_max_export_pos_size = 32;
  2955. rdev->config.evergreen.sx_max_export_smx_size = 96;
  2956. rdev->config.evergreen.max_hw_contexts = 4;
  2957. rdev->config.evergreen.sq_num_cf_insts = 1;
  2958. rdev->config.evergreen.sc_prim_fifo_size = 0x40;
  2959. rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
  2960. rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
  2961. gb_addr_config = CEDAR_GB_ADDR_CONFIG_GOLDEN;
  2962. break;
  2963. case CHIP_SUMO:
  2964. rdev->config.evergreen.num_ses = 1;
  2965. rdev->config.evergreen.max_pipes = 4;
  2966. rdev->config.evergreen.max_tile_pipes = 4;
  2967. if (rdev->pdev->device == 0x9648)
  2968. rdev->config.evergreen.max_simds = 3;
  2969. else if ((rdev->pdev->device == 0x9647) ||
  2970. (rdev->pdev->device == 0x964a))
  2971. rdev->config.evergreen.max_simds = 4;
  2972. else
  2973. rdev->config.evergreen.max_simds = 5;
  2974. rdev->config.evergreen.max_backends = 2 * rdev->config.evergreen.num_ses;
  2975. rdev->config.evergreen.max_gprs = 256;
  2976. rdev->config.evergreen.max_threads = 248;
  2977. rdev->config.evergreen.max_gs_threads = 32;
  2978. rdev->config.evergreen.max_stack_entries = 256;
  2979. rdev->config.evergreen.sx_num_of_sets = 4;
  2980. rdev->config.evergreen.sx_max_export_size = 256;
  2981. rdev->config.evergreen.sx_max_export_pos_size = 64;
  2982. rdev->config.evergreen.sx_max_export_smx_size = 192;
  2983. rdev->config.evergreen.max_hw_contexts = 8;
  2984. rdev->config.evergreen.sq_num_cf_insts = 2;
  2985. rdev->config.evergreen.sc_prim_fifo_size = 0x40;
  2986. rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
  2987. rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
  2988. gb_addr_config = SUMO_GB_ADDR_CONFIG_GOLDEN;
  2989. break;
  2990. case CHIP_SUMO2:
  2991. rdev->config.evergreen.num_ses = 1;
  2992. rdev->config.evergreen.max_pipes = 4;
  2993. rdev->config.evergreen.max_tile_pipes = 4;
  2994. rdev->config.evergreen.max_simds = 2;
  2995. rdev->config.evergreen.max_backends = 1 * rdev->config.evergreen.num_ses;
  2996. rdev->config.evergreen.max_gprs = 256;
  2997. rdev->config.evergreen.max_threads = 248;
  2998. rdev->config.evergreen.max_gs_threads = 32;
  2999. rdev->config.evergreen.max_stack_entries = 512;
  3000. rdev->config.evergreen.sx_num_of_sets = 4;
  3001. rdev->config.evergreen.sx_max_export_size = 256;
  3002. rdev->config.evergreen.sx_max_export_pos_size = 64;
  3003. rdev->config.evergreen.sx_max_export_smx_size = 192;
  3004. rdev->config.evergreen.max_hw_contexts = 4;
  3005. rdev->config.evergreen.sq_num_cf_insts = 2;
  3006. rdev->config.evergreen.sc_prim_fifo_size = 0x40;
  3007. rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
  3008. rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
  3009. gb_addr_config = SUMO2_GB_ADDR_CONFIG_GOLDEN;
  3010. break;
  3011. case CHIP_BARTS:
  3012. rdev->config.evergreen.num_ses = 2;
  3013. rdev->config.evergreen.max_pipes = 4;
  3014. rdev->config.evergreen.max_tile_pipes = 8;
  3015. rdev->config.evergreen.max_simds = 7;
  3016. rdev->config.evergreen.max_backends = 4 * rdev->config.evergreen.num_ses;
  3017. rdev->config.evergreen.max_gprs = 256;
  3018. rdev->config.evergreen.max_threads = 248;
  3019. rdev->config.evergreen.max_gs_threads = 32;
  3020. rdev->config.evergreen.max_stack_entries = 512;
  3021. rdev->config.evergreen.sx_num_of_sets = 4;
  3022. rdev->config.evergreen.sx_max_export_size = 256;
  3023. rdev->config.evergreen.sx_max_export_pos_size = 64;
  3024. rdev->config.evergreen.sx_max_export_smx_size = 192;
  3025. rdev->config.evergreen.max_hw_contexts = 8;
  3026. rdev->config.evergreen.sq_num_cf_insts = 2;
  3027. rdev->config.evergreen.sc_prim_fifo_size = 0x100;
  3028. rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
  3029. rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
  3030. gb_addr_config = BARTS_GB_ADDR_CONFIG_GOLDEN;
  3031. break;
  3032. case CHIP_TURKS:
  3033. rdev->config.evergreen.num_ses = 1;
  3034. rdev->config.evergreen.max_pipes = 4;
  3035. rdev->config.evergreen.max_tile_pipes = 4;
  3036. rdev->config.evergreen.max_simds = 6;
  3037. rdev->config.evergreen.max_backends = 2 * rdev->config.evergreen.num_ses;
  3038. rdev->config.evergreen.max_gprs = 256;
  3039. rdev->config.evergreen.max_threads = 248;
  3040. rdev->config.evergreen.max_gs_threads = 32;
  3041. rdev->config.evergreen.max_stack_entries = 256;
  3042. rdev->config.evergreen.sx_num_of_sets = 4;
  3043. rdev->config.evergreen.sx_max_export_size = 256;
  3044. rdev->config.evergreen.sx_max_export_pos_size = 64;
  3045. rdev->config.evergreen.sx_max_export_smx_size = 192;
  3046. rdev->config.evergreen.max_hw_contexts = 8;
  3047. rdev->config.evergreen.sq_num_cf_insts = 2;
  3048. rdev->config.evergreen.sc_prim_fifo_size = 0x100;
  3049. rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
  3050. rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
  3051. gb_addr_config = TURKS_GB_ADDR_CONFIG_GOLDEN;
  3052. break;
  3053. case CHIP_CAICOS:
  3054. rdev->config.evergreen.num_ses = 1;
  3055. rdev->config.evergreen.max_pipes = 2;
  3056. rdev->config.evergreen.max_tile_pipes = 2;
  3057. rdev->config.evergreen.max_simds = 2;
  3058. rdev->config.evergreen.max_backends = 1 * rdev->config.evergreen.num_ses;
  3059. rdev->config.evergreen.max_gprs = 256;
  3060. rdev->config.evergreen.max_threads = 192;
  3061. rdev->config.evergreen.max_gs_threads = 16;
  3062. rdev->config.evergreen.max_stack_entries = 256;
  3063. rdev->config.evergreen.sx_num_of_sets = 4;
  3064. rdev->config.evergreen.sx_max_export_size = 128;
  3065. rdev->config.evergreen.sx_max_export_pos_size = 32;
  3066. rdev->config.evergreen.sx_max_export_smx_size = 96;
  3067. rdev->config.evergreen.max_hw_contexts = 4;
  3068. rdev->config.evergreen.sq_num_cf_insts = 1;
  3069. rdev->config.evergreen.sc_prim_fifo_size = 0x40;
  3070. rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
  3071. rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
  3072. gb_addr_config = CAICOS_GB_ADDR_CONFIG_GOLDEN;
  3073. break;
  3074. }
  3075. /* Initialize HDP */
  3076. for (i = 0, j = 0; i < 32; i++, j += 0x18) {
  3077. WREG32((0x2c14 + j), 0x00000000);
  3078. WREG32((0x2c18 + j), 0x00000000);
  3079. WREG32((0x2c1c + j), 0x00000000);
  3080. WREG32((0x2c20 + j), 0x00000000);
  3081. WREG32((0x2c24 + j), 0x00000000);
  3082. }
  3083. WREG32(GRBM_CNTL, GRBM_READ_TIMEOUT(0xff));
  3084. WREG32(SRBM_INT_CNTL, 0x1);
  3085. WREG32(SRBM_INT_ACK, 0x1);
  3086. evergreen_fix_pci_max_read_req_size(rdev);
  3087. mc_shared_chmap = RREG32(MC_SHARED_CHMAP);
  3088. if ((rdev->family == CHIP_PALM) ||
  3089. (rdev->family == CHIP_SUMO) ||
  3090. (rdev->family == CHIP_SUMO2))
  3091. mc_arb_ramcfg = RREG32(FUS_MC_ARB_RAMCFG);
  3092. else
  3093. mc_arb_ramcfg = RREG32(MC_ARB_RAMCFG);
  3094. /* setup tiling info dword. gb_addr_config is not adequate since it does
  3095. * not have bank info, so create a custom tiling dword.
  3096. * bits 3:0 num_pipes
  3097. * bits 7:4 num_banks
  3098. * bits 11:8 group_size
  3099. * bits 15:12 row_size
  3100. */
  3101. rdev->config.evergreen.tile_config = 0;
  3102. switch (rdev->config.evergreen.max_tile_pipes) {
  3103. case 1:
  3104. default:
  3105. rdev->config.evergreen.tile_config |= (0 << 0);
  3106. break;
  3107. case 2:
  3108. rdev->config.evergreen.tile_config |= (1 << 0);
  3109. break;
  3110. case 4:
  3111. rdev->config.evergreen.tile_config |= (2 << 0);
  3112. break;
  3113. case 8:
  3114. rdev->config.evergreen.tile_config |= (3 << 0);
  3115. break;
  3116. }
  3117. /* num banks is 8 on all fusion asics. 0 = 4, 1 = 8, 2 = 16 */
  3118. if (rdev->flags & RADEON_IS_IGP)
  3119. rdev->config.evergreen.tile_config |= 1 << 4;
  3120. else {
  3121. switch ((mc_arb_ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT) {
  3122. case 0: /* four banks */
  3123. rdev->config.evergreen.tile_config |= 0 << 4;
  3124. break;
  3125. case 1: /* eight banks */
  3126. rdev->config.evergreen.tile_config |= 1 << 4;
  3127. break;
  3128. case 2: /* sixteen banks */
  3129. default:
  3130. rdev->config.evergreen.tile_config |= 2 << 4;
  3131. break;
  3132. }
  3133. }
  3134. rdev->config.evergreen.tile_config |= 0 << 8;
  3135. rdev->config.evergreen.tile_config |=
  3136. ((gb_addr_config & 0x30000000) >> 28) << 12;
  3137. if ((rdev->family >= CHIP_CEDAR) && (rdev->family <= CHIP_HEMLOCK)) {
  3138. u32 efuse_straps_4;
  3139. u32 efuse_straps_3;
  3140. efuse_straps_4 = RREG32_RCU(0x204);
  3141. efuse_straps_3 = RREG32_RCU(0x203);
  3142. tmp = (((efuse_straps_4 & 0xf) << 4) |
  3143. ((efuse_straps_3 & 0xf0000000) >> 28));
  3144. } else {
  3145. tmp = 0;
  3146. for (i = (rdev->config.evergreen.num_ses - 1); i >= 0; i--) {
  3147. u32 rb_disable_bitmap;
  3148. WREG32(GRBM_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_INDEX(i));
  3149. WREG32(RLC_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_INDEX(i));
  3150. rb_disable_bitmap = (RREG32(CC_RB_BACKEND_DISABLE) & 0x00ff0000) >> 16;
  3151. tmp <<= 4;
  3152. tmp |= rb_disable_bitmap;
  3153. }
  3154. }
  3155. /* enabled rb are just the one not disabled :) */
  3156. disabled_rb_mask = tmp;
  3157. tmp = 0;
  3158. for (i = 0; i < rdev->config.evergreen.max_backends; i++)
  3159. tmp |= (1 << i);
  3160. /* if all the backends are disabled, fix it up here */
  3161. if ((disabled_rb_mask & tmp) == tmp) {
  3162. for (i = 0; i < rdev->config.evergreen.max_backends; i++)
  3163. disabled_rb_mask &= ~(1 << i);
  3164. }
  3165. for (i = 0; i < rdev->config.evergreen.num_ses; i++) {
  3166. u32 simd_disable_bitmap;
  3167. WREG32(GRBM_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_INDEX(i));
  3168. WREG32(RLC_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_INDEX(i));
  3169. simd_disable_bitmap = (RREG32(CC_GC_SHADER_PIPE_CONFIG) & 0xffff0000) >> 16;
  3170. simd_disable_bitmap |= 0xffffffff << rdev->config.evergreen.max_simds;
  3171. tmp <<= 16;
  3172. tmp |= simd_disable_bitmap;
  3173. }
  3174. rdev->config.evergreen.active_simds = hweight32(~tmp);
  3175. WREG32(GRBM_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_BROADCAST_WRITES);
  3176. WREG32(RLC_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_BROADCAST_WRITES);
  3177. WREG32(GB_ADDR_CONFIG, gb_addr_config);
  3178. WREG32(DMIF_ADDR_CONFIG, gb_addr_config);
  3179. WREG32(HDP_ADDR_CONFIG, gb_addr_config);
  3180. WREG32(DMA_TILING_CONFIG, gb_addr_config);
  3181. WREG32(UVD_UDEC_ADDR_CONFIG, gb_addr_config);
  3182. WREG32(UVD_UDEC_DB_ADDR_CONFIG, gb_addr_config);
  3183. WREG32(UVD_UDEC_DBW_ADDR_CONFIG, gb_addr_config);
  3184. if ((rdev->config.evergreen.max_backends == 1) &&
  3185. (rdev->flags & RADEON_IS_IGP)) {
  3186. if ((disabled_rb_mask & 3) == 1) {
  3187. /* RB0 disabled, RB1 enabled */
  3188. tmp = 0x11111111;
  3189. } else {
  3190. /* RB1 disabled, RB0 enabled */
  3191. tmp = 0x00000000;
  3192. }
  3193. } else {
  3194. tmp = gb_addr_config & NUM_PIPES_MASK;
  3195. tmp = r6xx_remap_render_backend(rdev, tmp, rdev->config.evergreen.max_backends,
  3196. EVERGREEN_MAX_BACKENDS, disabled_rb_mask);
  3197. }
  3198. WREG32(GB_BACKEND_MAP, tmp);
  3199. WREG32(CGTS_SYS_TCC_DISABLE, 0);
  3200. WREG32(CGTS_TCC_DISABLE, 0);
  3201. WREG32(CGTS_USER_SYS_TCC_DISABLE, 0);
  3202. WREG32(CGTS_USER_TCC_DISABLE, 0);
  3203. /* set HW defaults for 3D engine */
  3204. WREG32(CP_QUEUE_THRESHOLDS, (ROQ_IB1_START(0x16) |
  3205. ROQ_IB2_START(0x2b)));
  3206. WREG32(CP_MEQ_THRESHOLDS, STQ_SPLIT(0x30));
  3207. WREG32(TA_CNTL_AUX, (DISABLE_CUBE_ANISO |
  3208. SYNC_GRADIENT |
  3209. SYNC_WALKER |
  3210. SYNC_ALIGNER));
  3211. sx_debug_1 = RREG32(SX_DEBUG_1);
  3212. sx_debug_1 |= ENABLE_NEW_SMX_ADDRESS;
  3213. WREG32(SX_DEBUG_1, sx_debug_1);
  3214. smx_dc_ctl0 = RREG32(SMX_DC_CTL0);
  3215. smx_dc_ctl0 &= ~NUMBER_OF_SETS(0x1ff);
  3216. smx_dc_ctl0 |= NUMBER_OF_SETS(rdev->config.evergreen.sx_num_of_sets);
  3217. WREG32(SMX_DC_CTL0, smx_dc_ctl0);
  3218. if (rdev->family <= CHIP_SUMO2)
  3219. WREG32(SMX_SAR_CTL0, 0x00010000);
  3220. WREG32(SX_EXPORT_BUFFER_SIZES, (COLOR_BUFFER_SIZE((rdev->config.evergreen.sx_max_export_size / 4) - 1) |
  3221. POSITION_BUFFER_SIZE((rdev->config.evergreen.sx_max_export_pos_size / 4) - 1) |
  3222. SMX_BUFFER_SIZE((rdev->config.evergreen.sx_max_export_smx_size / 4) - 1)));
  3223. WREG32(PA_SC_FIFO_SIZE, (SC_PRIM_FIFO_SIZE(rdev->config.evergreen.sc_prim_fifo_size) |
  3224. SC_HIZ_TILE_FIFO_SIZE(rdev->config.evergreen.sc_hiz_tile_fifo_size) |
  3225. SC_EARLYZ_TILE_FIFO_SIZE(rdev->config.evergreen.sc_earlyz_tile_fifo_size)));
  3226. WREG32(VGT_NUM_INSTANCES, 1);
  3227. WREG32(SPI_CONFIG_CNTL, 0);
  3228. WREG32(SPI_CONFIG_CNTL_1, VTX_DONE_DELAY(4));
  3229. WREG32(CP_PERFMON_CNTL, 0);
  3230. WREG32(SQ_MS_FIFO_SIZES, (CACHE_FIFO_SIZE(16 * rdev->config.evergreen.sq_num_cf_insts) |
  3231. FETCH_FIFO_HIWATER(0x4) |
  3232. DONE_FIFO_HIWATER(0xe0) |
  3233. ALU_UPDATE_FIFO_HIWATER(0x8)));
  3234. sq_config = RREG32(SQ_CONFIG);
  3235. sq_config &= ~(PS_PRIO(3) |
  3236. VS_PRIO(3) |
  3237. GS_PRIO(3) |
  3238. ES_PRIO(3));
  3239. sq_config |= (VC_ENABLE |
  3240. EXPORT_SRC_C |
  3241. PS_PRIO(0) |
  3242. VS_PRIO(1) |
  3243. GS_PRIO(2) |
  3244. ES_PRIO(3));
  3245. switch (rdev->family) {
  3246. case CHIP_CEDAR:
  3247. case CHIP_PALM:
  3248. case CHIP_SUMO:
  3249. case CHIP_SUMO2:
  3250. case CHIP_CAICOS:
  3251. /* no vertex cache */
  3252. sq_config &= ~VC_ENABLE;
  3253. break;
  3254. default:
  3255. break;
  3256. }
  3257. sq_lds_resource_mgmt = RREG32(SQ_LDS_RESOURCE_MGMT);
  3258. sq_gpr_resource_mgmt_1 = NUM_PS_GPRS((rdev->config.evergreen.max_gprs - (4 * 2))* 12 / 32);
  3259. sq_gpr_resource_mgmt_1 |= NUM_VS_GPRS((rdev->config.evergreen.max_gprs - (4 * 2)) * 6 / 32);
  3260. sq_gpr_resource_mgmt_1 |= NUM_CLAUSE_TEMP_GPRS(4);
  3261. sq_gpr_resource_mgmt_2 = NUM_GS_GPRS((rdev->config.evergreen.max_gprs - (4 * 2)) * 4 / 32);
  3262. sq_gpr_resource_mgmt_2 |= NUM_ES_GPRS((rdev->config.evergreen.max_gprs - (4 * 2)) * 4 / 32);
  3263. sq_gpr_resource_mgmt_3 = NUM_HS_GPRS((rdev->config.evergreen.max_gprs - (4 * 2)) * 3 / 32);
  3264. sq_gpr_resource_mgmt_3 |= NUM_LS_GPRS((rdev->config.evergreen.max_gprs - (4 * 2)) * 3 / 32);
  3265. switch (rdev->family) {
  3266. case CHIP_CEDAR:
  3267. case CHIP_PALM:
  3268. case CHIP_SUMO:
  3269. case CHIP_SUMO2:
  3270. ps_thread_count = 96;
  3271. break;
  3272. default:
  3273. ps_thread_count = 128;
  3274. break;
  3275. }
  3276. sq_thread_resource_mgmt = NUM_PS_THREADS(ps_thread_count);
  3277. sq_thread_resource_mgmt |= NUM_VS_THREADS((((rdev->config.evergreen.max_threads - ps_thread_count) / 6) / 8) * 8);
  3278. sq_thread_resource_mgmt |= NUM_GS_THREADS((((rdev->config.evergreen.max_threads - ps_thread_count) / 6) / 8) * 8);
  3279. sq_thread_resource_mgmt |= NUM_ES_THREADS((((rdev->config.evergreen.max_threads - ps_thread_count) / 6) / 8) * 8);
  3280. sq_thread_resource_mgmt_2 = NUM_HS_THREADS((((rdev->config.evergreen.max_threads - ps_thread_count) / 6) / 8) * 8);
  3281. sq_thread_resource_mgmt_2 |= NUM_LS_THREADS((((rdev->config.evergreen.max_threads - ps_thread_count) / 6) / 8) * 8);
  3282. sq_stack_resource_mgmt_1 = NUM_PS_STACK_ENTRIES((rdev->config.evergreen.max_stack_entries * 1) / 6);
  3283. sq_stack_resource_mgmt_1 |= NUM_VS_STACK_ENTRIES((rdev->config.evergreen.max_stack_entries * 1) / 6);
  3284. sq_stack_resource_mgmt_2 = NUM_GS_STACK_ENTRIES((rdev->config.evergreen.max_stack_entries * 1) / 6);
  3285. sq_stack_resource_mgmt_2 |= NUM_ES_STACK_ENTRIES((rdev->config.evergreen.max_stack_entries * 1) / 6);
  3286. sq_stack_resource_mgmt_3 = NUM_HS_STACK_ENTRIES((rdev->config.evergreen.max_stack_entries * 1) / 6);
  3287. sq_stack_resource_mgmt_3 |= NUM_LS_STACK_ENTRIES((rdev->config.evergreen.max_stack_entries * 1) / 6);
  3288. WREG32(SQ_CONFIG, sq_config);
  3289. WREG32(SQ_GPR_RESOURCE_MGMT_1, sq_gpr_resource_mgmt_1);
  3290. WREG32(SQ_GPR_RESOURCE_MGMT_2, sq_gpr_resource_mgmt_2);
  3291. WREG32(SQ_GPR_RESOURCE_MGMT_3, sq_gpr_resource_mgmt_3);
  3292. WREG32(SQ_THREAD_RESOURCE_MGMT, sq_thread_resource_mgmt);
  3293. WREG32(SQ_THREAD_RESOURCE_MGMT_2, sq_thread_resource_mgmt_2);
  3294. WREG32(SQ_STACK_RESOURCE_MGMT_1, sq_stack_resource_mgmt_1);
  3295. WREG32(SQ_STACK_RESOURCE_MGMT_2, sq_stack_resource_mgmt_2);
  3296. WREG32(SQ_STACK_RESOURCE_MGMT_3, sq_stack_resource_mgmt_3);
  3297. WREG32(SQ_DYN_GPR_CNTL_PS_FLUSH_REQ, 0);
  3298. WREG32(SQ_LDS_RESOURCE_MGMT, sq_lds_resource_mgmt);
  3299. WREG32(PA_SC_FORCE_EOV_MAX_CNTS, (FORCE_EOV_MAX_CLK_CNT(4095) |
  3300. FORCE_EOV_MAX_REZ_CNT(255)));
  3301. switch (rdev->family) {
  3302. case CHIP_CEDAR:
  3303. case CHIP_PALM:
  3304. case CHIP_SUMO:
  3305. case CHIP_SUMO2:
  3306. case CHIP_CAICOS:
  3307. vgt_cache_invalidation = CACHE_INVALIDATION(TC_ONLY);
  3308. break;
  3309. default:
  3310. vgt_cache_invalidation = CACHE_INVALIDATION(VC_AND_TC);
  3311. break;
  3312. }
  3313. vgt_cache_invalidation |= AUTO_INVLD_EN(ES_AND_GS_AUTO);
  3314. WREG32(VGT_CACHE_INVALIDATION, vgt_cache_invalidation);
  3315. WREG32(VGT_GS_VERTEX_REUSE, 16);
  3316. WREG32(PA_SU_LINE_STIPPLE_VALUE, 0);
  3317. WREG32(PA_SC_LINE_STIPPLE_STATE, 0);
  3318. WREG32(VGT_VERTEX_REUSE_BLOCK_CNTL, 14);
  3319. WREG32(VGT_OUT_DEALLOC_CNTL, 16);
  3320. WREG32(CB_PERF_CTR0_SEL_0, 0);
  3321. WREG32(CB_PERF_CTR0_SEL_1, 0);
  3322. WREG32(CB_PERF_CTR1_SEL_0, 0);
  3323. WREG32(CB_PERF_CTR1_SEL_1, 0);
  3324. WREG32(CB_PERF_CTR2_SEL_0, 0);
  3325. WREG32(CB_PERF_CTR2_SEL_1, 0);
  3326. WREG32(CB_PERF_CTR3_SEL_0, 0);
  3327. WREG32(CB_PERF_CTR3_SEL_1, 0);
  3328. /* clear render buffer base addresses */
  3329. WREG32(CB_COLOR0_BASE, 0);
  3330. WREG32(CB_COLOR1_BASE, 0);
  3331. WREG32(CB_COLOR2_BASE, 0);
  3332. WREG32(CB_COLOR3_BASE, 0);
  3333. WREG32(CB_COLOR4_BASE, 0);
  3334. WREG32(CB_COLOR5_BASE, 0);
  3335. WREG32(CB_COLOR6_BASE, 0);
  3336. WREG32(CB_COLOR7_BASE, 0);
  3337. WREG32(CB_COLOR8_BASE, 0);
  3338. WREG32(CB_COLOR9_BASE, 0);
  3339. WREG32(CB_COLOR10_BASE, 0);
  3340. WREG32(CB_COLOR11_BASE, 0);
  3341. /* set the shader const cache sizes to 0 */
  3342. for (i = SQ_ALU_CONST_BUFFER_SIZE_PS_0; i < 0x28200; i += 4)
  3343. WREG32(i, 0);
  3344. for (i = SQ_ALU_CONST_BUFFER_SIZE_HS_0; i < 0x29000; i += 4)
  3345. WREG32(i, 0);
  3346. tmp = RREG32(HDP_MISC_CNTL);
  3347. tmp |= HDP_FLUSH_INVALIDATE_CACHE;
  3348. WREG32(HDP_MISC_CNTL, tmp);
  3349. hdp_host_path_cntl = RREG32(HDP_HOST_PATH_CNTL);
  3350. WREG32(HDP_HOST_PATH_CNTL, hdp_host_path_cntl);
  3351. WREG32(PA_CL_ENHANCE, CLIP_VTX_REORDER_ENA | NUM_CLIP_SEQ(3));
  3352. udelay(50);
  3353. }
  3354. int evergreen_mc_init(struct radeon_device *rdev)
  3355. {
  3356. u32 tmp;
  3357. int chansize, numchan;
  3358. /* Get VRAM informations */
  3359. rdev->mc.vram_is_ddr = true;
  3360. if ((rdev->family == CHIP_PALM) ||
  3361. (rdev->family == CHIP_SUMO) ||
  3362. (rdev->family == CHIP_SUMO2))
  3363. tmp = RREG32(FUS_MC_ARB_RAMCFG);
  3364. else
  3365. tmp = RREG32(MC_ARB_RAMCFG);
  3366. if (tmp & CHANSIZE_OVERRIDE) {
  3367. chansize = 16;
  3368. } else if (tmp & CHANSIZE_MASK) {
  3369. chansize = 64;
  3370. } else {
  3371. chansize = 32;
  3372. }
  3373. tmp = RREG32(MC_SHARED_CHMAP);
  3374. switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
  3375. case 0:
  3376. default:
  3377. numchan = 1;
  3378. break;
  3379. case 1:
  3380. numchan = 2;
  3381. break;
  3382. case 2:
  3383. numchan = 4;
  3384. break;
  3385. case 3:
  3386. numchan = 8;
  3387. break;
  3388. }
  3389. rdev->mc.vram_width = numchan * chansize;
  3390. /* Could aper size report 0 ? */
  3391. rdev->mc.aper_base = pci_resource_start(rdev->pdev, 0);
  3392. rdev->mc.aper_size = pci_resource_len(rdev->pdev, 0);
  3393. /* Setup GPU memory space */
  3394. if ((rdev->family == CHIP_PALM) ||
  3395. (rdev->family == CHIP_SUMO) ||
  3396. (rdev->family == CHIP_SUMO2)) {
  3397. /* size in bytes on fusion */
  3398. rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE);
  3399. rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE);
  3400. } else {
  3401. /* size in MB on evergreen/cayman/tn */
  3402. rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE) * 1024ULL * 1024ULL;
  3403. rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE) * 1024ULL * 1024ULL;
  3404. }
  3405. rdev->mc.visible_vram_size = rdev->mc.aper_size;
  3406. r700_vram_gtt_location(rdev, &rdev->mc);
  3407. radeon_update_bandwidth_info(rdev);
  3408. return 0;
  3409. }
  3410. void evergreen_print_gpu_status_regs(struct radeon_device *rdev)
  3411. {
  3412. dev_info(rdev->dev, " GRBM_STATUS = 0x%08X\n",
  3413. RREG32(GRBM_STATUS));
  3414. dev_info(rdev->dev, " GRBM_STATUS_SE0 = 0x%08X\n",
  3415. RREG32(GRBM_STATUS_SE0));
  3416. dev_info(rdev->dev, " GRBM_STATUS_SE1 = 0x%08X\n",
  3417. RREG32(GRBM_STATUS_SE1));
  3418. dev_info(rdev->dev, " SRBM_STATUS = 0x%08X\n",
  3419. RREG32(SRBM_STATUS));
  3420. dev_info(rdev->dev, " SRBM_STATUS2 = 0x%08X\n",
  3421. RREG32(SRBM_STATUS2));
  3422. dev_info(rdev->dev, " R_008674_CP_STALLED_STAT1 = 0x%08X\n",
  3423. RREG32(CP_STALLED_STAT1));
  3424. dev_info(rdev->dev, " R_008678_CP_STALLED_STAT2 = 0x%08X\n",
  3425. RREG32(CP_STALLED_STAT2));
  3426. dev_info(rdev->dev, " R_00867C_CP_BUSY_STAT = 0x%08X\n",
  3427. RREG32(CP_BUSY_STAT));
  3428. dev_info(rdev->dev, " R_008680_CP_STAT = 0x%08X\n",
  3429. RREG32(CP_STAT));
  3430. dev_info(rdev->dev, " R_00D034_DMA_STATUS_REG = 0x%08X\n",
  3431. RREG32(DMA_STATUS_REG));
  3432. if (rdev->family >= CHIP_CAYMAN) {
  3433. dev_info(rdev->dev, " R_00D834_DMA_STATUS_REG = 0x%08X\n",
  3434. RREG32(DMA_STATUS_REG + 0x800));
  3435. }
  3436. }
  3437. bool evergreen_is_display_hung(struct radeon_device *rdev)
  3438. {
  3439. u32 crtc_hung = 0;
  3440. u32 crtc_status[6];
  3441. u32 i, j, tmp;
  3442. for (i = 0; i < rdev->num_crtc; i++) {
  3443. if (RREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i]) & EVERGREEN_CRTC_MASTER_EN) {
  3444. crtc_status[i] = RREG32(EVERGREEN_CRTC_STATUS_HV_COUNT + crtc_offsets[i]);
  3445. crtc_hung |= (1 << i);
  3446. }
  3447. }
  3448. for (j = 0; j < 10; j++) {
  3449. for (i = 0; i < rdev->num_crtc; i++) {
  3450. if (crtc_hung & (1 << i)) {
  3451. tmp = RREG32(EVERGREEN_CRTC_STATUS_HV_COUNT + crtc_offsets[i]);
  3452. if (tmp != crtc_status[i])
  3453. crtc_hung &= ~(1 << i);
  3454. }
  3455. }
  3456. if (crtc_hung == 0)
  3457. return false;
  3458. udelay(100);
  3459. }
  3460. return true;
  3461. }
  3462. u32 evergreen_gpu_check_soft_reset(struct radeon_device *rdev)
  3463. {
  3464. u32 reset_mask = 0;
  3465. u32 tmp;
  3466. /* GRBM_STATUS */
  3467. tmp = RREG32(GRBM_STATUS);
  3468. if (tmp & (PA_BUSY | SC_BUSY |
  3469. SH_BUSY | SX_BUSY |
  3470. TA_BUSY | VGT_BUSY |
  3471. DB_BUSY | CB_BUSY |
  3472. SPI_BUSY | VGT_BUSY_NO_DMA))
  3473. reset_mask |= RADEON_RESET_GFX;
  3474. if (tmp & (CF_RQ_PENDING | PF_RQ_PENDING |
  3475. CP_BUSY | CP_COHERENCY_BUSY))
  3476. reset_mask |= RADEON_RESET_CP;
  3477. if (tmp & GRBM_EE_BUSY)
  3478. reset_mask |= RADEON_RESET_GRBM | RADEON_RESET_GFX | RADEON_RESET_CP;
  3479. /* DMA_STATUS_REG */
  3480. tmp = RREG32(DMA_STATUS_REG);
  3481. if (!(tmp & DMA_IDLE))
  3482. reset_mask |= RADEON_RESET_DMA;
  3483. /* SRBM_STATUS2 */
  3484. tmp = RREG32(SRBM_STATUS2);
  3485. if (tmp & DMA_BUSY)
  3486. reset_mask |= RADEON_RESET_DMA;
  3487. /* SRBM_STATUS */
  3488. tmp = RREG32(SRBM_STATUS);
  3489. if (tmp & (RLC_RQ_PENDING | RLC_BUSY))
  3490. reset_mask |= RADEON_RESET_RLC;
  3491. if (tmp & IH_BUSY)
  3492. reset_mask |= RADEON_RESET_IH;
  3493. if (tmp & SEM_BUSY)
  3494. reset_mask |= RADEON_RESET_SEM;
  3495. if (tmp & GRBM_RQ_PENDING)
  3496. reset_mask |= RADEON_RESET_GRBM;
  3497. if (tmp & VMC_BUSY)
  3498. reset_mask |= RADEON_RESET_VMC;
  3499. if (tmp & (MCB_BUSY | MCB_NON_DISPLAY_BUSY |
  3500. MCC_BUSY | MCD_BUSY))
  3501. reset_mask |= RADEON_RESET_MC;
  3502. if (evergreen_is_display_hung(rdev))
  3503. reset_mask |= RADEON_RESET_DISPLAY;
  3504. /* VM_L2_STATUS */
  3505. tmp = RREG32(VM_L2_STATUS);
  3506. if (tmp & L2_BUSY)
  3507. reset_mask |= RADEON_RESET_VMC;
  3508. /* Skip MC reset as it's mostly likely not hung, just busy */
  3509. if (reset_mask & RADEON_RESET_MC) {
  3510. DRM_DEBUG("MC busy: 0x%08X, clearing.\n", reset_mask);
  3511. reset_mask &= ~RADEON_RESET_MC;
  3512. }
  3513. return reset_mask;
  3514. }
  3515. static void evergreen_gpu_soft_reset(struct radeon_device *rdev, u32 reset_mask)
  3516. {
  3517. struct evergreen_mc_save save;
  3518. u32 grbm_soft_reset = 0, srbm_soft_reset = 0;
  3519. u32 tmp;
  3520. if (reset_mask == 0)
  3521. return;
  3522. dev_info(rdev->dev, "GPU softreset: 0x%08X\n", reset_mask);
  3523. evergreen_print_gpu_status_regs(rdev);
  3524. /* Disable CP parsing/prefetching */
  3525. WREG32(CP_ME_CNTL, CP_ME_HALT | CP_PFP_HALT);
  3526. if (reset_mask & RADEON_RESET_DMA) {
  3527. /* Disable DMA */
  3528. tmp = RREG32(DMA_RB_CNTL);
  3529. tmp &= ~DMA_RB_ENABLE;
  3530. WREG32(DMA_RB_CNTL, tmp);
  3531. }
  3532. udelay(50);
  3533. evergreen_mc_stop(rdev, &save);
  3534. if (evergreen_mc_wait_for_idle(rdev)) {
  3535. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  3536. }
  3537. if (reset_mask & (RADEON_RESET_GFX | RADEON_RESET_COMPUTE)) {
  3538. grbm_soft_reset |= SOFT_RESET_DB |
  3539. SOFT_RESET_CB |
  3540. SOFT_RESET_PA |
  3541. SOFT_RESET_SC |
  3542. SOFT_RESET_SPI |
  3543. SOFT_RESET_SX |
  3544. SOFT_RESET_SH |
  3545. SOFT_RESET_TC |
  3546. SOFT_RESET_TA |
  3547. SOFT_RESET_VC |
  3548. SOFT_RESET_VGT;
  3549. }
  3550. if (reset_mask & RADEON_RESET_CP) {
  3551. grbm_soft_reset |= SOFT_RESET_CP |
  3552. SOFT_RESET_VGT;
  3553. srbm_soft_reset |= SOFT_RESET_GRBM;
  3554. }
  3555. if (reset_mask & RADEON_RESET_DMA)
  3556. srbm_soft_reset |= SOFT_RESET_DMA;
  3557. if (reset_mask & RADEON_RESET_DISPLAY)
  3558. srbm_soft_reset |= SOFT_RESET_DC;
  3559. if (reset_mask & RADEON_RESET_RLC)
  3560. srbm_soft_reset |= SOFT_RESET_RLC;
  3561. if (reset_mask & RADEON_RESET_SEM)
  3562. srbm_soft_reset |= SOFT_RESET_SEM;
  3563. if (reset_mask & RADEON_RESET_IH)
  3564. srbm_soft_reset |= SOFT_RESET_IH;
  3565. if (reset_mask & RADEON_RESET_GRBM)
  3566. srbm_soft_reset |= SOFT_RESET_GRBM;
  3567. if (reset_mask & RADEON_RESET_VMC)
  3568. srbm_soft_reset |= SOFT_RESET_VMC;
  3569. if (!(rdev->flags & RADEON_IS_IGP)) {
  3570. if (reset_mask & RADEON_RESET_MC)
  3571. srbm_soft_reset |= SOFT_RESET_MC;
  3572. }
  3573. if (grbm_soft_reset) {
  3574. tmp = RREG32(GRBM_SOFT_RESET);
  3575. tmp |= grbm_soft_reset;
  3576. dev_info(rdev->dev, "GRBM_SOFT_RESET=0x%08X\n", tmp);
  3577. WREG32(GRBM_SOFT_RESET, tmp);
  3578. tmp = RREG32(GRBM_SOFT_RESET);
  3579. udelay(50);
  3580. tmp &= ~grbm_soft_reset;
  3581. WREG32(GRBM_SOFT_RESET, tmp);
  3582. tmp = RREG32(GRBM_SOFT_RESET);
  3583. }
  3584. if (srbm_soft_reset) {
  3585. tmp = RREG32(SRBM_SOFT_RESET);
  3586. tmp |= srbm_soft_reset;
  3587. dev_info(rdev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
  3588. WREG32(SRBM_SOFT_RESET, tmp);
  3589. tmp = RREG32(SRBM_SOFT_RESET);
  3590. udelay(50);
  3591. tmp &= ~srbm_soft_reset;
  3592. WREG32(SRBM_SOFT_RESET, tmp);
  3593. tmp = RREG32(SRBM_SOFT_RESET);
  3594. }
  3595. /* Wait a little for things to settle down */
  3596. udelay(50);
  3597. evergreen_mc_resume(rdev, &save);
  3598. udelay(50);
  3599. evergreen_print_gpu_status_regs(rdev);
  3600. }
  3601. void evergreen_gpu_pci_config_reset(struct radeon_device *rdev)
  3602. {
  3603. struct evergreen_mc_save save;
  3604. u32 tmp, i;
  3605. dev_info(rdev->dev, "GPU pci config reset\n");
  3606. /* disable dpm? */
  3607. /* Disable CP parsing/prefetching */
  3608. WREG32(CP_ME_CNTL, CP_ME_HALT | CP_PFP_HALT);
  3609. udelay(50);
  3610. /* Disable DMA */
  3611. tmp = RREG32(DMA_RB_CNTL);
  3612. tmp &= ~DMA_RB_ENABLE;
  3613. WREG32(DMA_RB_CNTL, tmp);
  3614. /* XXX other engines? */
  3615. /* halt the rlc */
  3616. r600_rlc_stop(rdev);
  3617. udelay(50);
  3618. /* set mclk/sclk to bypass */
  3619. rv770_set_clk_bypass_mode(rdev);
  3620. /* disable BM */
  3621. pci_clear_master(rdev->pdev);
  3622. /* disable mem access */
  3623. evergreen_mc_stop(rdev, &save);
  3624. if (evergreen_mc_wait_for_idle(rdev)) {
  3625. dev_warn(rdev->dev, "Wait for MC idle timed out !\n");
  3626. }
  3627. /* reset */
  3628. radeon_pci_config_reset(rdev);
  3629. /* wait for asic to come out of reset */
  3630. for (i = 0; i < rdev->usec_timeout; i++) {
  3631. if (RREG32(CONFIG_MEMSIZE) != 0xffffffff)
  3632. break;
  3633. udelay(1);
  3634. }
  3635. }
  3636. int evergreen_asic_reset(struct radeon_device *rdev)
  3637. {
  3638. u32 reset_mask;
  3639. reset_mask = evergreen_gpu_check_soft_reset(rdev);
  3640. if (reset_mask)
  3641. r600_set_bios_scratch_engine_hung(rdev, true);
  3642. /* try soft reset */
  3643. evergreen_gpu_soft_reset(rdev, reset_mask);
  3644. reset_mask = evergreen_gpu_check_soft_reset(rdev);
  3645. /* try pci config reset */
  3646. if (reset_mask && radeon_hard_reset)
  3647. evergreen_gpu_pci_config_reset(rdev);
  3648. reset_mask = evergreen_gpu_check_soft_reset(rdev);
  3649. if (!reset_mask)
  3650. r600_set_bios_scratch_engine_hung(rdev, false);
  3651. return 0;
  3652. }
  3653. /**
  3654. * evergreen_gfx_is_lockup - Check if the GFX engine is locked up
  3655. *
  3656. * @rdev: radeon_device pointer
  3657. * @ring: radeon_ring structure holding ring information
  3658. *
  3659. * Check if the GFX engine is locked up.
  3660. * Returns true if the engine appears to be locked up, false if not.
  3661. */
  3662. bool evergreen_gfx_is_lockup(struct radeon_device *rdev, struct radeon_ring *ring)
  3663. {
  3664. u32 reset_mask = evergreen_gpu_check_soft_reset(rdev);
  3665. if (!(reset_mask & (RADEON_RESET_GFX |
  3666. RADEON_RESET_COMPUTE |
  3667. RADEON_RESET_CP))) {
  3668. radeon_ring_lockup_update(rdev, ring);
  3669. return false;
  3670. }
  3671. return radeon_ring_test_lockup(rdev, ring);
  3672. }
  3673. /*
  3674. * RLC
  3675. */
  3676. #define RLC_SAVE_RESTORE_LIST_END_MARKER 0x00000000
  3677. #define RLC_CLEAR_STATE_END_MARKER 0x00000001
  3678. void sumo_rlc_fini(struct radeon_device *rdev)
  3679. {
  3680. int r;
  3681. /* save restore block */
  3682. if (rdev->rlc.save_restore_obj) {
  3683. r = radeon_bo_reserve(rdev->rlc.save_restore_obj, false);
  3684. if (unlikely(r != 0))
  3685. dev_warn(rdev->dev, "(%d) reserve RLC sr bo failed\n", r);
  3686. radeon_bo_unpin(rdev->rlc.save_restore_obj);
  3687. radeon_bo_unreserve(rdev->rlc.save_restore_obj);
  3688. radeon_bo_unref(&rdev->rlc.save_restore_obj);
  3689. rdev->rlc.save_restore_obj = NULL;
  3690. }
  3691. /* clear state block */
  3692. if (rdev->rlc.clear_state_obj) {
  3693. r = radeon_bo_reserve(rdev->rlc.clear_state_obj, false);
  3694. if (unlikely(r != 0))
  3695. dev_warn(rdev->dev, "(%d) reserve RLC c bo failed\n", r);
  3696. radeon_bo_unpin(rdev->rlc.clear_state_obj);
  3697. radeon_bo_unreserve(rdev->rlc.clear_state_obj);
  3698. radeon_bo_unref(&rdev->rlc.clear_state_obj);
  3699. rdev->rlc.clear_state_obj = NULL;
  3700. }
  3701. /* clear state block */
  3702. if (rdev->rlc.cp_table_obj) {
  3703. r = radeon_bo_reserve(rdev->rlc.cp_table_obj, false);
  3704. if (unlikely(r != 0))
  3705. dev_warn(rdev->dev, "(%d) reserve RLC cp table bo failed\n", r);
  3706. radeon_bo_unpin(rdev->rlc.cp_table_obj);
  3707. radeon_bo_unreserve(rdev->rlc.cp_table_obj);
  3708. radeon_bo_unref(&rdev->rlc.cp_table_obj);
  3709. rdev->rlc.cp_table_obj = NULL;
  3710. }
  3711. }
  3712. #define CP_ME_TABLE_SIZE 96
  3713. int sumo_rlc_init(struct radeon_device *rdev)
  3714. {
  3715. const u32 *src_ptr;
  3716. volatile u32 *dst_ptr;
  3717. u32 dws, data, i, j, k, reg_num;
  3718. u32 reg_list_num, reg_list_hdr_blk_index, reg_list_blk_index = 0;
  3719. u64 reg_list_mc_addr;
  3720. const struct cs_section_def *cs_data;
  3721. int r;
  3722. src_ptr = rdev->rlc.reg_list;
  3723. dws = rdev->rlc.reg_list_size;
  3724. if (rdev->family >= CHIP_BONAIRE) {
  3725. dws += (5 * 16) + 48 + 48 + 64;
  3726. }
  3727. cs_data = rdev->rlc.cs_data;
  3728. if (src_ptr) {
  3729. /* save restore block */
  3730. if (rdev->rlc.save_restore_obj == NULL) {
  3731. r = radeon_bo_create(rdev, dws * 4, PAGE_SIZE, true,
  3732. RADEON_GEM_DOMAIN_VRAM, 0, NULL,
  3733. NULL, &rdev->rlc.save_restore_obj);
  3734. if (r) {
  3735. dev_warn(rdev->dev, "(%d) create RLC sr bo failed\n", r);
  3736. return r;
  3737. }
  3738. }
  3739. r = radeon_bo_reserve(rdev->rlc.save_restore_obj, false);
  3740. if (unlikely(r != 0)) {
  3741. sumo_rlc_fini(rdev);
  3742. return r;
  3743. }
  3744. r = radeon_bo_pin(rdev->rlc.save_restore_obj, RADEON_GEM_DOMAIN_VRAM,
  3745. &rdev->rlc.save_restore_gpu_addr);
  3746. if (r) {
  3747. radeon_bo_unreserve(rdev->rlc.save_restore_obj);
  3748. dev_warn(rdev->dev, "(%d) pin RLC sr bo failed\n", r);
  3749. sumo_rlc_fini(rdev);
  3750. return r;
  3751. }
  3752. r = radeon_bo_kmap(rdev->rlc.save_restore_obj, (void **)&rdev->rlc.sr_ptr);
  3753. if (r) {
  3754. dev_warn(rdev->dev, "(%d) map RLC sr bo failed\n", r);
  3755. sumo_rlc_fini(rdev);
  3756. return r;
  3757. }
  3758. /* write the sr buffer */
  3759. dst_ptr = rdev->rlc.sr_ptr;
  3760. if (rdev->family >= CHIP_TAHITI) {
  3761. /* SI */
  3762. for (i = 0; i < rdev->rlc.reg_list_size; i++)
  3763. dst_ptr[i] = cpu_to_le32(src_ptr[i]);
  3764. } else {
  3765. /* ON/LN/TN */
  3766. /* format:
  3767. * dw0: (reg2 << 16) | reg1
  3768. * dw1: reg1 save space
  3769. * dw2: reg2 save space
  3770. */
  3771. for (i = 0; i < dws; i++) {
  3772. data = src_ptr[i] >> 2;
  3773. i++;
  3774. if (i < dws)
  3775. data |= (src_ptr[i] >> 2) << 16;
  3776. j = (((i - 1) * 3) / 2);
  3777. dst_ptr[j] = cpu_to_le32(data);
  3778. }
  3779. j = ((i * 3) / 2);
  3780. dst_ptr[j] = cpu_to_le32(RLC_SAVE_RESTORE_LIST_END_MARKER);
  3781. }
  3782. radeon_bo_kunmap(rdev->rlc.save_restore_obj);
  3783. radeon_bo_unreserve(rdev->rlc.save_restore_obj);
  3784. }
  3785. if (cs_data) {
  3786. /* clear state block */
  3787. if (rdev->family >= CHIP_BONAIRE) {
  3788. rdev->rlc.clear_state_size = dws = cik_get_csb_size(rdev);
  3789. } else if (rdev->family >= CHIP_TAHITI) {
  3790. rdev->rlc.clear_state_size = si_get_csb_size(rdev);
  3791. dws = rdev->rlc.clear_state_size + (256 / 4);
  3792. } else {
  3793. reg_list_num = 0;
  3794. dws = 0;
  3795. for (i = 0; cs_data[i].section != NULL; i++) {
  3796. for (j = 0; cs_data[i].section[j].extent != NULL; j++) {
  3797. reg_list_num++;
  3798. dws += cs_data[i].section[j].reg_count;
  3799. }
  3800. }
  3801. reg_list_blk_index = (3 * reg_list_num + 2);
  3802. dws += reg_list_blk_index;
  3803. rdev->rlc.clear_state_size = dws;
  3804. }
  3805. if (rdev->rlc.clear_state_obj == NULL) {
  3806. r = radeon_bo_create(rdev, dws * 4, PAGE_SIZE, true,
  3807. RADEON_GEM_DOMAIN_VRAM, 0, NULL,
  3808. NULL, &rdev->rlc.clear_state_obj);
  3809. if (r) {
  3810. dev_warn(rdev->dev, "(%d) create RLC c bo failed\n", r);
  3811. sumo_rlc_fini(rdev);
  3812. return r;
  3813. }
  3814. }
  3815. r = radeon_bo_reserve(rdev->rlc.clear_state_obj, false);
  3816. if (unlikely(r != 0)) {
  3817. sumo_rlc_fini(rdev);
  3818. return r;
  3819. }
  3820. r = radeon_bo_pin(rdev->rlc.clear_state_obj, RADEON_GEM_DOMAIN_VRAM,
  3821. &rdev->rlc.clear_state_gpu_addr);
  3822. if (r) {
  3823. radeon_bo_unreserve(rdev->rlc.clear_state_obj);
  3824. dev_warn(rdev->dev, "(%d) pin RLC c bo failed\n", r);
  3825. sumo_rlc_fini(rdev);
  3826. return r;
  3827. }
  3828. r = radeon_bo_kmap(rdev->rlc.clear_state_obj, (void **)&rdev->rlc.cs_ptr);
  3829. if (r) {
  3830. dev_warn(rdev->dev, "(%d) map RLC c bo failed\n", r);
  3831. sumo_rlc_fini(rdev);
  3832. return r;
  3833. }
  3834. /* set up the cs buffer */
  3835. dst_ptr = rdev->rlc.cs_ptr;
  3836. if (rdev->family >= CHIP_BONAIRE) {
  3837. cik_get_csb_buffer(rdev, dst_ptr);
  3838. } else if (rdev->family >= CHIP_TAHITI) {
  3839. reg_list_mc_addr = rdev->rlc.clear_state_gpu_addr + 256;
  3840. dst_ptr[0] = cpu_to_le32(upper_32_bits(reg_list_mc_addr));
  3841. dst_ptr[1] = cpu_to_le32(lower_32_bits(reg_list_mc_addr));
  3842. dst_ptr[2] = cpu_to_le32(rdev->rlc.clear_state_size);
  3843. si_get_csb_buffer(rdev, &dst_ptr[(256/4)]);
  3844. } else {
  3845. reg_list_hdr_blk_index = 0;
  3846. reg_list_mc_addr = rdev->rlc.clear_state_gpu_addr + (reg_list_blk_index * 4);
  3847. data = upper_32_bits(reg_list_mc_addr);
  3848. dst_ptr[reg_list_hdr_blk_index] = cpu_to_le32(data);
  3849. reg_list_hdr_blk_index++;
  3850. for (i = 0; cs_data[i].section != NULL; i++) {
  3851. for (j = 0; cs_data[i].section[j].extent != NULL; j++) {
  3852. reg_num = cs_data[i].section[j].reg_count;
  3853. data = reg_list_mc_addr & 0xffffffff;
  3854. dst_ptr[reg_list_hdr_blk_index] = cpu_to_le32(data);
  3855. reg_list_hdr_blk_index++;
  3856. data = (cs_data[i].section[j].reg_index * 4) & 0xffffffff;
  3857. dst_ptr[reg_list_hdr_blk_index] = cpu_to_le32(data);
  3858. reg_list_hdr_blk_index++;
  3859. data = 0x08000000 | (reg_num * 4);
  3860. dst_ptr[reg_list_hdr_blk_index] = cpu_to_le32(data);
  3861. reg_list_hdr_blk_index++;
  3862. for (k = 0; k < reg_num; k++) {
  3863. data = cs_data[i].section[j].extent[k];
  3864. dst_ptr[reg_list_blk_index + k] = cpu_to_le32(data);
  3865. }
  3866. reg_list_mc_addr += reg_num * 4;
  3867. reg_list_blk_index += reg_num;
  3868. }
  3869. }
  3870. dst_ptr[reg_list_hdr_blk_index] = cpu_to_le32(RLC_CLEAR_STATE_END_MARKER);
  3871. }
  3872. radeon_bo_kunmap(rdev->rlc.clear_state_obj);
  3873. radeon_bo_unreserve(rdev->rlc.clear_state_obj);
  3874. }
  3875. if (rdev->rlc.cp_table_size) {
  3876. if (rdev->rlc.cp_table_obj == NULL) {
  3877. r = radeon_bo_create(rdev, rdev->rlc.cp_table_size,
  3878. PAGE_SIZE, true,
  3879. RADEON_GEM_DOMAIN_VRAM, 0, NULL,
  3880. NULL, &rdev->rlc.cp_table_obj);
  3881. if (r) {
  3882. dev_warn(rdev->dev, "(%d) create RLC cp table bo failed\n", r);
  3883. sumo_rlc_fini(rdev);
  3884. return r;
  3885. }
  3886. }
  3887. r = radeon_bo_reserve(rdev->rlc.cp_table_obj, false);
  3888. if (unlikely(r != 0)) {
  3889. dev_warn(rdev->dev, "(%d) reserve RLC cp table bo failed\n", r);
  3890. sumo_rlc_fini(rdev);
  3891. return r;
  3892. }
  3893. r = radeon_bo_pin(rdev->rlc.cp_table_obj, RADEON_GEM_DOMAIN_VRAM,
  3894. &rdev->rlc.cp_table_gpu_addr);
  3895. if (r) {
  3896. radeon_bo_unreserve(rdev->rlc.cp_table_obj);
  3897. dev_warn(rdev->dev, "(%d) pin RLC cp_table bo failed\n", r);
  3898. sumo_rlc_fini(rdev);
  3899. return r;
  3900. }
  3901. r = radeon_bo_kmap(rdev->rlc.cp_table_obj, (void **)&rdev->rlc.cp_table_ptr);
  3902. if (r) {
  3903. dev_warn(rdev->dev, "(%d) map RLC cp table bo failed\n", r);
  3904. sumo_rlc_fini(rdev);
  3905. return r;
  3906. }
  3907. cik_init_cp_pg_table(rdev);
  3908. radeon_bo_kunmap(rdev->rlc.cp_table_obj);
  3909. radeon_bo_unreserve(rdev->rlc.cp_table_obj);
  3910. }
  3911. return 0;
  3912. }
  3913. static void evergreen_rlc_start(struct radeon_device *rdev)
  3914. {
  3915. u32 mask = RLC_ENABLE;
  3916. if (rdev->flags & RADEON_IS_IGP) {
  3917. mask |= GFX_POWER_GATING_ENABLE | GFX_POWER_GATING_SRC;
  3918. }
  3919. WREG32(RLC_CNTL, mask);
  3920. }
  3921. int evergreen_rlc_resume(struct radeon_device *rdev)
  3922. {
  3923. u32 i;
  3924. const __be32 *fw_data;
  3925. if (!rdev->rlc_fw)
  3926. return -EINVAL;
  3927. r600_rlc_stop(rdev);
  3928. WREG32(RLC_HB_CNTL, 0);
  3929. if (rdev->flags & RADEON_IS_IGP) {
  3930. if (rdev->family == CHIP_ARUBA) {
  3931. u32 always_on_bitmap =
  3932. 3 | (3 << (16 * rdev->config.cayman.max_shader_engines));
  3933. /* find out the number of active simds */
  3934. u32 tmp = (RREG32(CC_GC_SHADER_PIPE_CONFIG) & 0xffff0000) >> 16;
  3935. tmp |= 0xffffffff << rdev->config.cayman.max_simds_per_se;
  3936. tmp = hweight32(~tmp);
  3937. if (tmp == rdev->config.cayman.max_simds_per_se) {
  3938. WREG32(TN_RLC_LB_ALWAYS_ACTIVE_SIMD_MASK, always_on_bitmap);
  3939. WREG32(TN_RLC_LB_PARAMS, 0x00601004);
  3940. WREG32(TN_RLC_LB_INIT_SIMD_MASK, 0xffffffff);
  3941. WREG32(TN_RLC_LB_CNTR_INIT, 0x00000000);
  3942. WREG32(TN_RLC_LB_CNTR_MAX, 0x00002000);
  3943. }
  3944. } else {
  3945. WREG32(RLC_HB_WPTR_LSB_ADDR, 0);
  3946. WREG32(RLC_HB_WPTR_MSB_ADDR, 0);
  3947. }
  3948. WREG32(TN_RLC_SAVE_AND_RESTORE_BASE, rdev->rlc.save_restore_gpu_addr >> 8);
  3949. WREG32(TN_RLC_CLEAR_STATE_RESTORE_BASE, rdev->rlc.clear_state_gpu_addr >> 8);
  3950. } else {
  3951. WREG32(RLC_HB_BASE, 0);
  3952. WREG32(RLC_HB_RPTR, 0);
  3953. WREG32(RLC_HB_WPTR, 0);
  3954. WREG32(RLC_HB_WPTR_LSB_ADDR, 0);
  3955. WREG32(RLC_HB_WPTR_MSB_ADDR, 0);
  3956. }
  3957. WREG32(RLC_MC_CNTL, 0);
  3958. WREG32(RLC_UCODE_CNTL, 0);
  3959. fw_data = (const __be32 *)rdev->rlc_fw->data;
  3960. if (rdev->family >= CHIP_ARUBA) {
  3961. for (i = 0; i < ARUBA_RLC_UCODE_SIZE; i++) {
  3962. WREG32(RLC_UCODE_ADDR, i);
  3963. WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
  3964. }
  3965. } else if (rdev->family >= CHIP_CAYMAN) {
  3966. for (i = 0; i < CAYMAN_RLC_UCODE_SIZE; i++) {
  3967. WREG32(RLC_UCODE_ADDR, i);
  3968. WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
  3969. }
  3970. } else {
  3971. for (i = 0; i < EVERGREEN_RLC_UCODE_SIZE; i++) {
  3972. WREG32(RLC_UCODE_ADDR, i);
  3973. WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
  3974. }
  3975. }
  3976. WREG32(RLC_UCODE_ADDR, 0);
  3977. evergreen_rlc_start(rdev);
  3978. return 0;
  3979. }
  3980. /* Interrupts */
  3981. u32 evergreen_get_vblank_counter(struct radeon_device *rdev, int crtc)
  3982. {
  3983. if (crtc >= rdev->num_crtc)
  3984. return 0;
  3985. else
  3986. return RREG32(CRTC_STATUS_FRAME_COUNT + crtc_offsets[crtc]);
  3987. }
  3988. void evergreen_disable_interrupt_state(struct radeon_device *rdev)
  3989. {
  3990. u32 tmp;
  3991. if (rdev->family >= CHIP_CAYMAN) {
  3992. cayman_cp_int_cntl_setup(rdev, 0,
  3993. CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
  3994. cayman_cp_int_cntl_setup(rdev, 1, 0);
  3995. cayman_cp_int_cntl_setup(rdev, 2, 0);
  3996. tmp = RREG32(CAYMAN_DMA1_CNTL) & ~TRAP_ENABLE;
  3997. WREG32(CAYMAN_DMA1_CNTL, tmp);
  3998. } else
  3999. WREG32(CP_INT_CNTL, CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
  4000. tmp = RREG32(DMA_CNTL) & ~TRAP_ENABLE;
  4001. WREG32(DMA_CNTL, tmp);
  4002. WREG32(GRBM_INT_CNTL, 0);
  4003. WREG32(SRBM_INT_CNTL, 0);
  4004. WREG32(INT_MASK + EVERGREEN_CRTC0_REGISTER_OFFSET, 0);
  4005. WREG32(INT_MASK + EVERGREEN_CRTC1_REGISTER_OFFSET, 0);
  4006. if (rdev->num_crtc >= 4) {
  4007. WREG32(INT_MASK + EVERGREEN_CRTC2_REGISTER_OFFSET, 0);
  4008. WREG32(INT_MASK + EVERGREEN_CRTC3_REGISTER_OFFSET, 0);
  4009. }
  4010. if (rdev->num_crtc >= 6) {
  4011. WREG32(INT_MASK + EVERGREEN_CRTC4_REGISTER_OFFSET, 0);
  4012. WREG32(INT_MASK + EVERGREEN_CRTC5_REGISTER_OFFSET, 0);
  4013. }
  4014. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET, 0);
  4015. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET, 0);
  4016. if (rdev->num_crtc >= 4) {
  4017. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET, 0);
  4018. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET, 0);
  4019. }
  4020. if (rdev->num_crtc >= 6) {
  4021. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET, 0);
  4022. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET, 0);
  4023. }
  4024. /* only one DAC on DCE5 */
  4025. if (!ASIC_IS_DCE5(rdev))
  4026. WREG32(DACA_AUTODETECT_INT_CONTROL, 0);
  4027. WREG32(DACB_AUTODETECT_INT_CONTROL, 0);
  4028. tmp = RREG32(DC_HPD1_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  4029. WREG32(DC_HPD1_INT_CONTROL, tmp);
  4030. tmp = RREG32(DC_HPD2_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  4031. WREG32(DC_HPD2_INT_CONTROL, tmp);
  4032. tmp = RREG32(DC_HPD3_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  4033. WREG32(DC_HPD3_INT_CONTROL, tmp);
  4034. tmp = RREG32(DC_HPD4_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  4035. WREG32(DC_HPD4_INT_CONTROL, tmp);
  4036. tmp = RREG32(DC_HPD5_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  4037. WREG32(DC_HPD5_INT_CONTROL, tmp);
  4038. tmp = RREG32(DC_HPD6_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  4039. WREG32(DC_HPD6_INT_CONTROL, tmp);
  4040. }
  4041. int evergreen_irq_set(struct radeon_device *rdev)
  4042. {
  4043. u32 cp_int_cntl = CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE;
  4044. u32 cp_int_cntl1 = 0, cp_int_cntl2 = 0;
  4045. u32 crtc1 = 0, crtc2 = 0, crtc3 = 0, crtc4 = 0, crtc5 = 0, crtc6 = 0;
  4046. u32 hpd1, hpd2, hpd3, hpd4, hpd5, hpd6;
  4047. u32 grbm_int_cntl = 0;
  4048. u32 afmt1 = 0, afmt2 = 0, afmt3 = 0, afmt4 = 0, afmt5 = 0, afmt6 = 0;
  4049. u32 dma_cntl, dma_cntl1 = 0;
  4050. u32 thermal_int = 0;
  4051. if (!rdev->irq.installed) {
  4052. WARN(1, "Can't enable IRQ/MSI because no handler is installed\n");
  4053. return -EINVAL;
  4054. }
  4055. /* don't enable anything if the ih is disabled */
  4056. if (!rdev->ih.enabled) {
  4057. r600_disable_interrupts(rdev);
  4058. /* force the active interrupt state to all disabled */
  4059. evergreen_disable_interrupt_state(rdev);
  4060. return 0;
  4061. }
  4062. hpd1 = RREG32(DC_HPD1_INT_CONTROL) & ~(DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN);
  4063. hpd2 = RREG32(DC_HPD2_INT_CONTROL) & ~(DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN);
  4064. hpd3 = RREG32(DC_HPD3_INT_CONTROL) & ~(DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN);
  4065. hpd4 = RREG32(DC_HPD4_INT_CONTROL) & ~(DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN);
  4066. hpd5 = RREG32(DC_HPD5_INT_CONTROL) & ~(DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN);
  4067. hpd6 = RREG32(DC_HPD6_INT_CONTROL) & ~(DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN);
  4068. if (rdev->family == CHIP_ARUBA)
  4069. thermal_int = RREG32(TN_CG_THERMAL_INT_CTRL) &
  4070. ~(THERM_INT_MASK_HIGH | THERM_INT_MASK_LOW);
  4071. else
  4072. thermal_int = RREG32(CG_THERMAL_INT) &
  4073. ~(THERM_INT_MASK_HIGH | THERM_INT_MASK_LOW);
  4074. afmt1 = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET) & ~AFMT_AZ_FORMAT_WTRIG_MASK;
  4075. afmt2 = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET) & ~AFMT_AZ_FORMAT_WTRIG_MASK;
  4076. afmt3 = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET) & ~AFMT_AZ_FORMAT_WTRIG_MASK;
  4077. afmt4 = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET) & ~AFMT_AZ_FORMAT_WTRIG_MASK;
  4078. afmt5 = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET) & ~AFMT_AZ_FORMAT_WTRIG_MASK;
  4079. afmt6 = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET) & ~AFMT_AZ_FORMAT_WTRIG_MASK;
  4080. dma_cntl = RREG32(DMA_CNTL) & ~TRAP_ENABLE;
  4081. if (rdev->family >= CHIP_CAYMAN) {
  4082. /* enable CP interrupts on all rings */
  4083. if (atomic_read(&rdev->irq.ring_int[RADEON_RING_TYPE_GFX_INDEX])) {
  4084. DRM_DEBUG("evergreen_irq_set: sw int gfx\n");
  4085. cp_int_cntl |= TIME_STAMP_INT_ENABLE;
  4086. }
  4087. if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_CP1_INDEX])) {
  4088. DRM_DEBUG("evergreen_irq_set: sw int cp1\n");
  4089. cp_int_cntl1 |= TIME_STAMP_INT_ENABLE;
  4090. }
  4091. if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_CP2_INDEX])) {
  4092. DRM_DEBUG("evergreen_irq_set: sw int cp2\n");
  4093. cp_int_cntl2 |= TIME_STAMP_INT_ENABLE;
  4094. }
  4095. } else {
  4096. if (atomic_read(&rdev->irq.ring_int[RADEON_RING_TYPE_GFX_INDEX])) {
  4097. DRM_DEBUG("evergreen_irq_set: sw int gfx\n");
  4098. cp_int_cntl |= RB_INT_ENABLE;
  4099. cp_int_cntl |= TIME_STAMP_INT_ENABLE;
  4100. }
  4101. }
  4102. if (atomic_read(&rdev->irq.ring_int[R600_RING_TYPE_DMA_INDEX])) {
  4103. DRM_DEBUG("r600_irq_set: sw int dma\n");
  4104. dma_cntl |= TRAP_ENABLE;
  4105. }
  4106. if (rdev->family >= CHIP_CAYMAN) {
  4107. dma_cntl1 = RREG32(CAYMAN_DMA1_CNTL) & ~TRAP_ENABLE;
  4108. if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_DMA1_INDEX])) {
  4109. DRM_DEBUG("r600_irq_set: sw int dma1\n");
  4110. dma_cntl1 |= TRAP_ENABLE;
  4111. }
  4112. }
  4113. if (rdev->irq.dpm_thermal) {
  4114. DRM_DEBUG("dpm thermal\n");
  4115. thermal_int |= THERM_INT_MASK_HIGH | THERM_INT_MASK_LOW;
  4116. }
  4117. if (rdev->irq.crtc_vblank_int[0] ||
  4118. atomic_read(&rdev->irq.pflip[0])) {
  4119. DRM_DEBUG("evergreen_irq_set: vblank 0\n");
  4120. crtc1 |= VBLANK_INT_MASK;
  4121. }
  4122. if (rdev->irq.crtc_vblank_int[1] ||
  4123. atomic_read(&rdev->irq.pflip[1])) {
  4124. DRM_DEBUG("evergreen_irq_set: vblank 1\n");
  4125. crtc2 |= VBLANK_INT_MASK;
  4126. }
  4127. if (rdev->irq.crtc_vblank_int[2] ||
  4128. atomic_read(&rdev->irq.pflip[2])) {
  4129. DRM_DEBUG("evergreen_irq_set: vblank 2\n");
  4130. crtc3 |= VBLANK_INT_MASK;
  4131. }
  4132. if (rdev->irq.crtc_vblank_int[3] ||
  4133. atomic_read(&rdev->irq.pflip[3])) {
  4134. DRM_DEBUG("evergreen_irq_set: vblank 3\n");
  4135. crtc4 |= VBLANK_INT_MASK;
  4136. }
  4137. if (rdev->irq.crtc_vblank_int[4] ||
  4138. atomic_read(&rdev->irq.pflip[4])) {
  4139. DRM_DEBUG("evergreen_irq_set: vblank 4\n");
  4140. crtc5 |= VBLANK_INT_MASK;
  4141. }
  4142. if (rdev->irq.crtc_vblank_int[5] ||
  4143. atomic_read(&rdev->irq.pflip[5])) {
  4144. DRM_DEBUG("evergreen_irq_set: vblank 5\n");
  4145. crtc6 |= VBLANK_INT_MASK;
  4146. }
  4147. if (rdev->irq.hpd[0]) {
  4148. DRM_DEBUG("evergreen_irq_set: hpd 1\n");
  4149. hpd1 |= DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN;
  4150. }
  4151. if (rdev->irq.hpd[1]) {
  4152. DRM_DEBUG("evergreen_irq_set: hpd 2\n");
  4153. hpd2 |= DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN;
  4154. }
  4155. if (rdev->irq.hpd[2]) {
  4156. DRM_DEBUG("evergreen_irq_set: hpd 3\n");
  4157. hpd3 |= DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN;
  4158. }
  4159. if (rdev->irq.hpd[3]) {
  4160. DRM_DEBUG("evergreen_irq_set: hpd 4\n");
  4161. hpd4 |= DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN;
  4162. }
  4163. if (rdev->irq.hpd[4]) {
  4164. DRM_DEBUG("evergreen_irq_set: hpd 5\n");
  4165. hpd5 |= DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN;
  4166. }
  4167. if (rdev->irq.hpd[5]) {
  4168. DRM_DEBUG("evergreen_irq_set: hpd 6\n");
  4169. hpd6 |= DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN;
  4170. }
  4171. if (rdev->irq.afmt[0]) {
  4172. DRM_DEBUG("evergreen_irq_set: hdmi 0\n");
  4173. afmt1 |= AFMT_AZ_FORMAT_WTRIG_MASK;
  4174. }
  4175. if (rdev->irq.afmt[1]) {
  4176. DRM_DEBUG("evergreen_irq_set: hdmi 1\n");
  4177. afmt2 |= AFMT_AZ_FORMAT_WTRIG_MASK;
  4178. }
  4179. if (rdev->irq.afmt[2]) {
  4180. DRM_DEBUG("evergreen_irq_set: hdmi 2\n");
  4181. afmt3 |= AFMT_AZ_FORMAT_WTRIG_MASK;
  4182. }
  4183. if (rdev->irq.afmt[3]) {
  4184. DRM_DEBUG("evergreen_irq_set: hdmi 3\n");
  4185. afmt4 |= AFMT_AZ_FORMAT_WTRIG_MASK;
  4186. }
  4187. if (rdev->irq.afmt[4]) {
  4188. DRM_DEBUG("evergreen_irq_set: hdmi 4\n");
  4189. afmt5 |= AFMT_AZ_FORMAT_WTRIG_MASK;
  4190. }
  4191. if (rdev->irq.afmt[5]) {
  4192. DRM_DEBUG("evergreen_irq_set: hdmi 5\n");
  4193. afmt6 |= AFMT_AZ_FORMAT_WTRIG_MASK;
  4194. }
  4195. if (rdev->family >= CHIP_CAYMAN) {
  4196. cayman_cp_int_cntl_setup(rdev, 0, cp_int_cntl);
  4197. cayman_cp_int_cntl_setup(rdev, 1, cp_int_cntl1);
  4198. cayman_cp_int_cntl_setup(rdev, 2, cp_int_cntl2);
  4199. } else
  4200. WREG32(CP_INT_CNTL, cp_int_cntl);
  4201. WREG32(DMA_CNTL, dma_cntl);
  4202. if (rdev->family >= CHIP_CAYMAN)
  4203. WREG32(CAYMAN_DMA1_CNTL, dma_cntl1);
  4204. WREG32(GRBM_INT_CNTL, grbm_int_cntl);
  4205. WREG32(INT_MASK + EVERGREEN_CRTC0_REGISTER_OFFSET, crtc1);
  4206. WREG32(INT_MASK + EVERGREEN_CRTC1_REGISTER_OFFSET, crtc2);
  4207. if (rdev->num_crtc >= 4) {
  4208. WREG32(INT_MASK + EVERGREEN_CRTC2_REGISTER_OFFSET, crtc3);
  4209. WREG32(INT_MASK + EVERGREEN_CRTC3_REGISTER_OFFSET, crtc4);
  4210. }
  4211. if (rdev->num_crtc >= 6) {
  4212. WREG32(INT_MASK + EVERGREEN_CRTC4_REGISTER_OFFSET, crtc5);
  4213. WREG32(INT_MASK + EVERGREEN_CRTC5_REGISTER_OFFSET, crtc6);
  4214. }
  4215. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET,
  4216. GRPH_PFLIP_INT_MASK);
  4217. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET,
  4218. GRPH_PFLIP_INT_MASK);
  4219. if (rdev->num_crtc >= 4) {
  4220. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET,
  4221. GRPH_PFLIP_INT_MASK);
  4222. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET,
  4223. GRPH_PFLIP_INT_MASK);
  4224. }
  4225. if (rdev->num_crtc >= 6) {
  4226. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET,
  4227. GRPH_PFLIP_INT_MASK);
  4228. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET,
  4229. GRPH_PFLIP_INT_MASK);
  4230. }
  4231. WREG32(DC_HPD1_INT_CONTROL, hpd1);
  4232. WREG32(DC_HPD2_INT_CONTROL, hpd2);
  4233. WREG32(DC_HPD3_INT_CONTROL, hpd3);
  4234. WREG32(DC_HPD4_INT_CONTROL, hpd4);
  4235. WREG32(DC_HPD5_INT_CONTROL, hpd5);
  4236. WREG32(DC_HPD6_INT_CONTROL, hpd6);
  4237. if (rdev->family == CHIP_ARUBA)
  4238. WREG32(TN_CG_THERMAL_INT_CTRL, thermal_int);
  4239. else
  4240. WREG32(CG_THERMAL_INT, thermal_int);
  4241. WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET, afmt1);
  4242. WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET, afmt2);
  4243. WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET, afmt3);
  4244. WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET, afmt4);
  4245. WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET, afmt5);
  4246. WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET, afmt6);
  4247. /* posting read */
  4248. RREG32(SRBM_STATUS);
  4249. return 0;
  4250. }
  4251. static void evergreen_irq_ack(struct radeon_device *rdev)
  4252. {
  4253. u32 tmp;
  4254. rdev->irq.stat_regs.evergreen.disp_int = RREG32(DISP_INTERRUPT_STATUS);
  4255. rdev->irq.stat_regs.evergreen.disp_int_cont = RREG32(DISP_INTERRUPT_STATUS_CONTINUE);
  4256. rdev->irq.stat_regs.evergreen.disp_int_cont2 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE2);
  4257. rdev->irq.stat_regs.evergreen.disp_int_cont3 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE3);
  4258. rdev->irq.stat_regs.evergreen.disp_int_cont4 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE4);
  4259. rdev->irq.stat_regs.evergreen.disp_int_cont5 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE5);
  4260. rdev->irq.stat_regs.evergreen.d1grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET);
  4261. rdev->irq.stat_regs.evergreen.d2grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET);
  4262. if (rdev->num_crtc >= 4) {
  4263. rdev->irq.stat_regs.evergreen.d3grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET);
  4264. rdev->irq.stat_regs.evergreen.d4grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET);
  4265. }
  4266. if (rdev->num_crtc >= 6) {
  4267. rdev->irq.stat_regs.evergreen.d5grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET);
  4268. rdev->irq.stat_regs.evergreen.d6grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET);
  4269. }
  4270. rdev->irq.stat_regs.evergreen.afmt_status1 = RREG32(AFMT_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET);
  4271. rdev->irq.stat_regs.evergreen.afmt_status2 = RREG32(AFMT_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET);
  4272. rdev->irq.stat_regs.evergreen.afmt_status3 = RREG32(AFMT_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET);
  4273. rdev->irq.stat_regs.evergreen.afmt_status4 = RREG32(AFMT_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET);
  4274. rdev->irq.stat_regs.evergreen.afmt_status5 = RREG32(AFMT_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET);
  4275. rdev->irq.stat_regs.evergreen.afmt_status6 = RREG32(AFMT_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET);
  4276. if (rdev->irq.stat_regs.evergreen.d1grph_int & GRPH_PFLIP_INT_OCCURRED)
  4277. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  4278. if (rdev->irq.stat_regs.evergreen.d2grph_int & GRPH_PFLIP_INT_OCCURRED)
  4279. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  4280. if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VBLANK_INTERRUPT)
  4281. WREG32(VBLANK_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, VBLANK_ACK);
  4282. if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VLINE_INTERRUPT)
  4283. WREG32(VLINE_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, VLINE_ACK);
  4284. if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VBLANK_INTERRUPT)
  4285. WREG32(VBLANK_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, VBLANK_ACK);
  4286. if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VLINE_INTERRUPT)
  4287. WREG32(VLINE_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, VLINE_ACK);
  4288. if (rdev->num_crtc >= 4) {
  4289. if (rdev->irq.stat_regs.evergreen.d3grph_int & GRPH_PFLIP_INT_OCCURRED)
  4290. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  4291. if (rdev->irq.stat_regs.evergreen.d4grph_int & GRPH_PFLIP_INT_OCCURRED)
  4292. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  4293. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VBLANK_INTERRUPT)
  4294. WREG32(VBLANK_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, VBLANK_ACK);
  4295. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VLINE_INTERRUPT)
  4296. WREG32(VLINE_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, VLINE_ACK);
  4297. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VBLANK_INTERRUPT)
  4298. WREG32(VBLANK_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, VBLANK_ACK);
  4299. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VLINE_INTERRUPT)
  4300. WREG32(VLINE_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, VLINE_ACK);
  4301. }
  4302. if (rdev->num_crtc >= 6) {
  4303. if (rdev->irq.stat_regs.evergreen.d5grph_int & GRPH_PFLIP_INT_OCCURRED)
  4304. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  4305. if (rdev->irq.stat_regs.evergreen.d6grph_int & GRPH_PFLIP_INT_OCCURRED)
  4306. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  4307. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VBLANK_INTERRUPT)
  4308. WREG32(VBLANK_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, VBLANK_ACK);
  4309. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VLINE_INTERRUPT)
  4310. WREG32(VLINE_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, VLINE_ACK);
  4311. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VBLANK_INTERRUPT)
  4312. WREG32(VBLANK_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, VBLANK_ACK);
  4313. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VLINE_INTERRUPT)
  4314. WREG32(VLINE_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, VLINE_ACK);
  4315. }
  4316. if (rdev->irq.stat_regs.evergreen.disp_int & DC_HPD1_INTERRUPT) {
  4317. tmp = RREG32(DC_HPD1_INT_CONTROL);
  4318. tmp |= DC_HPDx_INT_ACK;
  4319. WREG32(DC_HPD1_INT_CONTROL, tmp);
  4320. }
  4321. if (rdev->irq.stat_regs.evergreen.disp_int_cont & DC_HPD2_INTERRUPT) {
  4322. tmp = RREG32(DC_HPD2_INT_CONTROL);
  4323. tmp |= DC_HPDx_INT_ACK;
  4324. WREG32(DC_HPD2_INT_CONTROL, tmp);
  4325. }
  4326. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & DC_HPD3_INTERRUPT) {
  4327. tmp = RREG32(DC_HPD3_INT_CONTROL);
  4328. tmp |= DC_HPDx_INT_ACK;
  4329. WREG32(DC_HPD3_INT_CONTROL, tmp);
  4330. }
  4331. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & DC_HPD4_INTERRUPT) {
  4332. tmp = RREG32(DC_HPD4_INT_CONTROL);
  4333. tmp |= DC_HPDx_INT_ACK;
  4334. WREG32(DC_HPD4_INT_CONTROL, tmp);
  4335. }
  4336. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & DC_HPD5_INTERRUPT) {
  4337. tmp = RREG32(DC_HPD5_INT_CONTROL);
  4338. tmp |= DC_HPDx_INT_ACK;
  4339. WREG32(DC_HPD5_INT_CONTROL, tmp);
  4340. }
  4341. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & DC_HPD6_INTERRUPT) {
  4342. tmp = RREG32(DC_HPD5_INT_CONTROL);
  4343. tmp |= DC_HPDx_INT_ACK;
  4344. WREG32(DC_HPD6_INT_CONTROL, tmp);
  4345. }
  4346. if (rdev->irq.stat_regs.evergreen.disp_int & DC_HPD1_RX_INTERRUPT) {
  4347. tmp = RREG32(DC_HPD1_INT_CONTROL);
  4348. tmp |= DC_HPDx_RX_INT_ACK;
  4349. WREG32(DC_HPD1_INT_CONTROL, tmp);
  4350. }
  4351. if (rdev->irq.stat_regs.evergreen.disp_int_cont & DC_HPD2_RX_INTERRUPT) {
  4352. tmp = RREG32(DC_HPD2_INT_CONTROL);
  4353. tmp |= DC_HPDx_RX_INT_ACK;
  4354. WREG32(DC_HPD2_INT_CONTROL, tmp);
  4355. }
  4356. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & DC_HPD3_RX_INTERRUPT) {
  4357. tmp = RREG32(DC_HPD3_INT_CONTROL);
  4358. tmp |= DC_HPDx_RX_INT_ACK;
  4359. WREG32(DC_HPD3_INT_CONTROL, tmp);
  4360. }
  4361. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & DC_HPD4_RX_INTERRUPT) {
  4362. tmp = RREG32(DC_HPD4_INT_CONTROL);
  4363. tmp |= DC_HPDx_RX_INT_ACK;
  4364. WREG32(DC_HPD4_INT_CONTROL, tmp);
  4365. }
  4366. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & DC_HPD5_RX_INTERRUPT) {
  4367. tmp = RREG32(DC_HPD5_INT_CONTROL);
  4368. tmp |= DC_HPDx_RX_INT_ACK;
  4369. WREG32(DC_HPD5_INT_CONTROL, tmp);
  4370. }
  4371. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & DC_HPD6_RX_INTERRUPT) {
  4372. tmp = RREG32(DC_HPD5_INT_CONTROL);
  4373. tmp |= DC_HPDx_RX_INT_ACK;
  4374. WREG32(DC_HPD6_INT_CONTROL, tmp);
  4375. }
  4376. if (rdev->irq.stat_regs.evergreen.afmt_status1 & AFMT_AZ_FORMAT_WTRIG) {
  4377. tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET);
  4378. tmp |= AFMT_AZ_FORMAT_WTRIG_ACK;
  4379. WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET, tmp);
  4380. }
  4381. if (rdev->irq.stat_regs.evergreen.afmt_status2 & AFMT_AZ_FORMAT_WTRIG) {
  4382. tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET);
  4383. tmp |= AFMT_AZ_FORMAT_WTRIG_ACK;
  4384. WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET, tmp);
  4385. }
  4386. if (rdev->irq.stat_regs.evergreen.afmt_status3 & AFMT_AZ_FORMAT_WTRIG) {
  4387. tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET);
  4388. tmp |= AFMT_AZ_FORMAT_WTRIG_ACK;
  4389. WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET, tmp);
  4390. }
  4391. if (rdev->irq.stat_regs.evergreen.afmt_status4 & AFMT_AZ_FORMAT_WTRIG) {
  4392. tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET);
  4393. tmp |= AFMT_AZ_FORMAT_WTRIG_ACK;
  4394. WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET, tmp);
  4395. }
  4396. if (rdev->irq.stat_regs.evergreen.afmt_status5 & AFMT_AZ_FORMAT_WTRIG) {
  4397. tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET);
  4398. tmp |= AFMT_AZ_FORMAT_WTRIG_ACK;
  4399. WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET, tmp);
  4400. }
  4401. if (rdev->irq.stat_regs.evergreen.afmt_status6 & AFMT_AZ_FORMAT_WTRIG) {
  4402. tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET);
  4403. tmp |= AFMT_AZ_FORMAT_WTRIG_ACK;
  4404. WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET, tmp);
  4405. }
  4406. }
  4407. static void evergreen_irq_disable(struct radeon_device *rdev)
  4408. {
  4409. r600_disable_interrupts(rdev);
  4410. /* Wait and acknowledge irq */
  4411. mdelay(1);
  4412. evergreen_irq_ack(rdev);
  4413. evergreen_disable_interrupt_state(rdev);
  4414. }
  4415. void evergreen_irq_suspend(struct radeon_device *rdev)
  4416. {
  4417. evergreen_irq_disable(rdev);
  4418. r600_rlc_stop(rdev);
  4419. }
  4420. static u32 evergreen_get_ih_wptr(struct radeon_device *rdev)
  4421. {
  4422. u32 wptr, tmp;
  4423. if (rdev->wb.enabled)
  4424. wptr = le32_to_cpu(rdev->wb.wb[R600_WB_IH_WPTR_OFFSET/4]);
  4425. else
  4426. wptr = RREG32(IH_RB_WPTR);
  4427. if (wptr & RB_OVERFLOW) {
  4428. wptr &= ~RB_OVERFLOW;
  4429. /* When a ring buffer overflow happen start parsing interrupt
  4430. * from the last not overwritten vector (wptr + 16). Hopefully
  4431. * this should allow us to catchup.
  4432. */
  4433. dev_warn(rdev->dev, "IH ring buffer overflow (0x%08X, 0x%08X, 0x%08X)\n",
  4434. wptr, rdev->ih.rptr, (wptr + 16) & rdev->ih.ptr_mask);
  4435. rdev->ih.rptr = (wptr + 16) & rdev->ih.ptr_mask;
  4436. tmp = RREG32(IH_RB_CNTL);
  4437. tmp |= IH_WPTR_OVERFLOW_CLEAR;
  4438. WREG32(IH_RB_CNTL, tmp);
  4439. }
  4440. return (wptr & rdev->ih.ptr_mask);
  4441. }
  4442. int evergreen_irq_process(struct radeon_device *rdev)
  4443. {
  4444. u32 wptr;
  4445. u32 rptr;
  4446. u32 src_id, src_data;
  4447. u32 ring_index;
  4448. bool queue_hotplug = false;
  4449. bool queue_hdmi = false;
  4450. bool queue_dp = false;
  4451. bool queue_thermal = false;
  4452. u32 status, addr;
  4453. if (!rdev->ih.enabled || rdev->shutdown)
  4454. return IRQ_NONE;
  4455. wptr = evergreen_get_ih_wptr(rdev);
  4456. restart_ih:
  4457. /* is somebody else already processing irqs? */
  4458. if (atomic_xchg(&rdev->ih.lock, 1))
  4459. return IRQ_NONE;
  4460. rptr = rdev->ih.rptr;
  4461. DRM_DEBUG("r600_irq_process start: rptr %d, wptr %d\n", rptr, wptr);
  4462. /* Order reading of wptr vs. reading of IH ring data */
  4463. rmb();
  4464. /* display interrupts */
  4465. evergreen_irq_ack(rdev);
  4466. while (rptr != wptr) {
  4467. /* wptr/rptr are in bytes! */
  4468. ring_index = rptr / 4;
  4469. src_id = le32_to_cpu(rdev->ih.ring[ring_index]) & 0xff;
  4470. src_data = le32_to_cpu(rdev->ih.ring[ring_index + 1]) & 0xfffffff;
  4471. switch (src_id) {
  4472. case 1: /* D1 vblank/vline */
  4473. switch (src_data) {
  4474. case 0: /* D1 vblank */
  4475. if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VBLANK_INTERRUPT) {
  4476. if (rdev->irq.crtc_vblank_int[0]) {
  4477. drm_handle_vblank(rdev->ddev, 0);
  4478. rdev->pm.vblank_sync = true;
  4479. wake_up(&rdev->irq.vblank_queue);
  4480. }
  4481. if (atomic_read(&rdev->irq.pflip[0]))
  4482. radeon_crtc_handle_vblank(rdev, 0);
  4483. rdev->irq.stat_regs.evergreen.disp_int &= ~LB_D1_VBLANK_INTERRUPT;
  4484. DRM_DEBUG("IH: D1 vblank\n");
  4485. }
  4486. break;
  4487. case 1: /* D1 vline */
  4488. if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VLINE_INTERRUPT) {
  4489. rdev->irq.stat_regs.evergreen.disp_int &= ~LB_D1_VLINE_INTERRUPT;
  4490. DRM_DEBUG("IH: D1 vline\n");
  4491. }
  4492. break;
  4493. default:
  4494. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4495. break;
  4496. }
  4497. break;
  4498. case 2: /* D2 vblank/vline */
  4499. switch (src_data) {
  4500. case 0: /* D2 vblank */
  4501. if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VBLANK_INTERRUPT) {
  4502. if (rdev->irq.crtc_vblank_int[1]) {
  4503. drm_handle_vblank(rdev->ddev, 1);
  4504. rdev->pm.vblank_sync = true;
  4505. wake_up(&rdev->irq.vblank_queue);
  4506. }
  4507. if (atomic_read(&rdev->irq.pflip[1]))
  4508. radeon_crtc_handle_vblank(rdev, 1);
  4509. rdev->irq.stat_regs.evergreen.disp_int_cont &= ~LB_D2_VBLANK_INTERRUPT;
  4510. DRM_DEBUG("IH: D2 vblank\n");
  4511. }
  4512. break;
  4513. case 1: /* D2 vline */
  4514. if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VLINE_INTERRUPT) {
  4515. rdev->irq.stat_regs.evergreen.disp_int_cont &= ~LB_D2_VLINE_INTERRUPT;
  4516. DRM_DEBUG("IH: D2 vline\n");
  4517. }
  4518. break;
  4519. default:
  4520. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4521. break;
  4522. }
  4523. break;
  4524. case 3: /* D3 vblank/vline */
  4525. switch (src_data) {
  4526. case 0: /* D3 vblank */
  4527. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VBLANK_INTERRUPT) {
  4528. if (rdev->irq.crtc_vblank_int[2]) {
  4529. drm_handle_vblank(rdev->ddev, 2);
  4530. rdev->pm.vblank_sync = true;
  4531. wake_up(&rdev->irq.vblank_queue);
  4532. }
  4533. if (atomic_read(&rdev->irq.pflip[2]))
  4534. radeon_crtc_handle_vblank(rdev, 2);
  4535. rdev->irq.stat_regs.evergreen.disp_int_cont2 &= ~LB_D3_VBLANK_INTERRUPT;
  4536. DRM_DEBUG("IH: D3 vblank\n");
  4537. }
  4538. break;
  4539. case 1: /* D3 vline */
  4540. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VLINE_INTERRUPT) {
  4541. rdev->irq.stat_regs.evergreen.disp_int_cont2 &= ~LB_D3_VLINE_INTERRUPT;
  4542. DRM_DEBUG("IH: D3 vline\n");
  4543. }
  4544. break;
  4545. default:
  4546. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4547. break;
  4548. }
  4549. break;
  4550. case 4: /* D4 vblank/vline */
  4551. switch (src_data) {
  4552. case 0: /* D4 vblank */
  4553. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VBLANK_INTERRUPT) {
  4554. if (rdev->irq.crtc_vblank_int[3]) {
  4555. drm_handle_vblank(rdev->ddev, 3);
  4556. rdev->pm.vblank_sync = true;
  4557. wake_up(&rdev->irq.vblank_queue);
  4558. }
  4559. if (atomic_read(&rdev->irq.pflip[3]))
  4560. radeon_crtc_handle_vblank(rdev, 3);
  4561. rdev->irq.stat_regs.evergreen.disp_int_cont3 &= ~LB_D4_VBLANK_INTERRUPT;
  4562. DRM_DEBUG("IH: D4 vblank\n");
  4563. }
  4564. break;
  4565. case 1: /* D4 vline */
  4566. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VLINE_INTERRUPT) {
  4567. rdev->irq.stat_regs.evergreen.disp_int_cont3 &= ~LB_D4_VLINE_INTERRUPT;
  4568. DRM_DEBUG("IH: D4 vline\n");
  4569. }
  4570. break;
  4571. default:
  4572. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4573. break;
  4574. }
  4575. break;
  4576. case 5: /* D5 vblank/vline */
  4577. switch (src_data) {
  4578. case 0: /* D5 vblank */
  4579. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VBLANK_INTERRUPT) {
  4580. if (rdev->irq.crtc_vblank_int[4]) {
  4581. drm_handle_vblank(rdev->ddev, 4);
  4582. rdev->pm.vblank_sync = true;
  4583. wake_up(&rdev->irq.vblank_queue);
  4584. }
  4585. if (atomic_read(&rdev->irq.pflip[4]))
  4586. radeon_crtc_handle_vblank(rdev, 4);
  4587. rdev->irq.stat_regs.evergreen.disp_int_cont4 &= ~LB_D5_VBLANK_INTERRUPT;
  4588. DRM_DEBUG("IH: D5 vblank\n");
  4589. }
  4590. break;
  4591. case 1: /* D5 vline */
  4592. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VLINE_INTERRUPT) {
  4593. rdev->irq.stat_regs.evergreen.disp_int_cont4 &= ~LB_D5_VLINE_INTERRUPT;
  4594. DRM_DEBUG("IH: D5 vline\n");
  4595. }
  4596. break;
  4597. default:
  4598. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4599. break;
  4600. }
  4601. break;
  4602. case 6: /* D6 vblank/vline */
  4603. switch (src_data) {
  4604. case 0: /* D6 vblank */
  4605. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VBLANK_INTERRUPT) {
  4606. if (rdev->irq.crtc_vblank_int[5]) {
  4607. drm_handle_vblank(rdev->ddev, 5);
  4608. rdev->pm.vblank_sync = true;
  4609. wake_up(&rdev->irq.vblank_queue);
  4610. }
  4611. if (atomic_read(&rdev->irq.pflip[5]))
  4612. radeon_crtc_handle_vblank(rdev, 5);
  4613. rdev->irq.stat_regs.evergreen.disp_int_cont5 &= ~LB_D6_VBLANK_INTERRUPT;
  4614. DRM_DEBUG("IH: D6 vblank\n");
  4615. }
  4616. break;
  4617. case 1: /* D6 vline */
  4618. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VLINE_INTERRUPT) {
  4619. rdev->irq.stat_regs.evergreen.disp_int_cont5 &= ~LB_D6_VLINE_INTERRUPT;
  4620. DRM_DEBUG("IH: D6 vline\n");
  4621. }
  4622. break;
  4623. default:
  4624. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4625. break;
  4626. }
  4627. break;
  4628. case 8: /* D1 page flip */
  4629. case 10: /* D2 page flip */
  4630. case 12: /* D3 page flip */
  4631. case 14: /* D4 page flip */
  4632. case 16: /* D5 page flip */
  4633. case 18: /* D6 page flip */
  4634. DRM_DEBUG("IH: D%d flip\n", ((src_id - 8) >> 1) + 1);
  4635. if (radeon_use_pflipirq > 0)
  4636. radeon_crtc_handle_flip(rdev, (src_id - 8) >> 1);
  4637. break;
  4638. case 42: /* HPD hotplug */
  4639. switch (src_data) {
  4640. case 0:
  4641. if (rdev->irq.stat_regs.evergreen.disp_int & DC_HPD1_INTERRUPT) {
  4642. rdev->irq.stat_regs.evergreen.disp_int &= ~DC_HPD1_INTERRUPT;
  4643. queue_hotplug = true;
  4644. DRM_DEBUG("IH: HPD1\n");
  4645. }
  4646. break;
  4647. case 1:
  4648. if (rdev->irq.stat_regs.evergreen.disp_int_cont & DC_HPD2_INTERRUPT) {
  4649. rdev->irq.stat_regs.evergreen.disp_int_cont &= ~DC_HPD2_INTERRUPT;
  4650. queue_hotplug = true;
  4651. DRM_DEBUG("IH: HPD2\n");
  4652. }
  4653. break;
  4654. case 2:
  4655. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & DC_HPD3_INTERRUPT) {
  4656. rdev->irq.stat_regs.evergreen.disp_int_cont2 &= ~DC_HPD3_INTERRUPT;
  4657. queue_hotplug = true;
  4658. DRM_DEBUG("IH: HPD3\n");
  4659. }
  4660. break;
  4661. case 3:
  4662. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & DC_HPD4_INTERRUPT) {
  4663. rdev->irq.stat_regs.evergreen.disp_int_cont3 &= ~DC_HPD4_INTERRUPT;
  4664. queue_hotplug = true;
  4665. DRM_DEBUG("IH: HPD4\n");
  4666. }
  4667. break;
  4668. case 4:
  4669. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & DC_HPD5_INTERRUPT) {
  4670. rdev->irq.stat_regs.evergreen.disp_int_cont4 &= ~DC_HPD5_INTERRUPT;
  4671. queue_hotplug = true;
  4672. DRM_DEBUG("IH: HPD5\n");
  4673. }
  4674. break;
  4675. case 5:
  4676. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & DC_HPD6_INTERRUPT) {
  4677. rdev->irq.stat_regs.evergreen.disp_int_cont5 &= ~DC_HPD6_INTERRUPT;
  4678. queue_hotplug = true;
  4679. DRM_DEBUG("IH: HPD6\n");
  4680. }
  4681. break;
  4682. case 6:
  4683. if (rdev->irq.stat_regs.evergreen.disp_int & DC_HPD1_RX_INTERRUPT) {
  4684. rdev->irq.stat_regs.evergreen.disp_int &= ~DC_HPD1_RX_INTERRUPT;
  4685. queue_dp = true;
  4686. DRM_DEBUG("IH: HPD_RX 1\n");
  4687. }
  4688. break;
  4689. case 7:
  4690. if (rdev->irq.stat_regs.evergreen.disp_int_cont & DC_HPD2_RX_INTERRUPT) {
  4691. rdev->irq.stat_regs.evergreen.disp_int_cont &= ~DC_HPD2_RX_INTERRUPT;
  4692. queue_dp = true;
  4693. DRM_DEBUG("IH: HPD_RX 2\n");
  4694. }
  4695. break;
  4696. case 8:
  4697. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & DC_HPD3_RX_INTERRUPT) {
  4698. rdev->irq.stat_regs.evergreen.disp_int_cont2 &= ~DC_HPD3_RX_INTERRUPT;
  4699. queue_dp = true;
  4700. DRM_DEBUG("IH: HPD_RX 3\n");
  4701. }
  4702. break;
  4703. case 9:
  4704. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & DC_HPD4_RX_INTERRUPT) {
  4705. rdev->irq.stat_regs.evergreen.disp_int_cont3 &= ~DC_HPD4_RX_INTERRUPT;
  4706. queue_dp = true;
  4707. DRM_DEBUG("IH: HPD_RX 4\n");
  4708. }
  4709. break;
  4710. case 10:
  4711. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & DC_HPD5_RX_INTERRUPT) {
  4712. rdev->irq.stat_regs.evergreen.disp_int_cont4 &= ~DC_HPD5_RX_INTERRUPT;
  4713. queue_dp = true;
  4714. DRM_DEBUG("IH: HPD_RX 5\n");
  4715. }
  4716. break;
  4717. case 11:
  4718. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & DC_HPD6_RX_INTERRUPT) {
  4719. rdev->irq.stat_regs.evergreen.disp_int_cont5 &= ~DC_HPD6_RX_INTERRUPT;
  4720. queue_dp = true;
  4721. DRM_DEBUG("IH: HPD_RX 6\n");
  4722. }
  4723. break;
  4724. default:
  4725. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4726. break;
  4727. }
  4728. break;
  4729. case 44: /* hdmi */
  4730. switch (src_data) {
  4731. case 0:
  4732. if (rdev->irq.stat_regs.evergreen.afmt_status1 & AFMT_AZ_FORMAT_WTRIG) {
  4733. rdev->irq.stat_regs.evergreen.afmt_status1 &= ~AFMT_AZ_FORMAT_WTRIG;
  4734. queue_hdmi = true;
  4735. DRM_DEBUG("IH: HDMI0\n");
  4736. }
  4737. break;
  4738. case 1:
  4739. if (rdev->irq.stat_regs.evergreen.afmt_status2 & AFMT_AZ_FORMAT_WTRIG) {
  4740. rdev->irq.stat_regs.evergreen.afmt_status2 &= ~AFMT_AZ_FORMAT_WTRIG;
  4741. queue_hdmi = true;
  4742. DRM_DEBUG("IH: HDMI1\n");
  4743. }
  4744. break;
  4745. case 2:
  4746. if (rdev->irq.stat_regs.evergreen.afmt_status3 & AFMT_AZ_FORMAT_WTRIG) {
  4747. rdev->irq.stat_regs.evergreen.afmt_status3 &= ~AFMT_AZ_FORMAT_WTRIG;
  4748. queue_hdmi = true;
  4749. DRM_DEBUG("IH: HDMI2\n");
  4750. }
  4751. break;
  4752. case 3:
  4753. if (rdev->irq.stat_regs.evergreen.afmt_status4 & AFMT_AZ_FORMAT_WTRIG) {
  4754. rdev->irq.stat_regs.evergreen.afmt_status4 &= ~AFMT_AZ_FORMAT_WTRIG;
  4755. queue_hdmi = true;
  4756. DRM_DEBUG("IH: HDMI3\n");
  4757. }
  4758. break;
  4759. case 4:
  4760. if (rdev->irq.stat_regs.evergreen.afmt_status5 & AFMT_AZ_FORMAT_WTRIG) {
  4761. rdev->irq.stat_regs.evergreen.afmt_status5 &= ~AFMT_AZ_FORMAT_WTRIG;
  4762. queue_hdmi = true;
  4763. DRM_DEBUG("IH: HDMI4\n");
  4764. }
  4765. break;
  4766. case 5:
  4767. if (rdev->irq.stat_regs.evergreen.afmt_status6 & AFMT_AZ_FORMAT_WTRIG) {
  4768. rdev->irq.stat_regs.evergreen.afmt_status6 &= ~AFMT_AZ_FORMAT_WTRIG;
  4769. queue_hdmi = true;
  4770. DRM_DEBUG("IH: HDMI5\n");
  4771. }
  4772. break;
  4773. default:
  4774. DRM_ERROR("Unhandled interrupt: %d %d\n", src_id, src_data);
  4775. break;
  4776. }
  4777. case 96:
  4778. DRM_ERROR("SRBM_READ_ERROR: 0x%x\n", RREG32(SRBM_READ_ERROR));
  4779. WREG32(SRBM_INT_ACK, 0x1);
  4780. break;
  4781. case 124: /* UVD */
  4782. DRM_DEBUG("IH: UVD int: 0x%08x\n", src_data);
  4783. radeon_fence_process(rdev, R600_RING_TYPE_UVD_INDEX);
  4784. break;
  4785. case 146:
  4786. case 147:
  4787. addr = RREG32(VM_CONTEXT1_PROTECTION_FAULT_ADDR);
  4788. status = RREG32(VM_CONTEXT1_PROTECTION_FAULT_STATUS);
  4789. /* reset addr and status */
  4790. WREG32_P(VM_CONTEXT1_CNTL2, 1, ~1);
  4791. if (addr == 0x0 && status == 0x0)
  4792. break;
  4793. dev_err(rdev->dev, "GPU fault detected: %d 0x%08x\n", src_id, src_data);
  4794. dev_err(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_ADDR 0x%08X\n",
  4795. addr);
  4796. dev_err(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_STATUS 0x%08X\n",
  4797. status);
  4798. cayman_vm_decode_fault(rdev, status, addr);
  4799. break;
  4800. case 176: /* CP_INT in ring buffer */
  4801. case 177: /* CP_INT in IB1 */
  4802. case 178: /* CP_INT in IB2 */
  4803. DRM_DEBUG("IH: CP int: 0x%08x\n", src_data);
  4804. radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
  4805. break;
  4806. case 181: /* CP EOP event */
  4807. DRM_DEBUG("IH: CP EOP\n");
  4808. if (rdev->family >= CHIP_CAYMAN) {
  4809. switch (src_data) {
  4810. case 0:
  4811. radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
  4812. break;
  4813. case 1:
  4814. radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP1_INDEX);
  4815. break;
  4816. case 2:
  4817. radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP2_INDEX);
  4818. break;
  4819. }
  4820. } else
  4821. radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
  4822. break;
  4823. case 224: /* DMA trap event */
  4824. DRM_DEBUG("IH: DMA trap\n");
  4825. radeon_fence_process(rdev, R600_RING_TYPE_DMA_INDEX);
  4826. break;
  4827. case 230: /* thermal low to high */
  4828. DRM_DEBUG("IH: thermal low to high\n");
  4829. rdev->pm.dpm.thermal.high_to_low = false;
  4830. queue_thermal = true;
  4831. break;
  4832. case 231: /* thermal high to low */
  4833. DRM_DEBUG("IH: thermal high to low\n");
  4834. rdev->pm.dpm.thermal.high_to_low = true;
  4835. queue_thermal = true;
  4836. break;
  4837. case 233: /* GUI IDLE */
  4838. DRM_DEBUG("IH: GUI idle\n");
  4839. break;
  4840. case 244: /* DMA trap event */
  4841. if (rdev->family >= CHIP_CAYMAN) {
  4842. DRM_DEBUG("IH: DMA1 trap\n");
  4843. radeon_fence_process(rdev, CAYMAN_RING_TYPE_DMA1_INDEX);
  4844. }
  4845. break;
  4846. default:
  4847. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4848. break;
  4849. }
  4850. /* wptr/rptr are in bytes! */
  4851. rptr += 16;
  4852. rptr &= rdev->ih.ptr_mask;
  4853. WREG32(IH_RB_RPTR, rptr);
  4854. }
  4855. if (queue_dp)
  4856. schedule_work(&rdev->dp_work);
  4857. if (queue_hotplug)
  4858. schedule_work(&rdev->hotplug_work);
  4859. if (queue_hdmi)
  4860. schedule_work(&rdev->audio_work);
  4861. if (queue_thermal && rdev->pm.dpm_enabled)
  4862. schedule_work(&rdev->pm.dpm.thermal.work);
  4863. rdev->ih.rptr = rptr;
  4864. atomic_set(&rdev->ih.lock, 0);
  4865. /* make sure wptr hasn't changed while processing */
  4866. wptr = evergreen_get_ih_wptr(rdev);
  4867. if (wptr != rptr)
  4868. goto restart_ih;
  4869. return IRQ_HANDLED;
  4870. }
  4871. static int evergreen_startup(struct radeon_device *rdev)
  4872. {
  4873. struct radeon_ring *ring;
  4874. int r;
  4875. /* enable pcie gen2 link */
  4876. evergreen_pcie_gen2_enable(rdev);
  4877. /* enable aspm */
  4878. evergreen_program_aspm(rdev);
  4879. /* scratch needs to be initialized before MC */
  4880. r = r600_vram_scratch_init(rdev);
  4881. if (r)
  4882. return r;
  4883. evergreen_mc_program(rdev);
  4884. if (ASIC_IS_DCE5(rdev) && !rdev->pm.dpm_enabled) {
  4885. r = ni_mc_load_microcode(rdev);
  4886. if (r) {
  4887. DRM_ERROR("Failed to load MC firmware!\n");
  4888. return r;
  4889. }
  4890. }
  4891. if (rdev->flags & RADEON_IS_AGP) {
  4892. evergreen_agp_enable(rdev);
  4893. } else {
  4894. r = evergreen_pcie_gart_enable(rdev);
  4895. if (r)
  4896. return r;
  4897. }
  4898. evergreen_gpu_init(rdev);
  4899. /* allocate rlc buffers */
  4900. if (rdev->flags & RADEON_IS_IGP) {
  4901. rdev->rlc.reg_list = sumo_rlc_save_restore_register_list;
  4902. rdev->rlc.reg_list_size =
  4903. (u32)ARRAY_SIZE(sumo_rlc_save_restore_register_list);
  4904. rdev->rlc.cs_data = evergreen_cs_data;
  4905. r = sumo_rlc_init(rdev);
  4906. if (r) {
  4907. DRM_ERROR("Failed to init rlc BOs!\n");
  4908. return r;
  4909. }
  4910. }
  4911. /* allocate wb buffer */
  4912. r = radeon_wb_init(rdev);
  4913. if (r)
  4914. return r;
  4915. r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX);
  4916. if (r) {
  4917. dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
  4918. return r;
  4919. }
  4920. r = radeon_fence_driver_start_ring(rdev, R600_RING_TYPE_DMA_INDEX);
  4921. if (r) {
  4922. dev_err(rdev->dev, "failed initializing DMA fences (%d).\n", r);
  4923. return r;
  4924. }
  4925. r = uvd_v2_2_resume(rdev);
  4926. if (!r) {
  4927. r = radeon_fence_driver_start_ring(rdev,
  4928. R600_RING_TYPE_UVD_INDEX);
  4929. if (r)
  4930. dev_err(rdev->dev, "UVD fences init error (%d).\n", r);
  4931. }
  4932. if (r)
  4933. rdev->ring[R600_RING_TYPE_UVD_INDEX].ring_size = 0;
  4934. /* Enable IRQ */
  4935. if (!rdev->irq.installed) {
  4936. r = radeon_irq_kms_init(rdev);
  4937. if (r)
  4938. return r;
  4939. }
  4940. r = r600_irq_init(rdev);
  4941. if (r) {
  4942. DRM_ERROR("radeon: IH init failed (%d).\n", r);
  4943. radeon_irq_kms_fini(rdev);
  4944. return r;
  4945. }
  4946. evergreen_irq_set(rdev);
  4947. ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  4948. r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP_RPTR_OFFSET,
  4949. RADEON_CP_PACKET2);
  4950. if (r)
  4951. return r;
  4952. ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
  4953. r = radeon_ring_init(rdev, ring, ring->ring_size, R600_WB_DMA_RPTR_OFFSET,
  4954. DMA_PACKET(DMA_PACKET_NOP, 0, 0));
  4955. if (r)
  4956. return r;
  4957. r = evergreen_cp_load_microcode(rdev);
  4958. if (r)
  4959. return r;
  4960. r = evergreen_cp_resume(rdev);
  4961. if (r)
  4962. return r;
  4963. r = r600_dma_resume(rdev);
  4964. if (r)
  4965. return r;
  4966. ring = &rdev->ring[R600_RING_TYPE_UVD_INDEX];
  4967. if (ring->ring_size) {
  4968. r = radeon_ring_init(rdev, ring, ring->ring_size, 0,
  4969. RADEON_CP_PACKET2);
  4970. if (!r)
  4971. r = uvd_v1_0_init(rdev);
  4972. if (r)
  4973. DRM_ERROR("radeon: error initializing UVD (%d).\n", r);
  4974. }
  4975. r = radeon_ib_pool_init(rdev);
  4976. if (r) {
  4977. dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
  4978. return r;
  4979. }
  4980. r = radeon_audio_init(rdev);
  4981. if (r) {
  4982. DRM_ERROR("radeon: audio init failed\n");
  4983. return r;
  4984. }
  4985. return 0;
  4986. }
  4987. int evergreen_resume(struct radeon_device *rdev)
  4988. {
  4989. int r;
  4990. /* reset the asic, the gfx blocks are often in a bad state
  4991. * after the driver is unloaded or after a resume
  4992. */
  4993. if (radeon_asic_reset(rdev))
  4994. dev_warn(rdev->dev, "GPU reset failed !\n");
  4995. /* Do not reset GPU before posting, on rv770 hw unlike on r500 hw,
  4996. * posting will perform necessary task to bring back GPU into good
  4997. * shape.
  4998. */
  4999. /* post card */
  5000. atom_asic_init(rdev->mode_info.atom_context);
  5001. /* init golden registers */
  5002. evergreen_init_golden_registers(rdev);
  5003. if (rdev->pm.pm_method == PM_METHOD_DPM)
  5004. radeon_pm_resume(rdev);
  5005. rdev->accel_working = true;
  5006. r = evergreen_startup(rdev);
  5007. if (r) {
  5008. DRM_ERROR("evergreen startup failed on resume\n");
  5009. rdev->accel_working = false;
  5010. return r;
  5011. }
  5012. return r;
  5013. }
  5014. int evergreen_suspend(struct radeon_device *rdev)
  5015. {
  5016. radeon_pm_suspend(rdev);
  5017. radeon_audio_fini(rdev);
  5018. uvd_v1_0_fini(rdev);
  5019. radeon_uvd_suspend(rdev);
  5020. r700_cp_stop(rdev);
  5021. r600_dma_stop(rdev);
  5022. evergreen_irq_suspend(rdev);
  5023. radeon_wb_disable(rdev);
  5024. evergreen_pcie_gart_disable(rdev);
  5025. return 0;
  5026. }
  5027. /* Plan is to move initialization in that function and use
  5028. * helper function so that radeon_device_init pretty much
  5029. * do nothing more than calling asic specific function. This
  5030. * should also allow to remove a bunch of callback function
  5031. * like vram_info.
  5032. */
  5033. int evergreen_init(struct radeon_device *rdev)
  5034. {
  5035. int r;
  5036. /* Read BIOS */
  5037. if (!radeon_get_bios(rdev)) {
  5038. if (ASIC_IS_AVIVO(rdev))
  5039. return -EINVAL;
  5040. }
  5041. /* Must be an ATOMBIOS */
  5042. if (!rdev->is_atom_bios) {
  5043. dev_err(rdev->dev, "Expecting atombios for evergreen GPU\n");
  5044. return -EINVAL;
  5045. }
  5046. r = radeon_atombios_init(rdev);
  5047. if (r)
  5048. return r;
  5049. /* reset the asic, the gfx blocks are often in a bad state
  5050. * after the driver is unloaded or after a resume
  5051. */
  5052. if (radeon_asic_reset(rdev))
  5053. dev_warn(rdev->dev, "GPU reset failed !\n");
  5054. /* Post card if necessary */
  5055. if (!radeon_card_posted(rdev)) {
  5056. if (!rdev->bios) {
  5057. dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n");
  5058. return -EINVAL;
  5059. }
  5060. DRM_INFO("GPU not posted. posting now...\n");
  5061. atom_asic_init(rdev->mode_info.atom_context);
  5062. }
  5063. /* init golden registers */
  5064. evergreen_init_golden_registers(rdev);
  5065. /* Initialize scratch registers */
  5066. r600_scratch_init(rdev);
  5067. /* Initialize surface registers */
  5068. radeon_surface_init(rdev);
  5069. /* Initialize clocks */
  5070. radeon_get_clock_info(rdev->ddev);
  5071. /* Fence driver */
  5072. r = radeon_fence_driver_init(rdev);
  5073. if (r)
  5074. return r;
  5075. /* initialize AGP */
  5076. if (rdev->flags & RADEON_IS_AGP) {
  5077. r = radeon_agp_init(rdev);
  5078. if (r)
  5079. radeon_agp_disable(rdev);
  5080. }
  5081. /* initialize memory controller */
  5082. r = evergreen_mc_init(rdev);
  5083. if (r)
  5084. return r;
  5085. /* Memory manager */
  5086. r = radeon_bo_init(rdev);
  5087. if (r)
  5088. return r;
  5089. if (ASIC_IS_DCE5(rdev)) {
  5090. if (!rdev->me_fw || !rdev->pfp_fw || !rdev->rlc_fw || !rdev->mc_fw) {
  5091. r = ni_init_microcode(rdev);
  5092. if (r) {
  5093. DRM_ERROR("Failed to load firmware!\n");
  5094. return r;
  5095. }
  5096. }
  5097. } else {
  5098. if (!rdev->me_fw || !rdev->pfp_fw || !rdev->rlc_fw) {
  5099. r = r600_init_microcode(rdev);
  5100. if (r) {
  5101. DRM_ERROR("Failed to load firmware!\n");
  5102. return r;
  5103. }
  5104. }
  5105. }
  5106. /* Initialize power management */
  5107. radeon_pm_init(rdev);
  5108. rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ring_obj = NULL;
  5109. r600_ring_init(rdev, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX], 1024 * 1024);
  5110. rdev->ring[R600_RING_TYPE_DMA_INDEX].ring_obj = NULL;
  5111. r600_ring_init(rdev, &rdev->ring[R600_RING_TYPE_DMA_INDEX], 64 * 1024);
  5112. r = radeon_uvd_init(rdev);
  5113. if (!r) {
  5114. rdev->ring[R600_RING_TYPE_UVD_INDEX].ring_obj = NULL;
  5115. r600_ring_init(rdev, &rdev->ring[R600_RING_TYPE_UVD_INDEX],
  5116. 4096);
  5117. }
  5118. rdev->ih.ring_obj = NULL;
  5119. r600_ih_ring_init(rdev, 64 * 1024);
  5120. r = r600_pcie_gart_init(rdev);
  5121. if (r)
  5122. return r;
  5123. rdev->accel_working = true;
  5124. r = evergreen_startup(rdev);
  5125. if (r) {
  5126. dev_err(rdev->dev, "disabling GPU acceleration\n");
  5127. r700_cp_fini(rdev);
  5128. r600_dma_fini(rdev);
  5129. r600_irq_fini(rdev);
  5130. if (rdev->flags & RADEON_IS_IGP)
  5131. sumo_rlc_fini(rdev);
  5132. radeon_wb_fini(rdev);
  5133. radeon_ib_pool_fini(rdev);
  5134. radeon_irq_kms_fini(rdev);
  5135. evergreen_pcie_gart_fini(rdev);
  5136. rdev->accel_working = false;
  5137. }
  5138. /* Don't start up if the MC ucode is missing on BTC parts.
  5139. * The default clocks and voltages before the MC ucode
  5140. * is loaded are not suffient for advanced operations.
  5141. */
  5142. if (ASIC_IS_DCE5(rdev)) {
  5143. if (!rdev->mc_fw && !(rdev->flags & RADEON_IS_IGP)) {
  5144. DRM_ERROR("radeon: MC ucode required for NI+.\n");
  5145. return -EINVAL;
  5146. }
  5147. }
  5148. return 0;
  5149. }
  5150. void evergreen_fini(struct radeon_device *rdev)
  5151. {
  5152. radeon_pm_fini(rdev);
  5153. radeon_audio_fini(rdev);
  5154. r700_cp_fini(rdev);
  5155. r600_dma_fini(rdev);
  5156. r600_irq_fini(rdev);
  5157. if (rdev->flags & RADEON_IS_IGP)
  5158. sumo_rlc_fini(rdev);
  5159. radeon_wb_fini(rdev);
  5160. radeon_ib_pool_fini(rdev);
  5161. radeon_irq_kms_fini(rdev);
  5162. uvd_v1_0_fini(rdev);
  5163. radeon_uvd_fini(rdev);
  5164. evergreen_pcie_gart_fini(rdev);
  5165. r600_vram_scratch_fini(rdev);
  5166. radeon_gem_fini(rdev);
  5167. radeon_fence_driver_fini(rdev);
  5168. radeon_agp_fini(rdev);
  5169. radeon_bo_fini(rdev);
  5170. radeon_atombios_fini(rdev);
  5171. kfree(rdev->bios);
  5172. rdev->bios = NULL;
  5173. }
  5174. void evergreen_pcie_gen2_enable(struct radeon_device *rdev)
  5175. {
  5176. u32 link_width_cntl, speed_cntl;
  5177. if (radeon_pcie_gen2 == 0)
  5178. return;
  5179. if (rdev->flags & RADEON_IS_IGP)
  5180. return;
  5181. if (!(rdev->flags & RADEON_IS_PCIE))
  5182. return;
  5183. /* x2 cards have a special sequence */
  5184. if (ASIC_IS_X2(rdev))
  5185. return;
  5186. if ((rdev->pdev->bus->max_bus_speed != PCIE_SPEED_5_0GT) &&
  5187. (rdev->pdev->bus->max_bus_speed != PCIE_SPEED_8_0GT))
  5188. return;
  5189. speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  5190. if (speed_cntl & LC_CURRENT_DATA_RATE) {
  5191. DRM_INFO("PCIE gen 2 link speeds already enabled\n");
  5192. return;
  5193. }
  5194. DRM_INFO("enabling PCIE gen 2 link speeds, disable with radeon.pcie_gen2=0\n");
  5195. if ((speed_cntl & LC_OTHER_SIDE_EVER_SENT_GEN2) ||
  5196. (speed_cntl & LC_OTHER_SIDE_SUPPORTS_GEN2)) {
  5197. link_width_cntl = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
  5198. link_width_cntl &= ~LC_UPCONFIGURE_DIS;
  5199. WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
  5200. speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  5201. speed_cntl &= ~LC_TARGET_LINK_SPEED_OVERRIDE_EN;
  5202. WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
  5203. speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  5204. speed_cntl |= LC_CLR_FAILED_SPD_CHANGE_CNT;
  5205. WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
  5206. speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  5207. speed_cntl &= ~LC_CLR_FAILED_SPD_CHANGE_CNT;
  5208. WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
  5209. speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  5210. speed_cntl |= LC_GEN2_EN_STRAP;
  5211. WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
  5212. } else {
  5213. link_width_cntl = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
  5214. /* XXX: only disable it if gen1 bridge vendor == 0x111d or 0x1106 */
  5215. if (1)
  5216. link_width_cntl |= LC_UPCONFIGURE_DIS;
  5217. else
  5218. link_width_cntl &= ~LC_UPCONFIGURE_DIS;
  5219. WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
  5220. }
  5221. }
  5222. void evergreen_program_aspm(struct radeon_device *rdev)
  5223. {
  5224. u32 data, orig;
  5225. u32 pcie_lc_cntl, pcie_lc_cntl_old;
  5226. bool disable_l0s, disable_l1 = false, disable_plloff_in_l1 = false;
  5227. /* fusion_platform = true
  5228. * if the system is a fusion system
  5229. * (APU or DGPU in a fusion system).
  5230. * todo: check if the system is a fusion platform.
  5231. */
  5232. bool fusion_platform = false;
  5233. if (radeon_aspm == 0)
  5234. return;
  5235. if (!(rdev->flags & RADEON_IS_PCIE))
  5236. return;
  5237. switch (rdev->family) {
  5238. case CHIP_CYPRESS:
  5239. case CHIP_HEMLOCK:
  5240. case CHIP_JUNIPER:
  5241. case CHIP_REDWOOD:
  5242. case CHIP_CEDAR:
  5243. case CHIP_SUMO:
  5244. case CHIP_SUMO2:
  5245. case CHIP_PALM:
  5246. case CHIP_ARUBA:
  5247. disable_l0s = true;
  5248. break;
  5249. default:
  5250. disable_l0s = false;
  5251. break;
  5252. }
  5253. if (rdev->flags & RADEON_IS_IGP)
  5254. fusion_platform = true; /* XXX also dGPUs in a fusion system */
  5255. data = orig = RREG32_PIF_PHY0(PB0_PIF_PAIRING);
  5256. if (fusion_platform)
  5257. data &= ~MULTI_PIF;
  5258. else
  5259. data |= MULTI_PIF;
  5260. if (data != orig)
  5261. WREG32_PIF_PHY0(PB0_PIF_PAIRING, data);
  5262. data = orig = RREG32_PIF_PHY1(PB1_PIF_PAIRING);
  5263. if (fusion_platform)
  5264. data &= ~MULTI_PIF;
  5265. else
  5266. data |= MULTI_PIF;
  5267. if (data != orig)
  5268. WREG32_PIF_PHY1(PB1_PIF_PAIRING, data);
  5269. pcie_lc_cntl = pcie_lc_cntl_old = RREG32_PCIE_PORT(PCIE_LC_CNTL);
  5270. pcie_lc_cntl &= ~(LC_L0S_INACTIVITY_MASK | LC_L1_INACTIVITY_MASK);
  5271. if (!disable_l0s) {
  5272. if (rdev->family >= CHIP_BARTS)
  5273. pcie_lc_cntl |= LC_L0S_INACTIVITY(7);
  5274. else
  5275. pcie_lc_cntl |= LC_L0S_INACTIVITY(3);
  5276. }
  5277. if (!disable_l1) {
  5278. if (rdev->family >= CHIP_BARTS)
  5279. pcie_lc_cntl |= LC_L1_INACTIVITY(7);
  5280. else
  5281. pcie_lc_cntl |= LC_L1_INACTIVITY(8);
  5282. if (!disable_plloff_in_l1) {
  5283. data = orig = RREG32_PIF_PHY0(PB0_PIF_PWRDOWN_0);
  5284. data &= ~(PLL_POWER_STATE_IN_OFF_0_MASK | PLL_POWER_STATE_IN_TXS2_0_MASK);
  5285. data |= PLL_POWER_STATE_IN_OFF_0(7) | PLL_POWER_STATE_IN_TXS2_0(7);
  5286. if (data != orig)
  5287. WREG32_PIF_PHY0(PB0_PIF_PWRDOWN_0, data);
  5288. data = orig = RREG32_PIF_PHY0(PB0_PIF_PWRDOWN_1);
  5289. data &= ~(PLL_POWER_STATE_IN_OFF_1_MASK | PLL_POWER_STATE_IN_TXS2_1_MASK);
  5290. data |= PLL_POWER_STATE_IN_OFF_1(7) | PLL_POWER_STATE_IN_TXS2_1(7);
  5291. if (data != orig)
  5292. WREG32_PIF_PHY0(PB0_PIF_PWRDOWN_1, data);
  5293. data = orig = RREG32_PIF_PHY1(PB1_PIF_PWRDOWN_0);
  5294. data &= ~(PLL_POWER_STATE_IN_OFF_0_MASK | PLL_POWER_STATE_IN_TXS2_0_MASK);
  5295. data |= PLL_POWER_STATE_IN_OFF_0(7) | PLL_POWER_STATE_IN_TXS2_0(7);
  5296. if (data != orig)
  5297. WREG32_PIF_PHY1(PB1_PIF_PWRDOWN_0, data);
  5298. data = orig = RREG32_PIF_PHY1(PB1_PIF_PWRDOWN_1);
  5299. data &= ~(PLL_POWER_STATE_IN_OFF_1_MASK | PLL_POWER_STATE_IN_TXS2_1_MASK);
  5300. data |= PLL_POWER_STATE_IN_OFF_1(7) | PLL_POWER_STATE_IN_TXS2_1(7);
  5301. if (data != orig)
  5302. WREG32_PIF_PHY1(PB1_PIF_PWRDOWN_1, data);
  5303. if (rdev->family >= CHIP_BARTS) {
  5304. data = orig = RREG32_PIF_PHY0(PB0_PIF_PWRDOWN_0);
  5305. data &= ~PLL_RAMP_UP_TIME_0_MASK;
  5306. data |= PLL_RAMP_UP_TIME_0(4);
  5307. if (data != orig)
  5308. WREG32_PIF_PHY0(PB0_PIF_PWRDOWN_0, data);
  5309. data = orig = RREG32_PIF_PHY0(PB0_PIF_PWRDOWN_1);
  5310. data &= ~PLL_RAMP_UP_TIME_1_MASK;
  5311. data |= PLL_RAMP_UP_TIME_1(4);
  5312. if (data != orig)
  5313. WREG32_PIF_PHY0(PB0_PIF_PWRDOWN_1, data);
  5314. data = orig = RREG32_PIF_PHY1(PB1_PIF_PWRDOWN_0);
  5315. data &= ~PLL_RAMP_UP_TIME_0_MASK;
  5316. data |= PLL_RAMP_UP_TIME_0(4);
  5317. if (data != orig)
  5318. WREG32_PIF_PHY1(PB1_PIF_PWRDOWN_0, data);
  5319. data = orig = RREG32_PIF_PHY1(PB1_PIF_PWRDOWN_1);
  5320. data &= ~PLL_RAMP_UP_TIME_1_MASK;
  5321. data |= PLL_RAMP_UP_TIME_1(4);
  5322. if (data != orig)
  5323. WREG32_PIF_PHY1(PB1_PIF_PWRDOWN_1, data);
  5324. }
  5325. data = orig = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
  5326. data &= ~LC_DYN_LANES_PWR_STATE_MASK;
  5327. data |= LC_DYN_LANES_PWR_STATE(3);
  5328. if (data != orig)
  5329. WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, data);
  5330. if (rdev->family >= CHIP_BARTS) {
  5331. data = orig = RREG32_PIF_PHY0(PB0_PIF_CNTL);
  5332. data &= ~LS2_EXIT_TIME_MASK;
  5333. data |= LS2_EXIT_TIME(1);
  5334. if (data != orig)
  5335. WREG32_PIF_PHY0(PB0_PIF_CNTL, data);
  5336. data = orig = RREG32_PIF_PHY1(PB1_PIF_CNTL);
  5337. data &= ~LS2_EXIT_TIME_MASK;
  5338. data |= LS2_EXIT_TIME(1);
  5339. if (data != orig)
  5340. WREG32_PIF_PHY1(PB1_PIF_CNTL, data);
  5341. }
  5342. }
  5343. }
  5344. /* evergreen parts only */
  5345. if (rdev->family < CHIP_BARTS)
  5346. pcie_lc_cntl |= LC_PMI_TO_L1_DIS;
  5347. if (pcie_lc_cntl != pcie_lc_cntl_old)
  5348. WREG32_PCIE_PORT(PCIE_LC_CNTL, pcie_lc_cntl);
  5349. }