evergreen.c 171 KB

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