evergreen.c 173 KB

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