si.c 165 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613
  1. /*
  2. * Copyright 2011 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 <linux/module.h>
  28. #include <drm/drmP.h>
  29. #include "radeon.h"
  30. #include "radeon_asic.h"
  31. #include <drm/radeon_drm.h>
  32. #include "sid.h"
  33. #include "atom.h"
  34. #include "si_blit_shaders.h"
  35. #define SI_PFP_UCODE_SIZE 2144
  36. #define SI_PM4_UCODE_SIZE 2144
  37. #define SI_CE_UCODE_SIZE 2144
  38. #define SI_RLC_UCODE_SIZE 2048
  39. #define SI_MC_UCODE_SIZE 7769
  40. #define OLAND_MC_UCODE_SIZE 7863
  41. MODULE_FIRMWARE("radeon/TAHITI_pfp.bin");
  42. MODULE_FIRMWARE("radeon/TAHITI_me.bin");
  43. MODULE_FIRMWARE("radeon/TAHITI_ce.bin");
  44. MODULE_FIRMWARE("radeon/TAHITI_mc.bin");
  45. MODULE_FIRMWARE("radeon/TAHITI_rlc.bin");
  46. MODULE_FIRMWARE("radeon/PITCAIRN_pfp.bin");
  47. MODULE_FIRMWARE("radeon/PITCAIRN_me.bin");
  48. MODULE_FIRMWARE("radeon/PITCAIRN_ce.bin");
  49. MODULE_FIRMWARE("radeon/PITCAIRN_mc.bin");
  50. MODULE_FIRMWARE("radeon/PITCAIRN_rlc.bin");
  51. MODULE_FIRMWARE("radeon/VERDE_pfp.bin");
  52. MODULE_FIRMWARE("radeon/VERDE_me.bin");
  53. MODULE_FIRMWARE("radeon/VERDE_ce.bin");
  54. MODULE_FIRMWARE("radeon/VERDE_mc.bin");
  55. MODULE_FIRMWARE("radeon/VERDE_rlc.bin");
  56. MODULE_FIRMWARE("radeon/OLAND_pfp.bin");
  57. MODULE_FIRMWARE("radeon/OLAND_me.bin");
  58. MODULE_FIRMWARE("radeon/OLAND_ce.bin");
  59. MODULE_FIRMWARE("radeon/OLAND_mc.bin");
  60. MODULE_FIRMWARE("radeon/OLAND_rlc.bin");
  61. MODULE_FIRMWARE("radeon/HAINAN_pfp.bin");
  62. MODULE_FIRMWARE("radeon/HAINAN_me.bin");
  63. MODULE_FIRMWARE("radeon/HAINAN_ce.bin");
  64. MODULE_FIRMWARE("radeon/HAINAN_mc.bin");
  65. MODULE_FIRMWARE("radeon/HAINAN_rlc.bin");
  66. extern int r600_ih_ring_alloc(struct radeon_device *rdev);
  67. extern void r600_ih_ring_fini(struct radeon_device *rdev);
  68. extern void evergreen_fix_pci_max_read_req_size(struct radeon_device *rdev);
  69. extern void evergreen_mc_stop(struct radeon_device *rdev, struct evergreen_mc_save *save);
  70. extern void evergreen_mc_resume(struct radeon_device *rdev, struct evergreen_mc_save *save);
  71. extern u32 evergreen_get_number_of_dram_channels(struct radeon_device *rdev);
  72. extern void evergreen_print_gpu_status_regs(struct radeon_device *rdev);
  73. extern bool evergreen_is_display_hung(struct radeon_device *rdev);
  74. static const u32 tahiti_golden_rlc_registers[] =
  75. {
  76. 0xc424, 0xffffffff, 0x00601005,
  77. 0xc47c, 0xffffffff, 0x10104040,
  78. 0xc488, 0xffffffff, 0x0100000a,
  79. 0xc314, 0xffffffff, 0x00000800,
  80. 0xc30c, 0xffffffff, 0x800000f4,
  81. 0xf4a8, 0xffffffff, 0x00000000
  82. };
  83. static const u32 tahiti_golden_registers[] =
  84. {
  85. 0x9a10, 0x00010000, 0x00018208,
  86. 0x9830, 0xffffffff, 0x00000000,
  87. 0x9834, 0xf00fffff, 0x00000400,
  88. 0x9838, 0x0002021c, 0x00020200,
  89. 0xc78, 0x00000080, 0x00000000,
  90. 0xd030, 0x000300c0, 0x00800040,
  91. 0xd830, 0x000300c0, 0x00800040,
  92. 0x5bb0, 0x000000f0, 0x00000070,
  93. 0x5bc0, 0x00200000, 0x50100000,
  94. 0x7030, 0x31000311, 0x00000011,
  95. 0x277c, 0x00000003, 0x000007ff,
  96. 0x240c, 0x000007ff, 0x00000000,
  97. 0x8a14, 0xf000001f, 0x00000007,
  98. 0x8b24, 0xffffffff, 0x00ffffff,
  99. 0x8b10, 0x0000ff0f, 0x00000000,
  100. 0x28a4c, 0x07ffffff, 0x4e000000,
  101. 0x28350, 0x3f3f3fff, 0x2a00126a,
  102. 0x30, 0x000000ff, 0x0040,
  103. 0x34, 0x00000040, 0x00004040,
  104. 0x9100, 0x07ffffff, 0x03000000,
  105. 0x8e88, 0x01ff1f3f, 0x00000000,
  106. 0x8e84, 0x01ff1f3f, 0x00000000,
  107. 0x9060, 0x0000007f, 0x00000020,
  108. 0x9508, 0x00010000, 0x00010000,
  109. 0xac14, 0x00000200, 0x000002fb,
  110. 0xac10, 0xffffffff, 0x0000543b,
  111. 0xac0c, 0xffffffff, 0xa9210876,
  112. 0x88d0, 0xffffffff, 0x000fff40,
  113. 0x88d4, 0x0000001f, 0x00000010,
  114. 0x1410, 0x20000000, 0x20fffed8,
  115. 0x15c0, 0x000c0fc0, 0x000c0400
  116. };
  117. static const u32 tahiti_golden_registers2[] =
  118. {
  119. 0xc64, 0x00000001, 0x00000001
  120. };
  121. static const u32 pitcairn_golden_rlc_registers[] =
  122. {
  123. 0xc424, 0xffffffff, 0x00601004,
  124. 0xc47c, 0xffffffff, 0x10102020,
  125. 0xc488, 0xffffffff, 0x01000020,
  126. 0xc314, 0xffffffff, 0x00000800,
  127. 0xc30c, 0xffffffff, 0x800000a4
  128. };
  129. static const u32 pitcairn_golden_registers[] =
  130. {
  131. 0x9a10, 0x00010000, 0x00018208,
  132. 0x9830, 0xffffffff, 0x00000000,
  133. 0x9834, 0xf00fffff, 0x00000400,
  134. 0x9838, 0x0002021c, 0x00020200,
  135. 0xc78, 0x00000080, 0x00000000,
  136. 0xd030, 0x000300c0, 0x00800040,
  137. 0xd830, 0x000300c0, 0x00800040,
  138. 0x5bb0, 0x000000f0, 0x00000070,
  139. 0x5bc0, 0x00200000, 0x50100000,
  140. 0x7030, 0x31000311, 0x00000011,
  141. 0x2ae4, 0x00073ffe, 0x000022a2,
  142. 0x240c, 0x000007ff, 0x00000000,
  143. 0x8a14, 0xf000001f, 0x00000007,
  144. 0x8b24, 0xffffffff, 0x00ffffff,
  145. 0x8b10, 0x0000ff0f, 0x00000000,
  146. 0x28a4c, 0x07ffffff, 0x4e000000,
  147. 0x28350, 0x3f3f3fff, 0x2a00126a,
  148. 0x30, 0x000000ff, 0x0040,
  149. 0x34, 0x00000040, 0x00004040,
  150. 0x9100, 0x07ffffff, 0x03000000,
  151. 0x9060, 0x0000007f, 0x00000020,
  152. 0x9508, 0x00010000, 0x00010000,
  153. 0xac14, 0x000003ff, 0x000000f7,
  154. 0xac10, 0xffffffff, 0x00000000,
  155. 0xac0c, 0xffffffff, 0x32761054,
  156. 0x88d4, 0x0000001f, 0x00000010,
  157. 0x15c0, 0x000c0fc0, 0x000c0400
  158. };
  159. static const u32 verde_golden_rlc_registers[] =
  160. {
  161. 0xc424, 0xffffffff, 0x033f1005,
  162. 0xc47c, 0xffffffff, 0x10808020,
  163. 0xc488, 0xffffffff, 0x00800008,
  164. 0xc314, 0xffffffff, 0x00001000,
  165. 0xc30c, 0xffffffff, 0x80010014
  166. };
  167. static const u32 verde_golden_registers[] =
  168. {
  169. 0x9a10, 0x00010000, 0x00018208,
  170. 0x9830, 0xffffffff, 0x00000000,
  171. 0x9834, 0xf00fffff, 0x00000400,
  172. 0x9838, 0x0002021c, 0x00020200,
  173. 0xc78, 0x00000080, 0x00000000,
  174. 0xd030, 0x000300c0, 0x00800040,
  175. 0xd030, 0x000300c0, 0x00800040,
  176. 0xd830, 0x000300c0, 0x00800040,
  177. 0xd830, 0x000300c0, 0x00800040,
  178. 0x5bb0, 0x000000f0, 0x00000070,
  179. 0x5bc0, 0x00200000, 0x50100000,
  180. 0x7030, 0x31000311, 0x00000011,
  181. 0x2ae4, 0x00073ffe, 0x000022a2,
  182. 0x2ae4, 0x00073ffe, 0x000022a2,
  183. 0x2ae4, 0x00073ffe, 0x000022a2,
  184. 0x240c, 0x000007ff, 0x00000000,
  185. 0x240c, 0x000007ff, 0x00000000,
  186. 0x240c, 0x000007ff, 0x00000000,
  187. 0x8a14, 0xf000001f, 0x00000007,
  188. 0x8a14, 0xf000001f, 0x00000007,
  189. 0x8a14, 0xf000001f, 0x00000007,
  190. 0x8b24, 0xffffffff, 0x00ffffff,
  191. 0x8b10, 0x0000ff0f, 0x00000000,
  192. 0x28a4c, 0x07ffffff, 0x4e000000,
  193. 0x28350, 0x3f3f3fff, 0x0000124a,
  194. 0x28350, 0x3f3f3fff, 0x0000124a,
  195. 0x28350, 0x3f3f3fff, 0x0000124a,
  196. 0x30, 0x000000ff, 0x0040,
  197. 0x34, 0x00000040, 0x00004040,
  198. 0x9100, 0x07ffffff, 0x03000000,
  199. 0x9100, 0x07ffffff, 0x03000000,
  200. 0x8e88, 0x01ff1f3f, 0x00000000,
  201. 0x8e88, 0x01ff1f3f, 0x00000000,
  202. 0x8e88, 0x01ff1f3f, 0x00000000,
  203. 0x8e84, 0x01ff1f3f, 0x00000000,
  204. 0x8e84, 0x01ff1f3f, 0x00000000,
  205. 0x8e84, 0x01ff1f3f, 0x00000000,
  206. 0x9060, 0x0000007f, 0x00000020,
  207. 0x9508, 0x00010000, 0x00010000,
  208. 0xac14, 0x000003ff, 0x00000003,
  209. 0xac14, 0x000003ff, 0x00000003,
  210. 0xac14, 0x000003ff, 0x00000003,
  211. 0xac10, 0xffffffff, 0x00000000,
  212. 0xac10, 0xffffffff, 0x00000000,
  213. 0xac10, 0xffffffff, 0x00000000,
  214. 0xac0c, 0xffffffff, 0x00001032,
  215. 0xac0c, 0xffffffff, 0x00001032,
  216. 0xac0c, 0xffffffff, 0x00001032,
  217. 0x88d4, 0x0000001f, 0x00000010,
  218. 0x88d4, 0x0000001f, 0x00000010,
  219. 0x88d4, 0x0000001f, 0x00000010,
  220. 0x15c0, 0x000c0fc0, 0x000c0400
  221. };
  222. static const u32 oland_golden_rlc_registers[] =
  223. {
  224. 0xc424, 0xffffffff, 0x00601005,
  225. 0xc47c, 0xffffffff, 0x10104040,
  226. 0xc488, 0xffffffff, 0x0100000a,
  227. 0xc314, 0xffffffff, 0x00000800,
  228. 0xc30c, 0xffffffff, 0x800000f4
  229. };
  230. static const u32 oland_golden_registers[] =
  231. {
  232. 0x9a10, 0x00010000, 0x00018208,
  233. 0x9830, 0xffffffff, 0x00000000,
  234. 0x9834, 0xf00fffff, 0x00000400,
  235. 0x9838, 0x0002021c, 0x00020200,
  236. 0xc78, 0x00000080, 0x00000000,
  237. 0xd030, 0x000300c0, 0x00800040,
  238. 0xd830, 0x000300c0, 0x00800040,
  239. 0x5bb0, 0x000000f0, 0x00000070,
  240. 0x5bc0, 0x00200000, 0x50100000,
  241. 0x7030, 0x31000311, 0x00000011,
  242. 0x2ae4, 0x00073ffe, 0x000022a2,
  243. 0x240c, 0x000007ff, 0x00000000,
  244. 0x8a14, 0xf000001f, 0x00000007,
  245. 0x8b24, 0xffffffff, 0x00ffffff,
  246. 0x8b10, 0x0000ff0f, 0x00000000,
  247. 0x28a4c, 0x07ffffff, 0x4e000000,
  248. 0x28350, 0x3f3f3fff, 0x00000082,
  249. 0x30, 0x000000ff, 0x0040,
  250. 0x34, 0x00000040, 0x00004040,
  251. 0x9100, 0x07ffffff, 0x03000000,
  252. 0x9060, 0x0000007f, 0x00000020,
  253. 0x9508, 0x00010000, 0x00010000,
  254. 0xac14, 0x000003ff, 0x000000f3,
  255. 0xac10, 0xffffffff, 0x00000000,
  256. 0xac0c, 0xffffffff, 0x00003210,
  257. 0x88d4, 0x0000001f, 0x00000010,
  258. 0x15c0, 0x000c0fc0, 0x000c0400
  259. };
  260. static const u32 tahiti_mgcg_cgcg_init[] =
  261. {
  262. 0xc400, 0xffffffff, 0xfffffffc,
  263. 0x802c, 0xffffffff, 0xe0000000,
  264. 0x9a60, 0xffffffff, 0x00000100,
  265. 0x92a4, 0xffffffff, 0x00000100,
  266. 0xc164, 0xffffffff, 0x00000100,
  267. 0x9774, 0xffffffff, 0x00000100,
  268. 0x8984, 0xffffffff, 0x06000100,
  269. 0x8a18, 0xffffffff, 0x00000100,
  270. 0x92a0, 0xffffffff, 0x00000100,
  271. 0xc380, 0xffffffff, 0x00000100,
  272. 0x8b28, 0xffffffff, 0x00000100,
  273. 0x9144, 0xffffffff, 0x00000100,
  274. 0x8d88, 0xffffffff, 0x00000100,
  275. 0x8d8c, 0xffffffff, 0x00000100,
  276. 0x9030, 0xffffffff, 0x00000100,
  277. 0x9034, 0xffffffff, 0x00000100,
  278. 0x9038, 0xffffffff, 0x00000100,
  279. 0x903c, 0xffffffff, 0x00000100,
  280. 0xad80, 0xffffffff, 0x00000100,
  281. 0xac54, 0xffffffff, 0x00000100,
  282. 0x897c, 0xffffffff, 0x06000100,
  283. 0x9868, 0xffffffff, 0x00000100,
  284. 0x9510, 0xffffffff, 0x00000100,
  285. 0xaf04, 0xffffffff, 0x00000100,
  286. 0xae04, 0xffffffff, 0x00000100,
  287. 0x949c, 0xffffffff, 0x00000100,
  288. 0x802c, 0xffffffff, 0xe0000000,
  289. 0x9160, 0xffffffff, 0x00010000,
  290. 0x9164, 0xffffffff, 0x00030002,
  291. 0x9168, 0xffffffff, 0x00040007,
  292. 0x916c, 0xffffffff, 0x00060005,
  293. 0x9170, 0xffffffff, 0x00090008,
  294. 0x9174, 0xffffffff, 0x00020001,
  295. 0x9178, 0xffffffff, 0x00040003,
  296. 0x917c, 0xffffffff, 0x00000007,
  297. 0x9180, 0xffffffff, 0x00060005,
  298. 0x9184, 0xffffffff, 0x00090008,
  299. 0x9188, 0xffffffff, 0x00030002,
  300. 0x918c, 0xffffffff, 0x00050004,
  301. 0x9190, 0xffffffff, 0x00000008,
  302. 0x9194, 0xffffffff, 0x00070006,
  303. 0x9198, 0xffffffff, 0x000a0009,
  304. 0x919c, 0xffffffff, 0x00040003,
  305. 0x91a0, 0xffffffff, 0x00060005,
  306. 0x91a4, 0xffffffff, 0x00000009,
  307. 0x91a8, 0xffffffff, 0x00080007,
  308. 0x91ac, 0xffffffff, 0x000b000a,
  309. 0x91b0, 0xffffffff, 0x00050004,
  310. 0x91b4, 0xffffffff, 0x00070006,
  311. 0x91b8, 0xffffffff, 0x0008000b,
  312. 0x91bc, 0xffffffff, 0x000a0009,
  313. 0x91c0, 0xffffffff, 0x000d000c,
  314. 0x91c4, 0xffffffff, 0x00060005,
  315. 0x91c8, 0xffffffff, 0x00080007,
  316. 0x91cc, 0xffffffff, 0x0000000b,
  317. 0x91d0, 0xffffffff, 0x000a0009,
  318. 0x91d4, 0xffffffff, 0x000d000c,
  319. 0x91d8, 0xffffffff, 0x00070006,
  320. 0x91dc, 0xffffffff, 0x00090008,
  321. 0x91e0, 0xffffffff, 0x0000000c,
  322. 0x91e4, 0xffffffff, 0x000b000a,
  323. 0x91e8, 0xffffffff, 0x000e000d,
  324. 0x91ec, 0xffffffff, 0x00080007,
  325. 0x91f0, 0xffffffff, 0x000a0009,
  326. 0x91f4, 0xffffffff, 0x0000000d,
  327. 0x91f8, 0xffffffff, 0x000c000b,
  328. 0x91fc, 0xffffffff, 0x000f000e,
  329. 0x9200, 0xffffffff, 0x00090008,
  330. 0x9204, 0xffffffff, 0x000b000a,
  331. 0x9208, 0xffffffff, 0x000c000f,
  332. 0x920c, 0xffffffff, 0x000e000d,
  333. 0x9210, 0xffffffff, 0x00110010,
  334. 0x9214, 0xffffffff, 0x000a0009,
  335. 0x9218, 0xffffffff, 0x000c000b,
  336. 0x921c, 0xffffffff, 0x0000000f,
  337. 0x9220, 0xffffffff, 0x000e000d,
  338. 0x9224, 0xffffffff, 0x00110010,
  339. 0x9228, 0xffffffff, 0x000b000a,
  340. 0x922c, 0xffffffff, 0x000d000c,
  341. 0x9230, 0xffffffff, 0x00000010,
  342. 0x9234, 0xffffffff, 0x000f000e,
  343. 0x9238, 0xffffffff, 0x00120011,
  344. 0x923c, 0xffffffff, 0x000c000b,
  345. 0x9240, 0xffffffff, 0x000e000d,
  346. 0x9244, 0xffffffff, 0x00000011,
  347. 0x9248, 0xffffffff, 0x0010000f,
  348. 0x924c, 0xffffffff, 0x00130012,
  349. 0x9250, 0xffffffff, 0x000d000c,
  350. 0x9254, 0xffffffff, 0x000f000e,
  351. 0x9258, 0xffffffff, 0x00100013,
  352. 0x925c, 0xffffffff, 0x00120011,
  353. 0x9260, 0xffffffff, 0x00150014,
  354. 0x9264, 0xffffffff, 0x000e000d,
  355. 0x9268, 0xffffffff, 0x0010000f,
  356. 0x926c, 0xffffffff, 0x00000013,
  357. 0x9270, 0xffffffff, 0x00120011,
  358. 0x9274, 0xffffffff, 0x00150014,
  359. 0x9278, 0xffffffff, 0x000f000e,
  360. 0x927c, 0xffffffff, 0x00110010,
  361. 0x9280, 0xffffffff, 0x00000014,
  362. 0x9284, 0xffffffff, 0x00130012,
  363. 0x9288, 0xffffffff, 0x00160015,
  364. 0x928c, 0xffffffff, 0x0010000f,
  365. 0x9290, 0xffffffff, 0x00120011,
  366. 0x9294, 0xffffffff, 0x00000015,
  367. 0x9298, 0xffffffff, 0x00140013,
  368. 0x929c, 0xffffffff, 0x00170016,
  369. 0x9150, 0xffffffff, 0x96940200,
  370. 0x8708, 0xffffffff, 0x00900100,
  371. 0xc478, 0xffffffff, 0x00000080,
  372. 0xc404, 0xffffffff, 0x0020003f,
  373. 0x30, 0xffffffff, 0x0000001c,
  374. 0x34, 0x000f0000, 0x000f0000,
  375. 0x160c, 0xffffffff, 0x00000100,
  376. 0x1024, 0xffffffff, 0x00000100,
  377. 0x102c, 0x00000101, 0x00000000,
  378. 0x20a8, 0xffffffff, 0x00000104,
  379. 0x264c, 0x000c0000, 0x000c0000,
  380. 0x2648, 0x000c0000, 0x000c0000,
  381. 0x55e4, 0xff000fff, 0x00000100,
  382. 0x55e8, 0x00000001, 0x00000001,
  383. 0x2f50, 0x00000001, 0x00000001,
  384. 0x30cc, 0xc0000fff, 0x00000104,
  385. 0xc1e4, 0x00000001, 0x00000001,
  386. 0xd0c0, 0xfffffff0, 0x00000100,
  387. 0xd8c0, 0xfffffff0, 0x00000100
  388. };
  389. static const u32 pitcairn_mgcg_cgcg_init[] =
  390. {
  391. 0xc400, 0xffffffff, 0xfffffffc,
  392. 0x802c, 0xffffffff, 0xe0000000,
  393. 0x9a60, 0xffffffff, 0x00000100,
  394. 0x92a4, 0xffffffff, 0x00000100,
  395. 0xc164, 0xffffffff, 0x00000100,
  396. 0x9774, 0xffffffff, 0x00000100,
  397. 0x8984, 0xffffffff, 0x06000100,
  398. 0x8a18, 0xffffffff, 0x00000100,
  399. 0x92a0, 0xffffffff, 0x00000100,
  400. 0xc380, 0xffffffff, 0x00000100,
  401. 0x8b28, 0xffffffff, 0x00000100,
  402. 0x9144, 0xffffffff, 0x00000100,
  403. 0x8d88, 0xffffffff, 0x00000100,
  404. 0x8d8c, 0xffffffff, 0x00000100,
  405. 0x9030, 0xffffffff, 0x00000100,
  406. 0x9034, 0xffffffff, 0x00000100,
  407. 0x9038, 0xffffffff, 0x00000100,
  408. 0x903c, 0xffffffff, 0x00000100,
  409. 0xad80, 0xffffffff, 0x00000100,
  410. 0xac54, 0xffffffff, 0x00000100,
  411. 0x897c, 0xffffffff, 0x06000100,
  412. 0x9868, 0xffffffff, 0x00000100,
  413. 0x9510, 0xffffffff, 0x00000100,
  414. 0xaf04, 0xffffffff, 0x00000100,
  415. 0xae04, 0xffffffff, 0x00000100,
  416. 0x949c, 0xffffffff, 0x00000100,
  417. 0x802c, 0xffffffff, 0xe0000000,
  418. 0x9160, 0xffffffff, 0x00010000,
  419. 0x9164, 0xffffffff, 0x00030002,
  420. 0x9168, 0xffffffff, 0x00040007,
  421. 0x916c, 0xffffffff, 0x00060005,
  422. 0x9170, 0xffffffff, 0x00090008,
  423. 0x9174, 0xffffffff, 0x00020001,
  424. 0x9178, 0xffffffff, 0x00040003,
  425. 0x917c, 0xffffffff, 0x00000007,
  426. 0x9180, 0xffffffff, 0x00060005,
  427. 0x9184, 0xffffffff, 0x00090008,
  428. 0x9188, 0xffffffff, 0x00030002,
  429. 0x918c, 0xffffffff, 0x00050004,
  430. 0x9190, 0xffffffff, 0x00000008,
  431. 0x9194, 0xffffffff, 0x00070006,
  432. 0x9198, 0xffffffff, 0x000a0009,
  433. 0x919c, 0xffffffff, 0x00040003,
  434. 0x91a0, 0xffffffff, 0x00060005,
  435. 0x91a4, 0xffffffff, 0x00000009,
  436. 0x91a8, 0xffffffff, 0x00080007,
  437. 0x91ac, 0xffffffff, 0x000b000a,
  438. 0x91b0, 0xffffffff, 0x00050004,
  439. 0x91b4, 0xffffffff, 0x00070006,
  440. 0x91b8, 0xffffffff, 0x0008000b,
  441. 0x91bc, 0xffffffff, 0x000a0009,
  442. 0x91c0, 0xffffffff, 0x000d000c,
  443. 0x9200, 0xffffffff, 0x00090008,
  444. 0x9204, 0xffffffff, 0x000b000a,
  445. 0x9208, 0xffffffff, 0x000c000f,
  446. 0x920c, 0xffffffff, 0x000e000d,
  447. 0x9210, 0xffffffff, 0x00110010,
  448. 0x9214, 0xffffffff, 0x000a0009,
  449. 0x9218, 0xffffffff, 0x000c000b,
  450. 0x921c, 0xffffffff, 0x0000000f,
  451. 0x9220, 0xffffffff, 0x000e000d,
  452. 0x9224, 0xffffffff, 0x00110010,
  453. 0x9228, 0xffffffff, 0x000b000a,
  454. 0x922c, 0xffffffff, 0x000d000c,
  455. 0x9230, 0xffffffff, 0x00000010,
  456. 0x9234, 0xffffffff, 0x000f000e,
  457. 0x9238, 0xffffffff, 0x00120011,
  458. 0x923c, 0xffffffff, 0x000c000b,
  459. 0x9240, 0xffffffff, 0x000e000d,
  460. 0x9244, 0xffffffff, 0x00000011,
  461. 0x9248, 0xffffffff, 0x0010000f,
  462. 0x924c, 0xffffffff, 0x00130012,
  463. 0x9250, 0xffffffff, 0x000d000c,
  464. 0x9254, 0xffffffff, 0x000f000e,
  465. 0x9258, 0xffffffff, 0x00100013,
  466. 0x925c, 0xffffffff, 0x00120011,
  467. 0x9260, 0xffffffff, 0x00150014,
  468. 0x9150, 0xffffffff, 0x96940200,
  469. 0x8708, 0xffffffff, 0x00900100,
  470. 0xc478, 0xffffffff, 0x00000080,
  471. 0xc404, 0xffffffff, 0x0020003f,
  472. 0x30, 0xffffffff, 0x0000001c,
  473. 0x34, 0x000f0000, 0x000f0000,
  474. 0x160c, 0xffffffff, 0x00000100,
  475. 0x1024, 0xffffffff, 0x00000100,
  476. 0x102c, 0x00000101, 0x00000000,
  477. 0x20a8, 0xffffffff, 0x00000104,
  478. 0x55e4, 0xff000fff, 0x00000100,
  479. 0x55e8, 0x00000001, 0x00000001,
  480. 0x2f50, 0x00000001, 0x00000001,
  481. 0x30cc, 0xc0000fff, 0x00000104,
  482. 0xc1e4, 0x00000001, 0x00000001,
  483. 0xd0c0, 0xfffffff0, 0x00000100,
  484. 0xd8c0, 0xfffffff0, 0x00000100
  485. };
  486. static const u32 verde_mgcg_cgcg_init[] =
  487. {
  488. 0xc400, 0xffffffff, 0xfffffffc,
  489. 0x802c, 0xffffffff, 0xe0000000,
  490. 0x9a60, 0xffffffff, 0x00000100,
  491. 0x92a4, 0xffffffff, 0x00000100,
  492. 0xc164, 0xffffffff, 0x00000100,
  493. 0x9774, 0xffffffff, 0x00000100,
  494. 0x8984, 0xffffffff, 0x06000100,
  495. 0x8a18, 0xffffffff, 0x00000100,
  496. 0x92a0, 0xffffffff, 0x00000100,
  497. 0xc380, 0xffffffff, 0x00000100,
  498. 0x8b28, 0xffffffff, 0x00000100,
  499. 0x9144, 0xffffffff, 0x00000100,
  500. 0x8d88, 0xffffffff, 0x00000100,
  501. 0x8d8c, 0xffffffff, 0x00000100,
  502. 0x9030, 0xffffffff, 0x00000100,
  503. 0x9034, 0xffffffff, 0x00000100,
  504. 0x9038, 0xffffffff, 0x00000100,
  505. 0x903c, 0xffffffff, 0x00000100,
  506. 0xad80, 0xffffffff, 0x00000100,
  507. 0xac54, 0xffffffff, 0x00000100,
  508. 0x897c, 0xffffffff, 0x06000100,
  509. 0x9868, 0xffffffff, 0x00000100,
  510. 0x9510, 0xffffffff, 0x00000100,
  511. 0xaf04, 0xffffffff, 0x00000100,
  512. 0xae04, 0xffffffff, 0x00000100,
  513. 0x949c, 0xffffffff, 0x00000100,
  514. 0x802c, 0xffffffff, 0xe0000000,
  515. 0x9160, 0xffffffff, 0x00010000,
  516. 0x9164, 0xffffffff, 0x00030002,
  517. 0x9168, 0xffffffff, 0x00040007,
  518. 0x916c, 0xffffffff, 0x00060005,
  519. 0x9170, 0xffffffff, 0x00090008,
  520. 0x9174, 0xffffffff, 0x00020001,
  521. 0x9178, 0xffffffff, 0x00040003,
  522. 0x917c, 0xffffffff, 0x00000007,
  523. 0x9180, 0xffffffff, 0x00060005,
  524. 0x9184, 0xffffffff, 0x00090008,
  525. 0x9188, 0xffffffff, 0x00030002,
  526. 0x918c, 0xffffffff, 0x00050004,
  527. 0x9190, 0xffffffff, 0x00000008,
  528. 0x9194, 0xffffffff, 0x00070006,
  529. 0x9198, 0xffffffff, 0x000a0009,
  530. 0x919c, 0xffffffff, 0x00040003,
  531. 0x91a0, 0xffffffff, 0x00060005,
  532. 0x91a4, 0xffffffff, 0x00000009,
  533. 0x91a8, 0xffffffff, 0x00080007,
  534. 0x91ac, 0xffffffff, 0x000b000a,
  535. 0x91b0, 0xffffffff, 0x00050004,
  536. 0x91b4, 0xffffffff, 0x00070006,
  537. 0x91b8, 0xffffffff, 0x0008000b,
  538. 0x91bc, 0xffffffff, 0x000a0009,
  539. 0x91c0, 0xffffffff, 0x000d000c,
  540. 0x9200, 0xffffffff, 0x00090008,
  541. 0x9204, 0xffffffff, 0x000b000a,
  542. 0x9208, 0xffffffff, 0x000c000f,
  543. 0x920c, 0xffffffff, 0x000e000d,
  544. 0x9210, 0xffffffff, 0x00110010,
  545. 0x9214, 0xffffffff, 0x000a0009,
  546. 0x9218, 0xffffffff, 0x000c000b,
  547. 0x921c, 0xffffffff, 0x0000000f,
  548. 0x9220, 0xffffffff, 0x000e000d,
  549. 0x9224, 0xffffffff, 0x00110010,
  550. 0x9228, 0xffffffff, 0x000b000a,
  551. 0x922c, 0xffffffff, 0x000d000c,
  552. 0x9230, 0xffffffff, 0x00000010,
  553. 0x9234, 0xffffffff, 0x000f000e,
  554. 0x9238, 0xffffffff, 0x00120011,
  555. 0x923c, 0xffffffff, 0x000c000b,
  556. 0x9240, 0xffffffff, 0x000e000d,
  557. 0x9244, 0xffffffff, 0x00000011,
  558. 0x9248, 0xffffffff, 0x0010000f,
  559. 0x924c, 0xffffffff, 0x00130012,
  560. 0x9250, 0xffffffff, 0x000d000c,
  561. 0x9254, 0xffffffff, 0x000f000e,
  562. 0x9258, 0xffffffff, 0x00100013,
  563. 0x925c, 0xffffffff, 0x00120011,
  564. 0x9260, 0xffffffff, 0x00150014,
  565. 0x9150, 0xffffffff, 0x96940200,
  566. 0x8708, 0xffffffff, 0x00900100,
  567. 0xc478, 0xffffffff, 0x00000080,
  568. 0xc404, 0xffffffff, 0x0020003f,
  569. 0x30, 0xffffffff, 0x0000001c,
  570. 0x34, 0x000f0000, 0x000f0000,
  571. 0x160c, 0xffffffff, 0x00000100,
  572. 0x1024, 0xffffffff, 0x00000100,
  573. 0x102c, 0x00000101, 0x00000000,
  574. 0x20a8, 0xffffffff, 0x00000104,
  575. 0x264c, 0x000c0000, 0x000c0000,
  576. 0x2648, 0x000c0000, 0x000c0000,
  577. 0x55e4, 0xff000fff, 0x00000100,
  578. 0x55e8, 0x00000001, 0x00000001,
  579. 0x2f50, 0x00000001, 0x00000001,
  580. 0x30cc, 0xc0000fff, 0x00000104,
  581. 0xc1e4, 0x00000001, 0x00000001,
  582. 0xd0c0, 0xfffffff0, 0x00000100,
  583. 0xd8c0, 0xfffffff0, 0x00000100
  584. };
  585. static const u32 oland_mgcg_cgcg_init[] =
  586. {
  587. 0xc400, 0xffffffff, 0xfffffffc,
  588. 0x802c, 0xffffffff, 0xe0000000,
  589. 0x9a60, 0xffffffff, 0x00000100,
  590. 0x92a4, 0xffffffff, 0x00000100,
  591. 0xc164, 0xffffffff, 0x00000100,
  592. 0x9774, 0xffffffff, 0x00000100,
  593. 0x8984, 0xffffffff, 0x06000100,
  594. 0x8a18, 0xffffffff, 0x00000100,
  595. 0x92a0, 0xffffffff, 0x00000100,
  596. 0xc380, 0xffffffff, 0x00000100,
  597. 0x8b28, 0xffffffff, 0x00000100,
  598. 0x9144, 0xffffffff, 0x00000100,
  599. 0x8d88, 0xffffffff, 0x00000100,
  600. 0x8d8c, 0xffffffff, 0x00000100,
  601. 0x9030, 0xffffffff, 0x00000100,
  602. 0x9034, 0xffffffff, 0x00000100,
  603. 0x9038, 0xffffffff, 0x00000100,
  604. 0x903c, 0xffffffff, 0x00000100,
  605. 0xad80, 0xffffffff, 0x00000100,
  606. 0xac54, 0xffffffff, 0x00000100,
  607. 0x897c, 0xffffffff, 0x06000100,
  608. 0x9868, 0xffffffff, 0x00000100,
  609. 0x9510, 0xffffffff, 0x00000100,
  610. 0xaf04, 0xffffffff, 0x00000100,
  611. 0xae04, 0xffffffff, 0x00000100,
  612. 0x949c, 0xffffffff, 0x00000100,
  613. 0x802c, 0xffffffff, 0xe0000000,
  614. 0x9160, 0xffffffff, 0x00010000,
  615. 0x9164, 0xffffffff, 0x00030002,
  616. 0x9168, 0xffffffff, 0x00040007,
  617. 0x916c, 0xffffffff, 0x00060005,
  618. 0x9170, 0xffffffff, 0x00090008,
  619. 0x9174, 0xffffffff, 0x00020001,
  620. 0x9178, 0xffffffff, 0x00040003,
  621. 0x917c, 0xffffffff, 0x00000007,
  622. 0x9180, 0xffffffff, 0x00060005,
  623. 0x9184, 0xffffffff, 0x00090008,
  624. 0x9188, 0xffffffff, 0x00030002,
  625. 0x918c, 0xffffffff, 0x00050004,
  626. 0x9190, 0xffffffff, 0x00000008,
  627. 0x9194, 0xffffffff, 0x00070006,
  628. 0x9198, 0xffffffff, 0x000a0009,
  629. 0x919c, 0xffffffff, 0x00040003,
  630. 0x91a0, 0xffffffff, 0x00060005,
  631. 0x91a4, 0xffffffff, 0x00000009,
  632. 0x91a8, 0xffffffff, 0x00080007,
  633. 0x91ac, 0xffffffff, 0x000b000a,
  634. 0x91b0, 0xffffffff, 0x00050004,
  635. 0x91b4, 0xffffffff, 0x00070006,
  636. 0x91b8, 0xffffffff, 0x0008000b,
  637. 0x91bc, 0xffffffff, 0x000a0009,
  638. 0x91c0, 0xffffffff, 0x000d000c,
  639. 0x91c4, 0xffffffff, 0x00060005,
  640. 0x91c8, 0xffffffff, 0x00080007,
  641. 0x91cc, 0xffffffff, 0x0000000b,
  642. 0x91d0, 0xffffffff, 0x000a0009,
  643. 0x91d4, 0xffffffff, 0x000d000c,
  644. 0x9150, 0xffffffff, 0x96940200,
  645. 0x8708, 0xffffffff, 0x00900100,
  646. 0xc478, 0xffffffff, 0x00000080,
  647. 0xc404, 0xffffffff, 0x0020003f,
  648. 0x30, 0xffffffff, 0x0000001c,
  649. 0x34, 0x000f0000, 0x000f0000,
  650. 0x160c, 0xffffffff, 0x00000100,
  651. 0x1024, 0xffffffff, 0x00000100,
  652. 0x102c, 0x00000101, 0x00000000,
  653. 0x20a8, 0xffffffff, 0x00000104,
  654. 0x264c, 0x000c0000, 0x000c0000,
  655. 0x2648, 0x000c0000, 0x000c0000,
  656. 0x55e4, 0xff000fff, 0x00000100,
  657. 0x55e8, 0x00000001, 0x00000001,
  658. 0x2f50, 0x00000001, 0x00000001,
  659. 0x30cc, 0xc0000fff, 0x00000104,
  660. 0xc1e4, 0x00000001, 0x00000001,
  661. 0xd0c0, 0xfffffff0, 0x00000100,
  662. 0xd8c0, 0xfffffff0, 0x00000100
  663. };
  664. static u32 verde_pg_init[] =
  665. {
  666. 0x353c, 0xffffffff, 0x40000,
  667. 0x3538, 0xffffffff, 0x200010ff,
  668. 0x353c, 0xffffffff, 0x0,
  669. 0x353c, 0xffffffff, 0x0,
  670. 0x353c, 0xffffffff, 0x0,
  671. 0x353c, 0xffffffff, 0x0,
  672. 0x353c, 0xffffffff, 0x0,
  673. 0x353c, 0xffffffff, 0x7007,
  674. 0x3538, 0xffffffff, 0x300010ff,
  675. 0x353c, 0xffffffff, 0x0,
  676. 0x353c, 0xffffffff, 0x0,
  677. 0x353c, 0xffffffff, 0x0,
  678. 0x353c, 0xffffffff, 0x0,
  679. 0x353c, 0xffffffff, 0x0,
  680. 0x353c, 0xffffffff, 0x400000,
  681. 0x3538, 0xffffffff, 0x100010ff,
  682. 0x353c, 0xffffffff, 0x0,
  683. 0x353c, 0xffffffff, 0x0,
  684. 0x353c, 0xffffffff, 0x0,
  685. 0x353c, 0xffffffff, 0x0,
  686. 0x353c, 0xffffffff, 0x0,
  687. 0x353c, 0xffffffff, 0x120200,
  688. 0x3538, 0xffffffff, 0x500010ff,
  689. 0x353c, 0xffffffff, 0x0,
  690. 0x353c, 0xffffffff, 0x0,
  691. 0x353c, 0xffffffff, 0x0,
  692. 0x353c, 0xffffffff, 0x0,
  693. 0x353c, 0xffffffff, 0x0,
  694. 0x353c, 0xffffffff, 0x1e1e16,
  695. 0x3538, 0xffffffff, 0x600010ff,
  696. 0x353c, 0xffffffff, 0x0,
  697. 0x353c, 0xffffffff, 0x0,
  698. 0x353c, 0xffffffff, 0x0,
  699. 0x353c, 0xffffffff, 0x0,
  700. 0x353c, 0xffffffff, 0x0,
  701. 0x353c, 0xffffffff, 0x171f1e,
  702. 0x3538, 0xffffffff, 0x700010ff,
  703. 0x353c, 0xffffffff, 0x0,
  704. 0x353c, 0xffffffff, 0x0,
  705. 0x353c, 0xffffffff, 0x0,
  706. 0x353c, 0xffffffff, 0x0,
  707. 0x353c, 0xffffffff, 0x0,
  708. 0x353c, 0xffffffff, 0x0,
  709. 0x3538, 0xffffffff, 0x9ff,
  710. 0x3500, 0xffffffff, 0x0,
  711. 0x3504, 0xffffffff, 0x10000800,
  712. 0x3504, 0xffffffff, 0xf,
  713. 0x3504, 0xffffffff, 0xf,
  714. 0x3500, 0xffffffff, 0x4,
  715. 0x3504, 0xffffffff, 0x1000051e,
  716. 0x3504, 0xffffffff, 0xffff,
  717. 0x3504, 0xffffffff, 0xffff,
  718. 0x3500, 0xffffffff, 0x8,
  719. 0x3504, 0xffffffff, 0x80500,
  720. 0x3500, 0xffffffff, 0x12,
  721. 0x3504, 0xffffffff, 0x9050c,
  722. 0x3500, 0xffffffff, 0x1d,
  723. 0x3504, 0xffffffff, 0xb052c,
  724. 0x3500, 0xffffffff, 0x2a,
  725. 0x3504, 0xffffffff, 0x1053e,
  726. 0x3500, 0xffffffff, 0x2d,
  727. 0x3504, 0xffffffff, 0x10546,
  728. 0x3500, 0xffffffff, 0x30,
  729. 0x3504, 0xffffffff, 0xa054e,
  730. 0x3500, 0xffffffff, 0x3c,
  731. 0x3504, 0xffffffff, 0x1055f,
  732. 0x3500, 0xffffffff, 0x3f,
  733. 0x3504, 0xffffffff, 0x10567,
  734. 0x3500, 0xffffffff, 0x42,
  735. 0x3504, 0xffffffff, 0x1056f,
  736. 0x3500, 0xffffffff, 0x45,
  737. 0x3504, 0xffffffff, 0x10572,
  738. 0x3500, 0xffffffff, 0x48,
  739. 0x3504, 0xffffffff, 0x20575,
  740. 0x3500, 0xffffffff, 0x4c,
  741. 0x3504, 0xffffffff, 0x190801,
  742. 0x3500, 0xffffffff, 0x67,
  743. 0x3504, 0xffffffff, 0x1082a,
  744. 0x3500, 0xffffffff, 0x6a,
  745. 0x3504, 0xffffffff, 0x1b082d,
  746. 0x3500, 0xffffffff, 0x87,
  747. 0x3504, 0xffffffff, 0x310851,
  748. 0x3500, 0xffffffff, 0xba,
  749. 0x3504, 0xffffffff, 0x891,
  750. 0x3500, 0xffffffff, 0xbc,
  751. 0x3504, 0xffffffff, 0x893,
  752. 0x3500, 0xffffffff, 0xbe,
  753. 0x3504, 0xffffffff, 0x20895,
  754. 0x3500, 0xffffffff, 0xc2,
  755. 0x3504, 0xffffffff, 0x20899,
  756. 0x3500, 0xffffffff, 0xc6,
  757. 0x3504, 0xffffffff, 0x2089d,
  758. 0x3500, 0xffffffff, 0xca,
  759. 0x3504, 0xffffffff, 0x8a1,
  760. 0x3500, 0xffffffff, 0xcc,
  761. 0x3504, 0xffffffff, 0x8a3,
  762. 0x3500, 0xffffffff, 0xce,
  763. 0x3504, 0xffffffff, 0x308a5,
  764. 0x3500, 0xffffffff, 0xd3,
  765. 0x3504, 0xffffffff, 0x6d08cd,
  766. 0x3500, 0xffffffff, 0x142,
  767. 0x3504, 0xffffffff, 0x2000095a,
  768. 0x3504, 0xffffffff, 0x1,
  769. 0x3500, 0xffffffff, 0x144,
  770. 0x3504, 0xffffffff, 0x301f095b,
  771. 0x3500, 0xffffffff, 0x165,
  772. 0x3504, 0xffffffff, 0xc094d,
  773. 0x3500, 0xffffffff, 0x173,
  774. 0x3504, 0xffffffff, 0xf096d,
  775. 0x3500, 0xffffffff, 0x184,
  776. 0x3504, 0xffffffff, 0x15097f,
  777. 0x3500, 0xffffffff, 0x19b,
  778. 0x3504, 0xffffffff, 0xc0998,
  779. 0x3500, 0xffffffff, 0x1a9,
  780. 0x3504, 0xffffffff, 0x409a7,
  781. 0x3500, 0xffffffff, 0x1af,
  782. 0x3504, 0xffffffff, 0xcdc,
  783. 0x3500, 0xffffffff, 0x1b1,
  784. 0x3504, 0xffffffff, 0x800,
  785. 0x3508, 0xffffffff, 0x6c9b2000,
  786. 0x3510, 0xfc00, 0x2000,
  787. 0x3544, 0xffffffff, 0xfc0,
  788. 0x28d4, 0x00000100, 0x100
  789. };
  790. static void si_init_golden_registers(struct radeon_device *rdev)
  791. {
  792. switch (rdev->family) {
  793. case CHIP_TAHITI:
  794. radeon_program_register_sequence(rdev,
  795. tahiti_golden_registers,
  796. (const u32)ARRAY_SIZE(tahiti_golden_registers));
  797. radeon_program_register_sequence(rdev,
  798. tahiti_golden_rlc_registers,
  799. (const u32)ARRAY_SIZE(tahiti_golden_rlc_registers));
  800. radeon_program_register_sequence(rdev,
  801. tahiti_mgcg_cgcg_init,
  802. (const u32)ARRAY_SIZE(tahiti_mgcg_cgcg_init));
  803. radeon_program_register_sequence(rdev,
  804. tahiti_golden_registers2,
  805. (const u32)ARRAY_SIZE(tahiti_golden_registers2));
  806. break;
  807. case CHIP_PITCAIRN:
  808. radeon_program_register_sequence(rdev,
  809. pitcairn_golden_registers,
  810. (const u32)ARRAY_SIZE(pitcairn_golden_registers));
  811. radeon_program_register_sequence(rdev,
  812. pitcairn_golden_rlc_registers,
  813. (const u32)ARRAY_SIZE(pitcairn_golden_rlc_registers));
  814. radeon_program_register_sequence(rdev,
  815. pitcairn_mgcg_cgcg_init,
  816. (const u32)ARRAY_SIZE(pitcairn_mgcg_cgcg_init));
  817. break;
  818. case CHIP_VERDE:
  819. radeon_program_register_sequence(rdev,
  820. verde_golden_registers,
  821. (const u32)ARRAY_SIZE(verde_golden_registers));
  822. radeon_program_register_sequence(rdev,
  823. verde_golden_rlc_registers,
  824. (const u32)ARRAY_SIZE(verde_golden_rlc_registers));
  825. radeon_program_register_sequence(rdev,
  826. verde_mgcg_cgcg_init,
  827. (const u32)ARRAY_SIZE(verde_mgcg_cgcg_init));
  828. radeon_program_register_sequence(rdev,
  829. verde_pg_init,
  830. (const u32)ARRAY_SIZE(verde_pg_init));
  831. break;
  832. case CHIP_OLAND:
  833. radeon_program_register_sequence(rdev,
  834. oland_golden_registers,
  835. (const u32)ARRAY_SIZE(oland_golden_registers));
  836. radeon_program_register_sequence(rdev,
  837. oland_golden_rlc_registers,
  838. (const u32)ARRAY_SIZE(oland_golden_rlc_registers));
  839. radeon_program_register_sequence(rdev,
  840. oland_mgcg_cgcg_init,
  841. (const u32)ARRAY_SIZE(oland_mgcg_cgcg_init));
  842. break;
  843. default:
  844. break;
  845. }
  846. }
  847. #define PCIE_BUS_CLK 10000
  848. #define TCLK (PCIE_BUS_CLK / 10)
  849. /**
  850. * si_get_xclk - get the xclk
  851. *
  852. * @rdev: radeon_device pointer
  853. *
  854. * Returns the reference clock used by the gfx engine
  855. * (SI).
  856. */
  857. u32 si_get_xclk(struct radeon_device *rdev)
  858. {
  859. u32 reference_clock = rdev->clock.spll.reference_freq;
  860. u32 tmp;
  861. tmp = RREG32(CG_CLKPIN_CNTL_2);
  862. if (tmp & MUX_TCLK_TO_XCLK)
  863. return TCLK;
  864. tmp = RREG32(CG_CLKPIN_CNTL);
  865. if (tmp & XTALIN_DIVIDE)
  866. return reference_clock / 4;
  867. return reference_clock;
  868. }
  869. /* get temperature in millidegrees */
  870. int si_get_temp(struct radeon_device *rdev)
  871. {
  872. u32 temp;
  873. int actual_temp = 0;
  874. temp = (RREG32(CG_MULT_THERMAL_STATUS) & CTF_TEMP_MASK) >>
  875. CTF_TEMP_SHIFT;
  876. if (temp & 0x200)
  877. actual_temp = 255;
  878. else
  879. actual_temp = temp & 0x1ff;
  880. actual_temp = (actual_temp * 1000);
  881. return actual_temp;
  882. }
  883. #define TAHITI_IO_MC_REGS_SIZE 36
  884. static const u32 tahiti_io_mc_regs[TAHITI_IO_MC_REGS_SIZE][2] = {
  885. {0x0000006f, 0x03044000},
  886. {0x00000070, 0x0480c018},
  887. {0x00000071, 0x00000040},
  888. {0x00000072, 0x01000000},
  889. {0x00000074, 0x000000ff},
  890. {0x00000075, 0x00143400},
  891. {0x00000076, 0x08ec0800},
  892. {0x00000077, 0x040000cc},
  893. {0x00000079, 0x00000000},
  894. {0x0000007a, 0x21000409},
  895. {0x0000007c, 0x00000000},
  896. {0x0000007d, 0xe8000000},
  897. {0x0000007e, 0x044408a8},
  898. {0x0000007f, 0x00000003},
  899. {0x00000080, 0x00000000},
  900. {0x00000081, 0x01000000},
  901. {0x00000082, 0x02000000},
  902. {0x00000083, 0x00000000},
  903. {0x00000084, 0xe3f3e4f4},
  904. {0x00000085, 0x00052024},
  905. {0x00000087, 0x00000000},
  906. {0x00000088, 0x66036603},
  907. {0x00000089, 0x01000000},
  908. {0x0000008b, 0x1c0a0000},
  909. {0x0000008c, 0xff010000},
  910. {0x0000008e, 0xffffefff},
  911. {0x0000008f, 0xfff3efff},
  912. {0x00000090, 0xfff3efbf},
  913. {0x00000094, 0x00101101},
  914. {0x00000095, 0x00000fff},
  915. {0x00000096, 0x00116fff},
  916. {0x00000097, 0x60010000},
  917. {0x00000098, 0x10010000},
  918. {0x00000099, 0x00006000},
  919. {0x0000009a, 0x00001000},
  920. {0x0000009f, 0x00a77400}
  921. };
  922. static const u32 pitcairn_io_mc_regs[TAHITI_IO_MC_REGS_SIZE][2] = {
  923. {0x0000006f, 0x03044000},
  924. {0x00000070, 0x0480c018},
  925. {0x00000071, 0x00000040},
  926. {0x00000072, 0x01000000},
  927. {0x00000074, 0x000000ff},
  928. {0x00000075, 0x00143400},
  929. {0x00000076, 0x08ec0800},
  930. {0x00000077, 0x040000cc},
  931. {0x00000079, 0x00000000},
  932. {0x0000007a, 0x21000409},
  933. {0x0000007c, 0x00000000},
  934. {0x0000007d, 0xe8000000},
  935. {0x0000007e, 0x044408a8},
  936. {0x0000007f, 0x00000003},
  937. {0x00000080, 0x00000000},
  938. {0x00000081, 0x01000000},
  939. {0x00000082, 0x02000000},
  940. {0x00000083, 0x00000000},
  941. {0x00000084, 0xe3f3e4f4},
  942. {0x00000085, 0x00052024},
  943. {0x00000087, 0x00000000},
  944. {0x00000088, 0x66036603},
  945. {0x00000089, 0x01000000},
  946. {0x0000008b, 0x1c0a0000},
  947. {0x0000008c, 0xff010000},
  948. {0x0000008e, 0xffffefff},
  949. {0x0000008f, 0xfff3efff},
  950. {0x00000090, 0xfff3efbf},
  951. {0x00000094, 0x00101101},
  952. {0x00000095, 0x00000fff},
  953. {0x00000096, 0x00116fff},
  954. {0x00000097, 0x60010000},
  955. {0x00000098, 0x10010000},
  956. {0x00000099, 0x00006000},
  957. {0x0000009a, 0x00001000},
  958. {0x0000009f, 0x00a47400}
  959. };
  960. static const u32 verde_io_mc_regs[TAHITI_IO_MC_REGS_SIZE][2] = {
  961. {0x0000006f, 0x03044000},
  962. {0x00000070, 0x0480c018},
  963. {0x00000071, 0x00000040},
  964. {0x00000072, 0x01000000},
  965. {0x00000074, 0x000000ff},
  966. {0x00000075, 0x00143400},
  967. {0x00000076, 0x08ec0800},
  968. {0x00000077, 0x040000cc},
  969. {0x00000079, 0x00000000},
  970. {0x0000007a, 0x21000409},
  971. {0x0000007c, 0x00000000},
  972. {0x0000007d, 0xe8000000},
  973. {0x0000007e, 0x044408a8},
  974. {0x0000007f, 0x00000003},
  975. {0x00000080, 0x00000000},
  976. {0x00000081, 0x01000000},
  977. {0x00000082, 0x02000000},
  978. {0x00000083, 0x00000000},
  979. {0x00000084, 0xe3f3e4f4},
  980. {0x00000085, 0x00052024},
  981. {0x00000087, 0x00000000},
  982. {0x00000088, 0x66036603},
  983. {0x00000089, 0x01000000},
  984. {0x0000008b, 0x1c0a0000},
  985. {0x0000008c, 0xff010000},
  986. {0x0000008e, 0xffffefff},
  987. {0x0000008f, 0xfff3efff},
  988. {0x00000090, 0xfff3efbf},
  989. {0x00000094, 0x00101101},
  990. {0x00000095, 0x00000fff},
  991. {0x00000096, 0x00116fff},
  992. {0x00000097, 0x60010000},
  993. {0x00000098, 0x10010000},
  994. {0x00000099, 0x00006000},
  995. {0x0000009a, 0x00001000},
  996. {0x0000009f, 0x00a37400}
  997. };
  998. static const u32 oland_io_mc_regs[TAHITI_IO_MC_REGS_SIZE][2] = {
  999. {0x0000006f, 0x03044000},
  1000. {0x00000070, 0x0480c018},
  1001. {0x00000071, 0x00000040},
  1002. {0x00000072, 0x01000000},
  1003. {0x00000074, 0x000000ff},
  1004. {0x00000075, 0x00143400},
  1005. {0x00000076, 0x08ec0800},
  1006. {0x00000077, 0x040000cc},
  1007. {0x00000079, 0x00000000},
  1008. {0x0000007a, 0x21000409},
  1009. {0x0000007c, 0x00000000},
  1010. {0x0000007d, 0xe8000000},
  1011. {0x0000007e, 0x044408a8},
  1012. {0x0000007f, 0x00000003},
  1013. {0x00000080, 0x00000000},
  1014. {0x00000081, 0x01000000},
  1015. {0x00000082, 0x02000000},
  1016. {0x00000083, 0x00000000},
  1017. {0x00000084, 0xe3f3e4f4},
  1018. {0x00000085, 0x00052024},
  1019. {0x00000087, 0x00000000},
  1020. {0x00000088, 0x66036603},
  1021. {0x00000089, 0x01000000},
  1022. {0x0000008b, 0x1c0a0000},
  1023. {0x0000008c, 0xff010000},
  1024. {0x0000008e, 0xffffefff},
  1025. {0x0000008f, 0xfff3efff},
  1026. {0x00000090, 0xfff3efbf},
  1027. {0x00000094, 0x00101101},
  1028. {0x00000095, 0x00000fff},
  1029. {0x00000096, 0x00116fff},
  1030. {0x00000097, 0x60010000},
  1031. {0x00000098, 0x10010000},
  1032. {0x00000099, 0x00006000},
  1033. {0x0000009a, 0x00001000},
  1034. {0x0000009f, 0x00a17730}
  1035. };
  1036. static const u32 hainan_io_mc_regs[TAHITI_IO_MC_REGS_SIZE][2] = {
  1037. {0x0000006f, 0x03044000},
  1038. {0x00000070, 0x0480c018},
  1039. {0x00000071, 0x00000040},
  1040. {0x00000072, 0x01000000},
  1041. {0x00000074, 0x000000ff},
  1042. {0x00000075, 0x00143400},
  1043. {0x00000076, 0x08ec0800},
  1044. {0x00000077, 0x040000cc},
  1045. {0x00000079, 0x00000000},
  1046. {0x0000007a, 0x21000409},
  1047. {0x0000007c, 0x00000000},
  1048. {0x0000007d, 0xe8000000},
  1049. {0x0000007e, 0x044408a8},
  1050. {0x0000007f, 0x00000003},
  1051. {0x00000080, 0x00000000},
  1052. {0x00000081, 0x01000000},
  1053. {0x00000082, 0x02000000},
  1054. {0x00000083, 0x00000000},
  1055. {0x00000084, 0xe3f3e4f4},
  1056. {0x00000085, 0x00052024},
  1057. {0x00000087, 0x00000000},
  1058. {0x00000088, 0x66036603},
  1059. {0x00000089, 0x01000000},
  1060. {0x0000008b, 0x1c0a0000},
  1061. {0x0000008c, 0xff010000},
  1062. {0x0000008e, 0xffffefff},
  1063. {0x0000008f, 0xfff3efff},
  1064. {0x00000090, 0xfff3efbf},
  1065. {0x00000094, 0x00101101},
  1066. {0x00000095, 0x00000fff},
  1067. {0x00000096, 0x00116fff},
  1068. {0x00000097, 0x60010000},
  1069. {0x00000098, 0x10010000},
  1070. {0x00000099, 0x00006000},
  1071. {0x0000009a, 0x00001000},
  1072. {0x0000009f, 0x00a07730}
  1073. };
  1074. /* ucode loading */
  1075. static int si_mc_load_microcode(struct radeon_device *rdev)
  1076. {
  1077. const __be32 *fw_data;
  1078. u32 running, blackout = 0;
  1079. u32 *io_mc_regs;
  1080. int i, ucode_size, regs_size;
  1081. if (!rdev->mc_fw)
  1082. return -EINVAL;
  1083. switch (rdev->family) {
  1084. case CHIP_TAHITI:
  1085. io_mc_regs = (u32 *)&tahiti_io_mc_regs;
  1086. ucode_size = SI_MC_UCODE_SIZE;
  1087. regs_size = TAHITI_IO_MC_REGS_SIZE;
  1088. break;
  1089. case CHIP_PITCAIRN:
  1090. io_mc_regs = (u32 *)&pitcairn_io_mc_regs;
  1091. ucode_size = SI_MC_UCODE_SIZE;
  1092. regs_size = TAHITI_IO_MC_REGS_SIZE;
  1093. break;
  1094. case CHIP_VERDE:
  1095. default:
  1096. io_mc_regs = (u32 *)&verde_io_mc_regs;
  1097. ucode_size = SI_MC_UCODE_SIZE;
  1098. regs_size = TAHITI_IO_MC_REGS_SIZE;
  1099. break;
  1100. case CHIP_OLAND:
  1101. io_mc_regs = (u32 *)&oland_io_mc_regs;
  1102. ucode_size = OLAND_MC_UCODE_SIZE;
  1103. regs_size = TAHITI_IO_MC_REGS_SIZE;
  1104. break;
  1105. case CHIP_HAINAN:
  1106. io_mc_regs = (u32 *)&hainan_io_mc_regs;
  1107. ucode_size = OLAND_MC_UCODE_SIZE;
  1108. regs_size = TAHITI_IO_MC_REGS_SIZE;
  1109. break;
  1110. }
  1111. running = RREG32(MC_SEQ_SUP_CNTL) & RUN_MASK;
  1112. if (running == 0) {
  1113. if (running) {
  1114. blackout = RREG32(MC_SHARED_BLACKOUT_CNTL);
  1115. WREG32(MC_SHARED_BLACKOUT_CNTL, blackout | 1);
  1116. }
  1117. /* reset the engine and set to writable */
  1118. WREG32(MC_SEQ_SUP_CNTL, 0x00000008);
  1119. WREG32(MC_SEQ_SUP_CNTL, 0x00000010);
  1120. /* load mc io regs */
  1121. for (i = 0; i < regs_size; i++) {
  1122. WREG32(MC_SEQ_IO_DEBUG_INDEX, io_mc_regs[(i << 1)]);
  1123. WREG32(MC_SEQ_IO_DEBUG_DATA, io_mc_regs[(i << 1) + 1]);
  1124. }
  1125. /* load the MC ucode */
  1126. fw_data = (const __be32 *)rdev->mc_fw->data;
  1127. for (i = 0; i < ucode_size; i++)
  1128. WREG32(MC_SEQ_SUP_PGM, be32_to_cpup(fw_data++));
  1129. /* put the engine back into the active state */
  1130. WREG32(MC_SEQ_SUP_CNTL, 0x00000008);
  1131. WREG32(MC_SEQ_SUP_CNTL, 0x00000004);
  1132. WREG32(MC_SEQ_SUP_CNTL, 0x00000001);
  1133. /* wait for training to complete */
  1134. for (i = 0; i < rdev->usec_timeout; i++) {
  1135. if (RREG32(MC_SEQ_TRAIN_WAKEUP_CNTL) & TRAIN_DONE_D0)
  1136. break;
  1137. udelay(1);
  1138. }
  1139. for (i = 0; i < rdev->usec_timeout; i++) {
  1140. if (RREG32(MC_SEQ_TRAIN_WAKEUP_CNTL) & TRAIN_DONE_D1)
  1141. break;
  1142. udelay(1);
  1143. }
  1144. if (running)
  1145. WREG32(MC_SHARED_BLACKOUT_CNTL, blackout);
  1146. }
  1147. return 0;
  1148. }
  1149. static int si_init_microcode(struct radeon_device *rdev)
  1150. {
  1151. struct platform_device *pdev;
  1152. const char *chip_name;
  1153. const char *rlc_chip_name;
  1154. size_t pfp_req_size, me_req_size, ce_req_size, rlc_req_size, mc_req_size;
  1155. char fw_name[30];
  1156. int err;
  1157. DRM_DEBUG("\n");
  1158. pdev = platform_device_register_simple("radeon_cp", 0, NULL, 0);
  1159. err = IS_ERR(pdev);
  1160. if (err) {
  1161. printk(KERN_ERR "radeon_cp: Failed to register firmware\n");
  1162. return -EINVAL;
  1163. }
  1164. switch (rdev->family) {
  1165. case CHIP_TAHITI:
  1166. chip_name = "TAHITI";
  1167. rlc_chip_name = "TAHITI";
  1168. pfp_req_size = SI_PFP_UCODE_SIZE * 4;
  1169. me_req_size = SI_PM4_UCODE_SIZE * 4;
  1170. ce_req_size = SI_CE_UCODE_SIZE * 4;
  1171. rlc_req_size = SI_RLC_UCODE_SIZE * 4;
  1172. mc_req_size = SI_MC_UCODE_SIZE * 4;
  1173. break;
  1174. case CHIP_PITCAIRN:
  1175. chip_name = "PITCAIRN";
  1176. rlc_chip_name = "PITCAIRN";
  1177. pfp_req_size = SI_PFP_UCODE_SIZE * 4;
  1178. me_req_size = SI_PM4_UCODE_SIZE * 4;
  1179. ce_req_size = SI_CE_UCODE_SIZE * 4;
  1180. rlc_req_size = SI_RLC_UCODE_SIZE * 4;
  1181. mc_req_size = SI_MC_UCODE_SIZE * 4;
  1182. break;
  1183. case CHIP_VERDE:
  1184. chip_name = "VERDE";
  1185. rlc_chip_name = "VERDE";
  1186. pfp_req_size = SI_PFP_UCODE_SIZE * 4;
  1187. me_req_size = SI_PM4_UCODE_SIZE * 4;
  1188. ce_req_size = SI_CE_UCODE_SIZE * 4;
  1189. rlc_req_size = SI_RLC_UCODE_SIZE * 4;
  1190. mc_req_size = SI_MC_UCODE_SIZE * 4;
  1191. break;
  1192. case CHIP_OLAND:
  1193. chip_name = "OLAND";
  1194. rlc_chip_name = "OLAND";
  1195. pfp_req_size = SI_PFP_UCODE_SIZE * 4;
  1196. me_req_size = SI_PM4_UCODE_SIZE * 4;
  1197. ce_req_size = SI_CE_UCODE_SIZE * 4;
  1198. rlc_req_size = SI_RLC_UCODE_SIZE * 4;
  1199. mc_req_size = OLAND_MC_UCODE_SIZE * 4;
  1200. break;
  1201. case CHIP_HAINAN:
  1202. chip_name = "HAINAN";
  1203. rlc_chip_name = "HAINAN";
  1204. pfp_req_size = SI_PFP_UCODE_SIZE * 4;
  1205. me_req_size = SI_PM4_UCODE_SIZE * 4;
  1206. ce_req_size = SI_CE_UCODE_SIZE * 4;
  1207. rlc_req_size = SI_RLC_UCODE_SIZE * 4;
  1208. mc_req_size = OLAND_MC_UCODE_SIZE * 4;
  1209. break;
  1210. default: BUG();
  1211. }
  1212. DRM_INFO("Loading %s Microcode\n", chip_name);
  1213. snprintf(fw_name, sizeof(fw_name), "radeon/%s_pfp.bin", chip_name);
  1214. err = request_firmware(&rdev->pfp_fw, fw_name, &pdev->dev);
  1215. if (err)
  1216. goto out;
  1217. if (rdev->pfp_fw->size != pfp_req_size) {
  1218. printk(KERN_ERR
  1219. "si_cp: Bogus length %zu in firmware \"%s\"\n",
  1220. rdev->pfp_fw->size, fw_name);
  1221. err = -EINVAL;
  1222. goto out;
  1223. }
  1224. snprintf(fw_name, sizeof(fw_name), "radeon/%s_me.bin", chip_name);
  1225. err = request_firmware(&rdev->me_fw, fw_name, &pdev->dev);
  1226. if (err)
  1227. goto out;
  1228. if (rdev->me_fw->size != me_req_size) {
  1229. printk(KERN_ERR
  1230. "si_cp: Bogus length %zu in firmware \"%s\"\n",
  1231. rdev->me_fw->size, fw_name);
  1232. err = -EINVAL;
  1233. }
  1234. snprintf(fw_name, sizeof(fw_name), "radeon/%s_ce.bin", chip_name);
  1235. err = request_firmware(&rdev->ce_fw, fw_name, &pdev->dev);
  1236. if (err)
  1237. goto out;
  1238. if (rdev->ce_fw->size != ce_req_size) {
  1239. printk(KERN_ERR
  1240. "si_cp: Bogus length %zu in firmware \"%s\"\n",
  1241. rdev->ce_fw->size, fw_name);
  1242. err = -EINVAL;
  1243. }
  1244. snprintf(fw_name, sizeof(fw_name), "radeon/%s_rlc.bin", rlc_chip_name);
  1245. err = request_firmware(&rdev->rlc_fw, fw_name, &pdev->dev);
  1246. if (err)
  1247. goto out;
  1248. if (rdev->rlc_fw->size != rlc_req_size) {
  1249. printk(KERN_ERR
  1250. "si_rlc: Bogus length %zu in firmware \"%s\"\n",
  1251. rdev->rlc_fw->size, fw_name);
  1252. err = -EINVAL;
  1253. }
  1254. snprintf(fw_name, sizeof(fw_name), "radeon/%s_mc.bin", chip_name);
  1255. err = request_firmware(&rdev->mc_fw, fw_name, &pdev->dev);
  1256. if (err)
  1257. goto out;
  1258. if (rdev->mc_fw->size != mc_req_size) {
  1259. printk(KERN_ERR
  1260. "si_mc: Bogus length %zu in firmware \"%s\"\n",
  1261. rdev->mc_fw->size, fw_name);
  1262. err = -EINVAL;
  1263. }
  1264. out:
  1265. platform_device_unregister(pdev);
  1266. if (err) {
  1267. if (err != -EINVAL)
  1268. printk(KERN_ERR
  1269. "si_cp: Failed to load firmware \"%s\"\n",
  1270. fw_name);
  1271. release_firmware(rdev->pfp_fw);
  1272. rdev->pfp_fw = NULL;
  1273. release_firmware(rdev->me_fw);
  1274. rdev->me_fw = NULL;
  1275. release_firmware(rdev->ce_fw);
  1276. rdev->ce_fw = NULL;
  1277. release_firmware(rdev->rlc_fw);
  1278. rdev->rlc_fw = NULL;
  1279. release_firmware(rdev->mc_fw);
  1280. rdev->mc_fw = NULL;
  1281. }
  1282. return err;
  1283. }
  1284. /* watermark setup */
  1285. static u32 dce6_line_buffer_adjust(struct radeon_device *rdev,
  1286. struct radeon_crtc *radeon_crtc,
  1287. struct drm_display_mode *mode,
  1288. struct drm_display_mode *other_mode)
  1289. {
  1290. u32 tmp;
  1291. /*
  1292. * Line Buffer Setup
  1293. * There are 3 line buffers, each one shared by 2 display controllers.
  1294. * DC_LB_MEMORY_SPLIT controls how that line buffer is shared between
  1295. * the display controllers. The paritioning is done via one of four
  1296. * preset allocations specified in bits 21:20:
  1297. * 0 - half lb
  1298. * 2 - whole lb, other crtc must be disabled
  1299. */
  1300. /* this can get tricky if we have two large displays on a paired group
  1301. * of crtcs. Ideally for multiple large displays we'd assign them to
  1302. * non-linked crtcs for maximum line buffer allocation.
  1303. */
  1304. if (radeon_crtc->base.enabled && mode) {
  1305. if (other_mode)
  1306. tmp = 0; /* 1/2 */
  1307. else
  1308. tmp = 2; /* whole */
  1309. } else
  1310. tmp = 0;
  1311. WREG32(DC_LB_MEMORY_SPLIT + radeon_crtc->crtc_offset,
  1312. DC_LB_MEMORY_CONFIG(tmp));
  1313. if (radeon_crtc->base.enabled && mode) {
  1314. switch (tmp) {
  1315. case 0:
  1316. default:
  1317. return 4096 * 2;
  1318. case 2:
  1319. return 8192 * 2;
  1320. }
  1321. }
  1322. /* controller not enabled, so no lb used */
  1323. return 0;
  1324. }
  1325. static u32 si_get_number_of_dram_channels(struct radeon_device *rdev)
  1326. {
  1327. u32 tmp = RREG32(MC_SHARED_CHMAP);
  1328. switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
  1329. case 0:
  1330. default:
  1331. return 1;
  1332. case 1:
  1333. return 2;
  1334. case 2:
  1335. return 4;
  1336. case 3:
  1337. return 8;
  1338. case 4:
  1339. return 3;
  1340. case 5:
  1341. return 6;
  1342. case 6:
  1343. return 10;
  1344. case 7:
  1345. return 12;
  1346. case 8:
  1347. return 16;
  1348. }
  1349. }
  1350. struct dce6_wm_params {
  1351. u32 dram_channels; /* number of dram channels */
  1352. u32 yclk; /* bandwidth per dram data pin in kHz */
  1353. u32 sclk; /* engine clock in kHz */
  1354. u32 disp_clk; /* display clock in kHz */
  1355. u32 src_width; /* viewport width */
  1356. u32 active_time; /* active display time in ns */
  1357. u32 blank_time; /* blank time in ns */
  1358. bool interlaced; /* mode is interlaced */
  1359. fixed20_12 vsc; /* vertical scale ratio */
  1360. u32 num_heads; /* number of active crtcs */
  1361. u32 bytes_per_pixel; /* bytes per pixel display + overlay */
  1362. u32 lb_size; /* line buffer allocated to pipe */
  1363. u32 vtaps; /* vertical scaler taps */
  1364. };
  1365. static u32 dce6_dram_bandwidth(struct dce6_wm_params *wm)
  1366. {
  1367. /* Calculate raw DRAM Bandwidth */
  1368. fixed20_12 dram_efficiency; /* 0.7 */
  1369. fixed20_12 yclk, dram_channels, bandwidth;
  1370. fixed20_12 a;
  1371. a.full = dfixed_const(1000);
  1372. yclk.full = dfixed_const(wm->yclk);
  1373. yclk.full = dfixed_div(yclk, a);
  1374. dram_channels.full = dfixed_const(wm->dram_channels * 4);
  1375. a.full = dfixed_const(10);
  1376. dram_efficiency.full = dfixed_const(7);
  1377. dram_efficiency.full = dfixed_div(dram_efficiency, a);
  1378. bandwidth.full = dfixed_mul(dram_channels, yclk);
  1379. bandwidth.full = dfixed_mul(bandwidth, dram_efficiency);
  1380. return dfixed_trunc(bandwidth);
  1381. }
  1382. static u32 dce6_dram_bandwidth_for_display(struct dce6_wm_params *wm)
  1383. {
  1384. /* Calculate DRAM Bandwidth and the part allocated to display. */
  1385. fixed20_12 disp_dram_allocation; /* 0.3 to 0.7 */
  1386. fixed20_12 yclk, dram_channels, bandwidth;
  1387. fixed20_12 a;
  1388. a.full = dfixed_const(1000);
  1389. yclk.full = dfixed_const(wm->yclk);
  1390. yclk.full = dfixed_div(yclk, a);
  1391. dram_channels.full = dfixed_const(wm->dram_channels * 4);
  1392. a.full = dfixed_const(10);
  1393. disp_dram_allocation.full = dfixed_const(3); /* XXX worse case value 0.3 */
  1394. disp_dram_allocation.full = dfixed_div(disp_dram_allocation, a);
  1395. bandwidth.full = dfixed_mul(dram_channels, yclk);
  1396. bandwidth.full = dfixed_mul(bandwidth, disp_dram_allocation);
  1397. return dfixed_trunc(bandwidth);
  1398. }
  1399. static u32 dce6_data_return_bandwidth(struct dce6_wm_params *wm)
  1400. {
  1401. /* Calculate the display Data return Bandwidth */
  1402. fixed20_12 return_efficiency; /* 0.8 */
  1403. fixed20_12 sclk, bandwidth;
  1404. fixed20_12 a;
  1405. a.full = dfixed_const(1000);
  1406. sclk.full = dfixed_const(wm->sclk);
  1407. sclk.full = dfixed_div(sclk, a);
  1408. a.full = dfixed_const(10);
  1409. return_efficiency.full = dfixed_const(8);
  1410. return_efficiency.full = dfixed_div(return_efficiency, a);
  1411. a.full = dfixed_const(32);
  1412. bandwidth.full = dfixed_mul(a, sclk);
  1413. bandwidth.full = dfixed_mul(bandwidth, return_efficiency);
  1414. return dfixed_trunc(bandwidth);
  1415. }
  1416. static u32 dce6_get_dmif_bytes_per_request(struct dce6_wm_params *wm)
  1417. {
  1418. return 32;
  1419. }
  1420. static u32 dce6_dmif_request_bandwidth(struct dce6_wm_params *wm)
  1421. {
  1422. /* Calculate the DMIF Request Bandwidth */
  1423. fixed20_12 disp_clk_request_efficiency; /* 0.8 */
  1424. fixed20_12 disp_clk, sclk, bandwidth;
  1425. fixed20_12 a, b1, b2;
  1426. u32 min_bandwidth;
  1427. a.full = dfixed_const(1000);
  1428. disp_clk.full = dfixed_const(wm->disp_clk);
  1429. disp_clk.full = dfixed_div(disp_clk, a);
  1430. a.full = dfixed_const(dce6_get_dmif_bytes_per_request(wm) / 2);
  1431. b1.full = dfixed_mul(a, disp_clk);
  1432. a.full = dfixed_const(1000);
  1433. sclk.full = dfixed_const(wm->sclk);
  1434. sclk.full = dfixed_div(sclk, a);
  1435. a.full = dfixed_const(dce6_get_dmif_bytes_per_request(wm));
  1436. b2.full = dfixed_mul(a, sclk);
  1437. a.full = dfixed_const(10);
  1438. disp_clk_request_efficiency.full = dfixed_const(8);
  1439. disp_clk_request_efficiency.full = dfixed_div(disp_clk_request_efficiency, a);
  1440. min_bandwidth = min(dfixed_trunc(b1), dfixed_trunc(b2));
  1441. a.full = dfixed_const(min_bandwidth);
  1442. bandwidth.full = dfixed_mul(a, disp_clk_request_efficiency);
  1443. return dfixed_trunc(bandwidth);
  1444. }
  1445. static u32 dce6_available_bandwidth(struct dce6_wm_params *wm)
  1446. {
  1447. /* Calculate the Available bandwidth. Display can use this temporarily but not in average. */
  1448. u32 dram_bandwidth = dce6_dram_bandwidth(wm);
  1449. u32 data_return_bandwidth = dce6_data_return_bandwidth(wm);
  1450. u32 dmif_req_bandwidth = dce6_dmif_request_bandwidth(wm);
  1451. return min(dram_bandwidth, min(data_return_bandwidth, dmif_req_bandwidth));
  1452. }
  1453. static u32 dce6_average_bandwidth(struct dce6_wm_params *wm)
  1454. {
  1455. /* Calculate the display mode Average Bandwidth
  1456. * DisplayMode should contain the source and destination dimensions,
  1457. * timing, etc.
  1458. */
  1459. fixed20_12 bpp;
  1460. fixed20_12 line_time;
  1461. fixed20_12 src_width;
  1462. fixed20_12 bandwidth;
  1463. fixed20_12 a;
  1464. a.full = dfixed_const(1000);
  1465. line_time.full = dfixed_const(wm->active_time + wm->blank_time);
  1466. line_time.full = dfixed_div(line_time, a);
  1467. bpp.full = dfixed_const(wm->bytes_per_pixel);
  1468. src_width.full = dfixed_const(wm->src_width);
  1469. bandwidth.full = dfixed_mul(src_width, bpp);
  1470. bandwidth.full = dfixed_mul(bandwidth, wm->vsc);
  1471. bandwidth.full = dfixed_div(bandwidth, line_time);
  1472. return dfixed_trunc(bandwidth);
  1473. }
  1474. static u32 dce6_latency_watermark(struct dce6_wm_params *wm)
  1475. {
  1476. /* First calcualte the latency in ns */
  1477. u32 mc_latency = 2000; /* 2000 ns. */
  1478. u32 available_bandwidth = dce6_available_bandwidth(wm);
  1479. u32 worst_chunk_return_time = (512 * 8 * 1000) / available_bandwidth;
  1480. u32 cursor_line_pair_return_time = (128 * 4 * 1000) / available_bandwidth;
  1481. u32 dc_latency = 40000000 / wm->disp_clk; /* dc pipe latency */
  1482. u32 other_heads_data_return_time = ((wm->num_heads + 1) * worst_chunk_return_time) +
  1483. (wm->num_heads * cursor_line_pair_return_time);
  1484. u32 latency = mc_latency + other_heads_data_return_time + dc_latency;
  1485. u32 max_src_lines_per_dst_line, lb_fill_bw, line_fill_time;
  1486. u32 tmp, dmif_size = 12288;
  1487. fixed20_12 a, b, c;
  1488. if (wm->num_heads == 0)
  1489. return 0;
  1490. a.full = dfixed_const(2);
  1491. b.full = dfixed_const(1);
  1492. if ((wm->vsc.full > a.full) ||
  1493. ((wm->vsc.full > b.full) && (wm->vtaps >= 3)) ||
  1494. (wm->vtaps >= 5) ||
  1495. ((wm->vsc.full >= a.full) && wm->interlaced))
  1496. max_src_lines_per_dst_line = 4;
  1497. else
  1498. max_src_lines_per_dst_line = 2;
  1499. a.full = dfixed_const(available_bandwidth);
  1500. b.full = dfixed_const(wm->num_heads);
  1501. a.full = dfixed_div(a, b);
  1502. b.full = dfixed_const(mc_latency + 512);
  1503. c.full = dfixed_const(wm->disp_clk);
  1504. b.full = dfixed_div(b, c);
  1505. c.full = dfixed_const(dmif_size);
  1506. b.full = dfixed_div(c, b);
  1507. tmp = min(dfixed_trunc(a), dfixed_trunc(b));
  1508. b.full = dfixed_const(1000);
  1509. c.full = dfixed_const(wm->disp_clk);
  1510. b.full = dfixed_div(c, b);
  1511. c.full = dfixed_const(wm->bytes_per_pixel);
  1512. b.full = dfixed_mul(b, c);
  1513. lb_fill_bw = min(tmp, dfixed_trunc(b));
  1514. a.full = dfixed_const(max_src_lines_per_dst_line * wm->src_width * wm->bytes_per_pixel);
  1515. b.full = dfixed_const(1000);
  1516. c.full = dfixed_const(lb_fill_bw);
  1517. b.full = dfixed_div(c, b);
  1518. a.full = dfixed_div(a, b);
  1519. line_fill_time = dfixed_trunc(a);
  1520. if (line_fill_time < wm->active_time)
  1521. return latency;
  1522. else
  1523. return latency + (line_fill_time - wm->active_time);
  1524. }
  1525. static bool dce6_average_bandwidth_vs_dram_bandwidth_for_display(struct dce6_wm_params *wm)
  1526. {
  1527. if (dce6_average_bandwidth(wm) <=
  1528. (dce6_dram_bandwidth_for_display(wm) / wm->num_heads))
  1529. return true;
  1530. else
  1531. return false;
  1532. };
  1533. static bool dce6_average_bandwidth_vs_available_bandwidth(struct dce6_wm_params *wm)
  1534. {
  1535. if (dce6_average_bandwidth(wm) <=
  1536. (dce6_available_bandwidth(wm) / wm->num_heads))
  1537. return true;
  1538. else
  1539. return false;
  1540. };
  1541. static bool dce6_check_latency_hiding(struct dce6_wm_params *wm)
  1542. {
  1543. u32 lb_partitions = wm->lb_size / wm->src_width;
  1544. u32 line_time = wm->active_time + wm->blank_time;
  1545. u32 latency_tolerant_lines;
  1546. u32 latency_hiding;
  1547. fixed20_12 a;
  1548. a.full = dfixed_const(1);
  1549. if (wm->vsc.full > a.full)
  1550. latency_tolerant_lines = 1;
  1551. else {
  1552. if (lb_partitions <= (wm->vtaps + 1))
  1553. latency_tolerant_lines = 1;
  1554. else
  1555. latency_tolerant_lines = 2;
  1556. }
  1557. latency_hiding = (latency_tolerant_lines * line_time + wm->blank_time);
  1558. if (dce6_latency_watermark(wm) <= latency_hiding)
  1559. return true;
  1560. else
  1561. return false;
  1562. }
  1563. static void dce6_program_watermarks(struct radeon_device *rdev,
  1564. struct radeon_crtc *radeon_crtc,
  1565. u32 lb_size, u32 num_heads)
  1566. {
  1567. struct drm_display_mode *mode = &radeon_crtc->base.mode;
  1568. struct dce6_wm_params wm;
  1569. u32 pixel_period;
  1570. u32 line_time = 0;
  1571. u32 latency_watermark_a = 0, latency_watermark_b = 0;
  1572. u32 priority_a_mark = 0, priority_b_mark = 0;
  1573. u32 priority_a_cnt = PRIORITY_OFF;
  1574. u32 priority_b_cnt = PRIORITY_OFF;
  1575. u32 tmp, arb_control3;
  1576. fixed20_12 a, b, c;
  1577. if (radeon_crtc->base.enabled && num_heads && mode) {
  1578. pixel_period = 1000000 / (u32)mode->clock;
  1579. line_time = min((u32)mode->crtc_htotal * pixel_period, (u32)65535);
  1580. priority_a_cnt = 0;
  1581. priority_b_cnt = 0;
  1582. wm.yclk = rdev->pm.current_mclk * 10;
  1583. wm.sclk = rdev->pm.current_sclk * 10;
  1584. wm.disp_clk = mode->clock;
  1585. wm.src_width = mode->crtc_hdisplay;
  1586. wm.active_time = mode->crtc_hdisplay * pixel_period;
  1587. wm.blank_time = line_time - wm.active_time;
  1588. wm.interlaced = false;
  1589. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  1590. wm.interlaced = true;
  1591. wm.vsc = radeon_crtc->vsc;
  1592. wm.vtaps = 1;
  1593. if (radeon_crtc->rmx_type != RMX_OFF)
  1594. wm.vtaps = 2;
  1595. wm.bytes_per_pixel = 4; /* XXX: get this from fb config */
  1596. wm.lb_size = lb_size;
  1597. if (rdev->family == CHIP_ARUBA)
  1598. wm.dram_channels = evergreen_get_number_of_dram_channels(rdev);
  1599. else
  1600. wm.dram_channels = si_get_number_of_dram_channels(rdev);
  1601. wm.num_heads = num_heads;
  1602. /* set for high clocks */
  1603. latency_watermark_a = min(dce6_latency_watermark(&wm), (u32)65535);
  1604. /* set for low clocks */
  1605. /* wm.yclk = low clk; wm.sclk = low clk */
  1606. latency_watermark_b = min(dce6_latency_watermark(&wm), (u32)65535);
  1607. /* possibly force display priority to high */
  1608. /* should really do this at mode validation time... */
  1609. if (!dce6_average_bandwidth_vs_dram_bandwidth_for_display(&wm) ||
  1610. !dce6_average_bandwidth_vs_available_bandwidth(&wm) ||
  1611. !dce6_check_latency_hiding(&wm) ||
  1612. (rdev->disp_priority == 2)) {
  1613. DRM_DEBUG_KMS("force priority to high\n");
  1614. priority_a_cnt |= PRIORITY_ALWAYS_ON;
  1615. priority_b_cnt |= PRIORITY_ALWAYS_ON;
  1616. }
  1617. a.full = dfixed_const(1000);
  1618. b.full = dfixed_const(mode->clock);
  1619. b.full = dfixed_div(b, a);
  1620. c.full = dfixed_const(latency_watermark_a);
  1621. c.full = dfixed_mul(c, b);
  1622. c.full = dfixed_mul(c, radeon_crtc->hsc);
  1623. c.full = dfixed_div(c, a);
  1624. a.full = dfixed_const(16);
  1625. c.full = dfixed_div(c, a);
  1626. priority_a_mark = dfixed_trunc(c);
  1627. priority_a_cnt |= priority_a_mark & PRIORITY_MARK_MASK;
  1628. a.full = dfixed_const(1000);
  1629. b.full = dfixed_const(mode->clock);
  1630. b.full = dfixed_div(b, a);
  1631. c.full = dfixed_const(latency_watermark_b);
  1632. c.full = dfixed_mul(c, b);
  1633. c.full = dfixed_mul(c, radeon_crtc->hsc);
  1634. c.full = dfixed_div(c, a);
  1635. a.full = dfixed_const(16);
  1636. c.full = dfixed_div(c, a);
  1637. priority_b_mark = dfixed_trunc(c);
  1638. priority_b_cnt |= priority_b_mark & PRIORITY_MARK_MASK;
  1639. }
  1640. /* select wm A */
  1641. arb_control3 = RREG32(DPG_PIPE_ARBITRATION_CONTROL3 + radeon_crtc->crtc_offset);
  1642. tmp = arb_control3;
  1643. tmp &= ~LATENCY_WATERMARK_MASK(3);
  1644. tmp |= LATENCY_WATERMARK_MASK(1);
  1645. WREG32(DPG_PIPE_ARBITRATION_CONTROL3 + radeon_crtc->crtc_offset, tmp);
  1646. WREG32(DPG_PIPE_LATENCY_CONTROL + radeon_crtc->crtc_offset,
  1647. (LATENCY_LOW_WATERMARK(latency_watermark_a) |
  1648. LATENCY_HIGH_WATERMARK(line_time)));
  1649. /* select wm B */
  1650. tmp = RREG32(DPG_PIPE_ARBITRATION_CONTROL3 + radeon_crtc->crtc_offset);
  1651. tmp &= ~LATENCY_WATERMARK_MASK(3);
  1652. tmp |= LATENCY_WATERMARK_MASK(2);
  1653. WREG32(DPG_PIPE_ARBITRATION_CONTROL3 + radeon_crtc->crtc_offset, tmp);
  1654. WREG32(DPG_PIPE_LATENCY_CONTROL + radeon_crtc->crtc_offset,
  1655. (LATENCY_LOW_WATERMARK(latency_watermark_b) |
  1656. LATENCY_HIGH_WATERMARK(line_time)));
  1657. /* restore original selection */
  1658. WREG32(DPG_PIPE_ARBITRATION_CONTROL3 + radeon_crtc->crtc_offset, arb_control3);
  1659. /* write the priority marks */
  1660. WREG32(PRIORITY_A_CNT + radeon_crtc->crtc_offset, priority_a_cnt);
  1661. WREG32(PRIORITY_B_CNT + radeon_crtc->crtc_offset, priority_b_cnt);
  1662. }
  1663. void dce6_bandwidth_update(struct radeon_device *rdev)
  1664. {
  1665. struct drm_display_mode *mode0 = NULL;
  1666. struct drm_display_mode *mode1 = NULL;
  1667. u32 num_heads = 0, lb_size;
  1668. int i;
  1669. radeon_update_display_priority(rdev);
  1670. for (i = 0; i < rdev->num_crtc; i++) {
  1671. if (rdev->mode_info.crtcs[i]->base.enabled)
  1672. num_heads++;
  1673. }
  1674. for (i = 0; i < rdev->num_crtc; i += 2) {
  1675. mode0 = &rdev->mode_info.crtcs[i]->base.mode;
  1676. mode1 = &rdev->mode_info.crtcs[i+1]->base.mode;
  1677. lb_size = dce6_line_buffer_adjust(rdev, rdev->mode_info.crtcs[i], mode0, mode1);
  1678. dce6_program_watermarks(rdev, rdev->mode_info.crtcs[i], lb_size, num_heads);
  1679. lb_size = dce6_line_buffer_adjust(rdev, rdev->mode_info.crtcs[i+1], mode1, mode0);
  1680. dce6_program_watermarks(rdev, rdev->mode_info.crtcs[i+1], lb_size, num_heads);
  1681. }
  1682. }
  1683. /*
  1684. * Core functions
  1685. */
  1686. static void si_tiling_mode_table_init(struct radeon_device *rdev)
  1687. {
  1688. const u32 num_tile_mode_states = 32;
  1689. u32 reg_offset, gb_tile_moden, split_equal_to_row_size;
  1690. switch (rdev->config.si.mem_row_size_in_kb) {
  1691. case 1:
  1692. split_equal_to_row_size = ADDR_SURF_TILE_SPLIT_1KB;
  1693. break;
  1694. case 2:
  1695. default:
  1696. split_equal_to_row_size = ADDR_SURF_TILE_SPLIT_2KB;
  1697. break;
  1698. case 4:
  1699. split_equal_to_row_size = ADDR_SURF_TILE_SPLIT_4KB;
  1700. break;
  1701. }
  1702. if ((rdev->family == CHIP_TAHITI) ||
  1703. (rdev->family == CHIP_PITCAIRN)) {
  1704. for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++) {
  1705. switch (reg_offset) {
  1706. case 0: /* non-AA compressed depth or any compressed stencil */
  1707. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1708. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  1709. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1710. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  1711. NUM_BANKS(ADDR_SURF_16_BANK) |
  1712. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1713. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  1714. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  1715. break;
  1716. case 1: /* 2xAA/4xAA compressed depth only */
  1717. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1718. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  1719. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1720. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
  1721. NUM_BANKS(ADDR_SURF_16_BANK) |
  1722. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1723. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  1724. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  1725. break;
  1726. case 2: /* 8xAA compressed depth only */
  1727. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1728. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  1729. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1730. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  1731. NUM_BANKS(ADDR_SURF_16_BANK) |
  1732. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1733. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  1734. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  1735. break;
  1736. case 3: /* 2xAA/4xAA compressed depth with stencil (for depth buffer) */
  1737. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1738. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  1739. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1740. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
  1741. NUM_BANKS(ADDR_SURF_16_BANK) |
  1742. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1743. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  1744. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  1745. break;
  1746. case 4: /* Maps w/ a dimension less than the 2D macro-tile dimensions (for mipmapped depth textures) */
  1747. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  1748. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  1749. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1750. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  1751. NUM_BANKS(ADDR_SURF_16_BANK) |
  1752. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1753. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  1754. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  1755. break;
  1756. case 5: /* Uncompressed 16bpp depth - and stencil buffer allocated with it */
  1757. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1758. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  1759. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1760. TILE_SPLIT(split_equal_to_row_size) |
  1761. NUM_BANKS(ADDR_SURF_16_BANK) |
  1762. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1763. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  1764. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  1765. break;
  1766. case 6: /* Uncompressed 32bpp depth - and stencil buffer allocated with it */
  1767. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1768. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  1769. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1770. TILE_SPLIT(split_equal_to_row_size) |
  1771. NUM_BANKS(ADDR_SURF_16_BANK) |
  1772. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1773. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  1774. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
  1775. break;
  1776. case 7: /* Uncompressed 8bpp stencil without depth (drivers typically do not use) */
  1777. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1778. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  1779. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1780. TILE_SPLIT(split_equal_to_row_size) |
  1781. NUM_BANKS(ADDR_SURF_16_BANK) |
  1782. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1783. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  1784. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  1785. break;
  1786. case 8: /* 1D and 1D Array Surfaces */
  1787. gb_tile_moden = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
  1788. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  1789. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1790. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  1791. NUM_BANKS(ADDR_SURF_16_BANK) |
  1792. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1793. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  1794. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  1795. break;
  1796. case 9: /* Displayable maps. */
  1797. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  1798. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  1799. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1800. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  1801. NUM_BANKS(ADDR_SURF_16_BANK) |
  1802. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1803. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  1804. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  1805. break;
  1806. case 10: /* Display 8bpp. */
  1807. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1808. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  1809. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1810. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  1811. NUM_BANKS(ADDR_SURF_16_BANK) |
  1812. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1813. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  1814. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  1815. break;
  1816. case 11: /* Display 16bpp. */
  1817. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1818. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  1819. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1820. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  1821. NUM_BANKS(ADDR_SURF_16_BANK) |
  1822. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1823. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  1824. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  1825. break;
  1826. case 12: /* Display 32bpp. */
  1827. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1828. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  1829. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1830. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
  1831. NUM_BANKS(ADDR_SURF_16_BANK) |
  1832. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1833. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  1834. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
  1835. break;
  1836. case 13: /* Thin. */
  1837. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  1838. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  1839. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1840. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  1841. NUM_BANKS(ADDR_SURF_16_BANK) |
  1842. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1843. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  1844. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  1845. break;
  1846. case 14: /* Thin 8 bpp. */
  1847. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1848. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  1849. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1850. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  1851. NUM_BANKS(ADDR_SURF_16_BANK) |
  1852. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1853. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  1854. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
  1855. break;
  1856. case 15: /* Thin 16 bpp. */
  1857. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1858. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  1859. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1860. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  1861. NUM_BANKS(ADDR_SURF_16_BANK) |
  1862. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1863. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  1864. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
  1865. break;
  1866. case 16: /* Thin 32 bpp. */
  1867. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1868. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  1869. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1870. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
  1871. NUM_BANKS(ADDR_SURF_16_BANK) |
  1872. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1873. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  1874. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
  1875. break;
  1876. case 17: /* Thin 64 bpp. */
  1877. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1878. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  1879. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1880. TILE_SPLIT(split_equal_to_row_size) |
  1881. NUM_BANKS(ADDR_SURF_16_BANK) |
  1882. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1883. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  1884. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
  1885. break;
  1886. case 21: /* 8 bpp PRT. */
  1887. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1888. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  1889. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1890. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  1891. NUM_BANKS(ADDR_SURF_16_BANK) |
  1892. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
  1893. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  1894. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  1895. break;
  1896. case 22: /* 16 bpp PRT */
  1897. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1898. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  1899. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1900. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  1901. NUM_BANKS(ADDR_SURF_16_BANK) |
  1902. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1903. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  1904. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
  1905. break;
  1906. case 23: /* 32 bpp PRT */
  1907. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1908. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  1909. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1910. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  1911. NUM_BANKS(ADDR_SURF_16_BANK) |
  1912. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1913. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  1914. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  1915. break;
  1916. case 24: /* 64 bpp PRT */
  1917. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1918. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  1919. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1920. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
  1921. NUM_BANKS(ADDR_SURF_16_BANK) |
  1922. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1923. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  1924. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  1925. break;
  1926. case 25: /* 128 bpp PRT */
  1927. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1928. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  1929. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  1930. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_1KB) |
  1931. NUM_BANKS(ADDR_SURF_8_BANK) |
  1932. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1933. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  1934. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
  1935. break;
  1936. default:
  1937. gb_tile_moden = 0;
  1938. break;
  1939. }
  1940. rdev->config.si.tile_mode_array[reg_offset] = gb_tile_moden;
  1941. WREG32(GB_TILE_MODE0 + (reg_offset * 4), gb_tile_moden);
  1942. }
  1943. } else if ((rdev->family == CHIP_VERDE) ||
  1944. (rdev->family == CHIP_OLAND) ||
  1945. (rdev->family == CHIP_HAINAN)) {
  1946. for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++) {
  1947. switch (reg_offset) {
  1948. case 0: /* non-AA compressed depth or any compressed stencil */
  1949. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1950. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  1951. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  1952. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  1953. NUM_BANKS(ADDR_SURF_16_BANK) |
  1954. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1955. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  1956. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
  1957. break;
  1958. case 1: /* 2xAA/4xAA compressed depth only */
  1959. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1960. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  1961. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  1962. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
  1963. NUM_BANKS(ADDR_SURF_16_BANK) |
  1964. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1965. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  1966. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
  1967. break;
  1968. case 2: /* 8xAA compressed depth only */
  1969. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1970. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  1971. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  1972. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  1973. NUM_BANKS(ADDR_SURF_16_BANK) |
  1974. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1975. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  1976. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
  1977. break;
  1978. case 3: /* 2xAA/4xAA compressed depth with stencil (for depth buffer) */
  1979. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1980. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  1981. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  1982. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
  1983. NUM_BANKS(ADDR_SURF_16_BANK) |
  1984. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1985. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  1986. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
  1987. break;
  1988. case 4: /* Maps w/ a dimension less than the 2D macro-tile dimensions (for mipmapped depth textures) */
  1989. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  1990. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  1991. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  1992. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  1993. NUM_BANKS(ADDR_SURF_16_BANK) |
  1994. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1995. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  1996. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  1997. break;
  1998. case 5: /* Uncompressed 16bpp depth - and stencil buffer allocated with it */
  1999. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2000. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2001. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2002. TILE_SPLIT(split_equal_to_row_size) |
  2003. NUM_BANKS(ADDR_SURF_16_BANK) |
  2004. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2005. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2006. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2007. break;
  2008. case 6: /* Uncompressed 32bpp depth - and stencil buffer allocated with it */
  2009. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2010. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2011. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2012. TILE_SPLIT(split_equal_to_row_size) |
  2013. NUM_BANKS(ADDR_SURF_16_BANK) |
  2014. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2015. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2016. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2017. break;
  2018. case 7: /* Uncompressed 8bpp stencil without depth (drivers typically do not use) */
  2019. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2020. MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
  2021. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2022. TILE_SPLIT(split_equal_to_row_size) |
  2023. NUM_BANKS(ADDR_SURF_16_BANK) |
  2024. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2025. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2026. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
  2027. break;
  2028. case 8: /* 1D and 1D Array Surfaces */
  2029. gb_tile_moden = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
  2030. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2031. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2032. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  2033. NUM_BANKS(ADDR_SURF_16_BANK) |
  2034. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2035. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2036. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2037. break;
  2038. case 9: /* Displayable maps. */
  2039. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2040. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2041. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2042. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  2043. NUM_BANKS(ADDR_SURF_16_BANK) |
  2044. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2045. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2046. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2047. break;
  2048. case 10: /* Display 8bpp. */
  2049. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2050. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2051. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2052. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2053. NUM_BANKS(ADDR_SURF_16_BANK) |
  2054. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2055. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2056. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
  2057. break;
  2058. case 11: /* Display 16bpp. */
  2059. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2060. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2061. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2062. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2063. NUM_BANKS(ADDR_SURF_16_BANK) |
  2064. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2065. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2066. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2067. break;
  2068. case 12: /* Display 32bpp. */
  2069. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2070. MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
  2071. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2072. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
  2073. NUM_BANKS(ADDR_SURF_16_BANK) |
  2074. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2075. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2076. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2077. break;
  2078. case 13: /* Thin. */
  2079. gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  2080. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2081. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2082. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  2083. NUM_BANKS(ADDR_SURF_16_BANK) |
  2084. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2085. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2086. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2087. break;
  2088. case 14: /* Thin 8 bpp. */
  2089. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2090. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2091. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2092. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2093. NUM_BANKS(ADDR_SURF_16_BANK) |
  2094. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2095. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2096. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2097. break;
  2098. case 15: /* Thin 16 bpp. */
  2099. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2100. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2101. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2102. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2103. NUM_BANKS(ADDR_SURF_16_BANK) |
  2104. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2105. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2106. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2107. break;
  2108. case 16: /* Thin 32 bpp. */
  2109. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2110. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2111. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2112. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
  2113. NUM_BANKS(ADDR_SURF_16_BANK) |
  2114. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2115. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2116. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2117. break;
  2118. case 17: /* Thin 64 bpp. */
  2119. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2120. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2121. PIPE_CONFIG(ADDR_SURF_P4_8x16) |
  2122. TILE_SPLIT(split_equal_to_row_size) |
  2123. NUM_BANKS(ADDR_SURF_16_BANK) |
  2124. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2125. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2126. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2127. break;
  2128. case 21: /* 8 bpp PRT. */
  2129. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2130. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2131. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2132. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2133. NUM_BANKS(ADDR_SURF_16_BANK) |
  2134. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
  2135. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2136. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2137. break;
  2138. case 22: /* 16 bpp PRT */
  2139. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2140. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2141. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2142. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2143. NUM_BANKS(ADDR_SURF_16_BANK) |
  2144. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2145. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  2146. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
  2147. break;
  2148. case 23: /* 32 bpp PRT */
  2149. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2150. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2151. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2152. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  2153. NUM_BANKS(ADDR_SURF_16_BANK) |
  2154. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2155. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  2156. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2157. break;
  2158. case 24: /* 64 bpp PRT */
  2159. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2160. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2161. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2162. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
  2163. NUM_BANKS(ADDR_SURF_16_BANK) |
  2164. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2165. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2166. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
  2167. break;
  2168. case 25: /* 128 bpp PRT */
  2169. gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  2170. MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
  2171. PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
  2172. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_1KB) |
  2173. NUM_BANKS(ADDR_SURF_8_BANK) |
  2174. BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  2175. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  2176. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
  2177. break;
  2178. default:
  2179. gb_tile_moden = 0;
  2180. break;
  2181. }
  2182. rdev->config.si.tile_mode_array[reg_offset] = gb_tile_moden;
  2183. WREG32(GB_TILE_MODE0 + (reg_offset * 4), gb_tile_moden);
  2184. }
  2185. } else
  2186. DRM_ERROR("unknown asic: 0x%x\n", rdev->family);
  2187. }
  2188. static void si_select_se_sh(struct radeon_device *rdev,
  2189. u32 se_num, u32 sh_num)
  2190. {
  2191. u32 data = INSTANCE_BROADCAST_WRITES;
  2192. if ((se_num == 0xffffffff) && (sh_num == 0xffffffff))
  2193. data |= SH_BROADCAST_WRITES | SE_BROADCAST_WRITES;
  2194. else if (se_num == 0xffffffff)
  2195. data |= SE_BROADCAST_WRITES | SH_INDEX(sh_num);
  2196. else if (sh_num == 0xffffffff)
  2197. data |= SH_BROADCAST_WRITES | SE_INDEX(se_num);
  2198. else
  2199. data |= SH_INDEX(sh_num) | SE_INDEX(se_num);
  2200. WREG32(GRBM_GFX_INDEX, data);
  2201. }
  2202. static u32 si_create_bitmask(u32 bit_width)
  2203. {
  2204. u32 i, mask = 0;
  2205. for (i = 0; i < bit_width; i++) {
  2206. mask <<= 1;
  2207. mask |= 1;
  2208. }
  2209. return mask;
  2210. }
  2211. static u32 si_get_cu_enabled(struct radeon_device *rdev, u32 cu_per_sh)
  2212. {
  2213. u32 data, mask;
  2214. data = RREG32(CC_GC_SHADER_ARRAY_CONFIG);
  2215. if (data & 1)
  2216. data &= INACTIVE_CUS_MASK;
  2217. else
  2218. data = 0;
  2219. data |= RREG32(GC_USER_SHADER_ARRAY_CONFIG);
  2220. data >>= INACTIVE_CUS_SHIFT;
  2221. mask = si_create_bitmask(cu_per_sh);
  2222. return ~data & mask;
  2223. }
  2224. static void si_setup_spi(struct radeon_device *rdev,
  2225. u32 se_num, u32 sh_per_se,
  2226. u32 cu_per_sh)
  2227. {
  2228. int i, j, k;
  2229. u32 data, mask, active_cu;
  2230. for (i = 0; i < se_num; i++) {
  2231. for (j = 0; j < sh_per_se; j++) {
  2232. si_select_se_sh(rdev, i, j);
  2233. data = RREG32(SPI_STATIC_THREAD_MGMT_3);
  2234. active_cu = si_get_cu_enabled(rdev, cu_per_sh);
  2235. mask = 1;
  2236. for (k = 0; k < 16; k++) {
  2237. mask <<= k;
  2238. if (active_cu & mask) {
  2239. data &= ~mask;
  2240. WREG32(SPI_STATIC_THREAD_MGMT_3, data);
  2241. break;
  2242. }
  2243. }
  2244. }
  2245. }
  2246. si_select_se_sh(rdev, 0xffffffff, 0xffffffff);
  2247. }
  2248. static u32 si_get_rb_disabled(struct radeon_device *rdev,
  2249. u32 max_rb_num, u32 se_num,
  2250. u32 sh_per_se)
  2251. {
  2252. u32 data, mask;
  2253. data = RREG32(CC_RB_BACKEND_DISABLE);
  2254. if (data & 1)
  2255. data &= BACKEND_DISABLE_MASK;
  2256. else
  2257. data = 0;
  2258. data |= RREG32(GC_USER_RB_BACKEND_DISABLE);
  2259. data >>= BACKEND_DISABLE_SHIFT;
  2260. mask = si_create_bitmask(max_rb_num / se_num / sh_per_se);
  2261. return data & mask;
  2262. }
  2263. static void si_setup_rb(struct radeon_device *rdev,
  2264. u32 se_num, u32 sh_per_se,
  2265. u32 max_rb_num)
  2266. {
  2267. int i, j;
  2268. u32 data, mask;
  2269. u32 disabled_rbs = 0;
  2270. u32 enabled_rbs = 0;
  2271. for (i = 0; i < se_num; i++) {
  2272. for (j = 0; j < sh_per_se; j++) {
  2273. si_select_se_sh(rdev, i, j);
  2274. data = si_get_rb_disabled(rdev, max_rb_num, se_num, sh_per_se);
  2275. disabled_rbs |= data << ((i * sh_per_se + j) * TAHITI_RB_BITMAP_WIDTH_PER_SH);
  2276. }
  2277. }
  2278. si_select_se_sh(rdev, 0xffffffff, 0xffffffff);
  2279. mask = 1;
  2280. for (i = 0; i < max_rb_num; i++) {
  2281. if (!(disabled_rbs & mask))
  2282. enabled_rbs |= mask;
  2283. mask <<= 1;
  2284. }
  2285. for (i = 0; i < se_num; i++) {
  2286. si_select_se_sh(rdev, i, 0xffffffff);
  2287. data = 0;
  2288. for (j = 0; j < sh_per_se; j++) {
  2289. switch (enabled_rbs & 3) {
  2290. case 1:
  2291. data |= (RASTER_CONFIG_RB_MAP_0 << (i * sh_per_se + j) * 2);
  2292. break;
  2293. case 2:
  2294. data |= (RASTER_CONFIG_RB_MAP_3 << (i * sh_per_se + j) * 2);
  2295. break;
  2296. case 3:
  2297. default:
  2298. data |= (RASTER_CONFIG_RB_MAP_2 << (i * sh_per_se + j) * 2);
  2299. break;
  2300. }
  2301. enabled_rbs >>= 2;
  2302. }
  2303. WREG32(PA_SC_RASTER_CONFIG, data);
  2304. }
  2305. si_select_se_sh(rdev, 0xffffffff, 0xffffffff);
  2306. }
  2307. static void si_gpu_init(struct radeon_device *rdev)
  2308. {
  2309. u32 gb_addr_config = 0;
  2310. u32 mc_shared_chmap, mc_arb_ramcfg;
  2311. u32 sx_debug_1;
  2312. u32 hdp_host_path_cntl;
  2313. u32 tmp;
  2314. int i, j;
  2315. switch (rdev->family) {
  2316. case CHIP_TAHITI:
  2317. rdev->config.si.max_shader_engines = 2;
  2318. rdev->config.si.max_tile_pipes = 12;
  2319. rdev->config.si.max_cu_per_sh = 8;
  2320. rdev->config.si.max_sh_per_se = 2;
  2321. rdev->config.si.max_backends_per_se = 4;
  2322. rdev->config.si.max_texture_channel_caches = 12;
  2323. rdev->config.si.max_gprs = 256;
  2324. rdev->config.si.max_gs_threads = 32;
  2325. rdev->config.si.max_hw_contexts = 8;
  2326. rdev->config.si.sc_prim_fifo_size_frontend = 0x20;
  2327. rdev->config.si.sc_prim_fifo_size_backend = 0x100;
  2328. rdev->config.si.sc_hiz_tile_fifo_size = 0x30;
  2329. rdev->config.si.sc_earlyz_tile_fifo_size = 0x130;
  2330. gb_addr_config = TAHITI_GB_ADDR_CONFIG_GOLDEN;
  2331. break;
  2332. case CHIP_PITCAIRN:
  2333. rdev->config.si.max_shader_engines = 2;
  2334. rdev->config.si.max_tile_pipes = 8;
  2335. rdev->config.si.max_cu_per_sh = 5;
  2336. rdev->config.si.max_sh_per_se = 2;
  2337. rdev->config.si.max_backends_per_se = 4;
  2338. rdev->config.si.max_texture_channel_caches = 8;
  2339. rdev->config.si.max_gprs = 256;
  2340. rdev->config.si.max_gs_threads = 32;
  2341. rdev->config.si.max_hw_contexts = 8;
  2342. rdev->config.si.sc_prim_fifo_size_frontend = 0x20;
  2343. rdev->config.si.sc_prim_fifo_size_backend = 0x100;
  2344. rdev->config.si.sc_hiz_tile_fifo_size = 0x30;
  2345. rdev->config.si.sc_earlyz_tile_fifo_size = 0x130;
  2346. gb_addr_config = TAHITI_GB_ADDR_CONFIG_GOLDEN;
  2347. break;
  2348. case CHIP_VERDE:
  2349. default:
  2350. rdev->config.si.max_shader_engines = 1;
  2351. rdev->config.si.max_tile_pipes = 4;
  2352. rdev->config.si.max_cu_per_sh = 2;
  2353. rdev->config.si.max_sh_per_se = 2;
  2354. rdev->config.si.max_backends_per_se = 4;
  2355. rdev->config.si.max_texture_channel_caches = 4;
  2356. rdev->config.si.max_gprs = 256;
  2357. rdev->config.si.max_gs_threads = 32;
  2358. rdev->config.si.max_hw_contexts = 8;
  2359. rdev->config.si.sc_prim_fifo_size_frontend = 0x20;
  2360. rdev->config.si.sc_prim_fifo_size_backend = 0x40;
  2361. rdev->config.si.sc_hiz_tile_fifo_size = 0x30;
  2362. rdev->config.si.sc_earlyz_tile_fifo_size = 0x130;
  2363. gb_addr_config = VERDE_GB_ADDR_CONFIG_GOLDEN;
  2364. break;
  2365. case CHIP_OLAND:
  2366. rdev->config.si.max_shader_engines = 1;
  2367. rdev->config.si.max_tile_pipes = 4;
  2368. rdev->config.si.max_cu_per_sh = 6;
  2369. rdev->config.si.max_sh_per_se = 1;
  2370. rdev->config.si.max_backends_per_se = 2;
  2371. rdev->config.si.max_texture_channel_caches = 4;
  2372. rdev->config.si.max_gprs = 256;
  2373. rdev->config.si.max_gs_threads = 16;
  2374. rdev->config.si.max_hw_contexts = 8;
  2375. rdev->config.si.sc_prim_fifo_size_frontend = 0x20;
  2376. rdev->config.si.sc_prim_fifo_size_backend = 0x40;
  2377. rdev->config.si.sc_hiz_tile_fifo_size = 0x30;
  2378. rdev->config.si.sc_earlyz_tile_fifo_size = 0x130;
  2379. gb_addr_config = VERDE_GB_ADDR_CONFIG_GOLDEN;
  2380. break;
  2381. case CHIP_HAINAN:
  2382. rdev->config.si.max_shader_engines = 1;
  2383. rdev->config.si.max_tile_pipes = 4;
  2384. rdev->config.si.max_cu_per_sh = 5;
  2385. rdev->config.si.max_sh_per_se = 1;
  2386. rdev->config.si.max_backends_per_se = 1;
  2387. rdev->config.si.max_texture_channel_caches = 2;
  2388. rdev->config.si.max_gprs = 256;
  2389. rdev->config.si.max_gs_threads = 16;
  2390. rdev->config.si.max_hw_contexts = 8;
  2391. rdev->config.si.sc_prim_fifo_size_frontend = 0x20;
  2392. rdev->config.si.sc_prim_fifo_size_backend = 0x40;
  2393. rdev->config.si.sc_hiz_tile_fifo_size = 0x30;
  2394. rdev->config.si.sc_earlyz_tile_fifo_size = 0x130;
  2395. gb_addr_config = HAINAN_GB_ADDR_CONFIG_GOLDEN;
  2396. break;
  2397. }
  2398. /* Initialize HDP */
  2399. for (i = 0, j = 0; i < 32; i++, j += 0x18) {
  2400. WREG32((0x2c14 + j), 0x00000000);
  2401. WREG32((0x2c18 + j), 0x00000000);
  2402. WREG32((0x2c1c + j), 0x00000000);
  2403. WREG32((0x2c20 + j), 0x00000000);
  2404. WREG32((0x2c24 + j), 0x00000000);
  2405. }
  2406. WREG32(GRBM_CNTL, GRBM_READ_TIMEOUT(0xff));
  2407. evergreen_fix_pci_max_read_req_size(rdev);
  2408. WREG32(BIF_FB_EN, FB_READ_EN | FB_WRITE_EN);
  2409. mc_shared_chmap = RREG32(MC_SHARED_CHMAP);
  2410. mc_arb_ramcfg = RREG32(MC_ARB_RAMCFG);
  2411. rdev->config.si.num_tile_pipes = rdev->config.si.max_tile_pipes;
  2412. rdev->config.si.mem_max_burst_length_bytes = 256;
  2413. tmp = (mc_arb_ramcfg & NOOFCOLS_MASK) >> NOOFCOLS_SHIFT;
  2414. rdev->config.si.mem_row_size_in_kb = (4 * (1 << (8 + tmp))) / 1024;
  2415. if (rdev->config.si.mem_row_size_in_kb > 4)
  2416. rdev->config.si.mem_row_size_in_kb = 4;
  2417. /* XXX use MC settings? */
  2418. rdev->config.si.shader_engine_tile_size = 32;
  2419. rdev->config.si.num_gpus = 1;
  2420. rdev->config.si.multi_gpu_tile_size = 64;
  2421. /* fix up row size */
  2422. gb_addr_config &= ~ROW_SIZE_MASK;
  2423. switch (rdev->config.si.mem_row_size_in_kb) {
  2424. case 1:
  2425. default:
  2426. gb_addr_config |= ROW_SIZE(0);
  2427. break;
  2428. case 2:
  2429. gb_addr_config |= ROW_SIZE(1);
  2430. break;
  2431. case 4:
  2432. gb_addr_config |= ROW_SIZE(2);
  2433. break;
  2434. }
  2435. /* setup tiling info dword. gb_addr_config is not adequate since it does
  2436. * not have bank info, so create a custom tiling dword.
  2437. * bits 3:0 num_pipes
  2438. * bits 7:4 num_banks
  2439. * bits 11:8 group_size
  2440. * bits 15:12 row_size
  2441. */
  2442. rdev->config.si.tile_config = 0;
  2443. switch (rdev->config.si.num_tile_pipes) {
  2444. case 1:
  2445. rdev->config.si.tile_config |= (0 << 0);
  2446. break;
  2447. case 2:
  2448. rdev->config.si.tile_config |= (1 << 0);
  2449. break;
  2450. case 4:
  2451. rdev->config.si.tile_config |= (2 << 0);
  2452. break;
  2453. case 8:
  2454. default:
  2455. /* XXX what about 12? */
  2456. rdev->config.si.tile_config |= (3 << 0);
  2457. break;
  2458. }
  2459. switch ((mc_arb_ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT) {
  2460. case 0: /* four banks */
  2461. rdev->config.si.tile_config |= 0 << 4;
  2462. break;
  2463. case 1: /* eight banks */
  2464. rdev->config.si.tile_config |= 1 << 4;
  2465. break;
  2466. case 2: /* sixteen banks */
  2467. default:
  2468. rdev->config.si.tile_config |= 2 << 4;
  2469. break;
  2470. }
  2471. rdev->config.si.tile_config |=
  2472. ((gb_addr_config & PIPE_INTERLEAVE_SIZE_MASK) >> PIPE_INTERLEAVE_SIZE_SHIFT) << 8;
  2473. rdev->config.si.tile_config |=
  2474. ((gb_addr_config & ROW_SIZE_MASK) >> ROW_SIZE_SHIFT) << 12;
  2475. WREG32(GB_ADDR_CONFIG, gb_addr_config);
  2476. WREG32(DMIF_ADDR_CONFIG, gb_addr_config);
  2477. WREG32(DMIF_ADDR_CALC, gb_addr_config);
  2478. WREG32(HDP_ADDR_CONFIG, gb_addr_config);
  2479. WREG32(DMA_TILING_CONFIG + DMA0_REGISTER_OFFSET, gb_addr_config);
  2480. WREG32(DMA_TILING_CONFIG + DMA1_REGISTER_OFFSET, gb_addr_config);
  2481. if (rdev->has_uvd) {
  2482. WREG32(UVD_UDEC_ADDR_CONFIG, gb_addr_config);
  2483. WREG32(UVD_UDEC_DB_ADDR_CONFIG, gb_addr_config);
  2484. WREG32(UVD_UDEC_DBW_ADDR_CONFIG, gb_addr_config);
  2485. }
  2486. si_tiling_mode_table_init(rdev);
  2487. si_setup_rb(rdev, rdev->config.si.max_shader_engines,
  2488. rdev->config.si.max_sh_per_se,
  2489. rdev->config.si.max_backends_per_se);
  2490. si_setup_spi(rdev, rdev->config.si.max_shader_engines,
  2491. rdev->config.si.max_sh_per_se,
  2492. rdev->config.si.max_cu_per_sh);
  2493. /* set HW defaults for 3D engine */
  2494. WREG32(CP_QUEUE_THRESHOLDS, (ROQ_IB1_START(0x16) |
  2495. ROQ_IB2_START(0x2b)));
  2496. WREG32(CP_MEQ_THRESHOLDS, MEQ1_START(0x30) | MEQ2_START(0x60));
  2497. sx_debug_1 = RREG32(SX_DEBUG_1);
  2498. WREG32(SX_DEBUG_1, sx_debug_1);
  2499. WREG32(SPI_CONFIG_CNTL_1, VTX_DONE_DELAY(4));
  2500. WREG32(PA_SC_FIFO_SIZE, (SC_FRONTEND_PRIM_FIFO_SIZE(rdev->config.si.sc_prim_fifo_size_frontend) |
  2501. SC_BACKEND_PRIM_FIFO_SIZE(rdev->config.si.sc_prim_fifo_size_backend) |
  2502. SC_HIZ_TILE_FIFO_SIZE(rdev->config.si.sc_hiz_tile_fifo_size) |
  2503. SC_EARLYZ_TILE_FIFO_SIZE(rdev->config.si.sc_earlyz_tile_fifo_size)));
  2504. WREG32(VGT_NUM_INSTANCES, 1);
  2505. WREG32(CP_PERFMON_CNTL, 0);
  2506. WREG32(SQ_CONFIG, 0);
  2507. WREG32(PA_SC_FORCE_EOV_MAX_CNTS, (FORCE_EOV_MAX_CLK_CNT(4095) |
  2508. FORCE_EOV_MAX_REZ_CNT(255)));
  2509. WREG32(VGT_CACHE_INVALIDATION, CACHE_INVALIDATION(VC_AND_TC) |
  2510. AUTO_INVLD_EN(ES_AND_GS_AUTO));
  2511. WREG32(VGT_GS_VERTEX_REUSE, 16);
  2512. WREG32(PA_SC_LINE_STIPPLE_STATE, 0);
  2513. WREG32(CB_PERFCOUNTER0_SELECT0, 0);
  2514. WREG32(CB_PERFCOUNTER0_SELECT1, 0);
  2515. WREG32(CB_PERFCOUNTER1_SELECT0, 0);
  2516. WREG32(CB_PERFCOUNTER1_SELECT1, 0);
  2517. WREG32(CB_PERFCOUNTER2_SELECT0, 0);
  2518. WREG32(CB_PERFCOUNTER2_SELECT1, 0);
  2519. WREG32(CB_PERFCOUNTER3_SELECT0, 0);
  2520. WREG32(CB_PERFCOUNTER3_SELECT1, 0);
  2521. tmp = RREG32(HDP_MISC_CNTL);
  2522. tmp |= HDP_FLUSH_INVALIDATE_CACHE;
  2523. WREG32(HDP_MISC_CNTL, tmp);
  2524. hdp_host_path_cntl = RREG32(HDP_HOST_PATH_CNTL);
  2525. WREG32(HDP_HOST_PATH_CNTL, hdp_host_path_cntl);
  2526. WREG32(PA_CL_ENHANCE, CLIP_VTX_REORDER_ENA | NUM_CLIP_SEQ(3));
  2527. udelay(50);
  2528. }
  2529. /*
  2530. * GPU scratch registers helpers function.
  2531. */
  2532. static void si_scratch_init(struct radeon_device *rdev)
  2533. {
  2534. int i;
  2535. rdev->scratch.num_reg = 7;
  2536. rdev->scratch.reg_base = SCRATCH_REG0;
  2537. for (i = 0; i < rdev->scratch.num_reg; i++) {
  2538. rdev->scratch.free[i] = true;
  2539. rdev->scratch.reg[i] = rdev->scratch.reg_base + (i * 4);
  2540. }
  2541. }
  2542. void si_fence_ring_emit(struct radeon_device *rdev,
  2543. struct radeon_fence *fence)
  2544. {
  2545. struct radeon_ring *ring = &rdev->ring[fence->ring];
  2546. u64 addr = rdev->fence_drv[fence->ring].gpu_addr;
  2547. /* flush read cache over gart */
  2548. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
  2549. radeon_ring_write(ring, (CP_COHER_CNTL2 - PACKET3_SET_CONFIG_REG_START) >> 2);
  2550. radeon_ring_write(ring, 0);
  2551. radeon_ring_write(ring, PACKET3(PACKET3_SURFACE_SYNC, 3));
  2552. radeon_ring_write(ring, PACKET3_TCL1_ACTION_ENA |
  2553. PACKET3_TC_ACTION_ENA |
  2554. PACKET3_SH_KCACHE_ACTION_ENA |
  2555. PACKET3_SH_ICACHE_ACTION_ENA);
  2556. radeon_ring_write(ring, 0xFFFFFFFF);
  2557. radeon_ring_write(ring, 0);
  2558. radeon_ring_write(ring, 10); /* poll interval */
  2559. /* EVENT_WRITE_EOP - flush caches, send int */
  2560. radeon_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE_EOP, 4));
  2561. radeon_ring_write(ring, EVENT_TYPE(CACHE_FLUSH_AND_INV_TS_EVENT) | EVENT_INDEX(5));
  2562. radeon_ring_write(ring, addr & 0xffffffff);
  2563. radeon_ring_write(ring, (upper_32_bits(addr) & 0xff) | DATA_SEL(1) | INT_SEL(2));
  2564. radeon_ring_write(ring, fence->seq);
  2565. radeon_ring_write(ring, 0);
  2566. }
  2567. /*
  2568. * IB stuff
  2569. */
  2570. void si_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib)
  2571. {
  2572. struct radeon_ring *ring = &rdev->ring[ib->ring];
  2573. u32 header;
  2574. if (ib->is_const_ib) {
  2575. /* set switch buffer packet before const IB */
  2576. radeon_ring_write(ring, PACKET3(PACKET3_SWITCH_BUFFER, 0));
  2577. radeon_ring_write(ring, 0);
  2578. header = PACKET3(PACKET3_INDIRECT_BUFFER_CONST, 2);
  2579. } else {
  2580. u32 next_rptr;
  2581. if (ring->rptr_save_reg) {
  2582. next_rptr = ring->wptr + 3 + 4 + 8;
  2583. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
  2584. radeon_ring_write(ring, ((ring->rptr_save_reg -
  2585. PACKET3_SET_CONFIG_REG_START) >> 2));
  2586. radeon_ring_write(ring, next_rptr);
  2587. } else if (rdev->wb.enabled) {
  2588. next_rptr = ring->wptr + 5 + 4 + 8;
  2589. radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  2590. radeon_ring_write(ring, (1 << 8));
  2591. radeon_ring_write(ring, ring->next_rptr_gpu_addr & 0xfffffffc);
  2592. radeon_ring_write(ring, upper_32_bits(ring->next_rptr_gpu_addr) & 0xffffffff);
  2593. radeon_ring_write(ring, next_rptr);
  2594. }
  2595. header = PACKET3(PACKET3_INDIRECT_BUFFER, 2);
  2596. }
  2597. radeon_ring_write(ring, header);
  2598. radeon_ring_write(ring,
  2599. #ifdef __BIG_ENDIAN
  2600. (2 << 0) |
  2601. #endif
  2602. (ib->gpu_addr & 0xFFFFFFFC));
  2603. radeon_ring_write(ring, upper_32_bits(ib->gpu_addr) & 0xFFFF);
  2604. radeon_ring_write(ring, ib->length_dw |
  2605. (ib->vm ? (ib->vm->id << 24) : 0));
  2606. if (!ib->is_const_ib) {
  2607. /* flush read cache over gart for this vmid */
  2608. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
  2609. radeon_ring_write(ring, (CP_COHER_CNTL2 - PACKET3_SET_CONFIG_REG_START) >> 2);
  2610. radeon_ring_write(ring, ib->vm ? ib->vm->id : 0);
  2611. radeon_ring_write(ring, PACKET3(PACKET3_SURFACE_SYNC, 3));
  2612. radeon_ring_write(ring, PACKET3_TCL1_ACTION_ENA |
  2613. PACKET3_TC_ACTION_ENA |
  2614. PACKET3_SH_KCACHE_ACTION_ENA |
  2615. PACKET3_SH_ICACHE_ACTION_ENA);
  2616. radeon_ring_write(ring, 0xFFFFFFFF);
  2617. radeon_ring_write(ring, 0);
  2618. radeon_ring_write(ring, 10); /* poll interval */
  2619. }
  2620. }
  2621. /*
  2622. * CP.
  2623. */
  2624. static void si_cp_enable(struct radeon_device *rdev, bool enable)
  2625. {
  2626. if (enable)
  2627. WREG32(CP_ME_CNTL, 0);
  2628. else {
  2629. radeon_ttm_set_active_vram_size(rdev, rdev->mc.visible_vram_size);
  2630. WREG32(CP_ME_CNTL, (CP_ME_HALT | CP_PFP_HALT | CP_CE_HALT));
  2631. WREG32(SCRATCH_UMSK, 0);
  2632. rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false;
  2633. rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX].ready = false;
  2634. rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX].ready = false;
  2635. }
  2636. udelay(50);
  2637. }
  2638. static int si_cp_load_microcode(struct radeon_device *rdev)
  2639. {
  2640. const __be32 *fw_data;
  2641. int i;
  2642. if (!rdev->me_fw || !rdev->pfp_fw)
  2643. return -EINVAL;
  2644. si_cp_enable(rdev, false);
  2645. /* PFP */
  2646. fw_data = (const __be32 *)rdev->pfp_fw->data;
  2647. WREG32(CP_PFP_UCODE_ADDR, 0);
  2648. for (i = 0; i < SI_PFP_UCODE_SIZE; i++)
  2649. WREG32(CP_PFP_UCODE_DATA, be32_to_cpup(fw_data++));
  2650. WREG32(CP_PFP_UCODE_ADDR, 0);
  2651. /* CE */
  2652. fw_data = (const __be32 *)rdev->ce_fw->data;
  2653. WREG32(CP_CE_UCODE_ADDR, 0);
  2654. for (i = 0; i < SI_CE_UCODE_SIZE; i++)
  2655. WREG32(CP_CE_UCODE_DATA, be32_to_cpup(fw_data++));
  2656. WREG32(CP_CE_UCODE_ADDR, 0);
  2657. /* ME */
  2658. fw_data = (const __be32 *)rdev->me_fw->data;
  2659. WREG32(CP_ME_RAM_WADDR, 0);
  2660. for (i = 0; i < SI_PM4_UCODE_SIZE; i++)
  2661. WREG32(CP_ME_RAM_DATA, be32_to_cpup(fw_data++));
  2662. WREG32(CP_ME_RAM_WADDR, 0);
  2663. WREG32(CP_PFP_UCODE_ADDR, 0);
  2664. WREG32(CP_CE_UCODE_ADDR, 0);
  2665. WREG32(CP_ME_RAM_WADDR, 0);
  2666. WREG32(CP_ME_RAM_RADDR, 0);
  2667. return 0;
  2668. }
  2669. static int si_cp_start(struct radeon_device *rdev)
  2670. {
  2671. struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  2672. int r, i;
  2673. r = radeon_ring_lock(rdev, ring, 7 + 4);
  2674. if (r) {
  2675. DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
  2676. return r;
  2677. }
  2678. /* init the CP */
  2679. radeon_ring_write(ring, PACKET3(PACKET3_ME_INITIALIZE, 5));
  2680. radeon_ring_write(ring, 0x1);
  2681. radeon_ring_write(ring, 0x0);
  2682. radeon_ring_write(ring, rdev->config.si.max_hw_contexts - 1);
  2683. radeon_ring_write(ring, PACKET3_ME_INITIALIZE_DEVICE_ID(1));
  2684. radeon_ring_write(ring, 0);
  2685. radeon_ring_write(ring, 0);
  2686. /* init the CE partitions */
  2687. radeon_ring_write(ring, PACKET3(PACKET3_SET_BASE, 2));
  2688. radeon_ring_write(ring, PACKET3_BASE_INDEX(CE_PARTITION_BASE));
  2689. radeon_ring_write(ring, 0xc000);
  2690. radeon_ring_write(ring, 0xe000);
  2691. radeon_ring_unlock_commit(rdev, ring);
  2692. si_cp_enable(rdev, true);
  2693. r = radeon_ring_lock(rdev, ring, si_default_size + 10);
  2694. if (r) {
  2695. DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
  2696. return r;
  2697. }
  2698. /* setup clear context state */
  2699. radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
  2700. radeon_ring_write(ring, PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);
  2701. for (i = 0; i < si_default_size; i++)
  2702. radeon_ring_write(ring, si_default_state[i]);
  2703. radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
  2704. radeon_ring_write(ring, PACKET3_PREAMBLE_END_CLEAR_STATE);
  2705. /* set clear context state */
  2706. radeon_ring_write(ring, PACKET3(PACKET3_CLEAR_STATE, 0));
  2707. radeon_ring_write(ring, 0);
  2708. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 2));
  2709. radeon_ring_write(ring, 0x00000316);
  2710. radeon_ring_write(ring, 0x0000000e); /* VGT_VERTEX_REUSE_BLOCK_CNTL */
  2711. radeon_ring_write(ring, 0x00000010); /* VGT_OUT_DEALLOC_CNTL */
  2712. radeon_ring_unlock_commit(rdev, ring);
  2713. for (i = RADEON_RING_TYPE_GFX_INDEX; i <= CAYMAN_RING_TYPE_CP2_INDEX; ++i) {
  2714. ring = &rdev->ring[i];
  2715. r = radeon_ring_lock(rdev, ring, 2);
  2716. /* clear the compute context state */
  2717. radeon_ring_write(ring, PACKET3_COMPUTE(PACKET3_CLEAR_STATE, 0));
  2718. radeon_ring_write(ring, 0);
  2719. radeon_ring_unlock_commit(rdev, ring);
  2720. }
  2721. return 0;
  2722. }
  2723. static void si_cp_fini(struct radeon_device *rdev)
  2724. {
  2725. struct radeon_ring *ring;
  2726. si_cp_enable(rdev, false);
  2727. ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  2728. radeon_ring_fini(rdev, ring);
  2729. radeon_scratch_free(rdev, ring->rptr_save_reg);
  2730. ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
  2731. radeon_ring_fini(rdev, ring);
  2732. radeon_scratch_free(rdev, ring->rptr_save_reg);
  2733. ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
  2734. radeon_ring_fini(rdev, ring);
  2735. radeon_scratch_free(rdev, ring->rptr_save_reg);
  2736. }
  2737. static int si_cp_resume(struct radeon_device *rdev)
  2738. {
  2739. struct radeon_ring *ring;
  2740. u32 tmp;
  2741. u32 rb_bufsz;
  2742. int r;
  2743. /* Reset cp; if cp is reset, then PA, SH, VGT also need to be reset */
  2744. WREG32(GRBM_SOFT_RESET, (SOFT_RESET_CP |
  2745. SOFT_RESET_PA |
  2746. SOFT_RESET_VGT |
  2747. SOFT_RESET_SPI |
  2748. SOFT_RESET_SX));
  2749. RREG32(GRBM_SOFT_RESET);
  2750. mdelay(15);
  2751. WREG32(GRBM_SOFT_RESET, 0);
  2752. RREG32(GRBM_SOFT_RESET);
  2753. WREG32(CP_SEM_WAIT_TIMER, 0x0);
  2754. WREG32(CP_SEM_INCOMPLETE_TIMER_CNTL, 0x0);
  2755. /* Set the write pointer delay */
  2756. WREG32(CP_RB_WPTR_DELAY, 0);
  2757. WREG32(CP_DEBUG, 0);
  2758. WREG32(SCRATCH_ADDR, ((rdev->wb.gpu_addr + RADEON_WB_SCRATCH_OFFSET) >> 8) & 0xFFFFFFFF);
  2759. /* ring 0 - compute and gfx */
  2760. /* Set ring buffer size */
  2761. ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  2762. rb_bufsz = drm_order(ring->ring_size / 8);
  2763. tmp = (drm_order(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
  2764. #ifdef __BIG_ENDIAN
  2765. tmp |= BUF_SWAP_32BIT;
  2766. #endif
  2767. WREG32(CP_RB0_CNTL, tmp);
  2768. /* Initialize the ring buffer's read and write pointers */
  2769. WREG32(CP_RB0_CNTL, tmp | RB_RPTR_WR_ENA);
  2770. ring->wptr = 0;
  2771. WREG32(CP_RB0_WPTR, ring->wptr);
  2772. /* set the wb address whether it's enabled or not */
  2773. WREG32(CP_RB0_RPTR_ADDR, (rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFFFFFFFC);
  2774. WREG32(CP_RB0_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFF);
  2775. if (rdev->wb.enabled)
  2776. WREG32(SCRATCH_UMSK, 0xff);
  2777. else {
  2778. tmp |= RB_NO_UPDATE;
  2779. WREG32(SCRATCH_UMSK, 0);
  2780. }
  2781. mdelay(1);
  2782. WREG32(CP_RB0_CNTL, tmp);
  2783. WREG32(CP_RB0_BASE, ring->gpu_addr >> 8);
  2784. ring->rptr = RREG32(CP_RB0_RPTR);
  2785. /* ring1 - compute only */
  2786. /* Set ring buffer size */
  2787. ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
  2788. rb_bufsz = drm_order(ring->ring_size / 8);
  2789. tmp = (drm_order(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
  2790. #ifdef __BIG_ENDIAN
  2791. tmp |= BUF_SWAP_32BIT;
  2792. #endif
  2793. WREG32(CP_RB1_CNTL, tmp);
  2794. /* Initialize the ring buffer's read and write pointers */
  2795. WREG32(CP_RB1_CNTL, tmp | RB_RPTR_WR_ENA);
  2796. ring->wptr = 0;
  2797. WREG32(CP_RB1_WPTR, ring->wptr);
  2798. /* set the wb address whether it's enabled or not */
  2799. WREG32(CP_RB1_RPTR_ADDR, (rdev->wb.gpu_addr + RADEON_WB_CP1_RPTR_OFFSET) & 0xFFFFFFFC);
  2800. WREG32(CP_RB1_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP1_RPTR_OFFSET) & 0xFF);
  2801. mdelay(1);
  2802. WREG32(CP_RB1_CNTL, tmp);
  2803. WREG32(CP_RB1_BASE, ring->gpu_addr >> 8);
  2804. ring->rptr = RREG32(CP_RB1_RPTR);
  2805. /* ring2 - compute only */
  2806. /* Set ring buffer size */
  2807. ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
  2808. rb_bufsz = drm_order(ring->ring_size / 8);
  2809. tmp = (drm_order(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
  2810. #ifdef __BIG_ENDIAN
  2811. tmp |= BUF_SWAP_32BIT;
  2812. #endif
  2813. WREG32(CP_RB2_CNTL, tmp);
  2814. /* Initialize the ring buffer's read and write pointers */
  2815. WREG32(CP_RB2_CNTL, tmp | RB_RPTR_WR_ENA);
  2816. ring->wptr = 0;
  2817. WREG32(CP_RB2_WPTR, ring->wptr);
  2818. /* set the wb address whether it's enabled or not */
  2819. WREG32(CP_RB2_RPTR_ADDR, (rdev->wb.gpu_addr + RADEON_WB_CP2_RPTR_OFFSET) & 0xFFFFFFFC);
  2820. WREG32(CP_RB2_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP2_RPTR_OFFSET) & 0xFF);
  2821. mdelay(1);
  2822. WREG32(CP_RB2_CNTL, tmp);
  2823. WREG32(CP_RB2_BASE, ring->gpu_addr >> 8);
  2824. ring->rptr = RREG32(CP_RB2_RPTR);
  2825. /* start the rings */
  2826. si_cp_start(rdev);
  2827. rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = true;
  2828. rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX].ready = true;
  2829. rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX].ready = true;
  2830. r = radeon_ring_test(rdev, RADEON_RING_TYPE_GFX_INDEX, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]);
  2831. if (r) {
  2832. rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false;
  2833. rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX].ready = false;
  2834. rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX].ready = false;
  2835. return r;
  2836. }
  2837. r = radeon_ring_test(rdev, CAYMAN_RING_TYPE_CP1_INDEX, &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX]);
  2838. if (r) {
  2839. rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX].ready = false;
  2840. }
  2841. r = radeon_ring_test(rdev, CAYMAN_RING_TYPE_CP2_INDEX, &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX]);
  2842. if (r) {
  2843. rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX].ready = false;
  2844. }
  2845. return 0;
  2846. }
  2847. static u32 si_gpu_check_soft_reset(struct radeon_device *rdev)
  2848. {
  2849. u32 reset_mask = 0;
  2850. u32 tmp;
  2851. /* GRBM_STATUS */
  2852. tmp = RREG32(GRBM_STATUS);
  2853. if (tmp & (PA_BUSY | SC_BUSY |
  2854. BCI_BUSY | SX_BUSY |
  2855. TA_BUSY | VGT_BUSY |
  2856. DB_BUSY | CB_BUSY |
  2857. GDS_BUSY | SPI_BUSY |
  2858. IA_BUSY | IA_BUSY_NO_DMA))
  2859. reset_mask |= RADEON_RESET_GFX;
  2860. if (tmp & (CF_RQ_PENDING | PF_RQ_PENDING |
  2861. CP_BUSY | CP_COHERENCY_BUSY))
  2862. reset_mask |= RADEON_RESET_CP;
  2863. if (tmp & GRBM_EE_BUSY)
  2864. reset_mask |= RADEON_RESET_GRBM | RADEON_RESET_GFX | RADEON_RESET_CP;
  2865. /* GRBM_STATUS2 */
  2866. tmp = RREG32(GRBM_STATUS2);
  2867. if (tmp & (RLC_RQ_PENDING | RLC_BUSY))
  2868. reset_mask |= RADEON_RESET_RLC;
  2869. /* DMA_STATUS_REG 0 */
  2870. tmp = RREG32(DMA_STATUS_REG + DMA0_REGISTER_OFFSET);
  2871. if (!(tmp & DMA_IDLE))
  2872. reset_mask |= RADEON_RESET_DMA;
  2873. /* DMA_STATUS_REG 1 */
  2874. tmp = RREG32(DMA_STATUS_REG + DMA1_REGISTER_OFFSET);
  2875. if (!(tmp & DMA_IDLE))
  2876. reset_mask |= RADEON_RESET_DMA1;
  2877. /* SRBM_STATUS2 */
  2878. tmp = RREG32(SRBM_STATUS2);
  2879. if (tmp & DMA_BUSY)
  2880. reset_mask |= RADEON_RESET_DMA;
  2881. if (tmp & DMA1_BUSY)
  2882. reset_mask |= RADEON_RESET_DMA1;
  2883. /* SRBM_STATUS */
  2884. tmp = RREG32(SRBM_STATUS);
  2885. if (tmp & IH_BUSY)
  2886. reset_mask |= RADEON_RESET_IH;
  2887. if (tmp & SEM_BUSY)
  2888. reset_mask |= RADEON_RESET_SEM;
  2889. if (tmp & GRBM_RQ_PENDING)
  2890. reset_mask |= RADEON_RESET_GRBM;
  2891. if (tmp & VMC_BUSY)
  2892. reset_mask |= RADEON_RESET_VMC;
  2893. if (tmp & (MCB_BUSY | MCB_NON_DISPLAY_BUSY |
  2894. MCC_BUSY | MCD_BUSY))
  2895. reset_mask |= RADEON_RESET_MC;
  2896. if (evergreen_is_display_hung(rdev))
  2897. reset_mask |= RADEON_RESET_DISPLAY;
  2898. /* VM_L2_STATUS */
  2899. tmp = RREG32(VM_L2_STATUS);
  2900. if (tmp & L2_BUSY)
  2901. reset_mask |= RADEON_RESET_VMC;
  2902. /* Skip MC reset as it's mostly likely not hung, just busy */
  2903. if (reset_mask & RADEON_RESET_MC) {
  2904. DRM_DEBUG("MC busy: 0x%08X, clearing.\n", reset_mask);
  2905. reset_mask &= ~RADEON_RESET_MC;
  2906. }
  2907. return reset_mask;
  2908. }
  2909. static void si_gpu_soft_reset(struct radeon_device *rdev, u32 reset_mask)
  2910. {
  2911. struct evergreen_mc_save save;
  2912. u32 grbm_soft_reset = 0, srbm_soft_reset = 0;
  2913. u32 tmp;
  2914. if (reset_mask == 0)
  2915. return;
  2916. dev_info(rdev->dev, "GPU softreset: 0x%08X\n", reset_mask);
  2917. evergreen_print_gpu_status_regs(rdev);
  2918. dev_info(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_ADDR 0x%08X\n",
  2919. RREG32(VM_CONTEXT1_PROTECTION_FAULT_ADDR));
  2920. dev_info(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_STATUS 0x%08X\n",
  2921. RREG32(VM_CONTEXT1_PROTECTION_FAULT_STATUS));
  2922. /* Disable CP parsing/prefetching */
  2923. WREG32(CP_ME_CNTL, CP_ME_HALT | CP_PFP_HALT | CP_CE_HALT);
  2924. if (reset_mask & RADEON_RESET_DMA) {
  2925. /* dma0 */
  2926. tmp = RREG32(DMA_RB_CNTL + DMA0_REGISTER_OFFSET);
  2927. tmp &= ~DMA_RB_ENABLE;
  2928. WREG32(DMA_RB_CNTL + DMA0_REGISTER_OFFSET, tmp);
  2929. }
  2930. if (reset_mask & RADEON_RESET_DMA1) {
  2931. /* dma1 */
  2932. tmp = RREG32(DMA_RB_CNTL + DMA1_REGISTER_OFFSET);
  2933. tmp &= ~DMA_RB_ENABLE;
  2934. WREG32(DMA_RB_CNTL + DMA1_REGISTER_OFFSET, tmp);
  2935. }
  2936. udelay(50);
  2937. evergreen_mc_stop(rdev, &save);
  2938. if (evergreen_mc_wait_for_idle(rdev)) {
  2939. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  2940. }
  2941. if (reset_mask & (RADEON_RESET_GFX | RADEON_RESET_COMPUTE | RADEON_RESET_CP)) {
  2942. grbm_soft_reset = SOFT_RESET_CB |
  2943. SOFT_RESET_DB |
  2944. SOFT_RESET_GDS |
  2945. SOFT_RESET_PA |
  2946. SOFT_RESET_SC |
  2947. SOFT_RESET_BCI |
  2948. SOFT_RESET_SPI |
  2949. SOFT_RESET_SX |
  2950. SOFT_RESET_TC |
  2951. SOFT_RESET_TA |
  2952. SOFT_RESET_VGT |
  2953. SOFT_RESET_IA;
  2954. }
  2955. if (reset_mask & RADEON_RESET_CP) {
  2956. grbm_soft_reset |= SOFT_RESET_CP | SOFT_RESET_VGT;
  2957. srbm_soft_reset |= SOFT_RESET_GRBM;
  2958. }
  2959. if (reset_mask & RADEON_RESET_DMA)
  2960. srbm_soft_reset |= SOFT_RESET_DMA;
  2961. if (reset_mask & RADEON_RESET_DMA1)
  2962. srbm_soft_reset |= SOFT_RESET_DMA1;
  2963. if (reset_mask & RADEON_RESET_DISPLAY)
  2964. srbm_soft_reset |= SOFT_RESET_DC;
  2965. if (reset_mask & RADEON_RESET_RLC)
  2966. grbm_soft_reset |= SOFT_RESET_RLC;
  2967. if (reset_mask & RADEON_RESET_SEM)
  2968. srbm_soft_reset |= SOFT_RESET_SEM;
  2969. if (reset_mask & RADEON_RESET_IH)
  2970. srbm_soft_reset |= SOFT_RESET_IH;
  2971. if (reset_mask & RADEON_RESET_GRBM)
  2972. srbm_soft_reset |= SOFT_RESET_GRBM;
  2973. if (reset_mask & RADEON_RESET_VMC)
  2974. srbm_soft_reset |= SOFT_RESET_VMC;
  2975. if (reset_mask & RADEON_RESET_MC)
  2976. srbm_soft_reset |= SOFT_RESET_MC;
  2977. if (grbm_soft_reset) {
  2978. tmp = RREG32(GRBM_SOFT_RESET);
  2979. tmp |= grbm_soft_reset;
  2980. dev_info(rdev->dev, "GRBM_SOFT_RESET=0x%08X\n", tmp);
  2981. WREG32(GRBM_SOFT_RESET, tmp);
  2982. tmp = RREG32(GRBM_SOFT_RESET);
  2983. udelay(50);
  2984. tmp &= ~grbm_soft_reset;
  2985. WREG32(GRBM_SOFT_RESET, tmp);
  2986. tmp = RREG32(GRBM_SOFT_RESET);
  2987. }
  2988. if (srbm_soft_reset) {
  2989. tmp = RREG32(SRBM_SOFT_RESET);
  2990. tmp |= srbm_soft_reset;
  2991. dev_info(rdev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
  2992. WREG32(SRBM_SOFT_RESET, tmp);
  2993. tmp = RREG32(SRBM_SOFT_RESET);
  2994. udelay(50);
  2995. tmp &= ~srbm_soft_reset;
  2996. WREG32(SRBM_SOFT_RESET, tmp);
  2997. tmp = RREG32(SRBM_SOFT_RESET);
  2998. }
  2999. /* Wait a little for things to settle down */
  3000. udelay(50);
  3001. evergreen_mc_resume(rdev, &save);
  3002. udelay(50);
  3003. evergreen_print_gpu_status_regs(rdev);
  3004. }
  3005. int si_asic_reset(struct radeon_device *rdev)
  3006. {
  3007. u32 reset_mask;
  3008. reset_mask = si_gpu_check_soft_reset(rdev);
  3009. if (reset_mask)
  3010. r600_set_bios_scratch_engine_hung(rdev, true);
  3011. si_gpu_soft_reset(rdev, reset_mask);
  3012. reset_mask = si_gpu_check_soft_reset(rdev);
  3013. if (!reset_mask)
  3014. r600_set_bios_scratch_engine_hung(rdev, false);
  3015. return 0;
  3016. }
  3017. /**
  3018. * si_gfx_is_lockup - Check if the GFX engine is locked up
  3019. *
  3020. * @rdev: radeon_device pointer
  3021. * @ring: radeon_ring structure holding ring information
  3022. *
  3023. * Check if the GFX engine is locked up.
  3024. * Returns true if the engine appears to be locked up, false if not.
  3025. */
  3026. bool si_gfx_is_lockup(struct radeon_device *rdev, struct radeon_ring *ring)
  3027. {
  3028. u32 reset_mask = si_gpu_check_soft_reset(rdev);
  3029. if (!(reset_mask & (RADEON_RESET_GFX |
  3030. RADEON_RESET_COMPUTE |
  3031. RADEON_RESET_CP))) {
  3032. radeon_ring_lockup_update(ring);
  3033. return false;
  3034. }
  3035. /* force CP activities */
  3036. radeon_ring_force_activity(rdev, ring);
  3037. return radeon_ring_test_lockup(rdev, ring);
  3038. }
  3039. /**
  3040. * si_dma_is_lockup - Check if the DMA engine is locked up
  3041. *
  3042. * @rdev: radeon_device pointer
  3043. * @ring: radeon_ring structure holding ring information
  3044. *
  3045. * Check if the async DMA engine is locked up.
  3046. * Returns true if the engine appears to be locked up, false if not.
  3047. */
  3048. bool si_dma_is_lockup(struct radeon_device *rdev, struct radeon_ring *ring)
  3049. {
  3050. u32 reset_mask = si_gpu_check_soft_reset(rdev);
  3051. u32 mask;
  3052. if (ring->idx == R600_RING_TYPE_DMA_INDEX)
  3053. mask = RADEON_RESET_DMA;
  3054. else
  3055. mask = RADEON_RESET_DMA1;
  3056. if (!(reset_mask & mask)) {
  3057. radeon_ring_lockup_update(ring);
  3058. return false;
  3059. }
  3060. /* force ring activities */
  3061. radeon_ring_force_activity(rdev, ring);
  3062. return radeon_ring_test_lockup(rdev, ring);
  3063. }
  3064. /* MC */
  3065. static void si_mc_program(struct radeon_device *rdev)
  3066. {
  3067. struct evergreen_mc_save save;
  3068. u32 tmp;
  3069. int i, j;
  3070. /* Initialize HDP */
  3071. for (i = 0, j = 0; i < 32; i++, j += 0x18) {
  3072. WREG32((0x2c14 + j), 0x00000000);
  3073. WREG32((0x2c18 + j), 0x00000000);
  3074. WREG32((0x2c1c + j), 0x00000000);
  3075. WREG32((0x2c20 + j), 0x00000000);
  3076. WREG32((0x2c24 + j), 0x00000000);
  3077. }
  3078. WREG32(HDP_REG_COHERENCY_FLUSH_CNTL, 0);
  3079. evergreen_mc_stop(rdev, &save);
  3080. if (radeon_mc_wait_for_idle(rdev)) {
  3081. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  3082. }
  3083. if (!ASIC_IS_NODCE(rdev))
  3084. /* Lockout access through VGA aperture*/
  3085. WREG32(VGA_HDP_CONTROL, VGA_MEMORY_DISABLE);
  3086. /* Update configuration */
  3087. WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
  3088. rdev->mc.vram_start >> 12);
  3089. WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
  3090. rdev->mc.vram_end >> 12);
  3091. WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR,
  3092. rdev->vram_scratch.gpu_addr >> 12);
  3093. tmp = ((rdev->mc.vram_end >> 24) & 0xFFFF) << 16;
  3094. tmp |= ((rdev->mc.vram_start >> 24) & 0xFFFF);
  3095. WREG32(MC_VM_FB_LOCATION, tmp);
  3096. /* XXX double check these! */
  3097. WREG32(HDP_NONSURFACE_BASE, (rdev->mc.vram_start >> 8));
  3098. WREG32(HDP_NONSURFACE_INFO, (2 << 7) | (1 << 30));
  3099. WREG32(HDP_NONSURFACE_SIZE, 0x3FFFFFFF);
  3100. WREG32(MC_VM_AGP_BASE, 0);
  3101. WREG32(MC_VM_AGP_TOP, 0x0FFFFFFF);
  3102. WREG32(MC_VM_AGP_BOT, 0x0FFFFFFF);
  3103. if (radeon_mc_wait_for_idle(rdev)) {
  3104. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  3105. }
  3106. evergreen_mc_resume(rdev, &save);
  3107. if (!ASIC_IS_NODCE(rdev)) {
  3108. /* we need to own VRAM, so turn off the VGA renderer here
  3109. * to stop it overwriting our objects */
  3110. rv515_vga_render_disable(rdev);
  3111. }
  3112. }
  3113. static void si_vram_gtt_location(struct radeon_device *rdev,
  3114. struct radeon_mc *mc)
  3115. {
  3116. if (mc->mc_vram_size > 0xFFC0000000ULL) {
  3117. /* leave room for at least 1024M GTT */
  3118. dev_warn(rdev->dev, "limiting VRAM\n");
  3119. mc->real_vram_size = 0xFFC0000000ULL;
  3120. mc->mc_vram_size = 0xFFC0000000ULL;
  3121. }
  3122. radeon_vram_location(rdev, &rdev->mc, 0);
  3123. rdev->mc.gtt_base_align = 0;
  3124. radeon_gtt_location(rdev, mc);
  3125. }
  3126. static int si_mc_init(struct radeon_device *rdev)
  3127. {
  3128. u32 tmp;
  3129. int chansize, numchan;
  3130. /* Get VRAM informations */
  3131. rdev->mc.vram_is_ddr = true;
  3132. tmp = RREG32(MC_ARB_RAMCFG);
  3133. if (tmp & CHANSIZE_OVERRIDE) {
  3134. chansize = 16;
  3135. } else if (tmp & CHANSIZE_MASK) {
  3136. chansize = 64;
  3137. } else {
  3138. chansize = 32;
  3139. }
  3140. tmp = RREG32(MC_SHARED_CHMAP);
  3141. switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
  3142. case 0:
  3143. default:
  3144. numchan = 1;
  3145. break;
  3146. case 1:
  3147. numchan = 2;
  3148. break;
  3149. case 2:
  3150. numchan = 4;
  3151. break;
  3152. case 3:
  3153. numchan = 8;
  3154. break;
  3155. case 4:
  3156. numchan = 3;
  3157. break;
  3158. case 5:
  3159. numchan = 6;
  3160. break;
  3161. case 6:
  3162. numchan = 10;
  3163. break;
  3164. case 7:
  3165. numchan = 12;
  3166. break;
  3167. case 8:
  3168. numchan = 16;
  3169. break;
  3170. }
  3171. rdev->mc.vram_width = numchan * chansize;
  3172. /* Could aper size report 0 ? */
  3173. rdev->mc.aper_base = pci_resource_start(rdev->pdev, 0);
  3174. rdev->mc.aper_size = pci_resource_len(rdev->pdev, 0);
  3175. /* size in MB on si */
  3176. rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE) * 1024ULL * 1024ULL;
  3177. rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE) * 1024ULL * 1024ULL;
  3178. rdev->mc.visible_vram_size = rdev->mc.aper_size;
  3179. si_vram_gtt_location(rdev, &rdev->mc);
  3180. radeon_update_bandwidth_info(rdev);
  3181. return 0;
  3182. }
  3183. /*
  3184. * GART
  3185. */
  3186. void si_pcie_gart_tlb_flush(struct radeon_device *rdev)
  3187. {
  3188. /* flush hdp cache */
  3189. WREG32(HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1);
  3190. /* bits 0-15 are the VM contexts0-15 */
  3191. WREG32(VM_INVALIDATE_REQUEST, 1);
  3192. }
  3193. static int si_pcie_gart_enable(struct radeon_device *rdev)
  3194. {
  3195. int r, i;
  3196. if (rdev->gart.robj == NULL) {
  3197. dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
  3198. return -EINVAL;
  3199. }
  3200. r = radeon_gart_table_vram_pin(rdev);
  3201. if (r)
  3202. return r;
  3203. radeon_gart_restore(rdev);
  3204. /* Setup TLB control */
  3205. WREG32(MC_VM_MX_L1_TLB_CNTL,
  3206. (0xA << 7) |
  3207. ENABLE_L1_TLB |
  3208. SYSTEM_ACCESS_MODE_NOT_IN_SYS |
  3209. ENABLE_ADVANCED_DRIVER_MODEL |
  3210. SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU);
  3211. /* Setup L2 cache */
  3212. WREG32(VM_L2_CNTL, ENABLE_L2_CACHE |
  3213. ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
  3214. ENABLE_L2_PDE0_CACHE_LRU_UPDATE_BY_WRITE |
  3215. EFFECTIVE_L2_QUEUE_SIZE(7) |
  3216. CONTEXT1_IDENTITY_ACCESS_MODE(1));
  3217. WREG32(VM_L2_CNTL2, INVALIDATE_ALL_L1_TLBS | INVALIDATE_L2_CACHE);
  3218. WREG32(VM_L2_CNTL3, L2_CACHE_BIGK_ASSOCIATIVITY |
  3219. L2_CACHE_BIGK_FRAGMENT_SIZE(0));
  3220. /* setup context0 */
  3221. WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR, rdev->mc.gtt_start >> 12);
  3222. WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR, rdev->mc.gtt_end >> 12);
  3223. WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, rdev->gart.table_addr >> 12);
  3224. WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR,
  3225. (u32)(rdev->dummy_page.addr >> 12));
  3226. WREG32(VM_CONTEXT0_CNTL2, 0);
  3227. WREG32(VM_CONTEXT0_CNTL, (ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) |
  3228. RANGE_PROTECTION_FAULT_ENABLE_DEFAULT));
  3229. WREG32(0x15D4, 0);
  3230. WREG32(0x15D8, 0);
  3231. WREG32(0x15DC, 0);
  3232. /* empty context1-15 */
  3233. /* set vm size, must be a multiple of 4 */
  3234. WREG32(VM_CONTEXT1_PAGE_TABLE_START_ADDR, 0);
  3235. WREG32(VM_CONTEXT1_PAGE_TABLE_END_ADDR, rdev->vm_manager.max_pfn);
  3236. /* Assign the pt base to something valid for now; the pts used for
  3237. * the VMs are determined by the application and setup and assigned
  3238. * on the fly in the vm part of radeon_gart.c
  3239. */
  3240. for (i = 1; i < 16; i++) {
  3241. if (i < 8)
  3242. WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (i << 2),
  3243. rdev->gart.table_addr >> 12);
  3244. else
  3245. WREG32(VM_CONTEXT8_PAGE_TABLE_BASE_ADDR + ((i - 8) << 2),
  3246. rdev->gart.table_addr >> 12);
  3247. }
  3248. /* enable context1-15 */
  3249. WREG32(VM_CONTEXT1_PROTECTION_FAULT_DEFAULT_ADDR,
  3250. (u32)(rdev->dummy_page.addr >> 12));
  3251. WREG32(VM_CONTEXT1_CNTL2, 4);
  3252. WREG32(VM_CONTEXT1_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(1) |
  3253. RANGE_PROTECTION_FAULT_ENABLE_INTERRUPT |
  3254. RANGE_PROTECTION_FAULT_ENABLE_DEFAULT |
  3255. DUMMY_PAGE_PROTECTION_FAULT_ENABLE_INTERRUPT |
  3256. DUMMY_PAGE_PROTECTION_FAULT_ENABLE_DEFAULT |
  3257. PDE0_PROTECTION_FAULT_ENABLE_INTERRUPT |
  3258. PDE0_PROTECTION_FAULT_ENABLE_DEFAULT |
  3259. VALID_PROTECTION_FAULT_ENABLE_INTERRUPT |
  3260. VALID_PROTECTION_FAULT_ENABLE_DEFAULT |
  3261. READ_PROTECTION_FAULT_ENABLE_INTERRUPT |
  3262. READ_PROTECTION_FAULT_ENABLE_DEFAULT |
  3263. WRITE_PROTECTION_FAULT_ENABLE_INTERRUPT |
  3264. WRITE_PROTECTION_FAULT_ENABLE_DEFAULT);
  3265. si_pcie_gart_tlb_flush(rdev);
  3266. DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
  3267. (unsigned)(rdev->mc.gtt_size >> 20),
  3268. (unsigned long long)rdev->gart.table_addr);
  3269. rdev->gart.ready = true;
  3270. return 0;
  3271. }
  3272. static void si_pcie_gart_disable(struct radeon_device *rdev)
  3273. {
  3274. /* Disable all tables */
  3275. WREG32(VM_CONTEXT0_CNTL, 0);
  3276. WREG32(VM_CONTEXT1_CNTL, 0);
  3277. /* Setup TLB control */
  3278. WREG32(MC_VM_MX_L1_TLB_CNTL, SYSTEM_ACCESS_MODE_NOT_IN_SYS |
  3279. SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU);
  3280. /* Setup L2 cache */
  3281. WREG32(VM_L2_CNTL, ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
  3282. ENABLE_L2_PDE0_CACHE_LRU_UPDATE_BY_WRITE |
  3283. EFFECTIVE_L2_QUEUE_SIZE(7) |
  3284. CONTEXT1_IDENTITY_ACCESS_MODE(1));
  3285. WREG32(VM_L2_CNTL2, 0);
  3286. WREG32(VM_L2_CNTL3, L2_CACHE_BIGK_ASSOCIATIVITY |
  3287. L2_CACHE_BIGK_FRAGMENT_SIZE(0));
  3288. radeon_gart_table_vram_unpin(rdev);
  3289. }
  3290. static void si_pcie_gart_fini(struct radeon_device *rdev)
  3291. {
  3292. si_pcie_gart_disable(rdev);
  3293. radeon_gart_table_vram_free(rdev);
  3294. radeon_gart_fini(rdev);
  3295. }
  3296. /* vm parser */
  3297. static bool si_vm_reg_valid(u32 reg)
  3298. {
  3299. /* context regs are fine */
  3300. if (reg >= 0x28000)
  3301. return true;
  3302. /* check config regs */
  3303. switch (reg) {
  3304. case GRBM_GFX_INDEX:
  3305. case CP_STRMOUT_CNTL:
  3306. case VGT_VTX_VECT_EJECT_REG:
  3307. case VGT_CACHE_INVALIDATION:
  3308. case VGT_ESGS_RING_SIZE:
  3309. case VGT_GSVS_RING_SIZE:
  3310. case VGT_GS_VERTEX_REUSE:
  3311. case VGT_PRIMITIVE_TYPE:
  3312. case VGT_INDEX_TYPE:
  3313. case VGT_NUM_INDICES:
  3314. case VGT_NUM_INSTANCES:
  3315. case VGT_TF_RING_SIZE:
  3316. case VGT_HS_OFFCHIP_PARAM:
  3317. case VGT_TF_MEMORY_BASE:
  3318. case PA_CL_ENHANCE:
  3319. case PA_SU_LINE_STIPPLE_VALUE:
  3320. case PA_SC_LINE_STIPPLE_STATE:
  3321. case PA_SC_ENHANCE:
  3322. case SQC_CACHES:
  3323. case SPI_STATIC_THREAD_MGMT_1:
  3324. case SPI_STATIC_THREAD_MGMT_2:
  3325. case SPI_STATIC_THREAD_MGMT_3:
  3326. case SPI_PS_MAX_WAVE_ID:
  3327. case SPI_CONFIG_CNTL:
  3328. case SPI_CONFIG_CNTL_1:
  3329. case TA_CNTL_AUX:
  3330. return true;
  3331. default:
  3332. DRM_ERROR("Invalid register 0x%x in CS\n", reg);
  3333. return false;
  3334. }
  3335. }
  3336. static int si_vm_packet3_ce_check(struct radeon_device *rdev,
  3337. u32 *ib, struct radeon_cs_packet *pkt)
  3338. {
  3339. switch (pkt->opcode) {
  3340. case PACKET3_NOP:
  3341. case PACKET3_SET_BASE:
  3342. case PACKET3_SET_CE_DE_COUNTERS:
  3343. case PACKET3_LOAD_CONST_RAM:
  3344. case PACKET3_WRITE_CONST_RAM:
  3345. case PACKET3_WRITE_CONST_RAM_OFFSET:
  3346. case PACKET3_DUMP_CONST_RAM:
  3347. case PACKET3_INCREMENT_CE_COUNTER:
  3348. case PACKET3_WAIT_ON_DE_COUNTER:
  3349. case PACKET3_CE_WRITE:
  3350. break;
  3351. default:
  3352. DRM_ERROR("Invalid CE packet3: 0x%x\n", pkt->opcode);
  3353. return -EINVAL;
  3354. }
  3355. return 0;
  3356. }
  3357. static int si_vm_packet3_gfx_check(struct radeon_device *rdev,
  3358. u32 *ib, struct radeon_cs_packet *pkt)
  3359. {
  3360. u32 idx = pkt->idx + 1;
  3361. u32 idx_value = ib[idx];
  3362. u32 start_reg, end_reg, reg, i;
  3363. u32 command, info;
  3364. switch (pkt->opcode) {
  3365. case PACKET3_NOP:
  3366. case PACKET3_SET_BASE:
  3367. case PACKET3_CLEAR_STATE:
  3368. case PACKET3_INDEX_BUFFER_SIZE:
  3369. case PACKET3_DISPATCH_DIRECT:
  3370. case PACKET3_DISPATCH_INDIRECT:
  3371. case PACKET3_ALLOC_GDS:
  3372. case PACKET3_WRITE_GDS_RAM:
  3373. case PACKET3_ATOMIC_GDS:
  3374. case PACKET3_ATOMIC:
  3375. case PACKET3_OCCLUSION_QUERY:
  3376. case PACKET3_SET_PREDICATION:
  3377. case PACKET3_COND_EXEC:
  3378. case PACKET3_PRED_EXEC:
  3379. case PACKET3_DRAW_INDIRECT:
  3380. case PACKET3_DRAW_INDEX_INDIRECT:
  3381. case PACKET3_INDEX_BASE:
  3382. case PACKET3_DRAW_INDEX_2:
  3383. case PACKET3_CONTEXT_CONTROL:
  3384. case PACKET3_INDEX_TYPE:
  3385. case PACKET3_DRAW_INDIRECT_MULTI:
  3386. case PACKET3_DRAW_INDEX_AUTO:
  3387. case PACKET3_DRAW_INDEX_IMMD:
  3388. case PACKET3_NUM_INSTANCES:
  3389. case PACKET3_DRAW_INDEX_MULTI_AUTO:
  3390. case PACKET3_STRMOUT_BUFFER_UPDATE:
  3391. case PACKET3_DRAW_INDEX_OFFSET_2:
  3392. case PACKET3_DRAW_INDEX_MULTI_ELEMENT:
  3393. case PACKET3_DRAW_INDEX_INDIRECT_MULTI:
  3394. case PACKET3_MPEG_INDEX:
  3395. case PACKET3_WAIT_REG_MEM:
  3396. case PACKET3_MEM_WRITE:
  3397. case PACKET3_PFP_SYNC_ME:
  3398. case PACKET3_SURFACE_SYNC:
  3399. case PACKET3_EVENT_WRITE:
  3400. case PACKET3_EVENT_WRITE_EOP:
  3401. case PACKET3_EVENT_WRITE_EOS:
  3402. case PACKET3_SET_CONTEXT_REG:
  3403. case PACKET3_SET_CONTEXT_REG_INDIRECT:
  3404. case PACKET3_SET_SH_REG:
  3405. case PACKET3_SET_SH_REG_OFFSET:
  3406. case PACKET3_INCREMENT_DE_COUNTER:
  3407. case PACKET3_WAIT_ON_CE_COUNTER:
  3408. case PACKET3_WAIT_ON_AVAIL_BUFFER:
  3409. case PACKET3_ME_WRITE:
  3410. break;
  3411. case PACKET3_COPY_DATA:
  3412. if ((idx_value & 0xf00) == 0) {
  3413. reg = ib[idx + 3] * 4;
  3414. if (!si_vm_reg_valid(reg))
  3415. return -EINVAL;
  3416. }
  3417. break;
  3418. case PACKET3_WRITE_DATA:
  3419. if ((idx_value & 0xf00) == 0) {
  3420. start_reg = ib[idx + 1] * 4;
  3421. if (idx_value & 0x10000) {
  3422. if (!si_vm_reg_valid(start_reg))
  3423. return -EINVAL;
  3424. } else {
  3425. for (i = 0; i < (pkt->count - 2); i++) {
  3426. reg = start_reg + (4 * i);
  3427. if (!si_vm_reg_valid(reg))
  3428. return -EINVAL;
  3429. }
  3430. }
  3431. }
  3432. break;
  3433. case PACKET3_COND_WRITE:
  3434. if (idx_value & 0x100) {
  3435. reg = ib[idx + 5] * 4;
  3436. if (!si_vm_reg_valid(reg))
  3437. return -EINVAL;
  3438. }
  3439. break;
  3440. case PACKET3_COPY_DW:
  3441. if (idx_value & 0x2) {
  3442. reg = ib[idx + 3] * 4;
  3443. if (!si_vm_reg_valid(reg))
  3444. return -EINVAL;
  3445. }
  3446. break;
  3447. case PACKET3_SET_CONFIG_REG:
  3448. start_reg = (idx_value << 2) + PACKET3_SET_CONFIG_REG_START;
  3449. end_reg = 4 * pkt->count + start_reg - 4;
  3450. if ((start_reg < PACKET3_SET_CONFIG_REG_START) ||
  3451. (start_reg >= PACKET3_SET_CONFIG_REG_END) ||
  3452. (end_reg >= PACKET3_SET_CONFIG_REG_END)) {
  3453. DRM_ERROR("bad PACKET3_SET_CONFIG_REG\n");
  3454. return -EINVAL;
  3455. }
  3456. for (i = 0; i < pkt->count; i++) {
  3457. reg = start_reg + (4 * i);
  3458. if (!si_vm_reg_valid(reg))
  3459. return -EINVAL;
  3460. }
  3461. break;
  3462. case PACKET3_CP_DMA:
  3463. command = ib[idx + 4];
  3464. info = ib[idx + 1];
  3465. if (command & PACKET3_CP_DMA_CMD_SAS) {
  3466. /* src address space is register */
  3467. if (((info & 0x60000000) >> 29) == 0) {
  3468. start_reg = idx_value << 2;
  3469. if (command & PACKET3_CP_DMA_CMD_SAIC) {
  3470. reg = start_reg;
  3471. if (!si_vm_reg_valid(reg)) {
  3472. DRM_ERROR("CP DMA Bad SRC register\n");
  3473. return -EINVAL;
  3474. }
  3475. } else {
  3476. for (i = 0; i < (command & 0x1fffff); i++) {
  3477. reg = start_reg + (4 * i);
  3478. if (!si_vm_reg_valid(reg)) {
  3479. DRM_ERROR("CP DMA Bad SRC register\n");
  3480. return -EINVAL;
  3481. }
  3482. }
  3483. }
  3484. }
  3485. }
  3486. if (command & PACKET3_CP_DMA_CMD_DAS) {
  3487. /* dst address space is register */
  3488. if (((info & 0x00300000) >> 20) == 0) {
  3489. start_reg = ib[idx + 2];
  3490. if (command & PACKET3_CP_DMA_CMD_DAIC) {
  3491. reg = start_reg;
  3492. if (!si_vm_reg_valid(reg)) {
  3493. DRM_ERROR("CP DMA Bad DST register\n");
  3494. return -EINVAL;
  3495. }
  3496. } else {
  3497. for (i = 0; i < (command & 0x1fffff); i++) {
  3498. reg = start_reg + (4 * i);
  3499. if (!si_vm_reg_valid(reg)) {
  3500. DRM_ERROR("CP DMA Bad DST register\n");
  3501. return -EINVAL;
  3502. }
  3503. }
  3504. }
  3505. }
  3506. }
  3507. break;
  3508. default:
  3509. DRM_ERROR("Invalid GFX packet3: 0x%x\n", pkt->opcode);
  3510. return -EINVAL;
  3511. }
  3512. return 0;
  3513. }
  3514. static int si_vm_packet3_compute_check(struct radeon_device *rdev,
  3515. u32 *ib, struct radeon_cs_packet *pkt)
  3516. {
  3517. u32 idx = pkt->idx + 1;
  3518. u32 idx_value = ib[idx];
  3519. u32 start_reg, reg, i;
  3520. switch (pkt->opcode) {
  3521. case PACKET3_NOP:
  3522. case PACKET3_SET_BASE:
  3523. case PACKET3_CLEAR_STATE:
  3524. case PACKET3_DISPATCH_DIRECT:
  3525. case PACKET3_DISPATCH_INDIRECT:
  3526. case PACKET3_ALLOC_GDS:
  3527. case PACKET3_WRITE_GDS_RAM:
  3528. case PACKET3_ATOMIC_GDS:
  3529. case PACKET3_ATOMIC:
  3530. case PACKET3_OCCLUSION_QUERY:
  3531. case PACKET3_SET_PREDICATION:
  3532. case PACKET3_COND_EXEC:
  3533. case PACKET3_PRED_EXEC:
  3534. case PACKET3_CONTEXT_CONTROL:
  3535. case PACKET3_STRMOUT_BUFFER_UPDATE:
  3536. case PACKET3_WAIT_REG_MEM:
  3537. case PACKET3_MEM_WRITE:
  3538. case PACKET3_PFP_SYNC_ME:
  3539. case PACKET3_SURFACE_SYNC:
  3540. case PACKET3_EVENT_WRITE:
  3541. case PACKET3_EVENT_WRITE_EOP:
  3542. case PACKET3_EVENT_WRITE_EOS:
  3543. case PACKET3_SET_CONTEXT_REG:
  3544. case PACKET3_SET_CONTEXT_REG_INDIRECT:
  3545. case PACKET3_SET_SH_REG:
  3546. case PACKET3_SET_SH_REG_OFFSET:
  3547. case PACKET3_INCREMENT_DE_COUNTER:
  3548. case PACKET3_WAIT_ON_CE_COUNTER:
  3549. case PACKET3_WAIT_ON_AVAIL_BUFFER:
  3550. case PACKET3_ME_WRITE:
  3551. break;
  3552. case PACKET3_COPY_DATA:
  3553. if ((idx_value & 0xf00) == 0) {
  3554. reg = ib[idx + 3] * 4;
  3555. if (!si_vm_reg_valid(reg))
  3556. return -EINVAL;
  3557. }
  3558. break;
  3559. case PACKET3_WRITE_DATA:
  3560. if ((idx_value & 0xf00) == 0) {
  3561. start_reg = ib[idx + 1] * 4;
  3562. if (idx_value & 0x10000) {
  3563. if (!si_vm_reg_valid(start_reg))
  3564. return -EINVAL;
  3565. } else {
  3566. for (i = 0; i < (pkt->count - 2); i++) {
  3567. reg = start_reg + (4 * i);
  3568. if (!si_vm_reg_valid(reg))
  3569. return -EINVAL;
  3570. }
  3571. }
  3572. }
  3573. break;
  3574. case PACKET3_COND_WRITE:
  3575. if (idx_value & 0x100) {
  3576. reg = ib[idx + 5] * 4;
  3577. if (!si_vm_reg_valid(reg))
  3578. return -EINVAL;
  3579. }
  3580. break;
  3581. case PACKET3_COPY_DW:
  3582. if (idx_value & 0x2) {
  3583. reg = ib[idx + 3] * 4;
  3584. if (!si_vm_reg_valid(reg))
  3585. return -EINVAL;
  3586. }
  3587. break;
  3588. default:
  3589. DRM_ERROR("Invalid Compute packet3: 0x%x\n", pkt->opcode);
  3590. return -EINVAL;
  3591. }
  3592. return 0;
  3593. }
  3594. int si_ib_parse(struct radeon_device *rdev, struct radeon_ib *ib)
  3595. {
  3596. int ret = 0;
  3597. u32 idx = 0;
  3598. struct radeon_cs_packet pkt;
  3599. do {
  3600. pkt.idx = idx;
  3601. pkt.type = RADEON_CP_PACKET_GET_TYPE(ib->ptr[idx]);
  3602. pkt.count = RADEON_CP_PACKET_GET_COUNT(ib->ptr[idx]);
  3603. pkt.one_reg_wr = 0;
  3604. switch (pkt.type) {
  3605. case RADEON_PACKET_TYPE0:
  3606. dev_err(rdev->dev, "Packet0 not allowed!\n");
  3607. ret = -EINVAL;
  3608. break;
  3609. case RADEON_PACKET_TYPE2:
  3610. idx += 1;
  3611. break;
  3612. case RADEON_PACKET_TYPE3:
  3613. pkt.opcode = RADEON_CP_PACKET3_GET_OPCODE(ib->ptr[idx]);
  3614. if (ib->is_const_ib)
  3615. ret = si_vm_packet3_ce_check(rdev, ib->ptr, &pkt);
  3616. else {
  3617. switch (ib->ring) {
  3618. case RADEON_RING_TYPE_GFX_INDEX:
  3619. ret = si_vm_packet3_gfx_check(rdev, ib->ptr, &pkt);
  3620. break;
  3621. case CAYMAN_RING_TYPE_CP1_INDEX:
  3622. case CAYMAN_RING_TYPE_CP2_INDEX:
  3623. ret = si_vm_packet3_compute_check(rdev, ib->ptr, &pkt);
  3624. break;
  3625. default:
  3626. dev_err(rdev->dev, "Non-PM4 ring %d !\n", ib->ring);
  3627. ret = -EINVAL;
  3628. break;
  3629. }
  3630. }
  3631. idx += pkt.count + 2;
  3632. break;
  3633. default:
  3634. dev_err(rdev->dev, "Unknown packet type %d !\n", pkt.type);
  3635. ret = -EINVAL;
  3636. break;
  3637. }
  3638. if (ret)
  3639. break;
  3640. } while (idx < ib->length_dw);
  3641. return ret;
  3642. }
  3643. /*
  3644. * vm
  3645. */
  3646. int si_vm_init(struct radeon_device *rdev)
  3647. {
  3648. /* number of VMs */
  3649. rdev->vm_manager.nvm = 16;
  3650. /* base offset of vram pages */
  3651. rdev->vm_manager.vram_base_offset = 0;
  3652. return 0;
  3653. }
  3654. void si_vm_fini(struct radeon_device *rdev)
  3655. {
  3656. }
  3657. /**
  3658. * si_vm_set_page - update the page tables using the CP
  3659. *
  3660. * @rdev: radeon_device pointer
  3661. * @ib: indirect buffer to fill with commands
  3662. * @pe: addr of the page entry
  3663. * @addr: dst addr to write into pe
  3664. * @count: number of page entries to update
  3665. * @incr: increase next addr by incr bytes
  3666. * @flags: access flags
  3667. *
  3668. * Update the page tables using the CP (SI).
  3669. */
  3670. void si_vm_set_page(struct radeon_device *rdev,
  3671. struct radeon_ib *ib,
  3672. uint64_t pe,
  3673. uint64_t addr, unsigned count,
  3674. uint32_t incr, uint32_t flags)
  3675. {
  3676. uint32_t r600_flags = cayman_vm_page_flags(rdev, flags);
  3677. uint64_t value;
  3678. unsigned ndw;
  3679. if (rdev->asic->vm.pt_ring_index == RADEON_RING_TYPE_GFX_INDEX) {
  3680. while (count) {
  3681. ndw = 2 + count * 2;
  3682. if (ndw > 0x3FFE)
  3683. ndw = 0x3FFE;
  3684. ib->ptr[ib->length_dw++] = PACKET3(PACKET3_WRITE_DATA, ndw);
  3685. ib->ptr[ib->length_dw++] = (WRITE_DATA_ENGINE_SEL(0) |
  3686. WRITE_DATA_DST_SEL(1));
  3687. ib->ptr[ib->length_dw++] = pe;
  3688. ib->ptr[ib->length_dw++] = upper_32_bits(pe);
  3689. for (; ndw > 2; ndw -= 2, --count, pe += 8) {
  3690. if (flags & RADEON_VM_PAGE_SYSTEM) {
  3691. value = radeon_vm_map_gart(rdev, addr);
  3692. value &= 0xFFFFFFFFFFFFF000ULL;
  3693. } else if (flags & RADEON_VM_PAGE_VALID) {
  3694. value = addr;
  3695. } else {
  3696. value = 0;
  3697. }
  3698. addr += incr;
  3699. value |= r600_flags;
  3700. ib->ptr[ib->length_dw++] = value;
  3701. ib->ptr[ib->length_dw++] = upper_32_bits(value);
  3702. }
  3703. }
  3704. } else {
  3705. /* DMA */
  3706. if (flags & RADEON_VM_PAGE_SYSTEM) {
  3707. while (count) {
  3708. ndw = count * 2;
  3709. if (ndw > 0xFFFFE)
  3710. ndw = 0xFFFFE;
  3711. /* for non-physically contiguous pages (system) */
  3712. ib->ptr[ib->length_dw++] = DMA_PACKET(DMA_PACKET_WRITE, 0, 0, 0, ndw);
  3713. ib->ptr[ib->length_dw++] = pe;
  3714. ib->ptr[ib->length_dw++] = upper_32_bits(pe) & 0xff;
  3715. for (; ndw > 0; ndw -= 2, --count, pe += 8) {
  3716. if (flags & RADEON_VM_PAGE_SYSTEM) {
  3717. value = radeon_vm_map_gart(rdev, addr);
  3718. value &= 0xFFFFFFFFFFFFF000ULL;
  3719. } else if (flags & RADEON_VM_PAGE_VALID) {
  3720. value = addr;
  3721. } else {
  3722. value = 0;
  3723. }
  3724. addr += incr;
  3725. value |= r600_flags;
  3726. ib->ptr[ib->length_dw++] = value;
  3727. ib->ptr[ib->length_dw++] = upper_32_bits(value);
  3728. }
  3729. }
  3730. } else {
  3731. while (count) {
  3732. ndw = count * 2;
  3733. if (ndw > 0xFFFFE)
  3734. ndw = 0xFFFFE;
  3735. if (flags & RADEON_VM_PAGE_VALID)
  3736. value = addr;
  3737. else
  3738. value = 0;
  3739. /* for physically contiguous pages (vram) */
  3740. ib->ptr[ib->length_dw++] = DMA_PTE_PDE_PACKET(ndw);
  3741. ib->ptr[ib->length_dw++] = pe; /* dst addr */
  3742. ib->ptr[ib->length_dw++] = upper_32_bits(pe) & 0xff;
  3743. ib->ptr[ib->length_dw++] = r600_flags; /* mask */
  3744. ib->ptr[ib->length_dw++] = 0;
  3745. ib->ptr[ib->length_dw++] = value; /* value */
  3746. ib->ptr[ib->length_dw++] = upper_32_bits(value);
  3747. ib->ptr[ib->length_dw++] = incr; /* increment size */
  3748. ib->ptr[ib->length_dw++] = 0;
  3749. pe += ndw * 4;
  3750. addr += (ndw / 2) * incr;
  3751. count -= ndw / 2;
  3752. }
  3753. }
  3754. while (ib->length_dw & 0x7)
  3755. ib->ptr[ib->length_dw++] = DMA_PACKET(DMA_PACKET_NOP, 0, 0, 0, 0);
  3756. }
  3757. }
  3758. void si_vm_flush(struct radeon_device *rdev, int ridx, struct radeon_vm *vm)
  3759. {
  3760. struct radeon_ring *ring = &rdev->ring[ridx];
  3761. if (vm == NULL)
  3762. return;
  3763. /* write new base address */
  3764. radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  3765. radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
  3766. WRITE_DATA_DST_SEL(0)));
  3767. if (vm->id < 8) {
  3768. radeon_ring_write(ring,
  3769. (VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (vm->id << 2)) >> 2);
  3770. } else {
  3771. radeon_ring_write(ring,
  3772. (VM_CONTEXT8_PAGE_TABLE_BASE_ADDR + ((vm->id - 8) << 2)) >> 2);
  3773. }
  3774. radeon_ring_write(ring, 0);
  3775. radeon_ring_write(ring, vm->pd_gpu_addr >> 12);
  3776. /* flush hdp cache */
  3777. radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  3778. radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
  3779. WRITE_DATA_DST_SEL(0)));
  3780. radeon_ring_write(ring, HDP_MEM_COHERENCY_FLUSH_CNTL >> 2);
  3781. radeon_ring_write(ring, 0);
  3782. radeon_ring_write(ring, 0x1);
  3783. /* bits 0-15 are the VM contexts0-15 */
  3784. radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  3785. radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
  3786. WRITE_DATA_DST_SEL(0)));
  3787. radeon_ring_write(ring, VM_INVALIDATE_REQUEST >> 2);
  3788. radeon_ring_write(ring, 0);
  3789. radeon_ring_write(ring, 1 << vm->id);
  3790. /* sync PFP to ME, otherwise we might get invalid PFP reads */
  3791. radeon_ring_write(ring, PACKET3(PACKET3_PFP_SYNC_ME, 0));
  3792. radeon_ring_write(ring, 0x0);
  3793. }
  3794. void si_dma_vm_flush(struct radeon_device *rdev, int ridx, struct radeon_vm *vm)
  3795. {
  3796. struct radeon_ring *ring = &rdev->ring[ridx];
  3797. if (vm == NULL)
  3798. return;
  3799. radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_SRBM_WRITE, 0, 0, 0, 0));
  3800. if (vm->id < 8) {
  3801. radeon_ring_write(ring, (0xf << 16) | ((VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (vm->id << 2)) >> 2));
  3802. } else {
  3803. radeon_ring_write(ring, (0xf << 16) | ((VM_CONTEXT8_PAGE_TABLE_BASE_ADDR + ((vm->id - 8) << 2)) >> 2));
  3804. }
  3805. radeon_ring_write(ring, vm->pd_gpu_addr >> 12);
  3806. /* flush hdp cache */
  3807. radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_SRBM_WRITE, 0, 0, 0, 0));
  3808. radeon_ring_write(ring, (0xf << 16) | (HDP_MEM_COHERENCY_FLUSH_CNTL >> 2));
  3809. radeon_ring_write(ring, 1);
  3810. /* bits 0-7 are the VM contexts0-7 */
  3811. radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_SRBM_WRITE, 0, 0, 0, 0));
  3812. radeon_ring_write(ring, (0xf << 16) | (VM_INVALIDATE_REQUEST >> 2));
  3813. radeon_ring_write(ring, 1 << vm->id);
  3814. }
  3815. /*
  3816. * RLC
  3817. */
  3818. void si_rlc_fini(struct radeon_device *rdev)
  3819. {
  3820. int r;
  3821. /* save restore block */
  3822. if (rdev->rlc.save_restore_obj) {
  3823. r = radeon_bo_reserve(rdev->rlc.save_restore_obj, false);
  3824. if (unlikely(r != 0))
  3825. dev_warn(rdev->dev, "(%d) reserve RLC sr bo failed\n", r);
  3826. radeon_bo_unpin(rdev->rlc.save_restore_obj);
  3827. radeon_bo_unreserve(rdev->rlc.save_restore_obj);
  3828. radeon_bo_unref(&rdev->rlc.save_restore_obj);
  3829. rdev->rlc.save_restore_obj = NULL;
  3830. }
  3831. /* clear state block */
  3832. if (rdev->rlc.clear_state_obj) {
  3833. r = radeon_bo_reserve(rdev->rlc.clear_state_obj, false);
  3834. if (unlikely(r != 0))
  3835. dev_warn(rdev->dev, "(%d) reserve RLC c bo failed\n", r);
  3836. radeon_bo_unpin(rdev->rlc.clear_state_obj);
  3837. radeon_bo_unreserve(rdev->rlc.clear_state_obj);
  3838. radeon_bo_unref(&rdev->rlc.clear_state_obj);
  3839. rdev->rlc.clear_state_obj = NULL;
  3840. }
  3841. }
  3842. int si_rlc_init(struct radeon_device *rdev)
  3843. {
  3844. int r;
  3845. /* save restore block */
  3846. if (rdev->rlc.save_restore_obj == NULL) {
  3847. r = radeon_bo_create(rdev, RADEON_GPU_PAGE_SIZE, PAGE_SIZE, true,
  3848. RADEON_GEM_DOMAIN_VRAM, NULL,
  3849. &rdev->rlc.save_restore_obj);
  3850. if (r) {
  3851. dev_warn(rdev->dev, "(%d) create RLC sr bo failed\n", r);
  3852. return r;
  3853. }
  3854. }
  3855. r = radeon_bo_reserve(rdev->rlc.save_restore_obj, false);
  3856. if (unlikely(r != 0)) {
  3857. si_rlc_fini(rdev);
  3858. return r;
  3859. }
  3860. r = radeon_bo_pin(rdev->rlc.save_restore_obj, RADEON_GEM_DOMAIN_VRAM,
  3861. &rdev->rlc.save_restore_gpu_addr);
  3862. radeon_bo_unreserve(rdev->rlc.save_restore_obj);
  3863. if (r) {
  3864. dev_warn(rdev->dev, "(%d) pin RLC sr bo failed\n", r);
  3865. si_rlc_fini(rdev);
  3866. return r;
  3867. }
  3868. /* clear state block */
  3869. if (rdev->rlc.clear_state_obj == NULL) {
  3870. r = radeon_bo_create(rdev, RADEON_GPU_PAGE_SIZE, PAGE_SIZE, true,
  3871. RADEON_GEM_DOMAIN_VRAM, NULL,
  3872. &rdev->rlc.clear_state_obj);
  3873. if (r) {
  3874. dev_warn(rdev->dev, "(%d) create RLC c bo failed\n", r);
  3875. si_rlc_fini(rdev);
  3876. return r;
  3877. }
  3878. }
  3879. r = radeon_bo_reserve(rdev->rlc.clear_state_obj, false);
  3880. if (unlikely(r != 0)) {
  3881. si_rlc_fini(rdev);
  3882. return r;
  3883. }
  3884. r = radeon_bo_pin(rdev->rlc.clear_state_obj, RADEON_GEM_DOMAIN_VRAM,
  3885. &rdev->rlc.clear_state_gpu_addr);
  3886. radeon_bo_unreserve(rdev->rlc.clear_state_obj);
  3887. if (r) {
  3888. dev_warn(rdev->dev, "(%d) pin RLC c bo failed\n", r);
  3889. si_rlc_fini(rdev);
  3890. return r;
  3891. }
  3892. return 0;
  3893. }
  3894. static void si_rlc_stop(struct radeon_device *rdev)
  3895. {
  3896. WREG32(RLC_CNTL, 0);
  3897. }
  3898. static void si_rlc_start(struct radeon_device *rdev)
  3899. {
  3900. WREG32(RLC_CNTL, RLC_ENABLE);
  3901. }
  3902. static int si_rlc_resume(struct radeon_device *rdev)
  3903. {
  3904. u32 i;
  3905. const __be32 *fw_data;
  3906. if (!rdev->rlc_fw)
  3907. return -EINVAL;
  3908. si_rlc_stop(rdev);
  3909. WREG32(RLC_RL_BASE, 0);
  3910. WREG32(RLC_RL_SIZE, 0);
  3911. WREG32(RLC_LB_CNTL, 0);
  3912. WREG32(RLC_LB_CNTR_MAX, 0xffffffff);
  3913. WREG32(RLC_LB_CNTR_INIT, 0);
  3914. WREG32(RLC_SAVE_AND_RESTORE_BASE, rdev->rlc.save_restore_gpu_addr >> 8);
  3915. WREG32(RLC_CLEAR_STATE_RESTORE_BASE, rdev->rlc.clear_state_gpu_addr >> 8);
  3916. WREG32(RLC_MC_CNTL, 0);
  3917. WREG32(RLC_UCODE_CNTL, 0);
  3918. fw_data = (const __be32 *)rdev->rlc_fw->data;
  3919. for (i = 0; i < SI_RLC_UCODE_SIZE; i++) {
  3920. WREG32(RLC_UCODE_ADDR, i);
  3921. WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
  3922. }
  3923. WREG32(RLC_UCODE_ADDR, 0);
  3924. si_rlc_start(rdev);
  3925. return 0;
  3926. }
  3927. static void si_enable_interrupts(struct radeon_device *rdev)
  3928. {
  3929. u32 ih_cntl = RREG32(IH_CNTL);
  3930. u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
  3931. ih_cntl |= ENABLE_INTR;
  3932. ih_rb_cntl |= IH_RB_ENABLE;
  3933. WREG32(IH_CNTL, ih_cntl);
  3934. WREG32(IH_RB_CNTL, ih_rb_cntl);
  3935. rdev->ih.enabled = true;
  3936. }
  3937. static void si_disable_interrupts(struct radeon_device *rdev)
  3938. {
  3939. u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
  3940. u32 ih_cntl = RREG32(IH_CNTL);
  3941. ih_rb_cntl &= ~IH_RB_ENABLE;
  3942. ih_cntl &= ~ENABLE_INTR;
  3943. WREG32(IH_RB_CNTL, ih_rb_cntl);
  3944. WREG32(IH_CNTL, ih_cntl);
  3945. /* set rptr, wptr to 0 */
  3946. WREG32(IH_RB_RPTR, 0);
  3947. WREG32(IH_RB_WPTR, 0);
  3948. rdev->ih.enabled = false;
  3949. rdev->ih.rptr = 0;
  3950. }
  3951. static void si_disable_interrupt_state(struct radeon_device *rdev)
  3952. {
  3953. u32 tmp;
  3954. WREG32(CP_INT_CNTL_RING0, CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
  3955. WREG32(CP_INT_CNTL_RING1, 0);
  3956. WREG32(CP_INT_CNTL_RING2, 0);
  3957. tmp = RREG32(DMA_CNTL + DMA0_REGISTER_OFFSET) & ~TRAP_ENABLE;
  3958. WREG32(DMA_CNTL + DMA0_REGISTER_OFFSET, tmp);
  3959. tmp = RREG32(DMA_CNTL + DMA1_REGISTER_OFFSET) & ~TRAP_ENABLE;
  3960. WREG32(DMA_CNTL + DMA1_REGISTER_OFFSET, tmp);
  3961. WREG32(GRBM_INT_CNTL, 0);
  3962. if (rdev->num_crtc >= 2) {
  3963. WREG32(INT_MASK + EVERGREEN_CRTC0_REGISTER_OFFSET, 0);
  3964. WREG32(INT_MASK + EVERGREEN_CRTC1_REGISTER_OFFSET, 0);
  3965. }
  3966. if (rdev->num_crtc >= 4) {
  3967. WREG32(INT_MASK + EVERGREEN_CRTC2_REGISTER_OFFSET, 0);
  3968. WREG32(INT_MASK + EVERGREEN_CRTC3_REGISTER_OFFSET, 0);
  3969. }
  3970. if (rdev->num_crtc >= 6) {
  3971. WREG32(INT_MASK + EVERGREEN_CRTC4_REGISTER_OFFSET, 0);
  3972. WREG32(INT_MASK + EVERGREEN_CRTC5_REGISTER_OFFSET, 0);
  3973. }
  3974. if (rdev->num_crtc >= 2) {
  3975. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET, 0);
  3976. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET, 0);
  3977. }
  3978. if (rdev->num_crtc >= 4) {
  3979. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET, 0);
  3980. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET, 0);
  3981. }
  3982. if (rdev->num_crtc >= 6) {
  3983. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET, 0);
  3984. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET, 0);
  3985. }
  3986. if (!ASIC_IS_NODCE(rdev)) {
  3987. WREG32(DACA_AUTODETECT_INT_CONTROL, 0);
  3988. tmp = RREG32(DC_HPD1_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  3989. WREG32(DC_HPD1_INT_CONTROL, tmp);
  3990. tmp = RREG32(DC_HPD2_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  3991. WREG32(DC_HPD2_INT_CONTROL, tmp);
  3992. tmp = RREG32(DC_HPD3_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  3993. WREG32(DC_HPD3_INT_CONTROL, tmp);
  3994. tmp = RREG32(DC_HPD4_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  3995. WREG32(DC_HPD4_INT_CONTROL, tmp);
  3996. tmp = RREG32(DC_HPD5_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  3997. WREG32(DC_HPD5_INT_CONTROL, tmp);
  3998. tmp = RREG32(DC_HPD6_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  3999. WREG32(DC_HPD6_INT_CONTROL, tmp);
  4000. }
  4001. }
  4002. static int si_irq_init(struct radeon_device *rdev)
  4003. {
  4004. int ret = 0;
  4005. int rb_bufsz;
  4006. u32 interrupt_cntl, ih_cntl, ih_rb_cntl;
  4007. /* allocate ring */
  4008. ret = r600_ih_ring_alloc(rdev);
  4009. if (ret)
  4010. return ret;
  4011. /* disable irqs */
  4012. si_disable_interrupts(rdev);
  4013. /* init rlc */
  4014. ret = si_rlc_resume(rdev);
  4015. if (ret) {
  4016. r600_ih_ring_fini(rdev);
  4017. return ret;
  4018. }
  4019. /* setup interrupt control */
  4020. /* set dummy read address to ring address */
  4021. WREG32(INTERRUPT_CNTL2, rdev->ih.gpu_addr >> 8);
  4022. interrupt_cntl = RREG32(INTERRUPT_CNTL);
  4023. /* IH_DUMMY_RD_OVERRIDE=0 - dummy read disabled with msi, enabled without msi
  4024. * IH_DUMMY_RD_OVERRIDE=1 - dummy read controlled by IH_DUMMY_RD_EN
  4025. */
  4026. interrupt_cntl &= ~IH_DUMMY_RD_OVERRIDE;
  4027. /* IH_REQ_NONSNOOP_EN=1 if ring is in non-cacheable memory, e.g., vram */
  4028. interrupt_cntl &= ~IH_REQ_NONSNOOP_EN;
  4029. WREG32(INTERRUPT_CNTL, interrupt_cntl);
  4030. WREG32(IH_RB_BASE, rdev->ih.gpu_addr >> 8);
  4031. rb_bufsz = drm_order(rdev->ih.ring_size / 4);
  4032. ih_rb_cntl = (IH_WPTR_OVERFLOW_ENABLE |
  4033. IH_WPTR_OVERFLOW_CLEAR |
  4034. (rb_bufsz << 1));
  4035. if (rdev->wb.enabled)
  4036. ih_rb_cntl |= IH_WPTR_WRITEBACK_ENABLE;
  4037. /* set the writeback address whether it's enabled or not */
  4038. WREG32(IH_RB_WPTR_ADDR_LO, (rdev->wb.gpu_addr + R600_WB_IH_WPTR_OFFSET) & 0xFFFFFFFC);
  4039. WREG32(IH_RB_WPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + R600_WB_IH_WPTR_OFFSET) & 0xFF);
  4040. WREG32(IH_RB_CNTL, ih_rb_cntl);
  4041. /* set rptr, wptr to 0 */
  4042. WREG32(IH_RB_RPTR, 0);
  4043. WREG32(IH_RB_WPTR, 0);
  4044. /* Default settings for IH_CNTL (disabled at first) */
  4045. ih_cntl = MC_WRREQ_CREDIT(0x10) | MC_WR_CLEAN_CNT(0x10) | MC_VMID(0);
  4046. /* RPTR_REARM only works if msi's are enabled */
  4047. if (rdev->msi_enabled)
  4048. ih_cntl |= RPTR_REARM;
  4049. WREG32(IH_CNTL, ih_cntl);
  4050. /* force the active interrupt state to all disabled */
  4051. si_disable_interrupt_state(rdev);
  4052. pci_set_master(rdev->pdev);
  4053. /* enable irqs */
  4054. si_enable_interrupts(rdev);
  4055. return ret;
  4056. }
  4057. int si_irq_set(struct radeon_device *rdev)
  4058. {
  4059. u32 cp_int_cntl = CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE;
  4060. u32 cp_int_cntl1 = 0, cp_int_cntl2 = 0;
  4061. u32 crtc1 = 0, crtc2 = 0, crtc3 = 0, crtc4 = 0, crtc5 = 0, crtc6 = 0;
  4062. u32 hpd1 = 0, hpd2 = 0, hpd3 = 0, hpd4 = 0, hpd5 = 0, hpd6 = 0;
  4063. u32 grbm_int_cntl = 0;
  4064. u32 grph1 = 0, grph2 = 0, grph3 = 0, grph4 = 0, grph5 = 0, grph6 = 0;
  4065. u32 dma_cntl, dma_cntl1;
  4066. if (!rdev->irq.installed) {
  4067. WARN(1, "Can't enable IRQ/MSI because no handler is installed\n");
  4068. return -EINVAL;
  4069. }
  4070. /* don't enable anything if the ih is disabled */
  4071. if (!rdev->ih.enabled) {
  4072. si_disable_interrupts(rdev);
  4073. /* force the active interrupt state to all disabled */
  4074. si_disable_interrupt_state(rdev);
  4075. return 0;
  4076. }
  4077. if (!ASIC_IS_NODCE(rdev)) {
  4078. hpd1 = RREG32(DC_HPD1_INT_CONTROL) & ~DC_HPDx_INT_EN;
  4079. hpd2 = RREG32(DC_HPD2_INT_CONTROL) & ~DC_HPDx_INT_EN;
  4080. hpd3 = RREG32(DC_HPD3_INT_CONTROL) & ~DC_HPDx_INT_EN;
  4081. hpd4 = RREG32(DC_HPD4_INT_CONTROL) & ~DC_HPDx_INT_EN;
  4082. hpd5 = RREG32(DC_HPD5_INT_CONTROL) & ~DC_HPDx_INT_EN;
  4083. hpd6 = RREG32(DC_HPD6_INT_CONTROL) & ~DC_HPDx_INT_EN;
  4084. }
  4085. dma_cntl = RREG32(DMA_CNTL + DMA0_REGISTER_OFFSET) & ~TRAP_ENABLE;
  4086. dma_cntl1 = RREG32(DMA_CNTL + DMA1_REGISTER_OFFSET) & ~TRAP_ENABLE;
  4087. /* enable CP interrupts on all rings */
  4088. if (atomic_read(&rdev->irq.ring_int[RADEON_RING_TYPE_GFX_INDEX])) {
  4089. DRM_DEBUG("si_irq_set: sw int gfx\n");
  4090. cp_int_cntl |= TIME_STAMP_INT_ENABLE;
  4091. }
  4092. if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_CP1_INDEX])) {
  4093. DRM_DEBUG("si_irq_set: sw int cp1\n");
  4094. cp_int_cntl1 |= TIME_STAMP_INT_ENABLE;
  4095. }
  4096. if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_CP2_INDEX])) {
  4097. DRM_DEBUG("si_irq_set: sw int cp2\n");
  4098. cp_int_cntl2 |= TIME_STAMP_INT_ENABLE;
  4099. }
  4100. if (atomic_read(&rdev->irq.ring_int[R600_RING_TYPE_DMA_INDEX])) {
  4101. DRM_DEBUG("si_irq_set: sw int dma\n");
  4102. dma_cntl |= TRAP_ENABLE;
  4103. }
  4104. if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_DMA1_INDEX])) {
  4105. DRM_DEBUG("si_irq_set: sw int dma1\n");
  4106. dma_cntl1 |= TRAP_ENABLE;
  4107. }
  4108. if (rdev->irq.crtc_vblank_int[0] ||
  4109. atomic_read(&rdev->irq.pflip[0])) {
  4110. DRM_DEBUG("si_irq_set: vblank 0\n");
  4111. crtc1 |= VBLANK_INT_MASK;
  4112. }
  4113. if (rdev->irq.crtc_vblank_int[1] ||
  4114. atomic_read(&rdev->irq.pflip[1])) {
  4115. DRM_DEBUG("si_irq_set: vblank 1\n");
  4116. crtc2 |= VBLANK_INT_MASK;
  4117. }
  4118. if (rdev->irq.crtc_vblank_int[2] ||
  4119. atomic_read(&rdev->irq.pflip[2])) {
  4120. DRM_DEBUG("si_irq_set: vblank 2\n");
  4121. crtc3 |= VBLANK_INT_MASK;
  4122. }
  4123. if (rdev->irq.crtc_vblank_int[3] ||
  4124. atomic_read(&rdev->irq.pflip[3])) {
  4125. DRM_DEBUG("si_irq_set: vblank 3\n");
  4126. crtc4 |= VBLANK_INT_MASK;
  4127. }
  4128. if (rdev->irq.crtc_vblank_int[4] ||
  4129. atomic_read(&rdev->irq.pflip[4])) {
  4130. DRM_DEBUG("si_irq_set: vblank 4\n");
  4131. crtc5 |= VBLANK_INT_MASK;
  4132. }
  4133. if (rdev->irq.crtc_vblank_int[5] ||
  4134. atomic_read(&rdev->irq.pflip[5])) {
  4135. DRM_DEBUG("si_irq_set: vblank 5\n");
  4136. crtc6 |= VBLANK_INT_MASK;
  4137. }
  4138. if (rdev->irq.hpd[0]) {
  4139. DRM_DEBUG("si_irq_set: hpd 1\n");
  4140. hpd1 |= DC_HPDx_INT_EN;
  4141. }
  4142. if (rdev->irq.hpd[1]) {
  4143. DRM_DEBUG("si_irq_set: hpd 2\n");
  4144. hpd2 |= DC_HPDx_INT_EN;
  4145. }
  4146. if (rdev->irq.hpd[2]) {
  4147. DRM_DEBUG("si_irq_set: hpd 3\n");
  4148. hpd3 |= DC_HPDx_INT_EN;
  4149. }
  4150. if (rdev->irq.hpd[3]) {
  4151. DRM_DEBUG("si_irq_set: hpd 4\n");
  4152. hpd4 |= DC_HPDx_INT_EN;
  4153. }
  4154. if (rdev->irq.hpd[4]) {
  4155. DRM_DEBUG("si_irq_set: hpd 5\n");
  4156. hpd5 |= DC_HPDx_INT_EN;
  4157. }
  4158. if (rdev->irq.hpd[5]) {
  4159. DRM_DEBUG("si_irq_set: hpd 6\n");
  4160. hpd6 |= DC_HPDx_INT_EN;
  4161. }
  4162. WREG32(CP_INT_CNTL_RING0, cp_int_cntl);
  4163. WREG32(CP_INT_CNTL_RING1, cp_int_cntl1);
  4164. WREG32(CP_INT_CNTL_RING2, cp_int_cntl2);
  4165. WREG32(DMA_CNTL + DMA0_REGISTER_OFFSET, dma_cntl);
  4166. WREG32(DMA_CNTL + DMA1_REGISTER_OFFSET, dma_cntl1);
  4167. WREG32(GRBM_INT_CNTL, grbm_int_cntl);
  4168. if (rdev->num_crtc >= 2) {
  4169. WREG32(INT_MASK + EVERGREEN_CRTC0_REGISTER_OFFSET, crtc1);
  4170. WREG32(INT_MASK + EVERGREEN_CRTC1_REGISTER_OFFSET, crtc2);
  4171. }
  4172. if (rdev->num_crtc >= 4) {
  4173. WREG32(INT_MASK + EVERGREEN_CRTC2_REGISTER_OFFSET, crtc3);
  4174. WREG32(INT_MASK + EVERGREEN_CRTC3_REGISTER_OFFSET, crtc4);
  4175. }
  4176. if (rdev->num_crtc >= 6) {
  4177. WREG32(INT_MASK + EVERGREEN_CRTC4_REGISTER_OFFSET, crtc5);
  4178. WREG32(INT_MASK + EVERGREEN_CRTC5_REGISTER_OFFSET, crtc6);
  4179. }
  4180. if (rdev->num_crtc >= 2) {
  4181. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET, grph1);
  4182. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET, grph2);
  4183. }
  4184. if (rdev->num_crtc >= 4) {
  4185. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET, grph3);
  4186. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET, grph4);
  4187. }
  4188. if (rdev->num_crtc >= 6) {
  4189. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET, grph5);
  4190. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET, grph6);
  4191. }
  4192. if (!ASIC_IS_NODCE(rdev)) {
  4193. WREG32(DC_HPD1_INT_CONTROL, hpd1);
  4194. WREG32(DC_HPD2_INT_CONTROL, hpd2);
  4195. WREG32(DC_HPD3_INT_CONTROL, hpd3);
  4196. WREG32(DC_HPD4_INT_CONTROL, hpd4);
  4197. WREG32(DC_HPD5_INT_CONTROL, hpd5);
  4198. WREG32(DC_HPD6_INT_CONTROL, hpd6);
  4199. }
  4200. return 0;
  4201. }
  4202. static inline void si_irq_ack(struct radeon_device *rdev)
  4203. {
  4204. u32 tmp;
  4205. if (ASIC_IS_NODCE(rdev))
  4206. return;
  4207. rdev->irq.stat_regs.evergreen.disp_int = RREG32(DISP_INTERRUPT_STATUS);
  4208. rdev->irq.stat_regs.evergreen.disp_int_cont = RREG32(DISP_INTERRUPT_STATUS_CONTINUE);
  4209. rdev->irq.stat_regs.evergreen.disp_int_cont2 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE2);
  4210. rdev->irq.stat_regs.evergreen.disp_int_cont3 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE3);
  4211. rdev->irq.stat_regs.evergreen.disp_int_cont4 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE4);
  4212. rdev->irq.stat_regs.evergreen.disp_int_cont5 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE5);
  4213. rdev->irq.stat_regs.evergreen.d1grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET);
  4214. rdev->irq.stat_regs.evergreen.d2grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET);
  4215. if (rdev->num_crtc >= 4) {
  4216. rdev->irq.stat_regs.evergreen.d3grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET);
  4217. rdev->irq.stat_regs.evergreen.d4grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET);
  4218. }
  4219. if (rdev->num_crtc >= 6) {
  4220. rdev->irq.stat_regs.evergreen.d5grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET);
  4221. rdev->irq.stat_regs.evergreen.d6grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET);
  4222. }
  4223. if (rdev->irq.stat_regs.evergreen.d1grph_int & GRPH_PFLIP_INT_OCCURRED)
  4224. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  4225. if (rdev->irq.stat_regs.evergreen.d2grph_int & GRPH_PFLIP_INT_OCCURRED)
  4226. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  4227. if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VBLANK_INTERRUPT)
  4228. WREG32(VBLANK_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, VBLANK_ACK);
  4229. if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VLINE_INTERRUPT)
  4230. WREG32(VLINE_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, VLINE_ACK);
  4231. if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VBLANK_INTERRUPT)
  4232. WREG32(VBLANK_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, VBLANK_ACK);
  4233. if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VLINE_INTERRUPT)
  4234. WREG32(VLINE_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, VLINE_ACK);
  4235. if (rdev->num_crtc >= 4) {
  4236. if (rdev->irq.stat_regs.evergreen.d3grph_int & GRPH_PFLIP_INT_OCCURRED)
  4237. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  4238. if (rdev->irq.stat_regs.evergreen.d4grph_int & GRPH_PFLIP_INT_OCCURRED)
  4239. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  4240. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VBLANK_INTERRUPT)
  4241. WREG32(VBLANK_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, VBLANK_ACK);
  4242. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VLINE_INTERRUPT)
  4243. WREG32(VLINE_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, VLINE_ACK);
  4244. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VBLANK_INTERRUPT)
  4245. WREG32(VBLANK_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, VBLANK_ACK);
  4246. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VLINE_INTERRUPT)
  4247. WREG32(VLINE_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, VLINE_ACK);
  4248. }
  4249. if (rdev->num_crtc >= 6) {
  4250. if (rdev->irq.stat_regs.evergreen.d5grph_int & GRPH_PFLIP_INT_OCCURRED)
  4251. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  4252. if (rdev->irq.stat_regs.evergreen.d6grph_int & GRPH_PFLIP_INT_OCCURRED)
  4253. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  4254. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VBLANK_INTERRUPT)
  4255. WREG32(VBLANK_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, VBLANK_ACK);
  4256. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VLINE_INTERRUPT)
  4257. WREG32(VLINE_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, VLINE_ACK);
  4258. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VBLANK_INTERRUPT)
  4259. WREG32(VBLANK_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, VBLANK_ACK);
  4260. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VLINE_INTERRUPT)
  4261. WREG32(VLINE_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, VLINE_ACK);
  4262. }
  4263. if (rdev->irq.stat_regs.evergreen.disp_int & DC_HPD1_INTERRUPT) {
  4264. tmp = RREG32(DC_HPD1_INT_CONTROL);
  4265. tmp |= DC_HPDx_INT_ACK;
  4266. WREG32(DC_HPD1_INT_CONTROL, tmp);
  4267. }
  4268. if (rdev->irq.stat_regs.evergreen.disp_int_cont & DC_HPD2_INTERRUPT) {
  4269. tmp = RREG32(DC_HPD2_INT_CONTROL);
  4270. tmp |= DC_HPDx_INT_ACK;
  4271. WREG32(DC_HPD2_INT_CONTROL, tmp);
  4272. }
  4273. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & DC_HPD3_INTERRUPT) {
  4274. tmp = RREG32(DC_HPD3_INT_CONTROL);
  4275. tmp |= DC_HPDx_INT_ACK;
  4276. WREG32(DC_HPD3_INT_CONTROL, tmp);
  4277. }
  4278. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & DC_HPD4_INTERRUPT) {
  4279. tmp = RREG32(DC_HPD4_INT_CONTROL);
  4280. tmp |= DC_HPDx_INT_ACK;
  4281. WREG32(DC_HPD4_INT_CONTROL, tmp);
  4282. }
  4283. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & DC_HPD5_INTERRUPT) {
  4284. tmp = RREG32(DC_HPD5_INT_CONTROL);
  4285. tmp |= DC_HPDx_INT_ACK;
  4286. WREG32(DC_HPD5_INT_CONTROL, tmp);
  4287. }
  4288. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & DC_HPD6_INTERRUPT) {
  4289. tmp = RREG32(DC_HPD5_INT_CONTROL);
  4290. tmp |= DC_HPDx_INT_ACK;
  4291. WREG32(DC_HPD6_INT_CONTROL, tmp);
  4292. }
  4293. }
  4294. static void si_irq_disable(struct radeon_device *rdev)
  4295. {
  4296. si_disable_interrupts(rdev);
  4297. /* Wait and acknowledge irq */
  4298. mdelay(1);
  4299. si_irq_ack(rdev);
  4300. si_disable_interrupt_state(rdev);
  4301. }
  4302. static void si_irq_suspend(struct radeon_device *rdev)
  4303. {
  4304. si_irq_disable(rdev);
  4305. si_rlc_stop(rdev);
  4306. }
  4307. static void si_irq_fini(struct radeon_device *rdev)
  4308. {
  4309. si_irq_suspend(rdev);
  4310. r600_ih_ring_fini(rdev);
  4311. }
  4312. static inline u32 si_get_ih_wptr(struct radeon_device *rdev)
  4313. {
  4314. u32 wptr, tmp;
  4315. if (rdev->wb.enabled)
  4316. wptr = le32_to_cpu(rdev->wb.wb[R600_WB_IH_WPTR_OFFSET/4]);
  4317. else
  4318. wptr = RREG32(IH_RB_WPTR);
  4319. if (wptr & RB_OVERFLOW) {
  4320. /* When a ring buffer overflow happen start parsing interrupt
  4321. * from the last not overwritten vector (wptr + 16). Hopefully
  4322. * this should allow us to catchup.
  4323. */
  4324. dev_warn(rdev->dev, "IH ring buffer overflow (0x%08X, %d, %d)\n",
  4325. wptr, rdev->ih.rptr, (wptr + 16) + rdev->ih.ptr_mask);
  4326. rdev->ih.rptr = (wptr + 16) & rdev->ih.ptr_mask;
  4327. tmp = RREG32(IH_RB_CNTL);
  4328. tmp |= IH_WPTR_OVERFLOW_CLEAR;
  4329. WREG32(IH_RB_CNTL, tmp);
  4330. }
  4331. return (wptr & rdev->ih.ptr_mask);
  4332. }
  4333. /* SI IV Ring
  4334. * Each IV ring entry is 128 bits:
  4335. * [7:0] - interrupt source id
  4336. * [31:8] - reserved
  4337. * [59:32] - interrupt source data
  4338. * [63:60] - reserved
  4339. * [71:64] - RINGID
  4340. * [79:72] - VMID
  4341. * [127:80] - reserved
  4342. */
  4343. int si_irq_process(struct radeon_device *rdev)
  4344. {
  4345. u32 wptr;
  4346. u32 rptr;
  4347. u32 src_id, src_data, ring_id;
  4348. u32 ring_index;
  4349. bool queue_hotplug = false;
  4350. if (!rdev->ih.enabled || rdev->shutdown)
  4351. return IRQ_NONE;
  4352. wptr = si_get_ih_wptr(rdev);
  4353. restart_ih:
  4354. /* is somebody else already processing irqs? */
  4355. if (atomic_xchg(&rdev->ih.lock, 1))
  4356. return IRQ_NONE;
  4357. rptr = rdev->ih.rptr;
  4358. DRM_DEBUG("si_irq_process start: rptr %d, wptr %d\n", rptr, wptr);
  4359. /* Order reading of wptr vs. reading of IH ring data */
  4360. rmb();
  4361. /* display interrupts */
  4362. si_irq_ack(rdev);
  4363. while (rptr != wptr) {
  4364. /* wptr/rptr are in bytes! */
  4365. ring_index = rptr / 4;
  4366. src_id = le32_to_cpu(rdev->ih.ring[ring_index]) & 0xff;
  4367. src_data = le32_to_cpu(rdev->ih.ring[ring_index + 1]) & 0xfffffff;
  4368. ring_id = le32_to_cpu(rdev->ih.ring[ring_index + 2]) & 0xff;
  4369. switch (src_id) {
  4370. case 1: /* D1 vblank/vline */
  4371. switch (src_data) {
  4372. case 0: /* D1 vblank */
  4373. if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VBLANK_INTERRUPT) {
  4374. if (rdev->irq.crtc_vblank_int[0]) {
  4375. drm_handle_vblank(rdev->ddev, 0);
  4376. rdev->pm.vblank_sync = true;
  4377. wake_up(&rdev->irq.vblank_queue);
  4378. }
  4379. if (atomic_read(&rdev->irq.pflip[0]))
  4380. radeon_crtc_handle_flip(rdev, 0);
  4381. rdev->irq.stat_regs.evergreen.disp_int &= ~LB_D1_VBLANK_INTERRUPT;
  4382. DRM_DEBUG("IH: D1 vblank\n");
  4383. }
  4384. break;
  4385. case 1: /* D1 vline */
  4386. if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VLINE_INTERRUPT) {
  4387. rdev->irq.stat_regs.evergreen.disp_int &= ~LB_D1_VLINE_INTERRUPT;
  4388. DRM_DEBUG("IH: D1 vline\n");
  4389. }
  4390. break;
  4391. default:
  4392. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4393. break;
  4394. }
  4395. break;
  4396. case 2: /* D2 vblank/vline */
  4397. switch (src_data) {
  4398. case 0: /* D2 vblank */
  4399. if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VBLANK_INTERRUPT) {
  4400. if (rdev->irq.crtc_vblank_int[1]) {
  4401. drm_handle_vblank(rdev->ddev, 1);
  4402. rdev->pm.vblank_sync = true;
  4403. wake_up(&rdev->irq.vblank_queue);
  4404. }
  4405. if (atomic_read(&rdev->irq.pflip[1]))
  4406. radeon_crtc_handle_flip(rdev, 1);
  4407. rdev->irq.stat_regs.evergreen.disp_int_cont &= ~LB_D2_VBLANK_INTERRUPT;
  4408. DRM_DEBUG("IH: D2 vblank\n");
  4409. }
  4410. break;
  4411. case 1: /* D2 vline */
  4412. if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VLINE_INTERRUPT) {
  4413. rdev->irq.stat_regs.evergreen.disp_int_cont &= ~LB_D2_VLINE_INTERRUPT;
  4414. DRM_DEBUG("IH: D2 vline\n");
  4415. }
  4416. break;
  4417. default:
  4418. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4419. break;
  4420. }
  4421. break;
  4422. case 3: /* D3 vblank/vline */
  4423. switch (src_data) {
  4424. case 0: /* D3 vblank */
  4425. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VBLANK_INTERRUPT) {
  4426. if (rdev->irq.crtc_vblank_int[2]) {
  4427. drm_handle_vblank(rdev->ddev, 2);
  4428. rdev->pm.vblank_sync = true;
  4429. wake_up(&rdev->irq.vblank_queue);
  4430. }
  4431. if (atomic_read(&rdev->irq.pflip[2]))
  4432. radeon_crtc_handle_flip(rdev, 2);
  4433. rdev->irq.stat_regs.evergreen.disp_int_cont2 &= ~LB_D3_VBLANK_INTERRUPT;
  4434. DRM_DEBUG("IH: D3 vblank\n");
  4435. }
  4436. break;
  4437. case 1: /* D3 vline */
  4438. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VLINE_INTERRUPT) {
  4439. rdev->irq.stat_regs.evergreen.disp_int_cont2 &= ~LB_D3_VLINE_INTERRUPT;
  4440. DRM_DEBUG("IH: D3 vline\n");
  4441. }
  4442. break;
  4443. default:
  4444. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4445. break;
  4446. }
  4447. break;
  4448. case 4: /* D4 vblank/vline */
  4449. switch (src_data) {
  4450. case 0: /* D4 vblank */
  4451. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VBLANK_INTERRUPT) {
  4452. if (rdev->irq.crtc_vblank_int[3]) {
  4453. drm_handle_vblank(rdev->ddev, 3);
  4454. rdev->pm.vblank_sync = true;
  4455. wake_up(&rdev->irq.vblank_queue);
  4456. }
  4457. if (atomic_read(&rdev->irq.pflip[3]))
  4458. radeon_crtc_handle_flip(rdev, 3);
  4459. rdev->irq.stat_regs.evergreen.disp_int_cont3 &= ~LB_D4_VBLANK_INTERRUPT;
  4460. DRM_DEBUG("IH: D4 vblank\n");
  4461. }
  4462. break;
  4463. case 1: /* D4 vline */
  4464. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VLINE_INTERRUPT) {
  4465. rdev->irq.stat_regs.evergreen.disp_int_cont3 &= ~LB_D4_VLINE_INTERRUPT;
  4466. DRM_DEBUG("IH: D4 vline\n");
  4467. }
  4468. break;
  4469. default:
  4470. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4471. break;
  4472. }
  4473. break;
  4474. case 5: /* D5 vblank/vline */
  4475. switch (src_data) {
  4476. case 0: /* D5 vblank */
  4477. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VBLANK_INTERRUPT) {
  4478. if (rdev->irq.crtc_vblank_int[4]) {
  4479. drm_handle_vblank(rdev->ddev, 4);
  4480. rdev->pm.vblank_sync = true;
  4481. wake_up(&rdev->irq.vblank_queue);
  4482. }
  4483. if (atomic_read(&rdev->irq.pflip[4]))
  4484. radeon_crtc_handle_flip(rdev, 4);
  4485. rdev->irq.stat_regs.evergreen.disp_int_cont4 &= ~LB_D5_VBLANK_INTERRUPT;
  4486. DRM_DEBUG("IH: D5 vblank\n");
  4487. }
  4488. break;
  4489. case 1: /* D5 vline */
  4490. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VLINE_INTERRUPT) {
  4491. rdev->irq.stat_regs.evergreen.disp_int_cont4 &= ~LB_D5_VLINE_INTERRUPT;
  4492. DRM_DEBUG("IH: D5 vline\n");
  4493. }
  4494. break;
  4495. default:
  4496. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4497. break;
  4498. }
  4499. break;
  4500. case 6: /* D6 vblank/vline */
  4501. switch (src_data) {
  4502. case 0: /* D6 vblank */
  4503. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VBLANK_INTERRUPT) {
  4504. if (rdev->irq.crtc_vblank_int[5]) {
  4505. drm_handle_vblank(rdev->ddev, 5);
  4506. rdev->pm.vblank_sync = true;
  4507. wake_up(&rdev->irq.vblank_queue);
  4508. }
  4509. if (atomic_read(&rdev->irq.pflip[5]))
  4510. radeon_crtc_handle_flip(rdev, 5);
  4511. rdev->irq.stat_regs.evergreen.disp_int_cont5 &= ~LB_D6_VBLANK_INTERRUPT;
  4512. DRM_DEBUG("IH: D6 vblank\n");
  4513. }
  4514. break;
  4515. case 1: /* D6 vline */
  4516. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VLINE_INTERRUPT) {
  4517. rdev->irq.stat_regs.evergreen.disp_int_cont5 &= ~LB_D6_VLINE_INTERRUPT;
  4518. DRM_DEBUG("IH: D6 vline\n");
  4519. }
  4520. break;
  4521. default:
  4522. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4523. break;
  4524. }
  4525. break;
  4526. case 42: /* HPD hotplug */
  4527. switch (src_data) {
  4528. case 0:
  4529. if (rdev->irq.stat_regs.evergreen.disp_int & DC_HPD1_INTERRUPT) {
  4530. rdev->irq.stat_regs.evergreen.disp_int &= ~DC_HPD1_INTERRUPT;
  4531. queue_hotplug = true;
  4532. DRM_DEBUG("IH: HPD1\n");
  4533. }
  4534. break;
  4535. case 1:
  4536. if (rdev->irq.stat_regs.evergreen.disp_int_cont & DC_HPD2_INTERRUPT) {
  4537. rdev->irq.stat_regs.evergreen.disp_int_cont &= ~DC_HPD2_INTERRUPT;
  4538. queue_hotplug = true;
  4539. DRM_DEBUG("IH: HPD2\n");
  4540. }
  4541. break;
  4542. case 2:
  4543. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & DC_HPD3_INTERRUPT) {
  4544. rdev->irq.stat_regs.evergreen.disp_int_cont2 &= ~DC_HPD3_INTERRUPT;
  4545. queue_hotplug = true;
  4546. DRM_DEBUG("IH: HPD3\n");
  4547. }
  4548. break;
  4549. case 3:
  4550. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & DC_HPD4_INTERRUPT) {
  4551. rdev->irq.stat_regs.evergreen.disp_int_cont3 &= ~DC_HPD4_INTERRUPT;
  4552. queue_hotplug = true;
  4553. DRM_DEBUG("IH: HPD4\n");
  4554. }
  4555. break;
  4556. case 4:
  4557. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & DC_HPD5_INTERRUPT) {
  4558. rdev->irq.stat_regs.evergreen.disp_int_cont4 &= ~DC_HPD5_INTERRUPT;
  4559. queue_hotplug = true;
  4560. DRM_DEBUG("IH: HPD5\n");
  4561. }
  4562. break;
  4563. case 5:
  4564. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & DC_HPD6_INTERRUPT) {
  4565. rdev->irq.stat_regs.evergreen.disp_int_cont5 &= ~DC_HPD6_INTERRUPT;
  4566. queue_hotplug = true;
  4567. DRM_DEBUG("IH: HPD6\n");
  4568. }
  4569. break;
  4570. default:
  4571. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4572. break;
  4573. }
  4574. break;
  4575. case 146:
  4576. case 147:
  4577. dev_err(rdev->dev, "GPU fault detected: %d 0x%08x\n", src_id, src_data);
  4578. dev_err(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_ADDR 0x%08X\n",
  4579. RREG32(VM_CONTEXT1_PROTECTION_FAULT_ADDR));
  4580. dev_err(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_STATUS 0x%08X\n",
  4581. RREG32(VM_CONTEXT1_PROTECTION_FAULT_STATUS));
  4582. /* reset addr and status */
  4583. WREG32_P(VM_CONTEXT1_CNTL2, 1, ~1);
  4584. break;
  4585. case 176: /* RINGID0 CP_INT */
  4586. radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
  4587. break;
  4588. case 177: /* RINGID1 CP_INT */
  4589. radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP1_INDEX);
  4590. break;
  4591. case 178: /* RINGID2 CP_INT */
  4592. radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP2_INDEX);
  4593. break;
  4594. case 181: /* CP EOP event */
  4595. DRM_DEBUG("IH: CP EOP\n");
  4596. switch (ring_id) {
  4597. case 0:
  4598. radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
  4599. break;
  4600. case 1:
  4601. radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP1_INDEX);
  4602. break;
  4603. case 2:
  4604. radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP2_INDEX);
  4605. break;
  4606. }
  4607. break;
  4608. case 224: /* DMA trap event */
  4609. DRM_DEBUG("IH: DMA trap\n");
  4610. radeon_fence_process(rdev, R600_RING_TYPE_DMA_INDEX);
  4611. break;
  4612. case 233: /* GUI IDLE */
  4613. DRM_DEBUG("IH: GUI idle\n");
  4614. break;
  4615. case 244: /* DMA trap event */
  4616. DRM_DEBUG("IH: DMA1 trap\n");
  4617. radeon_fence_process(rdev, CAYMAN_RING_TYPE_DMA1_INDEX);
  4618. break;
  4619. default:
  4620. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4621. break;
  4622. }
  4623. /* wptr/rptr are in bytes! */
  4624. rptr += 16;
  4625. rptr &= rdev->ih.ptr_mask;
  4626. }
  4627. if (queue_hotplug)
  4628. schedule_work(&rdev->hotplug_work);
  4629. rdev->ih.rptr = rptr;
  4630. WREG32(IH_RB_RPTR, rdev->ih.rptr);
  4631. atomic_set(&rdev->ih.lock, 0);
  4632. /* make sure wptr hasn't changed while processing */
  4633. wptr = si_get_ih_wptr(rdev);
  4634. if (wptr != rptr)
  4635. goto restart_ih;
  4636. return IRQ_HANDLED;
  4637. }
  4638. /**
  4639. * si_copy_dma - copy pages using the DMA engine
  4640. *
  4641. * @rdev: radeon_device pointer
  4642. * @src_offset: src GPU address
  4643. * @dst_offset: dst GPU address
  4644. * @num_gpu_pages: number of GPU pages to xfer
  4645. * @fence: radeon fence object
  4646. *
  4647. * Copy GPU paging using the DMA engine (SI).
  4648. * Used by the radeon ttm implementation to move pages if
  4649. * registered as the asic copy callback.
  4650. */
  4651. int si_copy_dma(struct radeon_device *rdev,
  4652. uint64_t src_offset, uint64_t dst_offset,
  4653. unsigned num_gpu_pages,
  4654. struct radeon_fence **fence)
  4655. {
  4656. struct radeon_semaphore *sem = NULL;
  4657. int ring_index = rdev->asic->copy.dma_ring_index;
  4658. struct radeon_ring *ring = &rdev->ring[ring_index];
  4659. u32 size_in_bytes, cur_size_in_bytes;
  4660. int i, num_loops;
  4661. int r = 0;
  4662. r = radeon_semaphore_create(rdev, &sem);
  4663. if (r) {
  4664. DRM_ERROR("radeon: moving bo (%d).\n", r);
  4665. return r;
  4666. }
  4667. size_in_bytes = (num_gpu_pages << RADEON_GPU_PAGE_SHIFT);
  4668. num_loops = DIV_ROUND_UP(size_in_bytes, 0xfffff);
  4669. r = radeon_ring_lock(rdev, ring, num_loops * 5 + 11);
  4670. if (r) {
  4671. DRM_ERROR("radeon: moving bo (%d).\n", r);
  4672. radeon_semaphore_free(rdev, &sem, NULL);
  4673. return r;
  4674. }
  4675. if (radeon_fence_need_sync(*fence, ring->idx)) {
  4676. radeon_semaphore_sync_rings(rdev, sem, (*fence)->ring,
  4677. ring->idx);
  4678. radeon_fence_note_sync(*fence, ring->idx);
  4679. } else {
  4680. radeon_semaphore_free(rdev, &sem, NULL);
  4681. }
  4682. for (i = 0; i < num_loops; i++) {
  4683. cur_size_in_bytes = size_in_bytes;
  4684. if (cur_size_in_bytes > 0xFFFFF)
  4685. cur_size_in_bytes = 0xFFFFF;
  4686. size_in_bytes -= cur_size_in_bytes;
  4687. radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_COPY, 1, 0, 0, cur_size_in_bytes));
  4688. radeon_ring_write(ring, dst_offset & 0xffffffff);
  4689. radeon_ring_write(ring, src_offset & 0xffffffff);
  4690. radeon_ring_write(ring, upper_32_bits(dst_offset) & 0xff);
  4691. radeon_ring_write(ring, upper_32_bits(src_offset) & 0xff);
  4692. src_offset += cur_size_in_bytes;
  4693. dst_offset += cur_size_in_bytes;
  4694. }
  4695. r = radeon_fence_emit(rdev, fence, ring->idx);
  4696. if (r) {
  4697. radeon_ring_unlock_undo(rdev, ring);
  4698. return r;
  4699. }
  4700. radeon_ring_unlock_commit(rdev, ring);
  4701. radeon_semaphore_free(rdev, &sem, *fence);
  4702. return r;
  4703. }
  4704. /*
  4705. * startup/shutdown callbacks
  4706. */
  4707. static int si_startup(struct radeon_device *rdev)
  4708. {
  4709. struct radeon_ring *ring;
  4710. int r;
  4711. if (!rdev->me_fw || !rdev->pfp_fw || !rdev->ce_fw ||
  4712. !rdev->rlc_fw || !rdev->mc_fw) {
  4713. r = si_init_microcode(rdev);
  4714. if (r) {
  4715. DRM_ERROR("Failed to load firmware!\n");
  4716. return r;
  4717. }
  4718. }
  4719. r = si_mc_load_microcode(rdev);
  4720. if (r) {
  4721. DRM_ERROR("Failed to load MC firmware!\n");
  4722. return r;
  4723. }
  4724. r = r600_vram_scratch_init(rdev);
  4725. if (r)
  4726. return r;
  4727. si_mc_program(rdev);
  4728. r = si_pcie_gart_enable(rdev);
  4729. if (r)
  4730. return r;
  4731. si_gpu_init(rdev);
  4732. /* allocate rlc buffers */
  4733. r = si_rlc_init(rdev);
  4734. if (r) {
  4735. DRM_ERROR("Failed to init rlc BOs!\n");
  4736. return r;
  4737. }
  4738. /* allocate wb buffer */
  4739. r = radeon_wb_init(rdev);
  4740. if (r)
  4741. return r;
  4742. r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX);
  4743. if (r) {
  4744. dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
  4745. return r;
  4746. }
  4747. r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_CP1_INDEX);
  4748. if (r) {
  4749. dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
  4750. return r;
  4751. }
  4752. r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_CP2_INDEX);
  4753. if (r) {
  4754. dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
  4755. return r;
  4756. }
  4757. r = radeon_fence_driver_start_ring(rdev, R600_RING_TYPE_DMA_INDEX);
  4758. if (r) {
  4759. dev_err(rdev->dev, "failed initializing DMA fences (%d).\n", r);
  4760. return r;
  4761. }
  4762. r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_DMA1_INDEX);
  4763. if (r) {
  4764. dev_err(rdev->dev, "failed initializing DMA fences (%d).\n", r);
  4765. return r;
  4766. }
  4767. if (rdev->has_uvd) {
  4768. r = rv770_uvd_resume(rdev);
  4769. if (!r) {
  4770. r = radeon_fence_driver_start_ring(rdev,
  4771. R600_RING_TYPE_UVD_INDEX);
  4772. if (r)
  4773. dev_err(rdev->dev, "UVD fences init error (%d).\n", r);
  4774. }
  4775. if (r)
  4776. rdev->ring[R600_RING_TYPE_UVD_INDEX].ring_size = 0;
  4777. }
  4778. /* Enable IRQ */
  4779. r = si_irq_init(rdev);
  4780. if (r) {
  4781. DRM_ERROR("radeon: IH init failed (%d).\n", r);
  4782. radeon_irq_kms_fini(rdev);
  4783. return r;
  4784. }
  4785. si_irq_set(rdev);
  4786. ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  4787. r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP_RPTR_OFFSET,
  4788. CP_RB0_RPTR, CP_RB0_WPTR,
  4789. 0, 0xfffff, RADEON_CP_PACKET2);
  4790. if (r)
  4791. return r;
  4792. ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
  4793. r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP1_RPTR_OFFSET,
  4794. CP_RB1_RPTR, CP_RB1_WPTR,
  4795. 0, 0xfffff, RADEON_CP_PACKET2);
  4796. if (r)
  4797. return r;
  4798. ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
  4799. r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP2_RPTR_OFFSET,
  4800. CP_RB2_RPTR, CP_RB2_WPTR,
  4801. 0, 0xfffff, RADEON_CP_PACKET2);
  4802. if (r)
  4803. return r;
  4804. ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
  4805. r = radeon_ring_init(rdev, ring, ring->ring_size, R600_WB_DMA_RPTR_OFFSET,
  4806. DMA_RB_RPTR + DMA0_REGISTER_OFFSET,
  4807. DMA_RB_WPTR + DMA0_REGISTER_OFFSET,
  4808. 2, 0x3fffc, DMA_PACKET(DMA_PACKET_NOP, 0, 0, 0, 0));
  4809. if (r)
  4810. return r;
  4811. ring = &rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX];
  4812. r = radeon_ring_init(rdev, ring, ring->ring_size, CAYMAN_WB_DMA1_RPTR_OFFSET,
  4813. DMA_RB_RPTR + DMA1_REGISTER_OFFSET,
  4814. DMA_RB_WPTR + DMA1_REGISTER_OFFSET,
  4815. 2, 0x3fffc, DMA_PACKET(DMA_PACKET_NOP, 0, 0, 0, 0));
  4816. if (r)
  4817. return r;
  4818. r = si_cp_load_microcode(rdev);
  4819. if (r)
  4820. return r;
  4821. r = si_cp_resume(rdev);
  4822. if (r)
  4823. return r;
  4824. r = cayman_dma_resume(rdev);
  4825. if (r)
  4826. return r;
  4827. if (rdev->has_uvd) {
  4828. ring = &rdev->ring[R600_RING_TYPE_UVD_INDEX];
  4829. if (ring->ring_size) {
  4830. r = radeon_ring_init(rdev, ring, ring->ring_size,
  4831. R600_WB_UVD_RPTR_OFFSET,
  4832. UVD_RBC_RB_RPTR, UVD_RBC_RB_WPTR,
  4833. 0, 0xfffff, RADEON_CP_PACKET2);
  4834. if (!r)
  4835. r = r600_uvd_init(rdev);
  4836. if (r)
  4837. DRM_ERROR("radeon: failed initializing UVD (%d).\n", r);
  4838. }
  4839. }
  4840. r = radeon_ib_pool_init(rdev);
  4841. if (r) {
  4842. dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
  4843. return r;
  4844. }
  4845. r = radeon_vm_manager_init(rdev);
  4846. if (r) {
  4847. dev_err(rdev->dev, "vm manager initialization failed (%d).\n", r);
  4848. return r;
  4849. }
  4850. return 0;
  4851. }
  4852. int si_resume(struct radeon_device *rdev)
  4853. {
  4854. int r;
  4855. /* Do not reset GPU before posting, on rv770 hw unlike on r500 hw,
  4856. * posting will perform necessary task to bring back GPU into good
  4857. * shape.
  4858. */
  4859. /* post card */
  4860. atom_asic_init(rdev->mode_info.atom_context);
  4861. /* init golden registers */
  4862. si_init_golden_registers(rdev);
  4863. rdev->accel_working = true;
  4864. r = si_startup(rdev);
  4865. if (r) {
  4866. DRM_ERROR("si startup failed on resume\n");
  4867. rdev->accel_working = false;
  4868. return r;
  4869. }
  4870. return r;
  4871. }
  4872. int si_suspend(struct radeon_device *rdev)
  4873. {
  4874. radeon_vm_manager_fini(rdev);
  4875. si_cp_enable(rdev, false);
  4876. cayman_dma_stop(rdev);
  4877. if (rdev->has_uvd) {
  4878. r600_uvd_rbc_stop(rdev);
  4879. radeon_uvd_suspend(rdev);
  4880. }
  4881. si_irq_suspend(rdev);
  4882. radeon_wb_disable(rdev);
  4883. si_pcie_gart_disable(rdev);
  4884. return 0;
  4885. }
  4886. /* Plan is to move initialization in that function and use
  4887. * helper function so that radeon_device_init pretty much
  4888. * do nothing more than calling asic specific function. This
  4889. * should also allow to remove a bunch of callback function
  4890. * like vram_info.
  4891. */
  4892. int si_init(struct radeon_device *rdev)
  4893. {
  4894. struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  4895. int r;
  4896. /* Read BIOS */
  4897. if (!radeon_get_bios(rdev)) {
  4898. if (ASIC_IS_AVIVO(rdev))
  4899. return -EINVAL;
  4900. }
  4901. /* Must be an ATOMBIOS */
  4902. if (!rdev->is_atom_bios) {
  4903. dev_err(rdev->dev, "Expecting atombios for cayman GPU\n");
  4904. return -EINVAL;
  4905. }
  4906. r = radeon_atombios_init(rdev);
  4907. if (r)
  4908. return r;
  4909. /* Post card if necessary */
  4910. if (!radeon_card_posted(rdev)) {
  4911. if (!rdev->bios) {
  4912. dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n");
  4913. return -EINVAL;
  4914. }
  4915. DRM_INFO("GPU not posted. posting now...\n");
  4916. atom_asic_init(rdev->mode_info.atom_context);
  4917. }
  4918. /* init golden registers */
  4919. si_init_golden_registers(rdev);
  4920. /* Initialize scratch registers */
  4921. si_scratch_init(rdev);
  4922. /* Initialize surface registers */
  4923. radeon_surface_init(rdev);
  4924. /* Initialize clocks */
  4925. radeon_get_clock_info(rdev->ddev);
  4926. /* Fence driver */
  4927. r = radeon_fence_driver_init(rdev);
  4928. if (r)
  4929. return r;
  4930. /* initialize memory controller */
  4931. r = si_mc_init(rdev);
  4932. if (r)
  4933. return r;
  4934. /* Memory manager */
  4935. r = radeon_bo_init(rdev);
  4936. if (r)
  4937. return r;
  4938. r = radeon_irq_kms_init(rdev);
  4939. if (r)
  4940. return r;
  4941. ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  4942. ring->ring_obj = NULL;
  4943. r600_ring_init(rdev, ring, 1024 * 1024);
  4944. ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
  4945. ring->ring_obj = NULL;
  4946. r600_ring_init(rdev, ring, 1024 * 1024);
  4947. ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
  4948. ring->ring_obj = NULL;
  4949. r600_ring_init(rdev, ring, 1024 * 1024);
  4950. ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
  4951. ring->ring_obj = NULL;
  4952. r600_ring_init(rdev, ring, 64 * 1024);
  4953. ring = &rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX];
  4954. ring->ring_obj = NULL;
  4955. r600_ring_init(rdev, ring, 64 * 1024);
  4956. if (rdev->has_uvd) {
  4957. r = radeon_uvd_init(rdev);
  4958. if (!r) {
  4959. ring = &rdev->ring[R600_RING_TYPE_UVD_INDEX];
  4960. ring->ring_obj = NULL;
  4961. r600_ring_init(rdev, ring, 4096);
  4962. }
  4963. }
  4964. rdev->ih.ring_obj = NULL;
  4965. r600_ih_ring_init(rdev, 64 * 1024);
  4966. r = r600_pcie_gart_init(rdev);
  4967. if (r)
  4968. return r;
  4969. rdev->accel_working = true;
  4970. r = si_startup(rdev);
  4971. if (r) {
  4972. dev_err(rdev->dev, "disabling GPU acceleration\n");
  4973. si_cp_fini(rdev);
  4974. cayman_dma_fini(rdev);
  4975. si_irq_fini(rdev);
  4976. si_rlc_fini(rdev);
  4977. radeon_wb_fini(rdev);
  4978. radeon_ib_pool_fini(rdev);
  4979. radeon_vm_manager_fini(rdev);
  4980. radeon_irq_kms_fini(rdev);
  4981. si_pcie_gart_fini(rdev);
  4982. rdev->accel_working = false;
  4983. }
  4984. /* Don't start up if the MC ucode is missing.
  4985. * The default clocks and voltages before the MC ucode
  4986. * is loaded are not suffient for advanced operations.
  4987. */
  4988. if (!rdev->mc_fw) {
  4989. DRM_ERROR("radeon: MC ucode required for NI+.\n");
  4990. return -EINVAL;
  4991. }
  4992. return 0;
  4993. }
  4994. void si_fini(struct radeon_device *rdev)
  4995. {
  4996. si_cp_fini(rdev);
  4997. cayman_dma_fini(rdev);
  4998. si_irq_fini(rdev);
  4999. si_rlc_fini(rdev);
  5000. radeon_wb_fini(rdev);
  5001. radeon_vm_manager_fini(rdev);
  5002. radeon_ib_pool_fini(rdev);
  5003. radeon_irq_kms_fini(rdev);
  5004. if (rdev->has_uvd)
  5005. radeon_uvd_fini(rdev);
  5006. si_pcie_gart_fini(rdev);
  5007. r600_vram_scratch_fini(rdev);
  5008. radeon_gem_fini(rdev);
  5009. radeon_fence_driver_fini(rdev);
  5010. radeon_bo_fini(rdev);
  5011. radeon_atombios_fini(rdev);
  5012. kfree(rdev->bios);
  5013. rdev->bios = NULL;
  5014. }
  5015. /**
  5016. * si_get_gpu_clock_counter - return GPU clock counter snapshot
  5017. *
  5018. * @rdev: radeon_device pointer
  5019. *
  5020. * Fetches a GPU clock counter snapshot (SI).
  5021. * Returns the 64 bit clock counter snapshot.
  5022. */
  5023. uint64_t si_get_gpu_clock_counter(struct radeon_device *rdev)
  5024. {
  5025. uint64_t clock;
  5026. mutex_lock(&rdev->gpu_clock_mutex);
  5027. WREG32(RLC_CAPTURE_GPU_CLOCK_COUNT, 1);
  5028. clock = (uint64_t)RREG32(RLC_GPU_CLOCK_COUNT_LSB) |
  5029. ((uint64_t)RREG32(RLC_GPU_CLOCK_COUNT_MSB) << 32ULL);
  5030. mutex_unlock(&rdev->gpu_clock_mutex);
  5031. return clock;
  5032. }
  5033. int si_set_uvd_clocks(struct radeon_device *rdev, u32 vclk, u32 dclk)
  5034. {
  5035. unsigned fb_div = 0, vclk_div = 0, dclk_div = 0;
  5036. int r;
  5037. /* bypass vclk and dclk with bclk */
  5038. WREG32_P(CG_UPLL_FUNC_CNTL_2,
  5039. VCLK_SRC_SEL(1) | DCLK_SRC_SEL(1),
  5040. ~(VCLK_SRC_SEL_MASK | DCLK_SRC_SEL_MASK));
  5041. /* put PLL in bypass mode */
  5042. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_BYPASS_EN_MASK, ~UPLL_BYPASS_EN_MASK);
  5043. if (!vclk || !dclk) {
  5044. /* keep the Bypass mode, put PLL to sleep */
  5045. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_SLEEP_MASK, ~UPLL_SLEEP_MASK);
  5046. return 0;
  5047. }
  5048. r = radeon_uvd_calc_upll_dividers(rdev, vclk, dclk, 125000, 250000,
  5049. 16384, 0x03FFFFFF, 0, 128, 5,
  5050. &fb_div, &vclk_div, &dclk_div);
  5051. if (r)
  5052. return r;
  5053. /* set RESET_ANTI_MUX to 0 */
  5054. WREG32_P(CG_UPLL_FUNC_CNTL_5, 0, ~RESET_ANTI_MUX_MASK);
  5055. /* set VCO_MODE to 1 */
  5056. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_VCO_MODE_MASK, ~UPLL_VCO_MODE_MASK);
  5057. /* toggle UPLL_SLEEP to 1 then back to 0 */
  5058. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_SLEEP_MASK, ~UPLL_SLEEP_MASK);
  5059. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_SLEEP_MASK);
  5060. /* deassert UPLL_RESET */
  5061. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_RESET_MASK);
  5062. mdelay(1);
  5063. r = radeon_uvd_send_upll_ctlreq(rdev, CG_UPLL_FUNC_CNTL);
  5064. if (r)
  5065. return r;
  5066. /* assert UPLL_RESET again */
  5067. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_RESET_MASK, ~UPLL_RESET_MASK);
  5068. /* disable spread spectrum. */
  5069. WREG32_P(CG_UPLL_SPREAD_SPECTRUM, 0, ~SSEN_MASK);
  5070. /* set feedback divider */
  5071. WREG32_P(CG_UPLL_FUNC_CNTL_3, UPLL_FB_DIV(fb_div), ~UPLL_FB_DIV_MASK);
  5072. /* set ref divider to 0 */
  5073. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_REF_DIV_MASK);
  5074. if (fb_div < 307200)
  5075. WREG32_P(CG_UPLL_FUNC_CNTL_4, 0, ~UPLL_SPARE_ISPARE9);
  5076. else
  5077. WREG32_P(CG_UPLL_FUNC_CNTL_4, UPLL_SPARE_ISPARE9, ~UPLL_SPARE_ISPARE9);
  5078. /* set PDIV_A and PDIV_B */
  5079. WREG32_P(CG_UPLL_FUNC_CNTL_2,
  5080. UPLL_PDIV_A(vclk_div) | UPLL_PDIV_B(dclk_div),
  5081. ~(UPLL_PDIV_A_MASK | UPLL_PDIV_B_MASK));
  5082. /* give the PLL some time to settle */
  5083. mdelay(15);
  5084. /* deassert PLL_RESET */
  5085. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_RESET_MASK);
  5086. mdelay(15);
  5087. /* switch from bypass mode to normal mode */
  5088. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_BYPASS_EN_MASK);
  5089. r = radeon_uvd_send_upll_ctlreq(rdev, CG_UPLL_FUNC_CNTL);
  5090. if (r)
  5091. return r;
  5092. /* switch VCLK and DCLK selection */
  5093. WREG32_P(CG_UPLL_FUNC_CNTL_2,
  5094. VCLK_SRC_SEL(2) | DCLK_SRC_SEL(2),
  5095. ~(VCLK_SRC_SEL_MASK | DCLK_SRC_SEL_MASK));
  5096. mdelay(100);
  5097. return 0;
  5098. }