evergreen.c 161 KB

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