smu7_hwmgr.c 153 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731
  1. /*
  2. * Copyright 2015 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 "pp_debug.h"
  24. #include <linux/module.h>
  25. #include <linux/slab.h>
  26. #include <linux/fb.h>
  27. #include <asm/div64.h>
  28. #include "linux/delay.h"
  29. #include "pp_acpi.h"
  30. #include "ppatomctrl.h"
  31. #include "atombios.h"
  32. #include "pptable_v1_0.h"
  33. #include "pppcielanes.h"
  34. #include "amd_pcie_helpers.h"
  35. #include "hardwaremanager.h"
  36. #include "process_pptables_v1_0.h"
  37. #include "cgs_common.h"
  38. #include "smu7_common.h"
  39. #include "hwmgr.h"
  40. #include "smu7_hwmgr.h"
  41. #include "smu7_smumgr.h"
  42. #include "smu_ucode_xfer_vi.h"
  43. #include "smu7_powertune.h"
  44. #include "smu7_dyn_defaults.h"
  45. #include "smu7_thermal.h"
  46. #include "smu7_clockpowergating.h"
  47. #include "processpptables.h"
  48. #define MC_CG_ARB_FREQ_F0 0x0a
  49. #define MC_CG_ARB_FREQ_F1 0x0b
  50. #define MC_CG_ARB_FREQ_F2 0x0c
  51. #define MC_CG_ARB_FREQ_F3 0x0d
  52. #define MC_CG_SEQ_DRAMCONF_S0 0x05
  53. #define MC_CG_SEQ_DRAMCONF_S1 0x06
  54. #define MC_CG_SEQ_YCLK_SUSPEND 0x04
  55. #define MC_CG_SEQ_YCLK_RESUME 0x0a
  56. #define SMC_CG_IND_START 0xc0030000
  57. #define SMC_CG_IND_END 0xc0040000
  58. #define VOLTAGE_SCALE 4
  59. #define VOLTAGE_VID_OFFSET_SCALE1 625
  60. #define VOLTAGE_VID_OFFSET_SCALE2 100
  61. #define MEM_FREQ_LOW_LATENCY 25000
  62. #define MEM_FREQ_HIGH_LATENCY 80000
  63. #define MEM_LATENCY_HIGH 45
  64. #define MEM_LATENCY_LOW 35
  65. #define MEM_LATENCY_ERR 0xFFFF
  66. #define MC_SEQ_MISC0_GDDR5_SHIFT 28
  67. #define MC_SEQ_MISC0_GDDR5_MASK 0xf0000000
  68. #define MC_SEQ_MISC0_GDDR5_VALUE 5
  69. #define PCIE_BUS_CLK 10000
  70. #define TCLK (PCIE_BUS_CLK / 10)
  71. /** Values for the CG_THERMAL_CTRL::DPM_EVENT_SRC field. */
  72. enum DPM_EVENT_SRC {
  73. DPM_EVENT_SRC_ANALOG = 0,
  74. DPM_EVENT_SRC_EXTERNAL = 1,
  75. DPM_EVENT_SRC_DIGITAL = 2,
  76. DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3,
  77. DPM_EVENT_SRC_DIGITAL_OR_EXTERNAL = 4
  78. };
  79. static int smu7_avfs_control(struct pp_hwmgr *hwmgr, bool enable);
  80. static const unsigned long PhwVIslands_Magic = (unsigned long)(PHM_VIslands_Magic);
  81. static int smu7_force_clock_level(struct pp_hwmgr *hwmgr,
  82. enum pp_clock_type type, uint32_t mask);
  83. static struct smu7_power_state *cast_phw_smu7_power_state(
  84. struct pp_hw_power_state *hw_ps)
  85. {
  86. PP_ASSERT_WITH_CODE((PhwVIslands_Magic == hw_ps->magic),
  87. "Invalid Powerstate Type!",
  88. return NULL);
  89. return (struct smu7_power_state *)hw_ps;
  90. }
  91. static const struct smu7_power_state *cast_const_phw_smu7_power_state(
  92. const struct pp_hw_power_state *hw_ps)
  93. {
  94. PP_ASSERT_WITH_CODE((PhwVIslands_Magic == hw_ps->magic),
  95. "Invalid Powerstate Type!",
  96. return NULL);
  97. return (const struct smu7_power_state *)hw_ps;
  98. }
  99. /**
  100. * Find the MC microcode version and store it in the HwMgr struct
  101. *
  102. * @param hwmgr the address of the powerplay hardware manager.
  103. * @return always 0
  104. */
  105. static int smu7_get_mc_microcode_version(struct pp_hwmgr *hwmgr)
  106. {
  107. cgs_write_register(hwmgr->device, mmMC_SEQ_IO_DEBUG_INDEX, 0x9F);
  108. hwmgr->microcode_version_info.MC = cgs_read_register(hwmgr->device, mmMC_SEQ_IO_DEBUG_DATA);
  109. return 0;
  110. }
  111. static uint16_t smu7_get_current_pcie_speed(struct pp_hwmgr *hwmgr)
  112. {
  113. uint32_t speedCntl = 0;
  114. /* mmPCIE_PORT_INDEX rename as mmPCIE_INDEX */
  115. speedCntl = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__PCIE,
  116. ixPCIE_LC_SPEED_CNTL);
  117. return((uint16_t)PHM_GET_FIELD(speedCntl,
  118. PCIE_LC_SPEED_CNTL, LC_CURRENT_DATA_RATE));
  119. }
  120. static int smu7_get_current_pcie_lane_number(struct pp_hwmgr *hwmgr)
  121. {
  122. uint32_t link_width;
  123. /* mmPCIE_PORT_INDEX rename as mmPCIE_INDEX */
  124. link_width = PHM_READ_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__PCIE,
  125. PCIE_LC_LINK_WIDTH_CNTL, LC_LINK_WIDTH_RD);
  126. PP_ASSERT_WITH_CODE((7 >= link_width),
  127. "Invalid PCIe lane width!", return 0);
  128. return decode_pcie_lane_width(link_width);
  129. }
  130. /**
  131. * Enable voltage control
  132. *
  133. * @param pHwMgr the address of the powerplay hardware manager.
  134. * @return always PP_Result_OK
  135. */
  136. static int smu7_enable_smc_voltage_controller(struct pp_hwmgr *hwmgr)
  137. {
  138. if (hwmgr->feature_mask & PP_SMC_VOLTAGE_CONTROL_MASK)
  139. smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_Voltage_Cntl_Enable);
  140. return 0;
  141. }
  142. /**
  143. * Checks if we want to support voltage control
  144. *
  145. * @param hwmgr the address of the powerplay hardware manager.
  146. */
  147. static bool smu7_voltage_control(const struct pp_hwmgr *hwmgr)
  148. {
  149. const struct smu7_hwmgr *data =
  150. (const struct smu7_hwmgr *)(hwmgr->backend);
  151. return (SMU7_VOLTAGE_CONTROL_NONE != data->voltage_control);
  152. }
  153. /**
  154. * Enable voltage control
  155. *
  156. * @param hwmgr the address of the powerplay hardware manager.
  157. * @return always 0
  158. */
  159. static int smu7_enable_voltage_control(struct pp_hwmgr *hwmgr)
  160. {
  161. /* enable voltage control */
  162. PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
  163. GENERAL_PWRMGT, VOLT_PWRMGT_EN, 1);
  164. return 0;
  165. }
  166. static int phm_get_svi2_voltage_table_v0(pp_atomctrl_voltage_table *voltage_table,
  167. struct phm_clock_voltage_dependency_table *voltage_dependency_table
  168. )
  169. {
  170. uint32_t i;
  171. PP_ASSERT_WITH_CODE((NULL != voltage_table),
  172. "Voltage Dependency Table empty.", return -EINVAL;);
  173. voltage_table->mask_low = 0;
  174. voltage_table->phase_delay = 0;
  175. voltage_table->count = voltage_dependency_table->count;
  176. for (i = 0; i < voltage_dependency_table->count; i++) {
  177. voltage_table->entries[i].value =
  178. voltage_dependency_table->entries[i].v;
  179. voltage_table->entries[i].smio_low = 0;
  180. }
  181. return 0;
  182. }
  183. /**
  184. * Create Voltage Tables.
  185. *
  186. * @param hwmgr the address of the powerplay hardware manager.
  187. * @return always 0
  188. */
  189. static int smu7_construct_voltage_tables(struct pp_hwmgr *hwmgr)
  190. {
  191. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  192. struct phm_ppt_v1_information *table_info =
  193. (struct phm_ppt_v1_information *)hwmgr->pptable;
  194. int result = 0;
  195. uint32_t tmp;
  196. if (SMU7_VOLTAGE_CONTROL_BY_GPIO == data->mvdd_control) {
  197. result = atomctrl_get_voltage_table_v3(hwmgr,
  198. VOLTAGE_TYPE_MVDDC, VOLTAGE_OBJ_GPIO_LUT,
  199. &(data->mvdd_voltage_table));
  200. PP_ASSERT_WITH_CODE((0 == result),
  201. "Failed to retrieve MVDD table.",
  202. return result);
  203. } else if (SMU7_VOLTAGE_CONTROL_BY_SVID2 == data->mvdd_control) {
  204. if (hwmgr->pp_table_version == PP_TABLE_V1)
  205. result = phm_get_svi2_mvdd_voltage_table(&(data->mvdd_voltage_table),
  206. table_info->vdd_dep_on_mclk);
  207. else if (hwmgr->pp_table_version == PP_TABLE_V0)
  208. result = phm_get_svi2_voltage_table_v0(&(data->mvdd_voltage_table),
  209. hwmgr->dyn_state.mvdd_dependency_on_mclk);
  210. PP_ASSERT_WITH_CODE((0 == result),
  211. "Failed to retrieve SVI2 MVDD table from dependancy table.",
  212. return result;);
  213. }
  214. if (SMU7_VOLTAGE_CONTROL_BY_GPIO == data->vddci_control) {
  215. result = atomctrl_get_voltage_table_v3(hwmgr,
  216. VOLTAGE_TYPE_VDDCI, VOLTAGE_OBJ_GPIO_LUT,
  217. &(data->vddci_voltage_table));
  218. PP_ASSERT_WITH_CODE((0 == result),
  219. "Failed to retrieve VDDCI table.",
  220. return result);
  221. } else if (SMU7_VOLTAGE_CONTROL_BY_SVID2 == data->vddci_control) {
  222. if (hwmgr->pp_table_version == PP_TABLE_V1)
  223. result = phm_get_svi2_vddci_voltage_table(&(data->vddci_voltage_table),
  224. table_info->vdd_dep_on_mclk);
  225. else if (hwmgr->pp_table_version == PP_TABLE_V0)
  226. result = phm_get_svi2_voltage_table_v0(&(data->vddci_voltage_table),
  227. hwmgr->dyn_state.vddci_dependency_on_mclk);
  228. PP_ASSERT_WITH_CODE((0 == result),
  229. "Failed to retrieve SVI2 VDDCI table from dependancy table.",
  230. return result);
  231. }
  232. if (SMU7_VOLTAGE_CONTROL_BY_SVID2 == data->vdd_gfx_control) {
  233. /* VDDGFX has only SVI2 voltage control */
  234. result = phm_get_svi2_vdd_voltage_table(&(data->vddgfx_voltage_table),
  235. table_info->vddgfx_lookup_table);
  236. PP_ASSERT_WITH_CODE((0 == result),
  237. "Failed to retrieve SVI2 VDDGFX table from lookup table.", return result;);
  238. }
  239. if (SMU7_VOLTAGE_CONTROL_BY_GPIO == data->voltage_control) {
  240. result = atomctrl_get_voltage_table_v3(hwmgr,
  241. VOLTAGE_TYPE_VDDC, VOLTAGE_OBJ_GPIO_LUT,
  242. &data->vddc_voltage_table);
  243. PP_ASSERT_WITH_CODE((0 == result),
  244. "Failed to retrieve VDDC table.", return result;);
  245. } else if (SMU7_VOLTAGE_CONTROL_BY_SVID2 == data->voltage_control) {
  246. if (hwmgr->pp_table_version == PP_TABLE_V0)
  247. result = phm_get_svi2_voltage_table_v0(&data->vddc_voltage_table,
  248. hwmgr->dyn_state.vddc_dependency_on_mclk);
  249. else if (hwmgr->pp_table_version == PP_TABLE_V1)
  250. result = phm_get_svi2_vdd_voltage_table(&(data->vddc_voltage_table),
  251. table_info->vddc_lookup_table);
  252. PP_ASSERT_WITH_CODE((0 == result),
  253. "Failed to retrieve SVI2 VDDC table from dependancy table.", return result;);
  254. }
  255. tmp = smum_get_mac_definition(hwmgr->smumgr, SMU_MAX_LEVELS_VDDC);
  256. PP_ASSERT_WITH_CODE(
  257. (data->vddc_voltage_table.count <= tmp),
  258. "Too many voltage values for VDDC. Trimming to fit state table.",
  259. phm_trim_voltage_table_to_fit_state_table(tmp,
  260. &(data->vddc_voltage_table)));
  261. tmp = smum_get_mac_definition(hwmgr->smumgr, SMU_MAX_LEVELS_VDDGFX);
  262. PP_ASSERT_WITH_CODE(
  263. (data->vddgfx_voltage_table.count <= tmp),
  264. "Too many voltage values for VDDC. Trimming to fit state table.",
  265. phm_trim_voltage_table_to_fit_state_table(tmp,
  266. &(data->vddgfx_voltage_table)));
  267. tmp = smum_get_mac_definition(hwmgr->smumgr, SMU_MAX_LEVELS_VDDCI);
  268. PP_ASSERT_WITH_CODE(
  269. (data->vddci_voltage_table.count <= tmp),
  270. "Too many voltage values for VDDCI. Trimming to fit state table.",
  271. phm_trim_voltage_table_to_fit_state_table(tmp,
  272. &(data->vddci_voltage_table)));
  273. tmp = smum_get_mac_definition(hwmgr->smumgr, SMU_MAX_LEVELS_MVDD);
  274. PP_ASSERT_WITH_CODE(
  275. (data->mvdd_voltage_table.count <= tmp),
  276. "Too many voltage values for MVDD. Trimming to fit state table.",
  277. phm_trim_voltage_table_to_fit_state_table(tmp,
  278. &(data->mvdd_voltage_table)));
  279. return 0;
  280. }
  281. /**
  282. * Programs static screed detection parameters
  283. *
  284. * @param hwmgr the address of the powerplay hardware manager.
  285. * @return always 0
  286. */
  287. static int smu7_program_static_screen_threshold_parameters(
  288. struct pp_hwmgr *hwmgr)
  289. {
  290. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  291. /* Set static screen threshold unit */
  292. PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
  293. CG_STATIC_SCREEN_PARAMETER, STATIC_SCREEN_THRESHOLD_UNIT,
  294. data->static_screen_threshold_unit);
  295. /* Set static screen threshold */
  296. PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
  297. CG_STATIC_SCREEN_PARAMETER, STATIC_SCREEN_THRESHOLD,
  298. data->static_screen_threshold);
  299. return 0;
  300. }
  301. /**
  302. * Setup display gap for glitch free memory clock switching.
  303. *
  304. * @param hwmgr the address of the powerplay hardware manager.
  305. * @return always 0
  306. */
  307. static int smu7_enable_display_gap(struct pp_hwmgr *hwmgr)
  308. {
  309. uint32_t display_gap =
  310. cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC,
  311. ixCG_DISPLAY_GAP_CNTL);
  312. display_gap = PHM_SET_FIELD(display_gap, CG_DISPLAY_GAP_CNTL,
  313. DISP_GAP, DISPLAY_GAP_IGNORE);
  314. display_gap = PHM_SET_FIELD(display_gap, CG_DISPLAY_GAP_CNTL,
  315. DISP_GAP_MCHG, DISPLAY_GAP_VBLANK);
  316. cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
  317. ixCG_DISPLAY_GAP_CNTL, display_gap);
  318. return 0;
  319. }
  320. /**
  321. * Programs activity state transition voting clients
  322. *
  323. * @param hwmgr the address of the powerplay hardware manager.
  324. * @return always 0
  325. */
  326. static int smu7_program_voting_clients(struct pp_hwmgr *hwmgr)
  327. {
  328. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  329. /* Clear reset for voting clients before enabling DPM */
  330. PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
  331. SCLK_PWRMGT_CNTL, RESET_SCLK_CNT, 0);
  332. PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
  333. SCLK_PWRMGT_CNTL, RESET_BUSY_CNT, 0);
  334. cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
  335. ixCG_FREQ_TRAN_VOTING_0, data->voting_rights_clients0);
  336. cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
  337. ixCG_FREQ_TRAN_VOTING_1, data->voting_rights_clients1);
  338. cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
  339. ixCG_FREQ_TRAN_VOTING_2, data->voting_rights_clients2);
  340. cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
  341. ixCG_FREQ_TRAN_VOTING_3, data->voting_rights_clients3);
  342. cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
  343. ixCG_FREQ_TRAN_VOTING_4, data->voting_rights_clients4);
  344. cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
  345. ixCG_FREQ_TRAN_VOTING_5, data->voting_rights_clients5);
  346. cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
  347. ixCG_FREQ_TRAN_VOTING_6, data->voting_rights_clients6);
  348. cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
  349. ixCG_FREQ_TRAN_VOTING_7, data->voting_rights_clients7);
  350. return 0;
  351. }
  352. static int smu7_clear_voting_clients(struct pp_hwmgr *hwmgr)
  353. {
  354. /* Reset voting clients before disabling DPM */
  355. PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
  356. SCLK_PWRMGT_CNTL, RESET_SCLK_CNT, 1);
  357. PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
  358. SCLK_PWRMGT_CNTL, RESET_BUSY_CNT, 1);
  359. cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
  360. ixCG_FREQ_TRAN_VOTING_0, 0);
  361. cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
  362. ixCG_FREQ_TRAN_VOTING_1, 0);
  363. cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
  364. ixCG_FREQ_TRAN_VOTING_2, 0);
  365. cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
  366. ixCG_FREQ_TRAN_VOTING_3, 0);
  367. cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
  368. ixCG_FREQ_TRAN_VOTING_4, 0);
  369. cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
  370. ixCG_FREQ_TRAN_VOTING_5, 0);
  371. cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
  372. ixCG_FREQ_TRAN_VOTING_6, 0);
  373. cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
  374. ixCG_FREQ_TRAN_VOTING_7, 0);
  375. return 0;
  376. }
  377. /* Copy one arb setting to another and then switch the active set.
  378. * arb_src and arb_dest is one of the MC_CG_ARB_FREQ_Fx constants.
  379. */
  380. static int smu7_copy_and_switch_arb_sets(struct pp_hwmgr *hwmgr,
  381. uint32_t arb_src, uint32_t arb_dest)
  382. {
  383. uint32_t mc_arb_dram_timing;
  384. uint32_t mc_arb_dram_timing2;
  385. uint32_t burst_time;
  386. uint32_t mc_cg_config;
  387. switch (arb_src) {
  388. case MC_CG_ARB_FREQ_F0:
  389. mc_arb_dram_timing = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING);
  390. mc_arb_dram_timing2 = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2);
  391. burst_time = PHM_READ_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE0);
  392. break;
  393. case MC_CG_ARB_FREQ_F1:
  394. mc_arb_dram_timing = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING_1);
  395. mc_arb_dram_timing2 = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2_1);
  396. burst_time = PHM_READ_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE1);
  397. break;
  398. default:
  399. return -EINVAL;
  400. }
  401. switch (arb_dest) {
  402. case MC_CG_ARB_FREQ_F0:
  403. cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING, mc_arb_dram_timing);
  404. cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2, mc_arb_dram_timing2);
  405. PHM_WRITE_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE0, burst_time);
  406. break;
  407. case MC_CG_ARB_FREQ_F1:
  408. cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING_1, mc_arb_dram_timing);
  409. cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2_1, mc_arb_dram_timing2);
  410. PHM_WRITE_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE1, burst_time);
  411. break;
  412. default:
  413. return -EINVAL;
  414. }
  415. mc_cg_config = cgs_read_register(hwmgr->device, mmMC_CG_CONFIG);
  416. mc_cg_config |= 0x0000000F;
  417. cgs_write_register(hwmgr->device, mmMC_CG_CONFIG, mc_cg_config);
  418. PHM_WRITE_FIELD(hwmgr->device, MC_ARB_CG, CG_ARB_REQ, arb_dest);
  419. return 0;
  420. }
  421. static int smu7_reset_to_default(struct pp_hwmgr *hwmgr)
  422. {
  423. return smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_ResetToDefaults);
  424. }
  425. /**
  426. * Initial switch from ARB F0->F1
  427. *
  428. * @param hwmgr the address of the powerplay hardware manager.
  429. * @return always 0
  430. * This function is to be called from the SetPowerState table.
  431. */
  432. static int smu7_initial_switch_from_arbf0_to_f1(struct pp_hwmgr *hwmgr)
  433. {
  434. return smu7_copy_and_switch_arb_sets(hwmgr,
  435. MC_CG_ARB_FREQ_F0, MC_CG_ARB_FREQ_F1);
  436. }
  437. static int smu7_force_switch_to_arbf0(struct pp_hwmgr *hwmgr)
  438. {
  439. uint32_t tmp;
  440. tmp = (cgs_read_ind_register(hwmgr->device,
  441. CGS_IND_REG__SMC, ixSMC_SCRATCH9) &
  442. 0x0000ff00) >> 8;
  443. if (tmp == MC_CG_ARB_FREQ_F0)
  444. return 0;
  445. return smu7_copy_and_switch_arb_sets(hwmgr,
  446. tmp, MC_CG_ARB_FREQ_F0);
  447. }
  448. static int smu7_setup_default_pcie_table(struct pp_hwmgr *hwmgr)
  449. {
  450. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  451. struct phm_ppt_v1_information *table_info =
  452. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  453. struct phm_ppt_v1_pcie_table *pcie_table = NULL;
  454. uint32_t i, max_entry;
  455. uint32_t tmp;
  456. PP_ASSERT_WITH_CODE((data->use_pcie_performance_levels ||
  457. data->use_pcie_power_saving_levels), "No pcie performance levels!",
  458. return -EINVAL);
  459. if (table_info != NULL)
  460. pcie_table = table_info->pcie_table;
  461. if (data->use_pcie_performance_levels &&
  462. !data->use_pcie_power_saving_levels) {
  463. data->pcie_gen_power_saving = data->pcie_gen_performance;
  464. data->pcie_lane_power_saving = data->pcie_lane_performance;
  465. } else if (!data->use_pcie_performance_levels &&
  466. data->use_pcie_power_saving_levels) {
  467. data->pcie_gen_performance = data->pcie_gen_power_saving;
  468. data->pcie_lane_performance = data->pcie_lane_power_saving;
  469. }
  470. tmp = smum_get_mac_definition(hwmgr->smumgr, SMU_MAX_LEVELS_LINK);
  471. phm_reset_single_dpm_table(&data->dpm_table.pcie_speed_table,
  472. tmp,
  473. MAX_REGULAR_DPM_NUMBER);
  474. if (pcie_table != NULL) {
  475. /* max_entry is used to make sure we reserve one PCIE level
  476. * for boot level (fix for A+A PSPP issue).
  477. * If PCIE table from PPTable have ULV entry + 8 entries,
  478. * then ignore the last entry.*/
  479. max_entry = (tmp < pcie_table->count) ? tmp : pcie_table->count;
  480. for (i = 1; i < max_entry; i++) {
  481. phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, i - 1,
  482. get_pcie_gen_support(data->pcie_gen_cap,
  483. pcie_table->entries[i].gen_speed),
  484. get_pcie_lane_support(data->pcie_lane_cap,
  485. pcie_table->entries[i].lane_width));
  486. }
  487. data->dpm_table.pcie_speed_table.count = max_entry - 1;
  488. smum_update_smc_table(hwmgr, SMU_BIF_TABLE);
  489. } else {
  490. /* Hardcode Pcie Table */
  491. phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 0,
  492. get_pcie_gen_support(data->pcie_gen_cap,
  493. PP_Min_PCIEGen),
  494. get_pcie_lane_support(data->pcie_lane_cap,
  495. PP_Max_PCIELane));
  496. phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 1,
  497. get_pcie_gen_support(data->pcie_gen_cap,
  498. PP_Min_PCIEGen),
  499. get_pcie_lane_support(data->pcie_lane_cap,
  500. PP_Max_PCIELane));
  501. phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 2,
  502. get_pcie_gen_support(data->pcie_gen_cap,
  503. PP_Max_PCIEGen),
  504. get_pcie_lane_support(data->pcie_lane_cap,
  505. PP_Max_PCIELane));
  506. phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 3,
  507. get_pcie_gen_support(data->pcie_gen_cap,
  508. PP_Max_PCIEGen),
  509. get_pcie_lane_support(data->pcie_lane_cap,
  510. PP_Max_PCIELane));
  511. phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 4,
  512. get_pcie_gen_support(data->pcie_gen_cap,
  513. PP_Max_PCIEGen),
  514. get_pcie_lane_support(data->pcie_lane_cap,
  515. PP_Max_PCIELane));
  516. phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 5,
  517. get_pcie_gen_support(data->pcie_gen_cap,
  518. PP_Max_PCIEGen),
  519. get_pcie_lane_support(data->pcie_lane_cap,
  520. PP_Max_PCIELane));
  521. data->dpm_table.pcie_speed_table.count = 6;
  522. }
  523. /* Populate last level for boot PCIE level, but do not increment count. */
  524. phm_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table,
  525. data->dpm_table.pcie_speed_table.count,
  526. get_pcie_gen_support(data->pcie_gen_cap,
  527. PP_Min_PCIEGen),
  528. get_pcie_lane_support(data->pcie_lane_cap,
  529. PP_Max_PCIELane));
  530. return 0;
  531. }
  532. static int smu7_reset_dpm_tables(struct pp_hwmgr *hwmgr)
  533. {
  534. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  535. memset(&(data->dpm_table), 0x00, sizeof(data->dpm_table));
  536. phm_reset_single_dpm_table(
  537. &data->dpm_table.sclk_table,
  538. smum_get_mac_definition(hwmgr->smumgr,
  539. SMU_MAX_LEVELS_GRAPHICS),
  540. MAX_REGULAR_DPM_NUMBER);
  541. phm_reset_single_dpm_table(
  542. &data->dpm_table.mclk_table,
  543. smum_get_mac_definition(hwmgr->smumgr,
  544. SMU_MAX_LEVELS_MEMORY), MAX_REGULAR_DPM_NUMBER);
  545. phm_reset_single_dpm_table(
  546. &data->dpm_table.vddc_table,
  547. smum_get_mac_definition(hwmgr->smumgr,
  548. SMU_MAX_LEVELS_VDDC),
  549. MAX_REGULAR_DPM_NUMBER);
  550. phm_reset_single_dpm_table(
  551. &data->dpm_table.vddci_table,
  552. smum_get_mac_definition(hwmgr->smumgr,
  553. SMU_MAX_LEVELS_VDDCI), MAX_REGULAR_DPM_NUMBER);
  554. phm_reset_single_dpm_table(
  555. &data->dpm_table.mvdd_table,
  556. smum_get_mac_definition(hwmgr->smumgr,
  557. SMU_MAX_LEVELS_MVDD),
  558. MAX_REGULAR_DPM_NUMBER);
  559. return 0;
  560. }
  561. /*
  562. * This function is to initialize all DPM state tables
  563. * for SMU7 based on the dependency table.
  564. * Dynamic state patching function will then trim these
  565. * state tables to the allowed range based
  566. * on the power policy or external client requests,
  567. * such as UVD request, etc.
  568. */
  569. static int smu7_setup_dpm_tables_v0(struct pp_hwmgr *hwmgr)
  570. {
  571. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  572. struct phm_clock_voltage_dependency_table *allowed_vdd_sclk_table =
  573. hwmgr->dyn_state.vddc_dependency_on_sclk;
  574. struct phm_clock_voltage_dependency_table *allowed_vdd_mclk_table =
  575. hwmgr->dyn_state.vddc_dependency_on_mclk;
  576. struct phm_cac_leakage_table *std_voltage_table =
  577. hwmgr->dyn_state.cac_leakage_table;
  578. uint32_t i;
  579. PP_ASSERT_WITH_CODE(allowed_vdd_sclk_table != NULL,
  580. "SCLK dependency table is missing. This table is mandatory", return -EINVAL);
  581. PP_ASSERT_WITH_CODE(allowed_vdd_sclk_table->count >= 1,
  582. "SCLK dependency table has to have is missing. This table is mandatory", return -EINVAL);
  583. PP_ASSERT_WITH_CODE(allowed_vdd_mclk_table != NULL,
  584. "MCLK dependency table is missing. This table is mandatory", return -EINVAL);
  585. PP_ASSERT_WITH_CODE(allowed_vdd_mclk_table->count >= 1,
  586. "VMCLK dependency table has to have is missing. This table is mandatory", return -EINVAL);
  587. /* Initialize Sclk DPM table based on allow Sclk values*/
  588. data->dpm_table.sclk_table.count = 0;
  589. for (i = 0; i < allowed_vdd_sclk_table->count; i++) {
  590. if (i == 0 || data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count-1].value !=
  591. allowed_vdd_sclk_table->entries[i].clk) {
  592. data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count].value =
  593. allowed_vdd_sclk_table->entries[i].clk;
  594. data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count].enabled = 1; /*(i==0) ? 1 : 0; to do */
  595. data->dpm_table.sclk_table.count++;
  596. }
  597. }
  598. PP_ASSERT_WITH_CODE(allowed_vdd_mclk_table != NULL,
  599. "MCLK dependency table is missing. This table is mandatory", return -EINVAL);
  600. /* Initialize Mclk DPM table based on allow Mclk values */
  601. data->dpm_table.mclk_table.count = 0;
  602. for (i = 0; i < allowed_vdd_mclk_table->count; i++) {
  603. if (i == 0 || data->dpm_table.mclk_table.dpm_levels[data->dpm_table.mclk_table.count-1].value !=
  604. allowed_vdd_mclk_table->entries[i].clk) {
  605. data->dpm_table.mclk_table.dpm_levels[data->dpm_table.mclk_table.count].value =
  606. allowed_vdd_mclk_table->entries[i].clk;
  607. data->dpm_table.mclk_table.dpm_levels[data->dpm_table.mclk_table.count].enabled = 1; /*(i==0) ? 1 : 0; */
  608. data->dpm_table.mclk_table.count++;
  609. }
  610. }
  611. /* Initialize Vddc DPM table based on allow Vddc values. And populate corresponding std values. */
  612. for (i = 0; i < allowed_vdd_sclk_table->count; i++) {
  613. data->dpm_table.vddc_table.dpm_levels[i].value = allowed_vdd_mclk_table->entries[i].v;
  614. data->dpm_table.vddc_table.dpm_levels[i].param1 = std_voltage_table->entries[i].Leakage;
  615. /* param1 is for corresponding std voltage */
  616. data->dpm_table.vddc_table.dpm_levels[i].enabled = 1;
  617. }
  618. data->dpm_table.vddc_table.count = allowed_vdd_sclk_table->count;
  619. allowed_vdd_mclk_table = hwmgr->dyn_state.vddci_dependency_on_mclk;
  620. if (NULL != allowed_vdd_mclk_table) {
  621. /* Initialize Vddci DPM table based on allow Mclk values */
  622. for (i = 0; i < allowed_vdd_mclk_table->count; i++) {
  623. data->dpm_table.vddci_table.dpm_levels[i].value = allowed_vdd_mclk_table->entries[i].v;
  624. data->dpm_table.vddci_table.dpm_levels[i].enabled = 1;
  625. }
  626. data->dpm_table.vddci_table.count = allowed_vdd_mclk_table->count;
  627. }
  628. allowed_vdd_mclk_table = hwmgr->dyn_state.mvdd_dependency_on_mclk;
  629. if (NULL != allowed_vdd_mclk_table) {
  630. /*
  631. * Initialize MVDD DPM table based on allow Mclk
  632. * values
  633. */
  634. for (i = 0; i < allowed_vdd_mclk_table->count; i++) {
  635. data->dpm_table.mvdd_table.dpm_levels[i].value = allowed_vdd_mclk_table->entries[i].v;
  636. data->dpm_table.mvdd_table.dpm_levels[i].enabled = 1;
  637. }
  638. data->dpm_table.mvdd_table.count = allowed_vdd_mclk_table->count;
  639. }
  640. return 0;
  641. }
  642. static int smu7_setup_dpm_tables_v1(struct pp_hwmgr *hwmgr)
  643. {
  644. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  645. struct phm_ppt_v1_information *table_info =
  646. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  647. uint32_t i;
  648. struct phm_ppt_v1_clock_voltage_dependency_table *dep_sclk_table;
  649. struct phm_ppt_v1_clock_voltage_dependency_table *dep_mclk_table;
  650. if (table_info == NULL)
  651. return -EINVAL;
  652. dep_sclk_table = table_info->vdd_dep_on_sclk;
  653. dep_mclk_table = table_info->vdd_dep_on_mclk;
  654. PP_ASSERT_WITH_CODE(dep_sclk_table != NULL,
  655. "SCLK dependency table is missing.",
  656. return -EINVAL);
  657. PP_ASSERT_WITH_CODE(dep_sclk_table->count >= 1,
  658. "SCLK dependency table count is 0.",
  659. return -EINVAL);
  660. PP_ASSERT_WITH_CODE(dep_mclk_table != NULL,
  661. "MCLK dependency table is missing.",
  662. return -EINVAL);
  663. PP_ASSERT_WITH_CODE(dep_mclk_table->count >= 1,
  664. "MCLK dependency table count is 0",
  665. return -EINVAL);
  666. /* Initialize Sclk DPM table based on allow Sclk values */
  667. data->dpm_table.sclk_table.count = 0;
  668. for (i = 0; i < dep_sclk_table->count; i++) {
  669. if (i == 0 || data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count - 1].value !=
  670. dep_sclk_table->entries[i].clk) {
  671. data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count].value =
  672. dep_sclk_table->entries[i].clk;
  673. data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count].enabled =
  674. (i == 0) ? true : false;
  675. data->dpm_table.sclk_table.count++;
  676. }
  677. }
  678. /* Initialize Mclk DPM table based on allow Mclk values */
  679. data->dpm_table.mclk_table.count = 0;
  680. for (i = 0; i < dep_mclk_table->count; i++) {
  681. if (i == 0 || data->dpm_table.mclk_table.dpm_levels
  682. [data->dpm_table.mclk_table.count - 1].value !=
  683. dep_mclk_table->entries[i].clk) {
  684. data->dpm_table.mclk_table.dpm_levels[data->dpm_table.mclk_table.count].value =
  685. dep_mclk_table->entries[i].clk;
  686. data->dpm_table.mclk_table.dpm_levels[data->dpm_table.mclk_table.count].enabled =
  687. (i == 0) ? true : false;
  688. data->dpm_table.mclk_table.count++;
  689. }
  690. }
  691. return 0;
  692. }
  693. static int smu7_setup_default_dpm_tables(struct pp_hwmgr *hwmgr)
  694. {
  695. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  696. smu7_reset_dpm_tables(hwmgr);
  697. if (hwmgr->pp_table_version == PP_TABLE_V1)
  698. smu7_setup_dpm_tables_v1(hwmgr);
  699. else if (hwmgr->pp_table_version == PP_TABLE_V0)
  700. smu7_setup_dpm_tables_v0(hwmgr);
  701. smu7_setup_default_pcie_table(hwmgr);
  702. /* save a copy of the default DPM table */
  703. memcpy(&(data->golden_dpm_table), &(data->dpm_table),
  704. sizeof(struct smu7_dpm_table));
  705. return 0;
  706. }
  707. uint32_t smu7_get_xclk(struct pp_hwmgr *hwmgr)
  708. {
  709. uint32_t reference_clock, tmp;
  710. struct cgs_display_info info = {0};
  711. struct cgs_mode_info mode_info;
  712. info.mode_info = &mode_info;
  713. tmp = PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, CG_CLKPIN_CNTL_2, MUX_TCLK_TO_XCLK);
  714. if (tmp)
  715. return TCLK;
  716. cgs_get_active_displays_info(hwmgr->device, &info);
  717. reference_clock = mode_info.ref_clock;
  718. tmp = PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, CG_CLKPIN_CNTL, XTALIN_DIVIDE);
  719. if (0 != tmp)
  720. return reference_clock / 4;
  721. return reference_clock;
  722. }
  723. static int smu7_enable_vrhot_gpio_interrupt(struct pp_hwmgr *hwmgr)
  724. {
  725. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  726. PHM_PlatformCaps_RegulatorHot))
  727. return smum_send_msg_to_smc(hwmgr->smumgr,
  728. PPSMC_MSG_EnableVRHotGPIOInterrupt);
  729. return 0;
  730. }
  731. static int smu7_enable_sclk_control(struct pp_hwmgr *hwmgr)
  732. {
  733. PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, SCLK_PWRMGT_CNTL,
  734. SCLK_PWRMGT_OFF, 0);
  735. return 0;
  736. }
  737. static int smu7_enable_ulv(struct pp_hwmgr *hwmgr)
  738. {
  739. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  740. if (data->ulv_supported)
  741. return smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_EnableULV);
  742. return 0;
  743. }
  744. static int smu7_disable_ulv(struct pp_hwmgr *hwmgr)
  745. {
  746. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  747. if (data->ulv_supported)
  748. return smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_DisableULV);
  749. return 0;
  750. }
  751. static int smu7_enable_deep_sleep_master_switch(struct pp_hwmgr *hwmgr)
  752. {
  753. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  754. PHM_PlatformCaps_SclkDeepSleep)) {
  755. if (smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_MASTER_DeepSleep_ON))
  756. PP_ASSERT_WITH_CODE(false,
  757. "Attempt to enable Master Deep Sleep switch failed!",
  758. return -EINVAL);
  759. } else {
  760. if (smum_send_msg_to_smc(hwmgr->smumgr,
  761. PPSMC_MSG_MASTER_DeepSleep_OFF)) {
  762. PP_ASSERT_WITH_CODE(false,
  763. "Attempt to disable Master Deep Sleep switch failed!",
  764. return -EINVAL);
  765. }
  766. }
  767. return 0;
  768. }
  769. static int smu7_disable_deep_sleep_master_switch(struct pp_hwmgr *hwmgr)
  770. {
  771. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  772. PHM_PlatformCaps_SclkDeepSleep)) {
  773. if (smum_send_msg_to_smc(hwmgr->smumgr,
  774. PPSMC_MSG_MASTER_DeepSleep_OFF)) {
  775. PP_ASSERT_WITH_CODE(false,
  776. "Attempt to disable Master Deep Sleep switch failed!",
  777. return -EINVAL);
  778. }
  779. }
  780. return 0;
  781. }
  782. static int smu7_disable_handshake_uvd(struct pp_hwmgr *hwmgr)
  783. {
  784. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  785. uint32_t soft_register_value = 0;
  786. uint32_t handshake_disables_offset = data->soft_regs_start
  787. + smum_get_offsetof(hwmgr->smumgr,
  788. SMU_SoftRegisters, HandshakeDisables);
  789. soft_register_value = cgs_read_ind_register(hwmgr->device,
  790. CGS_IND_REG__SMC, handshake_disables_offset);
  791. soft_register_value |= smum_get_mac_definition(hwmgr->smumgr,
  792. SMU_UVD_MCLK_HANDSHAKE_DISABLE);
  793. cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
  794. handshake_disables_offset, soft_register_value);
  795. return 0;
  796. }
  797. static int smu7_enable_sclk_mclk_dpm(struct pp_hwmgr *hwmgr)
  798. {
  799. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  800. /* enable SCLK dpm */
  801. if (!data->sclk_dpm_key_disabled)
  802. PP_ASSERT_WITH_CODE(
  803. (0 == smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_DPM_Enable)),
  804. "Failed to enable SCLK DPM during DPM Start Function!",
  805. return -EINVAL);
  806. /* enable MCLK dpm */
  807. if (0 == data->mclk_dpm_key_disabled) {
  808. if (!(hwmgr->feature_mask & PP_UVD_HANDSHAKE_MASK))
  809. smu7_disable_handshake_uvd(hwmgr);
  810. PP_ASSERT_WITH_CODE(
  811. (0 == smum_send_msg_to_smc(hwmgr->smumgr,
  812. PPSMC_MSG_MCLKDPM_Enable)),
  813. "Failed to enable MCLK DPM during DPM Start Function!",
  814. return -EINVAL);
  815. PHM_WRITE_FIELD(hwmgr->device, MC_SEQ_CNTL_3, CAC_EN, 0x1);
  816. cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_MC0_CNTL, 0x5);
  817. cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_MC1_CNTL, 0x5);
  818. cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_CPL_CNTL, 0x100005);
  819. udelay(10);
  820. cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_MC0_CNTL, 0x400005);
  821. cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_MC1_CNTL, 0x400005);
  822. cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixLCAC_CPL_CNTL, 0x500005);
  823. }
  824. return 0;
  825. }
  826. static int smu7_start_dpm(struct pp_hwmgr *hwmgr)
  827. {
  828. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  829. /*enable general power management */
  830. PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT,
  831. GLOBAL_PWRMGT_EN, 1);
  832. /* enable sclk deep sleep */
  833. PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, SCLK_PWRMGT_CNTL,
  834. DYNAMIC_PM_EN, 1);
  835. /* prepare for PCIE DPM */
  836. cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
  837. data->soft_regs_start +
  838. smum_get_offsetof(hwmgr->smumgr, SMU_SoftRegisters,
  839. VoltageChangeTimeout), 0x1000);
  840. PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__PCIE,
  841. SWRST_COMMAND_1, RESETLC, 0x0);
  842. if (smu7_enable_sclk_mclk_dpm(hwmgr)) {
  843. pr_err("Failed to enable Sclk DPM and Mclk DPM!");
  844. return -EINVAL;
  845. }
  846. /* enable PCIE dpm */
  847. if (0 == data->pcie_dpm_key_disabled) {
  848. PP_ASSERT_WITH_CODE(
  849. (0 == smum_send_msg_to_smc(hwmgr->smumgr,
  850. PPSMC_MSG_PCIeDPM_Enable)),
  851. "Failed to enable pcie DPM during DPM Start Function!",
  852. return -EINVAL);
  853. }
  854. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  855. PHM_PlatformCaps_Falcon_QuickTransition)) {
  856. PP_ASSERT_WITH_CODE((0 == smum_send_msg_to_smc(hwmgr->smumgr,
  857. PPSMC_MSG_EnableACDCGPIOInterrupt)),
  858. "Failed to enable AC DC GPIO Interrupt!",
  859. );
  860. }
  861. return 0;
  862. }
  863. static int smu7_disable_sclk_mclk_dpm(struct pp_hwmgr *hwmgr)
  864. {
  865. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  866. /* disable SCLK dpm */
  867. if (!data->sclk_dpm_key_disabled) {
  868. PP_ASSERT_WITH_CODE(true == smum_is_dpm_running(hwmgr),
  869. "Trying to disable SCLK DPM when DPM is disabled",
  870. return 0);
  871. smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_DPM_Disable);
  872. }
  873. /* disable MCLK dpm */
  874. if (!data->mclk_dpm_key_disabled) {
  875. PP_ASSERT_WITH_CODE(true == smum_is_dpm_running(hwmgr),
  876. "Trying to disable MCLK DPM when DPM is disabled",
  877. return 0);
  878. smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_MCLKDPM_Disable);
  879. }
  880. return 0;
  881. }
  882. static int smu7_stop_dpm(struct pp_hwmgr *hwmgr)
  883. {
  884. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  885. /* disable general power management */
  886. PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT,
  887. GLOBAL_PWRMGT_EN, 0);
  888. /* disable sclk deep sleep */
  889. PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, SCLK_PWRMGT_CNTL,
  890. DYNAMIC_PM_EN, 0);
  891. /* disable PCIE dpm */
  892. if (!data->pcie_dpm_key_disabled) {
  893. PP_ASSERT_WITH_CODE(
  894. (smum_send_msg_to_smc(hwmgr->smumgr,
  895. PPSMC_MSG_PCIeDPM_Disable) == 0),
  896. "Failed to disable pcie DPM during DPM Stop Function!",
  897. return -EINVAL);
  898. }
  899. smu7_disable_sclk_mclk_dpm(hwmgr);
  900. PP_ASSERT_WITH_CODE(true == smum_is_dpm_running(hwmgr),
  901. "Trying to disable voltage DPM when DPM is disabled",
  902. return 0);
  903. smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_Voltage_Cntl_Disable);
  904. return 0;
  905. }
  906. static void smu7_set_dpm_event_sources(struct pp_hwmgr *hwmgr, uint32_t sources)
  907. {
  908. bool protection;
  909. enum DPM_EVENT_SRC src;
  910. switch (sources) {
  911. default:
  912. pr_err("Unknown throttling event sources.");
  913. /* fall through */
  914. case 0:
  915. protection = false;
  916. /* src is unused */
  917. break;
  918. case (1 << PHM_AutoThrottleSource_Thermal):
  919. protection = true;
  920. src = DPM_EVENT_SRC_DIGITAL;
  921. break;
  922. case (1 << PHM_AutoThrottleSource_External):
  923. protection = true;
  924. src = DPM_EVENT_SRC_EXTERNAL;
  925. break;
  926. case (1 << PHM_AutoThrottleSource_External) |
  927. (1 << PHM_AutoThrottleSource_Thermal):
  928. protection = true;
  929. src = DPM_EVENT_SRC_DIGITAL_OR_EXTERNAL;
  930. break;
  931. }
  932. /* Order matters - don't enable thermal protection for the wrong source. */
  933. if (protection) {
  934. PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, CG_THERMAL_CTRL,
  935. DPM_EVENT_SRC, src);
  936. PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT,
  937. THERMAL_PROTECTION_DIS,
  938. !phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  939. PHM_PlatformCaps_ThermalController));
  940. } else
  941. PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT,
  942. THERMAL_PROTECTION_DIS, 1);
  943. }
  944. static int smu7_enable_auto_throttle_source(struct pp_hwmgr *hwmgr,
  945. PHM_AutoThrottleSource source)
  946. {
  947. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  948. if (!(data->active_auto_throttle_sources & (1 << source))) {
  949. data->active_auto_throttle_sources |= 1 << source;
  950. smu7_set_dpm_event_sources(hwmgr, data->active_auto_throttle_sources);
  951. }
  952. return 0;
  953. }
  954. static int smu7_enable_thermal_auto_throttle(struct pp_hwmgr *hwmgr)
  955. {
  956. return smu7_enable_auto_throttle_source(hwmgr, PHM_AutoThrottleSource_Thermal);
  957. }
  958. static int smu7_disable_auto_throttle_source(struct pp_hwmgr *hwmgr,
  959. PHM_AutoThrottleSource source)
  960. {
  961. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  962. if (data->active_auto_throttle_sources & (1 << source)) {
  963. data->active_auto_throttle_sources &= ~(1 << source);
  964. smu7_set_dpm_event_sources(hwmgr, data->active_auto_throttle_sources);
  965. }
  966. return 0;
  967. }
  968. static int smu7_disable_thermal_auto_throttle(struct pp_hwmgr *hwmgr)
  969. {
  970. return smu7_disable_auto_throttle_source(hwmgr, PHM_AutoThrottleSource_Thermal);
  971. }
  972. static int smu7_pcie_performance_request(struct pp_hwmgr *hwmgr)
  973. {
  974. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  975. data->pcie_performance_request = true;
  976. return 0;
  977. }
  978. static int smu7_enable_dpm_tasks(struct pp_hwmgr *hwmgr)
  979. {
  980. int tmp_result = 0;
  981. int result = 0;
  982. tmp_result = (!smum_is_dpm_running(hwmgr)) ? 0 : -1;
  983. PP_ASSERT_WITH_CODE(tmp_result == 0,
  984. "DPM is already running",
  985. );
  986. if (smu7_voltage_control(hwmgr)) {
  987. tmp_result = smu7_enable_voltage_control(hwmgr);
  988. PP_ASSERT_WITH_CODE(tmp_result == 0,
  989. "Failed to enable voltage control!",
  990. result = tmp_result);
  991. tmp_result = smu7_construct_voltage_tables(hwmgr);
  992. PP_ASSERT_WITH_CODE((0 == tmp_result),
  993. "Failed to contruct voltage tables!",
  994. result = tmp_result);
  995. }
  996. smum_initialize_mc_reg_table(hwmgr);
  997. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  998. PHM_PlatformCaps_EngineSpreadSpectrumSupport))
  999. PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
  1000. GENERAL_PWRMGT, DYN_SPREAD_SPECTRUM_EN, 1);
  1001. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  1002. PHM_PlatformCaps_ThermalController))
  1003. PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
  1004. GENERAL_PWRMGT, THERMAL_PROTECTION_DIS, 0);
  1005. tmp_result = smu7_program_static_screen_threshold_parameters(hwmgr);
  1006. PP_ASSERT_WITH_CODE((0 == tmp_result),
  1007. "Failed to program static screen threshold parameters!",
  1008. result = tmp_result);
  1009. tmp_result = smu7_enable_display_gap(hwmgr);
  1010. PP_ASSERT_WITH_CODE((0 == tmp_result),
  1011. "Failed to enable display gap!", result = tmp_result);
  1012. tmp_result = smu7_program_voting_clients(hwmgr);
  1013. PP_ASSERT_WITH_CODE((0 == tmp_result),
  1014. "Failed to program voting clients!", result = tmp_result);
  1015. tmp_result = smum_process_firmware_header(hwmgr);
  1016. PP_ASSERT_WITH_CODE((0 == tmp_result),
  1017. "Failed to process firmware header!", result = tmp_result);
  1018. tmp_result = smu7_initial_switch_from_arbf0_to_f1(hwmgr);
  1019. PP_ASSERT_WITH_CODE((0 == tmp_result),
  1020. "Failed to initialize switch from ArbF0 to F1!",
  1021. result = tmp_result);
  1022. result = smu7_setup_default_dpm_tables(hwmgr);
  1023. PP_ASSERT_WITH_CODE(0 == result,
  1024. "Failed to setup default DPM tables!", return result);
  1025. tmp_result = smum_init_smc_table(hwmgr);
  1026. PP_ASSERT_WITH_CODE((0 == tmp_result),
  1027. "Failed to initialize SMC table!", result = tmp_result);
  1028. tmp_result = smu7_enable_vrhot_gpio_interrupt(hwmgr);
  1029. PP_ASSERT_WITH_CODE((0 == tmp_result),
  1030. "Failed to enable VR hot GPIO interrupt!", result = tmp_result);
  1031. smum_send_msg_to_smc(hwmgr->smumgr, (PPSMC_Msg)PPSMC_NoDisplay);
  1032. tmp_result = smu7_enable_sclk_control(hwmgr);
  1033. PP_ASSERT_WITH_CODE((0 == tmp_result),
  1034. "Failed to enable SCLK control!", result = tmp_result);
  1035. tmp_result = smu7_enable_smc_voltage_controller(hwmgr);
  1036. PP_ASSERT_WITH_CODE((0 == tmp_result),
  1037. "Failed to enable voltage control!", result = tmp_result);
  1038. tmp_result = smu7_enable_ulv(hwmgr);
  1039. PP_ASSERT_WITH_CODE((0 == tmp_result),
  1040. "Failed to enable ULV!", result = tmp_result);
  1041. tmp_result = smu7_enable_deep_sleep_master_switch(hwmgr);
  1042. PP_ASSERT_WITH_CODE((0 == tmp_result),
  1043. "Failed to enable deep sleep master switch!", result = tmp_result);
  1044. tmp_result = smu7_enable_didt_config(hwmgr);
  1045. PP_ASSERT_WITH_CODE((tmp_result == 0),
  1046. "Failed to enable deep sleep master switch!", result = tmp_result);
  1047. tmp_result = smu7_start_dpm(hwmgr);
  1048. PP_ASSERT_WITH_CODE((0 == tmp_result),
  1049. "Failed to start DPM!", result = tmp_result);
  1050. tmp_result = smu7_enable_smc_cac(hwmgr);
  1051. PP_ASSERT_WITH_CODE((0 == tmp_result),
  1052. "Failed to enable SMC CAC!", result = tmp_result);
  1053. tmp_result = smu7_enable_power_containment(hwmgr);
  1054. PP_ASSERT_WITH_CODE((0 == tmp_result),
  1055. "Failed to enable power containment!", result = tmp_result);
  1056. tmp_result = smu7_power_control_set_level(hwmgr);
  1057. PP_ASSERT_WITH_CODE((0 == tmp_result),
  1058. "Failed to power control set level!", result = tmp_result);
  1059. tmp_result = smu7_enable_thermal_auto_throttle(hwmgr);
  1060. PP_ASSERT_WITH_CODE((0 == tmp_result),
  1061. "Failed to enable thermal auto throttle!", result = tmp_result);
  1062. tmp_result = smu7_pcie_performance_request(hwmgr);
  1063. PP_ASSERT_WITH_CODE((0 == tmp_result),
  1064. "pcie performance request failed!", result = tmp_result);
  1065. return 0;
  1066. }
  1067. int smu7_disable_dpm_tasks(struct pp_hwmgr *hwmgr)
  1068. {
  1069. int tmp_result, result = 0;
  1070. tmp_result = (smum_is_dpm_running(hwmgr)) ? 0 : -1;
  1071. PP_ASSERT_WITH_CODE(tmp_result == 0,
  1072. "DPM is not running right now, no need to disable DPM!",
  1073. return 0);
  1074. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  1075. PHM_PlatformCaps_ThermalController))
  1076. PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
  1077. GENERAL_PWRMGT, THERMAL_PROTECTION_DIS, 1);
  1078. tmp_result = smu7_disable_power_containment(hwmgr);
  1079. PP_ASSERT_WITH_CODE((tmp_result == 0),
  1080. "Failed to disable power containment!", result = tmp_result);
  1081. tmp_result = smu7_disable_smc_cac(hwmgr);
  1082. PP_ASSERT_WITH_CODE((tmp_result == 0),
  1083. "Failed to disable SMC CAC!", result = tmp_result);
  1084. tmp_result = smu7_disable_didt_config(hwmgr);
  1085. PP_ASSERT_WITH_CODE((tmp_result == 0),
  1086. "Failed to disable DIDT!", result = tmp_result);
  1087. PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
  1088. CG_SPLL_SPREAD_SPECTRUM, SSEN, 0);
  1089. PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
  1090. GENERAL_PWRMGT, DYN_SPREAD_SPECTRUM_EN, 0);
  1091. tmp_result = smu7_disable_thermal_auto_throttle(hwmgr);
  1092. PP_ASSERT_WITH_CODE((tmp_result == 0),
  1093. "Failed to disable thermal auto throttle!", result = tmp_result);
  1094. tmp_result = smu7_avfs_control(hwmgr, false);
  1095. PP_ASSERT_WITH_CODE((tmp_result == 0),
  1096. "Failed to disable AVFS!", result = tmp_result);
  1097. tmp_result = smu7_stop_dpm(hwmgr);
  1098. PP_ASSERT_WITH_CODE((tmp_result == 0),
  1099. "Failed to stop DPM!", result = tmp_result);
  1100. tmp_result = smu7_disable_deep_sleep_master_switch(hwmgr);
  1101. PP_ASSERT_WITH_CODE((tmp_result == 0),
  1102. "Failed to disable deep sleep master switch!", result = tmp_result);
  1103. tmp_result = smu7_disable_ulv(hwmgr);
  1104. PP_ASSERT_WITH_CODE((tmp_result == 0),
  1105. "Failed to disable ULV!", result = tmp_result);
  1106. tmp_result = smu7_clear_voting_clients(hwmgr);
  1107. PP_ASSERT_WITH_CODE((tmp_result == 0),
  1108. "Failed to clear voting clients!", result = tmp_result);
  1109. tmp_result = smu7_reset_to_default(hwmgr);
  1110. PP_ASSERT_WITH_CODE((tmp_result == 0),
  1111. "Failed to reset to default!", result = tmp_result);
  1112. tmp_result = smu7_force_switch_to_arbf0(hwmgr);
  1113. PP_ASSERT_WITH_CODE((tmp_result == 0),
  1114. "Failed to force to switch arbf0!", result = tmp_result);
  1115. return result;
  1116. }
  1117. int smu7_reset_asic_tasks(struct pp_hwmgr *hwmgr)
  1118. {
  1119. return 0;
  1120. }
  1121. static void smu7_init_dpm_defaults(struct pp_hwmgr *hwmgr)
  1122. {
  1123. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  1124. struct phm_ppt_v1_information *table_info =
  1125. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  1126. struct cgs_system_info sys_info = {0};
  1127. int result;
  1128. data->dll_default_on = false;
  1129. data->mclk_dpm0_activity_target = 0xa;
  1130. data->mclk_activity_target = SMU7_MCLK_TARGETACTIVITY_DFLT;
  1131. data->vddc_vddgfx_delta = 300;
  1132. data->static_screen_threshold = SMU7_STATICSCREENTHRESHOLD_DFLT;
  1133. data->static_screen_threshold_unit = SMU7_STATICSCREENTHRESHOLDUNIT_DFLT;
  1134. data->voting_rights_clients0 = SMU7_VOTINGRIGHTSCLIENTS_DFLT0;
  1135. data->voting_rights_clients1 = SMU7_VOTINGRIGHTSCLIENTS_DFLT1;
  1136. data->voting_rights_clients2 = SMU7_VOTINGRIGHTSCLIENTS_DFLT2;
  1137. data->voting_rights_clients3 = SMU7_VOTINGRIGHTSCLIENTS_DFLT3;
  1138. data->voting_rights_clients4 = SMU7_VOTINGRIGHTSCLIENTS_DFLT4;
  1139. data->voting_rights_clients5 = SMU7_VOTINGRIGHTSCLIENTS_DFLT5;
  1140. data->voting_rights_clients6 = SMU7_VOTINGRIGHTSCLIENTS_DFLT6;
  1141. data->voting_rights_clients7 = SMU7_VOTINGRIGHTSCLIENTS_DFLT7;
  1142. data->mclk_dpm_key_disabled = hwmgr->feature_mask & PP_MCLK_DPM_MASK ? false : true;
  1143. data->sclk_dpm_key_disabled = hwmgr->feature_mask & PP_SCLK_DPM_MASK ? false : true;
  1144. data->pcie_dpm_key_disabled = hwmgr->feature_mask & PP_PCIE_DPM_MASK ? false : true;
  1145. /* need to set voltage control types before EVV patching */
  1146. data->voltage_control = SMU7_VOLTAGE_CONTROL_NONE;
  1147. data->vddci_control = SMU7_VOLTAGE_CONTROL_NONE;
  1148. data->mvdd_control = SMU7_VOLTAGE_CONTROL_NONE;
  1149. data->enable_tdc_limit_feature = true;
  1150. data->enable_pkg_pwr_tracking_feature = true;
  1151. data->force_pcie_gen = PP_PCIEGenInvalid;
  1152. data->ulv_supported = hwmgr->feature_mask & PP_ULV_MASK ? true : false;
  1153. if (hwmgr->chip_id == CHIP_POLARIS12 || hwmgr->smumgr->is_kicker) {
  1154. uint8_t tmp1, tmp2;
  1155. uint16_t tmp3 = 0;
  1156. atomctrl_get_svi2_info(hwmgr, VOLTAGE_TYPE_VDDC, &tmp1, &tmp2,
  1157. &tmp3);
  1158. tmp3 = (tmp3 >> 5) & 0x3;
  1159. data->vddc_phase_shed_control = ((tmp3 << 1) | (tmp3 >> 1)) & 0x3;
  1160. }
  1161. data->fast_watermark_threshold = 100;
  1162. if (atomctrl_is_voltage_controled_by_gpio_v3(hwmgr,
  1163. VOLTAGE_TYPE_VDDC, VOLTAGE_OBJ_SVID2))
  1164. data->voltage_control = SMU7_VOLTAGE_CONTROL_BY_SVID2;
  1165. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  1166. PHM_PlatformCaps_ControlVDDGFX)) {
  1167. if (atomctrl_is_voltage_controled_by_gpio_v3(hwmgr,
  1168. VOLTAGE_TYPE_VDDGFX, VOLTAGE_OBJ_SVID2)) {
  1169. data->vdd_gfx_control = SMU7_VOLTAGE_CONTROL_BY_SVID2;
  1170. }
  1171. }
  1172. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  1173. PHM_PlatformCaps_EnableMVDDControl)) {
  1174. if (atomctrl_is_voltage_controled_by_gpio_v3(hwmgr,
  1175. VOLTAGE_TYPE_MVDDC, VOLTAGE_OBJ_GPIO_LUT))
  1176. data->mvdd_control = SMU7_VOLTAGE_CONTROL_BY_GPIO;
  1177. else if (atomctrl_is_voltage_controled_by_gpio_v3(hwmgr,
  1178. VOLTAGE_TYPE_MVDDC, VOLTAGE_OBJ_SVID2))
  1179. data->mvdd_control = SMU7_VOLTAGE_CONTROL_BY_SVID2;
  1180. }
  1181. if (SMU7_VOLTAGE_CONTROL_NONE == data->vdd_gfx_control) {
  1182. phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
  1183. PHM_PlatformCaps_ControlVDDGFX);
  1184. }
  1185. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  1186. PHM_PlatformCaps_ControlVDDCI)) {
  1187. if (atomctrl_is_voltage_controled_by_gpio_v3(hwmgr,
  1188. VOLTAGE_TYPE_VDDCI, VOLTAGE_OBJ_GPIO_LUT))
  1189. data->vddci_control = SMU7_VOLTAGE_CONTROL_BY_GPIO;
  1190. else if (atomctrl_is_voltage_controled_by_gpio_v3(hwmgr,
  1191. VOLTAGE_TYPE_VDDCI, VOLTAGE_OBJ_SVID2))
  1192. data->vddci_control = SMU7_VOLTAGE_CONTROL_BY_SVID2;
  1193. }
  1194. if (data->mvdd_control == SMU7_VOLTAGE_CONTROL_NONE)
  1195. phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
  1196. PHM_PlatformCaps_EnableMVDDControl);
  1197. if (data->vddci_control == SMU7_VOLTAGE_CONTROL_NONE)
  1198. phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
  1199. PHM_PlatformCaps_ControlVDDCI);
  1200. if ((hwmgr->pp_table_version != PP_TABLE_V0) && (hwmgr->feature_mask & PP_CLOCK_STRETCH_MASK)
  1201. && (table_info->cac_dtp_table->usClockStretchAmount != 0))
  1202. phm_cap_set(hwmgr->platform_descriptor.platformCaps,
  1203. PHM_PlatformCaps_ClockStretcher);
  1204. data->pcie_gen_performance.max = PP_PCIEGen1;
  1205. data->pcie_gen_performance.min = PP_PCIEGen3;
  1206. data->pcie_gen_power_saving.max = PP_PCIEGen1;
  1207. data->pcie_gen_power_saving.min = PP_PCIEGen3;
  1208. data->pcie_lane_performance.max = 0;
  1209. data->pcie_lane_performance.min = 16;
  1210. data->pcie_lane_power_saving.max = 0;
  1211. data->pcie_lane_power_saving.min = 16;
  1212. sys_info.size = sizeof(struct cgs_system_info);
  1213. sys_info.info_id = CGS_SYSTEM_INFO_PG_FLAGS;
  1214. result = cgs_query_system_info(hwmgr->device, &sys_info);
  1215. if (!result) {
  1216. if (sys_info.value & AMD_PG_SUPPORT_UVD)
  1217. phm_cap_set(hwmgr->platform_descriptor.platformCaps,
  1218. PHM_PlatformCaps_UVDPowerGating);
  1219. if (sys_info.value & AMD_PG_SUPPORT_VCE)
  1220. phm_cap_set(hwmgr->platform_descriptor.platformCaps,
  1221. PHM_PlatformCaps_VCEPowerGating);
  1222. }
  1223. }
  1224. /**
  1225. * Get Leakage VDDC based on leakage ID.
  1226. *
  1227. * @param hwmgr the address of the powerplay hardware manager.
  1228. * @return always 0
  1229. */
  1230. static int smu7_get_evv_voltages(struct pp_hwmgr *hwmgr)
  1231. {
  1232. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  1233. uint16_t vv_id;
  1234. uint16_t vddc = 0;
  1235. uint16_t vddgfx = 0;
  1236. uint16_t i, j;
  1237. uint32_t sclk = 0;
  1238. struct phm_ppt_v1_information *table_info =
  1239. (struct phm_ppt_v1_information *)hwmgr->pptable;
  1240. struct phm_ppt_v1_clock_voltage_dependency_table *sclk_table = NULL;
  1241. for (i = 0; i < SMU7_MAX_LEAKAGE_COUNT; i++) {
  1242. vv_id = ATOM_VIRTUAL_VOLTAGE_ID0 + i;
  1243. if (data->vdd_gfx_control == SMU7_VOLTAGE_CONTROL_BY_SVID2) {
  1244. if ((hwmgr->pp_table_version == PP_TABLE_V1)
  1245. && !phm_get_sclk_for_voltage_evv(hwmgr,
  1246. table_info->vddgfx_lookup_table, vv_id, &sclk)) {
  1247. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  1248. PHM_PlatformCaps_ClockStretcher)) {
  1249. sclk_table = table_info->vdd_dep_on_sclk;
  1250. for (j = 1; j < sclk_table->count; j++) {
  1251. if (sclk_table->entries[j].clk == sclk &&
  1252. sclk_table->entries[j].cks_enable == 0) {
  1253. sclk += 5000;
  1254. break;
  1255. }
  1256. }
  1257. }
  1258. if (0 == atomctrl_get_voltage_evv_on_sclk
  1259. (hwmgr, VOLTAGE_TYPE_VDDGFX, sclk,
  1260. vv_id, &vddgfx)) {
  1261. /* need to make sure vddgfx is less than 2v or else, it could burn the ASIC. */
  1262. PP_ASSERT_WITH_CODE((vddgfx < 2000 && vddgfx != 0), "Invalid VDDGFX value!", return -EINVAL);
  1263. /* the voltage should not be zero nor equal to leakage ID */
  1264. if (vddgfx != 0 && vddgfx != vv_id) {
  1265. data->vddcgfx_leakage.actual_voltage[data->vddcgfx_leakage.count] = vddgfx;
  1266. data->vddcgfx_leakage.leakage_id[data->vddcgfx_leakage.count] = vv_id;
  1267. data->vddcgfx_leakage.count++;
  1268. }
  1269. } else {
  1270. pr_info("Error retrieving EVV voltage value!\n");
  1271. }
  1272. }
  1273. } else {
  1274. if ((hwmgr->pp_table_version == PP_TABLE_V0)
  1275. || !phm_get_sclk_for_voltage_evv(hwmgr,
  1276. table_info->vddc_lookup_table, vv_id, &sclk)) {
  1277. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  1278. PHM_PlatformCaps_ClockStretcher)) {
  1279. if (table_info == NULL)
  1280. return -EINVAL;
  1281. sclk_table = table_info->vdd_dep_on_sclk;
  1282. for (j = 1; j < sclk_table->count; j++) {
  1283. if (sclk_table->entries[j].clk == sclk &&
  1284. sclk_table->entries[j].cks_enable == 0) {
  1285. sclk += 5000;
  1286. break;
  1287. }
  1288. }
  1289. }
  1290. if (phm_get_voltage_evv_on_sclk(hwmgr,
  1291. VOLTAGE_TYPE_VDDC,
  1292. sclk, vv_id, &vddc) == 0) {
  1293. if (vddc >= 2000 || vddc == 0)
  1294. return -EINVAL;
  1295. } else {
  1296. pr_warn("failed to retrieving EVV voltage!\n");
  1297. continue;
  1298. }
  1299. /* the voltage should not be zero nor equal to leakage ID */
  1300. if (vddc != 0 && vddc != vv_id) {
  1301. data->vddc_leakage.actual_voltage[data->vddc_leakage.count] = (uint16_t)(vddc);
  1302. data->vddc_leakage.leakage_id[data->vddc_leakage.count] = vv_id;
  1303. data->vddc_leakage.count++;
  1304. }
  1305. }
  1306. }
  1307. }
  1308. return 0;
  1309. }
  1310. /**
  1311. * Change virtual leakage voltage to actual value.
  1312. *
  1313. * @param hwmgr the address of the powerplay hardware manager.
  1314. * @param pointer to changing voltage
  1315. * @param pointer to leakage table
  1316. */
  1317. static void smu7_patch_ppt_v1_with_vdd_leakage(struct pp_hwmgr *hwmgr,
  1318. uint16_t *voltage, struct smu7_leakage_voltage *leakage_table)
  1319. {
  1320. uint32_t index;
  1321. /* search for leakage voltage ID 0xff01 ~ 0xff08 */
  1322. for (index = 0; index < leakage_table->count; index++) {
  1323. /* if this voltage matches a leakage voltage ID */
  1324. /* patch with actual leakage voltage */
  1325. if (leakage_table->leakage_id[index] == *voltage) {
  1326. *voltage = leakage_table->actual_voltage[index];
  1327. break;
  1328. }
  1329. }
  1330. if (*voltage > ATOM_VIRTUAL_VOLTAGE_ID0)
  1331. pr_err("Voltage value looks like a Leakage ID but it's not patched \n");
  1332. }
  1333. /**
  1334. * Patch voltage lookup table by EVV leakages.
  1335. *
  1336. * @param hwmgr the address of the powerplay hardware manager.
  1337. * @param pointer to voltage lookup table
  1338. * @param pointer to leakage table
  1339. * @return always 0
  1340. */
  1341. static int smu7_patch_lookup_table_with_leakage(struct pp_hwmgr *hwmgr,
  1342. phm_ppt_v1_voltage_lookup_table *lookup_table,
  1343. struct smu7_leakage_voltage *leakage_table)
  1344. {
  1345. uint32_t i;
  1346. for (i = 0; i < lookup_table->count; i++)
  1347. smu7_patch_ppt_v1_with_vdd_leakage(hwmgr,
  1348. &lookup_table->entries[i].us_vdd, leakage_table);
  1349. return 0;
  1350. }
  1351. static int smu7_patch_clock_voltage_limits_with_vddc_leakage(
  1352. struct pp_hwmgr *hwmgr, struct smu7_leakage_voltage *leakage_table,
  1353. uint16_t *vddc)
  1354. {
  1355. struct phm_ppt_v1_information *table_info =
  1356. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  1357. smu7_patch_ppt_v1_with_vdd_leakage(hwmgr, (uint16_t *)vddc, leakage_table);
  1358. hwmgr->dyn_state.max_clock_voltage_on_dc.vddc =
  1359. table_info->max_clock_voltage_on_dc.vddc;
  1360. return 0;
  1361. }
  1362. static int smu7_patch_voltage_dependency_tables_with_lookup_table(
  1363. struct pp_hwmgr *hwmgr)
  1364. {
  1365. uint8_t entry_id;
  1366. uint8_t voltage_id;
  1367. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  1368. struct phm_ppt_v1_information *table_info =
  1369. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  1370. struct phm_ppt_v1_clock_voltage_dependency_table *sclk_table =
  1371. table_info->vdd_dep_on_sclk;
  1372. struct phm_ppt_v1_clock_voltage_dependency_table *mclk_table =
  1373. table_info->vdd_dep_on_mclk;
  1374. struct phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table =
  1375. table_info->mm_dep_table;
  1376. if (data->vdd_gfx_control == SMU7_VOLTAGE_CONTROL_BY_SVID2) {
  1377. for (entry_id = 0; entry_id < sclk_table->count; ++entry_id) {
  1378. voltage_id = sclk_table->entries[entry_id].vddInd;
  1379. sclk_table->entries[entry_id].vddgfx =
  1380. table_info->vddgfx_lookup_table->entries[voltage_id].us_vdd;
  1381. }
  1382. } else {
  1383. for (entry_id = 0; entry_id < sclk_table->count; ++entry_id) {
  1384. voltage_id = sclk_table->entries[entry_id].vddInd;
  1385. sclk_table->entries[entry_id].vddc =
  1386. table_info->vddc_lookup_table->entries[voltage_id].us_vdd;
  1387. }
  1388. }
  1389. for (entry_id = 0; entry_id < mclk_table->count; ++entry_id) {
  1390. voltage_id = mclk_table->entries[entry_id].vddInd;
  1391. mclk_table->entries[entry_id].vddc =
  1392. table_info->vddc_lookup_table->entries[voltage_id].us_vdd;
  1393. }
  1394. for (entry_id = 0; entry_id < mm_table->count; ++entry_id) {
  1395. voltage_id = mm_table->entries[entry_id].vddcInd;
  1396. mm_table->entries[entry_id].vddc =
  1397. table_info->vddc_lookup_table->entries[voltage_id].us_vdd;
  1398. }
  1399. return 0;
  1400. }
  1401. static int phm_add_voltage(struct pp_hwmgr *hwmgr,
  1402. phm_ppt_v1_voltage_lookup_table *look_up_table,
  1403. phm_ppt_v1_voltage_lookup_record *record)
  1404. {
  1405. uint32_t i;
  1406. PP_ASSERT_WITH_CODE((NULL != look_up_table),
  1407. "Lookup Table empty.", return -EINVAL);
  1408. PP_ASSERT_WITH_CODE((0 != look_up_table->count),
  1409. "Lookup Table empty.", return -EINVAL);
  1410. i = smum_get_mac_definition(hwmgr->smumgr, SMU_MAX_LEVELS_VDDGFX);
  1411. PP_ASSERT_WITH_CODE((i >= look_up_table->count),
  1412. "Lookup Table is full.", return -EINVAL);
  1413. /* This is to avoid entering duplicate calculated records. */
  1414. for (i = 0; i < look_up_table->count; i++) {
  1415. if (look_up_table->entries[i].us_vdd == record->us_vdd) {
  1416. if (look_up_table->entries[i].us_calculated == 1)
  1417. return 0;
  1418. break;
  1419. }
  1420. }
  1421. look_up_table->entries[i].us_calculated = 1;
  1422. look_up_table->entries[i].us_vdd = record->us_vdd;
  1423. look_up_table->entries[i].us_cac_low = record->us_cac_low;
  1424. look_up_table->entries[i].us_cac_mid = record->us_cac_mid;
  1425. look_up_table->entries[i].us_cac_high = record->us_cac_high;
  1426. /* Only increment the count when we're appending, not replacing duplicate entry. */
  1427. if (i == look_up_table->count)
  1428. look_up_table->count++;
  1429. return 0;
  1430. }
  1431. static int smu7_calc_voltage_dependency_tables(struct pp_hwmgr *hwmgr)
  1432. {
  1433. uint8_t entry_id;
  1434. struct phm_ppt_v1_voltage_lookup_record v_record;
  1435. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  1436. struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable);
  1437. phm_ppt_v1_clock_voltage_dependency_table *sclk_table = pptable_info->vdd_dep_on_sclk;
  1438. phm_ppt_v1_clock_voltage_dependency_table *mclk_table = pptable_info->vdd_dep_on_mclk;
  1439. if (data->vdd_gfx_control == SMU7_VOLTAGE_CONTROL_BY_SVID2) {
  1440. for (entry_id = 0; entry_id < sclk_table->count; ++entry_id) {
  1441. if (sclk_table->entries[entry_id].vdd_offset & (1 << 15))
  1442. v_record.us_vdd = sclk_table->entries[entry_id].vddgfx +
  1443. sclk_table->entries[entry_id].vdd_offset - 0xFFFF;
  1444. else
  1445. v_record.us_vdd = sclk_table->entries[entry_id].vddgfx +
  1446. sclk_table->entries[entry_id].vdd_offset;
  1447. sclk_table->entries[entry_id].vddc =
  1448. v_record.us_cac_low = v_record.us_cac_mid =
  1449. v_record.us_cac_high = v_record.us_vdd;
  1450. phm_add_voltage(hwmgr, pptable_info->vddc_lookup_table, &v_record);
  1451. }
  1452. for (entry_id = 0; entry_id < mclk_table->count; ++entry_id) {
  1453. if (mclk_table->entries[entry_id].vdd_offset & (1 << 15))
  1454. v_record.us_vdd = mclk_table->entries[entry_id].vddc +
  1455. mclk_table->entries[entry_id].vdd_offset - 0xFFFF;
  1456. else
  1457. v_record.us_vdd = mclk_table->entries[entry_id].vddc +
  1458. mclk_table->entries[entry_id].vdd_offset;
  1459. mclk_table->entries[entry_id].vddgfx = v_record.us_cac_low =
  1460. v_record.us_cac_mid = v_record.us_cac_high = v_record.us_vdd;
  1461. phm_add_voltage(hwmgr, pptable_info->vddgfx_lookup_table, &v_record);
  1462. }
  1463. }
  1464. return 0;
  1465. }
  1466. static int smu7_calc_mm_voltage_dependency_table(struct pp_hwmgr *hwmgr)
  1467. {
  1468. uint8_t entry_id;
  1469. struct phm_ppt_v1_voltage_lookup_record v_record;
  1470. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  1471. struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable);
  1472. phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table = pptable_info->mm_dep_table;
  1473. if (data->vdd_gfx_control == SMU7_VOLTAGE_CONTROL_BY_SVID2) {
  1474. for (entry_id = 0; entry_id < mm_table->count; entry_id++) {
  1475. if (mm_table->entries[entry_id].vddgfx_offset & (1 << 15))
  1476. v_record.us_vdd = mm_table->entries[entry_id].vddc +
  1477. mm_table->entries[entry_id].vddgfx_offset - 0xFFFF;
  1478. else
  1479. v_record.us_vdd = mm_table->entries[entry_id].vddc +
  1480. mm_table->entries[entry_id].vddgfx_offset;
  1481. /* Add the calculated VDDGFX to the VDDGFX lookup table */
  1482. mm_table->entries[entry_id].vddgfx = v_record.us_cac_low =
  1483. v_record.us_cac_mid = v_record.us_cac_high = v_record.us_vdd;
  1484. phm_add_voltage(hwmgr, pptable_info->vddgfx_lookup_table, &v_record);
  1485. }
  1486. }
  1487. return 0;
  1488. }
  1489. static int smu7_sort_lookup_table(struct pp_hwmgr *hwmgr,
  1490. struct phm_ppt_v1_voltage_lookup_table *lookup_table)
  1491. {
  1492. uint32_t table_size, i, j;
  1493. struct phm_ppt_v1_voltage_lookup_record tmp_voltage_lookup_record;
  1494. table_size = lookup_table->count;
  1495. PP_ASSERT_WITH_CODE(0 != lookup_table->count,
  1496. "Lookup table is empty", return -EINVAL);
  1497. /* Sorting voltages */
  1498. for (i = 0; i < table_size - 1; i++) {
  1499. for (j = i + 1; j > 0; j--) {
  1500. if (lookup_table->entries[j].us_vdd <
  1501. lookup_table->entries[j - 1].us_vdd) {
  1502. tmp_voltage_lookup_record = lookup_table->entries[j - 1];
  1503. lookup_table->entries[j - 1] = lookup_table->entries[j];
  1504. lookup_table->entries[j] = tmp_voltage_lookup_record;
  1505. }
  1506. }
  1507. }
  1508. return 0;
  1509. }
  1510. static int smu7_complete_dependency_tables(struct pp_hwmgr *hwmgr)
  1511. {
  1512. int result = 0;
  1513. int tmp_result;
  1514. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  1515. struct phm_ppt_v1_information *table_info =
  1516. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  1517. if (data->vdd_gfx_control == SMU7_VOLTAGE_CONTROL_BY_SVID2) {
  1518. tmp_result = smu7_patch_lookup_table_with_leakage(hwmgr,
  1519. table_info->vddgfx_lookup_table, &(data->vddcgfx_leakage));
  1520. if (tmp_result != 0)
  1521. result = tmp_result;
  1522. smu7_patch_ppt_v1_with_vdd_leakage(hwmgr,
  1523. &table_info->max_clock_voltage_on_dc.vddgfx, &(data->vddcgfx_leakage));
  1524. } else {
  1525. tmp_result = smu7_patch_lookup_table_with_leakage(hwmgr,
  1526. table_info->vddc_lookup_table, &(data->vddc_leakage));
  1527. if (tmp_result)
  1528. result = tmp_result;
  1529. tmp_result = smu7_patch_clock_voltage_limits_with_vddc_leakage(hwmgr,
  1530. &(data->vddc_leakage), &table_info->max_clock_voltage_on_dc.vddc);
  1531. if (tmp_result)
  1532. result = tmp_result;
  1533. }
  1534. tmp_result = smu7_patch_voltage_dependency_tables_with_lookup_table(hwmgr);
  1535. if (tmp_result)
  1536. result = tmp_result;
  1537. tmp_result = smu7_calc_voltage_dependency_tables(hwmgr);
  1538. if (tmp_result)
  1539. result = tmp_result;
  1540. tmp_result = smu7_calc_mm_voltage_dependency_table(hwmgr);
  1541. if (tmp_result)
  1542. result = tmp_result;
  1543. tmp_result = smu7_sort_lookup_table(hwmgr, table_info->vddgfx_lookup_table);
  1544. if (tmp_result)
  1545. result = tmp_result;
  1546. tmp_result = smu7_sort_lookup_table(hwmgr, table_info->vddc_lookup_table);
  1547. if (tmp_result)
  1548. result = tmp_result;
  1549. return result;
  1550. }
  1551. static int smu7_set_private_data_based_on_pptable_v1(struct pp_hwmgr *hwmgr)
  1552. {
  1553. struct phm_ppt_v1_information *table_info =
  1554. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  1555. struct phm_ppt_v1_clock_voltage_dependency_table *allowed_sclk_vdd_table =
  1556. table_info->vdd_dep_on_sclk;
  1557. struct phm_ppt_v1_clock_voltage_dependency_table *allowed_mclk_vdd_table =
  1558. table_info->vdd_dep_on_mclk;
  1559. PP_ASSERT_WITH_CODE(allowed_sclk_vdd_table != NULL,
  1560. "VDD dependency on SCLK table is missing.",
  1561. return -EINVAL);
  1562. PP_ASSERT_WITH_CODE(allowed_sclk_vdd_table->count >= 1,
  1563. "VDD dependency on SCLK table has to have is missing.",
  1564. return -EINVAL);
  1565. PP_ASSERT_WITH_CODE(allowed_mclk_vdd_table != NULL,
  1566. "VDD dependency on MCLK table is missing",
  1567. return -EINVAL);
  1568. PP_ASSERT_WITH_CODE(allowed_mclk_vdd_table->count >= 1,
  1569. "VDD dependency on MCLK table has to have is missing.",
  1570. return -EINVAL);
  1571. table_info->max_clock_voltage_on_ac.sclk =
  1572. allowed_sclk_vdd_table->entries[allowed_sclk_vdd_table->count - 1].clk;
  1573. table_info->max_clock_voltage_on_ac.mclk =
  1574. allowed_mclk_vdd_table->entries[allowed_mclk_vdd_table->count - 1].clk;
  1575. table_info->max_clock_voltage_on_ac.vddc =
  1576. allowed_sclk_vdd_table->entries[allowed_sclk_vdd_table->count - 1].vddc;
  1577. table_info->max_clock_voltage_on_ac.vddci =
  1578. allowed_mclk_vdd_table->entries[allowed_mclk_vdd_table->count - 1].vddci;
  1579. hwmgr->dyn_state.max_clock_voltage_on_ac.sclk = table_info->max_clock_voltage_on_ac.sclk;
  1580. hwmgr->dyn_state.max_clock_voltage_on_ac.mclk = table_info->max_clock_voltage_on_ac.mclk;
  1581. hwmgr->dyn_state.max_clock_voltage_on_ac.vddc = table_info->max_clock_voltage_on_ac.vddc;
  1582. hwmgr->dyn_state.max_clock_voltage_on_ac.vddci = table_info->max_clock_voltage_on_ac.vddci;
  1583. return 0;
  1584. }
  1585. static int smu7_patch_voltage_workaround(struct pp_hwmgr *hwmgr)
  1586. {
  1587. struct phm_ppt_v1_information *table_info =
  1588. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  1589. struct phm_ppt_v1_clock_voltage_dependency_table *dep_mclk_table;
  1590. struct phm_ppt_v1_voltage_lookup_table *lookup_table;
  1591. uint32_t i;
  1592. uint32_t hw_revision, sub_vendor_id, sub_sys_id;
  1593. struct cgs_system_info sys_info = {0};
  1594. if (table_info != NULL) {
  1595. dep_mclk_table = table_info->vdd_dep_on_mclk;
  1596. lookup_table = table_info->vddc_lookup_table;
  1597. } else
  1598. return 0;
  1599. sys_info.size = sizeof(struct cgs_system_info);
  1600. sys_info.info_id = CGS_SYSTEM_INFO_PCIE_REV;
  1601. cgs_query_system_info(hwmgr->device, &sys_info);
  1602. hw_revision = (uint32_t)sys_info.value;
  1603. sys_info.info_id = CGS_SYSTEM_INFO_PCIE_SUB_SYS_ID;
  1604. cgs_query_system_info(hwmgr->device, &sys_info);
  1605. sub_sys_id = (uint32_t)sys_info.value;
  1606. sys_info.info_id = CGS_SYSTEM_INFO_PCIE_SUB_SYS_VENDOR_ID;
  1607. cgs_query_system_info(hwmgr->device, &sys_info);
  1608. sub_vendor_id = (uint32_t)sys_info.value;
  1609. if (hwmgr->chip_id == CHIP_POLARIS10 && hw_revision == 0xC7 &&
  1610. ((sub_sys_id == 0xb37 && sub_vendor_id == 0x1002) ||
  1611. (sub_sys_id == 0x4a8 && sub_vendor_id == 0x1043) ||
  1612. (sub_sys_id == 0x9480 && sub_vendor_id == 0x1682))) {
  1613. if (lookup_table->entries[dep_mclk_table->entries[dep_mclk_table->count-1].vddInd].us_vdd >= 1000)
  1614. return 0;
  1615. for (i = 0; i < lookup_table->count; i++) {
  1616. if (lookup_table->entries[i].us_vdd < 0xff01 && lookup_table->entries[i].us_vdd >= 1000) {
  1617. dep_mclk_table->entries[dep_mclk_table->count-1].vddInd = (uint8_t) i;
  1618. return 0;
  1619. }
  1620. }
  1621. }
  1622. return 0;
  1623. }
  1624. static int smu7_thermal_parameter_init(struct pp_hwmgr *hwmgr)
  1625. {
  1626. struct pp_atomctrl_gpio_pin_assignment gpio_pin_assignment;
  1627. uint32_t temp_reg;
  1628. struct phm_ppt_v1_information *table_info =
  1629. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  1630. if (atomctrl_get_pp_assign_pin(hwmgr, VDDC_PCC_GPIO_PINID, &gpio_pin_assignment)) {
  1631. temp_reg = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCNB_PWRMGT_CNTL);
  1632. switch (gpio_pin_assignment.uc_gpio_pin_bit_shift) {
  1633. case 0:
  1634. temp_reg = PHM_SET_FIELD(temp_reg, CNB_PWRMGT_CNTL, GNB_SLOW_MODE, 0x1);
  1635. break;
  1636. case 1:
  1637. temp_reg = PHM_SET_FIELD(temp_reg, CNB_PWRMGT_CNTL, GNB_SLOW_MODE, 0x2);
  1638. break;
  1639. case 2:
  1640. temp_reg = PHM_SET_FIELD(temp_reg, CNB_PWRMGT_CNTL, GNB_SLOW, 0x1);
  1641. break;
  1642. case 3:
  1643. temp_reg = PHM_SET_FIELD(temp_reg, CNB_PWRMGT_CNTL, FORCE_NB_PS1, 0x1);
  1644. break;
  1645. case 4:
  1646. temp_reg = PHM_SET_FIELD(temp_reg, CNB_PWRMGT_CNTL, DPM_ENABLED, 0x1);
  1647. break;
  1648. default:
  1649. PP_ASSERT_WITH_CODE(0,
  1650. "Failed to setup PCC HW register! Wrong GPIO assigned for VDDC_PCC_GPIO_PINID!",
  1651. );
  1652. break;
  1653. }
  1654. cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCNB_PWRMGT_CNTL, temp_reg);
  1655. }
  1656. if (table_info == NULL)
  1657. return 0;
  1658. if (table_info->cac_dtp_table->usDefaultTargetOperatingTemp != 0 &&
  1659. hwmgr->thermal_controller.advanceFanControlParameters.ucFanControlMode) {
  1660. hwmgr->thermal_controller.advanceFanControlParameters.usFanPWMMinLimit =
  1661. (uint16_t)hwmgr->thermal_controller.advanceFanControlParameters.ucMinimumPWMLimit;
  1662. hwmgr->thermal_controller.advanceFanControlParameters.usFanPWMMaxLimit =
  1663. (uint16_t)hwmgr->thermal_controller.advanceFanControlParameters.usDefaultMaxFanPWM;
  1664. hwmgr->thermal_controller.advanceFanControlParameters.usFanPWMStep = 1;
  1665. hwmgr->thermal_controller.advanceFanControlParameters.usFanRPMMaxLimit = 100;
  1666. hwmgr->thermal_controller.advanceFanControlParameters.usFanRPMMinLimit =
  1667. (uint16_t)hwmgr->thermal_controller.advanceFanControlParameters.ucMinimumPWMLimit;
  1668. hwmgr->thermal_controller.advanceFanControlParameters.usFanRPMStep = 1;
  1669. table_info->cac_dtp_table->usDefaultTargetOperatingTemp = (table_info->cac_dtp_table->usDefaultTargetOperatingTemp >= 50) ?
  1670. (table_info->cac_dtp_table->usDefaultTargetOperatingTemp - 50) : 0;
  1671. table_info->cac_dtp_table->usOperatingTempMaxLimit = table_info->cac_dtp_table->usDefaultTargetOperatingTemp;
  1672. table_info->cac_dtp_table->usOperatingTempStep = 1;
  1673. table_info->cac_dtp_table->usOperatingTempHyst = 1;
  1674. hwmgr->thermal_controller.advanceFanControlParameters.usMaxFanPWM =
  1675. hwmgr->thermal_controller.advanceFanControlParameters.usDefaultMaxFanPWM;
  1676. hwmgr->thermal_controller.advanceFanControlParameters.usMaxFanRPM =
  1677. hwmgr->thermal_controller.advanceFanControlParameters.usDefaultMaxFanRPM;
  1678. hwmgr->dyn_state.cac_dtp_table->usOperatingTempMinLimit =
  1679. table_info->cac_dtp_table->usOperatingTempMinLimit;
  1680. hwmgr->dyn_state.cac_dtp_table->usOperatingTempMaxLimit =
  1681. table_info->cac_dtp_table->usOperatingTempMaxLimit;
  1682. hwmgr->dyn_state.cac_dtp_table->usDefaultTargetOperatingTemp =
  1683. table_info->cac_dtp_table->usDefaultTargetOperatingTemp;
  1684. hwmgr->dyn_state.cac_dtp_table->usOperatingTempStep =
  1685. table_info->cac_dtp_table->usOperatingTempStep;
  1686. hwmgr->dyn_state.cac_dtp_table->usTargetOperatingTemp =
  1687. table_info->cac_dtp_table->usTargetOperatingTemp;
  1688. if (hwmgr->feature_mask & PP_OD_FUZZY_FAN_CONTROL_MASK)
  1689. phm_cap_set(hwmgr->platform_descriptor.platformCaps,
  1690. PHM_PlatformCaps_ODFuzzyFanControlSupport);
  1691. }
  1692. return 0;
  1693. }
  1694. /**
  1695. * Change virtual leakage voltage to actual value.
  1696. *
  1697. * @param hwmgr the address of the powerplay hardware manager.
  1698. * @param pointer to changing voltage
  1699. * @param pointer to leakage table
  1700. */
  1701. static void smu7_patch_ppt_v0_with_vdd_leakage(struct pp_hwmgr *hwmgr,
  1702. uint32_t *voltage, struct smu7_leakage_voltage *leakage_table)
  1703. {
  1704. uint32_t index;
  1705. /* search for leakage voltage ID 0xff01 ~ 0xff08 */
  1706. for (index = 0; index < leakage_table->count; index++) {
  1707. /* if this voltage matches a leakage voltage ID */
  1708. /* patch with actual leakage voltage */
  1709. if (leakage_table->leakage_id[index] == *voltage) {
  1710. *voltage = leakage_table->actual_voltage[index];
  1711. break;
  1712. }
  1713. }
  1714. if (*voltage > ATOM_VIRTUAL_VOLTAGE_ID0)
  1715. pr_err("Voltage value looks like a Leakage ID but it's not patched \n");
  1716. }
  1717. static int smu7_patch_vddc(struct pp_hwmgr *hwmgr,
  1718. struct phm_clock_voltage_dependency_table *tab)
  1719. {
  1720. uint16_t i;
  1721. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  1722. if (tab)
  1723. for (i = 0; i < tab->count; i++)
  1724. smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, &tab->entries[i].v,
  1725. &data->vddc_leakage);
  1726. return 0;
  1727. }
  1728. static int smu7_patch_vddci(struct pp_hwmgr *hwmgr,
  1729. struct phm_clock_voltage_dependency_table *tab)
  1730. {
  1731. uint16_t i;
  1732. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  1733. if (tab)
  1734. for (i = 0; i < tab->count; i++)
  1735. smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, &tab->entries[i].v,
  1736. &data->vddci_leakage);
  1737. return 0;
  1738. }
  1739. static int smu7_patch_vce_vddc(struct pp_hwmgr *hwmgr,
  1740. struct phm_vce_clock_voltage_dependency_table *tab)
  1741. {
  1742. uint16_t i;
  1743. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  1744. if (tab)
  1745. for (i = 0; i < tab->count; i++)
  1746. smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, &tab->entries[i].v,
  1747. &data->vddc_leakage);
  1748. return 0;
  1749. }
  1750. static int smu7_patch_uvd_vddc(struct pp_hwmgr *hwmgr,
  1751. struct phm_uvd_clock_voltage_dependency_table *tab)
  1752. {
  1753. uint16_t i;
  1754. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  1755. if (tab)
  1756. for (i = 0; i < tab->count; i++)
  1757. smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, &tab->entries[i].v,
  1758. &data->vddc_leakage);
  1759. return 0;
  1760. }
  1761. static int smu7_patch_vddc_shed_limit(struct pp_hwmgr *hwmgr,
  1762. struct phm_phase_shedding_limits_table *tab)
  1763. {
  1764. uint16_t i;
  1765. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  1766. if (tab)
  1767. for (i = 0; i < tab->count; i++)
  1768. smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, &tab->entries[i].Voltage,
  1769. &data->vddc_leakage);
  1770. return 0;
  1771. }
  1772. static int smu7_patch_samu_vddc(struct pp_hwmgr *hwmgr,
  1773. struct phm_samu_clock_voltage_dependency_table *tab)
  1774. {
  1775. uint16_t i;
  1776. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  1777. if (tab)
  1778. for (i = 0; i < tab->count; i++)
  1779. smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, &tab->entries[i].v,
  1780. &data->vddc_leakage);
  1781. return 0;
  1782. }
  1783. static int smu7_patch_acp_vddc(struct pp_hwmgr *hwmgr,
  1784. struct phm_acp_clock_voltage_dependency_table *tab)
  1785. {
  1786. uint16_t i;
  1787. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  1788. if (tab)
  1789. for (i = 0; i < tab->count; i++)
  1790. smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, &tab->entries[i].v,
  1791. &data->vddc_leakage);
  1792. return 0;
  1793. }
  1794. static int smu7_patch_limits_vddc(struct pp_hwmgr *hwmgr,
  1795. struct phm_clock_and_voltage_limits *tab)
  1796. {
  1797. uint32_t vddc, vddci;
  1798. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  1799. if (tab) {
  1800. vddc = tab->vddc;
  1801. smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, &vddc,
  1802. &data->vddc_leakage);
  1803. tab->vddc = vddc;
  1804. vddci = tab->vddci;
  1805. smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, &vddci,
  1806. &data->vddci_leakage);
  1807. tab->vddci = vddci;
  1808. }
  1809. return 0;
  1810. }
  1811. static int smu7_patch_cac_vddc(struct pp_hwmgr *hwmgr, struct phm_cac_leakage_table *tab)
  1812. {
  1813. uint32_t i;
  1814. uint32_t vddc;
  1815. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  1816. if (tab) {
  1817. for (i = 0; i < tab->count; i++) {
  1818. vddc = (uint32_t)(tab->entries[i].Vddc);
  1819. smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, &vddc, &data->vddc_leakage);
  1820. tab->entries[i].Vddc = (uint16_t)vddc;
  1821. }
  1822. }
  1823. return 0;
  1824. }
  1825. static int smu7_patch_dependency_tables_with_leakage(struct pp_hwmgr *hwmgr)
  1826. {
  1827. int tmp;
  1828. tmp = smu7_patch_vddc(hwmgr, hwmgr->dyn_state.vddc_dependency_on_sclk);
  1829. if (tmp)
  1830. return -EINVAL;
  1831. tmp = smu7_patch_vddc(hwmgr, hwmgr->dyn_state.vddc_dependency_on_mclk);
  1832. if (tmp)
  1833. return -EINVAL;
  1834. tmp = smu7_patch_vddc(hwmgr, hwmgr->dyn_state.vddc_dep_on_dal_pwrl);
  1835. if (tmp)
  1836. return -EINVAL;
  1837. tmp = smu7_patch_vddci(hwmgr, hwmgr->dyn_state.vddci_dependency_on_mclk);
  1838. if (tmp)
  1839. return -EINVAL;
  1840. tmp = smu7_patch_vce_vddc(hwmgr, hwmgr->dyn_state.vce_clock_voltage_dependency_table);
  1841. if (tmp)
  1842. return -EINVAL;
  1843. tmp = smu7_patch_uvd_vddc(hwmgr, hwmgr->dyn_state.uvd_clock_voltage_dependency_table);
  1844. if (tmp)
  1845. return -EINVAL;
  1846. tmp = smu7_patch_samu_vddc(hwmgr, hwmgr->dyn_state.samu_clock_voltage_dependency_table);
  1847. if (tmp)
  1848. return -EINVAL;
  1849. tmp = smu7_patch_acp_vddc(hwmgr, hwmgr->dyn_state.acp_clock_voltage_dependency_table);
  1850. if (tmp)
  1851. return -EINVAL;
  1852. tmp = smu7_patch_vddc_shed_limit(hwmgr, hwmgr->dyn_state.vddc_phase_shed_limits_table);
  1853. if (tmp)
  1854. return -EINVAL;
  1855. tmp = smu7_patch_limits_vddc(hwmgr, &hwmgr->dyn_state.max_clock_voltage_on_ac);
  1856. if (tmp)
  1857. return -EINVAL;
  1858. tmp = smu7_patch_limits_vddc(hwmgr, &hwmgr->dyn_state.max_clock_voltage_on_dc);
  1859. if (tmp)
  1860. return -EINVAL;
  1861. tmp = smu7_patch_cac_vddc(hwmgr, hwmgr->dyn_state.cac_leakage_table);
  1862. if (tmp)
  1863. return -EINVAL;
  1864. return 0;
  1865. }
  1866. static int smu7_set_private_data_based_on_pptable_v0(struct pp_hwmgr *hwmgr)
  1867. {
  1868. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  1869. struct phm_clock_voltage_dependency_table *allowed_sclk_vddc_table = hwmgr->dyn_state.vddc_dependency_on_sclk;
  1870. struct phm_clock_voltage_dependency_table *allowed_mclk_vddc_table = hwmgr->dyn_state.vddc_dependency_on_mclk;
  1871. struct phm_clock_voltage_dependency_table *allowed_mclk_vddci_table = hwmgr->dyn_state.vddci_dependency_on_mclk;
  1872. PP_ASSERT_WITH_CODE(allowed_sclk_vddc_table != NULL,
  1873. "VDDC dependency on SCLK table is missing. This table is mandatory\n", return -EINVAL);
  1874. PP_ASSERT_WITH_CODE(allowed_sclk_vddc_table->count >= 1,
  1875. "VDDC dependency on SCLK table has to have is missing. This table is mandatory\n", return -EINVAL);
  1876. PP_ASSERT_WITH_CODE(allowed_mclk_vddc_table != NULL,
  1877. "VDDC dependency on MCLK table is missing. This table is mandatory\n", return -EINVAL);
  1878. PP_ASSERT_WITH_CODE(allowed_mclk_vddc_table->count >= 1,
  1879. "VDD dependency on MCLK table has to have is missing. This table is mandatory\n", return -EINVAL);
  1880. data->min_vddc_in_pptable = (uint16_t)allowed_sclk_vddc_table->entries[0].v;
  1881. data->max_vddc_in_pptable = (uint16_t)allowed_sclk_vddc_table->entries[allowed_sclk_vddc_table->count - 1].v;
  1882. hwmgr->dyn_state.max_clock_voltage_on_ac.sclk =
  1883. allowed_sclk_vddc_table->entries[allowed_sclk_vddc_table->count - 1].clk;
  1884. hwmgr->dyn_state.max_clock_voltage_on_ac.mclk =
  1885. allowed_mclk_vddc_table->entries[allowed_mclk_vddc_table->count - 1].clk;
  1886. hwmgr->dyn_state.max_clock_voltage_on_ac.vddc =
  1887. allowed_sclk_vddc_table->entries[allowed_sclk_vddc_table->count - 1].v;
  1888. if (allowed_mclk_vddci_table != NULL && allowed_mclk_vddci_table->count >= 1) {
  1889. data->min_vddci_in_pptable = (uint16_t)allowed_mclk_vddci_table->entries[0].v;
  1890. data->max_vddci_in_pptable = (uint16_t)allowed_mclk_vddci_table->entries[allowed_mclk_vddci_table->count - 1].v;
  1891. }
  1892. if (hwmgr->dyn_state.vddci_dependency_on_mclk != NULL && hwmgr->dyn_state.vddci_dependency_on_mclk->count > 1)
  1893. hwmgr->dyn_state.max_clock_voltage_on_ac.vddci = hwmgr->dyn_state.vddci_dependency_on_mclk->entries[hwmgr->dyn_state.vddci_dependency_on_mclk->count - 1].v;
  1894. return 0;
  1895. }
  1896. static int smu7_hwmgr_backend_fini(struct pp_hwmgr *hwmgr)
  1897. {
  1898. if (NULL != hwmgr->dyn_state.vddc_dep_on_dal_pwrl) {
  1899. kfree(hwmgr->dyn_state.vddc_dep_on_dal_pwrl);
  1900. hwmgr->dyn_state.vddc_dep_on_dal_pwrl = NULL;
  1901. }
  1902. pp_smu7_thermal_fini(hwmgr);
  1903. if (NULL != hwmgr->backend) {
  1904. kfree(hwmgr->backend);
  1905. hwmgr->backend = NULL;
  1906. }
  1907. return 0;
  1908. }
  1909. static int smu7_hwmgr_backend_init(struct pp_hwmgr *hwmgr)
  1910. {
  1911. struct smu7_hwmgr *data;
  1912. int result;
  1913. data = kzalloc(sizeof(struct smu7_hwmgr), GFP_KERNEL);
  1914. if (data == NULL)
  1915. return -ENOMEM;
  1916. hwmgr->backend = data;
  1917. pp_smu7_thermal_initialize(hwmgr);
  1918. smu7_patch_voltage_workaround(hwmgr);
  1919. smu7_init_dpm_defaults(hwmgr);
  1920. /* Get leakage voltage based on leakage ID. */
  1921. result = smu7_get_evv_voltages(hwmgr);
  1922. if (result) {
  1923. pr_info("Get EVV Voltage Failed. Abort Driver loading!\n");
  1924. return -EINVAL;
  1925. }
  1926. if (hwmgr->pp_table_version == PP_TABLE_V1) {
  1927. smu7_complete_dependency_tables(hwmgr);
  1928. smu7_set_private_data_based_on_pptable_v1(hwmgr);
  1929. } else if (hwmgr->pp_table_version == PP_TABLE_V0) {
  1930. smu7_patch_dependency_tables_with_leakage(hwmgr);
  1931. smu7_set_private_data_based_on_pptable_v0(hwmgr);
  1932. }
  1933. /* Initalize Dynamic State Adjustment Rule Settings */
  1934. result = phm_initializa_dynamic_state_adjustment_rule_settings(hwmgr);
  1935. if (0 == result) {
  1936. struct cgs_system_info sys_info = {0};
  1937. data->is_tlu_enabled = false;
  1938. hwmgr->platform_descriptor.hardwareActivityPerformanceLevels =
  1939. SMU7_MAX_HARDWARE_POWERLEVELS;
  1940. hwmgr->platform_descriptor.hardwarePerformanceLevels = 2;
  1941. hwmgr->platform_descriptor.minimumClocksReductionPercentage = 50;
  1942. sys_info.size = sizeof(struct cgs_system_info);
  1943. sys_info.info_id = CGS_SYSTEM_INFO_PCIE_GEN_INFO;
  1944. result = cgs_query_system_info(hwmgr->device, &sys_info);
  1945. if (result)
  1946. data->pcie_gen_cap = AMDGPU_DEFAULT_PCIE_GEN_MASK;
  1947. else
  1948. data->pcie_gen_cap = (uint32_t)sys_info.value;
  1949. if (data->pcie_gen_cap & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3)
  1950. data->pcie_spc_cap = 20;
  1951. sys_info.size = sizeof(struct cgs_system_info);
  1952. sys_info.info_id = CGS_SYSTEM_INFO_PCIE_MLW;
  1953. result = cgs_query_system_info(hwmgr->device, &sys_info);
  1954. if (result)
  1955. data->pcie_lane_cap = AMDGPU_DEFAULT_PCIE_MLW_MASK;
  1956. else
  1957. data->pcie_lane_cap = (uint32_t)sys_info.value;
  1958. hwmgr->platform_descriptor.vbiosInterruptId = 0x20000400; /* IRQ_SOURCE1_SW_INT */
  1959. /* The true clock step depends on the frequency, typically 4.5 or 9 MHz. Here we use 5. */
  1960. hwmgr->platform_descriptor.clockStep.engineClock = 500;
  1961. hwmgr->platform_descriptor.clockStep.memoryClock = 500;
  1962. smu7_thermal_parameter_init(hwmgr);
  1963. } else {
  1964. /* Ignore return value in here, we are cleaning up a mess. */
  1965. smu7_hwmgr_backend_fini(hwmgr);
  1966. }
  1967. return 0;
  1968. }
  1969. static int smu7_force_dpm_highest(struct pp_hwmgr *hwmgr)
  1970. {
  1971. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  1972. uint32_t level, tmp;
  1973. if (!data->pcie_dpm_key_disabled) {
  1974. if (data->dpm_level_enable_mask.pcie_dpm_enable_mask) {
  1975. level = 0;
  1976. tmp = data->dpm_level_enable_mask.pcie_dpm_enable_mask;
  1977. while (tmp >>= 1)
  1978. level++;
  1979. if (level)
  1980. smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
  1981. PPSMC_MSG_PCIeDPM_ForceLevel, level);
  1982. }
  1983. }
  1984. if (!data->sclk_dpm_key_disabled) {
  1985. if (data->dpm_level_enable_mask.sclk_dpm_enable_mask) {
  1986. level = 0;
  1987. tmp = data->dpm_level_enable_mask.sclk_dpm_enable_mask;
  1988. while (tmp >>= 1)
  1989. level++;
  1990. if (level)
  1991. smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
  1992. PPSMC_MSG_SCLKDPM_SetEnabledMask,
  1993. (1 << level));
  1994. }
  1995. }
  1996. if (!data->mclk_dpm_key_disabled) {
  1997. if (data->dpm_level_enable_mask.mclk_dpm_enable_mask) {
  1998. level = 0;
  1999. tmp = data->dpm_level_enable_mask.mclk_dpm_enable_mask;
  2000. while (tmp >>= 1)
  2001. level++;
  2002. if (level)
  2003. smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
  2004. PPSMC_MSG_MCLKDPM_SetEnabledMask,
  2005. (1 << level));
  2006. }
  2007. }
  2008. return 0;
  2009. }
  2010. static int smu7_upload_dpm_level_enable_mask(struct pp_hwmgr *hwmgr)
  2011. {
  2012. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  2013. if (hwmgr->pp_table_version == PP_TABLE_V1)
  2014. phm_apply_dal_min_voltage_request(hwmgr);
  2015. /* TO DO for v0 iceland and Ci*/
  2016. if (!data->sclk_dpm_key_disabled) {
  2017. if (data->dpm_level_enable_mask.sclk_dpm_enable_mask)
  2018. smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
  2019. PPSMC_MSG_SCLKDPM_SetEnabledMask,
  2020. data->dpm_level_enable_mask.sclk_dpm_enable_mask);
  2021. }
  2022. if (!data->mclk_dpm_key_disabled) {
  2023. if (data->dpm_level_enable_mask.mclk_dpm_enable_mask)
  2024. smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
  2025. PPSMC_MSG_MCLKDPM_SetEnabledMask,
  2026. data->dpm_level_enable_mask.mclk_dpm_enable_mask);
  2027. }
  2028. return 0;
  2029. }
  2030. static int smu7_unforce_dpm_levels(struct pp_hwmgr *hwmgr)
  2031. {
  2032. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  2033. if (!smum_is_dpm_running(hwmgr))
  2034. return -EINVAL;
  2035. if (!data->pcie_dpm_key_disabled) {
  2036. smum_send_msg_to_smc(hwmgr->smumgr,
  2037. PPSMC_MSG_PCIeDPM_UnForceLevel);
  2038. }
  2039. return smu7_upload_dpm_level_enable_mask(hwmgr);
  2040. }
  2041. static int smu7_force_dpm_lowest(struct pp_hwmgr *hwmgr)
  2042. {
  2043. struct smu7_hwmgr *data =
  2044. (struct smu7_hwmgr *)(hwmgr->backend);
  2045. uint32_t level;
  2046. if (!data->sclk_dpm_key_disabled)
  2047. if (data->dpm_level_enable_mask.sclk_dpm_enable_mask) {
  2048. level = phm_get_lowest_enabled_level(hwmgr,
  2049. data->dpm_level_enable_mask.sclk_dpm_enable_mask);
  2050. smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
  2051. PPSMC_MSG_SCLKDPM_SetEnabledMask,
  2052. (1 << level));
  2053. }
  2054. if (!data->mclk_dpm_key_disabled) {
  2055. if (data->dpm_level_enable_mask.mclk_dpm_enable_mask) {
  2056. level = phm_get_lowest_enabled_level(hwmgr,
  2057. data->dpm_level_enable_mask.mclk_dpm_enable_mask);
  2058. smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
  2059. PPSMC_MSG_MCLKDPM_SetEnabledMask,
  2060. (1 << level));
  2061. }
  2062. }
  2063. if (!data->pcie_dpm_key_disabled) {
  2064. if (data->dpm_level_enable_mask.pcie_dpm_enable_mask) {
  2065. level = phm_get_lowest_enabled_level(hwmgr,
  2066. data->dpm_level_enable_mask.pcie_dpm_enable_mask);
  2067. smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
  2068. PPSMC_MSG_PCIeDPM_ForceLevel,
  2069. (level));
  2070. }
  2071. }
  2072. return 0;
  2073. }
  2074. static int smu7_get_profiling_clk(struct pp_hwmgr *hwmgr, enum amd_dpm_forced_level level,
  2075. uint32_t *sclk_mask, uint32_t *mclk_mask, uint32_t *pcie_mask)
  2076. {
  2077. uint32_t percentage;
  2078. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  2079. struct smu7_dpm_table *golden_dpm_table = &data->golden_dpm_table;
  2080. int32_t tmp_mclk;
  2081. int32_t tmp_sclk;
  2082. int32_t count;
  2083. if (golden_dpm_table->mclk_table.count < 1)
  2084. return -EINVAL;
  2085. percentage = 100 * golden_dpm_table->sclk_table.dpm_levels[golden_dpm_table->sclk_table.count - 1].value /
  2086. golden_dpm_table->mclk_table.dpm_levels[golden_dpm_table->mclk_table.count - 1].value;
  2087. if (golden_dpm_table->mclk_table.count == 1) {
  2088. percentage = 70;
  2089. tmp_mclk = golden_dpm_table->mclk_table.dpm_levels[golden_dpm_table->mclk_table.count - 1].value;
  2090. *mclk_mask = golden_dpm_table->mclk_table.count - 1;
  2091. } else {
  2092. tmp_mclk = golden_dpm_table->mclk_table.dpm_levels[golden_dpm_table->mclk_table.count - 2].value;
  2093. *mclk_mask = golden_dpm_table->mclk_table.count - 2;
  2094. }
  2095. tmp_sclk = tmp_mclk * percentage / 100;
  2096. if (hwmgr->pp_table_version == PP_TABLE_V0) {
  2097. for (count = hwmgr->dyn_state.vddc_dependency_on_sclk->count-1;
  2098. count >= 0; count--) {
  2099. if (tmp_sclk >= hwmgr->dyn_state.vddc_dependency_on_sclk->entries[count].clk) {
  2100. tmp_sclk = hwmgr->dyn_state.vddc_dependency_on_sclk->entries[count].clk;
  2101. *sclk_mask = count;
  2102. break;
  2103. }
  2104. }
  2105. if (count < 0 || level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK)
  2106. *sclk_mask = 0;
  2107. if (level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK)
  2108. *sclk_mask = hwmgr->dyn_state.vddc_dependency_on_sclk->count-1;
  2109. } else if (hwmgr->pp_table_version == PP_TABLE_V1) {
  2110. struct phm_ppt_v1_information *table_info =
  2111. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  2112. for (count = table_info->vdd_dep_on_sclk->count-1; count >= 0; count--) {
  2113. if (tmp_sclk >= table_info->vdd_dep_on_sclk->entries[count].clk) {
  2114. tmp_sclk = table_info->vdd_dep_on_sclk->entries[count].clk;
  2115. *sclk_mask = count;
  2116. break;
  2117. }
  2118. }
  2119. if (count < 0 || level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK)
  2120. *sclk_mask = 0;
  2121. if (level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK)
  2122. *sclk_mask = table_info->vdd_dep_on_sclk->count - 1;
  2123. }
  2124. if (level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK)
  2125. *mclk_mask = 0;
  2126. else if (level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK)
  2127. *mclk_mask = golden_dpm_table->mclk_table.count - 1;
  2128. *pcie_mask = data->dpm_table.pcie_speed_table.count - 1;
  2129. return 0;
  2130. }
  2131. static int smu7_force_dpm_level(struct pp_hwmgr *hwmgr,
  2132. enum amd_dpm_forced_level level)
  2133. {
  2134. int ret = 0;
  2135. uint32_t sclk_mask = 0;
  2136. uint32_t mclk_mask = 0;
  2137. uint32_t pcie_mask = 0;
  2138. uint32_t profile_mode_mask = AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD |
  2139. AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK |
  2140. AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK |
  2141. AMD_DPM_FORCED_LEVEL_PROFILE_PEAK;
  2142. if (level == hwmgr->dpm_level)
  2143. return ret;
  2144. if (!(hwmgr->dpm_level & profile_mode_mask)) {
  2145. /* enter profile mode, save current level, disable gfx cg*/
  2146. if (level & profile_mode_mask) {
  2147. hwmgr->saved_dpm_level = hwmgr->dpm_level;
  2148. cgs_set_clockgating_state(hwmgr->device,
  2149. AMD_IP_BLOCK_TYPE_GFX,
  2150. AMD_CG_STATE_UNGATE);
  2151. }
  2152. } else {
  2153. /* exit profile mode, restore level, enable gfx cg*/
  2154. if (!(level & profile_mode_mask)) {
  2155. if (level == AMD_DPM_FORCED_LEVEL_PROFILE_EXIT)
  2156. level = hwmgr->saved_dpm_level;
  2157. cgs_set_clockgating_state(hwmgr->device,
  2158. AMD_IP_BLOCK_TYPE_GFX,
  2159. AMD_CG_STATE_GATE);
  2160. }
  2161. }
  2162. switch (level) {
  2163. case AMD_DPM_FORCED_LEVEL_HIGH:
  2164. ret = smu7_force_dpm_highest(hwmgr);
  2165. if (ret)
  2166. return ret;
  2167. hwmgr->dpm_level = level;
  2168. break;
  2169. case AMD_DPM_FORCED_LEVEL_LOW:
  2170. ret = smu7_force_dpm_lowest(hwmgr);
  2171. if (ret)
  2172. return ret;
  2173. hwmgr->dpm_level = level;
  2174. break;
  2175. case AMD_DPM_FORCED_LEVEL_AUTO:
  2176. ret = smu7_unforce_dpm_levels(hwmgr);
  2177. if (ret)
  2178. return ret;
  2179. hwmgr->dpm_level = level;
  2180. break;
  2181. case AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD:
  2182. case AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK:
  2183. case AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK:
  2184. case AMD_DPM_FORCED_LEVEL_PROFILE_PEAK:
  2185. ret = smu7_get_profiling_clk(hwmgr, level, &sclk_mask, &mclk_mask, &pcie_mask);
  2186. if (ret)
  2187. return ret;
  2188. hwmgr->dpm_level = level;
  2189. smu7_force_clock_level(hwmgr, PP_SCLK, 1<<sclk_mask);
  2190. smu7_force_clock_level(hwmgr, PP_MCLK, 1<<mclk_mask);
  2191. smu7_force_clock_level(hwmgr, PP_PCIE, 1<<pcie_mask);
  2192. break;
  2193. case AMD_DPM_FORCED_LEVEL_MANUAL:
  2194. hwmgr->dpm_level = level;
  2195. break;
  2196. case AMD_DPM_FORCED_LEVEL_PROFILE_EXIT:
  2197. default:
  2198. break;
  2199. }
  2200. if (level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK && hwmgr->saved_dpm_level != AMD_DPM_FORCED_LEVEL_PROFILE_PEAK)
  2201. smu7_fan_ctrl_set_fan_speed_percent(hwmgr, 100);
  2202. else if (level != AMD_DPM_FORCED_LEVEL_PROFILE_PEAK && hwmgr->saved_dpm_level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK)
  2203. smu7_fan_ctrl_reset_fan_speed_to_default(hwmgr);
  2204. return 0;
  2205. }
  2206. static int smu7_get_power_state_size(struct pp_hwmgr *hwmgr)
  2207. {
  2208. return sizeof(struct smu7_power_state);
  2209. }
  2210. static int smu7_vblank_too_short(struct pp_hwmgr *hwmgr,
  2211. uint32_t vblank_time_us)
  2212. {
  2213. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  2214. uint32_t switch_limit_us;
  2215. switch (hwmgr->chip_id) {
  2216. case CHIP_POLARIS10:
  2217. case CHIP_POLARIS11:
  2218. case CHIP_POLARIS12:
  2219. switch_limit_us = data->is_memory_gddr5 ? 190 : 150;
  2220. break;
  2221. default:
  2222. switch_limit_us = data->is_memory_gddr5 ? 450 : 150;
  2223. break;
  2224. }
  2225. if (vblank_time_us < switch_limit_us)
  2226. return true;
  2227. else
  2228. return false;
  2229. }
  2230. static int smu7_apply_state_adjust_rules(struct pp_hwmgr *hwmgr,
  2231. struct pp_power_state *request_ps,
  2232. const struct pp_power_state *current_ps)
  2233. {
  2234. struct smu7_power_state *smu7_ps =
  2235. cast_phw_smu7_power_state(&request_ps->hardware);
  2236. uint32_t sclk;
  2237. uint32_t mclk;
  2238. struct PP_Clocks minimum_clocks = {0};
  2239. bool disable_mclk_switching;
  2240. bool disable_mclk_switching_for_frame_lock;
  2241. struct cgs_display_info info = {0};
  2242. struct cgs_mode_info mode_info = {0};
  2243. const struct phm_clock_and_voltage_limits *max_limits;
  2244. uint32_t i;
  2245. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  2246. struct phm_ppt_v1_information *table_info =
  2247. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  2248. int32_t count;
  2249. int32_t stable_pstate_sclk = 0, stable_pstate_mclk = 0;
  2250. info.mode_info = &mode_info;
  2251. data->battery_state = (PP_StateUILabel_Battery ==
  2252. request_ps->classification.ui_label);
  2253. PP_ASSERT_WITH_CODE(smu7_ps->performance_level_count == 2,
  2254. "VI should always have 2 performance levels",
  2255. );
  2256. max_limits = (PP_PowerSource_AC == hwmgr->power_source) ?
  2257. &(hwmgr->dyn_state.max_clock_voltage_on_ac) :
  2258. &(hwmgr->dyn_state.max_clock_voltage_on_dc);
  2259. /* Cap clock DPM tables at DC MAX if it is in DC. */
  2260. if (PP_PowerSource_DC == hwmgr->power_source) {
  2261. for (i = 0; i < smu7_ps->performance_level_count; i++) {
  2262. if (smu7_ps->performance_levels[i].memory_clock > max_limits->mclk)
  2263. smu7_ps->performance_levels[i].memory_clock = max_limits->mclk;
  2264. if (smu7_ps->performance_levels[i].engine_clock > max_limits->sclk)
  2265. smu7_ps->performance_levels[i].engine_clock = max_limits->sclk;
  2266. }
  2267. }
  2268. smu7_ps->vce_clks.evclk = hwmgr->vce_arbiter.evclk;
  2269. smu7_ps->vce_clks.ecclk = hwmgr->vce_arbiter.ecclk;
  2270. cgs_get_active_displays_info(hwmgr->device, &info);
  2271. minimum_clocks.engineClock = hwmgr->display_config.min_core_set_clock;
  2272. minimum_clocks.memoryClock = hwmgr->display_config.min_mem_set_clock;
  2273. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  2274. PHM_PlatformCaps_StablePState)) {
  2275. max_limits = &(hwmgr->dyn_state.max_clock_voltage_on_ac);
  2276. stable_pstate_sclk = (max_limits->sclk * 75) / 100;
  2277. for (count = table_info->vdd_dep_on_sclk->count - 1;
  2278. count >= 0; count--) {
  2279. if (stable_pstate_sclk >=
  2280. table_info->vdd_dep_on_sclk->entries[count].clk) {
  2281. stable_pstate_sclk =
  2282. table_info->vdd_dep_on_sclk->entries[count].clk;
  2283. break;
  2284. }
  2285. }
  2286. if (count < 0)
  2287. stable_pstate_sclk = table_info->vdd_dep_on_sclk->entries[0].clk;
  2288. stable_pstate_mclk = max_limits->mclk;
  2289. minimum_clocks.engineClock = stable_pstate_sclk;
  2290. minimum_clocks.memoryClock = stable_pstate_mclk;
  2291. }
  2292. if (minimum_clocks.engineClock < hwmgr->gfx_arbiter.sclk)
  2293. minimum_clocks.engineClock = hwmgr->gfx_arbiter.sclk;
  2294. if (minimum_clocks.memoryClock < hwmgr->gfx_arbiter.mclk)
  2295. minimum_clocks.memoryClock = hwmgr->gfx_arbiter.mclk;
  2296. smu7_ps->sclk_threshold = hwmgr->gfx_arbiter.sclk_threshold;
  2297. if (0 != hwmgr->gfx_arbiter.sclk_over_drive) {
  2298. PP_ASSERT_WITH_CODE((hwmgr->gfx_arbiter.sclk_over_drive <=
  2299. hwmgr->platform_descriptor.overdriveLimit.engineClock),
  2300. "Overdrive sclk exceeds limit",
  2301. hwmgr->gfx_arbiter.sclk_over_drive =
  2302. hwmgr->platform_descriptor.overdriveLimit.engineClock);
  2303. if (hwmgr->gfx_arbiter.sclk_over_drive >= hwmgr->gfx_arbiter.sclk)
  2304. smu7_ps->performance_levels[1].engine_clock =
  2305. hwmgr->gfx_arbiter.sclk_over_drive;
  2306. }
  2307. if (0 != hwmgr->gfx_arbiter.mclk_over_drive) {
  2308. PP_ASSERT_WITH_CODE((hwmgr->gfx_arbiter.mclk_over_drive <=
  2309. hwmgr->platform_descriptor.overdriveLimit.memoryClock),
  2310. "Overdrive mclk exceeds limit",
  2311. hwmgr->gfx_arbiter.mclk_over_drive =
  2312. hwmgr->platform_descriptor.overdriveLimit.memoryClock);
  2313. if (hwmgr->gfx_arbiter.mclk_over_drive >= hwmgr->gfx_arbiter.mclk)
  2314. smu7_ps->performance_levels[1].memory_clock =
  2315. hwmgr->gfx_arbiter.mclk_over_drive;
  2316. }
  2317. disable_mclk_switching_for_frame_lock = phm_cap_enabled(
  2318. hwmgr->platform_descriptor.platformCaps,
  2319. PHM_PlatformCaps_DisableMclkSwitchingForFrameLock);
  2320. disable_mclk_switching = ((1 < info.display_count) ||
  2321. disable_mclk_switching_for_frame_lock ||
  2322. smu7_vblank_too_short(hwmgr, mode_info.vblank_time_us) ||
  2323. (mode_info.refresh_rate > 120));
  2324. sclk = smu7_ps->performance_levels[0].engine_clock;
  2325. mclk = smu7_ps->performance_levels[0].memory_clock;
  2326. if (disable_mclk_switching)
  2327. mclk = smu7_ps->performance_levels
  2328. [smu7_ps->performance_level_count - 1].memory_clock;
  2329. if (sclk < minimum_clocks.engineClock)
  2330. sclk = (minimum_clocks.engineClock > max_limits->sclk) ?
  2331. max_limits->sclk : minimum_clocks.engineClock;
  2332. if (mclk < minimum_clocks.memoryClock)
  2333. mclk = (minimum_clocks.memoryClock > max_limits->mclk) ?
  2334. max_limits->mclk : minimum_clocks.memoryClock;
  2335. smu7_ps->performance_levels[0].engine_clock = sclk;
  2336. smu7_ps->performance_levels[0].memory_clock = mclk;
  2337. smu7_ps->performance_levels[1].engine_clock =
  2338. (smu7_ps->performance_levels[1].engine_clock >=
  2339. smu7_ps->performance_levels[0].engine_clock) ?
  2340. smu7_ps->performance_levels[1].engine_clock :
  2341. smu7_ps->performance_levels[0].engine_clock;
  2342. if (disable_mclk_switching) {
  2343. if (mclk < smu7_ps->performance_levels[1].memory_clock)
  2344. mclk = smu7_ps->performance_levels[1].memory_clock;
  2345. smu7_ps->performance_levels[0].memory_clock = mclk;
  2346. smu7_ps->performance_levels[1].memory_clock = mclk;
  2347. } else {
  2348. if (smu7_ps->performance_levels[1].memory_clock <
  2349. smu7_ps->performance_levels[0].memory_clock)
  2350. smu7_ps->performance_levels[1].memory_clock =
  2351. smu7_ps->performance_levels[0].memory_clock;
  2352. }
  2353. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  2354. PHM_PlatformCaps_StablePState)) {
  2355. for (i = 0; i < smu7_ps->performance_level_count; i++) {
  2356. smu7_ps->performance_levels[i].engine_clock = stable_pstate_sclk;
  2357. smu7_ps->performance_levels[i].memory_clock = stable_pstate_mclk;
  2358. smu7_ps->performance_levels[i].pcie_gen = data->pcie_gen_performance.max;
  2359. smu7_ps->performance_levels[i].pcie_lane = data->pcie_gen_performance.max;
  2360. }
  2361. }
  2362. return 0;
  2363. }
  2364. static int smu7_dpm_get_mclk(struct pp_hwmgr *hwmgr, bool low)
  2365. {
  2366. struct pp_power_state *ps;
  2367. struct smu7_power_state *smu7_ps;
  2368. if (hwmgr == NULL)
  2369. return -EINVAL;
  2370. ps = hwmgr->request_ps;
  2371. if (ps == NULL)
  2372. return -EINVAL;
  2373. smu7_ps = cast_phw_smu7_power_state(&ps->hardware);
  2374. if (low)
  2375. return smu7_ps->performance_levels[0].memory_clock;
  2376. else
  2377. return smu7_ps->performance_levels
  2378. [smu7_ps->performance_level_count-1].memory_clock;
  2379. }
  2380. static int smu7_dpm_get_sclk(struct pp_hwmgr *hwmgr, bool low)
  2381. {
  2382. struct pp_power_state *ps;
  2383. struct smu7_power_state *smu7_ps;
  2384. if (hwmgr == NULL)
  2385. return -EINVAL;
  2386. ps = hwmgr->request_ps;
  2387. if (ps == NULL)
  2388. return -EINVAL;
  2389. smu7_ps = cast_phw_smu7_power_state(&ps->hardware);
  2390. if (low)
  2391. return smu7_ps->performance_levels[0].engine_clock;
  2392. else
  2393. return smu7_ps->performance_levels
  2394. [smu7_ps->performance_level_count-1].engine_clock;
  2395. }
  2396. static int smu7_dpm_patch_boot_state(struct pp_hwmgr *hwmgr,
  2397. struct pp_hw_power_state *hw_ps)
  2398. {
  2399. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  2400. struct smu7_power_state *ps = (struct smu7_power_state *)hw_ps;
  2401. ATOM_FIRMWARE_INFO_V2_2 *fw_info;
  2402. uint16_t size;
  2403. uint8_t frev, crev;
  2404. int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
  2405. /* First retrieve the Boot clocks and VDDC from the firmware info table.
  2406. * We assume here that fw_info is unchanged if this call fails.
  2407. */
  2408. fw_info = (ATOM_FIRMWARE_INFO_V2_2 *)cgs_atom_get_data_table(
  2409. hwmgr->device, index,
  2410. &size, &frev, &crev);
  2411. if (!fw_info)
  2412. /* During a test, there is no firmware info table. */
  2413. return 0;
  2414. /* Patch the state. */
  2415. data->vbios_boot_state.sclk_bootup_value =
  2416. le32_to_cpu(fw_info->ulDefaultEngineClock);
  2417. data->vbios_boot_state.mclk_bootup_value =
  2418. le32_to_cpu(fw_info->ulDefaultMemoryClock);
  2419. data->vbios_boot_state.mvdd_bootup_value =
  2420. le16_to_cpu(fw_info->usBootUpMVDDCVoltage);
  2421. data->vbios_boot_state.vddc_bootup_value =
  2422. le16_to_cpu(fw_info->usBootUpVDDCVoltage);
  2423. data->vbios_boot_state.vddci_bootup_value =
  2424. le16_to_cpu(fw_info->usBootUpVDDCIVoltage);
  2425. data->vbios_boot_state.pcie_gen_bootup_value =
  2426. smu7_get_current_pcie_speed(hwmgr);
  2427. data->vbios_boot_state.pcie_lane_bootup_value =
  2428. (uint16_t)smu7_get_current_pcie_lane_number(hwmgr);
  2429. /* set boot power state */
  2430. ps->performance_levels[0].memory_clock = data->vbios_boot_state.mclk_bootup_value;
  2431. ps->performance_levels[0].engine_clock = data->vbios_boot_state.sclk_bootup_value;
  2432. ps->performance_levels[0].pcie_gen = data->vbios_boot_state.pcie_gen_bootup_value;
  2433. ps->performance_levels[0].pcie_lane = data->vbios_boot_state.pcie_lane_bootup_value;
  2434. return 0;
  2435. }
  2436. static int smu7_get_number_of_powerplay_table_entries(struct pp_hwmgr *hwmgr)
  2437. {
  2438. int result;
  2439. unsigned long ret = 0;
  2440. if (hwmgr->pp_table_version == PP_TABLE_V0) {
  2441. result = pp_tables_get_num_of_entries(hwmgr, &ret);
  2442. return result ? 0 : ret;
  2443. } else if (hwmgr->pp_table_version == PP_TABLE_V1) {
  2444. result = get_number_of_powerplay_table_entries_v1_0(hwmgr);
  2445. return result;
  2446. }
  2447. return 0;
  2448. }
  2449. static int smu7_get_pp_table_entry_callback_func_v1(struct pp_hwmgr *hwmgr,
  2450. void *state, struct pp_power_state *power_state,
  2451. void *pp_table, uint32_t classification_flag)
  2452. {
  2453. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  2454. struct smu7_power_state *smu7_power_state =
  2455. (struct smu7_power_state *)(&(power_state->hardware));
  2456. struct smu7_performance_level *performance_level;
  2457. ATOM_Tonga_State *state_entry = (ATOM_Tonga_State *)state;
  2458. ATOM_Tonga_POWERPLAYTABLE *powerplay_table =
  2459. (ATOM_Tonga_POWERPLAYTABLE *)pp_table;
  2460. PPTable_Generic_SubTable_Header *sclk_dep_table =
  2461. (PPTable_Generic_SubTable_Header *)
  2462. (((unsigned long)powerplay_table) +
  2463. le16_to_cpu(powerplay_table->usSclkDependencyTableOffset));
  2464. ATOM_Tonga_MCLK_Dependency_Table *mclk_dep_table =
  2465. (ATOM_Tonga_MCLK_Dependency_Table *)
  2466. (((unsigned long)powerplay_table) +
  2467. le16_to_cpu(powerplay_table->usMclkDependencyTableOffset));
  2468. /* The following fields are not initialized here: id orderedList allStatesList */
  2469. power_state->classification.ui_label =
  2470. (le16_to_cpu(state_entry->usClassification) &
  2471. ATOM_PPLIB_CLASSIFICATION_UI_MASK) >>
  2472. ATOM_PPLIB_CLASSIFICATION_UI_SHIFT;
  2473. power_state->classification.flags = classification_flag;
  2474. /* NOTE: There is a classification2 flag in BIOS that is not being used right now */
  2475. power_state->classification.temporary_state = false;
  2476. power_state->classification.to_be_deleted = false;
  2477. power_state->validation.disallowOnDC =
  2478. (0 != (le32_to_cpu(state_entry->ulCapsAndSettings) &
  2479. ATOM_Tonga_DISALLOW_ON_DC));
  2480. power_state->pcie.lanes = 0;
  2481. power_state->display.disableFrameModulation = false;
  2482. power_state->display.limitRefreshrate = false;
  2483. power_state->display.enableVariBright =
  2484. (0 != (le32_to_cpu(state_entry->ulCapsAndSettings) &
  2485. ATOM_Tonga_ENABLE_VARIBRIGHT));
  2486. power_state->validation.supportedPowerLevels = 0;
  2487. power_state->uvd_clocks.VCLK = 0;
  2488. power_state->uvd_clocks.DCLK = 0;
  2489. power_state->temperatures.min = 0;
  2490. power_state->temperatures.max = 0;
  2491. performance_level = &(smu7_power_state->performance_levels
  2492. [smu7_power_state->performance_level_count++]);
  2493. PP_ASSERT_WITH_CODE(
  2494. (smu7_power_state->performance_level_count < smum_get_mac_definition(hwmgr->smumgr, SMU_MAX_LEVELS_GRAPHICS)),
  2495. "Performance levels exceeds SMC limit!",
  2496. return -EINVAL);
  2497. PP_ASSERT_WITH_CODE(
  2498. (smu7_power_state->performance_level_count <=
  2499. hwmgr->platform_descriptor.hardwareActivityPerformanceLevels),
  2500. "Performance levels exceeds Driver limit!",
  2501. return -EINVAL);
  2502. /* Performance levels are arranged from low to high. */
  2503. performance_level->memory_clock = mclk_dep_table->entries
  2504. [state_entry->ucMemoryClockIndexLow].ulMclk;
  2505. if (sclk_dep_table->ucRevId == 0)
  2506. performance_level->engine_clock = ((ATOM_Tonga_SCLK_Dependency_Table *)sclk_dep_table)->entries
  2507. [state_entry->ucEngineClockIndexLow].ulSclk;
  2508. else if (sclk_dep_table->ucRevId == 1)
  2509. performance_level->engine_clock = ((ATOM_Polaris_SCLK_Dependency_Table *)sclk_dep_table)->entries
  2510. [state_entry->ucEngineClockIndexLow].ulSclk;
  2511. performance_level->pcie_gen = get_pcie_gen_support(data->pcie_gen_cap,
  2512. state_entry->ucPCIEGenLow);
  2513. performance_level->pcie_lane = get_pcie_lane_support(data->pcie_lane_cap,
  2514. state_entry->ucPCIELaneHigh);
  2515. performance_level = &(smu7_power_state->performance_levels
  2516. [smu7_power_state->performance_level_count++]);
  2517. performance_level->memory_clock = mclk_dep_table->entries
  2518. [state_entry->ucMemoryClockIndexHigh].ulMclk;
  2519. if (sclk_dep_table->ucRevId == 0)
  2520. performance_level->engine_clock = ((ATOM_Tonga_SCLK_Dependency_Table *)sclk_dep_table)->entries
  2521. [state_entry->ucEngineClockIndexHigh].ulSclk;
  2522. else if (sclk_dep_table->ucRevId == 1)
  2523. performance_level->engine_clock = ((ATOM_Polaris_SCLK_Dependency_Table *)sclk_dep_table)->entries
  2524. [state_entry->ucEngineClockIndexHigh].ulSclk;
  2525. performance_level->pcie_gen = get_pcie_gen_support(data->pcie_gen_cap,
  2526. state_entry->ucPCIEGenHigh);
  2527. performance_level->pcie_lane = get_pcie_lane_support(data->pcie_lane_cap,
  2528. state_entry->ucPCIELaneHigh);
  2529. return 0;
  2530. }
  2531. static int smu7_get_pp_table_entry_v1(struct pp_hwmgr *hwmgr,
  2532. unsigned long entry_index, struct pp_power_state *state)
  2533. {
  2534. int result;
  2535. struct smu7_power_state *ps;
  2536. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  2537. struct phm_ppt_v1_information *table_info =
  2538. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  2539. struct phm_ppt_v1_clock_voltage_dependency_table *dep_mclk_table =
  2540. table_info->vdd_dep_on_mclk;
  2541. state->hardware.magic = PHM_VIslands_Magic;
  2542. ps = (struct smu7_power_state *)(&state->hardware);
  2543. result = get_powerplay_table_entry_v1_0(hwmgr, entry_index, state,
  2544. smu7_get_pp_table_entry_callback_func_v1);
  2545. /* This is the earliest time we have all the dependency table and the VBIOS boot state
  2546. * as PP_Tables_GetPowerPlayTableEntry retrieves the VBIOS boot state
  2547. * if there is only one VDDCI/MCLK level, check if it's the same as VBIOS boot state
  2548. */
  2549. if (dep_mclk_table != NULL && dep_mclk_table->count == 1) {
  2550. if (dep_mclk_table->entries[0].clk !=
  2551. data->vbios_boot_state.mclk_bootup_value)
  2552. pr_err("Single MCLK entry VDDCI/MCLK dependency table "
  2553. "does not match VBIOS boot MCLK level");
  2554. if (dep_mclk_table->entries[0].vddci !=
  2555. data->vbios_boot_state.vddci_bootup_value)
  2556. pr_err("Single VDDCI entry VDDCI/MCLK dependency table "
  2557. "does not match VBIOS boot VDDCI level");
  2558. }
  2559. /* set DC compatible flag if this state supports DC */
  2560. if (!state->validation.disallowOnDC)
  2561. ps->dc_compatible = true;
  2562. if (state->classification.flags & PP_StateClassificationFlag_ACPI)
  2563. data->acpi_pcie_gen = ps->performance_levels[0].pcie_gen;
  2564. ps->uvd_clks.vclk = state->uvd_clocks.VCLK;
  2565. ps->uvd_clks.dclk = state->uvd_clocks.DCLK;
  2566. if (!result) {
  2567. uint32_t i;
  2568. switch (state->classification.ui_label) {
  2569. case PP_StateUILabel_Performance:
  2570. data->use_pcie_performance_levels = true;
  2571. for (i = 0; i < ps->performance_level_count; i++) {
  2572. if (data->pcie_gen_performance.max <
  2573. ps->performance_levels[i].pcie_gen)
  2574. data->pcie_gen_performance.max =
  2575. ps->performance_levels[i].pcie_gen;
  2576. if (data->pcie_gen_performance.min >
  2577. ps->performance_levels[i].pcie_gen)
  2578. data->pcie_gen_performance.min =
  2579. ps->performance_levels[i].pcie_gen;
  2580. if (data->pcie_lane_performance.max <
  2581. ps->performance_levels[i].pcie_lane)
  2582. data->pcie_lane_performance.max =
  2583. ps->performance_levels[i].pcie_lane;
  2584. if (data->pcie_lane_performance.min >
  2585. ps->performance_levels[i].pcie_lane)
  2586. data->pcie_lane_performance.min =
  2587. ps->performance_levels[i].pcie_lane;
  2588. }
  2589. break;
  2590. case PP_StateUILabel_Battery:
  2591. data->use_pcie_power_saving_levels = true;
  2592. for (i = 0; i < ps->performance_level_count; i++) {
  2593. if (data->pcie_gen_power_saving.max <
  2594. ps->performance_levels[i].pcie_gen)
  2595. data->pcie_gen_power_saving.max =
  2596. ps->performance_levels[i].pcie_gen;
  2597. if (data->pcie_gen_power_saving.min >
  2598. ps->performance_levels[i].pcie_gen)
  2599. data->pcie_gen_power_saving.min =
  2600. ps->performance_levels[i].pcie_gen;
  2601. if (data->pcie_lane_power_saving.max <
  2602. ps->performance_levels[i].pcie_lane)
  2603. data->pcie_lane_power_saving.max =
  2604. ps->performance_levels[i].pcie_lane;
  2605. if (data->pcie_lane_power_saving.min >
  2606. ps->performance_levels[i].pcie_lane)
  2607. data->pcie_lane_power_saving.min =
  2608. ps->performance_levels[i].pcie_lane;
  2609. }
  2610. break;
  2611. default:
  2612. break;
  2613. }
  2614. }
  2615. return 0;
  2616. }
  2617. static int smu7_get_pp_table_entry_callback_func_v0(struct pp_hwmgr *hwmgr,
  2618. struct pp_hw_power_state *power_state,
  2619. unsigned int index, const void *clock_info)
  2620. {
  2621. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  2622. struct smu7_power_state *ps = cast_phw_smu7_power_state(power_state);
  2623. const ATOM_PPLIB_CI_CLOCK_INFO *visland_clk_info = clock_info;
  2624. struct smu7_performance_level *performance_level;
  2625. uint32_t engine_clock, memory_clock;
  2626. uint16_t pcie_gen_from_bios;
  2627. engine_clock = visland_clk_info->ucEngineClockHigh << 16 | visland_clk_info->usEngineClockLow;
  2628. memory_clock = visland_clk_info->ucMemoryClockHigh << 16 | visland_clk_info->usMemoryClockLow;
  2629. if (!(data->mc_micro_code_feature & DISABLE_MC_LOADMICROCODE) && memory_clock > data->highest_mclk)
  2630. data->highest_mclk = memory_clock;
  2631. PP_ASSERT_WITH_CODE(
  2632. (ps->performance_level_count < smum_get_mac_definition(hwmgr->smumgr, SMU_MAX_LEVELS_GRAPHICS)),
  2633. "Performance levels exceeds SMC limit!",
  2634. return -EINVAL);
  2635. PP_ASSERT_WITH_CODE(
  2636. (ps->performance_level_count <
  2637. hwmgr->platform_descriptor.hardwareActivityPerformanceLevels),
  2638. "Performance levels exceeds Driver limit, Skip!",
  2639. return 0);
  2640. performance_level = &(ps->performance_levels
  2641. [ps->performance_level_count++]);
  2642. /* Performance levels are arranged from low to high. */
  2643. performance_level->memory_clock = memory_clock;
  2644. performance_level->engine_clock = engine_clock;
  2645. pcie_gen_from_bios = visland_clk_info->ucPCIEGen;
  2646. performance_level->pcie_gen = get_pcie_gen_support(data->pcie_gen_cap, pcie_gen_from_bios);
  2647. performance_level->pcie_lane = get_pcie_lane_support(data->pcie_lane_cap, visland_clk_info->usPCIELane);
  2648. return 0;
  2649. }
  2650. static int smu7_get_pp_table_entry_v0(struct pp_hwmgr *hwmgr,
  2651. unsigned long entry_index, struct pp_power_state *state)
  2652. {
  2653. int result;
  2654. struct smu7_power_state *ps;
  2655. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  2656. struct phm_clock_voltage_dependency_table *dep_mclk_table =
  2657. hwmgr->dyn_state.vddci_dependency_on_mclk;
  2658. memset(&state->hardware, 0x00, sizeof(struct pp_hw_power_state));
  2659. state->hardware.magic = PHM_VIslands_Magic;
  2660. ps = (struct smu7_power_state *)(&state->hardware);
  2661. result = pp_tables_get_entry(hwmgr, entry_index, state,
  2662. smu7_get_pp_table_entry_callback_func_v0);
  2663. /*
  2664. * This is the earliest time we have all the dependency table
  2665. * and the VBIOS boot state as
  2666. * PP_Tables_GetPowerPlayTableEntry retrieves the VBIOS boot
  2667. * state if there is only one VDDCI/MCLK level, check if it's
  2668. * the same as VBIOS boot state
  2669. */
  2670. if (dep_mclk_table != NULL && dep_mclk_table->count == 1) {
  2671. if (dep_mclk_table->entries[0].clk !=
  2672. data->vbios_boot_state.mclk_bootup_value)
  2673. pr_err("Single MCLK entry VDDCI/MCLK dependency table "
  2674. "does not match VBIOS boot MCLK level");
  2675. if (dep_mclk_table->entries[0].v !=
  2676. data->vbios_boot_state.vddci_bootup_value)
  2677. pr_err("Single VDDCI entry VDDCI/MCLK dependency table "
  2678. "does not match VBIOS boot VDDCI level");
  2679. }
  2680. /* set DC compatible flag if this state supports DC */
  2681. if (!state->validation.disallowOnDC)
  2682. ps->dc_compatible = true;
  2683. if (state->classification.flags & PP_StateClassificationFlag_ACPI)
  2684. data->acpi_pcie_gen = ps->performance_levels[0].pcie_gen;
  2685. ps->uvd_clks.vclk = state->uvd_clocks.VCLK;
  2686. ps->uvd_clks.dclk = state->uvd_clocks.DCLK;
  2687. if (!result) {
  2688. uint32_t i;
  2689. switch (state->classification.ui_label) {
  2690. case PP_StateUILabel_Performance:
  2691. data->use_pcie_performance_levels = true;
  2692. for (i = 0; i < ps->performance_level_count; i++) {
  2693. if (data->pcie_gen_performance.max <
  2694. ps->performance_levels[i].pcie_gen)
  2695. data->pcie_gen_performance.max =
  2696. ps->performance_levels[i].pcie_gen;
  2697. if (data->pcie_gen_performance.min >
  2698. ps->performance_levels[i].pcie_gen)
  2699. data->pcie_gen_performance.min =
  2700. ps->performance_levels[i].pcie_gen;
  2701. if (data->pcie_lane_performance.max <
  2702. ps->performance_levels[i].pcie_lane)
  2703. data->pcie_lane_performance.max =
  2704. ps->performance_levels[i].pcie_lane;
  2705. if (data->pcie_lane_performance.min >
  2706. ps->performance_levels[i].pcie_lane)
  2707. data->pcie_lane_performance.min =
  2708. ps->performance_levels[i].pcie_lane;
  2709. }
  2710. break;
  2711. case PP_StateUILabel_Battery:
  2712. data->use_pcie_power_saving_levels = true;
  2713. for (i = 0; i < ps->performance_level_count; i++) {
  2714. if (data->pcie_gen_power_saving.max <
  2715. ps->performance_levels[i].pcie_gen)
  2716. data->pcie_gen_power_saving.max =
  2717. ps->performance_levels[i].pcie_gen;
  2718. if (data->pcie_gen_power_saving.min >
  2719. ps->performance_levels[i].pcie_gen)
  2720. data->pcie_gen_power_saving.min =
  2721. ps->performance_levels[i].pcie_gen;
  2722. if (data->pcie_lane_power_saving.max <
  2723. ps->performance_levels[i].pcie_lane)
  2724. data->pcie_lane_power_saving.max =
  2725. ps->performance_levels[i].pcie_lane;
  2726. if (data->pcie_lane_power_saving.min >
  2727. ps->performance_levels[i].pcie_lane)
  2728. data->pcie_lane_power_saving.min =
  2729. ps->performance_levels[i].pcie_lane;
  2730. }
  2731. break;
  2732. default:
  2733. break;
  2734. }
  2735. }
  2736. return 0;
  2737. }
  2738. static int smu7_get_pp_table_entry(struct pp_hwmgr *hwmgr,
  2739. unsigned long entry_index, struct pp_power_state *state)
  2740. {
  2741. if (hwmgr->pp_table_version == PP_TABLE_V0)
  2742. return smu7_get_pp_table_entry_v0(hwmgr, entry_index, state);
  2743. else if (hwmgr->pp_table_version == PP_TABLE_V1)
  2744. return smu7_get_pp_table_entry_v1(hwmgr, entry_index, state);
  2745. return 0;
  2746. }
  2747. static int smu7_get_gpu_power(struct pp_hwmgr *hwmgr,
  2748. struct pp_gpu_power *query)
  2749. {
  2750. PP_ASSERT_WITH_CODE(!smum_send_msg_to_smc(hwmgr->smumgr,
  2751. PPSMC_MSG_PmStatusLogStart),
  2752. "Failed to start pm status log!",
  2753. return -1);
  2754. msleep_interruptible(20);
  2755. PP_ASSERT_WITH_CODE(!smum_send_msg_to_smc(hwmgr->smumgr,
  2756. PPSMC_MSG_PmStatusLogSample),
  2757. "Failed to sample pm status log!",
  2758. return -1);
  2759. query->vddc_power = cgs_read_ind_register(hwmgr->device,
  2760. CGS_IND_REG__SMC,
  2761. ixSMU_PM_STATUS_40);
  2762. query->vddci_power = cgs_read_ind_register(hwmgr->device,
  2763. CGS_IND_REG__SMC,
  2764. ixSMU_PM_STATUS_49);
  2765. query->max_gpu_power = cgs_read_ind_register(hwmgr->device,
  2766. CGS_IND_REG__SMC,
  2767. ixSMU_PM_STATUS_94);
  2768. query->average_gpu_power = cgs_read_ind_register(hwmgr->device,
  2769. CGS_IND_REG__SMC,
  2770. ixSMU_PM_STATUS_95);
  2771. return 0;
  2772. }
  2773. static int smu7_read_sensor(struct pp_hwmgr *hwmgr, int idx,
  2774. void *value, int *size)
  2775. {
  2776. uint32_t sclk, mclk, activity_percent;
  2777. uint32_t offset;
  2778. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  2779. /* size must be at least 4 bytes for all sensors */
  2780. if (*size < 4)
  2781. return -EINVAL;
  2782. switch (idx) {
  2783. case AMDGPU_PP_SENSOR_GFX_SCLK:
  2784. smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_API_GetSclkFrequency);
  2785. sclk = cgs_read_register(hwmgr->device, mmSMC_MSG_ARG_0);
  2786. *((uint32_t *)value) = sclk;
  2787. *size = 4;
  2788. return 0;
  2789. case AMDGPU_PP_SENSOR_GFX_MCLK:
  2790. smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_API_GetMclkFrequency);
  2791. mclk = cgs_read_register(hwmgr->device, mmSMC_MSG_ARG_0);
  2792. *((uint32_t *)value) = mclk;
  2793. *size = 4;
  2794. return 0;
  2795. case AMDGPU_PP_SENSOR_GPU_LOAD:
  2796. offset = data->soft_regs_start + smum_get_offsetof(hwmgr->smumgr,
  2797. SMU_SoftRegisters,
  2798. AverageGraphicsActivity);
  2799. activity_percent = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, offset);
  2800. activity_percent += 0x80;
  2801. activity_percent >>= 8;
  2802. *((uint32_t *)value) = activity_percent > 100 ? 100 : activity_percent;
  2803. *size = 4;
  2804. return 0;
  2805. case AMDGPU_PP_SENSOR_GPU_TEMP:
  2806. *((uint32_t *)value) = smu7_thermal_get_temperature(hwmgr);
  2807. *size = 4;
  2808. return 0;
  2809. case AMDGPU_PP_SENSOR_UVD_POWER:
  2810. *((uint32_t *)value) = data->uvd_power_gated ? 0 : 1;
  2811. *size = 4;
  2812. return 0;
  2813. case AMDGPU_PP_SENSOR_VCE_POWER:
  2814. *((uint32_t *)value) = data->vce_power_gated ? 0 : 1;
  2815. *size = 4;
  2816. return 0;
  2817. case AMDGPU_PP_SENSOR_GPU_POWER:
  2818. if (*size < sizeof(struct pp_gpu_power))
  2819. return -EINVAL;
  2820. *size = sizeof(struct pp_gpu_power);
  2821. return smu7_get_gpu_power(hwmgr, (struct pp_gpu_power *)value);
  2822. default:
  2823. return -EINVAL;
  2824. }
  2825. }
  2826. static int smu7_find_dpm_states_clocks_in_dpm_table(struct pp_hwmgr *hwmgr, const void *input)
  2827. {
  2828. const struct phm_set_power_state_input *states =
  2829. (const struct phm_set_power_state_input *)input;
  2830. const struct smu7_power_state *smu7_ps =
  2831. cast_const_phw_smu7_power_state(states->pnew_state);
  2832. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  2833. struct smu7_single_dpm_table *sclk_table = &(data->dpm_table.sclk_table);
  2834. uint32_t sclk = smu7_ps->performance_levels
  2835. [smu7_ps->performance_level_count - 1].engine_clock;
  2836. struct smu7_single_dpm_table *mclk_table = &(data->dpm_table.mclk_table);
  2837. uint32_t mclk = smu7_ps->performance_levels
  2838. [smu7_ps->performance_level_count - 1].memory_clock;
  2839. struct PP_Clocks min_clocks = {0};
  2840. uint32_t i;
  2841. struct cgs_display_info info = {0};
  2842. data->need_update_smu7_dpm_table = 0;
  2843. for (i = 0; i < sclk_table->count; i++) {
  2844. if (sclk == sclk_table->dpm_levels[i].value)
  2845. break;
  2846. }
  2847. if (i >= sclk_table->count)
  2848. data->need_update_smu7_dpm_table |= DPMTABLE_OD_UPDATE_SCLK;
  2849. else {
  2850. /* TODO: Check SCLK in DAL's minimum clocks
  2851. * in case DeepSleep divider update is required.
  2852. */
  2853. if (data->display_timing.min_clock_in_sr != min_clocks.engineClockInSR &&
  2854. (min_clocks.engineClockInSR >= SMU7_MINIMUM_ENGINE_CLOCK ||
  2855. data->display_timing.min_clock_in_sr >= SMU7_MINIMUM_ENGINE_CLOCK))
  2856. data->need_update_smu7_dpm_table |= DPMTABLE_UPDATE_SCLK;
  2857. }
  2858. for (i = 0; i < mclk_table->count; i++) {
  2859. if (mclk == mclk_table->dpm_levels[i].value)
  2860. break;
  2861. }
  2862. if (i >= mclk_table->count)
  2863. data->need_update_smu7_dpm_table |= DPMTABLE_OD_UPDATE_MCLK;
  2864. cgs_get_active_displays_info(hwmgr->device, &info);
  2865. if (data->display_timing.num_existing_displays != info.display_count)
  2866. data->need_update_smu7_dpm_table |= DPMTABLE_UPDATE_MCLK;
  2867. return 0;
  2868. }
  2869. static uint16_t smu7_get_maximum_link_speed(struct pp_hwmgr *hwmgr,
  2870. const struct smu7_power_state *smu7_ps)
  2871. {
  2872. uint32_t i;
  2873. uint32_t sclk, max_sclk = 0;
  2874. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  2875. struct smu7_dpm_table *dpm_table = &data->dpm_table;
  2876. for (i = 0; i < smu7_ps->performance_level_count; i++) {
  2877. sclk = smu7_ps->performance_levels[i].engine_clock;
  2878. if (max_sclk < sclk)
  2879. max_sclk = sclk;
  2880. }
  2881. for (i = 0; i < dpm_table->sclk_table.count; i++) {
  2882. if (dpm_table->sclk_table.dpm_levels[i].value == max_sclk)
  2883. return (uint16_t) ((i >= dpm_table->pcie_speed_table.count) ?
  2884. dpm_table->pcie_speed_table.dpm_levels
  2885. [dpm_table->pcie_speed_table.count - 1].value :
  2886. dpm_table->pcie_speed_table.dpm_levels[i].value);
  2887. }
  2888. return 0;
  2889. }
  2890. static int smu7_request_link_speed_change_before_state_change(
  2891. struct pp_hwmgr *hwmgr, const void *input)
  2892. {
  2893. const struct phm_set_power_state_input *states =
  2894. (const struct phm_set_power_state_input *)input;
  2895. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  2896. const struct smu7_power_state *smu7_nps =
  2897. cast_const_phw_smu7_power_state(states->pnew_state);
  2898. const struct smu7_power_state *polaris10_cps =
  2899. cast_const_phw_smu7_power_state(states->pcurrent_state);
  2900. uint16_t target_link_speed = smu7_get_maximum_link_speed(hwmgr, smu7_nps);
  2901. uint16_t current_link_speed;
  2902. if (data->force_pcie_gen == PP_PCIEGenInvalid)
  2903. current_link_speed = smu7_get_maximum_link_speed(hwmgr, polaris10_cps);
  2904. else
  2905. current_link_speed = data->force_pcie_gen;
  2906. data->force_pcie_gen = PP_PCIEGenInvalid;
  2907. data->pspp_notify_required = false;
  2908. if (target_link_speed > current_link_speed) {
  2909. switch (target_link_speed) {
  2910. case PP_PCIEGen3:
  2911. if (0 == acpi_pcie_perf_request(hwmgr->device, PCIE_PERF_REQ_GEN3, false))
  2912. break;
  2913. data->force_pcie_gen = PP_PCIEGen2;
  2914. if (current_link_speed == PP_PCIEGen2)
  2915. break;
  2916. case PP_PCIEGen2:
  2917. if (0 == acpi_pcie_perf_request(hwmgr->device, PCIE_PERF_REQ_GEN2, false))
  2918. break;
  2919. default:
  2920. data->force_pcie_gen = smu7_get_current_pcie_speed(hwmgr);
  2921. break;
  2922. }
  2923. } else {
  2924. if (target_link_speed < current_link_speed)
  2925. data->pspp_notify_required = true;
  2926. }
  2927. return 0;
  2928. }
  2929. static int smu7_freeze_sclk_mclk_dpm(struct pp_hwmgr *hwmgr)
  2930. {
  2931. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  2932. if (0 == data->need_update_smu7_dpm_table)
  2933. return 0;
  2934. if ((0 == data->sclk_dpm_key_disabled) &&
  2935. (data->need_update_smu7_dpm_table &
  2936. (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_UPDATE_SCLK))) {
  2937. PP_ASSERT_WITH_CODE(true == smum_is_dpm_running(hwmgr),
  2938. "Trying to freeze SCLK DPM when DPM is disabled",
  2939. );
  2940. PP_ASSERT_WITH_CODE(0 == smum_send_msg_to_smc(hwmgr->smumgr,
  2941. PPSMC_MSG_SCLKDPM_FreezeLevel),
  2942. "Failed to freeze SCLK DPM during FreezeSclkMclkDPM Function!",
  2943. return -EINVAL);
  2944. }
  2945. if ((0 == data->mclk_dpm_key_disabled) &&
  2946. (data->need_update_smu7_dpm_table &
  2947. DPMTABLE_OD_UPDATE_MCLK)) {
  2948. PP_ASSERT_WITH_CODE(true == smum_is_dpm_running(hwmgr),
  2949. "Trying to freeze MCLK DPM when DPM is disabled",
  2950. );
  2951. PP_ASSERT_WITH_CODE(0 == smum_send_msg_to_smc(hwmgr->smumgr,
  2952. PPSMC_MSG_MCLKDPM_FreezeLevel),
  2953. "Failed to freeze MCLK DPM during FreezeSclkMclkDPM Function!",
  2954. return -EINVAL);
  2955. }
  2956. return 0;
  2957. }
  2958. static int smu7_populate_and_upload_sclk_mclk_dpm_levels(
  2959. struct pp_hwmgr *hwmgr, const void *input)
  2960. {
  2961. int result = 0;
  2962. const struct phm_set_power_state_input *states =
  2963. (const struct phm_set_power_state_input *)input;
  2964. const struct smu7_power_state *smu7_ps =
  2965. cast_const_phw_smu7_power_state(states->pnew_state);
  2966. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  2967. uint32_t sclk = smu7_ps->performance_levels
  2968. [smu7_ps->performance_level_count - 1].engine_clock;
  2969. uint32_t mclk = smu7_ps->performance_levels
  2970. [smu7_ps->performance_level_count - 1].memory_clock;
  2971. struct smu7_dpm_table *dpm_table = &data->dpm_table;
  2972. struct smu7_dpm_table *golden_dpm_table = &data->golden_dpm_table;
  2973. uint32_t dpm_count, clock_percent;
  2974. uint32_t i;
  2975. if (0 == data->need_update_smu7_dpm_table)
  2976. return 0;
  2977. if (data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_SCLK) {
  2978. dpm_table->sclk_table.dpm_levels
  2979. [dpm_table->sclk_table.count - 1].value = sclk;
  2980. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_OD6PlusinACSupport) ||
  2981. phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_OD6PlusinDCSupport)) {
  2982. /* Need to do calculation based on the golden DPM table
  2983. * as the Heatmap GPU Clock axis is also based on the default values
  2984. */
  2985. PP_ASSERT_WITH_CODE(
  2986. (golden_dpm_table->sclk_table.dpm_levels
  2987. [golden_dpm_table->sclk_table.count - 1].value != 0),
  2988. "Divide by 0!",
  2989. return -EINVAL);
  2990. dpm_count = dpm_table->sclk_table.count < 2 ? 0 : dpm_table->sclk_table.count - 2;
  2991. for (i = dpm_count; i > 1; i--) {
  2992. if (sclk > golden_dpm_table->sclk_table.dpm_levels[golden_dpm_table->sclk_table.count-1].value) {
  2993. clock_percent =
  2994. ((sclk
  2995. - golden_dpm_table->sclk_table.dpm_levels[golden_dpm_table->sclk_table.count-1].value
  2996. ) * 100)
  2997. / golden_dpm_table->sclk_table.dpm_levels[golden_dpm_table->sclk_table.count-1].value;
  2998. dpm_table->sclk_table.dpm_levels[i].value =
  2999. golden_dpm_table->sclk_table.dpm_levels[i].value +
  3000. (golden_dpm_table->sclk_table.dpm_levels[i].value *
  3001. clock_percent)/100;
  3002. } else if (golden_dpm_table->sclk_table.dpm_levels[dpm_table->sclk_table.count-1].value > sclk) {
  3003. clock_percent =
  3004. ((golden_dpm_table->sclk_table.dpm_levels[golden_dpm_table->sclk_table.count - 1].value
  3005. - sclk) * 100)
  3006. / golden_dpm_table->sclk_table.dpm_levels[golden_dpm_table->sclk_table.count-1].value;
  3007. dpm_table->sclk_table.dpm_levels[i].value =
  3008. golden_dpm_table->sclk_table.dpm_levels[i].value -
  3009. (golden_dpm_table->sclk_table.dpm_levels[i].value *
  3010. clock_percent) / 100;
  3011. } else
  3012. dpm_table->sclk_table.dpm_levels[i].value =
  3013. golden_dpm_table->sclk_table.dpm_levels[i].value;
  3014. }
  3015. }
  3016. }
  3017. if (data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_MCLK) {
  3018. dpm_table->mclk_table.dpm_levels
  3019. [dpm_table->mclk_table.count - 1].value = mclk;
  3020. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_OD6PlusinACSupport) ||
  3021. phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_OD6PlusinDCSupport)) {
  3022. PP_ASSERT_WITH_CODE(
  3023. (golden_dpm_table->mclk_table.dpm_levels
  3024. [golden_dpm_table->mclk_table.count-1].value != 0),
  3025. "Divide by 0!",
  3026. return -EINVAL);
  3027. dpm_count = dpm_table->mclk_table.count < 2 ? 0 : dpm_table->mclk_table.count - 2;
  3028. for (i = dpm_count; i > 1; i--) {
  3029. if (golden_dpm_table->mclk_table.dpm_levels[golden_dpm_table->mclk_table.count-1].value < mclk) {
  3030. clock_percent = ((mclk -
  3031. golden_dpm_table->mclk_table.dpm_levels[golden_dpm_table->mclk_table.count-1].value) * 100)
  3032. / golden_dpm_table->mclk_table.dpm_levels[golden_dpm_table->mclk_table.count-1].value;
  3033. dpm_table->mclk_table.dpm_levels[i].value =
  3034. golden_dpm_table->mclk_table.dpm_levels[i].value +
  3035. (golden_dpm_table->mclk_table.dpm_levels[i].value *
  3036. clock_percent) / 100;
  3037. } else if (golden_dpm_table->mclk_table.dpm_levels[dpm_table->mclk_table.count-1].value > mclk) {
  3038. clock_percent = (
  3039. (golden_dpm_table->mclk_table.dpm_levels[golden_dpm_table->mclk_table.count-1].value - mclk)
  3040. * 100)
  3041. / golden_dpm_table->mclk_table.dpm_levels[golden_dpm_table->mclk_table.count-1].value;
  3042. dpm_table->mclk_table.dpm_levels[i].value =
  3043. golden_dpm_table->mclk_table.dpm_levels[i].value -
  3044. (golden_dpm_table->mclk_table.dpm_levels[i].value *
  3045. clock_percent) / 100;
  3046. } else
  3047. dpm_table->mclk_table.dpm_levels[i].value =
  3048. golden_dpm_table->mclk_table.dpm_levels[i].value;
  3049. }
  3050. }
  3051. }
  3052. if (data->need_update_smu7_dpm_table &
  3053. (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_UPDATE_SCLK)) {
  3054. result = smum_populate_all_graphic_levels(hwmgr);
  3055. PP_ASSERT_WITH_CODE((0 == result),
  3056. "Failed to populate SCLK during PopulateNewDPMClocksStates Function!",
  3057. return result);
  3058. }
  3059. if (data->need_update_smu7_dpm_table &
  3060. (DPMTABLE_OD_UPDATE_MCLK + DPMTABLE_UPDATE_MCLK)) {
  3061. /*populate MCLK dpm table to SMU7 */
  3062. result = smum_populate_all_memory_levels(hwmgr);
  3063. PP_ASSERT_WITH_CODE((0 == result),
  3064. "Failed to populate MCLK during PopulateNewDPMClocksStates Function!",
  3065. return result);
  3066. }
  3067. return result;
  3068. }
  3069. static int smu7_trim_single_dpm_states(struct pp_hwmgr *hwmgr,
  3070. struct smu7_single_dpm_table *dpm_table,
  3071. uint32_t low_limit, uint32_t high_limit)
  3072. {
  3073. uint32_t i;
  3074. for (i = 0; i < dpm_table->count; i++) {
  3075. if ((dpm_table->dpm_levels[i].value < low_limit)
  3076. || (dpm_table->dpm_levels[i].value > high_limit))
  3077. dpm_table->dpm_levels[i].enabled = false;
  3078. else
  3079. dpm_table->dpm_levels[i].enabled = true;
  3080. }
  3081. return 0;
  3082. }
  3083. static int smu7_trim_dpm_states(struct pp_hwmgr *hwmgr,
  3084. const struct smu7_power_state *smu7_ps)
  3085. {
  3086. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  3087. uint32_t high_limit_count;
  3088. PP_ASSERT_WITH_CODE((smu7_ps->performance_level_count >= 1),
  3089. "power state did not have any performance level",
  3090. return -EINVAL);
  3091. high_limit_count = (1 == smu7_ps->performance_level_count) ? 0 : 1;
  3092. smu7_trim_single_dpm_states(hwmgr,
  3093. &(data->dpm_table.sclk_table),
  3094. smu7_ps->performance_levels[0].engine_clock,
  3095. smu7_ps->performance_levels[high_limit_count].engine_clock);
  3096. smu7_trim_single_dpm_states(hwmgr,
  3097. &(data->dpm_table.mclk_table),
  3098. smu7_ps->performance_levels[0].memory_clock,
  3099. smu7_ps->performance_levels[high_limit_count].memory_clock);
  3100. return 0;
  3101. }
  3102. static int smu7_generate_dpm_level_enable_mask(
  3103. struct pp_hwmgr *hwmgr, const void *input)
  3104. {
  3105. int result;
  3106. const struct phm_set_power_state_input *states =
  3107. (const struct phm_set_power_state_input *)input;
  3108. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  3109. const struct smu7_power_state *smu7_ps =
  3110. cast_const_phw_smu7_power_state(states->pnew_state);
  3111. result = smu7_trim_dpm_states(hwmgr, smu7_ps);
  3112. if (result)
  3113. return result;
  3114. data->dpm_level_enable_mask.sclk_dpm_enable_mask =
  3115. phm_get_dpm_level_enable_mask_value(&data->dpm_table.sclk_table);
  3116. data->dpm_level_enable_mask.mclk_dpm_enable_mask =
  3117. phm_get_dpm_level_enable_mask_value(&data->dpm_table.mclk_table);
  3118. data->dpm_level_enable_mask.pcie_dpm_enable_mask =
  3119. phm_get_dpm_level_enable_mask_value(&data->dpm_table.pcie_speed_table);
  3120. return 0;
  3121. }
  3122. static int smu7_unfreeze_sclk_mclk_dpm(struct pp_hwmgr *hwmgr)
  3123. {
  3124. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  3125. if (0 == data->need_update_smu7_dpm_table)
  3126. return 0;
  3127. if ((0 == data->sclk_dpm_key_disabled) &&
  3128. (data->need_update_smu7_dpm_table &
  3129. (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_UPDATE_SCLK))) {
  3130. PP_ASSERT_WITH_CODE(true == smum_is_dpm_running(hwmgr),
  3131. "Trying to Unfreeze SCLK DPM when DPM is disabled",
  3132. );
  3133. PP_ASSERT_WITH_CODE(0 == smum_send_msg_to_smc(hwmgr->smumgr,
  3134. PPSMC_MSG_SCLKDPM_UnfreezeLevel),
  3135. "Failed to unfreeze SCLK DPM during UnFreezeSclkMclkDPM Function!",
  3136. return -EINVAL);
  3137. }
  3138. if ((0 == data->mclk_dpm_key_disabled) &&
  3139. (data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_MCLK)) {
  3140. PP_ASSERT_WITH_CODE(true == smum_is_dpm_running(hwmgr),
  3141. "Trying to Unfreeze MCLK DPM when DPM is disabled",
  3142. );
  3143. PP_ASSERT_WITH_CODE(0 == smum_send_msg_to_smc(hwmgr->smumgr,
  3144. PPSMC_MSG_SCLKDPM_UnfreezeLevel),
  3145. "Failed to unfreeze MCLK DPM during UnFreezeSclkMclkDPM Function!",
  3146. return -EINVAL);
  3147. }
  3148. data->need_update_smu7_dpm_table = 0;
  3149. return 0;
  3150. }
  3151. static int smu7_notify_link_speed_change_after_state_change(
  3152. struct pp_hwmgr *hwmgr, const void *input)
  3153. {
  3154. const struct phm_set_power_state_input *states =
  3155. (const struct phm_set_power_state_input *)input;
  3156. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  3157. const struct smu7_power_state *smu7_ps =
  3158. cast_const_phw_smu7_power_state(states->pnew_state);
  3159. uint16_t target_link_speed = smu7_get_maximum_link_speed(hwmgr, smu7_ps);
  3160. uint8_t request;
  3161. if (data->pspp_notify_required) {
  3162. if (target_link_speed == PP_PCIEGen3)
  3163. request = PCIE_PERF_REQ_GEN3;
  3164. else if (target_link_speed == PP_PCIEGen2)
  3165. request = PCIE_PERF_REQ_GEN2;
  3166. else
  3167. request = PCIE_PERF_REQ_GEN1;
  3168. if (request == PCIE_PERF_REQ_GEN1 &&
  3169. smu7_get_current_pcie_speed(hwmgr) > 0)
  3170. return 0;
  3171. if (acpi_pcie_perf_request(hwmgr->device, request, false)) {
  3172. if (PP_PCIEGen2 == target_link_speed)
  3173. pr_info("PSPP request to switch to Gen2 from Gen3 Failed!");
  3174. else
  3175. pr_info("PSPP request to switch to Gen1 from Gen2 Failed!");
  3176. }
  3177. }
  3178. return 0;
  3179. }
  3180. static int smu7_notify_smc_display(struct pp_hwmgr *hwmgr)
  3181. {
  3182. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  3183. if (hwmgr->feature_mask & PP_VBI_TIME_SUPPORT_MASK)
  3184. smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
  3185. (PPSMC_Msg)PPSMC_MSG_SetVBITimeout, data->frame_time_x2);
  3186. return (smum_send_msg_to_smc(hwmgr->smumgr, (PPSMC_Msg)PPSMC_HasDisplay) == 0) ? 0 : -EINVAL;
  3187. }
  3188. static int smu7_set_power_state_tasks(struct pp_hwmgr *hwmgr, const void *input)
  3189. {
  3190. int tmp_result, result = 0;
  3191. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  3192. tmp_result = smu7_find_dpm_states_clocks_in_dpm_table(hwmgr, input);
  3193. PP_ASSERT_WITH_CODE((0 == tmp_result),
  3194. "Failed to find DPM states clocks in DPM table!",
  3195. result = tmp_result);
  3196. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  3197. PHM_PlatformCaps_PCIEPerformanceRequest)) {
  3198. tmp_result =
  3199. smu7_request_link_speed_change_before_state_change(hwmgr, input);
  3200. PP_ASSERT_WITH_CODE((0 == tmp_result),
  3201. "Failed to request link speed change before state change!",
  3202. result = tmp_result);
  3203. }
  3204. tmp_result = smu7_freeze_sclk_mclk_dpm(hwmgr);
  3205. PP_ASSERT_WITH_CODE((0 == tmp_result),
  3206. "Failed to freeze SCLK MCLK DPM!", result = tmp_result);
  3207. tmp_result = smu7_populate_and_upload_sclk_mclk_dpm_levels(hwmgr, input);
  3208. PP_ASSERT_WITH_CODE((0 == tmp_result),
  3209. "Failed to populate and upload SCLK MCLK DPM levels!",
  3210. result = tmp_result);
  3211. tmp_result = smu7_generate_dpm_level_enable_mask(hwmgr, input);
  3212. PP_ASSERT_WITH_CODE((0 == tmp_result),
  3213. "Failed to generate DPM level enabled mask!",
  3214. result = tmp_result);
  3215. tmp_result = smum_update_sclk_threshold(hwmgr);
  3216. PP_ASSERT_WITH_CODE((0 == tmp_result),
  3217. "Failed to update SCLK threshold!",
  3218. result = tmp_result);
  3219. tmp_result = smu7_notify_smc_display(hwmgr);
  3220. PP_ASSERT_WITH_CODE((0 == tmp_result),
  3221. "Failed to notify smc display settings!",
  3222. result = tmp_result);
  3223. tmp_result = smu7_unfreeze_sclk_mclk_dpm(hwmgr);
  3224. PP_ASSERT_WITH_CODE((0 == tmp_result),
  3225. "Failed to unfreeze SCLK MCLK DPM!",
  3226. result = tmp_result);
  3227. tmp_result = smu7_upload_dpm_level_enable_mask(hwmgr);
  3228. PP_ASSERT_WITH_CODE((0 == tmp_result),
  3229. "Failed to upload DPM level enabled mask!",
  3230. result = tmp_result);
  3231. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  3232. PHM_PlatformCaps_PCIEPerformanceRequest)) {
  3233. tmp_result =
  3234. smu7_notify_link_speed_change_after_state_change(hwmgr, input);
  3235. PP_ASSERT_WITH_CODE((0 == tmp_result),
  3236. "Failed to notify link speed change after state change!",
  3237. result = tmp_result);
  3238. }
  3239. data->apply_optimized_settings = false;
  3240. return result;
  3241. }
  3242. static int smu7_set_max_fan_pwm_output(struct pp_hwmgr *hwmgr, uint16_t us_max_fan_pwm)
  3243. {
  3244. hwmgr->thermal_controller.
  3245. advanceFanControlParameters.usMaxFanPWM = us_max_fan_pwm;
  3246. if (phm_is_hw_access_blocked(hwmgr))
  3247. return 0;
  3248. return smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
  3249. PPSMC_MSG_SetFanPwmMax, us_max_fan_pwm);
  3250. }
  3251. static int
  3252. smu7_notify_smc_display_change(struct pp_hwmgr *hwmgr, bool has_display)
  3253. {
  3254. PPSMC_Msg msg = has_display ? (PPSMC_Msg)PPSMC_HasDisplay : (PPSMC_Msg)PPSMC_NoDisplay;
  3255. return (smum_send_msg_to_smc(hwmgr->smumgr, msg) == 0) ? 0 : -1;
  3256. }
  3257. static int
  3258. smu7_notify_smc_display_config_after_ps_adjustment(struct pp_hwmgr *hwmgr)
  3259. {
  3260. uint32_t num_active_displays = 0;
  3261. struct cgs_display_info info = {0};
  3262. info.mode_info = NULL;
  3263. cgs_get_active_displays_info(hwmgr->device, &info);
  3264. num_active_displays = info.display_count;
  3265. if (num_active_displays > 1 && hwmgr->display_config.multi_monitor_in_sync != true)
  3266. smu7_notify_smc_display_change(hwmgr, false);
  3267. return 0;
  3268. }
  3269. /**
  3270. * Programs the display gap
  3271. *
  3272. * @param hwmgr the address of the powerplay hardware manager.
  3273. * @return always OK
  3274. */
  3275. static int smu7_program_display_gap(struct pp_hwmgr *hwmgr)
  3276. {
  3277. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  3278. uint32_t num_active_displays = 0;
  3279. uint32_t display_gap = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_DISPLAY_GAP_CNTL);
  3280. uint32_t display_gap2;
  3281. uint32_t pre_vbi_time_in_us;
  3282. uint32_t frame_time_in_us;
  3283. uint32_t ref_clock;
  3284. uint32_t refresh_rate = 0;
  3285. struct cgs_display_info info = {0};
  3286. struct cgs_mode_info mode_info;
  3287. info.mode_info = &mode_info;
  3288. cgs_get_active_displays_info(hwmgr->device, &info);
  3289. num_active_displays = info.display_count;
  3290. display_gap = PHM_SET_FIELD(display_gap, CG_DISPLAY_GAP_CNTL, DISP_GAP, (num_active_displays > 0) ? DISPLAY_GAP_VBLANK_OR_WM : DISPLAY_GAP_IGNORE);
  3291. cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_DISPLAY_GAP_CNTL, display_gap);
  3292. ref_clock = mode_info.ref_clock;
  3293. refresh_rate = mode_info.refresh_rate;
  3294. if (0 == refresh_rate)
  3295. refresh_rate = 60;
  3296. frame_time_in_us = 1000000 / refresh_rate;
  3297. pre_vbi_time_in_us = frame_time_in_us - 200 - mode_info.vblank_time_us;
  3298. data->frame_time_x2 = frame_time_in_us * 2 / 100;
  3299. display_gap2 = pre_vbi_time_in_us * (ref_clock / 100);
  3300. cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_DISPLAY_GAP_CNTL2, display_gap2);
  3301. cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
  3302. data->soft_regs_start + smum_get_offsetof(hwmgr->smumgr,
  3303. SMU_SoftRegisters,
  3304. PreVBlankGap), 0x64);
  3305. cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
  3306. data->soft_regs_start + smum_get_offsetof(hwmgr->smumgr,
  3307. SMU_SoftRegisters,
  3308. VBlankTimeout),
  3309. (frame_time_in_us - pre_vbi_time_in_us));
  3310. return 0;
  3311. }
  3312. static int smu7_display_configuration_changed_task(struct pp_hwmgr *hwmgr)
  3313. {
  3314. return smu7_program_display_gap(hwmgr);
  3315. }
  3316. /**
  3317. * Set maximum target operating fan output RPM
  3318. *
  3319. * @param hwmgr: the address of the powerplay hardware manager.
  3320. * @param usMaxFanRpm: max operating fan RPM value.
  3321. * @return The response that came from the SMC.
  3322. */
  3323. static int smu7_set_max_fan_rpm_output(struct pp_hwmgr *hwmgr, uint16_t us_max_fan_rpm)
  3324. {
  3325. hwmgr->thermal_controller.
  3326. advanceFanControlParameters.usMaxFanRPM = us_max_fan_rpm;
  3327. if (phm_is_hw_access_blocked(hwmgr))
  3328. return 0;
  3329. return smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
  3330. PPSMC_MSG_SetFanRpmMax, us_max_fan_rpm);
  3331. }
  3332. static int smu7_register_internal_thermal_interrupt(struct pp_hwmgr *hwmgr,
  3333. const void *thermal_interrupt_info)
  3334. {
  3335. return 0;
  3336. }
  3337. static bool
  3338. smu7_check_smc_update_required_for_display_configuration(struct pp_hwmgr *hwmgr)
  3339. {
  3340. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  3341. bool is_update_required = false;
  3342. struct cgs_display_info info = {0, 0, NULL};
  3343. cgs_get_active_displays_info(hwmgr->device, &info);
  3344. if (data->display_timing.num_existing_displays != info.display_count)
  3345. is_update_required = true;
  3346. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_SclkDeepSleep)) {
  3347. if (data->display_timing.min_clock_in_sr != hwmgr->display_config.min_core_set_clock_in_sr &&
  3348. (data->display_timing.min_clock_in_sr >= SMU7_MINIMUM_ENGINE_CLOCK ||
  3349. hwmgr->display_config.min_core_set_clock_in_sr >= SMU7_MINIMUM_ENGINE_CLOCK))
  3350. is_update_required = true;
  3351. }
  3352. return is_update_required;
  3353. }
  3354. static inline bool smu7_are_power_levels_equal(const struct smu7_performance_level *pl1,
  3355. const struct smu7_performance_level *pl2)
  3356. {
  3357. return ((pl1->memory_clock == pl2->memory_clock) &&
  3358. (pl1->engine_clock == pl2->engine_clock) &&
  3359. (pl1->pcie_gen == pl2->pcie_gen) &&
  3360. (pl1->pcie_lane == pl2->pcie_lane));
  3361. }
  3362. static int smu7_check_states_equal(struct pp_hwmgr *hwmgr,
  3363. const struct pp_hw_power_state *pstate1,
  3364. const struct pp_hw_power_state *pstate2, bool *equal)
  3365. {
  3366. const struct smu7_power_state *psa;
  3367. const struct smu7_power_state *psb;
  3368. int i;
  3369. if (pstate1 == NULL || pstate2 == NULL || equal == NULL)
  3370. return -EINVAL;
  3371. psa = cast_const_phw_smu7_power_state(pstate1);
  3372. psb = cast_const_phw_smu7_power_state(pstate2);
  3373. /* If the two states don't even have the same number of performance levels they cannot be the same state. */
  3374. if (psa->performance_level_count != psb->performance_level_count) {
  3375. *equal = false;
  3376. return 0;
  3377. }
  3378. for (i = 0; i < psa->performance_level_count; i++) {
  3379. if (!smu7_are_power_levels_equal(&(psa->performance_levels[i]), &(psb->performance_levels[i]))) {
  3380. /* If we have found even one performance level pair that is different the states are different. */
  3381. *equal = false;
  3382. return 0;
  3383. }
  3384. }
  3385. /* If all performance levels are the same try to use the UVD clocks to break the tie.*/
  3386. *equal = ((psa->uvd_clks.vclk == psb->uvd_clks.vclk) && (psa->uvd_clks.dclk == psb->uvd_clks.dclk));
  3387. *equal &= ((psa->vce_clks.evclk == psb->vce_clks.evclk) && (psa->vce_clks.ecclk == psb->vce_clks.ecclk));
  3388. *equal &= (psa->sclk_threshold == psb->sclk_threshold);
  3389. return 0;
  3390. }
  3391. static int smu7_upload_mc_firmware(struct pp_hwmgr *hwmgr)
  3392. {
  3393. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  3394. uint32_t vbios_version;
  3395. uint32_t tmp;
  3396. /* Read MC indirect register offset 0x9F bits [3:0] to see
  3397. * if VBIOS has already loaded a full version of MC ucode
  3398. * or not.
  3399. */
  3400. smu7_get_mc_microcode_version(hwmgr);
  3401. vbios_version = hwmgr->microcode_version_info.MC & 0xf;
  3402. data->need_long_memory_training = false;
  3403. cgs_write_register(hwmgr->device, mmMC_SEQ_IO_DEBUG_INDEX,
  3404. ixMC_IO_DEBUG_UP_13);
  3405. tmp = cgs_read_register(hwmgr->device, mmMC_SEQ_IO_DEBUG_DATA);
  3406. if (tmp & (1 << 23)) {
  3407. data->mem_latency_high = MEM_LATENCY_HIGH;
  3408. data->mem_latency_low = MEM_LATENCY_LOW;
  3409. } else {
  3410. data->mem_latency_high = 330;
  3411. data->mem_latency_low = 330;
  3412. }
  3413. return 0;
  3414. }
  3415. static int smu7_read_clock_registers(struct pp_hwmgr *hwmgr)
  3416. {
  3417. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  3418. data->clock_registers.vCG_SPLL_FUNC_CNTL =
  3419. cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_SPLL_FUNC_CNTL);
  3420. data->clock_registers.vCG_SPLL_FUNC_CNTL_2 =
  3421. cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_SPLL_FUNC_CNTL_2);
  3422. data->clock_registers.vCG_SPLL_FUNC_CNTL_3 =
  3423. cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_SPLL_FUNC_CNTL_3);
  3424. data->clock_registers.vCG_SPLL_FUNC_CNTL_4 =
  3425. cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_SPLL_FUNC_CNTL_4);
  3426. data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM =
  3427. cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_SPLL_SPREAD_SPECTRUM);
  3428. data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM_2 =
  3429. cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_SPLL_SPREAD_SPECTRUM_2);
  3430. data->clock_registers.vDLL_CNTL =
  3431. cgs_read_register(hwmgr->device, mmDLL_CNTL);
  3432. data->clock_registers.vMCLK_PWRMGT_CNTL =
  3433. cgs_read_register(hwmgr->device, mmMCLK_PWRMGT_CNTL);
  3434. data->clock_registers.vMPLL_AD_FUNC_CNTL =
  3435. cgs_read_register(hwmgr->device, mmMPLL_AD_FUNC_CNTL);
  3436. data->clock_registers.vMPLL_DQ_FUNC_CNTL =
  3437. cgs_read_register(hwmgr->device, mmMPLL_DQ_FUNC_CNTL);
  3438. data->clock_registers.vMPLL_FUNC_CNTL =
  3439. cgs_read_register(hwmgr->device, mmMPLL_FUNC_CNTL);
  3440. data->clock_registers.vMPLL_FUNC_CNTL_1 =
  3441. cgs_read_register(hwmgr->device, mmMPLL_FUNC_CNTL_1);
  3442. data->clock_registers.vMPLL_FUNC_CNTL_2 =
  3443. cgs_read_register(hwmgr->device, mmMPLL_FUNC_CNTL_2);
  3444. data->clock_registers.vMPLL_SS1 =
  3445. cgs_read_register(hwmgr->device, mmMPLL_SS1);
  3446. data->clock_registers.vMPLL_SS2 =
  3447. cgs_read_register(hwmgr->device, mmMPLL_SS2);
  3448. return 0;
  3449. }
  3450. /**
  3451. * Find out if memory is GDDR5.
  3452. *
  3453. * @param hwmgr the address of the powerplay hardware manager.
  3454. * @return always 0
  3455. */
  3456. static int smu7_get_memory_type(struct pp_hwmgr *hwmgr)
  3457. {
  3458. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  3459. uint32_t temp;
  3460. temp = cgs_read_register(hwmgr->device, mmMC_SEQ_MISC0);
  3461. data->is_memory_gddr5 = (MC_SEQ_MISC0_GDDR5_VALUE ==
  3462. ((temp & MC_SEQ_MISC0_GDDR5_MASK) >>
  3463. MC_SEQ_MISC0_GDDR5_SHIFT));
  3464. return 0;
  3465. }
  3466. /**
  3467. * Enables Dynamic Power Management by SMC
  3468. *
  3469. * @param hwmgr the address of the powerplay hardware manager.
  3470. * @return always 0
  3471. */
  3472. static int smu7_enable_acpi_power_management(struct pp_hwmgr *hwmgr)
  3473. {
  3474. PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
  3475. GENERAL_PWRMGT, STATIC_PM_EN, 1);
  3476. return 0;
  3477. }
  3478. /**
  3479. * Initialize PowerGating States for different engines
  3480. *
  3481. * @param hwmgr the address of the powerplay hardware manager.
  3482. * @return always 0
  3483. */
  3484. static int smu7_init_power_gate_state(struct pp_hwmgr *hwmgr)
  3485. {
  3486. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  3487. data->uvd_power_gated = false;
  3488. data->vce_power_gated = false;
  3489. data->samu_power_gated = false;
  3490. return 0;
  3491. }
  3492. static int smu7_init_sclk_threshold(struct pp_hwmgr *hwmgr)
  3493. {
  3494. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  3495. data->low_sclk_interrupt_threshold = 0;
  3496. return 0;
  3497. }
  3498. static int smu7_setup_asic_task(struct pp_hwmgr *hwmgr)
  3499. {
  3500. int tmp_result, result = 0;
  3501. smu7_upload_mc_firmware(hwmgr);
  3502. tmp_result = smu7_read_clock_registers(hwmgr);
  3503. PP_ASSERT_WITH_CODE((0 == tmp_result),
  3504. "Failed to read clock registers!", result = tmp_result);
  3505. tmp_result = smu7_get_memory_type(hwmgr);
  3506. PP_ASSERT_WITH_CODE((0 == tmp_result),
  3507. "Failed to get memory type!", result = tmp_result);
  3508. tmp_result = smu7_enable_acpi_power_management(hwmgr);
  3509. PP_ASSERT_WITH_CODE((0 == tmp_result),
  3510. "Failed to enable ACPI power management!", result = tmp_result);
  3511. tmp_result = smu7_init_power_gate_state(hwmgr);
  3512. PP_ASSERT_WITH_CODE((0 == tmp_result),
  3513. "Failed to init power gate state!", result = tmp_result);
  3514. tmp_result = smu7_get_mc_microcode_version(hwmgr);
  3515. PP_ASSERT_WITH_CODE((0 == tmp_result),
  3516. "Failed to get MC microcode version!", result = tmp_result);
  3517. tmp_result = smu7_init_sclk_threshold(hwmgr);
  3518. PP_ASSERT_WITH_CODE((0 == tmp_result),
  3519. "Failed to init sclk threshold!", result = tmp_result);
  3520. return result;
  3521. }
  3522. static int smu7_force_clock_level(struct pp_hwmgr *hwmgr,
  3523. enum pp_clock_type type, uint32_t mask)
  3524. {
  3525. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  3526. if (hwmgr->dpm_level & (AMD_DPM_FORCED_LEVEL_AUTO |
  3527. AMD_DPM_FORCED_LEVEL_LOW |
  3528. AMD_DPM_FORCED_LEVEL_HIGH))
  3529. return -EINVAL;
  3530. switch (type) {
  3531. case PP_SCLK:
  3532. if (!data->sclk_dpm_key_disabled)
  3533. smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
  3534. PPSMC_MSG_SCLKDPM_SetEnabledMask,
  3535. data->dpm_level_enable_mask.sclk_dpm_enable_mask & mask);
  3536. break;
  3537. case PP_MCLK:
  3538. if (!data->mclk_dpm_key_disabled)
  3539. smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
  3540. PPSMC_MSG_MCLKDPM_SetEnabledMask,
  3541. data->dpm_level_enable_mask.mclk_dpm_enable_mask & mask);
  3542. break;
  3543. case PP_PCIE:
  3544. {
  3545. uint32_t tmp = mask & data->dpm_level_enable_mask.pcie_dpm_enable_mask;
  3546. uint32_t level = 0;
  3547. while (tmp >>= 1)
  3548. level++;
  3549. if (!data->pcie_dpm_key_disabled)
  3550. smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
  3551. PPSMC_MSG_PCIeDPM_ForceLevel,
  3552. level);
  3553. break;
  3554. }
  3555. default:
  3556. break;
  3557. }
  3558. return 0;
  3559. }
  3560. static int smu7_print_clock_levels(struct pp_hwmgr *hwmgr,
  3561. enum pp_clock_type type, char *buf)
  3562. {
  3563. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  3564. struct smu7_single_dpm_table *sclk_table = &(data->dpm_table.sclk_table);
  3565. struct smu7_single_dpm_table *mclk_table = &(data->dpm_table.mclk_table);
  3566. struct smu7_single_dpm_table *pcie_table = &(data->dpm_table.pcie_speed_table);
  3567. int i, now, size = 0;
  3568. uint32_t clock, pcie_speed;
  3569. switch (type) {
  3570. case PP_SCLK:
  3571. smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_API_GetSclkFrequency);
  3572. clock = cgs_read_register(hwmgr->device, mmSMC_MSG_ARG_0);
  3573. for (i = 0; i < sclk_table->count; i++) {
  3574. if (clock > sclk_table->dpm_levels[i].value)
  3575. continue;
  3576. break;
  3577. }
  3578. now = i;
  3579. for (i = 0; i < sclk_table->count; i++)
  3580. size += sprintf(buf + size, "%d: %uMhz %s\n",
  3581. i, sclk_table->dpm_levels[i].value / 100,
  3582. (i == now) ? "*" : "");
  3583. break;
  3584. case PP_MCLK:
  3585. smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_API_GetMclkFrequency);
  3586. clock = cgs_read_register(hwmgr->device, mmSMC_MSG_ARG_0);
  3587. for (i = 0; i < mclk_table->count; i++) {
  3588. if (clock > mclk_table->dpm_levels[i].value)
  3589. continue;
  3590. break;
  3591. }
  3592. now = i;
  3593. for (i = 0; i < mclk_table->count; i++)
  3594. size += sprintf(buf + size, "%d: %uMhz %s\n",
  3595. i, mclk_table->dpm_levels[i].value / 100,
  3596. (i == now) ? "*" : "");
  3597. break;
  3598. case PP_PCIE:
  3599. pcie_speed = smu7_get_current_pcie_speed(hwmgr);
  3600. for (i = 0; i < pcie_table->count; i++) {
  3601. if (pcie_speed != pcie_table->dpm_levels[i].value)
  3602. continue;
  3603. break;
  3604. }
  3605. now = i;
  3606. for (i = 0; i < pcie_table->count; i++)
  3607. size += sprintf(buf + size, "%d: %s %s\n", i,
  3608. (pcie_table->dpm_levels[i].value == 0) ? "2.5GB, x8" :
  3609. (pcie_table->dpm_levels[i].value == 1) ? "5.0GB, x16" :
  3610. (pcie_table->dpm_levels[i].value == 2) ? "8.0GB, x16" : "",
  3611. (i == now) ? "*" : "");
  3612. break;
  3613. default:
  3614. break;
  3615. }
  3616. return size;
  3617. }
  3618. static int smu7_set_fan_control_mode(struct pp_hwmgr *hwmgr, uint32_t mode)
  3619. {
  3620. int result = 0;
  3621. switch (mode) {
  3622. case AMD_FAN_CTRL_NONE:
  3623. result = smu7_fan_ctrl_set_fan_speed_percent(hwmgr, 100);
  3624. break;
  3625. case AMD_FAN_CTRL_MANUAL:
  3626. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  3627. PHM_PlatformCaps_MicrocodeFanControl))
  3628. result = smu7_fan_ctrl_stop_smc_fan_control(hwmgr);
  3629. break;
  3630. case AMD_FAN_CTRL_AUTO:
  3631. result = smu7_fan_ctrl_set_static_mode(hwmgr, mode);
  3632. if (!result)
  3633. result = smu7_fan_ctrl_start_smc_fan_control(hwmgr);
  3634. break;
  3635. default:
  3636. break;
  3637. }
  3638. return result;
  3639. }
  3640. static int smu7_get_fan_control_mode(struct pp_hwmgr *hwmgr)
  3641. {
  3642. return hwmgr->fan_ctrl_enabled ? AMD_FAN_CTRL_AUTO : AMD_FAN_CTRL_MANUAL;
  3643. }
  3644. static int smu7_get_sclk_od(struct pp_hwmgr *hwmgr)
  3645. {
  3646. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  3647. struct smu7_single_dpm_table *sclk_table = &(data->dpm_table.sclk_table);
  3648. struct smu7_single_dpm_table *golden_sclk_table =
  3649. &(data->golden_dpm_table.sclk_table);
  3650. int value;
  3651. value = (sclk_table->dpm_levels[sclk_table->count - 1].value -
  3652. golden_sclk_table->dpm_levels[golden_sclk_table->count - 1].value) *
  3653. 100 /
  3654. golden_sclk_table->dpm_levels[golden_sclk_table->count - 1].value;
  3655. return value;
  3656. }
  3657. static int smu7_set_sclk_od(struct pp_hwmgr *hwmgr, uint32_t value)
  3658. {
  3659. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  3660. struct smu7_single_dpm_table *golden_sclk_table =
  3661. &(data->golden_dpm_table.sclk_table);
  3662. struct pp_power_state *ps;
  3663. struct smu7_power_state *smu7_ps;
  3664. if (value > 20)
  3665. value = 20;
  3666. ps = hwmgr->request_ps;
  3667. if (ps == NULL)
  3668. return -EINVAL;
  3669. smu7_ps = cast_phw_smu7_power_state(&ps->hardware);
  3670. smu7_ps->performance_levels[smu7_ps->performance_level_count - 1].engine_clock =
  3671. golden_sclk_table->dpm_levels[golden_sclk_table->count - 1].value *
  3672. value / 100 +
  3673. golden_sclk_table->dpm_levels[golden_sclk_table->count - 1].value;
  3674. return 0;
  3675. }
  3676. static int smu7_get_mclk_od(struct pp_hwmgr *hwmgr)
  3677. {
  3678. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  3679. struct smu7_single_dpm_table *mclk_table = &(data->dpm_table.mclk_table);
  3680. struct smu7_single_dpm_table *golden_mclk_table =
  3681. &(data->golden_dpm_table.mclk_table);
  3682. int value;
  3683. value = (mclk_table->dpm_levels[mclk_table->count - 1].value -
  3684. golden_mclk_table->dpm_levels[golden_mclk_table->count - 1].value) *
  3685. 100 /
  3686. golden_mclk_table->dpm_levels[golden_mclk_table->count - 1].value;
  3687. return value;
  3688. }
  3689. static int smu7_set_mclk_od(struct pp_hwmgr *hwmgr, uint32_t value)
  3690. {
  3691. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  3692. struct smu7_single_dpm_table *golden_mclk_table =
  3693. &(data->golden_dpm_table.mclk_table);
  3694. struct pp_power_state *ps;
  3695. struct smu7_power_state *smu7_ps;
  3696. if (value > 20)
  3697. value = 20;
  3698. ps = hwmgr->request_ps;
  3699. if (ps == NULL)
  3700. return -EINVAL;
  3701. smu7_ps = cast_phw_smu7_power_state(&ps->hardware);
  3702. smu7_ps->performance_levels[smu7_ps->performance_level_count - 1].memory_clock =
  3703. golden_mclk_table->dpm_levels[golden_mclk_table->count - 1].value *
  3704. value / 100 +
  3705. golden_mclk_table->dpm_levels[golden_mclk_table->count - 1].value;
  3706. return 0;
  3707. }
  3708. static int smu7_get_sclks(struct pp_hwmgr *hwmgr, struct amd_pp_clocks *clocks)
  3709. {
  3710. struct phm_ppt_v1_information *table_info =
  3711. (struct phm_ppt_v1_information *)hwmgr->pptable;
  3712. struct phm_ppt_v1_clock_voltage_dependency_table *dep_sclk_table = NULL;
  3713. struct phm_clock_voltage_dependency_table *sclk_table;
  3714. int i;
  3715. if (hwmgr->pp_table_version == PP_TABLE_V1) {
  3716. if (table_info == NULL || table_info->vdd_dep_on_sclk == NULL)
  3717. return -EINVAL;
  3718. dep_sclk_table = table_info->vdd_dep_on_sclk;
  3719. for (i = 0; i < dep_sclk_table->count; i++)
  3720. clocks->clock[i] = dep_sclk_table->entries[i].clk;
  3721. clocks->count = dep_sclk_table->count;
  3722. } else if (hwmgr->pp_table_version == PP_TABLE_V0) {
  3723. sclk_table = hwmgr->dyn_state.vddc_dependency_on_sclk;
  3724. for (i = 0; i < sclk_table->count; i++)
  3725. clocks->clock[i] = sclk_table->entries[i].clk;
  3726. clocks->count = sclk_table->count;
  3727. }
  3728. return 0;
  3729. }
  3730. static uint32_t smu7_get_mem_latency(struct pp_hwmgr *hwmgr, uint32_t clk)
  3731. {
  3732. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  3733. if (clk >= MEM_FREQ_LOW_LATENCY && clk < MEM_FREQ_HIGH_LATENCY)
  3734. return data->mem_latency_high;
  3735. else if (clk >= MEM_FREQ_HIGH_LATENCY)
  3736. return data->mem_latency_low;
  3737. else
  3738. return MEM_LATENCY_ERR;
  3739. }
  3740. static int smu7_get_mclks(struct pp_hwmgr *hwmgr, struct amd_pp_clocks *clocks)
  3741. {
  3742. struct phm_ppt_v1_information *table_info =
  3743. (struct phm_ppt_v1_information *)hwmgr->pptable;
  3744. struct phm_ppt_v1_clock_voltage_dependency_table *dep_mclk_table;
  3745. int i;
  3746. struct phm_clock_voltage_dependency_table *mclk_table;
  3747. if (hwmgr->pp_table_version == PP_TABLE_V1) {
  3748. if (table_info == NULL)
  3749. return -EINVAL;
  3750. dep_mclk_table = table_info->vdd_dep_on_mclk;
  3751. for (i = 0; i < dep_mclk_table->count; i++) {
  3752. clocks->clock[i] = dep_mclk_table->entries[i].clk;
  3753. clocks->latency[i] = smu7_get_mem_latency(hwmgr,
  3754. dep_mclk_table->entries[i].clk);
  3755. }
  3756. clocks->count = dep_mclk_table->count;
  3757. } else if (hwmgr->pp_table_version == PP_TABLE_V0) {
  3758. mclk_table = hwmgr->dyn_state.vddc_dependency_on_mclk;
  3759. for (i = 0; i < mclk_table->count; i++)
  3760. clocks->clock[i] = mclk_table->entries[i].clk;
  3761. clocks->count = mclk_table->count;
  3762. }
  3763. return 0;
  3764. }
  3765. static int smu7_get_clock_by_type(struct pp_hwmgr *hwmgr, enum amd_pp_clock_type type,
  3766. struct amd_pp_clocks *clocks)
  3767. {
  3768. switch (type) {
  3769. case amd_pp_sys_clock:
  3770. smu7_get_sclks(hwmgr, clocks);
  3771. break;
  3772. case amd_pp_mem_clock:
  3773. smu7_get_mclks(hwmgr, clocks);
  3774. break;
  3775. default:
  3776. return -EINVAL;
  3777. }
  3778. return 0;
  3779. }
  3780. static void smu7_find_min_clock_masks(struct pp_hwmgr *hwmgr,
  3781. uint32_t *sclk_mask, uint32_t *mclk_mask,
  3782. uint32_t min_sclk, uint32_t min_mclk)
  3783. {
  3784. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  3785. struct smu7_dpm_table *dpm_table = &(data->dpm_table);
  3786. uint32_t i;
  3787. for (i = 0; i < dpm_table->sclk_table.count; i++) {
  3788. if (dpm_table->sclk_table.dpm_levels[i].enabled &&
  3789. dpm_table->sclk_table.dpm_levels[i].value >= min_sclk)
  3790. *sclk_mask |= 1 << i;
  3791. }
  3792. for (i = 0; i < dpm_table->mclk_table.count; i++) {
  3793. if (dpm_table->mclk_table.dpm_levels[i].enabled &&
  3794. dpm_table->mclk_table.dpm_levels[i].value >= min_mclk)
  3795. *mclk_mask |= 1 << i;
  3796. }
  3797. }
  3798. static int smu7_set_power_profile_state(struct pp_hwmgr *hwmgr,
  3799. struct amd_pp_profile *request)
  3800. {
  3801. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  3802. int tmp_result, result = 0;
  3803. uint32_t sclk_mask = 0, mclk_mask = 0;
  3804. if (hwmgr->chip_id == CHIP_FIJI) {
  3805. if (request->type == AMD_PP_GFX_PROFILE)
  3806. smu7_enable_power_containment(hwmgr);
  3807. else if (request->type == AMD_PP_COMPUTE_PROFILE)
  3808. smu7_disable_power_containment(hwmgr);
  3809. }
  3810. if (hwmgr->dpm_level != AMD_DPM_FORCED_LEVEL_AUTO)
  3811. return -EINVAL;
  3812. tmp_result = smu7_freeze_sclk_mclk_dpm(hwmgr);
  3813. PP_ASSERT_WITH_CODE(!tmp_result,
  3814. "Failed to freeze SCLK MCLK DPM!",
  3815. result = tmp_result);
  3816. tmp_result = smum_populate_requested_graphic_levels(hwmgr, request);
  3817. PP_ASSERT_WITH_CODE(!tmp_result,
  3818. "Failed to populate requested graphic levels!",
  3819. result = tmp_result);
  3820. tmp_result = smu7_unfreeze_sclk_mclk_dpm(hwmgr);
  3821. PP_ASSERT_WITH_CODE(!tmp_result,
  3822. "Failed to unfreeze SCLK MCLK DPM!",
  3823. result = tmp_result);
  3824. smu7_find_min_clock_masks(hwmgr, &sclk_mask, &mclk_mask,
  3825. request->min_sclk, request->min_mclk);
  3826. if (sclk_mask) {
  3827. if (!data->sclk_dpm_key_disabled)
  3828. smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
  3829. PPSMC_MSG_SCLKDPM_SetEnabledMask,
  3830. data->dpm_level_enable_mask.
  3831. sclk_dpm_enable_mask &
  3832. sclk_mask);
  3833. }
  3834. if (mclk_mask) {
  3835. if (!data->mclk_dpm_key_disabled)
  3836. smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
  3837. PPSMC_MSG_MCLKDPM_SetEnabledMask,
  3838. data->dpm_level_enable_mask.
  3839. mclk_dpm_enable_mask &
  3840. mclk_mask);
  3841. }
  3842. return result;
  3843. }
  3844. static int smu7_avfs_control(struct pp_hwmgr *hwmgr, bool enable)
  3845. {
  3846. if (enable) {
  3847. if (!PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device,
  3848. CGS_IND_REG__SMC, FEATURE_STATUS, AVS_ON))
  3849. PP_ASSERT_WITH_CODE(!smum_send_msg_to_smc(
  3850. hwmgr->smumgr, PPSMC_MSG_EnableAvfs),
  3851. "Failed to enable AVFS!",
  3852. return -EINVAL);
  3853. } else if (PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device,
  3854. CGS_IND_REG__SMC, FEATURE_STATUS, AVS_ON))
  3855. PP_ASSERT_WITH_CODE(!smum_send_msg_to_smc(
  3856. hwmgr->smumgr, PPSMC_MSG_DisableAvfs),
  3857. "Failed to disable AVFS!",
  3858. return -EINVAL);
  3859. return 0;
  3860. }
  3861. static const struct pp_hwmgr_func smu7_hwmgr_funcs = {
  3862. .backend_init = &smu7_hwmgr_backend_init,
  3863. .backend_fini = &smu7_hwmgr_backend_fini,
  3864. .asic_setup = &smu7_setup_asic_task,
  3865. .dynamic_state_management_enable = &smu7_enable_dpm_tasks,
  3866. .apply_state_adjust_rules = smu7_apply_state_adjust_rules,
  3867. .force_dpm_level = &smu7_force_dpm_level,
  3868. .power_state_set = smu7_set_power_state_tasks,
  3869. .get_power_state_size = smu7_get_power_state_size,
  3870. .get_mclk = smu7_dpm_get_mclk,
  3871. .get_sclk = smu7_dpm_get_sclk,
  3872. .patch_boot_state = smu7_dpm_patch_boot_state,
  3873. .get_pp_table_entry = smu7_get_pp_table_entry,
  3874. .get_num_of_pp_table_entries = smu7_get_number_of_powerplay_table_entries,
  3875. .powerdown_uvd = smu7_powerdown_uvd,
  3876. .powergate_uvd = smu7_powergate_uvd,
  3877. .powergate_vce = smu7_powergate_vce,
  3878. .disable_clock_power_gating = smu7_disable_clock_power_gating,
  3879. .update_clock_gatings = smu7_update_clock_gatings,
  3880. .notify_smc_display_config_after_ps_adjustment = smu7_notify_smc_display_config_after_ps_adjustment,
  3881. .display_config_changed = smu7_display_configuration_changed_task,
  3882. .set_max_fan_pwm_output = smu7_set_max_fan_pwm_output,
  3883. .set_max_fan_rpm_output = smu7_set_max_fan_rpm_output,
  3884. .get_temperature = smu7_thermal_get_temperature,
  3885. .stop_thermal_controller = smu7_thermal_stop_thermal_controller,
  3886. .get_fan_speed_info = smu7_fan_ctrl_get_fan_speed_info,
  3887. .get_fan_speed_percent = smu7_fan_ctrl_get_fan_speed_percent,
  3888. .set_fan_speed_percent = smu7_fan_ctrl_set_fan_speed_percent,
  3889. .reset_fan_speed_to_default = smu7_fan_ctrl_reset_fan_speed_to_default,
  3890. .get_fan_speed_rpm = smu7_fan_ctrl_get_fan_speed_rpm,
  3891. .set_fan_speed_rpm = smu7_fan_ctrl_set_fan_speed_rpm,
  3892. .uninitialize_thermal_controller = smu7_thermal_ctrl_uninitialize_thermal_controller,
  3893. .register_internal_thermal_interrupt = smu7_register_internal_thermal_interrupt,
  3894. .check_smc_update_required_for_display_configuration = smu7_check_smc_update_required_for_display_configuration,
  3895. .check_states_equal = smu7_check_states_equal,
  3896. .set_fan_control_mode = smu7_set_fan_control_mode,
  3897. .get_fan_control_mode = smu7_get_fan_control_mode,
  3898. .force_clock_level = smu7_force_clock_level,
  3899. .print_clock_levels = smu7_print_clock_levels,
  3900. .enable_per_cu_power_gating = smu7_enable_per_cu_power_gating,
  3901. .get_sclk_od = smu7_get_sclk_od,
  3902. .set_sclk_od = smu7_set_sclk_od,
  3903. .get_mclk_od = smu7_get_mclk_od,
  3904. .set_mclk_od = smu7_set_mclk_od,
  3905. .get_clock_by_type = smu7_get_clock_by_type,
  3906. .read_sensor = smu7_read_sensor,
  3907. .dynamic_state_management_disable = smu7_disable_dpm_tasks,
  3908. .set_power_profile_state = smu7_set_power_profile_state,
  3909. .avfs_control = smu7_avfs_control,
  3910. .disable_smc_firmware_ctf = smu7_thermal_disable_alert,
  3911. };
  3912. uint8_t smu7_get_sleep_divider_id_from_clock(uint32_t clock,
  3913. uint32_t clock_insr)
  3914. {
  3915. uint8_t i;
  3916. uint32_t temp;
  3917. uint32_t min = max(clock_insr, (uint32_t)SMU7_MINIMUM_ENGINE_CLOCK);
  3918. PP_ASSERT_WITH_CODE((clock >= min), "Engine clock can't satisfy stutter requirement!", return 0);
  3919. for (i = SMU7_MAX_DEEPSLEEP_DIVIDER_ID; ; i--) {
  3920. temp = clock >> i;
  3921. if (temp >= min || i == 0)
  3922. break;
  3923. }
  3924. return i;
  3925. }
  3926. int smu7_init_function_pointers(struct pp_hwmgr *hwmgr)
  3927. {
  3928. int ret = 0;
  3929. hwmgr->hwmgr_func = &smu7_hwmgr_funcs;
  3930. if (hwmgr->pp_table_version == PP_TABLE_V0)
  3931. hwmgr->pptable_func = &pptable_funcs;
  3932. else if (hwmgr->pp_table_version == PP_TABLE_V1)
  3933. hwmgr->pptable_func = &pptable_v1_0_funcs;
  3934. return ret;
  3935. }