evergreen.c 169 KB

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