gfx_v7_0.c 164 KB

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