evergreen.c 158 KB

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