evergreen.c 155 KB

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