gfx_v7_0.c 156 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288
  1. /*
  2. * Copyright 2014 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. */
  23. #include <linux/firmware.h>
  24. #include <drm/drmP.h>
  25. #include "amdgpu.h"
  26. #include "amdgpu_ih.h"
  27. #include "amdgpu_gfx.h"
  28. #include "cikd.h"
  29. #include "cik.h"
  30. #include "cik_structs.h"
  31. #include "atom.h"
  32. #include "amdgpu_ucode.h"
  33. #include "clearstate_ci.h"
  34. #include "dce/dce_8_0_d.h"
  35. #include "dce/dce_8_0_sh_mask.h"
  36. #include "bif/bif_4_1_d.h"
  37. #include "bif/bif_4_1_sh_mask.h"
  38. #include "gca/gfx_7_0_d.h"
  39. #include "gca/gfx_7_2_enum.h"
  40. #include "gca/gfx_7_2_sh_mask.h"
  41. #include "gmc/gmc_7_0_d.h"
  42. #include "gmc/gmc_7_0_sh_mask.h"
  43. #include "oss/oss_2_0_d.h"
  44. #include "oss/oss_2_0_sh_mask.h"
  45. #define GFX7_NUM_GFX_RINGS 1
  46. #define GFX7_MEC_HPD_SIZE 2048
  47. static void gfx_v7_0_set_ring_funcs(struct amdgpu_device *adev);
  48. static void gfx_v7_0_set_irq_funcs(struct amdgpu_device *adev);
  49. static void gfx_v7_0_set_gds_init(struct amdgpu_device *adev);
  50. MODULE_FIRMWARE("radeon/bonaire_pfp.bin");
  51. MODULE_FIRMWARE("radeon/bonaire_me.bin");
  52. MODULE_FIRMWARE("radeon/bonaire_ce.bin");
  53. MODULE_FIRMWARE("radeon/bonaire_rlc.bin");
  54. MODULE_FIRMWARE("radeon/bonaire_mec.bin");
  55. MODULE_FIRMWARE("radeon/hawaii_pfp.bin");
  56. MODULE_FIRMWARE("radeon/hawaii_me.bin");
  57. MODULE_FIRMWARE("radeon/hawaii_ce.bin");
  58. MODULE_FIRMWARE("radeon/hawaii_rlc.bin");
  59. MODULE_FIRMWARE("radeon/hawaii_mec.bin");
  60. MODULE_FIRMWARE("radeon/kaveri_pfp.bin");
  61. MODULE_FIRMWARE("radeon/kaveri_me.bin");
  62. MODULE_FIRMWARE("radeon/kaveri_ce.bin");
  63. MODULE_FIRMWARE("radeon/kaveri_rlc.bin");
  64. MODULE_FIRMWARE("radeon/kaveri_mec.bin");
  65. MODULE_FIRMWARE("radeon/kaveri_mec2.bin");
  66. MODULE_FIRMWARE("radeon/kabini_pfp.bin");
  67. MODULE_FIRMWARE("radeon/kabini_me.bin");
  68. MODULE_FIRMWARE("radeon/kabini_ce.bin");
  69. MODULE_FIRMWARE("radeon/kabini_rlc.bin");
  70. MODULE_FIRMWARE("radeon/kabini_mec.bin");
  71. MODULE_FIRMWARE("radeon/mullins_pfp.bin");
  72. MODULE_FIRMWARE("radeon/mullins_me.bin");
  73. MODULE_FIRMWARE("radeon/mullins_ce.bin");
  74. MODULE_FIRMWARE("radeon/mullins_rlc.bin");
  75. MODULE_FIRMWARE("radeon/mullins_mec.bin");
  76. static const struct amdgpu_gds_reg_offset amdgpu_gds_reg_offset[] =
  77. {
  78. {mmGDS_VMID0_BASE, mmGDS_VMID0_SIZE, mmGDS_GWS_VMID0, mmGDS_OA_VMID0},
  79. {mmGDS_VMID1_BASE, mmGDS_VMID1_SIZE, mmGDS_GWS_VMID1, mmGDS_OA_VMID1},
  80. {mmGDS_VMID2_BASE, mmGDS_VMID2_SIZE, mmGDS_GWS_VMID2, mmGDS_OA_VMID2},
  81. {mmGDS_VMID3_BASE, mmGDS_VMID3_SIZE, mmGDS_GWS_VMID3, mmGDS_OA_VMID3},
  82. {mmGDS_VMID4_BASE, mmGDS_VMID4_SIZE, mmGDS_GWS_VMID4, mmGDS_OA_VMID4},
  83. {mmGDS_VMID5_BASE, mmGDS_VMID5_SIZE, mmGDS_GWS_VMID5, mmGDS_OA_VMID5},
  84. {mmGDS_VMID6_BASE, mmGDS_VMID6_SIZE, mmGDS_GWS_VMID6, mmGDS_OA_VMID6},
  85. {mmGDS_VMID7_BASE, mmGDS_VMID7_SIZE, mmGDS_GWS_VMID7, mmGDS_OA_VMID7},
  86. {mmGDS_VMID8_BASE, mmGDS_VMID8_SIZE, mmGDS_GWS_VMID8, mmGDS_OA_VMID8},
  87. {mmGDS_VMID9_BASE, mmGDS_VMID9_SIZE, mmGDS_GWS_VMID9, mmGDS_OA_VMID9},
  88. {mmGDS_VMID10_BASE, mmGDS_VMID10_SIZE, mmGDS_GWS_VMID10, mmGDS_OA_VMID10},
  89. {mmGDS_VMID11_BASE, mmGDS_VMID11_SIZE, mmGDS_GWS_VMID11, mmGDS_OA_VMID11},
  90. {mmGDS_VMID12_BASE, mmGDS_VMID12_SIZE, mmGDS_GWS_VMID12, mmGDS_OA_VMID12},
  91. {mmGDS_VMID13_BASE, mmGDS_VMID13_SIZE, mmGDS_GWS_VMID13, mmGDS_OA_VMID13},
  92. {mmGDS_VMID14_BASE, mmGDS_VMID14_SIZE, mmGDS_GWS_VMID14, mmGDS_OA_VMID14},
  93. {mmGDS_VMID15_BASE, mmGDS_VMID15_SIZE, mmGDS_GWS_VMID15, mmGDS_OA_VMID15}
  94. };
  95. static const u32 spectre_rlc_save_restore_register_list[] =
  96. {
  97. (0x0e00 << 16) | (0xc12c >> 2),
  98. 0x00000000,
  99. (0x0e00 << 16) | (0xc140 >> 2),
  100. 0x00000000,
  101. (0x0e00 << 16) | (0xc150 >> 2),
  102. 0x00000000,
  103. (0x0e00 << 16) | (0xc15c >> 2),
  104. 0x00000000,
  105. (0x0e00 << 16) | (0xc168 >> 2),
  106. 0x00000000,
  107. (0x0e00 << 16) | (0xc170 >> 2),
  108. 0x00000000,
  109. (0x0e00 << 16) | (0xc178 >> 2),
  110. 0x00000000,
  111. (0x0e00 << 16) | (0xc204 >> 2),
  112. 0x00000000,
  113. (0x0e00 << 16) | (0xc2b4 >> 2),
  114. 0x00000000,
  115. (0x0e00 << 16) | (0xc2b8 >> 2),
  116. 0x00000000,
  117. (0x0e00 << 16) | (0xc2bc >> 2),
  118. 0x00000000,
  119. (0x0e00 << 16) | (0xc2c0 >> 2),
  120. 0x00000000,
  121. (0x0e00 << 16) | (0x8228 >> 2),
  122. 0x00000000,
  123. (0x0e00 << 16) | (0x829c >> 2),
  124. 0x00000000,
  125. (0x0e00 << 16) | (0x869c >> 2),
  126. 0x00000000,
  127. (0x0600 << 16) | (0x98f4 >> 2),
  128. 0x00000000,
  129. (0x0e00 << 16) | (0x98f8 >> 2),
  130. 0x00000000,
  131. (0x0e00 << 16) | (0x9900 >> 2),
  132. 0x00000000,
  133. (0x0e00 << 16) | (0xc260 >> 2),
  134. 0x00000000,
  135. (0x0e00 << 16) | (0x90e8 >> 2),
  136. 0x00000000,
  137. (0x0e00 << 16) | (0x3c000 >> 2),
  138. 0x00000000,
  139. (0x0e00 << 16) | (0x3c00c >> 2),
  140. 0x00000000,
  141. (0x0e00 << 16) | (0x8c1c >> 2),
  142. 0x00000000,
  143. (0x0e00 << 16) | (0x9700 >> 2),
  144. 0x00000000,
  145. (0x0e00 << 16) | (0xcd20 >> 2),
  146. 0x00000000,
  147. (0x4e00 << 16) | (0xcd20 >> 2),
  148. 0x00000000,
  149. (0x5e00 << 16) | (0xcd20 >> 2),
  150. 0x00000000,
  151. (0x6e00 << 16) | (0xcd20 >> 2),
  152. 0x00000000,
  153. (0x7e00 << 16) | (0xcd20 >> 2),
  154. 0x00000000,
  155. (0x8e00 << 16) | (0xcd20 >> 2),
  156. 0x00000000,
  157. (0x9e00 << 16) | (0xcd20 >> 2),
  158. 0x00000000,
  159. (0xae00 << 16) | (0xcd20 >> 2),
  160. 0x00000000,
  161. (0xbe00 << 16) | (0xcd20 >> 2),
  162. 0x00000000,
  163. (0x0e00 << 16) | (0x89bc >> 2),
  164. 0x00000000,
  165. (0x0e00 << 16) | (0x8900 >> 2),
  166. 0x00000000,
  167. 0x3,
  168. (0x0e00 << 16) | (0xc130 >> 2),
  169. 0x00000000,
  170. (0x0e00 << 16) | (0xc134 >> 2),
  171. 0x00000000,
  172. (0x0e00 << 16) | (0xc1fc >> 2),
  173. 0x00000000,
  174. (0x0e00 << 16) | (0xc208 >> 2),
  175. 0x00000000,
  176. (0x0e00 << 16) | (0xc264 >> 2),
  177. 0x00000000,
  178. (0x0e00 << 16) | (0xc268 >> 2),
  179. 0x00000000,
  180. (0x0e00 << 16) | (0xc26c >> 2),
  181. 0x00000000,
  182. (0x0e00 << 16) | (0xc270 >> 2),
  183. 0x00000000,
  184. (0x0e00 << 16) | (0xc274 >> 2),
  185. 0x00000000,
  186. (0x0e00 << 16) | (0xc278 >> 2),
  187. 0x00000000,
  188. (0x0e00 << 16) | (0xc27c >> 2),
  189. 0x00000000,
  190. (0x0e00 << 16) | (0xc280 >> 2),
  191. 0x00000000,
  192. (0x0e00 << 16) | (0xc284 >> 2),
  193. 0x00000000,
  194. (0x0e00 << 16) | (0xc288 >> 2),
  195. 0x00000000,
  196. (0x0e00 << 16) | (0xc28c >> 2),
  197. 0x00000000,
  198. (0x0e00 << 16) | (0xc290 >> 2),
  199. 0x00000000,
  200. (0x0e00 << 16) | (0xc294 >> 2),
  201. 0x00000000,
  202. (0x0e00 << 16) | (0xc298 >> 2),
  203. 0x00000000,
  204. (0x0e00 << 16) | (0xc29c >> 2),
  205. 0x00000000,
  206. (0x0e00 << 16) | (0xc2a0 >> 2),
  207. 0x00000000,
  208. (0x0e00 << 16) | (0xc2a4 >> 2),
  209. 0x00000000,
  210. (0x0e00 << 16) | (0xc2a8 >> 2),
  211. 0x00000000,
  212. (0x0e00 << 16) | (0xc2ac >> 2),
  213. 0x00000000,
  214. (0x0e00 << 16) | (0xc2b0 >> 2),
  215. 0x00000000,
  216. (0x0e00 << 16) | (0x301d0 >> 2),
  217. 0x00000000,
  218. (0x0e00 << 16) | (0x30238 >> 2),
  219. 0x00000000,
  220. (0x0e00 << 16) | (0x30250 >> 2),
  221. 0x00000000,
  222. (0x0e00 << 16) | (0x30254 >> 2),
  223. 0x00000000,
  224. (0x0e00 << 16) | (0x30258 >> 2),
  225. 0x00000000,
  226. (0x0e00 << 16) | (0x3025c >> 2),
  227. 0x00000000,
  228. (0x4e00 << 16) | (0xc900 >> 2),
  229. 0x00000000,
  230. (0x5e00 << 16) | (0xc900 >> 2),
  231. 0x00000000,
  232. (0x6e00 << 16) | (0xc900 >> 2),
  233. 0x00000000,
  234. (0x7e00 << 16) | (0xc900 >> 2),
  235. 0x00000000,
  236. (0x8e00 << 16) | (0xc900 >> 2),
  237. 0x00000000,
  238. (0x9e00 << 16) | (0xc900 >> 2),
  239. 0x00000000,
  240. (0xae00 << 16) | (0xc900 >> 2),
  241. 0x00000000,
  242. (0xbe00 << 16) | (0xc900 >> 2),
  243. 0x00000000,
  244. (0x4e00 << 16) | (0xc904 >> 2),
  245. 0x00000000,
  246. (0x5e00 << 16) | (0xc904 >> 2),
  247. 0x00000000,
  248. (0x6e00 << 16) | (0xc904 >> 2),
  249. 0x00000000,
  250. (0x7e00 << 16) | (0xc904 >> 2),
  251. 0x00000000,
  252. (0x8e00 << 16) | (0xc904 >> 2),
  253. 0x00000000,
  254. (0x9e00 << 16) | (0xc904 >> 2),
  255. 0x00000000,
  256. (0xae00 << 16) | (0xc904 >> 2),
  257. 0x00000000,
  258. (0xbe00 << 16) | (0xc904 >> 2),
  259. 0x00000000,
  260. (0x4e00 << 16) | (0xc908 >> 2),
  261. 0x00000000,
  262. (0x5e00 << 16) | (0xc908 >> 2),
  263. 0x00000000,
  264. (0x6e00 << 16) | (0xc908 >> 2),
  265. 0x00000000,
  266. (0x7e00 << 16) | (0xc908 >> 2),
  267. 0x00000000,
  268. (0x8e00 << 16) | (0xc908 >> 2),
  269. 0x00000000,
  270. (0x9e00 << 16) | (0xc908 >> 2),
  271. 0x00000000,
  272. (0xae00 << 16) | (0xc908 >> 2),
  273. 0x00000000,
  274. (0xbe00 << 16) | (0xc908 >> 2),
  275. 0x00000000,
  276. (0x4e00 << 16) | (0xc90c >> 2),
  277. 0x00000000,
  278. (0x5e00 << 16) | (0xc90c >> 2),
  279. 0x00000000,
  280. (0x6e00 << 16) | (0xc90c >> 2),
  281. 0x00000000,
  282. (0x7e00 << 16) | (0xc90c >> 2),
  283. 0x00000000,
  284. (0x8e00 << 16) | (0xc90c >> 2),
  285. 0x00000000,
  286. (0x9e00 << 16) | (0xc90c >> 2),
  287. 0x00000000,
  288. (0xae00 << 16) | (0xc90c >> 2),
  289. 0x00000000,
  290. (0xbe00 << 16) | (0xc90c >> 2),
  291. 0x00000000,
  292. (0x4e00 << 16) | (0xc910 >> 2),
  293. 0x00000000,
  294. (0x5e00 << 16) | (0xc910 >> 2),
  295. 0x00000000,
  296. (0x6e00 << 16) | (0xc910 >> 2),
  297. 0x00000000,
  298. (0x7e00 << 16) | (0xc910 >> 2),
  299. 0x00000000,
  300. (0x8e00 << 16) | (0xc910 >> 2),
  301. 0x00000000,
  302. (0x9e00 << 16) | (0xc910 >> 2),
  303. 0x00000000,
  304. (0xae00 << 16) | (0xc910 >> 2),
  305. 0x00000000,
  306. (0xbe00 << 16) | (0xc910 >> 2),
  307. 0x00000000,
  308. (0x0e00 << 16) | (0xc99c >> 2),
  309. 0x00000000,
  310. (0x0e00 << 16) | (0x9834 >> 2),
  311. 0x00000000,
  312. (0x0000 << 16) | (0x30f00 >> 2),
  313. 0x00000000,
  314. (0x0001 << 16) | (0x30f00 >> 2),
  315. 0x00000000,
  316. (0x0000 << 16) | (0x30f04 >> 2),
  317. 0x00000000,
  318. (0x0001 << 16) | (0x30f04 >> 2),
  319. 0x00000000,
  320. (0x0000 << 16) | (0x30f08 >> 2),
  321. 0x00000000,
  322. (0x0001 << 16) | (0x30f08 >> 2),
  323. 0x00000000,
  324. (0x0000 << 16) | (0x30f0c >> 2),
  325. 0x00000000,
  326. (0x0001 << 16) | (0x30f0c >> 2),
  327. 0x00000000,
  328. (0x0600 << 16) | (0x9b7c >> 2),
  329. 0x00000000,
  330. (0x0e00 << 16) | (0x8a14 >> 2),
  331. 0x00000000,
  332. (0x0e00 << 16) | (0x8a18 >> 2),
  333. 0x00000000,
  334. (0x0600 << 16) | (0x30a00 >> 2),
  335. 0x00000000,
  336. (0x0e00 << 16) | (0x8bf0 >> 2),
  337. 0x00000000,
  338. (0x0e00 << 16) | (0x8bcc >> 2),
  339. 0x00000000,
  340. (0x0e00 << 16) | (0x8b24 >> 2),
  341. 0x00000000,
  342. (0x0e00 << 16) | (0x30a04 >> 2),
  343. 0x00000000,
  344. (0x0600 << 16) | (0x30a10 >> 2),
  345. 0x00000000,
  346. (0x0600 << 16) | (0x30a14 >> 2),
  347. 0x00000000,
  348. (0x0600 << 16) | (0x30a18 >> 2),
  349. 0x00000000,
  350. (0x0600 << 16) | (0x30a2c >> 2),
  351. 0x00000000,
  352. (0x0e00 << 16) | (0xc700 >> 2),
  353. 0x00000000,
  354. (0x0e00 << 16) | (0xc704 >> 2),
  355. 0x00000000,
  356. (0x0e00 << 16) | (0xc708 >> 2),
  357. 0x00000000,
  358. (0x0e00 << 16) | (0xc768 >> 2),
  359. 0x00000000,
  360. (0x0400 << 16) | (0xc770 >> 2),
  361. 0x00000000,
  362. (0x0400 << 16) | (0xc774 >> 2),
  363. 0x00000000,
  364. (0x0400 << 16) | (0xc778 >> 2),
  365. 0x00000000,
  366. (0x0400 << 16) | (0xc77c >> 2),
  367. 0x00000000,
  368. (0x0400 << 16) | (0xc780 >> 2),
  369. 0x00000000,
  370. (0x0400 << 16) | (0xc784 >> 2),
  371. 0x00000000,
  372. (0x0400 << 16) | (0xc788 >> 2),
  373. 0x00000000,
  374. (0x0400 << 16) | (0xc78c >> 2),
  375. 0x00000000,
  376. (0x0400 << 16) | (0xc798 >> 2),
  377. 0x00000000,
  378. (0x0400 << 16) | (0xc79c >> 2),
  379. 0x00000000,
  380. (0x0400 << 16) | (0xc7a0 >> 2),
  381. 0x00000000,
  382. (0x0400 << 16) | (0xc7a4 >> 2),
  383. 0x00000000,
  384. (0x0400 << 16) | (0xc7a8 >> 2),
  385. 0x00000000,
  386. (0x0400 << 16) | (0xc7ac >> 2),
  387. 0x00000000,
  388. (0x0400 << 16) | (0xc7b0 >> 2),
  389. 0x00000000,
  390. (0x0400 << 16) | (0xc7b4 >> 2),
  391. 0x00000000,
  392. (0x0e00 << 16) | (0x9100 >> 2),
  393. 0x00000000,
  394. (0x0e00 << 16) | (0x3c010 >> 2),
  395. 0x00000000,
  396. (0x0e00 << 16) | (0x92a8 >> 2),
  397. 0x00000000,
  398. (0x0e00 << 16) | (0x92ac >> 2),
  399. 0x00000000,
  400. (0x0e00 << 16) | (0x92b4 >> 2),
  401. 0x00000000,
  402. (0x0e00 << 16) | (0x92b8 >> 2),
  403. 0x00000000,
  404. (0x0e00 << 16) | (0x92bc >> 2),
  405. 0x00000000,
  406. (0x0e00 << 16) | (0x92c0 >> 2),
  407. 0x00000000,
  408. (0x0e00 << 16) | (0x92c4 >> 2),
  409. 0x00000000,
  410. (0x0e00 << 16) | (0x92c8 >> 2),
  411. 0x00000000,
  412. (0x0e00 << 16) | (0x92cc >> 2),
  413. 0x00000000,
  414. (0x0e00 << 16) | (0x92d0 >> 2),
  415. 0x00000000,
  416. (0x0e00 << 16) | (0x8c00 >> 2),
  417. 0x00000000,
  418. (0x0e00 << 16) | (0x8c04 >> 2),
  419. 0x00000000,
  420. (0x0e00 << 16) | (0x8c20 >> 2),
  421. 0x00000000,
  422. (0x0e00 << 16) | (0x8c38 >> 2),
  423. 0x00000000,
  424. (0x0e00 << 16) | (0x8c3c >> 2),
  425. 0x00000000,
  426. (0x0e00 << 16) | (0xae00 >> 2),
  427. 0x00000000,
  428. (0x0e00 << 16) | (0x9604 >> 2),
  429. 0x00000000,
  430. (0x0e00 << 16) | (0xac08 >> 2),
  431. 0x00000000,
  432. (0x0e00 << 16) | (0xac0c >> 2),
  433. 0x00000000,
  434. (0x0e00 << 16) | (0xac10 >> 2),
  435. 0x00000000,
  436. (0x0e00 << 16) | (0xac14 >> 2),
  437. 0x00000000,
  438. (0x0e00 << 16) | (0xac58 >> 2),
  439. 0x00000000,
  440. (0x0e00 << 16) | (0xac68 >> 2),
  441. 0x00000000,
  442. (0x0e00 << 16) | (0xac6c >> 2),
  443. 0x00000000,
  444. (0x0e00 << 16) | (0xac70 >> 2),
  445. 0x00000000,
  446. (0x0e00 << 16) | (0xac74 >> 2),
  447. 0x00000000,
  448. (0x0e00 << 16) | (0xac78 >> 2),
  449. 0x00000000,
  450. (0x0e00 << 16) | (0xac7c >> 2),
  451. 0x00000000,
  452. (0x0e00 << 16) | (0xac80 >> 2),
  453. 0x00000000,
  454. (0x0e00 << 16) | (0xac84 >> 2),
  455. 0x00000000,
  456. (0x0e00 << 16) | (0xac88 >> 2),
  457. 0x00000000,
  458. (0x0e00 << 16) | (0xac8c >> 2),
  459. 0x00000000,
  460. (0x0e00 << 16) | (0x970c >> 2),
  461. 0x00000000,
  462. (0x0e00 << 16) | (0x9714 >> 2),
  463. 0x00000000,
  464. (0x0e00 << 16) | (0x9718 >> 2),
  465. 0x00000000,
  466. (0x0e00 << 16) | (0x971c >> 2),
  467. 0x00000000,
  468. (0x0e00 << 16) | (0x31068 >> 2),
  469. 0x00000000,
  470. (0x4e00 << 16) | (0x31068 >> 2),
  471. 0x00000000,
  472. (0x5e00 << 16) | (0x31068 >> 2),
  473. 0x00000000,
  474. (0x6e00 << 16) | (0x31068 >> 2),
  475. 0x00000000,
  476. (0x7e00 << 16) | (0x31068 >> 2),
  477. 0x00000000,
  478. (0x8e00 << 16) | (0x31068 >> 2),
  479. 0x00000000,
  480. (0x9e00 << 16) | (0x31068 >> 2),
  481. 0x00000000,
  482. (0xae00 << 16) | (0x31068 >> 2),
  483. 0x00000000,
  484. (0xbe00 << 16) | (0x31068 >> 2),
  485. 0x00000000,
  486. (0x0e00 << 16) | (0xcd10 >> 2),
  487. 0x00000000,
  488. (0x0e00 << 16) | (0xcd14 >> 2),
  489. 0x00000000,
  490. (0x0e00 << 16) | (0x88b0 >> 2),
  491. 0x00000000,
  492. (0x0e00 << 16) | (0x88b4 >> 2),
  493. 0x00000000,
  494. (0x0e00 << 16) | (0x88b8 >> 2),
  495. 0x00000000,
  496. (0x0e00 << 16) | (0x88bc >> 2),
  497. 0x00000000,
  498. (0x0400 << 16) | (0x89c0 >> 2),
  499. 0x00000000,
  500. (0x0e00 << 16) | (0x88c4 >> 2),
  501. 0x00000000,
  502. (0x0e00 << 16) | (0x88c8 >> 2),
  503. 0x00000000,
  504. (0x0e00 << 16) | (0x88d0 >> 2),
  505. 0x00000000,
  506. (0x0e00 << 16) | (0x88d4 >> 2),
  507. 0x00000000,
  508. (0x0e00 << 16) | (0x88d8 >> 2),
  509. 0x00000000,
  510. (0x0e00 << 16) | (0x8980 >> 2),
  511. 0x00000000,
  512. (0x0e00 << 16) | (0x30938 >> 2),
  513. 0x00000000,
  514. (0x0e00 << 16) | (0x3093c >> 2),
  515. 0x00000000,
  516. (0x0e00 << 16) | (0x30940 >> 2),
  517. 0x00000000,
  518. (0x0e00 << 16) | (0x89a0 >> 2),
  519. 0x00000000,
  520. (0x0e00 << 16) | (0x30900 >> 2),
  521. 0x00000000,
  522. (0x0e00 << 16) | (0x30904 >> 2),
  523. 0x00000000,
  524. (0x0e00 << 16) | (0x89b4 >> 2),
  525. 0x00000000,
  526. (0x0e00 << 16) | (0x3c210 >> 2),
  527. 0x00000000,
  528. (0x0e00 << 16) | (0x3c214 >> 2),
  529. 0x00000000,
  530. (0x0e00 << 16) | (0x3c218 >> 2),
  531. 0x00000000,
  532. (0x0e00 << 16) | (0x8904 >> 2),
  533. 0x00000000,
  534. 0x5,
  535. (0x0e00 << 16) | (0x8c28 >> 2),
  536. (0x0e00 << 16) | (0x8c2c >> 2),
  537. (0x0e00 << 16) | (0x8c30 >> 2),
  538. (0x0e00 << 16) | (0x8c34 >> 2),
  539. (0x0e00 << 16) | (0x9600 >> 2),
  540. };
  541. static const u32 kalindi_rlc_save_restore_register_list[] =
  542. {
  543. (0x0e00 << 16) | (0xc12c >> 2),
  544. 0x00000000,
  545. (0x0e00 << 16) | (0xc140 >> 2),
  546. 0x00000000,
  547. (0x0e00 << 16) | (0xc150 >> 2),
  548. 0x00000000,
  549. (0x0e00 << 16) | (0xc15c >> 2),
  550. 0x00000000,
  551. (0x0e00 << 16) | (0xc168 >> 2),
  552. 0x00000000,
  553. (0x0e00 << 16) | (0xc170 >> 2),
  554. 0x00000000,
  555. (0x0e00 << 16) | (0xc204 >> 2),
  556. 0x00000000,
  557. (0x0e00 << 16) | (0xc2b4 >> 2),
  558. 0x00000000,
  559. (0x0e00 << 16) | (0xc2b8 >> 2),
  560. 0x00000000,
  561. (0x0e00 << 16) | (0xc2bc >> 2),
  562. 0x00000000,
  563. (0x0e00 << 16) | (0xc2c0 >> 2),
  564. 0x00000000,
  565. (0x0e00 << 16) | (0x8228 >> 2),
  566. 0x00000000,
  567. (0x0e00 << 16) | (0x829c >> 2),
  568. 0x00000000,
  569. (0x0e00 << 16) | (0x869c >> 2),
  570. 0x00000000,
  571. (0x0600 << 16) | (0x98f4 >> 2),
  572. 0x00000000,
  573. (0x0e00 << 16) | (0x98f8 >> 2),
  574. 0x00000000,
  575. (0x0e00 << 16) | (0x9900 >> 2),
  576. 0x00000000,
  577. (0x0e00 << 16) | (0xc260 >> 2),
  578. 0x00000000,
  579. (0x0e00 << 16) | (0x90e8 >> 2),
  580. 0x00000000,
  581. (0x0e00 << 16) | (0x3c000 >> 2),
  582. 0x00000000,
  583. (0x0e00 << 16) | (0x3c00c >> 2),
  584. 0x00000000,
  585. (0x0e00 << 16) | (0x8c1c >> 2),
  586. 0x00000000,
  587. (0x0e00 << 16) | (0x9700 >> 2),
  588. 0x00000000,
  589. (0x0e00 << 16) | (0xcd20 >> 2),
  590. 0x00000000,
  591. (0x4e00 << 16) | (0xcd20 >> 2),
  592. 0x00000000,
  593. (0x5e00 << 16) | (0xcd20 >> 2),
  594. 0x00000000,
  595. (0x6e00 << 16) | (0xcd20 >> 2),
  596. 0x00000000,
  597. (0x7e00 << 16) | (0xcd20 >> 2),
  598. 0x00000000,
  599. (0x0e00 << 16) | (0x89bc >> 2),
  600. 0x00000000,
  601. (0x0e00 << 16) | (0x8900 >> 2),
  602. 0x00000000,
  603. 0x3,
  604. (0x0e00 << 16) | (0xc130 >> 2),
  605. 0x00000000,
  606. (0x0e00 << 16) | (0xc134 >> 2),
  607. 0x00000000,
  608. (0x0e00 << 16) | (0xc1fc >> 2),
  609. 0x00000000,
  610. (0x0e00 << 16) | (0xc208 >> 2),
  611. 0x00000000,
  612. (0x0e00 << 16) | (0xc264 >> 2),
  613. 0x00000000,
  614. (0x0e00 << 16) | (0xc268 >> 2),
  615. 0x00000000,
  616. (0x0e00 << 16) | (0xc26c >> 2),
  617. 0x00000000,
  618. (0x0e00 << 16) | (0xc270 >> 2),
  619. 0x00000000,
  620. (0x0e00 << 16) | (0xc274 >> 2),
  621. 0x00000000,
  622. (0x0e00 << 16) | (0xc28c >> 2),
  623. 0x00000000,
  624. (0x0e00 << 16) | (0xc290 >> 2),
  625. 0x00000000,
  626. (0x0e00 << 16) | (0xc294 >> 2),
  627. 0x00000000,
  628. (0x0e00 << 16) | (0xc298 >> 2),
  629. 0x00000000,
  630. (0x0e00 << 16) | (0xc2a0 >> 2),
  631. 0x00000000,
  632. (0x0e00 << 16) | (0xc2a4 >> 2),
  633. 0x00000000,
  634. (0x0e00 << 16) | (0xc2a8 >> 2),
  635. 0x00000000,
  636. (0x0e00 << 16) | (0xc2ac >> 2),
  637. 0x00000000,
  638. (0x0e00 << 16) | (0x301d0 >> 2),
  639. 0x00000000,
  640. (0x0e00 << 16) | (0x30238 >> 2),
  641. 0x00000000,
  642. (0x0e00 << 16) | (0x30250 >> 2),
  643. 0x00000000,
  644. (0x0e00 << 16) | (0x30254 >> 2),
  645. 0x00000000,
  646. (0x0e00 << 16) | (0x30258 >> 2),
  647. 0x00000000,
  648. (0x0e00 << 16) | (0x3025c >> 2),
  649. 0x00000000,
  650. (0x4e00 << 16) | (0xc900 >> 2),
  651. 0x00000000,
  652. (0x5e00 << 16) | (0xc900 >> 2),
  653. 0x00000000,
  654. (0x6e00 << 16) | (0xc900 >> 2),
  655. 0x00000000,
  656. (0x7e00 << 16) | (0xc900 >> 2),
  657. 0x00000000,
  658. (0x4e00 << 16) | (0xc904 >> 2),
  659. 0x00000000,
  660. (0x5e00 << 16) | (0xc904 >> 2),
  661. 0x00000000,
  662. (0x6e00 << 16) | (0xc904 >> 2),
  663. 0x00000000,
  664. (0x7e00 << 16) | (0xc904 >> 2),
  665. 0x00000000,
  666. (0x4e00 << 16) | (0xc908 >> 2),
  667. 0x00000000,
  668. (0x5e00 << 16) | (0xc908 >> 2),
  669. 0x00000000,
  670. (0x6e00 << 16) | (0xc908 >> 2),
  671. 0x00000000,
  672. (0x7e00 << 16) | (0xc908 >> 2),
  673. 0x00000000,
  674. (0x4e00 << 16) | (0xc90c >> 2),
  675. 0x00000000,
  676. (0x5e00 << 16) | (0xc90c >> 2),
  677. 0x00000000,
  678. (0x6e00 << 16) | (0xc90c >> 2),
  679. 0x00000000,
  680. (0x7e00 << 16) | (0xc90c >> 2),
  681. 0x00000000,
  682. (0x4e00 << 16) | (0xc910 >> 2),
  683. 0x00000000,
  684. (0x5e00 << 16) | (0xc910 >> 2),
  685. 0x00000000,
  686. (0x6e00 << 16) | (0xc910 >> 2),
  687. 0x00000000,
  688. (0x7e00 << 16) | (0xc910 >> 2),
  689. 0x00000000,
  690. (0x0e00 << 16) | (0xc99c >> 2),
  691. 0x00000000,
  692. (0x0e00 << 16) | (0x9834 >> 2),
  693. 0x00000000,
  694. (0x0000 << 16) | (0x30f00 >> 2),
  695. 0x00000000,
  696. (0x0000 << 16) | (0x30f04 >> 2),
  697. 0x00000000,
  698. (0x0000 << 16) | (0x30f08 >> 2),
  699. 0x00000000,
  700. (0x0000 << 16) | (0x30f0c >> 2),
  701. 0x00000000,
  702. (0x0600 << 16) | (0x9b7c >> 2),
  703. 0x00000000,
  704. (0x0e00 << 16) | (0x8a14 >> 2),
  705. 0x00000000,
  706. (0x0e00 << 16) | (0x8a18 >> 2),
  707. 0x00000000,
  708. (0x0600 << 16) | (0x30a00 >> 2),
  709. 0x00000000,
  710. (0x0e00 << 16) | (0x8bf0 >> 2),
  711. 0x00000000,
  712. (0x0e00 << 16) | (0x8bcc >> 2),
  713. 0x00000000,
  714. (0x0e00 << 16) | (0x8b24 >> 2),
  715. 0x00000000,
  716. (0x0e00 << 16) | (0x30a04 >> 2),
  717. 0x00000000,
  718. (0x0600 << 16) | (0x30a10 >> 2),
  719. 0x00000000,
  720. (0x0600 << 16) | (0x30a14 >> 2),
  721. 0x00000000,
  722. (0x0600 << 16) | (0x30a18 >> 2),
  723. 0x00000000,
  724. (0x0600 << 16) | (0x30a2c >> 2),
  725. 0x00000000,
  726. (0x0e00 << 16) | (0xc700 >> 2),
  727. 0x00000000,
  728. (0x0e00 << 16) | (0xc704 >> 2),
  729. 0x00000000,
  730. (0x0e00 << 16) | (0xc708 >> 2),
  731. 0x00000000,
  732. (0x0e00 << 16) | (0xc768 >> 2),
  733. 0x00000000,
  734. (0x0400 << 16) | (0xc770 >> 2),
  735. 0x00000000,
  736. (0x0400 << 16) | (0xc774 >> 2),
  737. 0x00000000,
  738. (0x0400 << 16) | (0xc798 >> 2),
  739. 0x00000000,
  740. (0x0400 << 16) | (0xc79c >> 2),
  741. 0x00000000,
  742. (0x0e00 << 16) | (0x9100 >> 2),
  743. 0x00000000,
  744. (0x0e00 << 16) | (0x3c010 >> 2),
  745. 0x00000000,
  746. (0x0e00 << 16) | (0x8c00 >> 2),
  747. 0x00000000,
  748. (0x0e00 << 16) | (0x8c04 >> 2),
  749. 0x00000000,
  750. (0x0e00 << 16) | (0x8c20 >> 2),
  751. 0x00000000,
  752. (0x0e00 << 16) | (0x8c38 >> 2),
  753. 0x00000000,
  754. (0x0e00 << 16) | (0x8c3c >> 2),
  755. 0x00000000,
  756. (0x0e00 << 16) | (0xae00 >> 2),
  757. 0x00000000,
  758. (0x0e00 << 16) | (0x9604 >> 2),
  759. 0x00000000,
  760. (0x0e00 << 16) | (0xac08 >> 2),
  761. 0x00000000,
  762. (0x0e00 << 16) | (0xac0c >> 2),
  763. 0x00000000,
  764. (0x0e00 << 16) | (0xac10 >> 2),
  765. 0x00000000,
  766. (0x0e00 << 16) | (0xac14 >> 2),
  767. 0x00000000,
  768. (0x0e00 << 16) | (0xac58 >> 2),
  769. 0x00000000,
  770. (0x0e00 << 16) | (0xac68 >> 2),
  771. 0x00000000,
  772. (0x0e00 << 16) | (0xac6c >> 2),
  773. 0x00000000,
  774. (0x0e00 << 16) | (0xac70 >> 2),
  775. 0x00000000,
  776. (0x0e00 << 16) | (0xac74 >> 2),
  777. 0x00000000,
  778. (0x0e00 << 16) | (0xac78 >> 2),
  779. 0x00000000,
  780. (0x0e00 << 16) | (0xac7c >> 2),
  781. 0x00000000,
  782. (0x0e00 << 16) | (0xac80 >> 2),
  783. 0x00000000,
  784. (0x0e00 << 16) | (0xac84 >> 2),
  785. 0x00000000,
  786. (0x0e00 << 16) | (0xac88 >> 2),
  787. 0x00000000,
  788. (0x0e00 << 16) | (0xac8c >> 2),
  789. 0x00000000,
  790. (0x0e00 << 16) | (0x970c >> 2),
  791. 0x00000000,
  792. (0x0e00 << 16) | (0x9714 >> 2),
  793. 0x00000000,
  794. (0x0e00 << 16) | (0x9718 >> 2),
  795. 0x00000000,
  796. (0x0e00 << 16) | (0x971c >> 2),
  797. 0x00000000,
  798. (0x0e00 << 16) | (0x31068 >> 2),
  799. 0x00000000,
  800. (0x4e00 << 16) | (0x31068 >> 2),
  801. 0x00000000,
  802. (0x5e00 << 16) | (0x31068 >> 2),
  803. 0x00000000,
  804. (0x6e00 << 16) | (0x31068 >> 2),
  805. 0x00000000,
  806. (0x7e00 << 16) | (0x31068 >> 2),
  807. 0x00000000,
  808. (0x0e00 << 16) | (0xcd10 >> 2),
  809. 0x00000000,
  810. (0x0e00 << 16) | (0xcd14 >> 2),
  811. 0x00000000,
  812. (0x0e00 << 16) | (0x88b0 >> 2),
  813. 0x00000000,
  814. (0x0e00 << 16) | (0x88b4 >> 2),
  815. 0x00000000,
  816. (0x0e00 << 16) | (0x88b8 >> 2),
  817. 0x00000000,
  818. (0x0e00 << 16) | (0x88bc >> 2),
  819. 0x00000000,
  820. (0x0400 << 16) | (0x89c0 >> 2),
  821. 0x00000000,
  822. (0x0e00 << 16) | (0x88c4 >> 2),
  823. 0x00000000,
  824. (0x0e00 << 16) | (0x88c8 >> 2),
  825. 0x00000000,
  826. (0x0e00 << 16) | (0x88d0 >> 2),
  827. 0x00000000,
  828. (0x0e00 << 16) | (0x88d4 >> 2),
  829. 0x00000000,
  830. (0x0e00 << 16) | (0x88d8 >> 2),
  831. 0x00000000,
  832. (0x0e00 << 16) | (0x8980 >> 2),
  833. 0x00000000,
  834. (0x0e00 << 16) | (0x30938 >> 2),
  835. 0x00000000,
  836. (0x0e00 << 16) | (0x3093c >> 2),
  837. 0x00000000,
  838. (0x0e00 << 16) | (0x30940 >> 2),
  839. 0x00000000,
  840. (0x0e00 << 16) | (0x89a0 >> 2),
  841. 0x00000000,
  842. (0x0e00 << 16) | (0x30900 >> 2),
  843. 0x00000000,
  844. (0x0e00 << 16) | (0x30904 >> 2),
  845. 0x00000000,
  846. (0x0e00 << 16) | (0x89b4 >> 2),
  847. 0x00000000,
  848. (0x0e00 << 16) | (0x3e1fc >> 2),
  849. 0x00000000,
  850. (0x0e00 << 16) | (0x3c210 >> 2),
  851. 0x00000000,
  852. (0x0e00 << 16) | (0x3c214 >> 2),
  853. 0x00000000,
  854. (0x0e00 << 16) | (0x3c218 >> 2),
  855. 0x00000000,
  856. (0x0e00 << 16) | (0x8904 >> 2),
  857. 0x00000000,
  858. 0x5,
  859. (0x0e00 << 16) | (0x8c28 >> 2),
  860. (0x0e00 << 16) | (0x8c2c >> 2),
  861. (0x0e00 << 16) | (0x8c30 >> 2),
  862. (0x0e00 << 16) | (0x8c34 >> 2),
  863. (0x0e00 << 16) | (0x9600 >> 2),
  864. };
  865. static u32 gfx_v7_0_get_csb_size(struct amdgpu_device *adev);
  866. static void gfx_v7_0_get_csb_buffer(struct amdgpu_device *adev, volatile u32 *buffer);
  867. static void gfx_v7_0_init_cp_pg_table(struct amdgpu_device *adev);
  868. static void gfx_v7_0_init_pg(struct amdgpu_device *adev);
  869. static void gfx_v7_0_get_cu_info(struct amdgpu_device *adev);
  870. /*
  871. * Core functions
  872. */
  873. /**
  874. * gfx_v7_0_init_microcode - load ucode images from disk
  875. *
  876. * @adev: amdgpu_device pointer
  877. *
  878. * Use the firmware interface to load the ucode images into
  879. * the driver (not loaded into hw).
  880. * Returns 0 on success, error on failure.
  881. */
  882. static int gfx_v7_0_init_microcode(struct amdgpu_device *adev)
  883. {
  884. const char *chip_name;
  885. char fw_name[30];
  886. int err;
  887. DRM_DEBUG("\n");
  888. switch (adev->asic_type) {
  889. case CHIP_BONAIRE:
  890. chip_name = "bonaire";
  891. break;
  892. case CHIP_HAWAII:
  893. chip_name = "hawaii";
  894. break;
  895. case CHIP_KAVERI:
  896. chip_name = "kaveri";
  897. break;
  898. case CHIP_KABINI:
  899. chip_name = "kabini";
  900. break;
  901. case CHIP_MULLINS:
  902. chip_name = "mullins";
  903. break;
  904. default: BUG();
  905. }
  906. snprintf(fw_name, sizeof(fw_name), "radeon/%s_pfp.bin", chip_name);
  907. err = request_firmware(&adev->gfx.pfp_fw, fw_name, adev->dev);
  908. if (err)
  909. goto out;
  910. err = amdgpu_ucode_validate(adev->gfx.pfp_fw);
  911. if (err)
  912. goto out;
  913. snprintf(fw_name, sizeof(fw_name), "radeon/%s_me.bin", chip_name);
  914. err = request_firmware(&adev->gfx.me_fw, fw_name, adev->dev);
  915. if (err)
  916. goto out;
  917. err = amdgpu_ucode_validate(adev->gfx.me_fw);
  918. if (err)
  919. goto out;
  920. snprintf(fw_name, sizeof(fw_name), "radeon/%s_ce.bin", chip_name);
  921. err = request_firmware(&adev->gfx.ce_fw, fw_name, adev->dev);
  922. if (err)
  923. goto out;
  924. err = amdgpu_ucode_validate(adev->gfx.ce_fw);
  925. if (err)
  926. goto out;
  927. snprintf(fw_name, sizeof(fw_name), "radeon/%s_mec.bin", chip_name);
  928. err = request_firmware(&adev->gfx.mec_fw, fw_name, adev->dev);
  929. if (err)
  930. goto out;
  931. err = amdgpu_ucode_validate(adev->gfx.mec_fw);
  932. if (err)
  933. goto out;
  934. if (adev->asic_type == CHIP_KAVERI) {
  935. snprintf(fw_name, sizeof(fw_name), "radeon/%s_mec2.bin", chip_name);
  936. err = request_firmware(&adev->gfx.mec2_fw, fw_name, adev->dev);
  937. if (err)
  938. goto out;
  939. err = amdgpu_ucode_validate(adev->gfx.mec2_fw);
  940. if (err)
  941. goto out;
  942. }
  943. snprintf(fw_name, sizeof(fw_name), "radeon/%s_rlc.bin", chip_name);
  944. err = request_firmware(&adev->gfx.rlc_fw, fw_name, adev->dev);
  945. if (err)
  946. goto out;
  947. err = amdgpu_ucode_validate(adev->gfx.rlc_fw);
  948. out:
  949. if (err) {
  950. pr_err("gfx7: Failed to load firmware \"%s\"\n", fw_name);
  951. release_firmware(adev->gfx.pfp_fw);
  952. adev->gfx.pfp_fw = NULL;
  953. release_firmware(adev->gfx.me_fw);
  954. adev->gfx.me_fw = NULL;
  955. release_firmware(adev->gfx.ce_fw);
  956. adev->gfx.ce_fw = NULL;
  957. release_firmware(adev->gfx.mec_fw);
  958. adev->gfx.mec_fw = NULL;
  959. release_firmware(adev->gfx.mec2_fw);
  960. adev->gfx.mec2_fw = NULL;
  961. release_firmware(adev->gfx.rlc_fw);
  962. adev->gfx.rlc_fw = NULL;
  963. }
  964. return err;
  965. }
  966. static void gfx_v7_0_free_microcode(struct amdgpu_device *adev)
  967. {
  968. release_firmware(adev->gfx.pfp_fw);
  969. adev->gfx.pfp_fw = NULL;
  970. release_firmware(adev->gfx.me_fw);
  971. adev->gfx.me_fw = NULL;
  972. release_firmware(adev->gfx.ce_fw);
  973. adev->gfx.ce_fw = NULL;
  974. release_firmware(adev->gfx.mec_fw);
  975. adev->gfx.mec_fw = NULL;
  976. release_firmware(adev->gfx.mec2_fw);
  977. adev->gfx.mec2_fw = NULL;
  978. release_firmware(adev->gfx.rlc_fw);
  979. adev->gfx.rlc_fw = NULL;
  980. }
  981. /**
  982. * gfx_v7_0_tiling_mode_table_init - init the hw tiling table
  983. *
  984. * @adev: amdgpu_device pointer
  985. *
  986. * Starting with SI, the tiling setup is done globally in a
  987. * set of 32 tiling modes. Rather than selecting each set of
  988. * parameters per surface as on older asics, we just select
  989. * which index in the tiling table we want to use, and the
  990. * surface uses those parameters (CIK).
  991. */
  992. static void gfx_v7_0_tiling_mode_table_init(struct amdgpu_device *adev)
  993. {
  994. const u32 num_tile_mode_states =
  995. ARRAY_SIZE(adev->gfx.config.tile_mode_array);
  996. const u32 num_secondary_tile_mode_states =
  997. ARRAY_SIZE(adev->gfx.config.macrotile_mode_array);
  998. u32 reg_offset, split_equal_to_row_size;
  999. uint32_t *tile, *macrotile;
  1000. tile = adev->gfx.config.tile_mode_array;
  1001. macrotile = adev->gfx.config.macrotile_mode_array;
  1002. switch (adev->gfx.config.mem_row_size_in_kb) {
  1003. case 1:
  1004. split_equal_to_row_size = ADDR_SURF_TILE_SPLIT_1KB;
  1005. break;
  1006. case 2:
  1007. default:
  1008. split_equal_to_row_size = ADDR_SURF_TILE_SPLIT_2KB;
  1009. break;
  1010. case 4:
  1011. split_equal_to_row_size = ADDR_SURF_TILE_SPLIT_4KB;
  1012. break;
  1013. }
  1014. for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++)
  1015. tile[reg_offset] = 0;
  1016. for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++)
  1017. macrotile[reg_offset] = 0;
  1018. switch (adev->asic_type) {
  1019. case CHIP_BONAIRE:
  1020. tile[0] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1021. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  1022. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  1023. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  1024. tile[1] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1025. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  1026. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
  1027. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  1028. tile[2] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1029. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  1030. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  1031. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  1032. tile[3] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1033. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  1034. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
  1035. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  1036. tile[4] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1037. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  1038. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  1039. TILE_SPLIT(split_equal_to_row_size));
  1040. tile[5] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  1041. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  1042. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  1043. tile[6] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  1044. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  1045. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  1046. TILE_SPLIT(split_equal_to_row_size));
  1047. tile[7] = (TILE_SPLIT(split_equal_to_row_size));
  1048. tile[8] = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
  1049. PIPE_CONFIG(ADDR_SURF_P4_16x16));
  1050. tile[9] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  1051. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  1052. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING));
  1053. tile[10] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1054. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  1055. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  1056. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  1057. tile[11] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  1058. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  1059. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  1060. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
  1061. tile[12] = (TILE_SPLIT(split_equal_to_row_size));
  1062. tile[13] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  1063. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  1064. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING));
  1065. tile[14] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1066. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  1067. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  1068. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  1069. tile[15] = (ARRAY_MODE(ARRAY_3D_TILED_THIN1) |
  1070. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  1071. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  1072. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  1073. tile[16] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  1074. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  1075. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  1076. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
  1077. tile[17] = (TILE_SPLIT(split_equal_to_row_size));
  1078. tile[18] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
  1079. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  1080. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  1081. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  1082. tile[19] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
  1083. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  1084. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING));
  1085. tile[20] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
  1086. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  1087. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  1088. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  1089. tile[21] = (ARRAY_MODE(ARRAY_3D_TILED_THICK) |
  1090. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  1091. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  1092. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  1093. tile[22] = (ARRAY_MODE(ARRAY_PRT_TILED_THICK) |
  1094. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  1095. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  1096. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  1097. tile[23] = (TILE_SPLIT(split_equal_to_row_size));
  1098. tile[24] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
  1099. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  1100. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  1101. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  1102. tile[25] = (ARRAY_MODE(ARRAY_2D_TILED_XTHICK) |
  1103. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  1104. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  1105. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  1106. tile[26] = (ARRAY_MODE(ARRAY_3D_TILED_XTHICK) |
  1107. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  1108. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  1109. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  1110. tile[27] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  1111. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  1112. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING));
  1113. tile[28] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1114. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  1115. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  1116. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  1117. tile[29] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  1118. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  1119. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  1120. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
  1121. tile[30] = (TILE_SPLIT(split_equal_to_row_size));
  1122. macrotile[0] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1123. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  1124. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  1125. NUM_BANKS(ADDR_SURF_16_BANK));
  1126. macrotile[1] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1127. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  1128. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  1129. NUM_BANKS(ADDR_SURF_16_BANK));
  1130. macrotile[2] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1131. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  1132. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  1133. NUM_BANKS(ADDR_SURF_16_BANK));
  1134. macrotile[3] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1135. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  1136. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  1137. NUM_BANKS(ADDR_SURF_16_BANK));
  1138. macrotile[4] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1139. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  1140. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  1141. NUM_BANKS(ADDR_SURF_16_BANK));
  1142. macrotile[5] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1143. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  1144. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  1145. NUM_BANKS(ADDR_SURF_8_BANK));
  1146. macrotile[6] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1147. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  1148. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  1149. NUM_BANKS(ADDR_SURF_4_BANK));
  1150. macrotile[8] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
  1151. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
  1152. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  1153. NUM_BANKS(ADDR_SURF_16_BANK));
  1154. macrotile[9] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
  1155. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  1156. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  1157. NUM_BANKS(ADDR_SURF_16_BANK));
  1158. macrotile[10] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1159. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  1160. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  1161. NUM_BANKS(ADDR_SURF_16_BANK));
  1162. macrotile[11] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1163. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  1164. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  1165. NUM_BANKS(ADDR_SURF_16_BANK));
  1166. macrotile[12] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1167. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  1168. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  1169. NUM_BANKS(ADDR_SURF_16_BANK));
  1170. macrotile[13] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1171. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  1172. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  1173. NUM_BANKS(ADDR_SURF_8_BANK));
  1174. macrotile[14] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1175. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  1176. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  1177. NUM_BANKS(ADDR_SURF_4_BANK));
  1178. for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++)
  1179. WREG32(mmGB_TILE_MODE0 + reg_offset, tile[reg_offset]);
  1180. for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++)
  1181. if (reg_offset != 7)
  1182. WREG32(mmGB_MACROTILE_MODE0 + reg_offset, macrotile[reg_offset]);
  1183. break;
  1184. case CHIP_HAWAII:
  1185. tile[0] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1186. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  1187. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  1188. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  1189. tile[1] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1190. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  1191. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
  1192. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  1193. tile[2] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1194. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  1195. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  1196. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  1197. tile[3] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1198. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  1199. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
  1200. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  1201. tile[4] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1202. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  1203. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  1204. TILE_SPLIT(split_equal_to_row_size));
  1205. tile[5] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  1206. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  1207. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  1208. TILE_SPLIT(split_equal_to_row_size));
  1209. tile[6] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  1210. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  1211. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  1212. TILE_SPLIT(split_equal_to_row_size));
  1213. tile[7] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  1214. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  1215. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  1216. TILE_SPLIT(split_equal_to_row_size));
  1217. tile[8] = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
  1218. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16));
  1219. tile[9] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  1220. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  1221. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING));
  1222. tile[10] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1223. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  1224. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  1225. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  1226. tile[11] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  1227. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  1228. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  1229. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
  1230. tile[12] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
  1231. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  1232. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  1233. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
  1234. tile[13] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  1235. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  1236. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING));
  1237. tile[14] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1238. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  1239. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  1240. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  1241. tile[15] = (ARRAY_MODE(ARRAY_3D_TILED_THIN1) |
  1242. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  1243. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  1244. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  1245. tile[16] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  1246. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  1247. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  1248. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
  1249. tile[17] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  1250. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  1251. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  1252. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
  1253. tile[18] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
  1254. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  1255. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  1256. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  1257. tile[19] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
  1258. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  1259. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING));
  1260. tile[20] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
  1261. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  1262. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  1263. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  1264. tile[21] = (ARRAY_MODE(ARRAY_3D_TILED_THICK) |
  1265. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  1266. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  1267. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  1268. tile[22] = (ARRAY_MODE(ARRAY_PRT_TILED_THICK) |
  1269. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  1270. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  1271. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  1272. tile[23] = (ARRAY_MODE(ARRAY_PRT_TILED_THICK) |
  1273. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  1274. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  1275. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  1276. tile[24] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
  1277. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  1278. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  1279. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  1280. tile[25] = (ARRAY_MODE(ARRAY_2D_TILED_XTHICK) |
  1281. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  1282. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  1283. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  1284. tile[26] = (ARRAY_MODE(ARRAY_3D_TILED_XTHICK) |
  1285. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  1286. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  1287. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  1288. tile[27] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  1289. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  1290. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING));
  1291. tile[28] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1292. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  1293. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  1294. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  1295. tile[29] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  1296. PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
  1297. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  1298. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
  1299. tile[30] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  1300. PIPE_CONFIG(ADDR_SURF_P4_16x16) |
  1301. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  1302. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
  1303. macrotile[0] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1304. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  1305. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  1306. NUM_BANKS(ADDR_SURF_16_BANK));
  1307. macrotile[1] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1308. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  1309. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  1310. NUM_BANKS(ADDR_SURF_16_BANK));
  1311. macrotile[2] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1312. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  1313. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  1314. NUM_BANKS(ADDR_SURF_16_BANK));
  1315. macrotile[3] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1316. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  1317. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  1318. NUM_BANKS(ADDR_SURF_16_BANK));
  1319. macrotile[4] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1320. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  1321. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  1322. NUM_BANKS(ADDR_SURF_8_BANK));
  1323. macrotile[5] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1324. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  1325. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  1326. NUM_BANKS(ADDR_SURF_4_BANK));
  1327. macrotile[6] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1328. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  1329. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  1330. NUM_BANKS(ADDR_SURF_4_BANK));
  1331. macrotile[8] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1332. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  1333. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  1334. NUM_BANKS(ADDR_SURF_16_BANK));
  1335. macrotile[9] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1336. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  1337. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  1338. NUM_BANKS(ADDR_SURF_16_BANK));
  1339. macrotile[10] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1340. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  1341. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  1342. NUM_BANKS(ADDR_SURF_16_BANK));
  1343. macrotile[11] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1344. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  1345. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  1346. NUM_BANKS(ADDR_SURF_8_BANK));
  1347. macrotile[12] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1348. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  1349. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  1350. NUM_BANKS(ADDR_SURF_16_BANK));
  1351. macrotile[13] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1352. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  1353. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  1354. NUM_BANKS(ADDR_SURF_8_BANK));
  1355. macrotile[14] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1356. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  1357. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
  1358. NUM_BANKS(ADDR_SURF_4_BANK));
  1359. for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++)
  1360. WREG32(mmGB_TILE_MODE0 + reg_offset, tile[reg_offset]);
  1361. for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++)
  1362. if (reg_offset != 7)
  1363. WREG32(mmGB_MACROTILE_MODE0 + reg_offset, macrotile[reg_offset]);
  1364. break;
  1365. case CHIP_KABINI:
  1366. case CHIP_KAVERI:
  1367. case CHIP_MULLINS:
  1368. default:
  1369. tile[0] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1370. PIPE_CONFIG(ADDR_SURF_P2) |
  1371. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
  1372. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  1373. tile[1] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1374. PIPE_CONFIG(ADDR_SURF_P2) |
  1375. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
  1376. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  1377. tile[2] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1378. PIPE_CONFIG(ADDR_SURF_P2) |
  1379. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
  1380. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  1381. tile[3] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1382. PIPE_CONFIG(ADDR_SURF_P2) |
  1383. TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
  1384. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  1385. tile[4] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1386. PIPE_CONFIG(ADDR_SURF_P2) |
  1387. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  1388. TILE_SPLIT(split_equal_to_row_size));
  1389. tile[5] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  1390. PIPE_CONFIG(ADDR_SURF_P2) |
  1391. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
  1392. tile[6] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  1393. PIPE_CONFIG(ADDR_SURF_P2) |
  1394. MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
  1395. TILE_SPLIT(split_equal_to_row_size));
  1396. tile[7] = (TILE_SPLIT(split_equal_to_row_size));
  1397. tile[8] = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
  1398. PIPE_CONFIG(ADDR_SURF_P2));
  1399. tile[9] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  1400. PIPE_CONFIG(ADDR_SURF_P2) |
  1401. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING));
  1402. tile[10] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1403. PIPE_CONFIG(ADDR_SURF_P2) |
  1404. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  1405. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  1406. tile[11] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  1407. PIPE_CONFIG(ADDR_SURF_P2) |
  1408. MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
  1409. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
  1410. tile[12] = (TILE_SPLIT(split_equal_to_row_size));
  1411. tile[13] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  1412. PIPE_CONFIG(ADDR_SURF_P2) |
  1413. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING));
  1414. tile[14] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1415. PIPE_CONFIG(ADDR_SURF_P2) |
  1416. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  1417. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  1418. tile[15] = (ARRAY_MODE(ARRAY_3D_TILED_THIN1) |
  1419. PIPE_CONFIG(ADDR_SURF_P2) |
  1420. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  1421. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  1422. tile[16] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  1423. PIPE_CONFIG(ADDR_SURF_P2) |
  1424. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  1425. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
  1426. tile[17] = (TILE_SPLIT(split_equal_to_row_size));
  1427. tile[18] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
  1428. PIPE_CONFIG(ADDR_SURF_P2) |
  1429. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  1430. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  1431. tile[19] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
  1432. PIPE_CONFIG(ADDR_SURF_P2) |
  1433. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING));
  1434. tile[20] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
  1435. PIPE_CONFIG(ADDR_SURF_P2) |
  1436. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  1437. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  1438. tile[21] = (ARRAY_MODE(ARRAY_3D_TILED_THICK) |
  1439. PIPE_CONFIG(ADDR_SURF_P2) |
  1440. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  1441. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  1442. tile[22] = (ARRAY_MODE(ARRAY_PRT_TILED_THICK) |
  1443. PIPE_CONFIG(ADDR_SURF_P2) |
  1444. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  1445. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  1446. tile[23] = (TILE_SPLIT(split_equal_to_row_size));
  1447. tile[24] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
  1448. PIPE_CONFIG(ADDR_SURF_P2) |
  1449. MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
  1450. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  1451. tile[25] = (ARRAY_MODE(ARRAY_2D_TILED_XTHICK) |
  1452. PIPE_CONFIG(ADDR_SURF_P2) |
  1453. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  1454. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  1455. tile[26] = (ARRAY_MODE(ARRAY_3D_TILED_XTHICK) |
  1456. PIPE_CONFIG(ADDR_SURF_P2) |
  1457. MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
  1458. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
  1459. tile[27] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
  1460. PIPE_CONFIG(ADDR_SURF_P2) |
  1461. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING));
  1462. tile[28] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
  1463. PIPE_CONFIG(ADDR_SURF_P2) |
  1464. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  1465. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
  1466. tile[29] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
  1467. PIPE_CONFIG(ADDR_SURF_P2) |
  1468. MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
  1469. SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
  1470. tile[30] = (TILE_SPLIT(split_equal_to_row_size));
  1471. macrotile[0] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1472. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  1473. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  1474. NUM_BANKS(ADDR_SURF_8_BANK));
  1475. macrotile[1] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1476. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  1477. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  1478. NUM_BANKS(ADDR_SURF_8_BANK));
  1479. macrotile[2] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1480. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  1481. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  1482. NUM_BANKS(ADDR_SURF_8_BANK));
  1483. macrotile[3] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1484. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  1485. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  1486. NUM_BANKS(ADDR_SURF_8_BANK));
  1487. macrotile[4] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1488. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  1489. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  1490. NUM_BANKS(ADDR_SURF_8_BANK));
  1491. macrotile[5] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1492. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  1493. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  1494. NUM_BANKS(ADDR_SURF_8_BANK));
  1495. macrotile[6] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1496. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  1497. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  1498. NUM_BANKS(ADDR_SURF_8_BANK));
  1499. macrotile[8] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_4) |
  1500. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
  1501. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  1502. NUM_BANKS(ADDR_SURF_16_BANK));
  1503. macrotile[9] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_4) |
  1504. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  1505. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  1506. NUM_BANKS(ADDR_SURF_16_BANK));
  1507. macrotile[10] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
  1508. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
  1509. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  1510. NUM_BANKS(ADDR_SURF_16_BANK));
  1511. macrotile[11] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
  1512. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  1513. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  1514. NUM_BANKS(ADDR_SURF_16_BANK));
  1515. macrotile[12] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1516. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
  1517. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  1518. NUM_BANKS(ADDR_SURF_16_BANK));
  1519. macrotile[13] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1520. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  1521. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
  1522. NUM_BANKS(ADDR_SURF_16_BANK));
  1523. macrotile[14] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
  1524. BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
  1525. MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
  1526. NUM_BANKS(ADDR_SURF_8_BANK));
  1527. for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++)
  1528. WREG32(mmGB_TILE_MODE0 + reg_offset, tile[reg_offset]);
  1529. for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++)
  1530. if (reg_offset != 7)
  1531. WREG32(mmGB_MACROTILE_MODE0 + reg_offset, macrotile[reg_offset]);
  1532. break;
  1533. }
  1534. }
  1535. /**
  1536. * gfx_v7_0_select_se_sh - select which SE, SH to address
  1537. *
  1538. * @adev: amdgpu_device pointer
  1539. * @se_num: shader engine to address
  1540. * @sh_num: sh block to address
  1541. *
  1542. * Select which SE, SH combinations to address. Certain
  1543. * registers are instanced per SE or SH. 0xffffffff means
  1544. * broadcast to all SEs or SHs (CIK).
  1545. */
  1546. static void gfx_v7_0_select_se_sh(struct amdgpu_device *adev,
  1547. u32 se_num, u32 sh_num, u32 instance)
  1548. {
  1549. u32 data;
  1550. if (instance == 0xffffffff)
  1551. data = REG_SET_FIELD(0, GRBM_GFX_INDEX, INSTANCE_BROADCAST_WRITES, 1);
  1552. else
  1553. data = REG_SET_FIELD(0, GRBM_GFX_INDEX, INSTANCE_INDEX, instance);
  1554. if ((se_num == 0xffffffff) && (sh_num == 0xffffffff))
  1555. data |= GRBM_GFX_INDEX__SH_BROADCAST_WRITES_MASK |
  1556. GRBM_GFX_INDEX__SE_BROADCAST_WRITES_MASK;
  1557. else if (se_num == 0xffffffff)
  1558. data |= GRBM_GFX_INDEX__SE_BROADCAST_WRITES_MASK |
  1559. (sh_num << GRBM_GFX_INDEX__SH_INDEX__SHIFT);
  1560. else if (sh_num == 0xffffffff)
  1561. data |= GRBM_GFX_INDEX__SH_BROADCAST_WRITES_MASK |
  1562. (se_num << GRBM_GFX_INDEX__SE_INDEX__SHIFT);
  1563. else
  1564. data |= (sh_num << GRBM_GFX_INDEX__SH_INDEX__SHIFT) |
  1565. (se_num << GRBM_GFX_INDEX__SE_INDEX__SHIFT);
  1566. WREG32(mmGRBM_GFX_INDEX, data);
  1567. }
  1568. /**
  1569. * gfx_v7_0_get_rb_active_bitmap - computes the mask of enabled RBs
  1570. *
  1571. * @adev: amdgpu_device pointer
  1572. *
  1573. * Calculates the bitmask of enabled RBs (CIK).
  1574. * Returns the enabled RB bitmask.
  1575. */
  1576. static u32 gfx_v7_0_get_rb_active_bitmap(struct amdgpu_device *adev)
  1577. {
  1578. u32 data, mask;
  1579. data = RREG32(mmCC_RB_BACKEND_DISABLE);
  1580. data |= RREG32(mmGC_USER_RB_BACKEND_DISABLE);
  1581. data &= CC_RB_BACKEND_DISABLE__BACKEND_DISABLE_MASK;
  1582. data >>= GC_USER_RB_BACKEND_DISABLE__BACKEND_DISABLE__SHIFT;
  1583. mask = amdgpu_gfx_create_bitmask(adev->gfx.config.max_backends_per_se /
  1584. adev->gfx.config.max_sh_per_se);
  1585. return (~data) & mask;
  1586. }
  1587. static void
  1588. gfx_v7_0_raster_config(struct amdgpu_device *adev, u32 *rconf, u32 *rconf1)
  1589. {
  1590. switch (adev->asic_type) {
  1591. case CHIP_BONAIRE:
  1592. *rconf |= RB_MAP_PKR0(2) | RB_XSEL2(1) | SE_MAP(2) |
  1593. SE_XSEL(1) | SE_YSEL(1);
  1594. *rconf1 |= 0x0;
  1595. break;
  1596. case CHIP_HAWAII:
  1597. *rconf |= RB_MAP_PKR0(2) | RB_MAP_PKR1(2) |
  1598. RB_XSEL2(1) | PKR_MAP(2) | PKR_XSEL(1) |
  1599. PKR_YSEL(1) | SE_MAP(2) | SE_XSEL(2) |
  1600. SE_YSEL(3);
  1601. *rconf1 |= SE_PAIR_MAP(2) | SE_PAIR_XSEL(3) |
  1602. SE_PAIR_YSEL(2);
  1603. break;
  1604. case CHIP_KAVERI:
  1605. *rconf |= RB_MAP_PKR0(2);
  1606. *rconf1 |= 0x0;
  1607. break;
  1608. case CHIP_KABINI:
  1609. case CHIP_MULLINS:
  1610. *rconf |= 0x0;
  1611. *rconf1 |= 0x0;
  1612. break;
  1613. default:
  1614. DRM_ERROR("unknown asic: 0x%x\n", adev->asic_type);
  1615. break;
  1616. }
  1617. }
  1618. static void
  1619. gfx_v7_0_write_harvested_raster_configs(struct amdgpu_device *adev,
  1620. u32 raster_config, u32 raster_config_1,
  1621. unsigned rb_mask, unsigned num_rb)
  1622. {
  1623. unsigned sh_per_se = max_t(unsigned, adev->gfx.config.max_sh_per_se, 1);
  1624. unsigned num_se = max_t(unsigned, adev->gfx.config.max_shader_engines, 1);
  1625. unsigned rb_per_pkr = min_t(unsigned, num_rb / num_se / sh_per_se, 2);
  1626. unsigned rb_per_se = num_rb / num_se;
  1627. unsigned se_mask[4];
  1628. unsigned se;
  1629. se_mask[0] = ((1 << rb_per_se) - 1) & rb_mask;
  1630. se_mask[1] = (se_mask[0] << rb_per_se) & rb_mask;
  1631. se_mask[2] = (se_mask[1] << rb_per_se) & rb_mask;
  1632. se_mask[3] = (se_mask[2] << rb_per_se) & rb_mask;
  1633. WARN_ON(!(num_se == 1 || num_se == 2 || num_se == 4));
  1634. WARN_ON(!(sh_per_se == 1 || sh_per_se == 2));
  1635. WARN_ON(!(rb_per_pkr == 1 || rb_per_pkr == 2));
  1636. if ((num_se > 2) && ((!se_mask[0] && !se_mask[1]) ||
  1637. (!se_mask[2] && !se_mask[3]))) {
  1638. raster_config_1 &= ~SE_PAIR_MAP_MASK;
  1639. if (!se_mask[0] && !se_mask[1]) {
  1640. raster_config_1 |=
  1641. SE_PAIR_MAP(RASTER_CONFIG_SE_PAIR_MAP_3);
  1642. } else {
  1643. raster_config_1 |=
  1644. SE_PAIR_MAP(RASTER_CONFIG_SE_PAIR_MAP_0);
  1645. }
  1646. }
  1647. for (se = 0; se < num_se; se++) {
  1648. unsigned raster_config_se = raster_config;
  1649. unsigned pkr0_mask = ((1 << rb_per_pkr) - 1) << (se * rb_per_se);
  1650. unsigned pkr1_mask = pkr0_mask << rb_per_pkr;
  1651. int idx = (se / 2) * 2;
  1652. if ((num_se > 1) && (!se_mask[idx] || !se_mask[idx + 1])) {
  1653. raster_config_se &= ~SE_MAP_MASK;
  1654. if (!se_mask[idx]) {
  1655. raster_config_se |= SE_MAP(RASTER_CONFIG_SE_MAP_3);
  1656. } else {
  1657. raster_config_se |= SE_MAP(RASTER_CONFIG_SE_MAP_0);
  1658. }
  1659. }
  1660. pkr0_mask &= rb_mask;
  1661. pkr1_mask &= rb_mask;
  1662. if (rb_per_se > 2 && (!pkr0_mask || !pkr1_mask)) {
  1663. raster_config_se &= ~PKR_MAP_MASK;
  1664. if (!pkr0_mask) {
  1665. raster_config_se |= PKR_MAP(RASTER_CONFIG_PKR_MAP_3);
  1666. } else {
  1667. raster_config_se |= PKR_MAP(RASTER_CONFIG_PKR_MAP_0);
  1668. }
  1669. }
  1670. if (rb_per_se >= 2) {
  1671. unsigned rb0_mask = 1 << (se * rb_per_se);
  1672. unsigned rb1_mask = rb0_mask << 1;
  1673. rb0_mask &= rb_mask;
  1674. rb1_mask &= rb_mask;
  1675. if (!rb0_mask || !rb1_mask) {
  1676. raster_config_se &= ~RB_MAP_PKR0_MASK;
  1677. if (!rb0_mask) {
  1678. raster_config_se |=
  1679. RB_MAP_PKR0(RASTER_CONFIG_RB_MAP_3);
  1680. } else {
  1681. raster_config_se |=
  1682. RB_MAP_PKR0(RASTER_CONFIG_RB_MAP_0);
  1683. }
  1684. }
  1685. if (rb_per_se > 2) {
  1686. rb0_mask = 1 << (se * rb_per_se + rb_per_pkr);
  1687. rb1_mask = rb0_mask << 1;
  1688. rb0_mask &= rb_mask;
  1689. rb1_mask &= rb_mask;
  1690. if (!rb0_mask || !rb1_mask) {
  1691. raster_config_se &= ~RB_MAP_PKR1_MASK;
  1692. if (!rb0_mask) {
  1693. raster_config_se |=
  1694. RB_MAP_PKR1(RASTER_CONFIG_RB_MAP_3);
  1695. } else {
  1696. raster_config_se |=
  1697. RB_MAP_PKR1(RASTER_CONFIG_RB_MAP_0);
  1698. }
  1699. }
  1700. }
  1701. }
  1702. /* GRBM_GFX_INDEX has a different offset on CI+ */
  1703. gfx_v7_0_select_se_sh(adev, se, 0xffffffff, 0xffffffff);
  1704. WREG32(mmPA_SC_RASTER_CONFIG, raster_config_se);
  1705. WREG32(mmPA_SC_RASTER_CONFIG_1, raster_config_1);
  1706. }
  1707. /* GRBM_GFX_INDEX has a different offset on CI+ */
  1708. gfx_v7_0_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
  1709. }
  1710. /**
  1711. * gfx_v7_0_setup_rb - setup the RBs on the asic
  1712. *
  1713. * @adev: amdgpu_device pointer
  1714. * @se_num: number of SEs (shader engines) for the asic
  1715. * @sh_per_se: number of SH blocks per SE for the asic
  1716. *
  1717. * Configures per-SE/SH RB registers (CIK).
  1718. */
  1719. static void gfx_v7_0_setup_rb(struct amdgpu_device *adev)
  1720. {
  1721. int i, j;
  1722. u32 data;
  1723. u32 raster_config = 0, raster_config_1 = 0;
  1724. u32 active_rbs = 0;
  1725. u32 rb_bitmap_width_per_sh = adev->gfx.config.max_backends_per_se /
  1726. adev->gfx.config.max_sh_per_se;
  1727. unsigned num_rb_pipes;
  1728. mutex_lock(&adev->grbm_idx_mutex);
  1729. for (i = 0; i < adev->gfx.config.max_shader_engines; i++) {
  1730. for (j = 0; j < adev->gfx.config.max_sh_per_se; j++) {
  1731. gfx_v7_0_select_se_sh(adev, i, j, 0xffffffff);
  1732. data = gfx_v7_0_get_rb_active_bitmap(adev);
  1733. active_rbs |= data << ((i * adev->gfx.config.max_sh_per_se + j) *
  1734. rb_bitmap_width_per_sh);
  1735. }
  1736. }
  1737. gfx_v7_0_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
  1738. adev->gfx.config.backend_enable_mask = active_rbs;
  1739. adev->gfx.config.num_rbs = hweight32(active_rbs);
  1740. num_rb_pipes = min_t(unsigned, adev->gfx.config.max_backends_per_se *
  1741. adev->gfx.config.max_shader_engines, 16);
  1742. gfx_v7_0_raster_config(adev, &raster_config, &raster_config_1);
  1743. if (!adev->gfx.config.backend_enable_mask ||
  1744. adev->gfx.config.num_rbs >= num_rb_pipes) {
  1745. WREG32(mmPA_SC_RASTER_CONFIG, raster_config);
  1746. WREG32(mmPA_SC_RASTER_CONFIG_1, raster_config_1);
  1747. } else {
  1748. gfx_v7_0_write_harvested_raster_configs(adev, raster_config, raster_config_1,
  1749. adev->gfx.config.backend_enable_mask,
  1750. num_rb_pipes);
  1751. }
  1752. mutex_unlock(&adev->grbm_idx_mutex);
  1753. }
  1754. /**
  1755. * gfx_v7_0_init_compute_vmid - gart enable
  1756. *
  1757. * @adev: amdgpu_device pointer
  1758. *
  1759. * Initialize compute vmid sh_mem registers
  1760. *
  1761. */
  1762. #define DEFAULT_SH_MEM_BASES (0x6000)
  1763. #define FIRST_COMPUTE_VMID (8)
  1764. #define LAST_COMPUTE_VMID (16)
  1765. static void gfx_v7_0_init_compute_vmid(struct amdgpu_device *adev)
  1766. {
  1767. int i;
  1768. uint32_t sh_mem_config;
  1769. uint32_t sh_mem_bases;
  1770. /*
  1771. * Configure apertures:
  1772. * LDS: 0x60000000'00000000 - 0x60000001'00000000 (4GB)
  1773. * Scratch: 0x60000001'00000000 - 0x60000002'00000000 (4GB)
  1774. * GPUVM: 0x60010000'00000000 - 0x60020000'00000000 (1TB)
  1775. */
  1776. sh_mem_bases = DEFAULT_SH_MEM_BASES | (DEFAULT_SH_MEM_BASES << 16);
  1777. sh_mem_config = SH_MEM_ALIGNMENT_MODE_UNALIGNED <<
  1778. SH_MEM_CONFIG__ALIGNMENT_MODE__SHIFT;
  1779. sh_mem_config |= MTYPE_NONCACHED << SH_MEM_CONFIG__DEFAULT_MTYPE__SHIFT;
  1780. mutex_lock(&adev->srbm_mutex);
  1781. for (i = FIRST_COMPUTE_VMID; i < LAST_COMPUTE_VMID; i++) {
  1782. cik_srbm_select(adev, 0, 0, 0, i);
  1783. /* CP and shaders */
  1784. WREG32(mmSH_MEM_CONFIG, sh_mem_config);
  1785. WREG32(mmSH_MEM_APE1_BASE, 1);
  1786. WREG32(mmSH_MEM_APE1_LIMIT, 0);
  1787. WREG32(mmSH_MEM_BASES, sh_mem_bases);
  1788. }
  1789. cik_srbm_select(adev, 0, 0, 0, 0);
  1790. mutex_unlock(&adev->srbm_mutex);
  1791. }
  1792. static void gfx_v7_0_config_init(struct amdgpu_device *adev)
  1793. {
  1794. adev->gfx.config.double_offchip_lds_buf = 1;
  1795. }
  1796. /**
  1797. * gfx_v7_0_gpu_init - setup the 3D engine
  1798. *
  1799. * @adev: amdgpu_device pointer
  1800. *
  1801. * Configures the 3D engine and tiling configuration
  1802. * registers so that the 3D engine is usable.
  1803. */
  1804. static void gfx_v7_0_gpu_init(struct amdgpu_device *adev)
  1805. {
  1806. u32 sh_mem_cfg, sh_static_mem_cfg, sh_mem_base;
  1807. u32 tmp;
  1808. int i;
  1809. WREG32(mmGRBM_CNTL, (0xff << GRBM_CNTL__READ_TIMEOUT__SHIFT));
  1810. WREG32(mmGB_ADDR_CONFIG, adev->gfx.config.gb_addr_config);
  1811. WREG32(mmHDP_ADDR_CONFIG, adev->gfx.config.gb_addr_config);
  1812. WREG32(mmDMIF_ADDR_CALC, adev->gfx.config.gb_addr_config);
  1813. gfx_v7_0_tiling_mode_table_init(adev);
  1814. gfx_v7_0_setup_rb(adev);
  1815. gfx_v7_0_get_cu_info(adev);
  1816. gfx_v7_0_config_init(adev);
  1817. /* set HW defaults for 3D engine */
  1818. WREG32(mmCP_MEQ_THRESHOLDS,
  1819. (0x30 << CP_MEQ_THRESHOLDS__MEQ1_START__SHIFT) |
  1820. (0x60 << CP_MEQ_THRESHOLDS__MEQ2_START__SHIFT));
  1821. mutex_lock(&adev->grbm_idx_mutex);
  1822. /*
  1823. * making sure that the following register writes will be broadcasted
  1824. * to all the shaders
  1825. */
  1826. gfx_v7_0_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
  1827. /* XXX SH_MEM regs */
  1828. /* where to put LDS, scratch, GPUVM in FSA64 space */
  1829. sh_mem_cfg = REG_SET_FIELD(0, SH_MEM_CONFIG, ALIGNMENT_MODE,
  1830. SH_MEM_ALIGNMENT_MODE_UNALIGNED);
  1831. sh_mem_cfg = REG_SET_FIELD(sh_mem_cfg, SH_MEM_CONFIG, DEFAULT_MTYPE,
  1832. MTYPE_NC);
  1833. sh_mem_cfg = REG_SET_FIELD(sh_mem_cfg, SH_MEM_CONFIG, APE1_MTYPE,
  1834. MTYPE_UC);
  1835. sh_mem_cfg = REG_SET_FIELD(sh_mem_cfg, SH_MEM_CONFIG, PRIVATE_ATC, 0);
  1836. sh_static_mem_cfg = REG_SET_FIELD(0, SH_STATIC_MEM_CONFIG,
  1837. SWIZZLE_ENABLE, 1);
  1838. sh_static_mem_cfg = REG_SET_FIELD(sh_static_mem_cfg, SH_STATIC_MEM_CONFIG,
  1839. ELEMENT_SIZE, 1);
  1840. sh_static_mem_cfg = REG_SET_FIELD(sh_static_mem_cfg, SH_STATIC_MEM_CONFIG,
  1841. INDEX_STRIDE, 3);
  1842. WREG32(mmSH_STATIC_MEM_CONFIG, sh_static_mem_cfg);
  1843. mutex_lock(&adev->srbm_mutex);
  1844. for (i = 0; i < adev->vm_manager.id_mgr[0].num_ids; i++) {
  1845. if (i == 0)
  1846. sh_mem_base = 0;
  1847. else
  1848. sh_mem_base = adev->mc.shared_aperture_start >> 48;
  1849. cik_srbm_select(adev, 0, 0, 0, i);
  1850. /* CP and shaders */
  1851. WREG32(mmSH_MEM_CONFIG, sh_mem_cfg);
  1852. WREG32(mmSH_MEM_APE1_BASE, 1);
  1853. WREG32(mmSH_MEM_APE1_LIMIT, 0);
  1854. WREG32(mmSH_MEM_BASES, sh_mem_base);
  1855. }
  1856. cik_srbm_select(adev, 0, 0, 0, 0);
  1857. mutex_unlock(&adev->srbm_mutex);
  1858. gfx_v7_0_init_compute_vmid(adev);
  1859. WREG32(mmSX_DEBUG_1, 0x20);
  1860. WREG32(mmTA_CNTL_AUX, 0x00010000);
  1861. tmp = RREG32(mmSPI_CONFIG_CNTL);
  1862. tmp |= 0x03000000;
  1863. WREG32(mmSPI_CONFIG_CNTL, tmp);
  1864. WREG32(mmSQ_CONFIG, 1);
  1865. WREG32(mmDB_DEBUG, 0);
  1866. tmp = RREG32(mmDB_DEBUG2) & ~0xf00fffff;
  1867. tmp |= 0x00000400;
  1868. WREG32(mmDB_DEBUG2, tmp);
  1869. tmp = RREG32(mmDB_DEBUG3) & ~0x0002021c;
  1870. tmp |= 0x00020200;
  1871. WREG32(mmDB_DEBUG3, tmp);
  1872. tmp = RREG32(mmCB_HW_CONTROL) & ~0x00010000;
  1873. tmp |= 0x00018208;
  1874. WREG32(mmCB_HW_CONTROL, tmp);
  1875. WREG32(mmSPI_CONFIG_CNTL_1, (4 << SPI_CONFIG_CNTL_1__VTX_DONE_DELAY__SHIFT));
  1876. WREG32(mmPA_SC_FIFO_SIZE,
  1877. ((adev->gfx.config.sc_prim_fifo_size_frontend << PA_SC_FIFO_SIZE__SC_FRONTEND_PRIM_FIFO_SIZE__SHIFT) |
  1878. (adev->gfx.config.sc_prim_fifo_size_backend << PA_SC_FIFO_SIZE__SC_BACKEND_PRIM_FIFO_SIZE__SHIFT) |
  1879. (adev->gfx.config.sc_hiz_tile_fifo_size << PA_SC_FIFO_SIZE__SC_HIZ_TILE_FIFO_SIZE__SHIFT) |
  1880. (adev->gfx.config.sc_earlyz_tile_fifo_size << PA_SC_FIFO_SIZE__SC_EARLYZ_TILE_FIFO_SIZE__SHIFT)));
  1881. WREG32(mmVGT_NUM_INSTANCES, 1);
  1882. WREG32(mmCP_PERFMON_CNTL, 0);
  1883. WREG32(mmSQ_CONFIG, 0);
  1884. WREG32(mmPA_SC_FORCE_EOV_MAX_CNTS,
  1885. ((4095 << PA_SC_FORCE_EOV_MAX_CNTS__FORCE_EOV_MAX_CLK_CNT__SHIFT) |
  1886. (255 << PA_SC_FORCE_EOV_MAX_CNTS__FORCE_EOV_MAX_REZ_CNT__SHIFT)));
  1887. WREG32(mmVGT_CACHE_INVALIDATION,
  1888. (VC_AND_TC << VGT_CACHE_INVALIDATION__CACHE_INVALIDATION__SHIFT) |
  1889. (ES_AND_GS_AUTO << VGT_CACHE_INVALIDATION__AUTO_INVLD_EN__SHIFT));
  1890. WREG32(mmVGT_GS_VERTEX_REUSE, 16);
  1891. WREG32(mmPA_SC_LINE_STIPPLE_STATE, 0);
  1892. WREG32(mmPA_CL_ENHANCE, PA_CL_ENHANCE__CLIP_VTX_REORDER_ENA_MASK |
  1893. (3 << PA_CL_ENHANCE__NUM_CLIP_SEQ__SHIFT));
  1894. WREG32(mmPA_SC_ENHANCE, PA_SC_ENHANCE__ENABLE_PA_SC_OUT_OF_ORDER_MASK);
  1895. tmp = RREG32(mmSPI_ARB_PRIORITY);
  1896. tmp = REG_SET_FIELD(tmp, SPI_ARB_PRIORITY, PIPE_ORDER_TS0, 2);
  1897. tmp = REG_SET_FIELD(tmp, SPI_ARB_PRIORITY, PIPE_ORDER_TS1, 2);
  1898. tmp = REG_SET_FIELD(tmp, SPI_ARB_PRIORITY, PIPE_ORDER_TS2, 2);
  1899. tmp = REG_SET_FIELD(tmp, SPI_ARB_PRIORITY, PIPE_ORDER_TS3, 2);
  1900. WREG32(mmSPI_ARB_PRIORITY, tmp);
  1901. mutex_unlock(&adev->grbm_idx_mutex);
  1902. udelay(50);
  1903. }
  1904. /*
  1905. * GPU scratch registers helpers function.
  1906. */
  1907. /**
  1908. * gfx_v7_0_scratch_init - setup driver info for CP scratch regs
  1909. *
  1910. * @adev: amdgpu_device pointer
  1911. *
  1912. * Set up the number and offset of the CP scratch registers.
  1913. * NOTE: use of CP scratch registers is a legacy inferface and
  1914. * is not used by default on newer asics (r6xx+). On newer asics,
  1915. * memory buffers are used for fences rather than scratch regs.
  1916. */
  1917. static void gfx_v7_0_scratch_init(struct amdgpu_device *adev)
  1918. {
  1919. adev->gfx.scratch.num_reg = 8;
  1920. adev->gfx.scratch.reg_base = mmSCRATCH_REG0;
  1921. adev->gfx.scratch.free_mask = (1u << adev->gfx.scratch.num_reg) - 1;
  1922. }
  1923. /**
  1924. * gfx_v7_0_ring_test_ring - basic gfx ring test
  1925. *
  1926. * @adev: amdgpu_device pointer
  1927. * @ring: amdgpu_ring structure holding ring information
  1928. *
  1929. * Allocate a scratch register and write to it using the gfx ring (CIK).
  1930. * Provides a basic gfx ring test to verify that the ring is working.
  1931. * Used by gfx_v7_0_cp_gfx_resume();
  1932. * Returns 0 on success, error on failure.
  1933. */
  1934. static int gfx_v7_0_ring_test_ring(struct amdgpu_ring *ring)
  1935. {
  1936. struct amdgpu_device *adev = ring->adev;
  1937. uint32_t scratch;
  1938. uint32_t tmp = 0;
  1939. unsigned i;
  1940. int r;
  1941. r = amdgpu_gfx_scratch_get(adev, &scratch);
  1942. if (r) {
  1943. DRM_ERROR("amdgpu: cp failed to get scratch reg (%d).\n", r);
  1944. return r;
  1945. }
  1946. WREG32(scratch, 0xCAFEDEAD);
  1947. r = amdgpu_ring_alloc(ring, 3);
  1948. if (r) {
  1949. DRM_ERROR("amdgpu: cp failed to lock ring %d (%d).\n", ring->idx, r);
  1950. amdgpu_gfx_scratch_free(adev, scratch);
  1951. return r;
  1952. }
  1953. amdgpu_ring_write(ring, PACKET3(PACKET3_SET_UCONFIG_REG, 1));
  1954. amdgpu_ring_write(ring, (scratch - PACKET3_SET_UCONFIG_REG_START));
  1955. amdgpu_ring_write(ring, 0xDEADBEEF);
  1956. amdgpu_ring_commit(ring);
  1957. for (i = 0; i < adev->usec_timeout; i++) {
  1958. tmp = RREG32(scratch);
  1959. if (tmp == 0xDEADBEEF)
  1960. break;
  1961. DRM_UDELAY(1);
  1962. }
  1963. if (i < adev->usec_timeout) {
  1964. DRM_INFO("ring test on %d succeeded in %d usecs\n", ring->idx, i);
  1965. } else {
  1966. DRM_ERROR("amdgpu: ring %d test failed (scratch(0x%04X)=0x%08X)\n",
  1967. ring->idx, scratch, tmp);
  1968. r = -EINVAL;
  1969. }
  1970. amdgpu_gfx_scratch_free(adev, scratch);
  1971. return r;
  1972. }
  1973. /**
  1974. * gfx_v7_0_ring_emit_hdp - emit an hdp flush on the cp
  1975. *
  1976. * @adev: amdgpu_device pointer
  1977. * @ridx: amdgpu ring index
  1978. *
  1979. * Emits an hdp flush on the cp.
  1980. */
  1981. static void gfx_v7_0_ring_emit_hdp_flush(struct amdgpu_ring *ring)
  1982. {
  1983. u32 ref_and_mask;
  1984. int usepfp = ring->funcs->type == AMDGPU_RING_TYPE_COMPUTE ? 0 : 1;
  1985. if (ring->funcs->type == AMDGPU_RING_TYPE_COMPUTE) {
  1986. switch (ring->me) {
  1987. case 1:
  1988. ref_and_mask = GPU_HDP_FLUSH_DONE__CP2_MASK << ring->pipe;
  1989. break;
  1990. case 2:
  1991. ref_and_mask = GPU_HDP_FLUSH_DONE__CP6_MASK << ring->pipe;
  1992. break;
  1993. default:
  1994. return;
  1995. }
  1996. } else {
  1997. ref_and_mask = GPU_HDP_FLUSH_DONE__CP0_MASK;
  1998. }
  1999. amdgpu_ring_write(ring, PACKET3(PACKET3_WAIT_REG_MEM, 5));
  2000. amdgpu_ring_write(ring, (WAIT_REG_MEM_OPERATION(1) | /* write, wait, write */
  2001. WAIT_REG_MEM_FUNCTION(3) | /* == */
  2002. WAIT_REG_MEM_ENGINE(usepfp))); /* pfp or me */
  2003. amdgpu_ring_write(ring, mmGPU_HDP_FLUSH_REQ);
  2004. amdgpu_ring_write(ring, mmGPU_HDP_FLUSH_DONE);
  2005. amdgpu_ring_write(ring, ref_and_mask);
  2006. amdgpu_ring_write(ring, ref_and_mask);
  2007. amdgpu_ring_write(ring, 0x20); /* poll interval */
  2008. }
  2009. static void gfx_v7_0_ring_emit_vgt_flush(struct amdgpu_ring *ring)
  2010. {
  2011. amdgpu_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE, 0));
  2012. amdgpu_ring_write(ring, EVENT_TYPE(VS_PARTIAL_FLUSH) |
  2013. EVENT_INDEX(4));
  2014. amdgpu_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE, 0));
  2015. amdgpu_ring_write(ring, EVENT_TYPE(VGT_FLUSH) |
  2016. EVENT_INDEX(0));
  2017. }
  2018. /**
  2019. * gfx_v7_0_ring_emit_hdp_invalidate - emit an hdp invalidate on the cp
  2020. *
  2021. * @adev: amdgpu_device pointer
  2022. * @ridx: amdgpu ring index
  2023. *
  2024. * Emits an hdp invalidate on the cp.
  2025. */
  2026. static void gfx_v7_0_ring_emit_hdp_invalidate(struct amdgpu_ring *ring)
  2027. {
  2028. amdgpu_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  2029. amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
  2030. WRITE_DATA_DST_SEL(0) |
  2031. WR_CONFIRM));
  2032. amdgpu_ring_write(ring, mmHDP_DEBUG0);
  2033. amdgpu_ring_write(ring, 0);
  2034. amdgpu_ring_write(ring, 1);
  2035. }
  2036. /**
  2037. * gfx_v7_0_ring_emit_fence_gfx - emit a fence on the gfx ring
  2038. *
  2039. * @adev: amdgpu_device pointer
  2040. * @fence: amdgpu fence object
  2041. *
  2042. * Emits a fence sequnce number on the gfx ring and flushes
  2043. * GPU caches.
  2044. */
  2045. static void gfx_v7_0_ring_emit_fence_gfx(struct amdgpu_ring *ring, u64 addr,
  2046. u64 seq, unsigned flags)
  2047. {
  2048. bool write64bit = flags & AMDGPU_FENCE_FLAG_64BIT;
  2049. bool int_sel = flags & AMDGPU_FENCE_FLAG_INT;
  2050. /* Workaround for cache flush problems. First send a dummy EOP
  2051. * event down the pipe with seq one below.
  2052. */
  2053. amdgpu_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE_EOP, 4));
  2054. amdgpu_ring_write(ring, (EOP_TCL1_ACTION_EN |
  2055. EOP_TC_ACTION_EN |
  2056. EVENT_TYPE(CACHE_FLUSH_AND_INV_TS_EVENT) |
  2057. EVENT_INDEX(5)));
  2058. amdgpu_ring_write(ring, addr & 0xfffffffc);
  2059. amdgpu_ring_write(ring, (upper_32_bits(addr) & 0xffff) |
  2060. DATA_SEL(1) | INT_SEL(0));
  2061. amdgpu_ring_write(ring, lower_32_bits(seq - 1));
  2062. amdgpu_ring_write(ring, upper_32_bits(seq - 1));
  2063. /* Then send the real EOP event down the pipe. */
  2064. amdgpu_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE_EOP, 4));
  2065. amdgpu_ring_write(ring, (EOP_TCL1_ACTION_EN |
  2066. EOP_TC_ACTION_EN |
  2067. EVENT_TYPE(CACHE_FLUSH_AND_INV_TS_EVENT) |
  2068. EVENT_INDEX(5)));
  2069. amdgpu_ring_write(ring, addr & 0xfffffffc);
  2070. amdgpu_ring_write(ring, (upper_32_bits(addr) & 0xffff) |
  2071. DATA_SEL(write64bit ? 2 : 1) | INT_SEL(int_sel ? 2 : 0));
  2072. amdgpu_ring_write(ring, lower_32_bits(seq));
  2073. amdgpu_ring_write(ring, upper_32_bits(seq));
  2074. }
  2075. /**
  2076. * gfx_v7_0_ring_emit_fence_compute - emit a fence on the compute ring
  2077. *
  2078. * @adev: amdgpu_device pointer
  2079. * @fence: amdgpu fence object
  2080. *
  2081. * Emits a fence sequnce number on the compute ring and flushes
  2082. * GPU caches.
  2083. */
  2084. static void gfx_v7_0_ring_emit_fence_compute(struct amdgpu_ring *ring,
  2085. u64 addr, u64 seq,
  2086. unsigned flags)
  2087. {
  2088. bool write64bit = flags & AMDGPU_FENCE_FLAG_64BIT;
  2089. bool int_sel = flags & AMDGPU_FENCE_FLAG_INT;
  2090. /* RELEASE_MEM - flush caches, send int */
  2091. amdgpu_ring_write(ring, PACKET3(PACKET3_RELEASE_MEM, 5));
  2092. amdgpu_ring_write(ring, (EOP_TCL1_ACTION_EN |
  2093. EOP_TC_ACTION_EN |
  2094. EVENT_TYPE(CACHE_FLUSH_AND_INV_TS_EVENT) |
  2095. EVENT_INDEX(5)));
  2096. amdgpu_ring_write(ring, DATA_SEL(write64bit ? 2 : 1) | INT_SEL(int_sel ? 2 : 0));
  2097. amdgpu_ring_write(ring, addr & 0xfffffffc);
  2098. amdgpu_ring_write(ring, upper_32_bits(addr));
  2099. amdgpu_ring_write(ring, lower_32_bits(seq));
  2100. amdgpu_ring_write(ring, upper_32_bits(seq));
  2101. }
  2102. /*
  2103. * IB stuff
  2104. */
  2105. /**
  2106. * gfx_v7_0_ring_emit_ib - emit an IB (Indirect Buffer) on the ring
  2107. *
  2108. * @ring: amdgpu_ring structure holding ring information
  2109. * @ib: amdgpu indirect buffer object
  2110. *
  2111. * Emits an DE (drawing engine) or CE (constant engine) IB
  2112. * on the gfx ring. IBs are usually generated by userspace
  2113. * acceleration drivers and submitted to the kernel for
  2114. * sheduling on the ring. This function schedules the IB
  2115. * on the gfx ring for execution by the GPU.
  2116. */
  2117. static void gfx_v7_0_ring_emit_ib_gfx(struct amdgpu_ring *ring,
  2118. struct amdgpu_ib *ib,
  2119. unsigned vm_id, bool ctx_switch)
  2120. {
  2121. u32 header, control = 0;
  2122. /* insert SWITCH_BUFFER packet before first IB in the ring frame */
  2123. if (ctx_switch) {
  2124. amdgpu_ring_write(ring, PACKET3(PACKET3_SWITCH_BUFFER, 0));
  2125. amdgpu_ring_write(ring, 0);
  2126. }
  2127. if (ib->flags & AMDGPU_IB_FLAG_CE)
  2128. header = PACKET3(PACKET3_INDIRECT_BUFFER_CONST, 2);
  2129. else
  2130. header = PACKET3(PACKET3_INDIRECT_BUFFER, 2);
  2131. control |= ib->length_dw | (vm_id << 24);
  2132. amdgpu_ring_write(ring, header);
  2133. amdgpu_ring_write(ring,
  2134. #ifdef __BIG_ENDIAN
  2135. (2 << 0) |
  2136. #endif
  2137. (ib->gpu_addr & 0xFFFFFFFC));
  2138. amdgpu_ring_write(ring, upper_32_bits(ib->gpu_addr) & 0xFFFF);
  2139. amdgpu_ring_write(ring, control);
  2140. }
  2141. static void gfx_v7_0_ring_emit_ib_compute(struct amdgpu_ring *ring,
  2142. struct amdgpu_ib *ib,
  2143. unsigned vm_id, bool ctx_switch)
  2144. {
  2145. u32 control = INDIRECT_BUFFER_VALID | ib->length_dw | (vm_id << 24);
  2146. amdgpu_ring_write(ring, PACKET3(PACKET3_INDIRECT_BUFFER, 2));
  2147. amdgpu_ring_write(ring,
  2148. #ifdef __BIG_ENDIAN
  2149. (2 << 0) |
  2150. #endif
  2151. (ib->gpu_addr & 0xFFFFFFFC));
  2152. amdgpu_ring_write(ring, upper_32_bits(ib->gpu_addr) & 0xFFFF);
  2153. amdgpu_ring_write(ring, control);
  2154. }
  2155. static void gfx_v7_ring_emit_cntxcntl(struct amdgpu_ring *ring, uint32_t flags)
  2156. {
  2157. uint32_t dw2 = 0;
  2158. dw2 |= 0x80000000; /* set load_enable otherwise this package is just NOPs */
  2159. if (flags & AMDGPU_HAVE_CTX_SWITCH) {
  2160. gfx_v7_0_ring_emit_vgt_flush(ring);
  2161. /* set load_global_config & load_global_uconfig */
  2162. dw2 |= 0x8001;
  2163. /* set load_cs_sh_regs */
  2164. dw2 |= 0x01000000;
  2165. /* set load_per_context_state & load_gfx_sh_regs */
  2166. dw2 |= 0x10002;
  2167. }
  2168. amdgpu_ring_write(ring, PACKET3(PACKET3_CONTEXT_CONTROL, 1));
  2169. amdgpu_ring_write(ring, dw2);
  2170. amdgpu_ring_write(ring, 0);
  2171. }
  2172. /**
  2173. * gfx_v7_0_ring_test_ib - basic ring IB test
  2174. *
  2175. * @ring: amdgpu_ring structure holding ring information
  2176. *
  2177. * Allocate an IB and execute it on the gfx ring (CIK).
  2178. * Provides a basic gfx ring test to verify that IBs are working.
  2179. * Returns 0 on success, error on failure.
  2180. */
  2181. static int gfx_v7_0_ring_test_ib(struct amdgpu_ring *ring, long timeout)
  2182. {
  2183. struct amdgpu_device *adev = ring->adev;
  2184. struct amdgpu_ib ib;
  2185. struct dma_fence *f = NULL;
  2186. uint32_t scratch;
  2187. uint32_t tmp = 0;
  2188. long r;
  2189. r = amdgpu_gfx_scratch_get(adev, &scratch);
  2190. if (r) {
  2191. DRM_ERROR("amdgpu: failed to get scratch reg (%ld).\n", r);
  2192. return r;
  2193. }
  2194. WREG32(scratch, 0xCAFEDEAD);
  2195. memset(&ib, 0, sizeof(ib));
  2196. r = amdgpu_ib_get(adev, NULL, 256, &ib);
  2197. if (r) {
  2198. DRM_ERROR("amdgpu: failed to get ib (%ld).\n", r);
  2199. goto err1;
  2200. }
  2201. ib.ptr[0] = PACKET3(PACKET3_SET_UCONFIG_REG, 1);
  2202. ib.ptr[1] = ((scratch - PACKET3_SET_UCONFIG_REG_START));
  2203. ib.ptr[2] = 0xDEADBEEF;
  2204. ib.length_dw = 3;
  2205. r = amdgpu_ib_schedule(ring, 1, &ib, NULL, &f);
  2206. if (r)
  2207. goto err2;
  2208. r = dma_fence_wait_timeout(f, false, timeout);
  2209. if (r == 0) {
  2210. DRM_ERROR("amdgpu: IB test timed out\n");
  2211. r = -ETIMEDOUT;
  2212. goto err2;
  2213. } else if (r < 0) {
  2214. DRM_ERROR("amdgpu: fence wait failed (%ld).\n", r);
  2215. goto err2;
  2216. }
  2217. tmp = RREG32(scratch);
  2218. if (tmp == 0xDEADBEEF) {
  2219. DRM_INFO("ib test on ring %d succeeded\n", ring->idx);
  2220. r = 0;
  2221. } else {
  2222. DRM_ERROR("amdgpu: ib test failed (scratch(0x%04X)=0x%08X)\n",
  2223. scratch, tmp);
  2224. r = -EINVAL;
  2225. }
  2226. err2:
  2227. amdgpu_ib_free(adev, &ib, NULL);
  2228. dma_fence_put(f);
  2229. err1:
  2230. amdgpu_gfx_scratch_free(adev, scratch);
  2231. return r;
  2232. }
  2233. /*
  2234. * CP.
  2235. * On CIK, gfx and compute now have independant command processors.
  2236. *
  2237. * GFX
  2238. * Gfx consists of a single ring and can process both gfx jobs and
  2239. * compute jobs. The gfx CP consists of three microengines (ME):
  2240. * PFP - Pre-Fetch Parser
  2241. * ME - Micro Engine
  2242. * CE - Constant Engine
  2243. * The PFP and ME make up what is considered the Drawing Engine (DE).
  2244. * The CE is an asynchronous engine used for updating buffer desciptors
  2245. * used by the DE so that they can be loaded into cache in parallel
  2246. * while the DE is processing state update packets.
  2247. *
  2248. * Compute
  2249. * The compute CP consists of two microengines (ME):
  2250. * MEC1 - Compute MicroEngine 1
  2251. * MEC2 - Compute MicroEngine 2
  2252. * Each MEC supports 4 compute pipes and each pipe supports 8 queues.
  2253. * The queues are exposed to userspace and are programmed directly
  2254. * by the compute runtime.
  2255. */
  2256. /**
  2257. * gfx_v7_0_cp_gfx_enable - enable/disable the gfx CP MEs
  2258. *
  2259. * @adev: amdgpu_device pointer
  2260. * @enable: enable or disable the MEs
  2261. *
  2262. * Halts or unhalts the gfx MEs.
  2263. */
  2264. static void gfx_v7_0_cp_gfx_enable(struct amdgpu_device *adev, bool enable)
  2265. {
  2266. int i;
  2267. if (enable) {
  2268. WREG32(mmCP_ME_CNTL, 0);
  2269. } else {
  2270. WREG32(mmCP_ME_CNTL, (CP_ME_CNTL__ME_HALT_MASK | CP_ME_CNTL__PFP_HALT_MASK | CP_ME_CNTL__CE_HALT_MASK));
  2271. for (i = 0; i < adev->gfx.num_gfx_rings; i++)
  2272. adev->gfx.gfx_ring[i].ready = false;
  2273. }
  2274. udelay(50);
  2275. }
  2276. /**
  2277. * gfx_v7_0_cp_gfx_load_microcode - load the gfx CP ME ucode
  2278. *
  2279. * @adev: amdgpu_device pointer
  2280. *
  2281. * Loads the gfx PFP, ME, and CE ucode.
  2282. * Returns 0 for success, -EINVAL if the ucode is not available.
  2283. */
  2284. static int gfx_v7_0_cp_gfx_load_microcode(struct amdgpu_device *adev)
  2285. {
  2286. const struct gfx_firmware_header_v1_0 *pfp_hdr;
  2287. const struct gfx_firmware_header_v1_0 *ce_hdr;
  2288. const struct gfx_firmware_header_v1_0 *me_hdr;
  2289. const __le32 *fw_data;
  2290. unsigned i, fw_size;
  2291. if (!adev->gfx.me_fw || !adev->gfx.pfp_fw || !adev->gfx.ce_fw)
  2292. return -EINVAL;
  2293. pfp_hdr = (const struct gfx_firmware_header_v1_0 *)adev->gfx.pfp_fw->data;
  2294. ce_hdr = (const struct gfx_firmware_header_v1_0 *)adev->gfx.ce_fw->data;
  2295. me_hdr = (const struct gfx_firmware_header_v1_0 *)adev->gfx.me_fw->data;
  2296. amdgpu_ucode_print_gfx_hdr(&pfp_hdr->header);
  2297. amdgpu_ucode_print_gfx_hdr(&ce_hdr->header);
  2298. amdgpu_ucode_print_gfx_hdr(&me_hdr->header);
  2299. adev->gfx.pfp_fw_version = le32_to_cpu(pfp_hdr->header.ucode_version);
  2300. adev->gfx.ce_fw_version = le32_to_cpu(ce_hdr->header.ucode_version);
  2301. adev->gfx.me_fw_version = le32_to_cpu(me_hdr->header.ucode_version);
  2302. adev->gfx.me_feature_version = le32_to_cpu(me_hdr->ucode_feature_version);
  2303. adev->gfx.ce_feature_version = le32_to_cpu(ce_hdr->ucode_feature_version);
  2304. adev->gfx.pfp_feature_version = le32_to_cpu(pfp_hdr->ucode_feature_version);
  2305. gfx_v7_0_cp_gfx_enable(adev, false);
  2306. /* PFP */
  2307. fw_data = (const __le32 *)
  2308. (adev->gfx.pfp_fw->data +
  2309. le32_to_cpu(pfp_hdr->header.ucode_array_offset_bytes));
  2310. fw_size = le32_to_cpu(pfp_hdr->header.ucode_size_bytes) / 4;
  2311. WREG32(mmCP_PFP_UCODE_ADDR, 0);
  2312. for (i = 0; i < fw_size; i++)
  2313. WREG32(mmCP_PFP_UCODE_DATA, le32_to_cpup(fw_data++));
  2314. WREG32(mmCP_PFP_UCODE_ADDR, adev->gfx.pfp_fw_version);
  2315. /* CE */
  2316. fw_data = (const __le32 *)
  2317. (adev->gfx.ce_fw->data +
  2318. le32_to_cpu(ce_hdr->header.ucode_array_offset_bytes));
  2319. fw_size = le32_to_cpu(ce_hdr->header.ucode_size_bytes) / 4;
  2320. WREG32(mmCP_CE_UCODE_ADDR, 0);
  2321. for (i = 0; i < fw_size; i++)
  2322. WREG32(mmCP_CE_UCODE_DATA, le32_to_cpup(fw_data++));
  2323. WREG32(mmCP_CE_UCODE_ADDR, adev->gfx.ce_fw_version);
  2324. /* ME */
  2325. fw_data = (const __le32 *)
  2326. (adev->gfx.me_fw->data +
  2327. le32_to_cpu(me_hdr->header.ucode_array_offset_bytes));
  2328. fw_size = le32_to_cpu(me_hdr->header.ucode_size_bytes) / 4;
  2329. WREG32(mmCP_ME_RAM_WADDR, 0);
  2330. for (i = 0; i < fw_size; i++)
  2331. WREG32(mmCP_ME_RAM_DATA, le32_to_cpup(fw_data++));
  2332. WREG32(mmCP_ME_RAM_WADDR, adev->gfx.me_fw_version);
  2333. return 0;
  2334. }
  2335. /**
  2336. * gfx_v7_0_cp_gfx_start - start the gfx ring
  2337. *
  2338. * @adev: amdgpu_device pointer
  2339. *
  2340. * Enables the ring and loads the clear state context and other
  2341. * packets required to init the ring.
  2342. * Returns 0 for success, error for failure.
  2343. */
  2344. static int gfx_v7_0_cp_gfx_start(struct amdgpu_device *adev)
  2345. {
  2346. struct amdgpu_ring *ring = &adev->gfx.gfx_ring[0];
  2347. const struct cs_section_def *sect = NULL;
  2348. const struct cs_extent_def *ext = NULL;
  2349. int r, i;
  2350. /* init the CP */
  2351. WREG32(mmCP_MAX_CONTEXT, adev->gfx.config.max_hw_contexts - 1);
  2352. WREG32(mmCP_ENDIAN_SWAP, 0);
  2353. WREG32(mmCP_DEVICE_ID, 1);
  2354. gfx_v7_0_cp_gfx_enable(adev, true);
  2355. r = amdgpu_ring_alloc(ring, gfx_v7_0_get_csb_size(adev) + 8);
  2356. if (r) {
  2357. DRM_ERROR("amdgpu: cp failed to lock ring (%d).\n", r);
  2358. return r;
  2359. }
  2360. /* init the CE partitions. CE only used for gfx on CIK */
  2361. amdgpu_ring_write(ring, PACKET3(PACKET3_SET_BASE, 2));
  2362. amdgpu_ring_write(ring, PACKET3_BASE_INDEX(CE_PARTITION_BASE));
  2363. amdgpu_ring_write(ring, 0x8000);
  2364. amdgpu_ring_write(ring, 0x8000);
  2365. /* clear state buffer */
  2366. amdgpu_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
  2367. amdgpu_ring_write(ring, PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);
  2368. amdgpu_ring_write(ring, PACKET3(PACKET3_CONTEXT_CONTROL, 1));
  2369. amdgpu_ring_write(ring, 0x80000000);
  2370. amdgpu_ring_write(ring, 0x80000000);
  2371. for (sect = adev->gfx.rlc.cs_data; sect->section != NULL; ++sect) {
  2372. for (ext = sect->section; ext->extent != NULL; ++ext) {
  2373. if (sect->id == SECT_CONTEXT) {
  2374. amdgpu_ring_write(ring,
  2375. PACKET3(PACKET3_SET_CONTEXT_REG, ext->reg_count));
  2376. amdgpu_ring_write(ring, ext->reg_index - PACKET3_SET_CONTEXT_REG_START);
  2377. for (i = 0; i < ext->reg_count; i++)
  2378. amdgpu_ring_write(ring, ext->extent[i]);
  2379. }
  2380. }
  2381. }
  2382. amdgpu_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 2));
  2383. amdgpu_ring_write(ring, mmPA_SC_RASTER_CONFIG - PACKET3_SET_CONTEXT_REG_START);
  2384. switch (adev->asic_type) {
  2385. case CHIP_BONAIRE:
  2386. amdgpu_ring_write(ring, 0x16000012);
  2387. amdgpu_ring_write(ring, 0x00000000);
  2388. break;
  2389. case CHIP_KAVERI:
  2390. amdgpu_ring_write(ring, 0x00000000); /* XXX */
  2391. amdgpu_ring_write(ring, 0x00000000);
  2392. break;
  2393. case CHIP_KABINI:
  2394. case CHIP_MULLINS:
  2395. amdgpu_ring_write(ring, 0x00000000); /* XXX */
  2396. amdgpu_ring_write(ring, 0x00000000);
  2397. break;
  2398. case CHIP_HAWAII:
  2399. amdgpu_ring_write(ring, 0x3a00161a);
  2400. amdgpu_ring_write(ring, 0x0000002e);
  2401. break;
  2402. default:
  2403. amdgpu_ring_write(ring, 0x00000000);
  2404. amdgpu_ring_write(ring, 0x00000000);
  2405. break;
  2406. }
  2407. amdgpu_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
  2408. amdgpu_ring_write(ring, PACKET3_PREAMBLE_END_CLEAR_STATE);
  2409. amdgpu_ring_write(ring, PACKET3(PACKET3_CLEAR_STATE, 0));
  2410. amdgpu_ring_write(ring, 0);
  2411. amdgpu_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 2));
  2412. amdgpu_ring_write(ring, 0x00000316);
  2413. amdgpu_ring_write(ring, 0x0000000e); /* VGT_VERTEX_REUSE_BLOCK_CNTL */
  2414. amdgpu_ring_write(ring, 0x00000010); /* VGT_OUT_DEALLOC_CNTL */
  2415. amdgpu_ring_commit(ring);
  2416. return 0;
  2417. }
  2418. /**
  2419. * gfx_v7_0_cp_gfx_resume - setup the gfx ring buffer registers
  2420. *
  2421. * @adev: amdgpu_device pointer
  2422. *
  2423. * Program the location and size of the gfx ring buffer
  2424. * and test it to make sure it's working.
  2425. * Returns 0 for success, error for failure.
  2426. */
  2427. static int gfx_v7_0_cp_gfx_resume(struct amdgpu_device *adev)
  2428. {
  2429. struct amdgpu_ring *ring;
  2430. u32 tmp;
  2431. u32 rb_bufsz;
  2432. u64 rb_addr, rptr_addr;
  2433. int r;
  2434. WREG32(mmCP_SEM_WAIT_TIMER, 0x0);
  2435. if (adev->asic_type != CHIP_HAWAII)
  2436. WREG32(mmCP_SEM_INCOMPLETE_TIMER_CNTL, 0x0);
  2437. /* Set the write pointer delay */
  2438. WREG32(mmCP_RB_WPTR_DELAY, 0);
  2439. /* set the RB to use vmid 0 */
  2440. WREG32(mmCP_RB_VMID, 0);
  2441. WREG32(mmSCRATCH_ADDR, 0);
  2442. /* ring 0 - compute and gfx */
  2443. /* Set ring buffer size */
  2444. ring = &adev->gfx.gfx_ring[0];
  2445. rb_bufsz = order_base_2(ring->ring_size / 8);
  2446. tmp = (order_base_2(AMDGPU_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
  2447. #ifdef __BIG_ENDIAN
  2448. tmp |= 2 << CP_RB0_CNTL__BUF_SWAP__SHIFT;
  2449. #endif
  2450. WREG32(mmCP_RB0_CNTL, tmp);
  2451. /* Initialize the ring buffer's read and write pointers */
  2452. WREG32(mmCP_RB0_CNTL, tmp | CP_RB0_CNTL__RB_RPTR_WR_ENA_MASK);
  2453. ring->wptr = 0;
  2454. WREG32(mmCP_RB0_WPTR, lower_32_bits(ring->wptr));
  2455. /* set the wb address wether it's enabled or not */
  2456. rptr_addr = adev->wb.gpu_addr + (ring->rptr_offs * 4);
  2457. WREG32(mmCP_RB0_RPTR_ADDR, lower_32_bits(rptr_addr));
  2458. WREG32(mmCP_RB0_RPTR_ADDR_HI, upper_32_bits(rptr_addr) & 0xFF);
  2459. /* scratch register shadowing is no longer supported */
  2460. WREG32(mmSCRATCH_UMSK, 0);
  2461. mdelay(1);
  2462. WREG32(mmCP_RB0_CNTL, tmp);
  2463. rb_addr = ring->gpu_addr >> 8;
  2464. WREG32(mmCP_RB0_BASE, rb_addr);
  2465. WREG32(mmCP_RB0_BASE_HI, upper_32_bits(rb_addr));
  2466. /* start the ring */
  2467. gfx_v7_0_cp_gfx_start(adev);
  2468. ring->ready = true;
  2469. r = amdgpu_ring_test_ring(ring);
  2470. if (r) {
  2471. ring->ready = false;
  2472. return r;
  2473. }
  2474. return 0;
  2475. }
  2476. static u64 gfx_v7_0_ring_get_rptr(struct amdgpu_ring *ring)
  2477. {
  2478. return ring->adev->wb.wb[ring->rptr_offs];
  2479. }
  2480. static u64 gfx_v7_0_ring_get_wptr_gfx(struct amdgpu_ring *ring)
  2481. {
  2482. struct amdgpu_device *adev = ring->adev;
  2483. return RREG32(mmCP_RB0_WPTR);
  2484. }
  2485. static void gfx_v7_0_ring_set_wptr_gfx(struct amdgpu_ring *ring)
  2486. {
  2487. struct amdgpu_device *adev = ring->adev;
  2488. WREG32(mmCP_RB0_WPTR, lower_32_bits(ring->wptr));
  2489. (void)RREG32(mmCP_RB0_WPTR);
  2490. }
  2491. static u64 gfx_v7_0_ring_get_wptr_compute(struct amdgpu_ring *ring)
  2492. {
  2493. /* XXX check if swapping is necessary on BE */
  2494. return ring->adev->wb.wb[ring->wptr_offs];
  2495. }
  2496. static void gfx_v7_0_ring_set_wptr_compute(struct amdgpu_ring *ring)
  2497. {
  2498. struct amdgpu_device *adev = ring->adev;
  2499. /* XXX check if swapping is necessary on BE */
  2500. adev->wb.wb[ring->wptr_offs] = lower_32_bits(ring->wptr);
  2501. WDOORBELL32(ring->doorbell_index, lower_32_bits(ring->wptr));
  2502. }
  2503. /**
  2504. * gfx_v7_0_cp_compute_enable - enable/disable the compute CP MEs
  2505. *
  2506. * @adev: amdgpu_device pointer
  2507. * @enable: enable or disable the MEs
  2508. *
  2509. * Halts or unhalts the compute MEs.
  2510. */
  2511. static void gfx_v7_0_cp_compute_enable(struct amdgpu_device *adev, bool enable)
  2512. {
  2513. int i;
  2514. if (enable) {
  2515. WREG32(mmCP_MEC_CNTL, 0);
  2516. } else {
  2517. WREG32(mmCP_MEC_CNTL, (CP_MEC_CNTL__MEC_ME1_HALT_MASK | CP_MEC_CNTL__MEC_ME2_HALT_MASK));
  2518. for (i = 0; i < adev->gfx.num_compute_rings; i++)
  2519. adev->gfx.compute_ring[i].ready = false;
  2520. }
  2521. udelay(50);
  2522. }
  2523. /**
  2524. * gfx_v7_0_cp_compute_load_microcode - load the compute CP ME ucode
  2525. *
  2526. * @adev: amdgpu_device pointer
  2527. *
  2528. * Loads the compute MEC1&2 ucode.
  2529. * Returns 0 for success, -EINVAL if the ucode is not available.
  2530. */
  2531. static int gfx_v7_0_cp_compute_load_microcode(struct amdgpu_device *adev)
  2532. {
  2533. const struct gfx_firmware_header_v1_0 *mec_hdr;
  2534. const __le32 *fw_data;
  2535. unsigned i, fw_size;
  2536. if (!adev->gfx.mec_fw)
  2537. return -EINVAL;
  2538. mec_hdr = (const struct gfx_firmware_header_v1_0 *)adev->gfx.mec_fw->data;
  2539. amdgpu_ucode_print_gfx_hdr(&mec_hdr->header);
  2540. adev->gfx.mec_fw_version = le32_to_cpu(mec_hdr->header.ucode_version);
  2541. adev->gfx.mec_feature_version = le32_to_cpu(
  2542. mec_hdr->ucode_feature_version);
  2543. gfx_v7_0_cp_compute_enable(adev, false);
  2544. /* MEC1 */
  2545. fw_data = (const __le32 *)
  2546. (adev->gfx.mec_fw->data +
  2547. le32_to_cpu(mec_hdr->header.ucode_array_offset_bytes));
  2548. fw_size = le32_to_cpu(mec_hdr->header.ucode_size_bytes) / 4;
  2549. WREG32(mmCP_MEC_ME1_UCODE_ADDR, 0);
  2550. for (i = 0; i < fw_size; i++)
  2551. WREG32(mmCP_MEC_ME1_UCODE_DATA, le32_to_cpup(fw_data++));
  2552. WREG32(mmCP_MEC_ME1_UCODE_ADDR, 0);
  2553. if (adev->asic_type == CHIP_KAVERI) {
  2554. const struct gfx_firmware_header_v1_0 *mec2_hdr;
  2555. if (!adev->gfx.mec2_fw)
  2556. return -EINVAL;
  2557. mec2_hdr = (const struct gfx_firmware_header_v1_0 *)adev->gfx.mec2_fw->data;
  2558. amdgpu_ucode_print_gfx_hdr(&mec2_hdr->header);
  2559. adev->gfx.mec2_fw_version = le32_to_cpu(mec2_hdr->header.ucode_version);
  2560. adev->gfx.mec2_feature_version = le32_to_cpu(
  2561. mec2_hdr->ucode_feature_version);
  2562. /* MEC2 */
  2563. fw_data = (const __le32 *)
  2564. (adev->gfx.mec2_fw->data +
  2565. le32_to_cpu(mec2_hdr->header.ucode_array_offset_bytes));
  2566. fw_size = le32_to_cpu(mec2_hdr->header.ucode_size_bytes) / 4;
  2567. WREG32(mmCP_MEC_ME2_UCODE_ADDR, 0);
  2568. for (i = 0; i < fw_size; i++)
  2569. WREG32(mmCP_MEC_ME2_UCODE_DATA, le32_to_cpup(fw_data++));
  2570. WREG32(mmCP_MEC_ME2_UCODE_ADDR, 0);
  2571. }
  2572. return 0;
  2573. }
  2574. /**
  2575. * gfx_v7_0_cp_compute_fini - stop the compute queues
  2576. *
  2577. * @adev: amdgpu_device pointer
  2578. *
  2579. * Stop the compute queues and tear down the driver queue
  2580. * info.
  2581. */
  2582. static void gfx_v7_0_cp_compute_fini(struct amdgpu_device *adev)
  2583. {
  2584. int i;
  2585. for (i = 0; i < adev->gfx.num_compute_rings; i++) {
  2586. struct amdgpu_ring *ring = &adev->gfx.compute_ring[i];
  2587. amdgpu_bo_free_kernel(&ring->mqd_obj, NULL, NULL);
  2588. }
  2589. }
  2590. static void gfx_v7_0_mec_fini(struct amdgpu_device *adev)
  2591. {
  2592. amdgpu_bo_free_kernel(&adev->gfx.mec.hpd_eop_obj, NULL, NULL);
  2593. }
  2594. static int gfx_v7_0_mec_init(struct amdgpu_device *adev)
  2595. {
  2596. int r;
  2597. u32 *hpd;
  2598. size_t mec_hpd_size;
  2599. bitmap_zero(adev->gfx.mec.queue_bitmap, AMDGPU_MAX_COMPUTE_QUEUES);
  2600. /* take ownership of the relevant compute queues */
  2601. amdgpu_gfx_compute_queue_acquire(adev);
  2602. /* allocate space for ALL pipes (even the ones we don't own) */
  2603. mec_hpd_size = adev->gfx.mec.num_mec * adev->gfx.mec.num_pipe_per_mec
  2604. * GFX7_MEC_HPD_SIZE * 2;
  2605. r = amdgpu_bo_create_reserved(adev, mec_hpd_size, PAGE_SIZE,
  2606. AMDGPU_GEM_DOMAIN_GTT,
  2607. &adev->gfx.mec.hpd_eop_obj,
  2608. &adev->gfx.mec.hpd_eop_gpu_addr,
  2609. (void **)&hpd);
  2610. if (r) {
  2611. dev_warn(adev->dev, "(%d) create, pin or map of HDP EOP bo failed\n", r);
  2612. gfx_v7_0_mec_fini(adev);
  2613. return r;
  2614. }
  2615. /* clear memory. Not sure if this is required or not */
  2616. memset(hpd, 0, mec_hpd_size);
  2617. amdgpu_bo_kunmap(adev->gfx.mec.hpd_eop_obj);
  2618. amdgpu_bo_unreserve(adev->gfx.mec.hpd_eop_obj);
  2619. return 0;
  2620. }
  2621. struct hqd_registers
  2622. {
  2623. u32 cp_mqd_base_addr;
  2624. u32 cp_mqd_base_addr_hi;
  2625. u32 cp_hqd_active;
  2626. u32 cp_hqd_vmid;
  2627. u32 cp_hqd_persistent_state;
  2628. u32 cp_hqd_pipe_priority;
  2629. u32 cp_hqd_queue_priority;
  2630. u32 cp_hqd_quantum;
  2631. u32 cp_hqd_pq_base;
  2632. u32 cp_hqd_pq_base_hi;
  2633. u32 cp_hqd_pq_rptr;
  2634. u32 cp_hqd_pq_rptr_report_addr;
  2635. u32 cp_hqd_pq_rptr_report_addr_hi;
  2636. u32 cp_hqd_pq_wptr_poll_addr;
  2637. u32 cp_hqd_pq_wptr_poll_addr_hi;
  2638. u32 cp_hqd_pq_doorbell_control;
  2639. u32 cp_hqd_pq_wptr;
  2640. u32 cp_hqd_pq_control;
  2641. u32 cp_hqd_ib_base_addr;
  2642. u32 cp_hqd_ib_base_addr_hi;
  2643. u32 cp_hqd_ib_rptr;
  2644. u32 cp_hqd_ib_control;
  2645. u32 cp_hqd_iq_timer;
  2646. u32 cp_hqd_iq_rptr;
  2647. u32 cp_hqd_dequeue_request;
  2648. u32 cp_hqd_dma_offload;
  2649. u32 cp_hqd_sema_cmd;
  2650. u32 cp_hqd_msg_type;
  2651. u32 cp_hqd_atomic0_preop_lo;
  2652. u32 cp_hqd_atomic0_preop_hi;
  2653. u32 cp_hqd_atomic1_preop_lo;
  2654. u32 cp_hqd_atomic1_preop_hi;
  2655. u32 cp_hqd_hq_scheduler0;
  2656. u32 cp_hqd_hq_scheduler1;
  2657. u32 cp_mqd_control;
  2658. };
  2659. static void gfx_v7_0_compute_pipe_init(struct amdgpu_device *adev,
  2660. int mec, int pipe)
  2661. {
  2662. u64 eop_gpu_addr;
  2663. u32 tmp;
  2664. size_t eop_offset = (mec * adev->gfx.mec.num_pipe_per_mec + pipe)
  2665. * GFX7_MEC_HPD_SIZE * 2;
  2666. mutex_lock(&adev->srbm_mutex);
  2667. eop_gpu_addr = adev->gfx.mec.hpd_eop_gpu_addr + eop_offset;
  2668. cik_srbm_select(adev, mec + 1, pipe, 0, 0);
  2669. /* write the EOP addr */
  2670. WREG32(mmCP_HPD_EOP_BASE_ADDR, eop_gpu_addr >> 8);
  2671. WREG32(mmCP_HPD_EOP_BASE_ADDR_HI, upper_32_bits(eop_gpu_addr) >> 8);
  2672. /* set the VMID assigned */
  2673. WREG32(mmCP_HPD_EOP_VMID, 0);
  2674. /* set the EOP size, register value is 2^(EOP_SIZE+1) dwords */
  2675. tmp = RREG32(mmCP_HPD_EOP_CONTROL);
  2676. tmp &= ~CP_HPD_EOP_CONTROL__EOP_SIZE_MASK;
  2677. tmp |= order_base_2(GFX7_MEC_HPD_SIZE / 8);
  2678. WREG32(mmCP_HPD_EOP_CONTROL, tmp);
  2679. cik_srbm_select(adev, 0, 0, 0, 0);
  2680. mutex_unlock(&adev->srbm_mutex);
  2681. }
  2682. static int gfx_v7_0_mqd_deactivate(struct amdgpu_device *adev)
  2683. {
  2684. int i;
  2685. /* disable the queue if it's active */
  2686. if (RREG32(mmCP_HQD_ACTIVE) & 1) {
  2687. WREG32(mmCP_HQD_DEQUEUE_REQUEST, 1);
  2688. for (i = 0; i < adev->usec_timeout; i++) {
  2689. if (!(RREG32(mmCP_HQD_ACTIVE) & 1))
  2690. break;
  2691. udelay(1);
  2692. }
  2693. if (i == adev->usec_timeout)
  2694. return -ETIMEDOUT;
  2695. WREG32(mmCP_HQD_DEQUEUE_REQUEST, 0);
  2696. WREG32(mmCP_HQD_PQ_RPTR, 0);
  2697. WREG32(mmCP_HQD_PQ_WPTR, 0);
  2698. }
  2699. return 0;
  2700. }
  2701. static void gfx_v7_0_mqd_init(struct amdgpu_device *adev,
  2702. struct cik_mqd *mqd,
  2703. uint64_t mqd_gpu_addr,
  2704. struct amdgpu_ring *ring)
  2705. {
  2706. u64 hqd_gpu_addr;
  2707. u64 wb_gpu_addr;
  2708. /* init the mqd struct */
  2709. memset(mqd, 0, sizeof(struct cik_mqd));
  2710. mqd->header = 0xC0310800;
  2711. mqd->compute_static_thread_mgmt_se0 = 0xffffffff;
  2712. mqd->compute_static_thread_mgmt_se1 = 0xffffffff;
  2713. mqd->compute_static_thread_mgmt_se2 = 0xffffffff;
  2714. mqd->compute_static_thread_mgmt_se3 = 0xffffffff;
  2715. /* enable doorbell? */
  2716. mqd->cp_hqd_pq_doorbell_control =
  2717. RREG32(mmCP_HQD_PQ_DOORBELL_CONTROL);
  2718. if (ring->use_doorbell)
  2719. mqd->cp_hqd_pq_doorbell_control |= CP_HQD_PQ_DOORBELL_CONTROL__DOORBELL_EN_MASK;
  2720. else
  2721. mqd->cp_hqd_pq_doorbell_control &= ~CP_HQD_PQ_DOORBELL_CONTROL__DOORBELL_EN_MASK;
  2722. /* set the pointer to the MQD */
  2723. mqd->cp_mqd_base_addr_lo = mqd_gpu_addr & 0xfffffffc;
  2724. mqd->cp_mqd_base_addr_hi = upper_32_bits(mqd_gpu_addr);
  2725. /* set MQD vmid to 0 */
  2726. mqd->cp_mqd_control = RREG32(mmCP_MQD_CONTROL);
  2727. mqd->cp_mqd_control &= ~CP_MQD_CONTROL__VMID_MASK;
  2728. /* set the pointer to the HQD, this is similar CP_RB0_BASE/_HI */
  2729. hqd_gpu_addr = ring->gpu_addr >> 8;
  2730. mqd->cp_hqd_pq_base_lo = hqd_gpu_addr;
  2731. mqd->cp_hqd_pq_base_hi = upper_32_bits(hqd_gpu_addr);
  2732. /* set up the HQD, this is similar to CP_RB0_CNTL */
  2733. mqd->cp_hqd_pq_control = RREG32(mmCP_HQD_PQ_CONTROL);
  2734. mqd->cp_hqd_pq_control &=
  2735. ~(CP_HQD_PQ_CONTROL__QUEUE_SIZE_MASK |
  2736. CP_HQD_PQ_CONTROL__RPTR_BLOCK_SIZE_MASK);
  2737. mqd->cp_hqd_pq_control |=
  2738. order_base_2(ring->ring_size / 8);
  2739. mqd->cp_hqd_pq_control |=
  2740. (order_base_2(AMDGPU_GPU_PAGE_SIZE/8) << 8);
  2741. #ifdef __BIG_ENDIAN
  2742. mqd->cp_hqd_pq_control |=
  2743. 2 << CP_HQD_PQ_CONTROL__ENDIAN_SWAP__SHIFT;
  2744. #endif
  2745. mqd->cp_hqd_pq_control &=
  2746. ~(CP_HQD_PQ_CONTROL__UNORD_DISPATCH_MASK |
  2747. CP_HQD_PQ_CONTROL__ROQ_PQ_IB_FLIP_MASK |
  2748. CP_HQD_PQ_CONTROL__PQ_VOLATILE_MASK);
  2749. mqd->cp_hqd_pq_control |=
  2750. CP_HQD_PQ_CONTROL__PRIV_STATE_MASK |
  2751. CP_HQD_PQ_CONTROL__KMD_QUEUE_MASK; /* assuming kernel queue control */
  2752. /* only used if CP_PQ_WPTR_POLL_CNTL.CP_PQ_WPTR_POLL_CNTL__EN_MASK=1 */
  2753. wb_gpu_addr = adev->wb.gpu_addr + (ring->wptr_offs * 4);
  2754. mqd->cp_hqd_pq_wptr_poll_addr_lo = wb_gpu_addr & 0xfffffffc;
  2755. mqd->cp_hqd_pq_wptr_poll_addr_hi = upper_32_bits(wb_gpu_addr) & 0xffff;
  2756. /* set the wb address wether it's enabled or not */
  2757. wb_gpu_addr = adev->wb.gpu_addr + (ring->rptr_offs * 4);
  2758. mqd->cp_hqd_pq_rptr_report_addr_lo = wb_gpu_addr & 0xfffffffc;
  2759. mqd->cp_hqd_pq_rptr_report_addr_hi =
  2760. upper_32_bits(wb_gpu_addr) & 0xffff;
  2761. /* enable the doorbell if requested */
  2762. if (ring->use_doorbell) {
  2763. mqd->cp_hqd_pq_doorbell_control =
  2764. RREG32(mmCP_HQD_PQ_DOORBELL_CONTROL);
  2765. mqd->cp_hqd_pq_doorbell_control &=
  2766. ~CP_HQD_PQ_DOORBELL_CONTROL__DOORBELL_OFFSET_MASK;
  2767. mqd->cp_hqd_pq_doorbell_control |=
  2768. (ring->doorbell_index <<
  2769. CP_HQD_PQ_DOORBELL_CONTROL__DOORBELL_OFFSET__SHIFT);
  2770. mqd->cp_hqd_pq_doorbell_control |=
  2771. CP_HQD_PQ_DOORBELL_CONTROL__DOORBELL_EN_MASK;
  2772. mqd->cp_hqd_pq_doorbell_control &=
  2773. ~(CP_HQD_PQ_DOORBELL_CONTROL__DOORBELL_SOURCE_MASK |
  2774. CP_HQD_PQ_DOORBELL_CONTROL__DOORBELL_HIT_MASK);
  2775. } else {
  2776. mqd->cp_hqd_pq_doorbell_control = 0;
  2777. }
  2778. /* read and write pointers, similar to CP_RB0_WPTR/_RPTR */
  2779. ring->wptr = 0;
  2780. mqd->cp_hqd_pq_wptr = lower_32_bits(ring->wptr);
  2781. mqd->cp_hqd_pq_rptr = RREG32(mmCP_HQD_PQ_RPTR);
  2782. /* set the vmid for the queue */
  2783. mqd->cp_hqd_vmid = 0;
  2784. /* defaults */
  2785. mqd->cp_hqd_ib_control = RREG32(mmCP_HQD_IB_CONTROL);
  2786. mqd->cp_hqd_ib_base_addr_lo = RREG32(mmCP_HQD_IB_BASE_ADDR);
  2787. mqd->cp_hqd_ib_base_addr_hi = RREG32(mmCP_HQD_IB_BASE_ADDR_HI);
  2788. mqd->cp_hqd_ib_rptr = RREG32(mmCP_HQD_IB_RPTR);
  2789. mqd->cp_hqd_persistent_state = RREG32(mmCP_HQD_PERSISTENT_STATE);
  2790. mqd->cp_hqd_sema_cmd = RREG32(mmCP_HQD_SEMA_CMD);
  2791. mqd->cp_hqd_msg_type = RREG32(mmCP_HQD_MSG_TYPE);
  2792. mqd->cp_hqd_atomic0_preop_lo = RREG32(mmCP_HQD_ATOMIC0_PREOP_LO);
  2793. mqd->cp_hqd_atomic0_preop_hi = RREG32(mmCP_HQD_ATOMIC0_PREOP_HI);
  2794. mqd->cp_hqd_atomic1_preop_lo = RREG32(mmCP_HQD_ATOMIC1_PREOP_LO);
  2795. mqd->cp_hqd_atomic1_preop_hi = RREG32(mmCP_HQD_ATOMIC1_PREOP_HI);
  2796. mqd->cp_hqd_pq_rptr = RREG32(mmCP_HQD_PQ_RPTR);
  2797. mqd->cp_hqd_quantum = RREG32(mmCP_HQD_QUANTUM);
  2798. mqd->cp_hqd_pipe_priority = RREG32(mmCP_HQD_PIPE_PRIORITY);
  2799. mqd->cp_hqd_queue_priority = RREG32(mmCP_HQD_QUEUE_PRIORITY);
  2800. mqd->cp_hqd_iq_rptr = RREG32(mmCP_HQD_IQ_RPTR);
  2801. /* activate the queue */
  2802. mqd->cp_hqd_active = 1;
  2803. }
  2804. int gfx_v7_0_mqd_commit(struct amdgpu_device *adev, struct cik_mqd *mqd)
  2805. {
  2806. uint32_t tmp;
  2807. uint32_t mqd_reg;
  2808. uint32_t *mqd_data;
  2809. /* HQD registers extend from mmCP_MQD_BASE_ADDR to mmCP_MQD_CONTROL */
  2810. mqd_data = &mqd->cp_mqd_base_addr_lo;
  2811. /* disable wptr polling */
  2812. tmp = RREG32(mmCP_PQ_WPTR_POLL_CNTL);
  2813. tmp = REG_SET_FIELD(tmp, CP_PQ_WPTR_POLL_CNTL, EN, 0);
  2814. WREG32(mmCP_PQ_WPTR_POLL_CNTL, tmp);
  2815. /* program all HQD registers */
  2816. for (mqd_reg = mmCP_HQD_VMID; mqd_reg <= mmCP_MQD_CONTROL; mqd_reg++)
  2817. WREG32(mqd_reg, mqd_data[mqd_reg - mmCP_MQD_BASE_ADDR]);
  2818. /* activate the HQD */
  2819. for (mqd_reg = mmCP_MQD_BASE_ADDR; mqd_reg <= mmCP_HQD_ACTIVE; mqd_reg++)
  2820. WREG32(mqd_reg, mqd_data[mqd_reg - mmCP_MQD_BASE_ADDR]);
  2821. return 0;
  2822. }
  2823. static int gfx_v7_0_compute_queue_init(struct amdgpu_device *adev, int ring_id)
  2824. {
  2825. int r;
  2826. u64 mqd_gpu_addr;
  2827. struct cik_mqd *mqd;
  2828. struct amdgpu_ring *ring = &adev->gfx.compute_ring[ring_id];
  2829. r = amdgpu_bo_create_reserved(adev, sizeof(struct cik_mqd), PAGE_SIZE,
  2830. AMDGPU_GEM_DOMAIN_GTT, &ring->mqd_obj,
  2831. &mqd_gpu_addr, (void **)&mqd);
  2832. if (r) {
  2833. dev_warn(adev->dev, "(%d) create MQD bo failed\n", r);
  2834. return r;
  2835. }
  2836. mutex_lock(&adev->srbm_mutex);
  2837. cik_srbm_select(adev, ring->me, ring->pipe, ring->queue, 0);
  2838. gfx_v7_0_mqd_init(adev, mqd, mqd_gpu_addr, ring);
  2839. gfx_v7_0_mqd_deactivate(adev);
  2840. gfx_v7_0_mqd_commit(adev, mqd);
  2841. cik_srbm_select(adev, 0, 0, 0, 0);
  2842. mutex_unlock(&adev->srbm_mutex);
  2843. amdgpu_bo_kunmap(ring->mqd_obj);
  2844. amdgpu_bo_unreserve(ring->mqd_obj);
  2845. return 0;
  2846. }
  2847. /**
  2848. * gfx_v7_0_cp_compute_resume - setup the compute queue registers
  2849. *
  2850. * @adev: amdgpu_device pointer
  2851. *
  2852. * Program the compute queues and test them to make sure they
  2853. * are working.
  2854. * Returns 0 for success, error for failure.
  2855. */
  2856. static int gfx_v7_0_cp_compute_resume(struct amdgpu_device *adev)
  2857. {
  2858. int r, i, j;
  2859. u32 tmp;
  2860. struct amdgpu_ring *ring;
  2861. /* fix up chicken bits */
  2862. tmp = RREG32(mmCP_CPF_DEBUG);
  2863. tmp |= (1 << 23);
  2864. WREG32(mmCP_CPF_DEBUG, tmp);
  2865. /* init all pipes (even the ones we don't own) */
  2866. for (i = 0; i < adev->gfx.mec.num_mec; i++)
  2867. for (j = 0; j < adev->gfx.mec.num_pipe_per_mec; j++)
  2868. gfx_v7_0_compute_pipe_init(adev, i, j);
  2869. /* init the queues */
  2870. for (i = 0; i < adev->gfx.num_compute_rings; i++) {
  2871. r = gfx_v7_0_compute_queue_init(adev, i);
  2872. if (r) {
  2873. gfx_v7_0_cp_compute_fini(adev);
  2874. return r;
  2875. }
  2876. }
  2877. gfx_v7_0_cp_compute_enable(adev, true);
  2878. for (i = 0; i < adev->gfx.num_compute_rings; i++) {
  2879. ring = &adev->gfx.compute_ring[i];
  2880. ring->ready = true;
  2881. r = amdgpu_ring_test_ring(ring);
  2882. if (r)
  2883. ring->ready = false;
  2884. }
  2885. return 0;
  2886. }
  2887. static void gfx_v7_0_cp_enable(struct amdgpu_device *adev, bool enable)
  2888. {
  2889. gfx_v7_0_cp_gfx_enable(adev, enable);
  2890. gfx_v7_0_cp_compute_enable(adev, enable);
  2891. }
  2892. static int gfx_v7_0_cp_load_microcode(struct amdgpu_device *adev)
  2893. {
  2894. int r;
  2895. r = gfx_v7_0_cp_gfx_load_microcode(adev);
  2896. if (r)
  2897. return r;
  2898. r = gfx_v7_0_cp_compute_load_microcode(adev);
  2899. if (r)
  2900. return r;
  2901. return 0;
  2902. }
  2903. static void gfx_v7_0_enable_gui_idle_interrupt(struct amdgpu_device *adev,
  2904. bool enable)
  2905. {
  2906. u32 tmp = RREG32(mmCP_INT_CNTL_RING0);
  2907. if (enable)
  2908. tmp |= (CP_INT_CNTL_RING0__CNTX_BUSY_INT_ENABLE_MASK |
  2909. CP_INT_CNTL_RING0__CNTX_EMPTY_INT_ENABLE_MASK);
  2910. else
  2911. tmp &= ~(CP_INT_CNTL_RING0__CNTX_BUSY_INT_ENABLE_MASK |
  2912. CP_INT_CNTL_RING0__CNTX_EMPTY_INT_ENABLE_MASK);
  2913. WREG32(mmCP_INT_CNTL_RING0, tmp);
  2914. }
  2915. static int gfx_v7_0_cp_resume(struct amdgpu_device *adev)
  2916. {
  2917. int r;
  2918. gfx_v7_0_enable_gui_idle_interrupt(adev, false);
  2919. r = gfx_v7_0_cp_load_microcode(adev);
  2920. if (r)
  2921. return r;
  2922. r = gfx_v7_0_cp_gfx_resume(adev);
  2923. if (r)
  2924. return r;
  2925. r = gfx_v7_0_cp_compute_resume(adev);
  2926. if (r)
  2927. return r;
  2928. gfx_v7_0_enable_gui_idle_interrupt(adev, true);
  2929. return 0;
  2930. }
  2931. /**
  2932. * gfx_v7_0_ring_emit_vm_flush - cik vm flush using the CP
  2933. *
  2934. * @ring: the ring to emmit the commands to
  2935. *
  2936. * Sync the command pipeline with the PFP. E.g. wait for everything
  2937. * to be completed.
  2938. */
  2939. static void gfx_v7_0_ring_emit_pipeline_sync(struct amdgpu_ring *ring)
  2940. {
  2941. int usepfp = (ring->funcs->type == AMDGPU_RING_TYPE_GFX);
  2942. uint32_t seq = ring->fence_drv.sync_seq;
  2943. uint64_t addr = ring->fence_drv.gpu_addr;
  2944. amdgpu_ring_write(ring, PACKET3(PACKET3_WAIT_REG_MEM, 5));
  2945. amdgpu_ring_write(ring, (WAIT_REG_MEM_MEM_SPACE(1) | /* memory */
  2946. WAIT_REG_MEM_FUNCTION(3) | /* equal */
  2947. WAIT_REG_MEM_ENGINE(usepfp))); /* pfp or me */
  2948. amdgpu_ring_write(ring, addr & 0xfffffffc);
  2949. amdgpu_ring_write(ring, upper_32_bits(addr) & 0xffffffff);
  2950. amdgpu_ring_write(ring, seq);
  2951. amdgpu_ring_write(ring, 0xffffffff);
  2952. amdgpu_ring_write(ring, 4); /* poll interval */
  2953. if (usepfp) {
  2954. /* synce CE with ME to prevent CE fetch CEIB before context switch done */
  2955. amdgpu_ring_write(ring, PACKET3(PACKET3_SWITCH_BUFFER, 0));
  2956. amdgpu_ring_write(ring, 0);
  2957. amdgpu_ring_write(ring, PACKET3(PACKET3_SWITCH_BUFFER, 0));
  2958. amdgpu_ring_write(ring, 0);
  2959. }
  2960. }
  2961. /*
  2962. * vm
  2963. * VMID 0 is the physical GPU addresses as used by the kernel.
  2964. * VMIDs 1-15 are used for userspace clients and are handled
  2965. * by the amdgpu vm/hsa code.
  2966. */
  2967. /**
  2968. * gfx_v7_0_ring_emit_vm_flush - cik vm flush using the CP
  2969. *
  2970. * @adev: amdgpu_device pointer
  2971. *
  2972. * Update the page table base and flush the VM TLB
  2973. * using the CP (CIK).
  2974. */
  2975. static void gfx_v7_0_ring_emit_vm_flush(struct amdgpu_ring *ring,
  2976. unsigned vm_id, uint64_t pd_addr)
  2977. {
  2978. int usepfp = (ring->funcs->type == AMDGPU_RING_TYPE_GFX);
  2979. amdgpu_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  2980. amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(usepfp) |
  2981. WRITE_DATA_DST_SEL(0)));
  2982. if (vm_id < 8) {
  2983. amdgpu_ring_write(ring,
  2984. (mmVM_CONTEXT0_PAGE_TABLE_BASE_ADDR + vm_id));
  2985. } else {
  2986. amdgpu_ring_write(ring,
  2987. (mmVM_CONTEXT8_PAGE_TABLE_BASE_ADDR + vm_id - 8));
  2988. }
  2989. amdgpu_ring_write(ring, 0);
  2990. amdgpu_ring_write(ring, pd_addr >> 12);
  2991. /* bits 0-15 are the VM contexts0-15 */
  2992. amdgpu_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  2993. amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
  2994. WRITE_DATA_DST_SEL(0)));
  2995. amdgpu_ring_write(ring, mmVM_INVALIDATE_REQUEST);
  2996. amdgpu_ring_write(ring, 0);
  2997. amdgpu_ring_write(ring, 1 << vm_id);
  2998. /* wait for the invalidate to complete */
  2999. amdgpu_ring_write(ring, PACKET3(PACKET3_WAIT_REG_MEM, 5));
  3000. amdgpu_ring_write(ring, (WAIT_REG_MEM_OPERATION(0) | /* wait */
  3001. WAIT_REG_MEM_FUNCTION(0) | /* always */
  3002. WAIT_REG_MEM_ENGINE(0))); /* me */
  3003. amdgpu_ring_write(ring, mmVM_INVALIDATE_REQUEST);
  3004. amdgpu_ring_write(ring, 0);
  3005. amdgpu_ring_write(ring, 0); /* ref */
  3006. amdgpu_ring_write(ring, 0); /* mask */
  3007. amdgpu_ring_write(ring, 0x20); /* poll interval */
  3008. /* compute doesn't have PFP */
  3009. if (usepfp) {
  3010. /* sync PFP to ME, otherwise we might get invalid PFP reads */
  3011. amdgpu_ring_write(ring, PACKET3(PACKET3_PFP_SYNC_ME, 0));
  3012. amdgpu_ring_write(ring, 0x0);
  3013. /* synce CE with ME to prevent CE fetch CEIB before context switch done */
  3014. amdgpu_ring_write(ring, PACKET3(PACKET3_SWITCH_BUFFER, 0));
  3015. amdgpu_ring_write(ring, 0);
  3016. amdgpu_ring_write(ring, PACKET3(PACKET3_SWITCH_BUFFER, 0));
  3017. amdgpu_ring_write(ring, 0);
  3018. }
  3019. }
  3020. /*
  3021. * RLC
  3022. * The RLC is a multi-purpose microengine that handles a
  3023. * variety of functions.
  3024. */
  3025. static void gfx_v7_0_rlc_fini(struct amdgpu_device *adev)
  3026. {
  3027. amdgpu_bo_free_kernel(&adev->gfx.rlc.save_restore_obj, NULL, NULL);
  3028. amdgpu_bo_free_kernel(&adev->gfx.rlc.clear_state_obj, NULL, NULL);
  3029. amdgpu_bo_free_kernel(&adev->gfx.rlc.cp_table_obj, NULL, NULL);
  3030. }
  3031. static int gfx_v7_0_rlc_init(struct amdgpu_device *adev)
  3032. {
  3033. const u32 *src_ptr;
  3034. volatile u32 *dst_ptr;
  3035. u32 dws, i;
  3036. const struct cs_section_def *cs_data;
  3037. int r;
  3038. /* allocate rlc buffers */
  3039. if (adev->flags & AMD_IS_APU) {
  3040. if (adev->asic_type == CHIP_KAVERI) {
  3041. adev->gfx.rlc.reg_list = spectre_rlc_save_restore_register_list;
  3042. adev->gfx.rlc.reg_list_size =
  3043. (u32)ARRAY_SIZE(spectre_rlc_save_restore_register_list);
  3044. } else {
  3045. adev->gfx.rlc.reg_list = kalindi_rlc_save_restore_register_list;
  3046. adev->gfx.rlc.reg_list_size =
  3047. (u32)ARRAY_SIZE(kalindi_rlc_save_restore_register_list);
  3048. }
  3049. }
  3050. adev->gfx.rlc.cs_data = ci_cs_data;
  3051. adev->gfx.rlc.cp_table_size = ALIGN(CP_ME_TABLE_SIZE * 5 * 4, 2048); /* CP JT */
  3052. adev->gfx.rlc.cp_table_size += 64 * 1024; /* GDS */
  3053. src_ptr = adev->gfx.rlc.reg_list;
  3054. dws = adev->gfx.rlc.reg_list_size;
  3055. dws += (5 * 16) + 48 + 48 + 64;
  3056. cs_data = adev->gfx.rlc.cs_data;
  3057. if (src_ptr) {
  3058. /* save restore block */
  3059. r = amdgpu_bo_create_reserved(adev, dws * 4, PAGE_SIZE,
  3060. AMDGPU_GEM_DOMAIN_VRAM,
  3061. &adev->gfx.rlc.save_restore_obj,
  3062. &adev->gfx.rlc.save_restore_gpu_addr,
  3063. (void **)&adev->gfx.rlc.sr_ptr);
  3064. if (r) {
  3065. dev_warn(adev->dev, "(%d) create, pin or map of RLC sr bo failed\n", r);
  3066. gfx_v7_0_rlc_fini(adev);
  3067. return r;
  3068. }
  3069. /* write the sr buffer */
  3070. dst_ptr = adev->gfx.rlc.sr_ptr;
  3071. for (i = 0; i < adev->gfx.rlc.reg_list_size; i++)
  3072. dst_ptr[i] = cpu_to_le32(src_ptr[i]);
  3073. amdgpu_bo_kunmap(adev->gfx.rlc.save_restore_obj);
  3074. amdgpu_bo_unreserve(adev->gfx.rlc.save_restore_obj);
  3075. }
  3076. if (cs_data) {
  3077. /* clear state block */
  3078. adev->gfx.rlc.clear_state_size = dws = gfx_v7_0_get_csb_size(adev);
  3079. r = amdgpu_bo_create_reserved(adev, dws * 4, PAGE_SIZE,
  3080. AMDGPU_GEM_DOMAIN_VRAM,
  3081. &adev->gfx.rlc.clear_state_obj,
  3082. &adev->gfx.rlc.clear_state_gpu_addr,
  3083. (void **)&adev->gfx.rlc.cs_ptr);
  3084. if (r) {
  3085. dev_warn(adev->dev, "(%d) create RLC c bo failed\n", r);
  3086. gfx_v7_0_rlc_fini(adev);
  3087. return r;
  3088. }
  3089. /* set up the cs buffer */
  3090. dst_ptr = adev->gfx.rlc.cs_ptr;
  3091. gfx_v7_0_get_csb_buffer(adev, dst_ptr);
  3092. amdgpu_bo_kunmap(adev->gfx.rlc.clear_state_obj);
  3093. amdgpu_bo_unreserve(adev->gfx.rlc.clear_state_obj);
  3094. }
  3095. if (adev->gfx.rlc.cp_table_size) {
  3096. r = amdgpu_bo_create_reserved(adev, adev->gfx.rlc.cp_table_size,
  3097. PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM,
  3098. &adev->gfx.rlc.cp_table_obj,
  3099. &adev->gfx.rlc.cp_table_gpu_addr,
  3100. (void **)&adev->gfx.rlc.cp_table_ptr);
  3101. if (r) {
  3102. dev_warn(adev->dev, "(%d) create RLC cp table bo failed\n", r);
  3103. gfx_v7_0_rlc_fini(adev);
  3104. return r;
  3105. }
  3106. gfx_v7_0_init_cp_pg_table(adev);
  3107. amdgpu_bo_kunmap(adev->gfx.rlc.cp_table_obj);
  3108. amdgpu_bo_unreserve(adev->gfx.rlc.cp_table_obj);
  3109. }
  3110. return 0;
  3111. }
  3112. static void gfx_v7_0_enable_lbpw(struct amdgpu_device *adev, bool enable)
  3113. {
  3114. u32 tmp;
  3115. tmp = RREG32(mmRLC_LB_CNTL);
  3116. if (enable)
  3117. tmp |= RLC_LB_CNTL__LOAD_BALANCE_ENABLE_MASK;
  3118. else
  3119. tmp &= ~RLC_LB_CNTL__LOAD_BALANCE_ENABLE_MASK;
  3120. WREG32(mmRLC_LB_CNTL, tmp);
  3121. }
  3122. static void gfx_v7_0_wait_for_rlc_serdes(struct amdgpu_device *adev)
  3123. {
  3124. u32 i, j, k;
  3125. u32 mask;
  3126. mutex_lock(&adev->grbm_idx_mutex);
  3127. for (i = 0; i < adev->gfx.config.max_shader_engines; i++) {
  3128. for (j = 0; j < adev->gfx.config.max_sh_per_se; j++) {
  3129. gfx_v7_0_select_se_sh(adev, i, j, 0xffffffff);
  3130. for (k = 0; k < adev->usec_timeout; k++) {
  3131. if (RREG32(mmRLC_SERDES_CU_MASTER_BUSY) == 0)
  3132. break;
  3133. udelay(1);
  3134. }
  3135. }
  3136. }
  3137. gfx_v7_0_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
  3138. mutex_unlock(&adev->grbm_idx_mutex);
  3139. mask = RLC_SERDES_NONCU_MASTER_BUSY__SE_MASTER_BUSY_MASK |
  3140. RLC_SERDES_NONCU_MASTER_BUSY__GC_MASTER_BUSY_MASK |
  3141. RLC_SERDES_NONCU_MASTER_BUSY__TC0_MASTER_BUSY_MASK |
  3142. RLC_SERDES_NONCU_MASTER_BUSY__TC1_MASTER_BUSY_MASK;
  3143. for (k = 0; k < adev->usec_timeout; k++) {
  3144. if ((RREG32(mmRLC_SERDES_NONCU_MASTER_BUSY) & mask) == 0)
  3145. break;
  3146. udelay(1);
  3147. }
  3148. }
  3149. static void gfx_v7_0_update_rlc(struct amdgpu_device *adev, u32 rlc)
  3150. {
  3151. u32 tmp;
  3152. tmp = RREG32(mmRLC_CNTL);
  3153. if (tmp != rlc)
  3154. WREG32(mmRLC_CNTL, rlc);
  3155. }
  3156. static u32 gfx_v7_0_halt_rlc(struct amdgpu_device *adev)
  3157. {
  3158. u32 data, orig;
  3159. orig = data = RREG32(mmRLC_CNTL);
  3160. if (data & RLC_CNTL__RLC_ENABLE_F32_MASK) {
  3161. u32 i;
  3162. data &= ~RLC_CNTL__RLC_ENABLE_F32_MASK;
  3163. WREG32(mmRLC_CNTL, data);
  3164. for (i = 0; i < adev->usec_timeout; i++) {
  3165. if ((RREG32(mmRLC_GPM_STAT) & RLC_GPM_STAT__RLC_BUSY_MASK) == 0)
  3166. break;
  3167. udelay(1);
  3168. }
  3169. gfx_v7_0_wait_for_rlc_serdes(adev);
  3170. }
  3171. return orig;
  3172. }
  3173. static void gfx_v7_0_enter_rlc_safe_mode(struct amdgpu_device *adev)
  3174. {
  3175. u32 tmp, i, mask;
  3176. tmp = 0x1 | (1 << 1);
  3177. WREG32(mmRLC_GPR_REG2, tmp);
  3178. mask = RLC_GPM_STAT__GFX_POWER_STATUS_MASK |
  3179. RLC_GPM_STAT__GFX_CLOCK_STATUS_MASK;
  3180. for (i = 0; i < adev->usec_timeout; i++) {
  3181. if ((RREG32(mmRLC_GPM_STAT) & mask) == mask)
  3182. break;
  3183. udelay(1);
  3184. }
  3185. for (i = 0; i < adev->usec_timeout; i++) {
  3186. if ((RREG32(mmRLC_GPR_REG2) & 0x1) == 0)
  3187. break;
  3188. udelay(1);
  3189. }
  3190. }
  3191. static void gfx_v7_0_exit_rlc_safe_mode(struct amdgpu_device *adev)
  3192. {
  3193. u32 tmp;
  3194. tmp = 0x1 | (0 << 1);
  3195. WREG32(mmRLC_GPR_REG2, tmp);
  3196. }
  3197. /**
  3198. * gfx_v7_0_rlc_stop - stop the RLC ME
  3199. *
  3200. * @adev: amdgpu_device pointer
  3201. *
  3202. * Halt the RLC ME (MicroEngine) (CIK).
  3203. */
  3204. static void gfx_v7_0_rlc_stop(struct amdgpu_device *adev)
  3205. {
  3206. WREG32(mmRLC_CNTL, 0);
  3207. gfx_v7_0_enable_gui_idle_interrupt(adev, false);
  3208. gfx_v7_0_wait_for_rlc_serdes(adev);
  3209. }
  3210. /**
  3211. * gfx_v7_0_rlc_start - start the RLC ME
  3212. *
  3213. * @adev: amdgpu_device pointer
  3214. *
  3215. * Unhalt the RLC ME (MicroEngine) (CIK).
  3216. */
  3217. static void gfx_v7_0_rlc_start(struct amdgpu_device *adev)
  3218. {
  3219. WREG32(mmRLC_CNTL, RLC_CNTL__RLC_ENABLE_F32_MASK);
  3220. gfx_v7_0_enable_gui_idle_interrupt(adev, true);
  3221. udelay(50);
  3222. }
  3223. static void gfx_v7_0_rlc_reset(struct amdgpu_device *adev)
  3224. {
  3225. u32 tmp = RREG32(mmGRBM_SOFT_RESET);
  3226. tmp |= GRBM_SOFT_RESET__SOFT_RESET_RLC_MASK;
  3227. WREG32(mmGRBM_SOFT_RESET, tmp);
  3228. udelay(50);
  3229. tmp &= ~GRBM_SOFT_RESET__SOFT_RESET_RLC_MASK;
  3230. WREG32(mmGRBM_SOFT_RESET, tmp);
  3231. udelay(50);
  3232. }
  3233. /**
  3234. * gfx_v7_0_rlc_resume - setup the RLC hw
  3235. *
  3236. * @adev: amdgpu_device pointer
  3237. *
  3238. * Initialize the RLC registers, load the ucode,
  3239. * and start the RLC (CIK).
  3240. * Returns 0 for success, -EINVAL if the ucode is not available.
  3241. */
  3242. static int gfx_v7_0_rlc_resume(struct amdgpu_device *adev)
  3243. {
  3244. const struct rlc_firmware_header_v1_0 *hdr;
  3245. const __le32 *fw_data;
  3246. unsigned i, fw_size;
  3247. u32 tmp;
  3248. if (!adev->gfx.rlc_fw)
  3249. return -EINVAL;
  3250. hdr = (const struct rlc_firmware_header_v1_0 *)adev->gfx.rlc_fw->data;
  3251. amdgpu_ucode_print_rlc_hdr(&hdr->header);
  3252. adev->gfx.rlc_fw_version = le32_to_cpu(hdr->header.ucode_version);
  3253. adev->gfx.rlc_feature_version = le32_to_cpu(
  3254. hdr->ucode_feature_version);
  3255. gfx_v7_0_rlc_stop(adev);
  3256. /* disable CG */
  3257. tmp = RREG32(mmRLC_CGCG_CGLS_CTRL) & 0xfffffffc;
  3258. WREG32(mmRLC_CGCG_CGLS_CTRL, tmp);
  3259. gfx_v7_0_rlc_reset(adev);
  3260. gfx_v7_0_init_pg(adev);
  3261. WREG32(mmRLC_LB_CNTR_INIT, 0);
  3262. WREG32(mmRLC_LB_CNTR_MAX, 0x00008000);
  3263. mutex_lock(&adev->grbm_idx_mutex);
  3264. gfx_v7_0_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
  3265. WREG32(mmRLC_LB_INIT_CU_MASK, 0xffffffff);
  3266. WREG32(mmRLC_LB_PARAMS, 0x00600408);
  3267. WREG32(mmRLC_LB_CNTL, 0x80000004);
  3268. mutex_unlock(&adev->grbm_idx_mutex);
  3269. WREG32(mmRLC_MC_CNTL, 0);
  3270. WREG32(mmRLC_UCODE_CNTL, 0);
  3271. fw_data = (const __le32 *)
  3272. (adev->gfx.rlc_fw->data + le32_to_cpu(hdr->header.ucode_array_offset_bytes));
  3273. fw_size = le32_to_cpu(hdr->header.ucode_size_bytes) / 4;
  3274. WREG32(mmRLC_GPM_UCODE_ADDR, 0);
  3275. for (i = 0; i < fw_size; i++)
  3276. WREG32(mmRLC_GPM_UCODE_DATA, le32_to_cpup(fw_data++));
  3277. WREG32(mmRLC_GPM_UCODE_ADDR, adev->gfx.rlc_fw_version);
  3278. /* XXX - find out what chips support lbpw */
  3279. gfx_v7_0_enable_lbpw(adev, false);
  3280. if (adev->asic_type == CHIP_BONAIRE)
  3281. WREG32(mmRLC_DRIVER_CPDMA_STATUS, 0);
  3282. gfx_v7_0_rlc_start(adev);
  3283. return 0;
  3284. }
  3285. static void gfx_v7_0_enable_cgcg(struct amdgpu_device *adev, bool enable)
  3286. {
  3287. u32 data, orig, tmp, tmp2;
  3288. orig = data = RREG32(mmRLC_CGCG_CGLS_CTRL);
  3289. if (enable && (adev->cg_flags & AMD_CG_SUPPORT_GFX_CGCG)) {
  3290. gfx_v7_0_enable_gui_idle_interrupt(adev, true);
  3291. tmp = gfx_v7_0_halt_rlc(adev);
  3292. mutex_lock(&adev->grbm_idx_mutex);
  3293. gfx_v7_0_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
  3294. WREG32(mmRLC_SERDES_WR_CU_MASTER_MASK, 0xffffffff);
  3295. WREG32(mmRLC_SERDES_WR_NONCU_MASTER_MASK, 0xffffffff);
  3296. tmp2 = RLC_SERDES_WR_CTRL__BPM_ADDR_MASK |
  3297. RLC_SERDES_WR_CTRL__CGCG_OVERRIDE_0_MASK |
  3298. RLC_SERDES_WR_CTRL__CGLS_ENABLE_MASK;
  3299. WREG32(mmRLC_SERDES_WR_CTRL, tmp2);
  3300. mutex_unlock(&adev->grbm_idx_mutex);
  3301. gfx_v7_0_update_rlc(adev, tmp);
  3302. data |= RLC_CGCG_CGLS_CTRL__CGCG_EN_MASK | RLC_CGCG_CGLS_CTRL__CGLS_EN_MASK;
  3303. if (orig != data)
  3304. WREG32(mmRLC_CGCG_CGLS_CTRL, data);
  3305. } else {
  3306. gfx_v7_0_enable_gui_idle_interrupt(adev, false);
  3307. RREG32(mmCB_CGTT_SCLK_CTRL);
  3308. RREG32(mmCB_CGTT_SCLK_CTRL);
  3309. RREG32(mmCB_CGTT_SCLK_CTRL);
  3310. RREG32(mmCB_CGTT_SCLK_CTRL);
  3311. data &= ~(RLC_CGCG_CGLS_CTRL__CGCG_EN_MASK | RLC_CGCG_CGLS_CTRL__CGLS_EN_MASK);
  3312. if (orig != data)
  3313. WREG32(mmRLC_CGCG_CGLS_CTRL, data);
  3314. gfx_v7_0_enable_gui_idle_interrupt(adev, true);
  3315. }
  3316. }
  3317. static void gfx_v7_0_enable_mgcg(struct amdgpu_device *adev, bool enable)
  3318. {
  3319. u32 data, orig, tmp = 0;
  3320. if (enable && (adev->cg_flags & AMD_CG_SUPPORT_GFX_MGCG)) {
  3321. if (adev->cg_flags & AMD_CG_SUPPORT_GFX_MGLS) {
  3322. if (adev->cg_flags & AMD_CG_SUPPORT_GFX_CP_LS) {
  3323. orig = data = RREG32(mmCP_MEM_SLP_CNTL);
  3324. data |= CP_MEM_SLP_CNTL__CP_MEM_LS_EN_MASK;
  3325. if (orig != data)
  3326. WREG32(mmCP_MEM_SLP_CNTL, data);
  3327. }
  3328. }
  3329. orig = data = RREG32(mmRLC_CGTT_MGCG_OVERRIDE);
  3330. data |= 0x00000001;
  3331. data &= 0xfffffffd;
  3332. if (orig != data)
  3333. WREG32(mmRLC_CGTT_MGCG_OVERRIDE, data);
  3334. tmp = gfx_v7_0_halt_rlc(adev);
  3335. mutex_lock(&adev->grbm_idx_mutex);
  3336. gfx_v7_0_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
  3337. WREG32(mmRLC_SERDES_WR_CU_MASTER_MASK, 0xffffffff);
  3338. WREG32(mmRLC_SERDES_WR_NONCU_MASTER_MASK, 0xffffffff);
  3339. data = RLC_SERDES_WR_CTRL__BPM_ADDR_MASK |
  3340. RLC_SERDES_WR_CTRL__MGCG_OVERRIDE_0_MASK;
  3341. WREG32(mmRLC_SERDES_WR_CTRL, data);
  3342. mutex_unlock(&adev->grbm_idx_mutex);
  3343. gfx_v7_0_update_rlc(adev, tmp);
  3344. if (adev->cg_flags & AMD_CG_SUPPORT_GFX_CGTS) {
  3345. orig = data = RREG32(mmCGTS_SM_CTRL_REG);
  3346. data &= ~CGTS_SM_CTRL_REG__SM_MODE_MASK;
  3347. data |= (0x2 << CGTS_SM_CTRL_REG__SM_MODE__SHIFT);
  3348. data |= CGTS_SM_CTRL_REG__SM_MODE_ENABLE_MASK;
  3349. data &= ~CGTS_SM_CTRL_REG__OVERRIDE_MASK;
  3350. if ((adev->cg_flags & AMD_CG_SUPPORT_GFX_MGLS) &&
  3351. (adev->cg_flags & AMD_CG_SUPPORT_GFX_CGTS_LS))
  3352. data &= ~CGTS_SM_CTRL_REG__LS_OVERRIDE_MASK;
  3353. data &= ~CGTS_SM_CTRL_REG__ON_MONITOR_ADD_MASK;
  3354. data |= CGTS_SM_CTRL_REG__ON_MONITOR_ADD_EN_MASK;
  3355. data |= (0x96 << CGTS_SM_CTRL_REG__ON_MONITOR_ADD__SHIFT);
  3356. if (orig != data)
  3357. WREG32(mmCGTS_SM_CTRL_REG, data);
  3358. }
  3359. } else {
  3360. orig = data = RREG32(mmRLC_CGTT_MGCG_OVERRIDE);
  3361. data |= 0x00000003;
  3362. if (orig != data)
  3363. WREG32(mmRLC_CGTT_MGCG_OVERRIDE, data);
  3364. data = RREG32(mmRLC_MEM_SLP_CNTL);
  3365. if (data & RLC_MEM_SLP_CNTL__RLC_MEM_LS_EN_MASK) {
  3366. data &= ~RLC_MEM_SLP_CNTL__RLC_MEM_LS_EN_MASK;
  3367. WREG32(mmRLC_MEM_SLP_CNTL, data);
  3368. }
  3369. data = RREG32(mmCP_MEM_SLP_CNTL);
  3370. if (data & CP_MEM_SLP_CNTL__CP_MEM_LS_EN_MASK) {
  3371. data &= ~CP_MEM_SLP_CNTL__CP_MEM_LS_EN_MASK;
  3372. WREG32(mmCP_MEM_SLP_CNTL, data);
  3373. }
  3374. orig = data = RREG32(mmCGTS_SM_CTRL_REG);
  3375. data |= CGTS_SM_CTRL_REG__OVERRIDE_MASK | CGTS_SM_CTRL_REG__LS_OVERRIDE_MASK;
  3376. if (orig != data)
  3377. WREG32(mmCGTS_SM_CTRL_REG, data);
  3378. tmp = gfx_v7_0_halt_rlc(adev);
  3379. mutex_lock(&adev->grbm_idx_mutex);
  3380. gfx_v7_0_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
  3381. WREG32(mmRLC_SERDES_WR_CU_MASTER_MASK, 0xffffffff);
  3382. WREG32(mmRLC_SERDES_WR_NONCU_MASTER_MASK, 0xffffffff);
  3383. data = RLC_SERDES_WR_CTRL__BPM_ADDR_MASK | RLC_SERDES_WR_CTRL__MGCG_OVERRIDE_1_MASK;
  3384. WREG32(mmRLC_SERDES_WR_CTRL, data);
  3385. mutex_unlock(&adev->grbm_idx_mutex);
  3386. gfx_v7_0_update_rlc(adev, tmp);
  3387. }
  3388. }
  3389. static void gfx_v7_0_update_cg(struct amdgpu_device *adev,
  3390. bool enable)
  3391. {
  3392. gfx_v7_0_enable_gui_idle_interrupt(adev, false);
  3393. /* order matters! */
  3394. if (enable) {
  3395. gfx_v7_0_enable_mgcg(adev, true);
  3396. gfx_v7_0_enable_cgcg(adev, true);
  3397. } else {
  3398. gfx_v7_0_enable_cgcg(adev, false);
  3399. gfx_v7_0_enable_mgcg(adev, false);
  3400. }
  3401. gfx_v7_0_enable_gui_idle_interrupt(adev, true);
  3402. }
  3403. static void gfx_v7_0_enable_sclk_slowdown_on_pu(struct amdgpu_device *adev,
  3404. bool enable)
  3405. {
  3406. u32 data, orig;
  3407. orig = data = RREG32(mmRLC_PG_CNTL);
  3408. if (enable && (adev->pg_flags & AMD_PG_SUPPORT_RLC_SMU_HS))
  3409. data |= RLC_PG_CNTL__SMU_CLK_SLOWDOWN_ON_PU_ENABLE_MASK;
  3410. else
  3411. data &= ~RLC_PG_CNTL__SMU_CLK_SLOWDOWN_ON_PU_ENABLE_MASK;
  3412. if (orig != data)
  3413. WREG32(mmRLC_PG_CNTL, data);
  3414. }
  3415. static void gfx_v7_0_enable_sclk_slowdown_on_pd(struct amdgpu_device *adev,
  3416. bool enable)
  3417. {
  3418. u32 data, orig;
  3419. orig = data = RREG32(mmRLC_PG_CNTL);
  3420. if (enable && (adev->pg_flags & AMD_PG_SUPPORT_RLC_SMU_HS))
  3421. data |= RLC_PG_CNTL__SMU_CLK_SLOWDOWN_ON_PD_ENABLE_MASK;
  3422. else
  3423. data &= ~RLC_PG_CNTL__SMU_CLK_SLOWDOWN_ON_PD_ENABLE_MASK;
  3424. if (orig != data)
  3425. WREG32(mmRLC_PG_CNTL, data);
  3426. }
  3427. static void gfx_v7_0_enable_cp_pg(struct amdgpu_device *adev, bool enable)
  3428. {
  3429. u32 data, orig;
  3430. orig = data = RREG32(mmRLC_PG_CNTL);
  3431. if (enable && (adev->pg_flags & AMD_PG_SUPPORT_CP))
  3432. data &= ~0x8000;
  3433. else
  3434. data |= 0x8000;
  3435. if (orig != data)
  3436. WREG32(mmRLC_PG_CNTL, data);
  3437. }
  3438. static void gfx_v7_0_enable_gds_pg(struct amdgpu_device *adev, bool enable)
  3439. {
  3440. u32 data, orig;
  3441. orig = data = RREG32(mmRLC_PG_CNTL);
  3442. if (enable && (adev->pg_flags & AMD_PG_SUPPORT_GDS))
  3443. data &= ~0x2000;
  3444. else
  3445. data |= 0x2000;
  3446. if (orig != data)
  3447. WREG32(mmRLC_PG_CNTL, data);
  3448. }
  3449. static void gfx_v7_0_init_cp_pg_table(struct amdgpu_device *adev)
  3450. {
  3451. const __le32 *fw_data;
  3452. volatile u32 *dst_ptr;
  3453. int me, i, max_me = 4;
  3454. u32 bo_offset = 0;
  3455. u32 table_offset, table_size;
  3456. if (adev->asic_type == CHIP_KAVERI)
  3457. max_me = 5;
  3458. if (adev->gfx.rlc.cp_table_ptr == NULL)
  3459. return;
  3460. /* write the cp table buffer */
  3461. dst_ptr = adev->gfx.rlc.cp_table_ptr;
  3462. for (me = 0; me < max_me; me++) {
  3463. if (me == 0) {
  3464. const struct gfx_firmware_header_v1_0 *hdr =
  3465. (const struct gfx_firmware_header_v1_0 *)adev->gfx.ce_fw->data;
  3466. fw_data = (const __le32 *)
  3467. (adev->gfx.ce_fw->data +
  3468. le32_to_cpu(hdr->header.ucode_array_offset_bytes));
  3469. table_offset = le32_to_cpu(hdr->jt_offset);
  3470. table_size = le32_to_cpu(hdr->jt_size);
  3471. } else if (me == 1) {
  3472. const struct gfx_firmware_header_v1_0 *hdr =
  3473. (const struct gfx_firmware_header_v1_0 *)adev->gfx.pfp_fw->data;
  3474. fw_data = (const __le32 *)
  3475. (adev->gfx.pfp_fw->data +
  3476. le32_to_cpu(hdr->header.ucode_array_offset_bytes));
  3477. table_offset = le32_to_cpu(hdr->jt_offset);
  3478. table_size = le32_to_cpu(hdr->jt_size);
  3479. } else if (me == 2) {
  3480. const struct gfx_firmware_header_v1_0 *hdr =
  3481. (const struct gfx_firmware_header_v1_0 *)adev->gfx.me_fw->data;
  3482. fw_data = (const __le32 *)
  3483. (adev->gfx.me_fw->data +
  3484. le32_to_cpu(hdr->header.ucode_array_offset_bytes));
  3485. table_offset = le32_to_cpu(hdr->jt_offset);
  3486. table_size = le32_to_cpu(hdr->jt_size);
  3487. } else if (me == 3) {
  3488. const struct gfx_firmware_header_v1_0 *hdr =
  3489. (const struct gfx_firmware_header_v1_0 *)adev->gfx.mec_fw->data;
  3490. fw_data = (const __le32 *)
  3491. (adev->gfx.mec_fw->data +
  3492. le32_to_cpu(hdr->header.ucode_array_offset_bytes));
  3493. table_offset = le32_to_cpu(hdr->jt_offset);
  3494. table_size = le32_to_cpu(hdr->jt_size);
  3495. } else {
  3496. const struct gfx_firmware_header_v1_0 *hdr =
  3497. (const struct gfx_firmware_header_v1_0 *)adev->gfx.mec2_fw->data;
  3498. fw_data = (const __le32 *)
  3499. (adev->gfx.mec2_fw->data +
  3500. le32_to_cpu(hdr->header.ucode_array_offset_bytes));
  3501. table_offset = le32_to_cpu(hdr->jt_offset);
  3502. table_size = le32_to_cpu(hdr->jt_size);
  3503. }
  3504. for (i = 0; i < table_size; i ++) {
  3505. dst_ptr[bo_offset + i] =
  3506. cpu_to_le32(le32_to_cpu(fw_data[table_offset + i]));
  3507. }
  3508. bo_offset += table_size;
  3509. }
  3510. }
  3511. static void gfx_v7_0_enable_gfx_cgpg(struct amdgpu_device *adev,
  3512. bool enable)
  3513. {
  3514. u32 data, orig;
  3515. if (enable && (adev->pg_flags & AMD_PG_SUPPORT_GFX_PG)) {
  3516. orig = data = RREG32(mmRLC_PG_CNTL);
  3517. data |= RLC_PG_CNTL__GFX_POWER_GATING_ENABLE_MASK;
  3518. if (orig != data)
  3519. WREG32(mmRLC_PG_CNTL, data);
  3520. orig = data = RREG32(mmRLC_AUTO_PG_CTRL);
  3521. data |= RLC_AUTO_PG_CTRL__AUTO_PG_EN_MASK;
  3522. if (orig != data)
  3523. WREG32(mmRLC_AUTO_PG_CTRL, data);
  3524. } else {
  3525. orig = data = RREG32(mmRLC_PG_CNTL);
  3526. data &= ~RLC_PG_CNTL__GFX_POWER_GATING_ENABLE_MASK;
  3527. if (orig != data)
  3528. WREG32(mmRLC_PG_CNTL, data);
  3529. orig = data = RREG32(mmRLC_AUTO_PG_CTRL);
  3530. data &= ~RLC_AUTO_PG_CTRL__AUTO_PG_EN_MASK;
  3531. if (orig != data)
  3532. WREG32(mmRLC_AUTO_PG_CTRL, data);
  3533. data = RREG32(mmDB_RENDER_CONTROL);
  3534. }
  3535. }
  3536. static void gfx_v7_0_set_user_cu_inactive_bitmap(struct amdgpu_device *adev,
  3537. u32 bitmap)
  3538. {
  3539. u32 data;
  3540. if (!bitmap)
  3541. return;
  3542. data = bitmap << GC_USER_SHADER_ARRAY_CONFIG__INACTIVE_CUS__SHIFT;
  3543. data &= GC_USER_SHADER_ARRAY_CONFIG__INACTIVE_CUS_MASK;
  3544. WREG32(mmGC_USER_SHADER_ARRAY_CONFIG, data);
  3545. }
  3546. static u32 gfx_v7_0_get_cu_active_bitmap(struct amdgpu_device *adev)
  3547. {
  3548. u32 data, mask;
  3549. data = RREG32(mmCC_GC_SHADER_ARRAY_CONFIG);
  3550. data |= RREG32(mmGC_USER_SHADER_ARRAY_CONFIG);
  3551. data &= CC_GC_SHADER_ARRAY_CONFIG__INACTIVE_CUS_MASK;
  3552. data >>= CC_GC_SHADER_ARRAY_CONFIG__INACTIVE_CUS__SHIFT;
  3553. mask = amdgpu_gfx_create_bitmask(adev->gfx.config.max_cu_per_sh);
  3554. return (~data) & mask;
  3555. }
  3556. static void gfx_v7_0_init_ao_cu_mask(struct amdgpu_device *adev)
  3557. {
  3558. u32 tmp;
  3559. WREG32(mmRLC_PG_ALWAYS_ON_CU_MASK, adev->gfx.cu_info.ao_cu_mask);
  3560. tmp = RREG32(mmRLC_MAX_PG_CU);
  3561. tmp &= ~RLC_MAX_PG_CU__MAX_POWERED_UP_CU_MASK;
  3562. tmp |= (adev->gfx.cu_info.number << RLC_MAX_PG_CU__MAX_POWERED_UP_CU__SHIFT);
  3563. WREG32(mmRLC_MAX_PG_CU, tmp);
  3564. }
  3565. static void gfx_v7_0_enable_gfx_static_mgpg(struct amdgpu_device *adev,
  3566. bool enable)
  3567. {
  3568. u32 data, orig;
  3569. orig = data = RREG32(mmRLC_PG_CNTL);
  3570. if (enable && (adev->pg_flags & AMD_PG_SUPPORT_GFX_SMG))
  3571. data |= RLC_PG_CNTL__STATIC_PER_CU_PG_ENABLE_MASK;
  3572. else
  3573. data &= ~RLC_PG_CNTL__STATIC_PER_CU_PG_ENABLE_MASK;
  3574. if (orig != data)
  3575. WREG32(mmRLC_PG_CNTL, data);
  3576. }
  3577. static void gfx_v7_0_enable_gfx_dynamic_mgpg(struct amdgpu_device *adev,
  3578. bool enable)
  3579. {
  3580. u32 data, orig;
  3581. orig = data = RREG32(mmRLC_PG_CNTL);
  3582. if (enable && (adev->pg_flags & AMD_PG_SUPPORT_GFX_DMG))
  3583. data |= RLC_PG_CNTL__DYN_PER_CU_PG_ENABLE_MASK;
  3584. else
  3585. data &= ~RLC_PG_CNTL__DYN_PER_CU_PG_ENABLE_MASK;
  3586. if (orig != data)
  3587. WREG32(mmRLC_PG_CNTL, data);
  3588. }
  3589. #define RLC_SAVE_AND_RESTORE_STARTING_OFFSET 0x90
  3590. #define RLC_CLEAR_STATE_DESCRIPTOR_OFFSET 0x3D
  3591. static void gfx_v7_0_init_gfx_cgpg(struct amdgpu_device *adev)
  3592. {
  3593. u32 data, orig;
  3594. u32 i;
  3595. if (adev->gfx.rlc.cs_data) {
  3596. WREG32(mmRLC_GPM_SCRATCH_ADDR, RLC_CLEAR_STATE_DESCRIPTOR_OFFSET);
  3597. WREG32(mmRLC_GPM_SCRATCH_DATA, upper_32_bits(adev->gfx.rlc.clear_state_gpu_addr));
  3598. WREG32(mmRLC_GPM_SCRATCH_DATA, lower_32_bits(adev->gfx.rlc.clear_state_gpu_addr));
  3599. WREG32(mmRLC_GPM_SCRATCH_DATA, adev->gfx.rlc.clear_state_size);
  3600. } else {
  3601. WREG32(mmRLC_GPM_SCRATCH_ADDR, RLC_CLEAR_STATE_DESCRIPTOR_OFFSET);
  3602. for (i = 0; i < 3; i++)
  3603. WREG32(mmRLC_GPM_SCRATCH_DATA, 0);
  3604. }
  3605. if (adev->gfx.rlc.reg_list) {
  3606. WREG32(mmRLC_GPM_SCRATCH_ADDR, RLC_SAVE_AND_RESTORE_STARTING_OFFSET);
  3607. for (i = 0; i < adev->gfx.rlc.reg_list_size; i++)
  3608. WREG32(mmRLC_GPM_SCRATCH_DATA, adev->gfx.rlc.reg_list[i]);
  3609. }
  3610. orig = data = RREG32(mmRLC_PG_CNTL);
  3611. data |= RLC_PG_CNTL__GFX_POWER_GATING_SRC_MASK;
  3612. if (orig != data)
  3613. WREG32(mmRLC_PG_CNTL, data);
  3614. WREG32(mmRLC_SAVE_AND_RESTORE_BASE, adev->gfx.rlc.save_restore_gpu_addr >> 8);
  3615. WREG32(mmRLC_JUMP_TABLE_RESTORE, adev->gfx.rlc.cp_table_gpu_addr >> 8);
  3616. data = RREG32(mmCP_RB_WPTR_POLL_CNTL);
  3617. data &= ~CP_RB_WPTR_POLL_CNTL__IDLE_POLL_COUNT_MASK;
  3618. data |= (0x60 << CP_RB_WPTR_POLL_CNTL__IDLE_POLL_COUNT__SHIFT);
  3619. WREG32(mmCP_RB_WPTR_POLL_CNTL, data);
  3620. data = 0x10101010;
  3621. WREG32(mmRLC_PG_DELAY, data);
  3622. data = RREG32(mmRLC_PG_DELAY_2);
  3623. data &= ~0xff;
  3624. data |= 0x3;
  3625. WREG32(mmRLC_PG_DELAY_2, data);
  3626. data = RREG32(mmRLC_AUTO_PG_CTRL);
  3627. data &= ~RLC_AUTO_PG_CTRL__GRBM_REG_SAVE_GFX_IDLE_THRESHOLD_MASK;
  3628. data |= (0x700 << RLC_AUTO_PG_CTRL__GRBM_REG_SAVE_GFX_IDLE_THRESHOLD__SHIFT);
  3629. WREG32(mmRLC_AUTO_PG_CTRL, data);
  3630. }
  3631. static void gfx_v7_0_update_gfx_pg(struct amdgpu_device *adev, bool enable)
  3632. {
  3633. gfx_v7_0_enable_gfx_cgpg(adev, enable);
  3634. gfx_v7_0_enable_gfx_static_mgpg(adev, enable);
  3635. gfx_v7_0_enable_gfx_dynamic_mgpg(adev, enable);
  3636. }
  3637. static u32 gfx_v7_0_get_csb_size(struct amdgpu_device *adev)
  3638. {
  3639. u32 count = 0;
  3640. const struct cs_section_def *sect = NULL;
  3641. const struct cs_extent_def *ext = NULL;
  3642. if (adev->gfx.rlc.cs_data == NULL)
  3643. return 0;
  3644. /* begin clear state */
  3645. count += 2;
  3646. /* context control state */
  3647. count += 3;
  3648. for (sect = adev->gfx.rlc.cs_data; sect->section != NULL; ++sect) {
  3649. for (ext = sect->section; ext->extent != NULL; ++ext) {
  3650. if (sect->id == SECT_CONTEXT)
  3651. count += 2 + ext->reg_count;
  3652. else
  3653. return 0;
  3654. }
  3655. }
  3656. /* pa_sc_raster_config/pa_sc_raster_config1 */
  3657. count += 4;
  3658. /* end clear state */
  3659. count += 2;
  3660. /* clear state */
  3661. count += 2;
  3662. return count;
  3663. }
  3664. static void gfx_v7_0_get_csb_buffer(struct amdgpu_device *adev,
  3665. volatile u32 *buffer)
  3666. {
  3667. u32 count = 0, i;
  3668. const struct cs_section_def *sect = NULL;
  3669. const struct cs_extent_def *ext = NULL;
  3670. if (adev->gfx.rlc.cs_data == NULL)
  3671. return;
  3672. if (buffer == NULL)
  3673. return;
  3674. buffer[count++] = cpu_to_le32(PACKET3(PACKET3_PREAMBLE_CNTL, 0));
  3675. buffer[count++] = cpu_to_le32(PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);
  3676. buffer[count++] = cpu_to_le32(PACKET3(PACKET3_CONTEXT_CONTROL, 1));
  3677. buffer[count++] = cpu_to_le32(0x80000000);
  3678. buffer[count++] = cpu_to_le32(0x80000000);
  3679. for (sect = adev->gfx.rlc.cs_data; sect->section != NULL; ++sect) {
  3680. for (ext = sect->section; ext->extent != NULL; ++ext) {
  3681. if (sect->id == SECT_CONTEXT) {
  3682. buffer[count++] =
  3683. cpu_to_le32(PACKET3(PACKET3_SET_CONTEXT_REG, ext->reg_count));
  3684. buffer[count++] = cpu_to_le32(ext->reg_index - PACKET3_SET_CONTEXT_REG_START);
  3685. for (i = 0; i < ext->reg_count; i++)
  3686. buffer[count++] = cpu_to_le32(ext->extent[i]);
  3687. } else {
  3688. return;
  3689. }
  3690. }
  3691. }
  3692. buffer[count++] = cpu_to_le32(PACKET3(PACKET3_SET_CONTEXT_REG, 2));
  3693. buffer[count++] = cpu_to_le32(mmPA_SC_RASTER_CONFIG - PACKET3_SET_CONTEXT_REG_START);
  3694. switch (adev->asic_type) {
  3695. case CHIP_BONAIRE:
  3696. buffer[count++] = cpu_to_le32(0x16000012);
  3697. buffer[count++] = cpu_to_le32(0x00000000);
  3698. break;
  3699. case CHIP_KAVERI:
  3700. buffer[count++] = cpu_to_le32(0x00000000); /* XXX */
  3701. buffer[count++] = cpu_to_le32(0x00000000);
  3702. break;
  3703. case CHIP_KABINI:
  3704. case CHIP_MULLINS:
  3705. buffer[count++] = cpu_to_le32(0x00000000); /* XXX */
  3706. buffer[count++] = cpu_to_le32(0x00000000);
  3707. break;
  3708. case CHIP_HAWAII:
  3709. buffer[count++] = cpu_to_le32(0x3a00161a);
  3710. buffer[count++] = cpu_to_le32(0x0000002e);
  3711. break;
  3712. default:
  3713. buffer[count++] = cpu_to_le32(0x00000000);
  3714. buffer[count++] = cpu_to_le32(0x00000000);
  3715. break;
  3716. }
  3717. buffer[count++] = cpu_to_le32(PACKET3(PACKET3_PREAMBLE_CNTL, 0));
  3718. buffer[count++] = cpu_to_le32(PACKET3_PREAMBLE_END_CLEAR_STATE);
  3719. buffer[count++] = cpu_to_le32(PACKET3(PACKET3_CLEAR_STATE, 0));
  3720. buffer[count++] = cpu_to_le32(0);
  3721. }
  3722. static void gfx_v7_0_init_pg(struct amdgpu_device *adev)
  3723. {
  3724. if (adev->pg_flags & (AMD_PG_SUPPORT_GFX_PG |
  3725. AMD_PG_SUPPORT_GFX_SMG |
  3726. AMD_PG_SUPPORT_GFX_DMG |
  3727. AMD_PG_SUPPORT_CP |
  3728. AMD_PG_SUPPORT_GDS |
  3729. AMD_PG_SUPPORT_RLC_SMU_HS)) {
  3730. gfx_v7_0_enable_sclk_slowdown_on_pu(adev, true);
  3731. gfx_v7_0_enable_sclk_slowdown_on_pd(adev, true);
  3732. if (adev->pg_flags & AMD_PG_SUPPORT_GFX_PG) {
  3733. gfx_v7_0_init_gfx_cgpg(adev);
  3734. gfx_v7_0_enable_cp_pg(adev, true);
  3735. gfx_v7_0_enable_gds_pg(adev, true);
  3736. }
  3737. gfx_v7_0_init_ao_cu_mask(adev);
  3738. gfx_v7_0_update_gfx_pg(adev, true);
  3739. }
  3740. }
  3741. static void gfx_v7_0_fini_pg(struct amdgpu_device *adev)
  3742. {
  3743. if (adev->pg_flags & (AMD_PG_SUPPORT_GFX_PG |
  3744. AMD_PG_SUPPORT_GFX_SMG |
  3745. AMD_PG_SUPPORT_GFX_DMG |
  3746. AMD_PG_SUPPORT_CP |
  3747. AMD_PG_SUPPORT_GDS |
  3748. AMD_PG_SUPPORT_RLC_SMU_HS)) {
  3749. gfx_v7_0_update_gfx_pg(adev, false);
  3750. if (adev->pg_flags & AMD_PG_SUPPORT_GFX_PG) {
  3751. gfx_v7_0_enable_cp_pg(adev, false);
  3752. gfx_v7_0_enable_gds_pg(adev, false);
  3753. }
  3754. }
  3755. }
  3756. /**
  3757. * gfx_v7_0_get_gpu_clock_counter - return GPU clock counter snapshot
  3758. *
  3759. * @adev: amdgpu_device pointer
  3760. *
  3761. * Fetches a GPU clock counter snapshot (SI).
  3762. * Returns the 64 bit clock counter snapshot.
  3763. */
  3764. static uint64_t gfx_v7_0_get_gpu_clock_counter(struct amdgpu_device *adev)
  3765. {
  3766. uint64_t clock;
  3767. mutex_lock(&adev->gfx.gpu_clock_mutex);
  3768. WREG32(mmRLC_CAPTURE_GPU_CLOCK_COUNT, 1);
  3769. clock = (uint64_t)RREG32(mmRLC_GPU_CLOCK_COUNT_LSB) |
  3770. ((uint64_t)RREG32(mmRLC_GPU_CLOCK_COUNT_MSB) << 32ULL);
  3771. mutex_unlock(&adev->gfx.gpu_clock_mutex);
  3772. return clock;
  3773. }
  3774. static void gfx_v7_0_ring_emit_gds_switch(struct amdgpu_ring *ring,
  3775. uint32_t vmid,
  3776. uint32_t gds_base, uint32_t gds_size,
  3777. uint32_t gws_base, uint32_t gws_size,
  3778. uint32_t oa_base, uint32_t oa_size)
  3779. {
  3780. gds_base = gds_base >> AMDGPU_GDS_SHIFT;
  3781. gds_size = gds_size >> AMDGPU_GDS_SHIFT;
  3782. gws_base = gws_base >> AMDGPU_GWS_SHIFT;
  3783. gws_size = gws_size >> AMDGPU_GWS_SHIFT;
  3784. oa_base = oa_base >> AMDGPU_OA_SHIFT;
  3785. oa_size = oa_size >> AMDGPU_OA_SHIFT;
  3786. /* GDS Base */
  3787. amdgpu_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  3788. amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
  3789. WRITE_DATA_DST_SEL(0)));
  3790. amdgpu_ring_write(ring, amdgpu_gds_reg_offset[vmid].mem_base);
  3791. amdgpu_ring_write(ring, 0);
  3792. amdgpu_ring_write(ring, gds_base);
  3793. /* GDS Size */
  3794. amdgpu_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  3795. amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
  3796. WRITE_DATA_DST_SEL(0)));
  3797. amdgpu_ring_write(ring, amdgpu_gds_reg_offset[vmid].mem_size);
  3798. amdgpu_ring_write(ring, 0);
  3799. amdgpu_ring_write(ring, gds_size);
  3800. /* GWS */
  3801. amdgpu_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  3802. amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
  3803. WRITE_DATA_DST_SEL(0)));
  3804. amdgpu_ring_write(ring, amdgpu_gds_reg_offset[vmid].gws);
  3805. amdgpu_ring_write(ring, 0);
  3806. amdgpu_ring_write(ring, gws_size << GDS_GWS_VMID0__SIZE__SHIFT | gws_base);
  3807. /* OA */
  3808. amdgpu_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
  3809. amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
  3810. WRITE_DATA_DST_SEL(0)));
  3811. amdgpu_ring_write(ring, amdgpu_gds_reg_offset[vmid].oa);
  3812. amdgpu_ring_write(ring, 0);
  3813. amdgpu_ring_write(ring, (1 << (oa_size + oa_base)) - (1 << oa_base));
  3814. }
  3815. static uint32_t wave_read_ind(struct amdgpu_device *adev, uint32_t simd, uint32_t wave, uint32_t address)
  3816. {
  3817. WREG32(mmSQ_IND_INDEX,
  3818. (wave << SQ_IND_INDEX__WAVE_ID__SHIFT) |
  3819. (simd << SQ_IND_INDEX__SIMD_ID__SHIFT) |
  3820. (address << SQ_IND_INDEX__INDEX__SHIFT) |
  3821. (SQ_IND_INDEX__FORCE_READ_MASK));
  3822. return RREG32(mmSQ_IND_DATA);
  3823. }
  3824. static void wave_read_regs(struct amdgpu_device *adev, uint32_t simd,
  3825. uint32_t wave, uint32_t thread,
  3826. uint32_t regno, uint32_t num, uint32_t *out)
  3827. {
  3828. WREG32(mmSQ_IND_INDEX,
  3829. (wave << SQ_IND_INDEX__WAVE_ID__SHIFT) |
  3830. (simd << SQ_IND_INDEX__SIMD_ID__SHIFT) |
  3831. (regno << SQ_IND_INDEX__INDEX__SHIFT) |
  3832. (thread << SQ_IND_INDEX__THREAD_ID__SHIFT) |
  3833. (SQ_IND_INDEX__FORCE_READ_MASK) |
  3834. (SQ_IND_INDEX__AUTO_INCR_MASK));
  3835. while (num--)
  3836. *(out++) = RREG32(mmSQ_IND_DATA);
  3837. }
  3838. static void gfx_v7_0_read_wave_data(struct amdgpu_device *adev, uint32_t simd, uint32_t wave, uint32_t *dst, int *no_fields)
  3839. {
  3840. /* type 0 wave data */
  3841. dst[(*no_fields)++] = 0;
  3842. dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_STATUS);
  3843. dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_PC_LO);
  3844. dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_PC_HI);
  3845. dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_EXEC_LO);
  3846. dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_EXEC_HI);
  3847. dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_HW_ID);
  3848. dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_INST_DW0);
  3849. dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_INST_DW1);
  3850. dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_GPR_ALLOC);
  3851. dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_LDS_ALLOC);
  3852. dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_TRAPSTS);
  3853. dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_IB_STS);
  3854. dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_TBA_LO);
  3855. dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_TBA_HI);
  3856. dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_TMA_LO);
  3857. dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_TMA_HI);
  3858. dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_IB_DBG0);
  3859. dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_M0);
  3860. }
  3861. static void gfx_v7_0_read_wave_sgprs(struct amdgpu_device *adev, uint32_t simd,
  3862. uint32_t wave, uint32_t start,
  3863. uint32_t size, uint32_t *dst)
  3864. {
  3865. wave_read_regs(
  3866. adev, simd, wave, 0,
  3867. start + SQIND_WAVE_SGPRS_OFFSET, size, dst);
  3868. }
  3869. static const struct amdgpu_gfx_funcs gfx_v7_0_gfx_funcs = {
  3870. .get_gpu_clock_counter = &gfx_v7_0_get_gpu_clock_counter,
  3871. .select_se_sh = &gfx_v7_0_select_se_sh,
  3872. .read_wave_data = &gfx_v7_0_read_wave_data,
  3873. .read_wave_sgprs = &gfx_v7_0_read_wave_sgprs,
  3874. };
  3875. static const struct amdgpu_rlc_funcs gfx_v7_0_rlc_funcs = {
  3876. .enter_safe_mode = gfx_v7_0_enter_rlc_safe_mode,
  3877. .exit_safe_mode = gfx_v7_0_exit_rlc_safe_mode
  3878. };
  3879. static int gfx_v7_0_early_init(void *handle)
  3880. {
  3881. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  3882. adev->gfx.num_gfx_rings = GFX7_NUM_GFX_RINGS;
  3883. adev->gfx.num_compute_rings = AMDGPU_MAX_COMPUTE_RINGS;
  3884. adev->gfx.funcs = &gfx_v7_0_gfx_funcs;
  3885. adev->gfx.rlc.funcs = &gfx_v7_0_rlc_funcs;
  3886. gfx_v7_0_set_ring_funcs(adev);
  3887. gfx_v7_0_set_irq_funcs(adev);
  3888. gfx_v7_0_set_gds_init(adev);
  3889. return 0;
  3890. }
  3891. static int gfx_v7_0_late_init(void *handle)
  3892. {
  3893. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  3894. int r;
  3895. r = amdgpu_irq_get(adev, &adev->gfx.priv_reg_irq, 0);
  3896. if (r)
  3897. return r;
  3898. r = amdgpu_irq_get(adev, &adev->gfx.priv_inst_irq, 0);
  3899. if (r)
  3900. return r;
  3901. return 0;
  3902. }
  3903. static void gfx_v7_0_gpu_early_init(struct amdgpu_device *adev)
  3904. {
  3905. u32 gb_addr_config;
  3906. u32 mc_shared_chmap, mc_arb_ramcfg;
  3907. u32 dimm00_addr_map, dimm01_addr_map, dimm10_addr_map, dimm11_addr_map;
  3908. u32 tmp;
  3909. switch (adev->asic_type) {
  3910. case CHIP_BONAIRE:
  3911. adev->gfx.config.max_shader_engines = 2;
  3912. adev->gfx.config.max_tile_pipes = 4;
  3913. adev->gfx.config.max_cu_per_sh = 7;
  3914. adev->gfx.config.max_sh_per_se = 1;
  3915. adev->gfx.config.max_backends_per_se = 2;
  3916. adev->gfx.config.max_texture_channel_caches = 4;
  3917. adev->gfx.config.max_gprs = 256;
  3918. adev->gfx.config.max_gs_threads = 32;
  3919. adev->gfx.config.max_hw_contexts = 8;
  3920. adev->gfx.config.sc_prim_fifo_size_frontend = 0x20;
  3921. adev->gfx.config.sc_prim_fifo_size_backend = 0x100;
  3922. adev->gfx.config.sc_hiz_tile_fifo_size = 0x30;
  3923. adev->gfx.config.sc_earlyz_tile_fifo_size = 0x130;
  3924. gb_addr_config = BONAIRE_GB_ADDR_CONFIG_GOLDEN;
  3925. break;
  3926. case CHIP_HAWAII:
  3927. adev->gfx.config.max_shader_engines = 4;
  3928. adev->gfx.config.max_tile_pipes = 16;
  3929. adev->gfx.config.max_cu_per_sh = 11;
  3930. adev->gfx.config.max_sh_per_se = 1;
  3931. adev->gfx.config.max_backends_per_se = 4;
  3932. adev->gfx.config.max_texture_channel_caches = 16;
  3933. adev->gfx.config.max_gprs = 256;
  3934. adev->gfx.config.max_gs_threads = 32;
  3935. adev->gfx.config.max_hw_contexts = 8;
  3936. adev->gfx.config.sc_prim_fifo_size_frontend = 0x20;
  3937. adev->gfx.config.sc_prim_fifo_size_backend = 0x100;
  3938. adev->gfx.config.sc_hiz_tile_fifo_size = 0x30;
  3939. adev->gfx.config.sc_earlyz_tile_fifo_size = 0x130;
  3940. gb_addr_config = HAWAII_GB_ADDR_CONFIG_GOLDEN;
  3941. break;
  3942. case CHIP_KAVERI:
  3943. adev->gfx.config.max_shader_engines = 1;
  3944. adev->gfx.config.max_tile_pipes = 4;
  3945. adev->gfx.config.max_cu_per_sh = 8;
  3946. adev->gfx.config.max_backends_per_se = 2;
  3947. adev->gfx.config.max_sh_per_se = 1;
  3948. adev->gfx.config.max_texture_channel_caches = 4;
  3949. adev->gfx.config.max_gprs = 256;
  3950. adev->gfx.config.max_gs_threads = 16;
  3951. adev->gfx.config.max_hw_contexts = 8;
  3952. adev->gfx.config.sc_prim_fifo_size_frontend = 0x20;
  3953. adev->gfx.config.sc_prim_fifo_size_backend = 0x100;
  3954. adev->gfx.config.sc_hiz_tile_fifo_size = 0x30;
  3955. adev->gfx.config.sc_earlyz_tile_fifo_size = 0x130;
  3956. gb_addr_config = BONAIRE_GB_ADDR_CONFIG_GOLDEN;
  3957. break;
  3958. case CHIP_KABINI:
  3959. case CHIP_MULLINS:
  3960. default:
  3961. adev->gfx.config.max_shader_engines = 1;
  3962. adev->gfx.config.max_tile_pipes = 2;
  3963. adev->gfx.config.max_cu_per_sh = 2;
  3964. adev->gfx.config.max_sh_per_se = 1;
  3965. adev->gfx.config.max_backends_per_se = 1;
  3966. adev->gfx.config.max_texture_channel_caches = 2;
  3967. adev->gfx.config.max_gprs = 256;
  3968. adev->gfx.config.max_gs_threads = 16;
  3969. adev->gfx.config.max_hw_contexts = 8;
  3970. adev->gfx.config.sc_prim_fifo_size_frontend = 0x20;
  3971. adev->gfx.config.sc_prim_fifo_size_backend = 0x100;
  3972. adev->gfx.config.sc_hiz_tile_fifo_size = 0x30;
  3973. adev->gfx.config.sc_earlyz_tile_fifo_size = 0x130;
  3974. gb_addr_config = BONAIRE_GB_ADDR_CONFIG_GOLDEN;
  3975. break;
  3976. }
  3977. mc_shared_chmap = RREG32(mmMC_SHARED_CHMAP);
  3978. adev->gfx.config.mc_arb_ramcfg = RREG32(mmMC_ARB_RAMCFG);
  3979. mc_arb_ramcfg = adev->gfx.config.mc_arb_ramcfg;
  3980. adev->gfx.config.num_tile_pipes = adev->gfx.config.max_tile_pipes;
  3981. adev->gfx.config.mem_max_burst_length_bytes = 256;
  3982. if (adev->flags & AMD_IS_APU) {
  3983. /* Get memory bank mapping mode. */
  3984. tmp = RREG32(mmMC_FUS_DRAM0_BANK_ADDR_MAPPING);
  3985. dimm00_addr_map = REG_GET_FIELD(tmp, MC_FUS_DRAM0_BANK_ADDR_MAPPING, DIMM0ADDRMAP);
  3986. dimm01_addr_map = REG_GET_FIELD(tmp, MC_FUS_DRAM0_BANK_ADDR_MAPPING, DIMM1ADDRMAP);
  3987. tmp = RREG32(mmMC_FUS_DRAM1_BANK_ADDR_MAPPING);
  3988. dimm10_addr_map = REG_GET_FIELD(tmp, MC_FUS_DRAM1_BANK_ADDR_MAPPING, DIMM0ADDRMAP);
  3989. dimm11_addr_map = REG_GET_FIELD(tmp, MC_FUS_DRAM1_BANK_ADDR_MAPPING, DIMM1ADDRMAP);
  3990. /* Validate settings in case only one DIMM installed. */
  3991. if ((dimm00_addr_map == 0) || (dimm00_addr_map == 3) || (dimm00_addr_map == 4) || (dimm00_addr_map > 12))
  3992. dimm00_addr_map = 0;
  3993. if ((dimm01_addr_map == 0) || (dimm01_addr_map == 3) || (dimm01_addr_map == 4) || (dimm01_addr_map > 12))
  3994. dimm01_addr_map = 0;
  3995. if ((dimm10_addr_map == 0) || (dimm10_addr_map == 3) || (dimm10_addr_map == 4) || (dimm10_addr_map > 12))
  3996. dimm10_addr_map = 0;
  3997. if ((dimm11_addr_map == 0) || (dimm11_addr_map == 3) || (dimm11_addr_map == 4) || (dimm11_addr_map > 12))
  3998. dimm11_addr_map = 0;
  3999. /* If DIMM Addr map is 8GB, ROW size should be 2KB. Otherwise 1KB. */
  4000. /* If ROW size(DIMM1) != ROW size(DMIMM0), ROW size should be larger one. */
  4001. if ((dimm00_addr_map == 11) || (dimm01_addr_map == 11) || (dimm10_addr_map == 11) || (dimm11_addr_map == 11))
  4002. adev->gfx.config.mem_row_size_in_kb = 2;
  4003. else
  4004. adev->gfx.config.mem_row_size_in_kb = 1;
  4005. } else {
  4006. tmp = (mc_arb_ramcfg & MC_ARB_RAMCFG__NOOFCOLS_MASK) >> MC_ARB_RAMCFG__NOOFCOLS__SHIFT;
  4007. adev->gfx.config.mem_row_size_in_kb = (4 * (1 << (8 + tmp))) / 1024;
  4008. if (adev->gfx.config.mem_row_size_in_kb > 4)
  4009. adev->gfx.config.mem_row_size_in_kb = 4;
  4010. }
  4011. /* XXX use MC settings? */
  4012. adev->gfx.config.shader_engine_tile_size = 32;
  4013. adev->gfx.config.num_gpus = 1;
  4014. adev->gfx.config.multi_gpu_tile_size = 64;
  4015. /* fix up row size */
  4016. gb_addr_config &= ~GB_ADDR_CONFIG__ROW_SIZE_MASK;
  4017. switch (adev->gfx.config.mem_row_size_in_kb) {
  4018. case 1:
  4019. default:
  4020. gb_addr_config |= (0 << GB_ADDR_CONFIG__ROW_SIZE__SHIFT);
  4021. break;
  4022. case 2:
  4023. gb_addr_config |= (1 << GB_ADDR_CONFIG__ROW_SIZE__SHIFT);
  4024. break;
  4025. case 4:
  4026. gb_addr_config |= (2 << GB_ADDR_CONFIG__ROW_SIZE__SHIFT);
  4027. break;
  4028. }
  4029. adev->gfx.config.gb_addr_config = gb_addr_config;
  4030. }
  4031. static int gfx_v7_0_compute_ring_init(struct amdgpu_device *adev, int ring_id,
  4032. int mec, int pipe, int queue)
  4033. {
  4034. int r;
  4035. unsigned irq_type;
  4036. struct amdgpu_ring *ring = &adev->gfx.compute_ring[ring_id];
  4037. /* mec0 is me1 */
  4038. ring->me = mec + 1;
  4039. ring->pipe = pipe;
  4040. ring->queue = queue;
  4041. ring->ring_obj = NULL;
  4042. ring->use_doorbell = true;
  4043. ring->doorbell_index = AMDGPU_DOORBELL_MEC_RING0 + ring_id;
  4044. sprintf(ring->name, "comp_%d.%d.%d", ring->me, ring->pipe, ring->queue);
  4045. irq_type = AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP
  4046. + ((ring->me - 1) * adev->gfx.mec.num_pipe_per_mec)
  4047. + ring->pipe;
  4048. /* type-2 packets are deprecated on MEC, use type-3 instead */
  4049. r = amdgpu_ring_init(adev, ring, 1024,
  4050. &adev->gfx.eop_irq, irq_type);
  4051. if (r)
  4052. return r;
  4053. return 0;
  4054. }
  4055. static int gfx_v7_0_sw_init(void *handle)
  4056. {
  4057. struct amdgpu_ring *ring;
  4058. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  4059. int i, j, k, r, ring_id;
  4060. switch (adev->asic_type) {
  4061. case CHIP_KAVERI:
  4062. adev->gfx.mec.num_mec = 2;
  4063. break;
  4064. case CHIP_BONAIRE:
  4065. case CHIP_HAWAII:
  4066. case CHIP_KABINI:
  4067. case CHIP_MULLINS:
  4068. default:
  4069. adev->gfx.mec.num_mec = 1;
  4070. break;
  4071. }
  4072. adev->gfx.mec.num_pipe_per_mec = 4;
  4073. adev->gfx.mec.num_queue_per_pipe = 8;
  4074. /* EOP Event */
  4075. r = amdgpu_irq_add_id(adev, AMDGPU_IH_CLIENTID_LEGACY, 181, &adev->gfx.eop_irq);
  4076. if (r)
  4077. return r;
  4078. /* Privileged reg */
  4079. r = amdgpu_irq_add_id(adev, AMDGPU_IH_CLIENTID_LEGACY, 184,
  4080. &adev->gfx.priv_reg_irq);
  4081. if (r)
  4082. return r;
  4083. /* Privileged inst */
  4084. r = amdgpu_irq_add_id(adev, AMDGPU_IH_CLIENTID_LEGACY, 185,
  4085. &adev->gfx.priv_inst_irq);
  4086. if (r)
  4087. return r;
  4088. gfx_v7_0_scratch_init(adev);
  4089. r = gfx_v7_0_init_microcode(adev);
  4090. if (r) {
  4091. DRM_ERROR("Failed to load gfx firmware!\n");
  4092. return r;
  4093. }
  4094. r = gfx_v7_0_rlc_init(adev);
  4095. if (r) {
  4096. DRM_ERROR("Failed to init rlc BOs!\n");
  4097. return r;
  4098. }
  4099. /* allocate mec buffers */
  4100. r = gfx_v7_0_mec_init(adev);
  4101. if (r) {
  4102. DRM_ERROR("Failed to init MEC BOs!\n");
  4103. return r;
  4104. }
  4105. for (i = 0; i < adev->gfx.num_gfx_rings; i++) {
  4106. ring = &adev->gfx.gfx_ring[i];
  4107. ring->ring_obj = NULL;
  4108. sprintf(ring->name, "gfx");
  4109. r = amdgpu_ring_init(adev, ring, 1024,
  4110. &adev->gfx.eop_irq, AMDGPU_CP_IRQ_GFX_EOP);
  4111. if (r)
  4112. return r;
  4113. }
  4114. /* set up the compute queues - allocate horizontally across pipes */
  4115. ring_id = 0;
  4116. for (i = 0; i < adev->gfx.mec.num_mec; ++i) {
  4117. for (j = 0; j < adev->gfx.mec.num_queue_per_pipe; j++) {
  4118. for (k = 0; k < adev->gfx.mec.num_pipe_per_mec; k++) {
  4119. if (!amdgpu_gfx_is_mec_queue_enabled(adev, i, k, j))
  4120. continue;
  4121. r = gfx_v7_0_compute_ring_init(adev,
  4122. ring_id,
  4123. i, k, j);
  4124. if (r)
  4125. return r;
  4126. ring_id++;
  4127. }
  4128. }
  4129. }
  4130. /* reserve GDS, GWS and OA resource for gfx */
  4131. r = amdgpu_bo_create_kernel(adev, adev->gds.mem.gfx_partition_size,
  4132. PAGE_SIZE, AMDGPU_GEM_DOMAIN_GDS,
  4133. &adev->gds.gds_gfx_bo, NULL, NULL);
  4134. if (r)
  4135. return r;
  4136. r = amdgpu_bo_create_kernel(adev, adev->gds.gws.gfx_partition_size,
  4137. PAGE_SIZE, AMDGPU_GEM_DOMAIN_GWS,
  4138. &adev->gds.gws_gfx_bo, NULL, NULL);
  4139. if (r)
  4140. return r;
  4141. r = amdgpu_bo_create_kernel(adev, adev->gds.oa.gfx_partition_size,
  4142. PAGE_SIZE, AMDGPU_GEM_DOMAIN_OA,
  4143. &adev->gds.oa_gfx_bo, NULL, NULL);
  4144. if (r)
  4145. return r;
  4146. adev->gfx.ce_ram_size = 0x8000;
  4147. gfx_v7_0_gpu_early_init(adev);
  4148. return r;
  4149. }
  4150. static int gfx_v7_0_sw_fini(void *handle)
  4151. {
  4152. int i;
  4153. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  4154. amdgpu_bo_free_kernel(&adev->gds.oa_gfx_bo, NULL, NULL);
  4155. amdgpu_bo_free_kernel(&adev->gds.gws_gfx_bo, NULL, NULL);
  4156. amdgpu_bo_free_kernel(&adev->gds.gds_gfx_bo, NULL, NULL);
  4157. for (i = 0; i < adev->gfx.num_gfx_rings; i++)
  4158. amdgpu_ring_fini(&adev->gfx.gfx_ring[i]);
  4159. for (i = 0; i < adev->gfx.num_compute_rings; i++)
  4160. amdgpu_ring_fini(&adev->gfx.compute_ring[i]);
  4161. gfx_v7_0_cp_compute_fini(adev);
  4162. gfx_v7_0_rlc_fini(adev);
  4163. gfx_v7_0_mec_fini(adev);
  4164. gfx_v7_0_free_microcode(adev);
  4165. return 0;
  4166. }
  4167. static int gfx_v7_0_hw_init(void *handle)
  4168. {
  4169. int r;
  4170. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  4171. gfx_v7_0_gpu_init(adev);
  4172. /* init rlc */
  4173. r = gfx_v7_0_rlc_resume(adev);
  4174. if (r)
  4175. return r;
  4176. r = gfx_v7_0_cp_resume(adev);
  4177. if (r)
  4178. return r;
  4179. return r;
  4180. }
  4181. static int gfx_v7_0_hw_fini(void *handle)
  4182. {
  4183. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  4184. amdgpu_irq_put(adev, &adev->gfx.priv_reg_irq, 0);
  4185. amdgpu_irq_put(adev, &adev->gfx.priv_inst_irq, 0);
  4186. gfx_v7_0_cp_enable(adev, false);
  4187. gfx_v7_0_rlc_stop(adev);
  4188. gfx_v7_0_fini_pg(adev);
  4189. return 0;
  4190. }
  4191. static int gfx_v7_0_suspend(void *handle)
  4192. {
  4193. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  4194. return gfx_v7_0_hw_fini(adev);
  4195. }
  4196. static int gfx_v7_0_resume(void *handle)
  4197. {
  4198. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  4199. return gfx_v7_0_hw_init(adev);
  4200. }
  4201. static bool gfx_v7_0_is_idle(void *handle)
  4202. {
  4203. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  4204. if (RREG32(mmGRBM_STATUS) & GRBM_STATUS__GUI_ACTIVE_MASK)
  4205. return false;
  4206. else
  4207. return true;
  4208. }
  4209. static int gfx_v7_0_wait_for_idle(void *handle)
  4210. {
  4211. unsigned i;
  4212. u32 tmp;
  4213. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  4214. for (i = 0; i < adev->usec_timeout; i++) {
  4215. /* read MC_STATUS */
  4216. tmp = RREG32(mmGRBM_STATUS) & GRBM_STATUS__GUI_ACTIVE_MASK;
  4217. if (!tmp)
  4218. return 0;
  4219. udelay(1);
  4220. }
  4221. return -ETIMEDOUT;
  4222. }
  4223. static int gfx_v7_0_soft_reset(void *handle)
  4224. {
  4225. u32 grbm_soft_reset = 0, srbm_soft_reset = 0;
  4226. u32 tmp;
  4227. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  4228. /* GRBM_STATUS */
  4229. tmp = RREG32(mmGRBM_STATUS);
  4230. if (tmp & (GRBM_STATUS__PA_BUSY_MASK | GRBM_STATUS__SC_BUSY_MASK |
  4231. GRBM_STATUS__BCI_BUSY_MASK | GRBM_STATUS__SX_BUSY_MASK |
  4232. GRBM_STATUS__TA_BUSY_MASK | GRBM_STATUS__VGT_BUSY_MASK |
  4233. GRBM_STATUS__DB_BUSY_MASK | GRBM_STATUS__CB_BUSY_MASK |
  4234. GRBM_STATUS__GDS_BUSY_MASK | GRBM_STATUS__SPI_BUSY_MASK |
  4235. GRBM_STATUS__IA_BUSY_MASK | GRBM_STATUS__IA_BUSY_NO_DMA_MASK))
  4236. grbm_soft_reset |= GRBM_SOFT_RESET__SOFT_RESET_CP_MASK |
  4237. GRBM_SOFT_RESET__SOFT_RESET_GFX_MASK;
  4238. if (tmp & (GRBM_STATUS__CP_BUSY_MASK | GRBM_STATUS__CP_COHERENCY_BUSY_MASK)) {
  4239. grbm_soft_reset |= GRBM_SOFT_RESET__SOFT_RESET_CP_MASK;
  4240. srbm_soft_reset |= SRBM_SOFT_RESET__SOFT_RESET_GRBM_MASK;
  4241. }
  4242. /* GRBM_STATUS2 */
  4243. tmp = RREG32(mmGRBM_STATUS2);
  4244. if (tmp & GRBM_STATUS2__RLC_BUSY_MASK)
  4245. grbm_soft_reset |= GRBM_SOFT_RESET__SOFT_RESET_RLC_MASK;
  4246. /* SRBM_STATUS */
  4247. tmp = RREG32(mmSRBM_STATUS);
  4248. if (tmp & SRBM_STATUS__GRBM_RQ_PENDING_MASK)
  4249. srbm_soft_reset |= SRBM_SOFT_RESET__SOFT_RESET_GRBM_MASK;
  4250. if (grbm_soft_reset || srbm_soft_reset) {
  4251. /* disable CG/PG */
  4252. gfx_v7_0_fini_pg(adev);
  4253. gfx_v7_0_update_cg(adev, false);
  4254. /* stop the rlc */
  4255. gfx_v7_0_rlc_stop(adev);
  4256. /* Disable GFX parsing/prefetching */
  4257. WREG32(mmCP_ME_CNTL, CP_ME_CNTL__ME_HALT_MASK | CP_ME_CNTL__PFP_HALT_MASK | CP_ME_CNTL__CE_HALT_MASK);
  4258. /* Disable MEC parsing/prefetching */
  4259. WREG32(mmCP_MEC_CNTL, CP_MEC_CNTL__MEC_ME1_HALT_MASK | CP_MEC_CNTL__MEC_ME2_HALT_MASK);
  4260. if (grbm_soft_reset) {
  4261. tmp = RREG32(mmGRBM_SOFT_RESET);
  4262. tmp |= grbm_soft_reset;
  4263. dev_info(adev->dev, "GRBM_SOFT_RESET=0x%08X\n", tmp);
  4264. WREG32(mmGRBM_SOFT_RESET, tmp);
  4265. tmp = RREG32(mmGRBM_SOFT_RESET);
  4266. udelay(50);
  4267. tmp &= ~grbm_soft_reset;
  4268. WREG32(mmGRBM_SOFT_RESET, tmp);
  4269. tmp = RREG32(mmGRBM_SOFT_RESET);
  4270. }
  4271. if (srbm_soft_reset) {
  4272. tmp = RREG32(mmSRBM_SOFT_RESET);
  4273. tmp |= srbm_soft_reset;
  4274. dev_info(adev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
  4275. WREG32(mmSRBM_SOFT_RESET, tmp);
  4276. tmp = RREG32(mmSRBM_SOFT_RESET);
  4277. udelay(50);
  4278. tmp &= ~srbm_soft_reset;
  4279. WREG32(mmSRBM_SOFT_RESET, tmp);
  4280. tmp = RREG32(mmSRBM_SOFT_RESET);
  4281. }
  4282. /* Wait a little for things to settle down */
  4283. udelay(50);
  4284. }
  4285. return 0;
  4286. }
  4287. static void gfx_v7_0_set_gfx_eop_interrupt_state(struct amdgpu_device *adev,
  4288. enum amdgpu_interrupt_state state)
  4289. {
  4290. u32 cp_int_cntl;
  4291. switch (state) {
  4292. case AMDGPU_IRQ_STATE_DISABLE:
  4293. cp_int_cntl = RREG32(mmCP_INT_CNTL_RING0);
  4294. cp_int_cntl &= ~CP_INT_CNTL_RING0__TIME_STAMP_INT_ENABLE_MASK;
  4295. WREG32(mmCP_INT_CNTL_RING0, cp_int_cntl);
  4296. break;
  4297. case AMDGPU_IRQ_STATE_ENABLE:
  4298. cp_int_cntl = RREG32(mmCP_INT_CNTL_RING0);
  4299. cp_int_cntl |= CP_INT_CNTL_RING0__TIME_STAMP_INT_ENABLE_MASK;
  4300. WREG32(mmCP_INT_CNTL_RING0, cp_int_cntl);
  4301. break;
  4302. default:
  4303. break;
  4304. }
  4305. }
  4306. static void gfx_v7_0_set_compute_eop_interrupt_state(struct amdgpu_device *adev,
  4307. int me, int pipe,
  4308. enum amdgpu_interrupt_state state)
  4309. {
  4310. u32 mec_int_cntl, mec_int_cntl_reg;
  4311. /*
  4312. * amdgpu controls only the first MEC. That's why this function only
  4313. * handles the setting of interrupts for this specific MEC. All other
  4314. * pipes' interrupts are set by amdkfd.
  4315. */
  4316. if (me == 1) {
  4317. switch (pipe) {
  4318. case 0:
  4319. mec_int_cntl_reg = mmCP_ME1_PIPE0_INT_CNTL;
  4320. break;
  4321. case 1:
  4322. mec_int_cntl_reg = mmCP_ME1_PIPE1_INT_CNTL;
  4323. break;
  4324. case 2:
  4325. mec_int_cntl_reg = mmCP_ME1_PIPE2_INT_CNTL;
  4326. break;
  4327. case 3:
  4328. mec_int_cntl_reg = mmCP_ME1_PIPE3_INT_CNTL;
  4329. break;
  4330. default:
  4331. DRM_DEBUG("invalid pipe %d\n", pipe);
  4332. return;
  4333. }
  4334. } else {
  4335. DRM_DEBUG("invalid me %d\n", me);
  4336. return;
  4337. }
  4338. switch (state) {
  4339. case AMDGPU_IRQ_STATE_DISABLE:
  4340. mec_int_cntl = RREG32(mec_int_cntl_reg);
  4341. mec_int_cntl &= ~CP_INT_CNTL_RING0__TIME_STAMP_INT_ENABLE_MASK;
  4342. WREG32(mec_int_cntl_reg, mec_int_cntl);
  4343. break;
  4344. case AMDGPU_IRQ_STATE_ENABLE:
  4345. mec_int_cntl = RREG32(mec_int_cntl_reg);
  4346. mec_int_cntl |= CP_INT_CNTL_RING0__TIME_STAMP_INT_ENABLE_MASK;
  4347. WREG32(mec_int_cntl_reg, mec_int_cntl);
  4348. break;
  4349. default:
  4350. break;
  4351. }
  4352. }
  4353. static int gfx_v7_0_set_priv_reg_fault_state(struct amdgpu_device *adev,
  4354. struct amdgpu_irq_src *src,
  4355. unsigned type,
  4356. enum amdgpu_interrupt_state state)
  4357. {
  4358. u32 cp_int_cntl;
  4359. switch (state) {
  4360. case AMDGPU_IRQ_STATE_DISABLE:
  4361. cp_int_cntl = RREG32(mmCP_INT_CNTL_RING0);
  4362. cp_int_cntl &= ~CP_INT_CNTL_RING0__PRIV_REG_INT_ENABLE_MASK;
  4363. WREG32(mmCP_INT_CNTL_RING0, cp_int_cntl);
  4364. break;
  4365. case AMDGPU_IRQ_STATE_ENABLE:
  4366. cp_int_cntl = RREG32(mmCP_INT_CNTL_RING0);
  4367. cp_int_cntl |= CP_INT_CNTL_RING0__PRIV_REG_INT_ENABLE_MASK;
  4368. WREG32(mmCP_INT_CNTL_RING0, cp_int_cntl);
  4369. break;
  4370. default:
  4371. break;
  4372. }
  4373. return 0;
  4374. }
  4375. static int gfx_v7_0_set_priv_inst_fault_state(struct amdgpu_device *adev,
  4376. struct amdgpu_irq_src *src,
  4377. unsigned type,
  4378. enum amdgpu_interrupt_state state)
  4379. {
  4380. u32 cp_int_cntl;
  4381. switch (state) {
  4382. case AMDGPU_IRQ_STATE_DISABLE:
  4383. cp_int_cntl = RREG32(mmCP_INT_CNTL_RING0);
  4384. cp_int_cntl &= ~CP_INT_CNTL_RING0__PRIV_INSTR_INT_ENABLE_MASK;
  4385. WREG32(mmCP_INT_CNTL_RING0, cp_int_cntl);
  4386. break;
  4387. case AMDGPU_IRQ_STATE_ENABLE:
  4388. cp_int_cntl = RREG32(mmCP_INT_CNTL_RING0);
  4389. cp_int_cntl |= CP_INT_CNTL_RING0__PRIV_INSTR_INT_ENABLE_MASK;
  4390. WREG32(mmCP_INT_CNTL_RING0, cp_int_cntl);
  4391. break;
  4392. default:
  4393. break;
  4394. }
  4395. return 0;
  4396. }
  4397. static int gfx_v7_0_set_eop_interrupt_state(struct amdgpu_device *adev,
  4398. struct amdgpu_irq_src *src,
  4399. unsigned type,
  4400. enum amdgpu_interrupt_state state)
  4401. {
  4402. switch (type) {
  4403. case AMDGPU_CP_IRQ_GFX_EOP:
  4404. gfx_v7_0_set_gfx_eop_interrupt_state(adev, state);
  4405. break;
  4406. case AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP:
  4407. gfx_v7_0_set_compute_eop_interrupt_state(adev, 1, 0, state);
  4408. break;
  4409. case AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE1_EOP:
  4410. gfx_v7_0_set_compute_eop_interrupt_state(adev, 1, 1, state);
  4411. break;
  4412. case AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE2_EOP:
  4413. gfx_v7_0_set_compute_eop_interrupt_state(adev, 1, 2, state);
  4414. break;
  4415. case AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE3_EOP:
  4416. gfx_v7_0_set_compute_eop_interrupt_state(adev, 1, 3, state);
  4417. break;
  4418. case AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE0_EOP:
  4419. gfx_v7_0_set_compute_eop_interrupt_state(adev, 2, 0, state);
  4420. break;
  4421. case AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE1_EOP:
  4422. gfx_v7_0_set_compute_eop_interrupt_state(adev, 2, 1, state);
  4423. break;
  4424. case AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE2_EOP:
  4425. gfx_v7_0_set_compute_eop_interrupt_state(adev, 2, 2, state);
  4426. break;
  4427. case AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE3_EOP:
  4428. gfx_v7_0_set_compute_eop_interrupt_state(adev, 2, 3, state);
  4429. break;
  4430. default:
  4431. break;
  4432. }
  4433. return 0;
  4434. }
  4435. static int gfx_v7_0_eop_irq(struct amdgpu_device *adev,
  4436. struct amdgpu_irq_src *source,
  4437. struct amdgpu_iv_entry *entry)
  4438. {
  4439. u8 me_id, pipe_id;
  4440. struct amdgpu_ring *ring;
  4441. int i;
  4442. DRM_DEBUG("IH: CP EOP\n");
  4443. me_id = (entry->ring_id & 0x0c) >> 2;
  4444. pipe_id = (entry->ring_id & 0x03) >> 0;
  4445. switch (me_id) {
  4446. case 0:
  4447. amdgpu_fence_process(&adev->gfx.gfx_ring[0]);
  4448. break;
  4449. case 1:
  4450. case 2:
  4451. for (i = 0; i < adev->gfx.num_compute_rings; i++) {
  4452. ring = &adev->gfx.compute_ring[i];
  4453. if ((ring->me == me_id) && (ring->pipe == pipe_id))
  4454. amdgpu_fence_process(ring);
  4455. }
  4456. break;
  4457. }
  4458. return 0;
  4459. }
  4460. static int gfx_v7_0_priv_reg_irq(struct amdgpu_device *adev,
  4461. struct amdgpu_irq_src *source,
  4462. struct amdgpu_iv_entry *entry)
  4463. {
  4464. DRM_ERROR("Illegal register access in command stream\n");
  4465. schedule_work(&adev->reset_work);
  4466. return 0;
  4467. }
  4468. static int gfx_v7_0_priv_inst_irq(struct amdgpu_device *adev,
  4469. struct amdgpu_irq_src *source,
  4470. struct amdgpu_iv_entry *entry)
  4471. {
  4472. DRM_ERROR("Illegal instruction in command stream\n");
  4473. // XXX soft reset the gfx block only
  4474. schedule_work(&adev->reset_work);
  4475. return 0;
  4476. }
  4477. static int gfx_v7_0_set_clockgating_state(void *handle,
  4478. enum amd_clockgating_state state)
  4479. {
  4480. bool gate = false;
  4481. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  4482. if (state == AMD_CG_STATE_GATE)
  4483. gate = true;
  4484. gfx_v7_0_enable_gui_idle_interrupt(adev, false);
  4485. /* order matters! */
  4486. if (gate) {
  4487. gfx_v7_0_enable_mgcg(adev, true);
  4488. gfx_v7_0_enable_cgcg(adev, true);
  4489. } else {
  4490. gfx_v7_0_enable_cgcg(adev, false);
  4491. gfx_v7_0_enable_mgcg(adev, false);
  4492. }
  4493. gfx_v7_0_enable_gui_idle_interrupt(adev, true);
  4494. return 0;
  4495. }
  4496. static int gfx_v7_0_set_powergating_state(void *handle,
  4497. enum amd_powergating_state state)
  4498. {
  4499. bool gate = false;
  4500. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  4501. if (state == AMD_PG_STATE_GATE)
  4502. gate = true;
  4503. if (adev->pg_flags & (AMD_PG_SUPPORT_GFX_PG |
  4504. AMD_PG_SUPPORT_GFX_SMG |
  4505. AMD_PG_SUPPORT_GFX_DMG |
  4506. AMD_PG_SUPPORT_CP |
  4507. AMD_PG_SUPPORT_GDS |
  4508. AMD_PG_SUPPORT_RLC_SMU_HS)) {
  4509. gfx_v7_0_update_gfx_pg(adev, gate);
  4510. if (adev->pg_flags & AMD_PG_SUPPORT_GFX_PG) {
  4511. gfx_v7_0_enable_cp_pg(adev, gate);
  4512. gfx_v7_0_enable_gds_pg(adev, gate);
  4513. }
  4514. }
  4515. return 0;
  4516. }
  4517. static const struct amd_ip_funcs gfx_v7_0_ip_funcs = {
  4518. .name = "gfx_v7_0",
  4519. .early_init = gfx_v7_0_early_init,
  4520. .late_init = gfx_v7_0_late_init,
  4521. .sw_init = gfx_v7_0_sw_init,
  4522. .sw_fini = gfx_v7_0_sw_fini,
  4523. .hw_init = gfx_v7_0_hw_init,
  4524. .hw_fini = gfx_v7_0_hw_fini,
  4525. .suspend = gfx_v7_0_suspend,
  4526. .resume = gfx_v7_0_resume,
  4527. .is_idle = gfx_v7_0_is_idle,
  4528. .wait_for_idle = gfx_v7_0_wait_for_idle,
  4529. .soft_reset = gfx_v7_0_soft_reset,
  4530. .set_clockgating_state = gfx_v7_0_set_clockgating_state,
  4531. .set_powergating_state = gfx_v7_0_set_powergating_state,
  4532. };
  4533. static const struct amdgpu_ring_funcs gfx_v7_0_ring_funcs_gfx = {
  4534. .type = AMDGPU_RING_TYPE_GFX,
  4535. .align_mask = 0xff,
  4536. .nop = PACKET3(PACKET3_NOP, 0x3FFF),
  4537. .support_64bit_ptrs = false,
  4538. .get_rptr = gfx_v7_0_ring_get_rptr,
  4539. .get_wptr = gfx_v7_0_ring_get_wptr_gfx,
  4540. .set_wptr = gfx_v7_0_ring_set_wptr_gfx,
  4541. .emit_frame_size =
  4542. 20 + /* gfx_v7_0_ring_emit_gds_switch */
  4543. 7 + /* gfx_v7_0_ring_emit_hdp_flush */
  4544. 5 + /* gfx_v7_0_ring_emit_hdp_invalidate */
  4545. 12 + 12 + 12 + /* gfx_v7_0_ring_emit_fence_gfx x3 for user fence, vm fence */
  4546. 7 + 4 + /* gfx_v7_0_ring_emit_pipeline_sync */
  4547. 17 + 6 + /* gfx_v7_0_ring_emit_vm_flush */
  4548. 3 + 4, /* gfx_v7_ring_emit_cntxcntl including vgt flush*/
  4549. .emit_ib_size = 4, /* gfx_v7_0_ring_emit_ib_gfx */
  4550. .emit_ib = gfx_v7_0_ring_emit_ib_gfx,
  4551. .emit_fence = gfx_v7_0_ring_emit_fence_gfx,
  4552. .emit_pipeline_sync = gfx_v7_0_ring_emit_pipeline_sync,
  4553. .emit_vm_flush = gfx_v7_0_ring_emit_vm_flush,
  4554. .emit_gds_switch = gfx_v7_0_ring_emit_gds_switch,
  4555. .emit_hdp_flush = gfx_v7_0_ring_emit_hdp_flush,
  4556. .emit_hdp_invalidate = gfx_v7_0_ring_emit_hdp_invalidate,
  4557. .test_ring = gfx_v7_0_ring_test_ring,
  4558. .test_ib = gfx_v7_0_ring_test_ib,
  4559. .insert_nop = amdgpu_ring_insert_nop,
  4560. .pad_ib = amdgpu_ring_generic_pad_ib,
  4561. .emit_cntxcntl = gfx_v7_ring_emit_cntxcntl,
  4562. };
  4563. static const struct amdgpu_ring_funcs gfx_v7_0_ring_funcs_compute = {
  4564. .type = AMDGPU_RING_TYPE_COMPUTE,
  4565. .align_mask = 0xff,
  4566. .nop = PACKET3(PACKET3_NOP, 0x3FFF),
  4567. .support_64bit_ptrs = false,
  4568. .get_rptr = gfx_v7_0_ring_get_rptr,
  4569. .get_wptr = gfx_v7_0_ring_get_wptr_compute,
  4570. .set_wptr = gfx_v7_0_ring_set_wptr_compute,
  4571. .emit_frame_size =
  4572. 20 + /* gfx_v7_0_ring_emit_gds_switch */
  4573. 7 + /* gfx_v7_0_ring_emit_hdp_flush */
  4574. 5 + /* gfx_v7_0_ring_emit_hdp_invalidate */
  4575. 7 + /* gfx_v7_0_ring_emit_pipeline_sync */
  4576. 17 + /* gfx_v7_0_ring_emit_vm_flush */
  4577. 7 + 7 + 7, /* gfx_v7_0_ring_emit_fence_compute x3 for user fence, vm fence */
  4578. .emit_ib_size = 4, /* gfx_v7_0_ring_emit_ib_compute */
  4579. .emit_ib = gfx_v7_0_ring_emit_ib_compute,
  4580. .emit_fence = gfx_v7_0_ring_emit_fence_compute,
  4581. .emit_pipeline_sync = gfx_v7_0_ring_emit_pipeline_sync,
  4582. .emit_vm_flush = gfx_v7_0_ring_emit_vm_flush,
  4583. .emit_gds_switch = gfx_v7_0_ring_emit_gds_switch,
  4584. .emit_hdp_flush = gfx_v7_0_ring_emit_hdp_flush,
  4585. .emit_hdp_invalidate = gfx_v7_0_ring_emit_hdp_invalidate,
  4586. .test_ring = gfx_v7_0_ring_test_ring,
  4587. .test_ib = gfx_v7_0_ring_test_ib,
  4588. .insert_nop = amdgpu_ring_insert_nop,
  4589. .pad_ib = amdgpu_ring_generic_pad_ib,
  4590. };
  4591. static void gfx_v7_0_set_ring_funcs(struct amdgpu_device *adev)
  4592. {
  4593. int i;
  4594. for (i = 0; i < adev->gfx.num_gfx_rings; i++)
  4595. adev->gfx.gfx_ring[i].funcs = &gfx_v7_0_ring_funcs_gfx;
  4596. for (i = 0; i < adev->gfx.num_compute_rings; i++)
  4597. adev->gfx.compute_ring[i].funcs = &gfx_v7_0_ring_funcs_compute;
  4598. }
  4599. static const struct amdgpu_irq_src_funcs gfx_v7_0_eop_irq_funcs = {
  4600. .set = gfx_v7_0_set_eop_interrupt_state,
  4601. .process = gfx_v7_0_eop_irq,
  4602. };
  4603. static const struct amdgpu_irq_src_funcs gfx_v7_0_priv_reg_irq_funcs = {
  4604. .set = gfx_v7_0_set_priv_reg_fault_state,
  4605. .process = gfx_v7_0_priv_reg_irq,
  4606. };
  4607. static const struct amdgpu_irq_src_funcs gfx_v7_0_priv_inst_irq_funcs = {
  4608. .set = gfx_v7_0_set_priv_inst_fault_state,
  4609. .process = gfx_v7_0_priv_inst_irq,
  4610. };
  4611. static void gfx_v7_0_set_irq_funcs(struct amdgpu_device *adev)
  4612. {
  4613. adev->gfx.eop_irq.num_types = AMDGPU_CP_IRQ_LAST;
  4614. adev->gfx.eop_irq.funcs = &gfx_v7_0_eop_irq_funcs;
  4615. adev->gfx.priv_reg_irq.num_types = 1;
  4616. adev->gfx.priv_reg_irq.funcs = &gfx_v7_0_priv_reg_irq_funcs;
  4617. adev->gfx.priv_inst_irq.num_types = 1;
  4618. adev->gfx.priv_inst_irq.funcs = &gfx_v7_0_priv_inst_irq_funcs;
  4619. }
  4620. static void gfx_v7_0_set_gds_init(struct amdgpu_device *adev)
  4621. {
  4622. /* init asci gds info */
  4623. adev->gds.mem.total_size = RREG32(mmGDS_VMID0_SIZE);
  4624. adev->gds.gws.total_size = 64;
  4625. adev->gds.oa.total_size = 16;
  4626. if (adev->gds.mem.total_size == 64 * 1024) {
  4627. adev->gds.mem.gfx_partition_size = 4096;
  4628. adev->gds.mem.cs_partition_size = 4096;
  4629. adev->gds.gws.gfx_partition_size = 4;
  4630. adev->gds.gws.cs_partition_size = 4;
  4631. adev->gds.oa.gfx_partition_size = 4;
  4632. adev->gds.oa.cs_partition_size = 1;
  4633. } else {
  4634. adev->gds.mem.gfx_partition_size = 1024;
  4635. adev->gds.mem.cs_partition_size = 1024;
  4636. adev->gds.gws.gfx_partition_size = 16;
  4637. adev->gds.gws.cs_partition_size = 16;
  4638. adev->gds.oa.gfx_partition_size = 4;
  4639. adev->gds.oa.cs_partition_size = 4;
  4640. }
  4641. }
  4642. static void gfx_v7_0_get_cu_info(struct amdgpu_device *adev)
  4643. {
  4644. int i, j, k, counter, active_cu_number = 0;
  4645. u32 mask, bitmap, ao_bitmap, ao_cu_mask = 0;
  4646. struct amdgpu_cu_info *cu_info = &adev->gfx.cu_info;
  4647. unsigned disable_masks[4 * 2];
  4648. u32 ao_cu_num;
  4649. if (adev->flags & AMD_IS_APU)
  4650. ao_cu_num = 2;
  4651. else
  4652. ao_cu_num = adev->gfx.config.max_cu_per_sh;
  4653. memset(cu_info, 0, sizeof(*cu_info));
  4654. amdgpu_gfx_parse_disable_cu(disable_masks, 4, 2);
  4655. mutex_lock(&adev->grbm_idx_mutex);
  4656. for (i = 0; i < adev->gfx.config.max_shader_engines; i++) {
  4657. for (j = 0; j < adev->gfx.config.max_sh_per_se; j++) {
  4658. mask = 1;
  4659. ao_bitmap = 0;
  4660. counter = 0;
  4661. gfx_v7_0_select_se_sh(adev, i, j, 0xffffffff);
  4662. if (i < 4 && j < 2)
  4663. gfx_v7_0_set_user_cu_inactive_bitmap(
  4664. adev, disable_masks[i * 2 + j]);
  4665. bitmap = gfx_v7_0_get_cu_active_bitmap(adev);
  4666. cu_info->bitmap[i][j] = bitmap;
  4667. for (k = 0; k < adev->gfx.config.max_cu_per_sh; k ++) {
  4668. if (bitmap & mask) {
  4669. if (counter < ao_cu_num)
  4670. ao_bitmap |= mask;
  4671. counter ++;
  4672. }
  4673. mask <<= 1;
  4674. }
  4675. active_cu_number += counter;
  4676. if (i < 2 && j < 2)
  4677. ao_cu_mask |= (ao_bitmap << (i * 16 + j * 8));
  4678. cu_info->ao_cu_bitmap[i][j] = ao_bitmap;
  4679. }
  4680. }
  4681. gfx_v7_0_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
  4682. mutex_unlock(&adev->grbm_idx_mutex);
  4683. cu_info->number = active_cu_number;
  4684. cu_info->ao_cu_mask = ao_cu_mask;
  4685. }
  4686. const struct amdgpu_ip_block_version gfx_v7_0_ip_block =
  4687. {
  4688. .type = AMD_IP_BLOCK_TYPE_GFX,
  4689. .major = 7,
  4690. .minor = 0,
  4691. .rev = 0,
  4692. .funcs = &gfx_v7_0_ip_funcs,
  4693. };
  4694. const struct amdgpu_ip_block_version gfx_v7_1_ip_block =
  4695. {
  4696. .type = AMD_IP_BLOCK_TYPE_GFX,
  4697. .major = 7,
  4698. .minor = 1,
  4699. .rev = 0,
  4700. .funcs = &gfx_v7_0_ip_funcs,
  4701. };
  4702. const struct amdgpu_ip_block_version gfx_v7_2_ip_block =
  4703. {
  4704. .type = AMD_IP_BLOCK_TYPE_GFX,
  4705. .major = 7,
  4706. .minor = 2,
  4707. .rev = 0,
  4708. .funcs = &gfx_v7_0_ip_funcs,
  4709. };
  4710. const struct amdgpu_ip_block_version gfx_v7_3_ip_block =
  4711. {
  4712. .type = AMD_IP_BLOCK_TYPE_GFX,
  4713. .major = 7,
  4714. .minor = 3,
  4715. .rev = 0,
  4716. .funcs = &gfx_v7_0_ip_funcs,
  4717. };