ni_dpm.c 130 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379
  1. /*
  2. * Copyright 2012 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 "drmP.h"
  24. #include "radeon.h"
  25. #include "radeon_asic.h"
  26. #include "nid.h"
  27. #include "r600_dpm.h"
  28. #include "ni_dpm.h"
  29. #include "atom.h"
  30. #include <linux/math64.h>
  31. #include <linux/seq_file.h>
  32. #define MC_CG_ARB_FREQ_F0 0x0a
  33. #define MC_CG_ARB_FREQ_F1 0x0b
  34. #define MC_CG_ARB_FREQ_F2 0x0c
  35. #define MC_CG_ARB_FREQ_F3 0x0d
  36. #define SMC_RAM_END 0xC000
  37. static const struct ni_cac_weights cac_weights_cayman_xt =
  38. {
  39. 0x15,
  40. 0x2,
  41. 0x19,
  42. 0x2,
  43. 0x8,
  44. 0x14,
  45. 0x2,
  46. 0x16,
  47. 0xE,
  48. 0x17,
  49. 0x13,
  50. 0x2B,
  51. 0x10,
  52. 0x7,
  53. 0x5,
  54. 0x5,
  55. 0x5,
  56. 0x2,
  57. 0x3,
  58. 0x9,
  59. 0x10,
  60. 0x10,
  61. 0x2B,
  62. 0xA,
  63. 0x9,
  64. 0x4,
  65. 0xD,
  66. 0xD,
  67. 0x3E,
  68. 0x18,
  69. 0x14,
  70. 0,
  71. 0x3,
  72. 0x3,
  73. 0x5,
  74. 0,
  75. 0x2,
  76. 0,
  77. 0,
  78. 0,
  79. 0,
  80. 0,
  81. 0,
  82. 0,
  83. 0,
  84. 0,
  85. 0x1CC,
  86. 0,
  87. 0x164,
  88. 1,
  89. 1,
  90. 1,
  91. 1,
  92. 12,
  93. 12,
  94. 12,
  95. 0x12,
  96. 0x1F,
  97. 132,
  98. 5,
  99. 7,
  100. 0,
  101. { 0, 0, 0, 0, 0, 0, 0, 0 },
  102. { 0, 0, 0, 0 },
  103. true
  104. };
  105. static const struct ni_cac_weights cac_weights_cayman_pro =
  106. {
  107. 0x16,
  108. 0x4,
  109. 0x10,
  110. 0x2,
  111. 0xA,
  112. 0x16,
  113. 0x2,
  114. 0x18,
  115. 0x10,
  116. 0x1A,
  117. 0x16,
  118. 0x2D,
  119. 0x12,
  120. 0xA,
  121. 0x6,
  122. 0x6,
  123. 0x6,
  124. 0x2,
  125. 0x4,
  126. 0xB,
  127. 0x11,
  128. 0x11,
  129. 0x2D,
  130. 0xC,
  131. 0xC,
  132. 0x7,
  133. 0x10,
  134. 0x10,
  135. 0x3F,
  136. 0x1A,
  137. 0x16,
  138. 0,
  139. 0x7,
  140. 0x4,
  141. 0x6,
  142. 1,
  143. 0x2,
  144. 0x1,
  145. 0,
  146. 0,
  147. 0,
  148. 0,
  149. 0,
  150. 0,
  151. 0x30,
  152. 0,
  153. 0x1CF,
  154. 0,
  155. 0x166,
  156. 1,
  157. 1,
  158. 1,
  159. 1,
  160. 12,
  161. 12,
  162. 12,
  163. 0x15,
  164. 0x1F,
  165. 132,
  166. 6,
  167. 6,
  168. 0,
  169. { 0, 0, 0, 0, 0, 0, 0, 0 },
  170. { 0, 0, 0, 0 },
  171. true
  172. };
  173. static const struct ni_cac_weights cac_weights_cayman_le =
  174. {
  175. 0x7,
  176. 0xE,
  177. 0x1,
  178. 0xA,
  179. 0x1,
  180. 0x3F,
  181. 0x2,
  182. 0x18,
  183. 0x10,
  184. 0x1A,
  185. 0x1,
  186. 0x3F,
  187. 0x1,
  188. 0xE,
  189. 0x6,
  190. 0x6,
  191. 0x6,
  192. 0x2,
  193. 0x4,
  194. 0x9,
  195. 0x1A,
  196. 0x1A,
  197. 0x2C,
  198. 0xA,
  199. 0x11,
  200. 0x8,
  201. 0x19,
  202. 0x19,
  203. 0x1,
  204. 0x1,
  205. 0x1A,
  206. 0,
  207. 0x8,
  208. 0x5,
  209. 0x8,
  210. 0x1,
  211. 0x3,
  212. 0x1,
  213. 0,
  214. 0,
  215. 0,
  216. 0,
  217. 0,
  218. 0,
  219. 0x38,
  220. 0x38,
  221. 0x239,
  222. 0x3,
  223. 0x18A,
  224. 1,
  225. 1,
  226. 1,
  227. 1,
  228. 12,
  229. 12,
  230. 12,
  231. 0x15,
  232. 0x22,
  233. 132,
  234. 6,
  235. 6,
  236. 0,
  237. { 0, 0, 0, 0, 0, 0, 0, 0 },
  238. { 0, 0, 0, 0 },
  239. true
  240. };
  241. #define NISLANDS_MGCG_SEQUENCE 300
  242. static const u32 cayman_cgcg_cgls_default[] =
  243. {
  244. 0x000008f8, 0x00000010, 0xffffffff,
  245. 0x000008fc, 0x00000000, 0xffffffff,
  246. 0x000008f8, 0x00000011, 0xffffffff,
  247. 0x000008fc, 0x00000000, 0xffffffff,
  248. 0x000008f8, 0x00000012, 0xffffffff,
  249. 0x000008fc, 0x00000000, 0xffffffff,
  250. 0x000008f8, 0x00000013, 0xffffffff,
  251. 0x000008fc, 0x00000000, 0xffffffff,
  252. 0x000008f8, 0x00000014, 0xffffffff,
  253. 0x000008fc, 0x00000000, 0xffffffff,
  254. 0x000008f8, 0x00000015, 0xffffffff,
  255. 0x000008fc, 0x00000000, 0xffffffff,
  256. 0x000008f8, 0x00000016, 0xffffffff,
  257. 0x000008fc, 0x00000000, 0xffffffff,
  258. 0x000008f8, 0x00000017, 0xffffffff,
  259. 0x000008fc, 0x00000000, 0xffffffff,
  260. 0x000008f8, 0x00000018, 0xffffffff,
  261. 0x000008fc, 0x00000000, 0xffffffff,
  262. 0x000008f8, 0x00000019, 0xffffffff,
  263. 0x000008fc, 0x00000000, 0xffffffff,
  264. 0x000008f8, 0x0000001a, 0xffffffff,
  265. 0x000008fc, 0x00000000, 0xffffffff,
  266. 0x000008f8, 0x0000001b, 0xffffffff,
  267. 0x000008fc, 0x00000000, 0xffffffff,
  268. 0x000008f8, 0x00000020, 0xffffffff,
  269. 0x000008fc, 0x00000000, 0xffffffff,
  270. 0x000008f8, 0x00000021, 0xffffffff,
  271. 0x000008fc, 0x00000000, 0xffffffff,
  272. 0x000008f8, 0x00000022, 0xffffffff,
  273. 0x000008fc, 0x00000000, 0xffffffff,
  274. 0x000008f8, 0x00000023, 0xffffffff,
  275. 0x000008fc, 0x00000000, 0xffffffff,
  276. 0x000008f8, 0x00000024, 0xffffffff,
  277. 0x000008fc, 0x00000000, 0xffffffff,
  278. 0x000008f8, 0x00000025, 0xffffffff,
  279. 0x000008fc, 0x00000000, 0xffffffff,
  280. 0x000008f8, 0x00000026, 0xffffffff,
  281. 0x000008fc, 0x00000000, 0xffffffff,
  282. 0x000008f8, 0x00000027, 0xffffffff,
  283. 0x000008fc, 0x00000000, 0xffffffff,
  284. 0x000008f8, 0x00000028, 0xffffffff,
  285. 0x000008fc, 0x00000000, 0xffffffff,
  286. 0x000008f8, 0x00000029, 0xffffffff,
  287. 0x000008fc, 0x00000000, 0xffffffff,
  288. 0x000008f8, 0x0000002a, 0xffffffff,
  289. 0x000008fc, 0x00000000, 0xffffffff,
  290. 0x000008f8, 0x0000002b, 0xffffffff,
  291. 0x000008fc, 0x00000000, 0xffffffff
  292. };
  293. #define CAYMAN_CGCG_CGLS_DEFAULT_LENGTH sizeof(cayman_cgcg_cgls_default) / (3 * sizeof(u32))
  294. static const u32 cayman_cgcg_cgls_disable[] =
  295. {
  296. 0x000008f8, 0x00000010, 0xffffffff,
  297. 0x000008fc, 0xffffffff, 0xffffffff,
  298. 0x000008f8, 0x00000011, 0xffffffff,
  299. 0x000008fc, 0xffffffff, 0xffffffff,
  300. 0x000008f8, 0x00000012, 0xffffffff,
  301. 0x000008fc, 0xffffffff, 0xffffffff,
  302. 0x000008f8, 0x00000013, 0xffffffff,
  303. 0x000008fc, 0xffffffff, 0xffffffff,
  304. 0x000008f8, 0x00000014, 0xffffffff,
  305. 0x000008fc, 0xffffffff, 0xffffffff,
  306. 0x000008f8, 0x00000015, 0xffffffff,
  307. 0x000008fc, 0xffffffff, 0xffffffff,
  308. 0x000008f8, 0x00000016, 0xffffffff,
  309. 0x000008fc, 0xffffffff, 0xffffffff,
  310. 0x000008f8, 0x00000017, 0xffffffff,
  311. 0x000008fc, 0xffffffff, 0xffffffff,
  312. 0x000008f8, 0x00000018, 0xffffffff,
  313. 0x000008fc, 0xffffffff, 0xffffffff,
  314. 0x000008f8, 0x00000019, 0xffffffff,
  315. 0x000008fc, 0xffffffff, 0xffffffff,
  316. 0x000008f8, 0x0000001a, 0xffffffff,
  317. 0x000008fc, 0xffffffff, 0xffffffff,
  318. 0x000008f8, 0x0000001b, 0xffffffff,
  319. 0x000008fc, 0xffffffff, 0xffffffff,
  320. 0x000008f8, 0x00000020, 0xffffffff,
  321. 0x000008fc, 0x00000000, 0xffffffff,
  322. 0x000008f8, 0x00000021, 0xffffffff,
  323. 0x000008fc, 0x00000000, 0xffffffff,
  324. 0x000008f8, 0x00000022, 0xffffffff,
  325. 0x000008fc, 0x00000000, 0xffffffff,
  326. 0x000008f8, 0x00000023, 0xffffffff,
  327. 0x000008fc, 0x00000000, 0xffffffff,
  328. 0x000008f8, 0x00000024, 0xffffffff,
  329. 0x000008fc, 0x00000000, 0xffffffff,
  330. 0x000008f8, 0x00000025, 0xffffffff,
  331. 0x000008fc, 0x00000000, 0xffffffff,
  332. 0x000008f8, 0x00000026, 0xffffffff,
  333. 0x000008fc, 0x00000000, 0xffffffff,
  334. 0x000008f8, 0x00000027, 0xffffffff,
  335. 0x000008fc, 0x00000000, 0xffffffff,
  336. 0x000008f8, 0x00000028, 0xffffffff,
  337. 0x000008fc, 0x00000000, 0xffffffff,
  338. 0x000008f8, 0x00000029, 0xffffffff,
  339. 0x000008fc, 0x00000000, 0xffffffff,
  340. 0x000008f8, 0x0000002a, 0xffffffff,
  341. 0x000008fc, 0x00000000, 0xffffffff,
  342. 0x000008f8, 0x0000002b, 0xffffffff,
  343. 0x000008fc, 0x00000000, 0xffffffff,
  344. 0x00000644, 0x000f7902, 0x001f4180,
  345. 0x00000644, 0x000f3802, 0x001f4180
  346. };
  347. #define CAYMAN_CGCG_CGLS_DISABLE_LENGTH sizeof(cayman_cgcg_cgls_disable) / (3 * sizeof(u32))
  348. static const u32 cayman_cgcg_cgls_enable[] =
  349. {
  350. 0x00000644, 0x000f7882, 0x001f4080,
  351. 0x000008f8, 0x00000010, 0xffffffff,
  352. 0x000008fc, 0x00000000, 0xffffffff,
  353. 0x000008f8, 0x00000011, 0xffffffff,
  354. 0x000008fc, 0x00000000, 0xffffffff,
  355. 0x000008f8, 0x00000012, 0xffffffff,
  356. 0x000008fc, 0x00000000, 0xffffffff,
  357. 0x000008f8, 0x00000013, 0xffffffff,
  358. 0x000008fc, 0x00000000, 0xffffffff,
  359. 0x000008f8, 0x00000014, 0xffffffff,
  360. 0x000008fc, 0x00000000, 0xffffffff,
  361. 0x000008f8, 0x00000015, 0xffffffff,
  362. 0x000008fc, 0x00000000, 0xffffffff,
  363. 0x000008f8, 0x00000016, 0xffffffff,
  364. 0x000008fc, 0x00000000, 0xffffffff,
  365. 0x000008f8, 0x00000017, 0xffffffff,
  366. 0x000008fc, 0x00000000, 0xffffffff,
  367. 0x000008f8, 0x00000018, 0xffffffff,
  368. 0x000008fc, 0x00000000, 0xffffffff,
  369. 0x000008f8, 0x00000019, 0xffffffff,
  370. 0x000008fc, 0x00000000, 0xffffffff,
  371. 0x000008f8, 0x0000001a, 0xffffffff,
  372. 0x000008fc, 0x00000000, 0xffffffff,
  373. 0x000008f8, 0x0000001b, 0xffffffff,
  374. 0x000008fc, 0x00000000, 0xffffffff,
  375. 0x000008f8, 0x00000020, 0xffffffff,
  376. 0x000008fc, 0xffffffff, 0xffffffff,
  377. 0x000008f8, 0x00000021, 0xffffffff,
  378. 0x000008fc, 0xffffffff, 0xffffffff,
  379. 0x000008f8, 0x00000022, 0xffffffff,
  380. 0x000008fc, 0xffffffff, 0xffffffff,
  381. 0x000008f8, 0x00000023, 0xffffffff,
  382. 0x000008fc, 0xffffffff, 0xffffffff,
  383. 0x000008f8, 0x00000024, 0xffffffff,
  384. 0x000008fc, 0xffffffff, 0xffffffff,
  385. 0x000008f8, 0x00000025, 0xffffffff,
  386. 0x000008fc, 0xffffffff, 0xffffffff,
  387. 0x000008f8, 0x00000026, 0xffffffff,
  388. 0x000008fc, 0xffffffff, 0xffffffff,
  389. 0x000008f8, 0x00000027, 0xffffffff,
  390. 0x000008fc, 0xffffffff, 0xffffffff,
  391. 0x000008f8, 0x00000028, 0xffffffff,
  392. 0x000008fc, 0xffffffff, 0xffffffff,
  393. 0x000008f8, 0x00000029, 0xffffffff,
  394. 0x000008fc, 0xffffffff, 0xffffffff,
  395. 0x000008f8, 0x0000002a, 0xffffffff,
  396. 0x000008fc, 0xffffffff, 0xffffffff,
  397. 0x000008f8, 0x0000002b, 0xffffffff,
  398. 0x000008fc, 0xffffffff, 0xffffffff
  399. };
  400. #define CAYMAN_CGCG_CGLS_ENABLE_LENGTH sizeof(cayman_cgcg_cgls_enable) / (3 * sizeof(u32))
  401. static const u32 cayman_mgcg_default[] =
  402. {
  403. 0x0000802c, 0xc0000000, 0xffffffff,
  404. 0x00003fc4, 0xc0000000, 0xffffffff,
  405. 0x00005448, 0x00000100, 0xffffffff,
  406. 0x000055e4, 0x00000100, 0xffffffff,
  407. 0x0000160c, 0x00000100, 0xffffffff,
  408. 0x00008984, 0x06000100, 0xffffffff,
  409. 0x0000c164, 0x00000100, 0xffffffff,
  410. 0x00008a18, 0x00000100, 0xffffffff,
  411. 0x0000897c, 0x06000100, 0xffffffff,
  412. 0x00008b28, 0x00000100, 0xffffffff,
  413. 0x00009144, 0x00800200, 0xffffffff,
  414. 0x00009a60, 0x00000100, 0xffffffff,
  415. 0x00009868, 0x00000100, 0xffffffff,
  416. 0x00008d58, 0x00000100, 0xffffffff,
  417. 0x00009510, 0x00000100, 0xffffffff,
  418. 0x0000949c, 0x00000100, 0xffffffff,
  419. 0x00009654, 0x00000100, 0xffffffff,
  420. 0x00009030, 0x00000100, 0xffffffff,
  421. 0x00009034, 0x00000100, 0xffffffff,
  422. 0x00009038, 0x00000100, 0xffffffff,
  423. 0x0000903c, 0x00000100, 0xffffffff,
  424. 0x00009040, 0x00000100, 0xffffffff,
  425. 0x0000a200, 0x00000100, 0xffffffff,
  426. 0x0000a204, 0x00000100, 0xffffffff,
  427. 0x0000a208, 0x00000100, 0xffffffff,
  428. 0x0000a20c, 0x00000100, 0xffffffff,
  429. 0x00009744, 0x00000100, 0xffffffff,
  430. 0x00003f80, 0x00000100, 0xffffffff,
  431. 0x0000a210, 0x00000100, 0xffffffff,
  432. 0x0000a214, 0x00000100, 0xffffffff,
  433. 0x000004d8, 0x00000100, 0xffffffff,
  434. 0x00009664, 0x00000100, 0xffffffff,
  435. 0x00009698, 0x00000100, 0xffffffff,
  436. 0x000004d4, 0x00000200, 0xffffffff,
  437. 0x000004d0, 0x00000000, 0xffffffff,
  438. 0x000030cc, 0x00000104, 0xffffffff,
  439. 0x0000d0c0, 0x00000100, 0xffffffff,
  440. 0x0000d8c0, 0x00000100, 0xffffffff,
  441. 0x0000802c, 0x40000000, 0xffffffff,
  442. 0x00003fc4, 0x40000000, 0xffffffff,
  443. 0x0000915c, 0x00010000, 0xffffffff,
  444. 0x00009160, 0x00030002, 0xffffffff,
  445. 0x00009164, 0x00050004, 0xffffffff,
  446. 0x00009168, 0x00070006, 0xffffffff,
  447. 0x00009178, 0x00070000, 0xffffffff,
  448. 0x0000917c, 0x00030002, 0xffffffff,
  449. 0x00009180, 0x00050004, 0xffffffff,
  450. 0x0000918c, 0x00010006, 0xffffffff,
  451. 0x00009190, 0x00090008, 0xffffffff,
  452. 0x00009194, 0x00070000, 0xffffffff,
  453. 0x00009198, 0x00030002, 0xffffffff,
  454. 0x0000919c, 0x00050004, 0xffffffff,
  455. 0x000091a8, 0x00010006, 0xffffffff,
  456. 0x000091ac, 0x00090008, 0xffffffff,
  457. 0x000091b0, 0x00070000, 0xffffffff,
  458. 0x000091b4, 0x00030002, 0xffffffff,
  459. 0x000091b8, 0x00050004, 0xffffffff,
  460. 0x000091c4, 0x00010006, 0xffffffff,
  461. 0x000091c8, 0x00090008, 0xffffffff,
  462. 0x000091cc, 0x00070000, 0xffffffff,
  463. 0x000091d0, 0x00030002, 0xffffffff,
  464. 0x000091d4, 0x00050004, 0xffffffff,
  465. 0x000091e0, 0x00010006, 0xffffffff,
  466. 0x000091e4, 0x00090008, 0xffffffff,
  467. 0x000091e8, 0x00000000, 0xffffffff,
  468. 0x000091ec, 0x00070000, 0xffffffff,
  469. 0x000091f0, 0x00030002, 0xffffffff,
  470. 0x000091f4, 0x00050004, 0xffffffff,
  471. 0x00009200, 0x00010006, 0xffffffff,
  472. 0x00009204, 0x00090008, 0xffffffff,
  473. 0x00009208, 0x00070000, 0xffffffff,
  474. 0x0000920c, 0x00030002, 0xffffffff,
  475. 0x00009210, 0x00050004, 0xffffffff,
  476. 0x0000921c, 0x00010006, 0xffffffff,
  477. 0x00009220, 0x00090008, 0xffffffff,
  478. 0x00009224, 0x00070000, 0xffffffff,
  479. 0x00009228, 0x00030002, 0xffffffff,
  480. 0x0000922c, 0x00050004, 0xffffffff,
  481. 0x00009238, 0x00010006, 0xffffffff,
  482. 0x0000923c, 0x00090008, 0xffffffff,
  483. 0x00009240, 0x00070000, 0xffffffff,
  484. 0x00009244, 0x00030002, 0xffffffff,
  485. 0x00009248, 0x00050004, 0xffffffff,
  486. 0x00009254, 0x00010006, 0xffffffff,
  487. 0x00009258, 0x00090008, 0xffffffff,
  488. 0x0000925c, 0x00070000, 0xffffffff,
  489. 0x00009260, 0x00030002, 0xffffffff,
  490. 0x00009264, 0x00050004, 0xffffffff,
  491. 0x00009270, 0x00010006, 0xffffffff,
  492. 0x00009274, 0x00090008, 0xffffffff,
  493. 0x00009278, 0x00070000, 0xffffffff,
  494. 0x0000927c, 0x00030002, 0xffffffff,
  495. 0x00009280, 0x00050004, 0xffffffff,
  496. 0x0000928c, 0x00010006, 0xffffffff,
  497. 0x00009290, 0x00090008, 0xffffffff,
  498. 0x000092a8, 0x00070000, 0xffffffff,
  499. 0x000092ac, 0x00030002, 0xffffffff,
  500. 0x000092b0, 0x00050004, 0xffffffff,
  501. 0x000092bc, 0x00010006, 0xffffffff,
  502. 0x000092c0, 0x00090008, 0xffffffff,
  503. 0x000092c4, 0x00070000, 0xffffffff,
  504. 0x000092c8, 0x00030002, 0xffffffff,
  505. 0x000092cc, 0x00050004, 0xffffffff,
  506. 0x000092d8, 0x00010006, 0xffffffff,
  507. 0x000092dc, 0x00090008, 0xffffffff,
  508. 0x00009294, 0x00000000, 0xffffffff,
  509. 0x0000802c, 0x40010000, 0xffffffff,
  510. 0x00003fc4, 0x40010000, 0xffffffff,
  511. 0x0000915c, 0x00010000, 0xffffffff,
  512. 0x00009160, 0x00030002, 0xffffffff,
  513. 0x00009164, 0x00050004, 0xffffffff,
  514. 0x00009168, 0x00070006, 0xffffffff,
  515. 0x00009178, 0x00070000, 0xffffffff,
  516. 0x0000917c, 0x00030002, 0xffffffff,
  517. 0x00009180, 0x00050004, 0xffffffff,
  518. 0x0000918c, 0x00010006, 0xffffffff,
  519. 0x00009190, 0x00090008, 0xffffffff,
  520. 0x00009194, 0x00070000, 0xffffffff,
  521. 0x00009198, 0x00030002, 0xffffffff,
  522. 0x0000919c, 0x00050004, 0xffffffff,
  523. 0x000091a8, 0x00010006, 0xffffffff,
  524. 0x000091ac, 0x00090008, 0xffffffff,
  525. 0x000091b0, 0x00070000, 0xffffffff,
  526. 0x000091b4, 0x00030002, 0xffffffff,
  527. 0x000091b8, 0x00050004, 0xffffffff,
  528. 0x000091c4, 0x00010006, 0xffffffff,
  529. 0x000091c8, 0x00090008, 0xffffffff,
  530. 0x000091cc, 0x00070000, 0xffffffff,
  531. 0x000091d0, 0x00030002, 0xffffffff,
  532. 0x000091d4, 0x00050004, 0xffffffff,
  533. 0x000091e0, 0x00010006, 0xffffffff,
  534. 0x000091e4, 0x00090008, 0xffffffff,
  535. 0x000091e8, 0x00000000, 0xffffffff,
  536. 0x000091ec, 0x00070000, 0xffffffff,
  537. 0x000091f0, 0x00030002, 0xffffffff,
  538. 0x000091f4, 0x00050004, 0xffffffff,
  539. 0x00009200, 0x00010006, 0xffffffff,
  540. 0x00009204, 0x00090008, 0xffffffff,
  541. 0x00009208, 0x00070000, 0xffffffff,
  542. 0x0000920c, 0x00030002, 0xffffffff,
  543. 0x00009210, 0x00050004, 0xffffffff,
  544. 0x0000921c, 0x00010006, 0xffffffff,
  545. 0x00009220, 0x00090008, 0xffffffff,
  546. 0x00009224, 0x00070000, 0xffffffff,
  547. 0x00009228, 0x00030002, 0xffffffff,
  548. 0x0000922c, 0x00050004, 0xffffffff,
  549. 0x00009238, 0x00010006, 0xffffffff,
  550. 0x0000923c, 0x00090008, 0xffffffff,
  551. 0x00009240, 0x00070000, 0xffffffff,
  552. 0x00009244, 0x00030002, 0xffffffff,
  553. 0x00009248, 0x00050004, 0xffffffff,
  554. 0x00009254, 0x00010006, 0xffffffff,
  555. 0x00009258, 0x00090008, 0xffffffff,
  556. 0x0000925c, 0x00070000, 0xffffffff,
  557. 0x00009260, 0x00030002, 0xffffffff,
  558. 0x00009264, 0x00050004, 0xffffffff,
  559. 0x00009270, 0x00010006, 0xffffffff,
  560. 0x00009274, 0x00090008, 0xffffffff,
  561. 0x00009278, 0x00070000, 0xffffffff,
  562. 0x0000927c, 0x00030002, 0xffffffff,
  563. 0x00009280, 0x00050004, 0xffffffff,
  564. 0x0000928c, 0x00010006, 0xffffffff,
  565. 0x00009290, 0x00090008, 0xffffffff,
  566. 0x000092a8, 0x00070000, 0xffffffff,
  567. 0x000092ac, 0x00030002, 0xffffffff,
  568. 0x000092b0, 0x00050004, 0xffffffff,
  569. 0x000092bc, 0x00010006, 0xffffffff,
  570. 0x000092c0, 0x00090008, 0xffffffff,
  571. 0x000092c4, 0x00070000, 0xffffffff,
  572. 0x000092c8, 0x00030002, 0xffffffff,
  573. 0x000092cc, 0x00050004, 0xffffffff,
  574. 0x000092d8, 0x00010006, 0xffffffff,
  575. 0x000092dc, 0x00090008, 0xffffffff,
  576. 0x00009294, 0x00000000, 0xffffffff,
  577. 0x0000802c, 0xc0000000, 0xffffffff,
  578. 0x00003fc4, 0xc0000000, 0xffffffff,
  579. 0x000008f8, 0x00000010, 0xffffffff,
  580. 0x000008fc, 0x00000000, 0xffffffff,
  581. 0x000008f8, 0x00000011, 0xffffffff,
  582. 0x000008fc, 0x00000000, 0xffffffff,
  583. 0x000008f8, 0x00000012, 0xffffffff,
  584. 0x000008fc, 0x00000000, 0xffffffff,
  585. 0x000008f8, 0x00000013, 0xffffffff,
  586. 0x000008fc, 0x00000000, 0xffffffff,
  587. 0x000008f8, 0x00000014, 0xffffffff,
  588. 0x000008fc, 0x00000000, 0xffffffff,
  589. 0x000008f8, 0x00000015, 0xffffffff,
  590. 0x000008fc, 0x00000000, 0xffffffff,
  591. 0x000008f8, 0x00000016, 0xffffffff,
  592. 0x000008fc, 0x00000000, 0xffffffff,
  593. 0x000008f8, 0x00000017, 0xffffffff,
  594. 0x000008fc, 0x00000000, 0xffffffff,
  595. 0x000008f8, 0x00000018, 0xffffffff,
  596. 0x000008fc, 0x00000000, 0xffffffff,
  597. 0x000008f8, 0x00000019, 0xffffffff,
  598. 0x000008fc, 0x00000000, 0xffffffff,
  599. 0x000008f8, 0x0000001a, 0xffffffff,
  600. 0x000008fc, 0x00000000, 0xffffffff,
  601. 0x000008f8, 0x0000001b, 0xffffffff,
  602. 0x000008fc, 0x00000000, 0xffffffff
  603. };
  604. #define CAYMAN_MGCG_DEFAULT_LENGTH sizeof(cayman_mgcg_default) / (3 * sizeof(u32))
  605. static const u32 cayman_mgcg_disable[] =
  606. {
  607. 0x0000802c, 0xc0000000, 0xffffffff,
  608. 0x000008f8, 0x00000000, 0xffffffff,
  609. 0x000008fc, 0xffffffff, 0xffffffff,
  610. 0x000008f8, 0x00000001, 0xffffffff,
  611. 0x000008fc, 0xffffffff, 0xffffffff,
  612. 0x000008f8, 0x00000002, 0xffffffff,
  613. 0x000008fc, 0xffffffff, 0xffffffff,
  614. 0x000008f8, 0x00000003, 0xffffffff,
  615. 0x000008fc, 0xffffffff, 0xffffffff,
  616. 0x00009150, 0x00600000, 0xffffffff
  617. };
  618. #define CAYMAN_MGCG_DISABLE_LENGTH sizeof(cayman_mgcg_disable) / (3 * sizeof(u32))
  619. static const u32 cayman_mgcg_enable[] =
  620. {
  621. 0x0000802c, 0xc0000000, 0xffffffff,
  622. 0x000008f8, 0x00000000, 0xffffffff,
  623. 0x000008fc, 0x00000000, 0xffffffff,
  624. 0x000008f8, 0x00000001, 0xffffffff,
  625. 0x000008fc, 0x00000000, 0xffffffff,
  626. 0x000008f8, 0x00000002, 0xffffffff,
  627. 0x000008fc, 0x00600000, 0xffffffff,
  628. 0x000008f8, 0x00000003, 0xffffffff,
  629. 0x000008fc, 0x00000000, 0xffffffff,
  630. 0x00009150, 0x96944200, 0xffffffff
  631. };
  632. #define CAYMAN_MGCG_ENABLE_LENGTH sizeof(cayman_mgcg_enable) / (3 * sizeof(u32))
  633. #define NISLANDS_SYSLS_SEQUENCE 100
  634. static const u32 cayman_sysls_default[] =
  635. {
  636. /* Register, Value, Mask bits */
  637. 0x000055e8, 0x00000000, 0xffffffff,
  638. 0x0000d0bc, 0x00000000, 0xffffffff,
  639. 0x0000d8bc, 0x00000000, 0xffffffff,
  640. 0x000015c0, 0x000c1401, 0xffffffff,
  641. 0x0000264c, 0x000c0400, 0xffffffff,
  642. 0x00002648, 0x000c0400, 0xffffffff,
  643. 0x00002650, 0x000c0400, 0xffffffff,
  644. 0x000020b8, 0x000c0400, 0xffffffff,
  645. 0x000020bc, 0x000c0400, 0xffffffff,
  646. 0x000020c0, 0x000c0c80, 0xffffffff,
  647. 0x0000f4a0, 0x000000c0, 0xffffffff,
  648. 0x0000f4a4, 0x00680fff, 0xffffffff,
  649. 0x00002f50, 0x00000404, 0xffffffff,
  650. 0x000004c8, 0x00000001, 0xffffffff,
  651. 0x000064ec, 0x00000000, 0xffffffff,
  652. 0x00000c7c, 0x00000000, 0xffffffff,
  653. 0x00008dfc, 0x00000000, 0xffffffff
  654. };
  655. #define CAYMAN_SYSLS_DEFAULT_LENGTH sizeof(cayman_sysls_default) / (3 * sizeof(u32))
  656. static const u32 cayman_sysls_disable[] =
  657. {
  658. /* Register, Value, Mask bits */
  659. 0x0000d0c0, 0x00000000, 0xffffffff,
  660. 0x0000d8c0, 0x00000000, 0xffffffff,
  661. 0x000055e8, 0x00000000, 0xffffffff,
  662. 0x0000d0bc, 0x00000000, 0xffffffff,
  663. 0x0000d8bc, 0x00000000, 0xffffffff,
  664. 0x000015c0, 0x00041401, 0xffffffff,
  665. 0x0000264c, 0x00040400, 0xffffffff,
  666. 0x00002648, 0x00040400, 0xffffffff,
  667. 0x00002650, 0x00040400, 0xffffffff,
  668. 0x000020b8, 0x00040400, 0xffffffff,
  669. 0x000020bc, 0x00040400, 0xffffffff,
  670. 0x000020c0, 0x00040c80, 0xffffffff,
  671. 0x0000f4a0, 0x000000c0, 0xffffffff,
  672. 0x0000f4a4, 0x00680000, 0xffffffff,
  673. 0x00002f50, 0x00000404, 0xffffffff,
  674. 0x000004c8, 0x00000001, 0xffffffff,
  675. 0x000064ec, 0x00007ffd, 0xffffffff,
  676. 0x00000c7c, 0x0000ff00, 0xffffffff,
  677. 0x00008dfc, 0x0000007f, 0xffffffff
  678. };
  679. #define CAYMAN_SYSLS_DISABLE_LENGTH sizeof(cayman_sysls_disable) / (3 * sizeof(u32))
  680. static const u32 cayman_sysls_enable[] =
  681. {
  682. /* Register, Value, Mask bits */
  683. 0x000055e8, 0x00000001, 0xffffffff,
  684. 0x0000d0bc, 0x00000100, 0xffffffff,
  685. 0x0000d8bc, 0x00000100, 0xffffffff,
  686. 0x000015c0, 0x000c1401, 0xffffffff,
  687. 0x0000264c, 0x000c0400, 0xffffffff,
  688. 0x00002648, 0x000c0400, 0xffffffff,
  689. 0x00002650, 0x000c0400, 0xffffffff,
  690. 0x000020b8, 0x000c0400, 0xffffffff,
  691. 0x000020bc, 0x000c0400, 0xffffffff,
  692. 0x000020c0, 0x000c0c80, 0xffffffff,
  693. 0x0000f4a0, 0x000000c0, 0xffffffff,
  694. 0x0000f4a4, 0x00680fff, 0xffffffff,
  695. 0x00002f50, 0x00000903, 0xffffffff,
  696. 0x000004c8, 0x00000000, 0xffffffff,
  697. 0x000064ec, 0x00000000, 0xffffffff,
  698. 0x00000c7c, 0x00000000, 0xffffffff,
  699. 0x00008dfc, 0x00000000, 0xffffffff
  700. };
  701. #define CAYMAN_SYSLS_ENABLE_LENGTH sizeof(cayman_sysls_enable) / (3 * sizeof(u32))
  702. struct rv7xx_power_info *rv770_get_pi(struct radeon_device *rdev);
  703. struct evergreen_power_info *evergreen_get_pi(struct radeon_device *rdev);
  704. extern int ni_mc_load_microcode(struct radeon_device *rdev);
  705. struct ni_power_info *ni_get_pi(struct radeon_device *rdev)
  706. {
  707. struct ni_power_info *pi = rdev->pm.dpm.priv;
  708. return pi;
  709. }
  710. struct ni_ps *ni_get_ps(struct radeon_ps *rps)
  711. {
  712. struct ni_ps *ps = rps->ps_priv;
  713. return ps;
  714. }
  715. static void ni_calculate_leakage_for_v_and_t_formula(const struct ni_leakage_coeffients *coeff,
  716. u16 v, s32 t,
  717. u32 ileakage,
  718. u32 *leakage)
  719. {
  720. s64 kt, kv, leakage_w, i_leakage, vddc, temperature;
  721. i_leakage = div64_s64(drm_int2fixp(ileakage), 1000);
  722. vddc = div64_s64(drm_int2fixp(v), 1000);
  723. temperature = div64_s64(drm_int2fixp(t), 1000);
  724. kt = drm_fixp_mul(div64_s64(drm_int2fixp(coeff->at), 1000),
  725. drm_fixp_exp(drm_fixp_mul(div64_s64(drm_int2fixp(coeff->bt), 1000), temperature)));
  726. kv = drm_fixp_mul(div64_s64(drm_int2fixp(coeff->av), 1000),
  727. drm_fixp_exp(drm_fixp_mul(div64_s64(drm_int2fixp(coeff->bv), 1000), vddc)));
  728. leakage_w = drm_fixp_mul(drm_fixp_mul(drm_fixp_mul(i_leakage, kt), kv), vddc);
  729. *leakage = drm_fixp2int(leakage_w * 1000);
  730. }
  731. static void ni_calculate_leakage_for_v_and_t(struct radeon_device *rdev,
  732. const struct ni_leakage_coeffients *coeff,
  733. u16 v,
  734. s32 t,
  735. u32 i_leakage,
  736. u32 *leakage)
  737. {
  738. ni_calculate_leakage_for_v_and_t_formula(coeff, v, t, i_leakage, leakage);
  739. }
  740. bool ni_dpm_vblank_too_short(struct radeon_device *rdev)
  741. {
  742. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  743. u32 vblank_time = r600_dpm_get_vblank_time(rdev);
  744. /* we never hit the non-gddr5 limit so disable it */
  745. u32 switch_limit = pi->mem_gddr5 ? 450 : 0;
  746. if (vblank_time < switch_limit)
  747. return true;
  748. else
  749. return false;
  750. }
  751. static void ni_apply_state_adjust_rules(struct radeon_device *rdev,
  752. struct radeon_ps *rps)
  753. {
  754. struct ni_ps *ps = ni_get_ps(rps);
  755. struct radeon_clock_and_voltage_limits *max_limits;
  756. bool disable_mclk_switching;
  757. u32 mclk;
  758. u16 vddci;
  759. int i;
  760. if ((rdev->pm.dpm.new_active_crtc_count > 1) ||
  761. ni_dpm_vblank_too_short(rdev))
  762. disable_mclk_switching = true;
  763. else
  764. disable_mclk_switching = false;
  765. if (rdev->pm.dpm.ac_power)
  766. max_limits = &rdev->pm.dpm.dyn_state.max_clock_voltage_on_ac;
  767. else
  768. max_limits = &rdev->pm.dpm.dyn_state.max_clock_voltage_on_dc;
  769. if (rdev->pm.dpm.ac_power == false) {
  770. for (i = 0; i < ps->performance_level_count; i++) {
  771. if (ps->performance_levels[i].mclk > max_limits->mclk)
  772. ps->performance_levels[i].mclk = max_limits->mclk;
  773. if (ps->performance_levels[i].sclk > max_limits->sclk)
  774. ps->performance_levels[i].sclk = max_limits->sclk;
  775. if (ps->performance_levels[i].vddc > max_limits->vddc)
  776. ps->performance_levels[i].vddc = max_limits->vddc;
  777. if (ps->performance_levels[i].vddci > max_limits->vddci)
  778. ps->performance_levels[i].vddci = max_limits->vddci;
  779. }
  780. }
  781. /* XXX validate the min clocks required for display */
  782. /* adjust low state */
  783. if (disable_mclk_switching) {
  784. ps->performance_levels[0].mclk =
  785. ps->performance_levels[ps->performance_level_count - 1].mclk;
  786. ps->performance_levels[0].vddci =
  787. ps->performance_levels[ps->performance_level_count - 1].vddci;
  788. }
  789. btc_skip_blacklist_clocks(rdev, max_limits->sclk, max_limits->mclk,
  790. &ps->performance_levels[0].sclk,
  791. &ps->performance_levels[0].mclk);
  792. for (i = 1; i < ps->performance_level_count; i++) {
  793. if (ps->performance_levels[i].sclk < ps->performance_levels[i - 1].sclk)
  794. ps->performance_levels[i].sclk = ps->performance_levels[i - 1].sclk;
  795. if (ps->performance_levels[i].vddc < ps->performance_levels[i - 1].vddc)
  796. ps->performance_levels[i].vddc = ps->performance_levels[i - 1].vddc;
  797. }
  798. /* adjust remaining states */
  799. if (disable_mclk_switching) {
  800. mclk = ps->performance_levels[0].mclk;
  801. vddci = ps->performance_levels[0].vddci;
  802. for (i = 1; i < ps->performance_level_count; i++) {
  803. if (mclk < ps->performance_levels[i].mclk)
  804. mclk = ps->performance_levels[i].mclk;
  805. if (vddci < ps->performance_levels[i].vddci)
  806. vddci = ps->performance_levels[i].vddci;
  807. }
  808. for (i = 0; i < ps->performance_level_count; i++) {
  809. ps->performance_levels[i].mclk = mclk;
  810. ps->performance_levels[i].vddci = vddci;
  811. }
  812. } else {
  813. for (i = 1; i < ps->performance_level_count; i++) {
  814. if (ps->performance_levels[i].mclk < ps->performance_levels[i - 1].mclk)
  815. ps->performance_levels[i].mclk = ps->performance_levels[i - 1].mclk;
  816. if (ps->performance_levels[i].vddci < ps->performance_levels[i - 1].vddci)
  817. ps->performance_levels[i].vddci = ps->performance_levels[i - 1].vddci;
  818. }
  819. }
  820. for (i = 1; i < ps->performance_level_count; i++)
  821. btc_skip_blacklist_clocks(rdev, max_limits->sclk, max_limits->mclk,
  822. &ps->performance_levels[i].sclk,
  823. &ps->performance_levels[i].mclk);
  824. for (i = 0; i < ps->performance_level_count; i++)
  825. btc_adjust_clock_combinations(rdev, max_limits,
  826. &ps->performance_levels[i]);
  827. for (i = 0; i < ps->performance_level_count; i++) {
  828. btc_apply_voltage_dependency_rules(&rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk,
  829. ps->performance_levels[i].sclk,
  830. max_limits->vddc, &ps->performance_levels[i].vddc);
  831. btc_apply_voltage_dependency_rules(&rdev->pm.dpm.dyn_state.vddci_dependency_on_mclk,
  832. ps->performance_levels[i].mclk,
  833. max_limits->vddci, &ps->performance_levels[i].vddci);
  834. btc_apply_voltage_dependency_rules(&rdev->pm.dpm.dyn_state.vddc_dependency_on_mclk,
  835. ps->performance_levels[i].mclk,
  836. max_limits->vddc, &ps->performance_levels[i].vddc);
  837. btc_apply_voltage_dependency_rules(&rdev->pm.dpm.dyn_state.vddc_dependency_on_dispclk,
  838. rdev->clock.current_dispclk,
  839. max_limits->vddc, &ps->performance_levels[i].vddc);
  840. }
  841. for (i = 0; i < ps->performance_level_count; i++) {
  842. btc_apply_voltage_delta_rules(rdev,
  843. max_limits->vddc, max_limits->vddci,
  844. &ps->performance_levels[i].vddc,
  845. &ps->performance_levels[i].vddci);
  846. }
  847. ps->dc_compatible = true;
  848. for (i = 0; i < ps->performance_level_count; i++) {
  849. if (ps->performance_levels[i].vddc > rdev->pm.dpm.dyn_state.max_clock_voltage_on_dc.vddc)
  850. ps->dc_compatible = false;
  851. if (ps->performance_levels[i].vddc < rdev->pm.dpm.dyn_state.min_vddc_for_pcie_gen2)
  852. ps->performance_levels[i].flags &= ~ATOM_PPLIB_R600_FLAGS_PCIEGEN2;
  853. }
  854. }
  855. static void ni_cg_clockgating_default(struct radeon_device *rdev)
  856. {
  857. u32 count;
  858. const u32 *ps = NULL;
  859. ps = (const u32 *)&cayman_cgcg_cgls_default;
  860. count = CAYMAN_CGCG_CGLS_DEFAULT_LENGTH;
  861. btc_program_mgcg_hw_sequence(rdev, ps, count);
  862. }
  863. static void ni_gfx_clockgating_enable(struct radeon_device *rdev,
  864. bool enable)
  865. {
  866. u32 count;
  867. const u32 *ps = NULL;
  868. if (enable) {
  869. ps = (const u32 *)&cayman_cgcg_cgls_enable;
  870. count = CAYMAN_CGCG_CGLS_ENABLE_LENGTH;
  871. } else {
  872. ps = (const u32 *)&cayman_cgcg_cgls_disable;
  873. count = CAYMAN_CGCG_CGLS_DISABLE_LENGTH;
  874. }
  875. btc_program_mgcg_hw_sequence(rdev, ps, count);
  876. }
  877. static void ni_mg_clockgating_default(struct radeon_device *rdev)
  878. {
  879. u32 count;
  880. const u32 *ps = NULL;
  881. ps = (const u32 *)&cayman_mgcg_default;
  882. count = CAYMAN_MGCG_DEFAULT_LENGTH;
  883. btc_program_mgcg_hw_sequence(rdev, ps, count);
  884. }
  885. static void ni_mg_clockgating_enable(struct radeon_device *rdev,
  886. bool enable)
  887. {
  888. u32 count;
  889. const u32 *ps = NULL;
  890. if (enable) {
  891. ps = (const u32 *)&cayman_mgcg_enable;
  892. count = CAYMAN_MGCG_ENABLE_LENGTH;
  893. } else {
  894. ps = (const u32 *)&cayman_mgcg_disable;
  895. count = CAYMAN_MGCG_DISABLE_LENGTH;
  896. }
  897. btc_program_mgcg_hw_sequence(rdev, ps, count);
  898. }
  899. static void ni_ls_clockgating_default(struct radeon_device *rdev)
  900. {
  901. u32 count;
  902. const u32 *ps = NULL;
  903. ps = (const u32 *)&cayman_sysls_default;
  904. count = CAYMAN_SYSLS_DEFAULT_LENGTH;
  905. btc_program_mgcg_hw_sequence(rdev, ps, count);
  906. }
  907. static void ni_ls_clockgating_enable(struct radeon_device *rdev,
  908. bool enable)
  909. {
  910. u32 count;
  911. const u32 *ps = NULL;
  912. if (enable) {
  913. ps = (const u32 *)&cayman_sysls_enable;
  914. count = CAYMAN_SYSLS_ENABLE_LENGTH;
  915. } else {
  916. ps = (const u32 *)&cayman_sysls_disable;
  917. count = CAYMAN_SYSLS_DISABLE_LENGTH;
  918. }
  919. btc_program_mgcg_hw_sequence(rdev, ps, count);
  920. }
  921. static int ni_patch_single_dependency_table_based_on_leakage(struct radeon_device *rdev,
  922. struct radeon_clock_voltage_dependency_table *table)
  923. {
  924. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  925. u32 i;
  926. if (table) {
  927. for (i = 0; i < table->count; i++) {
  928. if (0xff01 == table->entries[i].v) {
  929. if (pi->max_vddc == 0)
  930. return -EINVAL;
  931. table->entries[i].v = pi->max_vddc;
  932. }
  933. }
  934. }
  935. return 0;
  936. }
  937. static int ni_patch_dependency_tables_based_on_leakage(struct radeon_device *rdev)
  938. {
  939. int ret = 0;
  940. ret = ni_patch_single_dependency_table_based_on_leakage(rdev,
  941. &rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk);
  942. ret = ni_patch_single_dependency_table_based_on_leakage(rdev,
  943. &rdev->pm.dpm.dyn_state.vddc_dependency_on_mclk);
  944. return ret;
  945. }
  946. static void ni_stop_dpm(struct radeon_device *rdev)
  947. {
  948. WREG32_P(GENERAL_PWRMGT, 0, ~GLOBAL_PWRMGT_EN);
  949. }
  950. #if 0
  951. static int ni_notify_hw_of_power_source(struct radeon_device *rdev,
  952. bool ac_power)
  953. {
  954. if (ac_power)
  955. return (rv770_send_msg_to_smc(rdev, PPSMC_MSG_RunningOnAC) == PPSMC_Result_OK) ?
  956. 0 : -EINVAL;
  957. return 0;
  958. }
  959. #endif
  960. static PPSMC_Result ni_send_msg_to_smc_with_parameter(struct radeon_device *rdev,
  961. PPSMC_Msg msg, u32 parameter)
  962. {
  963. WREG32(SMC_SCRATCH0, parameter);
  964. return rv770_send_msg_to_smc(rdev, msg);
  965. }
  966. static int ni_restrict_performance_levels_before_switch(struct radeon_device *rdev)
  967. {
  968. if (rv770_send_msg_to_smc(rdev, PPSMC_MSG_NoForcedLevel) != PPSMC_Result_OK)
  969. return -EINVAL;
  970. return (ni_send_msg_to_smc_with_parameter(rdev, PPSMC_MSG_SetEnabledLevels, 1) == PPSMC_Result_OK) ?
  971. 0 : -EINVAL;
  972. }
  973. int ni_dpm_force_performance_level(struct radeon_device *rdev,
  974. enum radeon_dpm_forced_level level)
  975. {
  976. if (level == RADEON_DPM_FORCED_LEVEL_HIGH) {
  977. if (ni_send_msg_to_smc_with_parameter(rdev, PPSMC_MSG_SetEnabledLevels, 0) != PPSMC_Result_OK)
  978. return -EINVAL;
  979. if (ni_send_msg_to_smc_with_parameter(rdev, PPSMC_MSG_SetForcedLevels, 1) != PPSMC_Result_OK)
  980. return -EINVAL;
  981. } else if (level == RADEON_DPM_FORCED_LEVEL_LOW) {
  982. if (ni_send_msg_to_smc_with_parameter(rdev, PPSMC_MSG_SetForcedLevels, 0) != PPSMC_Result_OK)
  983. return -EINVAL;
  984. if (ni_send_msg_to_smc_with_parameter(rdev, PPSMC_MSG_SetEnabledLevels, 1) != PPSMC_Result_OK)
  985. return -EINVAL;
  986. } else if (level == RADEON_DPM_FORCED_LEVEL_AUTO) {
  987. if (ni_send_msg_to_smc_with_parameter(rdev, PPSMC_MSG_SetForcedLevels, 0) != PPSMC_Result_OK)
  988. return -EINVAL;
  989. if (ni_send_msg_to_smc_with_parameter(rdev, PPSMC_MSG_SetEnabledLevels, 0) != PPSMC_Result_OK)
  990. return -EINVAL;
  991. }
  992. rdev->pm.dpm.forced_level = level;
  993. return 0;
  994. }
  995. static void ni_stop_smc(struct radeon_device *rdev)
  996. {
  997. u32 tmp;
  998. int i;
  999. for (i = 0; i < rdev->usec_timeout; i++) {
  1000. tmp = RREG32(LB_SYNC_RESET_SEL) & LB_SYNC_RESET_SEL_MASK;
  1001. if (tmp != 1)
  1002. break;
  1003. udelay(1);
  1004. }
  1005. udelay(100);
  1006. r7xx_stop_smc(rdev);
  1007. }
  1008. static int ni_process_firmware_header(struct radeon_device *rdev)
  1009. {
  1010. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  1011. struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
  1012. struct ni_power_info *ni_pi = ni_get_pi(rdev);
  1013. u32 tmp;
  1014. int ret;
  1015. ret = rv770_read_smc_sram_dword(rdev,
  1016. NISLANDS_SMC_FIRMWARE_HEADER_LOCATION +
  1017. NISLANDS_SMC_FIRMWARE_HEADER_stateTable,
  1018. &tmp, pi->sram_end);
  1019. if (ret)
  1020. return ret;
  1021. pi->state_table_start = (u16)tmp;
  1022. ret = rv770_read_smc_sram_dword(rdev,
  1023. NISLANDS_SMC_FIRMWARE_HEADER_LOCATION +
  1024. NISLANDS_SMC_FIRMWARE_HEADER_softRegisters,
  1025. &tmp, pi->sram_end);
  1026. if (ret)
  1027. return ret;
  1028. pi->soft_regs_start = (u16)tmp;
  1029. ret = rv770_read_smc_sram_dword(rdev,
  1030. NISLANDS_SMC_FIRMWARE_HEADER_LOCATION +
  1031. NISLANDS_SMC_FIRMWARE_HEADER_mcRegisterTable,
  1032. &tmp, pi->sram_end);
  1033. if (ret)
  1034. return ret;
  1035. eg_pi->mc_reg_table_start = (u16)tmp;
  1036. ret = rv770_read_smc_sram_dword(rdev,
  1037. NISLANDS_SMC_FIRMWARE_HEADER_LOCATION +
  1038. NISLANDS_SMC_FIRMWARE_HEADER_fanTable,
  1039. &tmp, pi->sram_end);
  1040. if (ret)
  1041. return ret;
  1042. ni_pi->fan_table_start = (u16)tmp;
  1043. ret = rv770_read_smc_sram_dword(rdev,
  1044. NISLANDS_SMC_FIRMWARE_HEADER_LOCATION +
  1045. NISLANDS_SMC_FIRMWARE_HEADER_mcArbDramAutoRefreshTable,
  1046. &tmp, pi->sram_end);
  1047. if (ret)
  1048. return ret;
  1049. ni_pi->arb_table_start = (u16)tmp;
  1050. ret = rv770_read_smc_sram_dword(rdev,
  1051. NISLANDS_SMC_FIRMWARE_HEADER_LOCATION +
  1052. NISLANDS_SMC_FIRMWARE_HEADER_cacTable,
  1053. &tmp, pi->sram_end);
  1054. if (ret)
  1055. return ret;
  1056. ni_pi->cac_table_start = (u16)tmp;
  1057. ret = rv770_read_smc_sram_dword(rdev,
  1058. NISLANDS_SMC_FIRMWARE_HEADER_LOCATION +
  1059. NISLANDS_SMC_FIRMWARE_HEADER_spllTable,
  1060. &tmp, pi->sram_end);
  1061. if (ret)
  1062. return ret;
  1063. ni_pi->spll_table_start = (u16)tmp;
  1064. return ret;
  1065. }
  1066. static void ni_read_clock_registers(struct radeon_device *rdev)
  1067. {
  1068. struct ni_power_info *ni_pi = ni_get_pi(rdev);
  1069. ni_pi->clock_registers.cg_spll_func_cntl = RREG32(CG_SPLL_FUNC_CNTL);
  1070. ni_pi->clock_registers.cg_spll_func_cntl_2 = RREG32(CG_SPLL_FUNC_CNTL_2);
  1071. ni_pi->clock_registers.cg_spll_func_cntl_3 = RREG32(CG_SPLL_FUNC_CNTL_3);
  1072. ni_pi->clock_registers.cg_spll_func_cntl_4 = RREG32(CG_SPLL_FUNC_CNTL_4);
  1073. ni_pi->clock_registers.cg_spll_spread_spectrum = RREG32(CG_SPLL_SPREAD_SPECTRUM);
  1074. ni_pi->clock_registers.cg_spll_spread_spectrum_2 = RREG32(CG_SPLL_SPREAD_SPECTRUM_2);
  1075. ni_pi->clock_registers.mpll_ad_func_cntl = RREG32(MPLL_AD_FUNC_CNTL);
  1076. ni_pi->clock_registers.mpll_ad_func_cntl_2 = RREG32(MPLL_AD_FUNC_CNTL_2);
  1077. ni_pi->clock_registers.mpll_dq_func_cntl = RREG32(MPLL_DQ_FUNC_CNTL);
  1078. ni_pi->clock_registers.mpll_dq_func_cntl_2 = RREG32(MPLL_DQ_FUNC_CNTL_2);
  1079. ni_pi->clock_registers.mclk_pwrmgt_cntl = RREG32(MCLK_PWRMGT_CNTL);
  1080. ni_pi->clock_registers.dll_cntl = RREG32(DLL_CNTL);
  1081. ni_pi->clock_registers.mpll_ss1 = RREG32(MPLL_SS1);
  1082. ni_pi->clock_registers.mpll_ss2 = RREG32(MPLL_SS2);
  1083. }
  1084. #if 0
  1085. static int ni_enter_ulp_state(struct radeon_device *rdev)
  1086. {
  1087. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  1088. if (pi->gfx_clock_gating) {
  1089. WREG32_P(SCLK_PWRMGT_CNTL, 0, ~DYN_GFX_CLK_OFF_EN);
  1090. WREG32_P(SCLK_PWRMGT_CNTL, GFX_CLK_FORCE_ON, ~GFX_CLK_FORCE_ON);
  1091. WREG32_P(SCLK_PWRMGT_CNTL, 0, ~GFX_CLK_FORCE_ON);
  1092. RREG32(GB_ADDR_CONFIG);
  1093. }
  1094. WREG32_P(SMC_MSG, HOST_SMC_MSG(PPSMC_MSG_SwitchToMinimumPower),
  1095. ~HOST_SMC_MSG_MASK);
  1096. udelay(25000);
  1097. return 0;
  1098. }
  1099. #endif
  1100. static void ni_program_response_times(struct radeon_device *rdev)
  1101. {
  1102. u32 voltage_response_time, backbias_response_time, acpi_delay_time, vbi_time_out;
  1103. u32 vddc_dly, bb_dly, acpi_dly, vbi_dly, mclk_switch_limit;
  1104. u32 reference_clock;
  1105. rv770_write_smc_soft_register(rdev, NI_SMC_SOFT_REGISTER_mvdd_chg_time, 1);
  1106. voltage_response_time = (u32)rdev->pm.dpm.voltage_response_time;
  1107. backbias_response_time = (u32)rdev->pm.dpm.backbias_response_time;
  1108. if (voltage_response_time == 0)
  1109. voltage_response_time = 1000;
  1110. if (backbias_response_time == 0)
  1111. backbias_response_time = 1000;
  1112. acpi_delay_time = 15000;
  1113. vbi_time_out = 100000;
  1114. reference_clock = radeon_get_xclk(rdev);
  1115. vddc_dly = (voltage_response_time * reference_clock) / 1600;
  1116. bb_dly = (backbias_response_time * reference_clock) / 1600;
  1117. acpi_dly = (acpi_delay_time * reference_clock) / 1600;
  1118. vbi_dly = (vbi_time_out * reference_clock) / 1600;
  1119. mclk_switch_limit = (460 * reference_clock) / 100;
  1120. rv770_write_smc_soft_register(rdev, NI_SMC_SOFT_REGISTER_delay_vreg, vddc_dly);
  1121. rv770_write_smc_soft_register(rdev, NI_SMC_SOFT_REGISTER_delay_bbias, bb_dly);
  1122. rv770_write_smc_soft_register(rdev, NI_SMC_SOFT_REGISTER_delay_acpi, acpi_dly);
  1123. rv770_write_smc_soft_register(rdev, NI_SMC_SOFT_REGISTER_mclk_chg_timeout, vbi_dly);
  1124. rv770_write_smc_soft_register(rdev, NI_SMC_SOFT_REGISTER_mc_block_delay, 0xAA);
  1125. rv770_write_smc_soft_register(rdev, NI_SMC_SOFT_REGISTER_mclk_switch_lim, mclk_switch_limit);
  1126. }
  1127. static void ni_populate_smc_voltage_table(struct radeon_device *rdev,
  1128. struct atom_voltage_table *voltage_table,
  1129. NISLANDS_SMC_STATETABLE *table)
  1130. {
  1131. unsigned int i;
  1132. for (i = 0; i < voltage_table->count; i++) {
  1133. table->highSMIO[i] = 0;
  1134. table->lowSMIO[i] |= cpu_to_be32(voltage_table->entries[i].smio_low);
  1135. }
  1136. }
  1137. static void ni_populate_smc_voltage_tables(struct radeon_device *rdev,
  1138. NISLANDS_SMC_STATETABLE *table)
  1139. {
  1140. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  1141. struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
  1142. unsigned char i;
  1143. if (eg_pi->vddc_voltage_table.count) {
  1144. ni_populate_smc_voltage_table(rdev, &eg_pi->vddc_voltage_table, table);
  1145. table->voltageMaskTable.highMask[NISLANDS_SMC_VOLTAGEMASK_VDDC] = 0;
  1146. table->voltageMaskTable.lowMask[NISLANDS_SMC_VOLTAGEMASK_VDDC] =
  1147. cpu_to_be32(eg_pi->vddc_voltage_table.mask_low);
  1148. for (i = 0; i < eg_pi->vddc_voltage_table.count; i++) {
  1149. if (pi->max_vddc_in_table <= eg_pi->vddc_voltage_table.entries[i].value) {
  1150. table->maxVDDCIndexInPPTable = i;
  1151. break;
  1152. }
  1153. }
  1154. }
  1155. if (eg_pi->vddci_voltage_table.count) {
  1156. ni_populate_smc_voltage_table(rdev, &eg_pi->vddci_voltage_table, table);
  1157. table->voltageMaskTable.highMask[NISLANDS_SMC_VOLTAGEMASK_VDDCI] = 0;
  1158. table->voltageMaskTable.lowMask[NISLANDS_SMC_VOLTAGEMASK_VDDCI] =
  1159. cpu_to_be32(eg_pi->vddci_voltage_table.mask_low);
  1160. }
  1161. }
  1162. static int ni_populate_voltage_value(struct radeon_device *rdev,
  1163. struct atom_voltage_table *table,
  1164. u16 value,
  1165. NISLANDS_SMC_VOLTAGE_VALUE *voltage)
  1166. {
  1167. unsigned int i;
  1168. for (i = 0; i < table->count; i++) {
  1169. if (value <= table->entries[i].value) {
  1170. voltage->index = (u8)i;
  1171. voltage->value = cpu_to_be16(table->entries[i].value);
  1172. break;
  1173. }
  1174. }
  1175. if (i >= table->count)
  1176. return -EINVAL;
  1177. return 0;
  1178. }
  1179. static void ni_populate_mvdd_value(struct radeon_device *rdev,
  1180. u32 mclk,
  1181. NISLANDS_SMC_VOLTAGE_VALUE *voltage)
  1182. {
  1183. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  1184. struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
  1185. if (!pi->mvdd_control) {
  1186. voltage->index = eg_pi->mvdd_high_index;
  1187. voltage->value = cpu_to_be16(MVDD_HIGH_VALUE);
  1188. return;
  1189. }
  1190. if (mclk <= pi->mvdd_split_frequency) {
  1191. voltage->index = eg_pi->mvdd_low_index;
  1192. voltage->value = cpu_to_be16(MVDD_LOW_VALUE);
  1193. } else {
  1194. voltage->index = eg_pi->mvdd_high_index;
  1195. voltage->value = cpu_to_be16(MVDD_HIGH_VALUE);
  1196. }
  1197. }
  1198. static int ni_get_std_voltage_value(struct radeon_device *rdev,
  1199. NISLANDS_SMC_VOLTAGE_VALUE *voltage,
  1200. u16 *std_voltage)
  1201. {
  1202. if (rdev->pm.dpm.dyn_state.cac_leakage_table.entries &&
  1203. ((u32)voltage->index < rdev->pm.dpm.dyn_state.cac_leakage_table.count))
  1204. *std_voltage = rdev->pm.dpm.dyn_state.cac_leakage_table.entries[voltage->index].vddc;
  1205. else
  1206. *std_voltage = be16_to_cpu(voltage->value);
  1207. return 0;
  1208. }
  1209. static void ni_populate_std_voltage_value(struct radeon_device *rdev,
  1210. u16 value, u8 index,
  1211. NISLANDS_SMC_VOLTAGE_VALUE *voltage)
  1212. {
  1213. voltage->index = index;
  1214. voltage->value = cpu_to_be16(value);
  1215. }
  1216. static u32 ni_get_smc_power_scaling_factor(struct radeon_device *rdev)
  1217. {
  1218. u32 xclk_period;
  1219. u32 xclk = radeon_get_xclk(rdev);
  1220. u32 tmp = RREG32(CG_CAC_CTRL) & TID_CNT_MASK;
  1221. xclk_period = (1000000000UL / xclk);
  1222. xclk_period /= 10000UL;
  1223. return tmp * xclk_period;
  1224. }
  1225. static u32 ni_scale_power_for_smc(u32 power_in_watts, u32 scaling_factor)
  1226. {
  1227. return (power_in_watts * scaling_factor) << 2;
  1228. }
  1229. static u32 ni_calculate_power_boost_limit(struct radeon_device *rdev,
  1230. struct radeon_ps *radeon_state,
  1231. u32 near_tdp_limit)
  1232. {
  1233. struct ni_ps *state = ni_get_ps(radeon_state);
  1234. struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
  1235. struct ni_power_info *ni_pi = ni_get_pi(rdev);
  1236. u32 power_boost_limit = 0;
  1237. int ret;
  1238. if (ni_pi->enable_power_containment &&
  1239. ni_pi->use_power_boost_limit) {
  1240. NISLANDS_SMC_VOLTAGE_VALUE vddc;
  1241. u16 std_vddc_med;
  1242. u16 std_vddc_high;
  1243. u64 tmp, n, d;
  1244. if (state->performance_level_count < 3)
  1245. return 0;
  1246. ret = ni_populate_voltage_value(rdev, &eg_pi->vddc_voltage_table,
  1247. state->performance_levels[state->performance_level_count - 2].vddc,
  1248. &vddc);
  1249. if (ret)
  1250. return 0;
  1251. ret = ni_get_std_voltage_value(rdev, &vddc, &std_vddc_med);
  1252. if (ret)
  1253. return 0;
  1254. ret = ni_populate_voltage_value(rdev, &eg_pi->vddc_voltage_table,
  1255. state->performance_levels[state->performance_level_count - 1].vddc,
  1256. &vddc);
  1257. if (ret)
  1258. return 0;
  1259. ret = ni_get_std_voltage_value(rdev, &vddc, &std_vddc_high);
  1260. if (ret)
  1261. return 0;
  1262. n = ((u64)near_tdp_limit * ((u64)std_vddc_med * (u64)std_vddc_med) * 90);
  1263. d = ((u64)std_vddc_high * (u64)std_vddc_high * 100);
  1264. tmp = div64_u64(n, d);
  1265. if (tmp >> 32)
  1266. return 0;
  1267. power_boost_limit = (u32)tmp;
  1268. }
  1269. return power_boost_limit;
  1270. }
  1271. static int ni_calculate_adjusted_tdp_limits(struct radeon_device *rdev,
  1272. bool adjust_polarity,
  1273. u32 tdp_adjustment,
  1274. u32 *tdp_limit,
  1275. u32 *near_tdp_limit)
  1276. {
  1277. if (tdp_adjustment > (u32)rdev->pm.dpm.tdp_od_limit)
  1278. return -EINVAL;
  1279. if (adjust_polarity) {
  1280. *tdp_limit = ((100 + tdp_adjustment) * rdev->pm.dpm.tdp_limit) / 100;
  1281. *near_tdp_limit = rdev->pm.dpm.near_tdp_limit + (*tdp_limit - rdev->pm.dpm.tdp_limit);
  1282. } else {
  1283. *tdp_limit = ((100 - tdp_adjustment) * rdev->pm.dpm.tdp_limit) / 100;
  1284. *near_tdp_limit = rdev->pm.dpm.near_tdp_limit - (rdev->pm.dpm.tdp_limit - *tdp_limit);
  1285. }
  1286. return 0;
  1287. }
  1288. static int ni_populate_smc_tdp_limits(struct radeon_device *rdev,
  1289. struct radeon_ps *radeon_state)
  1290. {
  1291. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  1292. struct ni_power_info *ni_pi = ni_get_pi(rdev);
  1293. if (ni_pi->enable_power_containment) {
  1294. NISLANDS_SMC_STATETABLE *smc_table = &ni_pi->smc_statetable;
  1295. u32 scaling_factor = ni_get_smc_power_scaling_factor(rdev);
  1296. u32 tdp_limit;
  1297. u32 near_tdp_limit;
  1298. u32 power_boost_limit;
  1299. int ret;
  1300. if (scaling_factor == 0)
  1301. return -EINVAL;
  1302. memset(smc_table, 0, sizeof(NISLANDS_SMC_STATETABLE));
  1303. ret = ni_calculate_adjusted_tdp_limits(rdev,
  1304. false, /* ??? */
  1305. rdev->pm.dpm.tdp_adjustment,
  1306. &tdp_limit,
  1307. &near_tdp_limit);
  1308. if (ret)
  1309. return ret;
  1310. power_boost_limit = ni_calculate_power_boost_limit(rdev, radeon_state,
  1311. near_tdp_limit);
  1312. smc_table->dpm2Params.TDPLimit =
  1313. cpu_to_be32(ni_scale_power_for_smc(tdp_limit, scaling_factor));
  1314. smc_table->dpm2Params.NearTDPLimit =
  1315. cpu_to_be32(ni_scale_power_for_smc(near_tdp_limit, scaling_factor));
  1316. smc_table->dpm2Params.SafePowerLimit =
  1317. cpu_to_be32(ni_scale_power_for_smc((near_tdp_limit * NISLANDS_DPM2_TDP_SAFE_LIMIT_PERCENT) / 100,
  1318. scaling_factor));
  1319. smc_table->dpm2Params.PowerBoostLimit =
  1320. cpu_to_be32(ni_scale_power_for_smc(power_boost_limit, scaling_factor));
  1321. ret = rv770_copy_bytes_to_smc(rdev,
  1322. (u16)(pi->state_table_start + offsetof(NISLANDS_SMC_STATETABLE, dpm2Params) +
  1323. offsetof(PP_NIslands_DPM2Parameters, TDPLimit)),
  1324. (u8 *)(&smc_table->dpm2Params.TDPLimit),
  1325. sizeof(u32) * 4, pi->sram_end);
  1326. if (ret)
  1327. return ret;
  1328. }
  1329. return 0;
  1330. }
  1331. int ni_copy_and_switch_arb_sets(struct radeon_device *rdev,
  1332. u32 arb_freq_src, u32 arb_freq_dest)
  1333. {
  1334. u32 mc_arb_dram_timing;
  1335. u32 mc_arb_dram_timing2;
  1336. u32 burst_time;
  1337. u32 mc_cg_config;
  1338. switch (arb_freq_src) {
  1339. case MC_CG_ARB_FREQ_F0:
  1340. mc_arb_dram_timing = RREG32(MC_ARB_DRAM_TIMING);
  1341. mc_arb_dram_timing2 = RREG32(MC_ARB_DRAM_TIMING2);
  1342. burst_time = (RREG32(MC_ARB_BURST_TIME) & STATE0_MASK) >> STATE0_SHIFT;
  1343. break;
  1344. case MC_CG_ARB_FREQ_F1:
  1345. mc_arb_dram_timing = RREG32(MC_ARB_DRAM_TIMING_1);
  1346. mc_arb_dram_timing2 = RREG32(MC_ARB_DRAM_TIMING2_1);
  1347. burst_time = (RREG32(MC_ARB_BURST_TIME) & STATE1_MASK) >> STATE1_SHIFT;
  1348. break;
  1349. case MC_CG_ARB_FREQ_F2:
  1350. mc_arb_dram_timing = RREG32(MC_ARB_DRAM_TIMING_2);
  1351. mc_arb_dram_timing2 = RREG32(MC_ARB_DRAM_TIMING2_2);
  1352. burst_time = (RREG32(MC_ARB_BURST_TIME) & STATE2_MASK) >> STATE2_SHIFT;
  1353. break;
  1354. case MC_CG_ARB_FREQ_F3:
  1355. mc_arb_dram_timing = RREG32(MC_ARB_DRAM_TIMING_3);
  1356. mc_arb_dram_timing2 = RREG32(MC_ARB_DRAM_TIMING2_3);
  1357. burst_time = (RREG32(MC_ARB_BURST_TIME) & STATE3_MASK) >> STATE3_SHIFT;
  1358. break;
  1359. default:
  1360. return -EINVAL;
  1361. }
  1362. switch (arb_freq_dest) {
  1363. case MC_CG_ARB_FREQ_F0:
  1364. WREG32(MC_ARB_DRAM_TIMING, mc_arb_dram_timing);
  1365. WREG32(MC_ARB_DRAM_TIMING2, mc_arb_dram_timing2);
  1366. WREG32_P(MC_ARB_BURST_TIME, STATE0(burst_time), ~STATE0_MASK);
  1367. break;
  1368. case MC_CG_ARB_FREQ_F1:
  1369. WREG32(MC_ARB_DRAM_TIMING_1, mc_arb_dram_timing);
  1370. WREG32(MC_ARB_DRAM_TIMING2_1, mc_arb_dram_timing2);
  1371. WREG32_P(MC_ARB_BURST_TIME, STATE1(burst_time), ~STATE1_MASK);
  1372. break;
  1373. case MC_CG_ARB_FREQ_F2:
  1374. WREG32(MC_ARB_DRAM_TIMING_2, mc_arb_dram_timing);
  1375. WREG32(MC_ARB_DRAM_TIMING2_2, mc_arb_dram_timing2);
  1376. WREG32_P(MC_ARB_BURST_TIME, STATE2(burst_time), ~STATE2_MASK);
  1377. break;
  1378. case MC_CG_ARB_FREQ_F3:
  1379. WREG32(MC_ARB_DRAM_TIMING_3, mc_arb_dram_timing);
  1380. WREG32(MC_ARB_DRAM_TIMING2_3, mc_arb_dram_timing2);
  1381. WREG32_P(MC_ARB_BURST_TIME, STATE3(burst_time), ~STATE3_MASK);
  1382. break;
  1383. default:
  1384. return -EINVAL;
  1385. }
  1386. mc_cg_config = RREG32(MC_CG_CONFIG) | 0x0000000F;
  1387. WREG32(MC_CG_CONFIG, mc_cg_config);
  1388. WREG32_P(MC_ARB_CG, CG_ARB_REQ(arb_freq_dest), ~CG_ARB_REQ_MASK);
  1389. return 0;
  1390. }
  1391. static int ni_init_arb_table_index(struct radeon_device *rdev)
  1392. {
  1393. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  1394. struct ni_power_info *ni_pi = ni_get_pi(rdev);
  1395. u32 tmp;
  1396. int ret;
  1397. ret = rv770_read_smc_sram_dword(rdev, ni_pi->arb_table_start,
  1398. &tmp, pi->sram_end);
  1399. if (ret)
  1400. return ret;
  1401. tmp &= 0x00FFFFFF;
  1402. tmp |= ((u32)MC_CG_ARB_FREQ_F1) << 24;
  1403. return rv770_write_smc_sram_dword(rdev, ni_pi->arb_table_start,
  1404. tmp, pi->sram_end);
  1405. }
  1406. static int ni_initial_switch_from_arb_f0_to_f1(struct radeon_device *rdev)
  1407. {
  1408. return ni_copy_and_switch_arb_sets(rdev, MC_CG_ARB_FREQ_F0, MC_CG_ARB_FREQ_F1);
  1409. }
  1410. static int ni_force_switch_to_arb_f0(struct radeon_device *rdev)
  1411. {
  1412. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  1413. struct ni_power_info *ni_pi = ni_get_pi(rdev);
  1414. u32 tmp;
  1415. int ret;
  1416. ret = rv770_read_smc_sram_dword(rdev, ni_pi->arb_table_start,
  1417. &tmp, pi->sram_end);
  1418. if (ret)
  1419. return ret;
  1420. tmp = (tmp >> 24) & 0xff;
  1421. if (tmp == MC_CG_ARB_FREQ_F0)
  1422. return 0;
  1423. return ni_copy_and_switch_arb_sets(rdev, tmp, MC_CG_ARB_FREQ_F0);
  1424. }
  1425. static int ni_populate_memory_timing_parameters(struct radeon_device *rdev,
  1426. struct rv7xx_pl *pl,
  1427. SMC_NIslands_MCArbDramTimingRegisterSet *arb_regs)
  1428. {
  1429. u32 dram_timing;
  1430. u32 dram_timing2;
  1431. arb_regs->mc_arb_rfsh_rate =
  1432. (u8)rv770_calculate_memory_refresh_rate(rdev, pl->sclk);
  1433. radeon_atom_set_engine_dram_timings(rdev,
  1434. pl->sclk,
  1435. pl->mclk);
  1436. dram_timing = RREG32(MC_ARB_DRAM_TIMING);
  1437. dram_timing2 = RREG32(MC_ARB_DRAM_TIMING2);
  1438. arb_regs->mc_arb_dram_timing = cpu_to_be32(dram_timing);
  1439. arb_regs->mc_arb_dram_timing2 = cpu_to_be32(dram_timing2);
  1440. return 0;
  1441. }
  1442. static int ni_do_program_memory_timing_parameters(struct radeon_device *rdev,
  1443. struct radeon_ps *radeon_state,
  1444. unsigned int first_arb_set)
  1445. {
  1446. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  1447. struct ni_power_info *ni_pi = ni_get_pi(rdev);
  1448. struct ni_ps *state = ni_get_ps(radeon_state);
  1449. SMC_NIslands_MCArbDramTimingRegisterSet arb_regs = { 0 };
  1450. int i, ret = 0;
  1451. for (i = 0; i < state->performance_level_count; i++) {
  1452. ret = ni_populate_memory_timing_parameters(rdev, &state->performance_levels[i], &arb_regs);
  1453. if (ret)
  1454. break;
  1455. ret = rv770_copy_bytes_to_smc(rdev,
  1456. (u16)(ni_pi->arb_table_start +
  1457. offsetof(SMC_NIslands_MCArbDramTimingRegisters, data) +
  1458. sizeof(SMC_NIslands_MCArbDramTimingRegisterSet) * (first_arb_set + i)),
  1459. (u8 *)&arb_regs,
  1460. (u16)sizeof(SMC_NIslands_MCArbDramTimingRegisterSet),
  1461. pi->sram_end);
  1462. if (ret)
  1463. break;
  1464. }
  1465. return ret;
  1466. }
  1467. static int ni_program_memory_timing_parameters(struct radeon_device *rdev,
  1468. struct radeon_ps *radeon_new_state)
  1469. {
  1470. return ni_do_program_memory_timing_parameters(rdev, radeon_new_state,
  1471. NISLANDS_DRIVER_STATE_ARB_INDEX);
  1472. }
  1473. static void ni_populate_initial_mvdd_value(struct radeon_device *rdev,
  1474. struct NISLANDS_SMC_VOLTAGE_VALUE *voltage)
  1475. {
  1476. struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
  1477. voltage->index = eg_pi->mvdd_high_index;
  1478. voltage->value = cpu_to_be16(MVDD_HIGH_VALUE);
  1479. }
  1480. static int ni_populate_smc_initial_state(struct radeon_device *rdev,
  1481. struct radeon_ps *radeon_initial_state,
  1482. NISLANDS_SMC_STATETABLE *table)
  1483. {
  1484. struct ni_ps *initial_state = ni_get_ps(radeon_initial_state);
  1485. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  1486. struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
  1487. struct ni_power_info *ni_pi = ni_get_pi(rdev);
  1488. u32 reg;
  1489. int ret;
  1490. table->initialState.levels[0].mclk.vMPLL_AD_FUNC_CNTL =
  1491. cpu_to_be32(ni_pi->clock_registers.mpll_ad_func_cntl);
  1492. table->initialState.levels[0].mclk.vMPLL_AD_FUNC_CNTL_2 =
  1493. cpu_to_be32(ni_pi->clock_registers.mpll_ad_func_cntl_2);
  1494. table->initialState.levels[0].mclk.vMPLL_DQ_FUNC_CNTL =
  1495. cpu_to_be32(ni_pi->clock_registers.mpll_dq_func_cntl);
  1496. table->initialState.levels[0].mclk.vMPLL_DQ_FUNC_CNTL_2 =
  1497. cpu_to_be32(ni_pi->clock_registers.mpll_dq_func_cntl_2);
  1498. table->initialState.levels[0].mclk.vMCLK_PWRMGT_CNTL =
  1499. cpu_to_be32(ni_pi->clock_registers.mclk_pwrmgt_cntl);
  1500. table->initialState.levels[0].mclk.vDLL_CNTL =
  1501. cpu_to_be32(ni_pi->clock_registers.dll_cntl);
  1502. table->initialState.levels[0].mclk.vMPLL_SS =
  1503. cpu_to_be32(ni_pi->clock_registers.mpll_ss1);
  1504. table->initialState.levels[0].mclk.vMPLL_SS2 =
  1505. cpu_to_be32(ni_pi->clock_registers.mpll_ss2);
  1506. table->initialState.levels[0].mclk.mclk_value =
  1507. cpu_to_be32(initial_state->performance_levels[0].mclk);
  1508. table->initialState.levels[0].sclk.vCG_SPLL_FUNC_CNTL =
  1509. cpu_to_be32(ni_pi->clock_registers.cg_spll_func_cntl);
  1510. table->initialState.levels[0].sclk.vCG_SPLL_FUNC_CNTL_2 =
  1511. cpu_to_be32(ni_pi->clock_registers.cg_spll_func_cntl_2);
  1512. table->initialState.levels[0].sclk.vCG_SPLL_FUNC_CNTL_3 =
  1513. cpu_to_be32(ni_pi->clock_registers.cg_spll_func_cntl_3);
  1514. table->initialState.levels[0].sclk.vCG_SPLL_FUNC_CNTL_4 =
  1515. cpu_to_be32(ni_pi->clock_registers.cg_spll_func_cntl_4);
  1516. table->initialState.levels[0].sclk.vCG_SPLL_SPREAD_SPECTRUM =
  1517. cpu_to_be32(ni_pi->clock_registers.cg_spll_spread_spectrum);
  1518. table->initialState.levels[0].sclk.vCG_SPLL_SPREAD_SPECTRUM_2 =
  1519. cpu_to_be32(ni_pi->clock_registers.cg_spll_spread_spectrum_2);
  1520. table->initialState.levels[0].sclk.sclk_value =
  1521. cpu_to_be32(initial_state->performance_levels[0].sclk);
  1522. table->initialState.levels[0].arbRefreshState =
  1523. NISLANDS_INITIAL_STATE_ARB_INDEX;
  1524. table->initialState.levels[0].ACIndex = 0;
  1525. ret = ni_populate_voltage_value(rdev, &eg_pi->vddc_voltage_table,
  1526. initial_state->performance_levels[0].vddc,
  1527. &table->initialState.levels[0].vddc);
  1528. if (!ret) {
  1529. u16 std_vddc;
  1530. ret = ni_get_std_voltage_value(rdev,
  1531. &table->initialState.levels[0].vddc,
  1532. &std_vddc);
  1533. if (!ret)
  1534. ni_populate_std_voltage_value(rdev, std_vddc,
  1535. table->initialState.levels[0].vddc.index,
  1536. &table->initialState.levels[0].std_vddc);
  1537. }
  1538. if (eg_pi->vddci_control)
  1539. ni_populate_voltage_value(rdev,
  1540. &eg_pi->vddci_voltage_table,
  1541. initial_state->performance_levels[0].vddci,
  1542. &table->initialState.levels[0].vddci);
  1543. ni_populate_initial_mvdd_value(rdev, &table->initialState.levels[0].mvdd);
  1544. reg = CG_R(0xffff) | CG_L(0);
  1545. table->initialState.levels[0].aT = cpu_to_be32(reg);
  1546. table->initialState.levels[0].bSP = cpu_to_be32(pi->dsp);
  1547. if (pi->boot_in_gen2)
  1548. table->initialState.levels[0].gen2PCIE = 1;
  1549. else
  1550. table->initialState.levels[0].gen2PCIE = 0;
  1551. if (pi->mem_gddr5) {
  1552. table->initialState.levels[0].strobeMode =
  1553. cypress_get_strobe_mode_settings(rdev,
  1554. initial_state->performance_levels[0].mclk);
  1555. if (initial_state->performance_levels[0].mclk > pi->mclk_edc_enable_threshold)
  1556. table->initialState.levels[0].mcFlags = NISLANDS_SMC_MC_EDC_RD_FLAG | NISLANDS_SMC_MC_EDC_WR_FLAG;
  1557. else
  1558. table->initialState.levels[0].mcFlags = 0;
  1559. }
  1560. table->initialState.levelCount = 1;
  1561. table->initialState.flags |= PPSMC_SWSTATE_FLAG_DC;
  1562. table->initialState.levels[0].dpm2.MaxPS = 0;
  1563. table->initialState.levels[0].dpm2.NearTDPDec = 0;
  1564. table->initialState.levels[0].dpm2.AboveSafeInc = 0;
  1565. table->initialState.levels[0].dpm2.BelowSafeInc = 0;
  1566. reg = MIN_POWER_MASK | MAX_POWER_MASK;
  1567. table->initialState.levels[0].SQPowerThrottle = cpu_to_be32(reg);
  1568. reg = MAX_POWER_DELTA_MASK | STI_SIZE_MASK | LTI_RATIO_MASK;
  1569. table->initialState.levels[0].SQPowerThrottle_2 = cpu_to_be32(reg);
  1570. return 0;
  1571. }
  1572. static int ni_populate_smc_acpi_state(struct radeon_device *rdev,
  1573. NISLANDS_SMC_STATETABLE *table)
  1574. {
  1575. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  1576. struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
  1577. struct ni_power_info *ni_pi = ni_get_pi(rdev);
  1578. u32 mpll_ad_func_cntl = ni_pi->clock_registers.mpll_ad_func_cntl;
  1579. u32 mpll_ad_func_cntl_2 = ni_pi->clock_registers.mpll_ad_func_cntl_2;
  1580. u32 mpll_dq_func_cntl = ni_pi->clock_registers.mpll_dq_func_cntl;
  1581. u32 mpll_dq_func_cntl_2 = ni_pi->clock_registers.mpll_dq_func_cntl_2;
  1582. u32 spll_func_cntl = ni_pi->clock_registers.cg_spll_func_cntl;
  1583. u32 spll_func_cntl_2 = ni_pi->clock_registers.cg_spll_func_cntl_2;
  1584. u32 spll_func_cntl_3 = ni_pi->clock_registers.cg_spll_func_cntl_3;
  1585. u32 spll_func_cntl_4 = ni_pi->clock_registers.cg_spll_func_cntl_4;
  1586. u32 mclk_pwrmgt_cntl = ni_pi->clock_registers.mclk_pwrmgt_cntl;
  1587. u32 dll_cntl = ni_pi->clock_registers.dll_cntl;
  1588. u32 reg;
  1589. int ret;
  1590. table->ACPIState = table->initialState;
  1591. table->ACPIState.flags &= ~PPSMC_SWSTATE_FLAG_DC;
  1592. if (pi->acpi_vddc) {
  1593. ret = ni_populate_voltage_value(rdev,
  1594. &eg_pi->vddc_voltage_table,
  1595. pi->acpi_vddc, &table->ACPIState.levels[0].vddc);
  1596. if (!ret) {
  1597. u16 std_vddc;
  1598. ret = ni_get_std_voltage_value(rdev,
  1599. &table->ACPIState.levels[0].vddc, &std_vddc);
  1600. if (!ret)
  1601. ni_populate_std_voltage_value(rdev, std_vddc,
  1602. table->ACPIState.levels[0].vddc.index,
  1603. &table->ACPIState.levels[0].std_vddc);
  1604. }
  1605. if (pi->pcie_gen2) {
  1606. if (pi->acpi_pcie_gen2)
  1607. table->ACPIState.levels[0].gen2PCIE = 1;
  1608. else
  1609. table->ACPIState.levels[0].gen2PCIE = 0;
  1610. } else {
  1611. table->ACPIState.levels[0].gen2PCIE = 0;
  1612. }
  1613. } else {
  1614. ret = ni_populate_voltage_value(rdev,
  1615. &eg_pi->vddc_voltage_table,
  1616. pi->min_vddc_in_table,
  1617. &table->ACPIState.levels[0].vddc);
  1618. if (!ret) {
  1619. u16 std_vddc;
  1620. ret = ni_get_std_voltage_value(rdev,
  1621. &table->ACPIState.levels[0].vddc,
  1622. &std_vddc);
  1623. if (!ret)
  1624. ni_populate_std_voltage_value(rdev, std_vddc,
  1625. table->ACPIState.levels[0].vddc.index,
  1626. &table->ACPIState.levels[0].std_vddc);
  1627. }
  1628. table->ACPIState.levels[0].gen2PCIE = 0;
  1629. }
  1630. if (eg_pi->acpi_vddci) {
  1631. if (eg_pi->vddci_control)
  1632. ni_populate_voltage_value(rdev,
  1633. &eg_pi->vddci_voltage_table,
  1634. eg_pi->acpi_vddci,
  1635. &table->ACPIState.levels[0].vddci);
  1636. }
  1637. mpll_ad_func_cntl &= ~PDNB;
  1638. mpll_ad_func_cntl_2 |= BIAS_GEN_PDNB | RESET_EN;
  1639. if (pi->mem_gddr5)
  1640. mpll_dq_func_cntl &= ~PDNB;
  1641. mpll_dq_func_cntl_2 |= BIAS_GEN_PDNB | RESET_EN | BYPASS;
  1642. mclk_pwrmgt_cntl |= (MRDCKA0_RESET |
  1643. MRDCKA1_RESET |
  1644. MRDCKB0_RESET |
  1645. MRDCKB1_RESET |
  1646. MRDCKC0_RESET |
  1647. MRDCKC1_RESET |
  1648. MRDCKD0_RESET |
  1649. MRDCKD1_RESET);
  1650. mclk_pwrmgt_cntl &= ~(MRDCKA0_PDNB |
  1651. MRDCKA1_PDNB |
  1652. MRDCKB0_PDNB |
  1653. MRDCKB1_PDNB |
  1654. MRDCKC0_PDNB |
  1655. MRDCKC1_PDNB |
  1656. MRDCKD0_PDNB |
  1657. MRDCKD1_PDNB);
  1658. dll_cntl |= (MRDCKA0_BYPASS |
  1659. MRDCKA1_BYPASS |
  1660. MRDCKB0_BYPASS |
  1661. MRDCKB1_BYPASS |
  1662. MRDCKC0_BYPASS |
  1663. MRDCKC1_BYPASS |
  1664. MRDCKD0_BYPASS |
  1665. MRDCKD1_BYPASS);
  1666. spll_func_cntl_2 &= ~SCLK_MUX_SEL_MASK;
  1667. spll_func_cntl_2 |= SCLK_MUX_SEL(4);
  1668. table->ACPIState.levels[0].mclk.vMPLL_AD_FUNC_CNTL = cpu_to_be32(mpll_ad_func_cntl);
  1669. table->ACPIState.levels[0].mclk.vMPLL_AD_FUNC_CNTL_2 = cpu_to_be32(mpll_ad_func_cntl_2);
  1670. table->ACPIState.levels[0].mclk.vMPLL_DQ_FUNC_CNTL = cpu_to_be32(mpll_dq_func_cntl);
  1671. table->ACPIState.levels[0].mclk.vMPLL_DQ_FUNC_CNTL_2 = cpu_to_be32(mpll_dq_func_cntl_2);
  1672. table->ACPIState.levels[0].mclk.vMCLK_PWRMGT_CNTL = cpu_to_be32(mclk_pwrmgt_cntl);
  1673. table->ACPIState.levels[0].mclk.vDLL_CNTL = cpu_to_be32(dll_cntl);
  1674. table->ACPIState.levels[0].mclk.mclk_value = 0;
  1675. table->ACPIState.levels[0].sclk.vCG_SPLL_FUNC_CNTL = cpu_to_be32(spll_func_cntl);
  1676. table->ACPIState.levels[0].sclk.vCG_SPLL_FUNC_CNTL_2 = cpu_to_be32(spll_func_cntl_2);
  1677. table->ACPIState.levels[0].sclk.vCG_SPLL_FUNC_CNTL_3 = cpu_to_be32(spll_func_cntl_3);
  1678. table->ACPIState.levels[0].sclk.vCG_SPLL_FUNC_CNTL_4 = cpu_to_be32(spll_func_cntl_4);
  1679. table->ACPIState.levels[0].sclk.sclk_value = 0;
  1680. ni_populate_mvdd_value(rdev, 0, &table->ACPIState.levels[0].mvdd);
  1681. if (eg_pi->dynamic_ac_timing)
  1682. table->ACPIState.levels[0].ACIndex = 1;
  1683. table->ACPIState.levels[0].dpm2.MaxPS = 0;
  1684. table->ACPIState.levels[0].dpm2.NearTDPDec = 0;
  1685. table->ACPIState.levels[0].dpm2.AboveSafeInc = 0;
  1686. table->ACPIState.levels[0].dpm2.BelowSafeInc = 0;
  1687. reg = MIN_POWER_MASK | MAX_POWER_MASK;
  1688. table->ACPIState.levels[0].SQPowerThrottle = cpu_to_be32(reg);
  1689. reg = MAX_POWER_DELTA_MASK | STI_SIZE_MASK | LTI_RATIO_MASK;
  1690. table->ACPIState.levels[0].SQPowerThrottle_2 = cpu_to_be32(reg);
  1691. return 0;
  1692. }
  1693. static int ni_init_smc_table(struct radeon_device *rdev)
  1694. {
  1695. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  1696. struct ni_power_info *ni_pi = ni_get_pi(rdev);
  1697. int ret;
  1698. struct radeon_ps *radeon_boot_state = rdev->pm.dpm.boot_ps;
  1699. NISLANDS_SMC_STATETABLE *table = &ni_pi->smc_statetable;
  1700. memset(table, 0, sizeof(NISLANDS_SMC_STATETABLE));
  1701. ni_populate_smc_voltage_tables(rdev, table);
  1702. switch (rdev->pm.int_thermal_type) {
  1703. case THERMAL_TYPE_NI:
  1704. case THERMAL_TYPE_EMC2103_WITH_INTERNAL:
  1705. table->thermalProtectType = PPSMC_THERMAL_PROTECT_TYPE_INTERNAL;
  1706. break;
  1707. case THERMAL_TYPE_NONE:
  1708. table->thermalProtectType = PPSMC_THERMAL_PROTECT_TYPE_NONE;
  1709. break;
  1710. default:
  1711. table->thermalProtectType = PPSMC_THERMAL_PROTECT_TYPE_EXTERNAL;
  1712. break;
  1713. }
  1714. if (rdev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_HARDWAREDC)
  1715. table->systemFlags |= PPSMC_SYSTEMFLAG_GPIO_DC;
  1716. if (rdev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_REGULATOR_HOT)
  1717. table->systemFlags |= PPSMC_SYSTEMFLAG_REGULATOR_HOT;
  1718. if (rdev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_STEPVDDC)
  1719. table->systemFlags |= PPSMC_SYSTEMFLAG_STEPVDDC;
  1720. if (pi->mem_gddr5)
  1721. table->systemFlags |= PPSMC_SYSTEMFLAG_GDDR5;
  1722. ret = ni_populate_smc_initial_state(rdev, radeon_boot_state, table);
  1723. if (ret)
  1724. return ret;
  1725. ret = ni_populate_smc_acpi_state(rdev, table);
  1726. if (ret)
  1727. return ret;
  1728. table->driverState = table->initialState;
  1729. table->ULVState = table->initialState;
  1730. ret = ni_do_program_memory_timing_parameters(rdev, radeon_boot_state,
  1731. NISLANDS_INITIAL_STATE_ARB_INDEX);
  1732. if (ret)
  1733. return ret;
  1734. return rv770_copy_bytes_to_smc(rdev, pi->state_table_start, (u8 *)table,
  1735. sizeof(NISLANDS_SMC_STATETABLE), pi->sram_end);
  1736. }
  1737. static int ni_calculate_sclk_params(struct radeon_device *rdev,
  1738. u32 engine_clock,
  1739. NISLANDS_SMC_SCLK_VALUE *sclk)
  1740. {
  1741. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  1742. struct ni_power_info *ni_pi = ni_get_pi(rdev);
  1743. struct atom_clock_dividers dividers;
  1744. u32 spll_func_cntl = ni_pi->clock_registers.cg_spll_func_cntl;
  1745. u32 spll_func_cntl_2 = ni_pi->clock_registers.cg_spll_func_cntl_2;
  1746. u32 spll_func_cntl_3 = ni_pi->clock_registers.cg_spll_func_cntl_3;
  1747. u32 spll_func_cntl_4 = ni_pi->clock_registers.cg_spll_func_cntl_4;
  1748. u32 cg_spll_spread_spectrum = ni_pi->clock_registers.cg_spll_spread_spectrum;
  1749. u32 cg_spll_spread_spectrum_2 = ni_pi->clock_registers.cg_spll_spread_spectrum_2;
  1750. u64 tmp;
  1751. u32 reference_clock = rdev->clock.spll.reference_freq;
  1752. u32 reference_divider;
  1753. u32 fbdiv;
  1754. int ret;
  1755. ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM,
  1756. engine_clock, false, &dividers);
  1757. if (ret)
  1758. return ret;
  1759. reference_divider = 1 + dividers.ref_div;
  1760. tmp = (u64) engine_clock * reference_divider * dividers.post_div * 16834;
  1761. do_div(tmp, reference_clock);
  1762. fbdiv = (u32) tmp;
  1763. spll_func_cntl &= ~(SPLL_PDIV_A_MASK | SPLL_REF_DIV_MASK);
  1764. spll_func_cntl |= SPLL_REF_DIV(dividers.ref_div);
  1765. spll_func_cntl |= SPLL_PDIV_A(dividers.post_div);
  1766. spll_func_cntl_2 &= ~SCLK_MUX_SEL_MASK;
  1767. spll_func_cntl_2 |= SCLK_MUX_SEL(2);
  1768. spll_func_cntl_3 &= ~SPLL_FB_DIV_MASK;
  1769. spll_func_cntl_3 |= SPLL_FB_DIV(fbdiv);
  1770. spll_func_cntl_3 |= SPLL_DITHEN;
  1771. if (pi->sclk_ss) {
  1772. struct radeon_atom_ss ss;
  1773. u32 vco_freq = engine_clock * dividers.post_div;
  1774. if (radeon_atombios_get_asic_ss_info(rdev, &ss,
  1775. ASIC_INTERNAL_ENGINE_SS, vco_freq)) {
  1776. u32 clk_s = reference_clock * 5 / (reference_divider * ss.rate);
  1777. u32 clk_v = 4 * ss.percentage * fbdiv / (clk_s * 10000);
  1778. cg_spll_spread_spectrum &= ~CLK_S_MASK;
  1779. cg_spll_spread_spectrum |= CLK_S(clk_s);
  1780. cg_spll_spread_spectrum |= SSEN;
  1781. cg_spll_spread_spectrum_2 &= ~CLK_V_MASK;
  1782. cg_spll_spread_spectrum_2 |= CLK_V(clk_v);
  1783. }
  1784. }
  1785. sclk->sclk_value = engine_clock;
  1786. sclk->vCG_SPLL_FUNC_CNTL = spll_func_cntl;
  1787. sclk->vCG_SPLL_FUNC_CNTL_2 = spll_func_cntl_2;
  1788. sclk->vCG_SPLL_FUNC_CNTL_3 = spll_func_cntl_3;
  1789. sclk->vCG_SPLL_FUNC_CNTL_4 = spll_func_cntl_4;
  1790. sclk->vCG_SPLL_SPREAD_SPECTRUM = cg_spll_spread_spectrum;
  1791. sclk->vCG_SPLL_SPREAD_SPECTRUM_2 = cg_spll_spread_spectrum_2;
  1792. return 0;
  1793. }
  1794. static int ni_populate_sclk_value(struct radeon_device *rdev,
  1795. u32 engine_clock,
  1796. NISLANDS_SMC_SCLK_VALUE *sclk)
  1797. {
  1798. NISLANDS_SMC_SCLK_VALUE sclk_tmp;
  1799. int ret;
  1800. ret = ni_calculate_sclk_params(rdev, engine_clock, &sclk_tmp);
  1801. if (!ret) {
  1802. sclk->sclk_value = cpu_to_be32(sclk_tmp.sclk_value);
  1803. sclk->vCG_SPLL_FUNC_CNTL = cpu_to_be32(sclk_tmp.vCG_SPLL_FUNC_CNTL);
  1804. sclk->vCG_SPLL_FUNC_CNTL_2 = cpu_to_be32(sclk_tmp.vCG_SPLL_FUNC_CNTL_2);
  1805. sclk->vCG_SPLL_FUNC_CNTL_3 = cpu_to_be32(sclk_tmp.vCG_SPLL_FUNC_CNTL_3);
  1806. sclk->vCG_SPLL_FUNC_CNTL_4 = cpu_to_be32(sclk_tmp.vCG_SPLL_FUNC_CNTL_4);
  1807. sclk->vCG_SPLL_SPREAD_SPECTRUM = cpu_to_be32(sclk_tmp.vCG_SPLL_SPREAD_SPECTRUM);
  1808. sclk->vCG_SPLL_SPREAD_SPECTRUM_2 = cpu_to_be32(sclk_tmp.vCG_SPLL_SPREAD_SPECTRUM_2);
  1809. }
  1810. return ret;
  1811. }
  1812. static int ni_init_smc_spll_table(struct radeon_device *rdev)
  1813. {
  1814. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  1815. struct ni_power_info *ni_pi = ni_get_pi(rdev);
  1816. SMC_NISLANDS_SPLL_DIV_TABLE *spll_table;
  1817. NISLANDS_SMC_SCLK_VALUE sclk_params;
  1818. u32 fb_div;
  1819. u32 p_div;
  1820. u32 clk_s;
  1821. u32 clk_v;
  1822. u32 sclk = 0;
  1823. int i, ret;
  1824. u32 tmp;
  1825. if (ni_pi->spll_table_start == 0)
  1826. return -EINVAL;
  1827. spll_table = kzalloc(sizeof(SMC_NISLANDS_SPLL_DIV_TABLE), GFP_KERNEL);
  1828. if (spll_table == NULL)
  1829. return -ENOMEM;
  1830. for (i = 0; i < 256; i++) {
  1831. ret = ni_calculate_sclk_params(rdev, sclk, &sclk_params);
  1832. if (ret)
  1833. break;
  1834. p_div = (sclk_params.vCG_SPLL_FUNC_CNTL & SPLL_PDIV_A_MASK) >> SPLL_PDIV_A_SHIFT;
  1835. fb_div = (sclk_params.vCG_SPLL_FUNC_CNTL_3 & SPLL_FB_DIV_MASK) >> SPLL_FB_DIV_SHIFT;
  1836. clk_s = (sclk_params.vCG_SPLL_SPREAD_SPECTRUM & CLK_S_MASK) >> CLK_S_SHIFT;
  1837. clk_v = (sclk_params.vCG_SPLL_SPREAD_SPECTRUM_2 & CLK_V_MASK) >> CLK_V_SHIFT;
  1838. fb_div &= ~0x00001FFF;
  1839. fb_div >>= 1;
  1840. clk_v >>= 6;
  1841. if (p_div & ~(SMC_NISLANDS_SPLL_DIV_TABLE_PDIV_MASK >> SMC_NISLANDS_SPLL_DIV_TABLE_PDIV_SHIFT))
  1842. ret = -EINVAL;
  1843. if (clk_s & ~(SMC_NISLANDS_SPLL_DIV_TABLE_CLKS_MASK >> SMC_NISLANDS_SPLL_DIV_TABLE_CLKS_SHIFT))
  1844. ret = -EINVAL;
  1845. if (clk_s & ~(SMC_NISLANDS_SPLL_DIV_TABLE_CLKS_MASK >> SMC_NISLANDS_SPLL_DIV_TABLE_CLKS_SHIFT))
  1846. ret = -EINVAL;
  1847. if (clk_v & ~(SMC_NISLANDS_SPLL_DIV_TABLE_CLKV_MASK >> SMC_NISLANDS_SPLL_DIV_TABLE_CLKV_SHIFT))
  1848. ret = -EINVAL;
  1849. if (ret)
  1850. break;
  1851. tmp = ((fb_div << SMC_NISLANDS_SPLL_DIV_TABLE_FBDIV_SHIFT) & SMC_NISLANDS_SPLL_DIV_TABLE_FBDIV_MASK) |
  1852. ((p_div << SMC_NISLANDS_SPLL_DIV_TABLE_PDIV_SHIFT) & SMC_NISLANDS_SPLL_DIV_TABLE_PDIV_MASK);
  1853. spll_table->freq[i] = cpu_to_be32(tmp);
  1854. tmp = ((clk_v << SMC_NISLANDS_SPLL_DIV_TABLE_CLKV_SHIFT) & SMC_NISLANDS_SPLL_DIV_TABLE_CLKV_MASK) |
  1855. ((clk_s << SMC_NISLANDS_SPLL_DIV_TABLE_CLKS_SHIFT) & SMC_NISLANDS_SPLL_DIV_TABLE_CLKS_MASK);
  1856. spll_table->ss[i] = cpu_to_be32(tmp);
  1857. sclk += 512;
  1858. }
  1859. if (!ret)
  1860. ret = rv770_copy_bytes_to_smc(rdev, ni_pi->spll_table_start, (u8 *)spll_table,
  1861. sizeof(SMC_NISLANDS_SPLL_DIV_TABLE), pi->sram_end);
  1862. kfree(spll_table);
  1863. return ret;
  1864. }
  1865. static int ni_populate_mclk_value(struct radeon_device *rdev,
  1866. u32 engine_clock,
  1867. u32 memory_clock,
  1868. NISLANDS_SMC_MCLK_VALUE *mclk,
  1869. bool strobe_mode,
  1870. bool dll_state_on)
  1871. {
  1872. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  1873. struct ni_power_info *ni_pi = ni_get_pi(rdev);
  1874. u32 mpll_ad_func_cntl = ni_pi->clock_registers.mpll_ad_func_cntl;
  1875. u32 mpll_ad_func_cntl_2 = ni_pi->clock_registers.mpll_ad_func_cntl_2;
  1876. u32 mpll_dq_func_cntl = ni_pi->clock_registers.mpll_dq_func_cntl;
  1877. u32 mpll_dq_func_cntl_2 = ni_pi->clock_registers.mpll_dq_func_cntl_2;
  1878. u32 mclk_pwrmgt_cntl = ni_pi->clock_registers.mclk_pwrmgt_cntl;
  1879. u32 dll_cntl = ni_pi->clock_registers.dll_cntl;
  1880. u32 mpll_ss1 = ni_pi->clock_registers.mpll_ss1;
  1881. u32 mpll_ss2 = ni_pi->clock_registers.mpll_ss2;
  1882. struct atom_clock_dividers dividers;
  1883. u32 ibias;
  1884. u32 dll_speed;
  1885. int ret;
  1886. u32 mc_seq_misc7;
  1887. ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_MEMORY_PLL_PARAM,
  1888. memory_clock, strobe_mode, &dividers);
  1889. if (ret)
  1890. return ret;
  1891. if (!strobe_mode) {
  1892. mc_seq_misc7 = RREG32(MC_SEQ_MISC7);
  1893. if (mc_seq_misc7 & 0x8000000)
  1894. dividers.post_div = 1;
  1895. }
  1896. ibias = cypress_map_clkf_to_ibias(rdev, dividers.whole_fb_div);
  1897. mpll_ad_func_cntl &= ~(CLKR_MASK |
  1898. YCLK_POST_DIV_MASK |
  1899. CLKF_MASK |
  1900. CLKFRAC_MASK |
  1901. IBIAS_MASK);
  1902. mpll_ad_func_cntl |= CLKR(dividers.ref_div);
  1903. mpll_ad_func_cntl |= YCLK_POST_DIV(dividers.post_div);
  1904. mpll_ad_func_cntl |= CLKF(dividers.whole_fb_div);
  1905. mpll_ad_func_cntl |= CLKFRAC(dividers.frac_fb_div);
  1906. mpll_ad_func_cntl |= IBIAS(ibias);
  1907. if (dividers.vco_mode)
  1908. mpll_ad_func_cntl_2 |= VCO_MODE;
  1909. else
  1910. mpll_ad_func_cntl_2 &= ~VCO_MODE;
  1911. if (pi->mem_gddr5) {
  1912. mpll_dq_func_cntl &= ~(CLKR_MASK |
  1913. YCLK_POST_DIV_MASK |
  1914. CLKF_MASK |
  1915. CLKFRAC_MASK |
  1916. IBIAS_MASK);
  1917. mpll_dq_func_cntl |= CLKR(dividers.ref_div);
  1918. mpll_dq_func_cntl |= YCLK_POST_DIV(dividers.post_div);
  1919. mpll_dq_func_cntl |= CLKF(dividers.whole_fb_div);
  1920. mpll_dq_func_cntl |= CLKFRAC(dividers.frac_fb_div);
  1921. mpll_dq_func_cntl |= IBIAS(ibias);
  1922. if (strobe_mode)
  1923. mpll_dq_func_cntl &= ~PDNB;
  1924. else
  1925. mpll_dq_func_cntl |= PDNB;
  1926. if (dividers.vco_mode)
  1927. mpll_dq_func_cntl_2 |= VCO_MODE;
  1928. else
  1929. mpll_dq_func_cntl_2 &= ~VCO_MODE;
  1930. }
  1931. if (pi->mclk_ss) {
  1932. struct radeon_atom_ss ss;
  1933. u32 vco_freq = memory_clock * dividers.post_div;
  1934. if (radeon_atombios_get_asic_ss_info(rdev, &ss,
  1935. ASIC_INTERNAL_MEMORY_SS, vco_freq)) {
  1936. u32 reference_clock = rdev->clock.mpll.reference_freq;
  1937. u32 decoded_ref = rv740_get_decoded_reference_divider(dividers.ref_div);
  1938. u32 clk_s = reference_clock * 5 / (decoded_ref * ss.rate);
  1939. u32 clk_v = ss.percentage *
  1940. (0x4000 * dividers.whole_fb_div + 0x800 * dividers.frac_fb_div) / (clk_s * 625);
  1941. mpll_ss1 &= ~CLKV_MASK;
  1942. mpll_ss1 |= CLKV(clk_v);
  1943. mpll_ss2 &= ~CLKS_MASK;
  1944. mpll_ss2 |= CLKS(clk_s);
  1945. }
  1946. }
  1947. dll_speed = rv740_get_dll_speed(pi->mem_gddr5,
  1948. memory_clock);
  1949. mclk_pwrmgt_cntl &= ~DLL_SPEED_MASK;
  1950. mclk_pwrmgt_cntl |= DLL_SPEED(dll_speed);
  1951. if (dll_state_on)
  1952. mclk_pwrmgt_cntl |= (MRDCKA0_PDNB |
  1953. MRDCKA1_PDNB |
  1954. MRDCKB0_PDNB |
  1955. MRDCKB1_PDNB |
  1956. MRDCKC0_PDNB |
  1957. MRDCKC1_PDNB |
  1958. MRDCKD0_PDNB |
  1959. MRDCKD1_PDNB);
  1960. else
  1961. mclk_pwrmgt_cntl &= ~(MRDCKA0_PDNB |
  1962. MRDCKA1_PDNB |
  1963. MRDCKB0_PDNB |
  1964. MRDCKB1_PDNB |
  1965. MRDCKC0_PDNB |
  1966. MRDCKC1_PDNB |
  1967. MRDCKD0_PDNB |
  1968. MRDCKD1_PDNB);
  1969. mclk->mclk_value = cpu_to_be32(memory_clock);
  1970. mclk->vMPLL_AD_FUNC_CNTL = cpu_to_be32(mpll_ad_func_cntl);
  1971. mclk->vMPLL_AD_FUNC_CNTL_2 = cpu_to_be32(mpll_ad_func_cntl_2);
  1972. mclk->vMPLL_DQ_FUNC_CNTL = cpu_to_be32(mpll_dq_func_cntl);
  1973. mclk->vMPLL_DQ_FUNC_CNTL_2 = cpu_to_be32(mpll_dq_func_cntl_2);
  1974. mclk->vMCLK_PWRMGT_CNTL = cpu_to_be32(mclk_pwrmgt_cntl);
  1975. mclk->vDLL_CNTL = cpu_to_be32(dll_cntl);
  1976. mclk->vMPLL_SS = cpu_to_be32(mpll_ss1);
  1977. mclk->vMPLL_SS2 = cpu_to_be32(mpll_ss2);
  1978. return 0;
  1979. }
  1980. static void ni_populate_smc_sp(struct radeon_device *rdev,
  1981. struct radeon_ps *radeon_state,
  1982. NISLANDS_SMC_SWSTATE *smc_state)
  1983. {
  1984. struct ni_ps *ps = ni_get_ps(radeon_state);
  1985. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  1986. int i;
  1987. for (i = 0; i < ps->performance_level_count - 1; i++)
  1988. smc_state->levels[i].bSP = cpu_to_be32(pi->dsp);
  1989. smc_state->levels[ps->performance_level_count - 1].bSP =
  1990. cpu_to_be32(pi->psp);
  1991. }
  1992. static int ni_convert_power_level_to_smc(struct radeon_device *rdev,
  1993. struct rv7xx_pl *pl,
  1994. NISLANDS_SMC_HW_PERFORMANCE_LEVEL *level)
  1995. {
  1996. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  1997. struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
  1998. struct ni_power_info *ni_pi = ni_get_pi(rdev);
  1999. int ret;
  2000. bool dll_state_on;
  2001. u16 std_vddc;
  2002. u32 tmp = RREG32(DC_STUTTER_CNTL);
  2003. level->gen2PCIE = pi->pcie_gen2 ?
  2004. ((pl->flags & ATOM_PPLIB_R600_FLAGS_PCIEGEN2) ? 1 : 0) : 0;
  2005. ret = ni_populate_sclk_value(rdev, pl->sclk, &level->sclk);
  2006. if (ret)
  2007. return ret;
  2008. level->mcFlags = 0;
  2009. if (pi->mclk_stutter_mode_threshold &&
  2010. (pl->mclk <= pi->mclk_stutter_mode_threshold) &&
  2011. !eg_pi->uvd_enabled &&
  2012. (tmp & DC_STUTTER_ENABLE_A) &&
  2013. (tmp & DC_STUTTER_ENABLE_B))
  2014. level->mcFlags |= NISLANDS_SMC_MC_STUTTER_EN;
  2015. if (pi->mem_gddr5) {
  2016. if (pl->mclk > pi->mclk_edc_enable_threshold)
  2017. level->mcFlags |= NISLANDS_SMC_MC_EDC_RD_FLAG;
  2018. if (pl->mclk > eg_pi->mclk_edc_wr_enable_threshold)
  2019. level->mcFlags |= NISLANDS_SMC_MC_EDC_WR_FLAG;
  2020. level->strobeMode = cypress_get_strobe_mode_settings(rdev, pl->mclk);
  2021. if (level->strobeMode & NISLANDS_SMC_STROBE_ENABLE) {
  2022. if (cypress_get_mclk_frequency_ratio(rdev, pl->mclk, true) >=
  2023. ((RREG32(MC_SEQ_MISC7) >> 16) & 0xf))
  2024. dll_state_on = ((RREG32(MC_SEQ_MISC5) >> 1) & 0x1) ? true : false;
  2025. else
  2026. dll_state_on = ((RREG32(MC_SEQ_MISC6) >> 1) & 0x1) ? true : false;
  2027. } else {
  2028. dll_state_on = false;
  2029. if (pl->mclk > ni_pi->mclk_rtt_mode_threshold)
  2030. level->mcFlags |= NISLANDS_SMC_MC_RTT_ENABLE;
  2031. }
  2032. ret = ni_populate_mclk_value(rdev, pl->sclk, pl->mclk,
  2033. &level->mclk,
  2034. (level->strobeMode & NISLANDS_SMC_STROBE_ENABLE) != 0,
  2035. dll_state_on);
  2036. } else
  2037. ret = ni_populate_mclk_value(rdev, pl->sclk, pl->mclk, &level->mclk, 1, 1);
  2038. if (ret)
  2039. return ret;
  2040. ret = ni_populate_voltage_value(rdev, &eg_pi->vddc_voltage_table,
  2041. pl->vddc, &level->vddc);
  2042. if (ret)
  2043. return ret;
  2044. ret = ni_get_std_voltage_value(rdev, &level->vddc, &std_vddc);
  2045. if (ret)
  2046. return ret;
  2047. ni_populate_std_voltage_value(rdev, std_vddc,
  2048. level->vddc.index, &level->std_vddc);
  2049. if (eg_pi->vddci_control) {
  2050. ret = ni_populate_voltage_value(rdev, &eg_pi->vddci_voltage_table,
  2051. pl->vddci, &level->vddci);
  2052. if (ret)
  2053. return ret;
  2054. }
  2055. ni_populate_mvdd_value(rdev, pl->mclk, &level->mvdd);
  2056. return ret;
  2057. }
  2058. static int ni_populate_smc_t(struct radeon_device *rdev,
  2059. struct radeon_ps *radeon_state,
  2060. NISLANDS_SMC_SWSTATE *smc_state)
  2061. {
  2062. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  2063. struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
  2064. struct ni_ps *state = ni_get_ps(radeon_state);
  2065. u32 a_t;
  2066. u32 t_l, t_h;
  2067. u32 high_bsp;
  2068. int i, ret;
  2069. if (state->performance_level_count >= 9)
  2070. return -EINVAL;
  2071. if (state->performance_level_count < 2) {
  2072. a_t = CG_R(0xffff) | CG_L(0);
  2073. smc_state->levels[0].aT = cpu_to_be32(a_t);
  2074. return 0;
  2075. }
  2076. smc_state->levels[0].aT = cpu_to_be32(0);
  2077. for (i = 0; i <= state->performance_level_count - 2; i++) {
  2078. if (eg_pi->uvd_enabled)
  2079. ret = r600_calculate_at(
  2080. 1000 * (i * (eg_pi->smu_uvd_hs ? 2 : 8) + 2),
  2081. 100 * R600_AH_DFLT,
  2082. state->performance_levels[i + 1].sclk,
  2083. state->performance_levels[i].sclk,
  2084. &t_l,
  2085. &t_h);
  2086. else
  2087. ret = r600_calculate_at(
  2088. 1000 * (i + 1),
  2089. 100 * R600_AH_DFLT,
  2090. state->performance_levels[i + 1].sclk,
  2091. state->performance_levels[i].sclk,
  2092. &t_l,
  2093. &t_h);
  2094. if (ret) {
  2095. t_h = (i + 1) * 1000 - 50 * R600_AH_DFLT;
  2096. t_l = (i + 1) * 1000 + 50 * R600_AH_DFLT;
  2097. }
  2098. a_t = be32_to_cpu(smc_state->levels[i].aT) & ~CG_R_MASK;
  2099. a_t |= CG_R(t_l * pi->bsp / 20000);
  2100. smc_state->levels[i].aT = cpu_to_be32(a_t);
  2101. high_bsp = (i == state->performance_level_count - 2) ?
  2102. pi->pbsp : pi->bsp;
  2103. a_t = CG_R(0xffff) | CG_L(t_h * high_bsp / 20000);
  2104. smc_state->levels[i + 1].aT = cpu_to_be32(a_t);
  2105. }
  2106. return 0;
  2107. }
  2108. static int ni_populate_power_containment_values(struct radeon_device *rdev,
  2109. struct radeon_ps *radeon_state,
  2110. NISLANDS_SMC_SWSTATE *smc_state)
  2111. {
  2112. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  2113. struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
  2114. struct ni_power_info *ni_pi = ni_get_pi(rdev);
  2115. struct ni_ps *state = ni_get_ps(radeon_state);
  2116. u32 prev_sclk;
  2117. u32 max_sclk;
  2118. u32 min_sclk;
  2119. int i, ret;
  2120. u32 tdp_limit;
  2121. u32 near_tdp_limit;
  2122. u32 power_boost_limit;
  2123. u8 max_ps_percent;
  2124. if (ni_pi->enable_power_containment == false)
  2125. return 0;
  2126. if (state->performance_level_count == 0)
  2127. return -EINVAL;
  2128. if (smc_state->levelCount != state->performance_level_count)
  2129. return -EINVAL;
  2130. ret = ni_calculate_adjusted_tdp_limits(rdev,
  2131. false, /* ??? */
  2132. rdev->pm.dpm.tdp_adjustment,
  2133. &tdp_limit,
  2134. &near_tdp_limit);
  2135. if (ret)
  2136. return ret;
  2137. power_boost_limit = ni_calculate_power_boost_limit(rdev, radeon_state, near_tdp_limit);
  2138. ret = rv770_write_smc_sram_dword(rdev,
  2139. pi->state_table_start +
  2140. offsetof(NISLANDS_SMC_STATETABLE, dpm2Params) +
  2141. offsetof(PP_NIslands_DPM2Parameters, PowerBoostLimit),
  2142. ni_scale_power_for_smc(power_boost_limit, ni_get_smc_power_scaling_factor(rdev)),
  2143. pi->sram_end);
  2144. if (ret)
  2145. power_boost_limit = 0;
  2146. smc_state->levels[0].dpm2.MaxPS = 0;
  2147. smc_state->levels[0].dpm2.NearTDPDec = 0;
  2148. smc_state->levels[0].dpm2.AboveSafeInc = 0;
  2149. smc_state->levels[0].dpm2.BelowSafeInc = 0;
  2150. smc_state->levels[0].stateFlags |= power_boost_limit ? PPSMC_STATEFLAG_POWERBOOST : 0;
  2151. for (i = 1; i < state->performance_level_count; i++) {
  2152. prev_sclk = state->performance_levels[i-1].sclk;
  2153. max_sclk = state->performance_levels[i].sclk;
  2154. max_ps_percent = (i != (state->performance_level_count - 1)) ?
  2155. NISLANDS_DPM2_MAXPS_PERCENT_M : NISLANDS_DPM2_MAXPS_PERCENT_H;
  2156. if (max_sclk < prev_sclk)
  2157. return -EINVAL;
  2158. if ((max_ps_percent == 0) || (prev_sclk == max_sclk) || eg_pi->uvd_enabled)
  2159. min_sclk = max_sclk;
  2160. else if (1 == i)
  2161. min_sclk = prev_sclk;
  2162. else
  2163. min_sclk = (prev_sclk * (u32)max_ps_percent) / 100;
  2164. if (min_sclk < state->performance_levels[0].sclk)
  2165. min_sclk = state->performance_levels[0].sclk;
  2166. if (min_sclk == 0)
  2167. return -EINVAL;
  2168. smc_state->levels[i].dpm2.MaxPS =
  2169. (u8)((NISLANDS_DPM2_MAX_PULSE_SKIP * (max_sclk - min_sclk)) / max_sclk);
  2170. smc_state->levels[i].dpm2.NearTDPDec = NISLANDS_DPM2_NEAR_TDP_DEC;
  2171. smc_state->levels[i].dpm2.AboveSafeInc = NISLANDS_DPM2_ABOVE_SAFE_INC;
  2172. smc_state->levels[i].dpm2.BelowSafeInc = NISLANDS_DPM2_BELOW_SAFE_INC;
  2173. smc_state->levels[i].stateFlags |=
  2174. ((i != (state->performance_level_count - 1)) && power_boost_limit) ?
  2175. PPSMC_STATEFLAG_POWERBOOST : 0;
  2176. }
  2177. return 0;
  2178. }
  2179. static int ni_populate_sq_ramping_values(struct radeon_device *rdev,
  2180. struct radeon_ps *radeon_state,
  2181. NISLANDS_SMC_SWSTATE *smc_state)
  2182. {
  2183. struct ni_power_info *ni_pi = ni_get_pi(rdev);
  2184. struct ni_ps *state = ni_get_ps(radeon_state);
  2185. u32 sq_power_throttle;
  2186. u32 sq_power_throttle2;
  2187. bool enable_sq_ramping = ni_pi->enable_sq_ramping;
  2188. int i;
  2189. if (state->performance_level_count == 0)
  2190. return -EINVAL;
  2191. if (smc_state->levelCount != state->performance_level_count)
  2192. return -EINVAL;
  2193. if (rdev->pm.dpm.sq_ramping_threshold == 0)
  2194. return -EINVAL;
  2195. if (NISLANDS_DPM2_SQ_RAMP_MAX_POWER > (MAX_POWER_MASK >> MAX_POWER_SHIFT))
  2196. enable_sq_ramping = false;
  2197. if (NISLANDS_DPM2_SQ_RAMP_MIN_POWER > (MIN_POWER_MASK >> MIN_POWER_SHIFT))
  2198. enable_sq_ramping = false;
  2199. if (NISLANDS_DPM2_SQ_RAMP_MAX_POWER_DELTA > (MAX_POWER_DELTA_MASK >> MAX_POWER_DELTA_SHIFT))
  2200. enable_sq_ramping = false;
  2201. if (NISLANDS_DPM2_SQ_RAMP_STI_SIZE > (STI_SIZE_MASK >> STI_SIZE_SHIFT))
  2202. enable_sq_ramping = false;
  2203. if (NISLANDS_DPM2_SQ_RAMP_LTI_RATIO > (LTI_RATIO_MASK >> LTI_RATIO_SHIFT))
  2204. enable_sq_ramping = false;
  2205. for (i = 0; i < state->performance_level_count; i++) {
  2206. sq_power_throttle = 0;
  2207. sq_power_throttle2 = 0;
  2208. if ((state->performance_levels[i].sclk >= rdev->pm.dpm.sq_ramping_threshold) &&
  2209. enable_sq_ramping) {
  2210. sq_power_throttle |= MAX_POWER(NISLANDS_DPM2_SQ_RAMP_MAX_POWER);
  2211. sq_power_throttle |= MIN_POWER(NISLANDS_DPM2_SQ_RAMP_MIN_POWER);
  2212. sq_power_throttle2 |= MAX_POWER_DELTA(NISLANDS_DPM2_SQ_RAMP_MAX_POWER_DELTA);
  2213. sq_power_throttle2 |= STI_SIZE(NISLANDS_DPM2_SQ_RAMP_STI_SIZE);
  2214. sq_power_throttle2 |= LTI_RATIO(NISLANDS_DPM2_SQ_RAMP_LTI_RATIO);
  2215. } else {
  2216. sq_power_throttle |= MAX_POWER_MASK | MIN_POWER_MASK;
  2217. sq_power_throttle2 |= MAX_POWER_DELTA_MASK | STI_SIZE_MASK | LTI_RATIO_MASK;
  2218. }
  2219. smc_state->levels[i].SQPowerThrottle = cpu_to_be32(sq_power_throttle);
  2220. smc_state->levels[i].SQPowerThrottle_2 = cpu_to_be32(sq_power_throttle2);
  2221. }
  2222. return 0;
  2223. }
  2224. static int ni_enable_power_containment(struct radeon_device *rdev,
  2225. struct radeon_ps *radeon_new_state,
  2226. bool enable)
  2227. {
  2228. struct ni_power_info *ni_pi = ni_get_pi(rdev);
  2229. PPSMC_Result smc_result;
  2230. int ret = 0;
  2231. if (ni_pi->enable_power_containment) {
  2232. if (enable) {
  2233. if (!r600_is_uvd_state(radeon_new_state->class, radeon_new_state->class2)) {
  2234. smc_result = rv770_send_msg_to_smc(rdev, PPSMC_TDPClampingActive);
  2235. if (smc_result != PPSMC_Result_OK) {
  2236. ret = -EINVAL;
  2237. ni_pi->pc_enabled = false;
  2238. } else {
  2239. ni_pi->pc_enabled = true;
  2240. }
  2241. }
  2242. } else {
  2243. smc_result = rv770_send_msg_to_smc(rdev, PPSMC_TDPClampingInactive);
  2244. if (smc_result != PPSMC_Result_OK)
  2245. ret = -EINVAL;
  2246. ni_pi->pc_enabled = false;
  2247. }
  2248. }
  2249. return ret;
  2250. }
  2251. static int ni_convert_power_state_to_smc(struct radeon_device *rdev,
  2252. struct radeon_ps *radeon_state,
  2253. NISLANDS_SMC_SWSTATE *smc_state)
  2254. {
  2255. struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
  2256. struct ni_power_info *ni_pi = ni_get_pi(rdev);
  2257. struct ni_ps *state = ni_get_ps(radeon_state);
  2258. int i, ret;
  2259. u32 threshold = state->performance_levels[state->performance_level_count - 1].sclk * 100 / 100;
  2260. if (!(radeon_state->caps & ATOM_PPLIB_DISALLOW_ON_DC))
  2261. smc_state->flags |= PPSMC_SWSTATE_FLAG_DC;
  2262. smc_state->levelCount = 0;
  2263. if (state->performance_level_count > NISLANDS_MAX_SMC_PERFORMANCE_LEVELS_PER_SWSTATE)
  2264. return -EINVAL;
  2265. for (i = 0; i < state->performance_level_count; i++) {
  2266. ret = ni_convert_power_level_to_smc(rdev, &state->performance_levels[i],
  2267. &smc_state->levels[i]);
  2268. smc_state->levels[i].arbRefreshState =
  2269. (u8)(NISLANDS_DRIVER_STATE_ARB_INDEX + i);
  2270. if (ret)
  2271. return ret;
  2272. if (ni_pi->enable_power_containment)
  2273. smc_state->levels[i].displayWatermark =
  2274. (state->performance_levels[i].sclk < threshold) ?
  2275. PPSMC_DISPLAY_WATERMARK_LOW : PPSMC_DISPLAY_WATERMARK_HIGH;
  2276. else
  2277. smc_state->levels[i].displayWatermark = (i < 2) ?
  2278. PPSMC_DISPLAY_WATERMARK_LOW : PPSMC_DISPLAY_WATERMARK_HIGH;
  2279. if (eg_pi->dynamic_ac_timing)
  2280. smc_state->levels[i].ACIndex = NISLANDS_MCREGISTERTABLE_FIRST_DRIVERSTATE_SLOT + i;
  2281. else
  2282. smc_state->levels[i].ACIndex = 0;
  2283. smc_state->levelCount++;
  2284. }
  2285. rv770_write_smc_soft_register(rdev, NI_SMC_SOFT_REGISTER_watermark_threshold,
  2286. cpu_to_be32(threshold / 512));
  2287. ni_populate_smc_sp(rdev, radeon_state, smc_state);
  2288. ret = ni_populate_power_containment_values(rdev, radeon_state, smc_state);
  2289. if (ret)
  2290. ni_pi->enable_power_containment = false;
  2291. ret = ni_populate_sq_ramping_values(rdev, radeon_state, smc_state);
  2292. if (ret)
  2293. ni_pi->enable_sq_ramping = false;
  2294. return ni_populate_smc_t(rdev, radeon_state, smc_state);
  2295. }
  2296. static int ni_upload_sw_state(struct radeon_device *rdev,
  2297. struct radeon_ps *radeon_new_state)
  2298. {
  2299. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  2300. u16 address = pi->state_table_start +
  2301. offsetof(NISLANDS_SMC_STATETABLE, driverState);
  2302. u16 state_size = sizeof(NISLANDS_SMC_SWSTATE) +
  2303. ((NISLANDS_MAX_SMC_PERFORMANCE_LEVELS_PER_SWSTATE - 1) * sizeof(NISLANDS_SMC_HW_PERFORMANCE_LEVEL));
  2304. int ret;
  2305. NISLANDS_SMC_SWSTATE *smc_state = kzalloc(state_size, GFP_KERNEL);
  2306. if (smc_state == NULL)
  2307. return -ENOMEM;
  2308. ret = ni_convert_power_state_to_smc(rdev, radeon_new_state, smc_state);
  2309. if (ret)
  2310. goto done;
  2311. ret = rv770_copy_bytes_to_smc(rdev, address, (u8 *)smc_state, state_size, pi->sram_end);
  2312. done:
  2313. kfree(smc_state);
  2314. return ret;
  2315. }
  2316. static int ni_set_mc_special_registers(struct radeon_device *rdev,
  2317. struct ni_mc_reg_table *table)
  2318. {
  2319. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  2320. u8 i, j, k;
  2321. u32 temp_reg;
  2322. for (i = 0, j = table->last; i < table->last; i++) {
  2323. switch (table->mc_reg_address[i].s1) {
  2324. case MC_SEQ_MISC1 >> 2:
  2325. if (j >= SMC_NISLANDS_MC_REGISTER_ARRAY_SIZE)
  2326. return -EINVAL;
  2327. temp_reg = RREG32(MC_PMG_CMD_EMRS);
  2328. table->mc_reg_address[j].s1 = MC_PMG_CMD_EMRS >> 2;
  2329. table->mc_reg_address[j].s0 = MC_SEQ_PMG_CMD_EMRS_LP >> 2;
  2330. for (k = 0; k < table->num_entries; k++)
  2331. table->mc_reg_table_entry[k].mc_data[j] =
  2332. ((temp_reg & 0xffff0000)) |
  2333. ((table->mc_reg_table_entry[k].mc_data[i] & 0xffff0000) >> 16);
  2334. j++;
  2335. if (j >= SMC_NISLANDS_MC_REGISTER_ARRAY_SIZE)
  2336. return -EINVAL;
  2337. temp_reg = RREG32(MC_PMG_CMD_MRS);
  2338. table->mc_reg_address[j].s1 = MC_PMG_CMD_MRS >> 2;
  2339. table->mc_reg_address[j].s0 = MC_SEQ_PMG_CMD_MRS_LP >> 2;
  2340. for(k = 0; k < table->num_entries; k++) {
  2341. table->mc_reg_table_entry[k].mc_data[j] =
  2342. (temp_reg & 0xffff0000) |
  2343. (table->mc_reg_table_entry[k].mc_data[i] & 0x0000ffff);
  2344. if (!pi->mem_gddr5)
  2345. table->mc_reg_table_entry[k].mc_data[j] |= 0x100;
  2346. }
  2347. j++;
  2348. if (j > SMC_NISLANDS_MC_REGISTER_ARRAY_SIZE)
  2349. return -EINVAL;
  2350. break;
  2351. case MC_SEQ_RESERVE_M >> 2:
  2352. temp_reg = RREG32(MC_PMG_CMD_MRS1);
  2353. table->mc_reg_address[j].s1 = MC_PMG_CMD_MRS1 >> 2;
  2354. table->mc_reg_address[j].s0 = MC_SEQ_PMG_CMD_MRS1_LP >> 2;
  2355. for (k = 0; k < table->num_entries; k++)
  2356. table->mc_reg_table_entry[k].mc_data[j] =
  2357. (temp_reg & 0xffff0000) |
  2358. (table->mc_reg_table_entry[k].mc_data[i] & 0x0000ffff);
  2359. j++;
  2360. if (j > SMC_NISLANDS_MC_REGISTER_ARRAY_SIZE)
  2361. return -EINVAL;
  2362. break;
  2363. default:
  2364. break;
  2365. }
  2366. }
  2367. table->last = j;
  2368. return 0;
  2369. }
  2370. static bool ni_check_s0_mc_reg_index(u16 in_reg, u16 *out_reg)
  2371. {
  2372. bool result = true;
  2373. switch (in_reg) {
  2374. case MC_SEQ_RAS_TIMING >> 2:
  2375. *out_reg = MC_SEQ_RAS_TIMING_LP >> 2;
  2376. break;
  2377. case MC_SEQ_CAS_TIMING >> 2:
  2378. *out_reg = MC_SEQ_CAS_TIMING_LP >> 2;
  2379. break;
  2380. case MC_SEQ_MISC_TIMING >> 2:
  2381. *out_reg = MC_SEQ_MISC_TIMING_LP >> 2;
  2382. break;
  2383. case MC_SEQ_MISC_TIMING2 >> 2:
  2384. *out_reg = MC_SEQ_MISC_TIMING2_LP >> 2;
  2385. break;
  2386. case MC_SEQ_RD_CTL_D0 >> 2:
  2387. *out_reg = MC_SEQ_RD_CTL_D0_LP >> 2;
  2388. break;
  2389. case MC_SEQ_RD_CTL_D1 >> 2:
  2390. *out_reg = MC_SEQ_RD_CTL_D1_LP >> 2;
  2391. break;
  2392. case MC_SEQ_WR_CTL_D0 >> 2:
  2393. *out_reg = MC_SEQ_WR_CTL_D0_LP >> 2;
  2394. break;
  2395. case MC_SEQ_WR_CTL_D1 >> 2:
  2396. *out_reg = MC_SEQ_WR_CTL_D1_LP >> 2;
  2397. break;
  2398. case MC_PMG_CMD_EMRS >> 2:
  2399. *out_reg = MC_SEQ_PMG_CMD_EMRS_LP >> 2;
  2400. break;
  2401. case MC_PMG_CMD_MRS >> 2:
  2402. *out_reg = MC_SEQ_PMG_CMD_MRS_LP >> 2;
  2403. break;
  2404. case MC_PMG_CMD_MRS1 >> 2:
  2405. *out_reg = MC_SEQ_PMG_CMD_MRS1_LP >> 2;
  2406. break;
  2407. case MC_SEQ_PMG_TIMING >> 2:
  2408. *out_reg = MC_SEQ_PMG_TIMING_LP >> 2;
  2409. break;
  2410. case MC_PMG_CMD_MRS2 >> 2:
  2411. *out_reg = MC_SEQ_PMG_CMD_MRS2_LP >> 2;
  2412. break;
  2413. default:
  2414. result = false;
  2415. break;
  2416. }
  2417. return result;
  2418. }
  2419. static void ni_set_valid_flag(struct ni_mc_reg_table *table)
  2420. {
  2421. u8 i, j;
  2422. for (i = 0; i < table->last; i++) {
  2423. for (j = 1; j < table->num_entries; j++) {
  2424. if (table->mc_reg_table_entry[j-1].mc_data[i] != table->mc_reg_table_entry[j].mc_data[i]) {
  2425. table->valid_flag |= 1 << i;
  2426. break;
  2427. }
  2428. }
  2429. }
  2430. }
  2431. static void ni_set_s0_mc_reg_index(struct ni_mc_reg_table *table)
  2432. {
  2433. u32 i;
  2434. u16 address;
  2435. for (i = 0; i < table->last; i++)
  2436. table->mc_reg_address[i].s0 =
  2437. ni_check_s0_mc_reg_index(table->mc_reg_address[i].s1, &address) ?
  2438. address : table->mc_reg_address[i].s1;
  2439. }
  2440. static int ni_copy_vbios_mc_reg_table(struct atom_mc_reg_table *table,
  2441. struct ni_mc_reg_table *ni_table)
  2442. {
  2443. u8 i, j;
  2444. if (table->last > SMC_NISLANDS_MC_REGISTER_ARRAY_SIZE)
  2445. return -EINVAL;
  2446. if (table->num_entries > MAX_AC_TIMING_ENTRIES)
  2447. return -EINVAL;
  2448. for (i = 0; i < table->last; i++)
  2449. ni_table->mc_reg_address[i].s1 = table->mc_reg_address[i].s1;
  2450. ni_table->last = table->last;
  2451. for (i = 0; i < table->num_entries; i++) {
  2452. ni_table->mc_reg_table_entry[i].mclk_max =
  2453. table->mc_reg_table_entry[i].mclk_max;
  2454. for (j = 0; j < table->last; j++)
  2455. ni_table->mc_reg_table_entry[i].mc_data[j] =
  2456. table->mc_reg_table_entry[i].mc_data[j];
  2457. }
  2458. ni_table->num_entries = table->num_entries;
  2459. return 0;
  2460. }
  2461. static int ni_initialize_mc_reg_table(struct radeon_device *rdev)
  2462. {
  2463. struct ni_power_info *ni_pi = ni_get_pi(rdev);
  2464. int ret;
  2465. struct atom_mc_reg_table *table;
  2466. struct ni_mc_reg_table *ni_table = &ni_pi->mc_reg_table;
  2467. u8 module_index = rv770_get_memory_module_index(rdev);
  2468. table = kzalloc(sizeof(struct atom_mc_reg_table), GFP_KERNEL);
  2469. if (!table)
  2470. return -ENOMEM;
  2471. WREG32(MC_SEQ_RAS_TIMING_LP, RREG32(MC_SEQ_RAS_TIMING));
  2472. WREG32(MC_SEQ_CAS_TIMING_LP, RREG32(MC_SEQ_CAS_TIMING));
  2473. WREG32(MC_SEQ_MISC_TIMING_LP, RREG32(MC_SEQ_MISC_TIMING));
  2474. WREG32(MC_SEQ_MISC_TIMING2_LP, RREG32(MC_SEQ_MISC_TIMING2));
  2475. WREG32(MC_SEQ_PMG_CMD_EMRS_LP, RREG32(MC_PMG_CMD_EMRS));
  2476. WREG32(MC_SEQ_PMG_CMD_MRS_LP, RREG32(MC_PMG_CMD_MRS));
  2477. WREG32(MC_SEQ_PMG_CMD_MRS1_LP, RREG32(MC_PMG_CMD_MRS1));
  2478. WREG32(MC_SEQ_WR_CTL_D0_LP, RREG32(MC_SEQ_WR_CTL_D0));
  2479. WREG32(MC_SEQ_WR_CTL_D1_LP, RREG32(MC_SEQ_WR_CTL_D1));
  2480. WREG32(MC_SEQ_RD_CTL_D0_LP, RREG32(MC_SEQ_RD_CTL_D0));
  2481. WREG32(MC_SEQ_RD_CTL_D1_LP, RREG32(MC_SEQ_RD_CTL_D1));
  2482. WREG32(MC_SEQ_PMG_TIMING_LP, RREG32(MC_SEQ_PMG_TIMING));
  2483. WREG32(MC_SEQ_PMG_CMD_MRS2_LP, RREG32(MC_PMG_CMD_MRS2));
  2484. ret = radeon_atom_init_mc_reg_table(rdev, module_index, table);
  2485. if (ret)
  2486. goto init_mc_done;
  2487. ret = ni_copy_vbios_mc_reg_table(table, ni_table);
  2488. if (ret)
  2489. goto init_mc_done;
  2490. ni_set_s0_mc_reg_index(ni_table);
  2491. ret = ni_set_mc_special_registers(rdev, ni_table);
  2492. if (ret)
  2493. goto init_mc_done;
  2494. ni_set_valid_flag(ni_table);
  2495. init_mc_done:
  2496. kfree(table);
  2497. return ret;
  2498. }
  2499. static void ni_populate_mc_reg_addresses(struct radeon_device *rdev,
  2500. SMC_NIslands_MCRegisters *mc_reg_table)
  2501. {
  2502. struct ni_power_info *ni_pi = ni_get_pi(rdev);
  2503. u32 i, j;
  2504. for (i = 0, j = 0; j < ni_pi->mc_reg_table.last; j++) {
  2505. if (ni_pi->mc_reg_table.valid_flag & (1 << j)) {
  2506. if (i >= SMC_NISLANDS_MC_REGISTER_ARRAY_SIZE)
  2507. break;
  2508. mc_reg_table->address[i].s0 =
  2509. cpu_to_be16(ni_pi->mc_reg_table.mc_reg_address[j].s0);
  2510. mc_reg_table->address[i].s1 =
  2511. cpu_to_be16(ni_pi->mc_reg_table.mc_reg_address[j].s1);
  2512. i++;
  2513. }
  2514. }
  2515. mc_reg_table->last = (u8)i;
  2516. }
  2517. static void ni_convert_mc_registers(struct ni_mc_reg_entry *entry,
  2518. SMC_NIslands_MCRegisterSet *data,
  2519. u32 num_entries, u32 valid_flag)
  2520. {
  2521. u32 i, j;
  2522. for (i = 0, j = 0; j < num_entries; j++) {
  2523. if (valid_flag & (1 << j)) {
  2524. data->value[i] = cpu_to_be32(entry->mc_data[j]);
  2525. i++;
  2526. }
  2527. }
  2528. }
  2529. static void ni_convert_mc_reg_table_entry_to_smc(struct radeon_device *rdev,
  2530. struct rv7xx_pl *pl,
  2531. SMC_NIslands_MCRegisterSet *mc_reg_table_data)
  2532. {
  2533. struct ni_power_info *ni_pi = ni_get_pi(rdev);
  2534. u32 i = 0;
  2535. for (i = 0; i < ni_pi->mc_reg_table.num_entries; i++) {
  2536. if (pl->mclk <= ni_pi->mc_reg_table.mc_reg_table_entry[i].mclk_max)
  2537. break;
  2538. }
  2539. if ((i == ni_pi->mc_reg_table.num_entries) && (i > 0))
  2540. --i;
  2541. ni_convert_mc_registers(&ni_pi->mc_reg_table.mc_reg_table_entry[i],
  2542. mc_reg_table_data,
  2543. ni_pi->mc_reg_table.last,
  2544. ni_pi->mc_reg_table.valid_flag);
  2545. }
  2546. static void ni_convert_mc_reg_table_to_smc(struct radeon_device *rdev,
  2547. struct radeon_ps *radeon_state,
  2548. SMC_NIslands_MCRegisters *mc_reg_table)
  2549. {
  2550. struct ni_ps *state = ni_get_ps(radeon_state);
  2551. int i;
  2552. for (i = 0; i < state->performance_level_count; i++) {
  2553. ni_convert_mc_reg_table_entry_to_smc(rdev,
  2554. &state->performance_levels[i],
  2555. &mc_reg_table->data[NISLANDS_MCREGISTERTABLE_FIRST_DRIVERSTATE_SLOT + i]);
  2556. }
  2557. }
  2558. static int ni_populate_mc_reg_table(struct radeon_device *rdev,
  2559. struct radeon_ps *radeon_boot_state)
  2560. {
  2561. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  2562. struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
  2563. struct ni_power_info *ni_pi = ni_get_pi(rdev);
  2564. struct ni_ps *boot_state = ni_get_ps(radeon_boot_state);
  2565. SMC_NIslands_MCRegisters *mc_reg_table = &ni_pi->smc_mc_reg_table;
  2566. memset(mc_reg_table, 0, sizeof(SMC_NIslands_MCRegisters));
  2567. rv770_write_smc_soft_register(rdev, NI_SMC_SOFT_REGISTER_seq_index, 1);
  2568. ni_populate_mc_reg_addresses(rdev, mc_reg_table);
  2569. ni_convert_mc_reg_table_entry_to_smc(rdev, &boot_state->performance_levels[0],
  2570. &mc_reg_table->data[0]);
  2571. ni_convert_mc_registers(&ni_pi->mc_reg_table.mc_reg_table_entry[0],
  2572. &mc_reg_table->data[1],
  2573. ni_pi->mc_reg_table.last,
  2574. ni_pi->mc_reg_table.valid_flag);
  2575. ni_convert_mc_reg_table_to_smc(rdev, radeon_boot_state, mc_reg_table);
  2576. return rv770_copy_bytes_to_smc(rdev, eg_pi->mc_reg_table_start,
  2577. (u8 *)mc_reg_table,
  2578. sizeof(SMC_NIslands_MCRegisters),
  2579. pi->sram_end);
  2580. }
  2581. static int ni_upload_mc_reg_table(struct radeon_device *rdev,
  2582. struct radeon_ps *radeon_new_state)
  2583. {
  2584. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  2585. struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
  2586. struct ni_power_info *ni_pi = ni_get_pi(rdev);
  2587. struct ni_ps *ni_new_state = ni_get_ps(radeon_new_state);
  2588. SMC_NIslands_MCRegisters *mc_reg_table = &ni_pi->smc_mc_reg_table;
  2589. u16 address;
  2590. memset(mc_reg_table, 0, sizeof(SMC_NIslands_MCRegisters));
  2591. ni_convert_mc_reg_table_to_smc(rdev, radeon_new_state, mc_reg_table);
  2592. address = eg_pi->mc_reg_table_start +
  2593. (u16)offsetof(SMC_NIslands_MCRegisters, data[NISLANDS_MCREGISTERTABLE_FIRST_DRIVERSTATE_SLOT]);
  2594. return rv770_copy_bytes_to_smc(rdev, address,
  2595. (u8 *)&mc_reg_table->data[NISLANDS_MCREGISTERTABLE_FIRST_DRIVERSTATE_SLOT],
  2596. sizeof(SMC_NIslands_MCRegisterSet) * ni_new_state->performance_level_count,
  2597. pi->sram_end);
  2598. }
  2599. static int ni_init_driver_calculated_leakage_table(struct radeon_device *rdev,
  2600. PP_NIslands_CACTABLES *cac_tables)
  2601. {
  2602. struct ni_power_info *ni_pi = ni_get_pi(rdev);
  2603. struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
  2604. u32 leakage = 0;
  2605. unsigned int i, j, table_size;
  2606. s32 t;
  2607. u32 smc_leakage, max_leakage = 0;
  2608. u32 scaling_factor;
  2609. table_size = eg_pi->vddc_voltage_table.count;
  2610. if (SMC_NISLANDS_LKGE_LUT_NUM_OF_VOLT_ENTRIES < table_size)
  2611. table_size = SMC_NISLANDS_LKGE_LUT_NUM_OF_VOLT_ENTRIES;
  2612. scaling_factor = ni_get_smc_power_scaling_factor(rdev);
  2613. for (i = 0; i < SMC_NISLANDS_LKGE_LUT_NUM_OF_TEMP_ENTRIES; i++) {
  2614. for (j = 0; j < table_size; j++) {
  2615. t = (1000 * ((i + 1) * 8));
  2616. if (t < ni_pi->cac_data.leakage_minimum_temperature)
  2617. t = ni_pi->cac_data.leakage_minimum_temperature;
  2618. ni_calculate_leakage_for_v_and_t(rdev,
  2619. &ni_pi->cac_data.leakage_coefficients,
  2620. eg_pi->vddc_voltage_table.entries[j].value,
  2621. t,
  2622. ni_pi->cac_data.i_leakage,
  2623. &leakage);
  2624. smc_leakage = ni_scale_power_for_smc(leakage, scaling_factor) / 1000;
  2625. if (smc_leakage > max_leakage)
  2626. max_leakage = smc_leakage;
  2627. cac_tables->cac_lkge_lut[i][j] = cpu_to_be32(smc_leakage);
  2628. }
  2629. }
  2630. for (j = table_size; j < SMC_NISLANDS_LKGE_LUT_NUM_OF_VOLT_ENTRIES; j++) {
  2631. for (i = 0; i < SMC_NISLANDS_LKGE_LUT_NUM_OF_TEMP_ENTRIES; i++)
  2632. cac_tables->cac_lkge_lut[i][j] = cpu_to_be32(max_leakage);
  2633. }
  2634. return 0;
  2635. }
  2636. static int ni_init_simplified_leakage_table(struct radeon_device *rdev,
  2637. PP_NIslands_CACTABLES *cac_tables)
  2638. {
  2639. struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
  2640. struct radeon_cac_leakage_table *leakage_table =
  2641. &rdev->pm.dpm.dyn_state.cac_leakage_table;
  2642. u32 i, j, table_size;
  2643. u32 smc_leakage, max_leakage = 0;
  2644. u32 scaling_factor;
  2645. if (!leakage_table)
  2646. return -EINVAL;
  2647. table_size = leakage_table->count;
  2648. if (eg_pi->vddc_voltage_table.count != table_size)
  2649. table_size = (eg_pi->vddc_voltage_table.count < leakage_table->count) ?
  2650. eg_pi->vddc_voltage_table.count : leakage_table->count;
  2651. if (SMC_NISLANDS_LKGE_LUT_NUM_OF_VOLT_ENTRIES < table_size)
  2652. table_size = SMC_NISLANDS_LKGE_LUT_NUM_OF_VOLT_ENTRIES;
  2653. if (table_size == 0)
  2654. return -EINVAL;
  2655. scaling_factor = ni_get_smc_power_scaling_factor(rdev);
  2656. for (j = 0; j < table_size; j++) {
  2657. smc_leakage = leakage_table->entries[j].leakage;
  2658. if (smc_leakage > max_leakage)
  2659. max_leakage = smc_leakage;
  2660. for (i = 0; i < SMC_NISLANDS_LKGE_LUT_NUM_OF_TEMP_ENTRIES; i++)
  2661. cac_tables->cac_lkge_lut[i][j] =
  2662. cpu_to_be32(ni_scale_power_for_smc(smc_leakage, scaling_factor));
  2663. }
  2664. for (j = table_size; j < SMC_NISLANDS_LKGE_LUT_NUM_OF_VOLT_ENTRIES; j++) {
  2665. for (i = 0; i < SMC_NISLANDS_LKGE_LUT_NUM_OF_TEMP_ENTRIES; i++)
  2666. cac_tables->cac_lkge_lut[i][j] =
  2667. cpu_to_be32(ni_scale_power_for_smc(max_leakage, scaling_factor));
  2668. }
  2669. return 0;
  2670. }
  2671. static int ni_initialize_smc_cac_tables(struct radeon_device *rdev)
  2672. {
  2673. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  2674. struct ni_power_info *ni_pi = ni_get_pi(rdev);
  2675. PP_NIslands_CACTABLES *cac_tables = NULL;
  2676. int i, ret;
  2677. u32 reg;
  2678. if (ni_pi->enable_cac == false)
  2679. return 0;
  2680. cac_tables = kzalloc(sizeof(PP_NIslands_CACTABLES), GFP_KERNEL);
  2681. if (!cac_tables)
  2682. return -ENOMEM;
  2683. reg = RREG32(CG_CAC_CTRL) & ~(TID_CNT_MASK | TID_UNIT_MASK);
  2684. reg |= (TID_CNT(ni_pi->cac_weights->tid_cnt) |
  2685. TID_UNIT(ni_pi->cac_weights->tid_unit));
  2686. WREG32(CG_CAC_CTRL, reg);
  2687. for (i = 0; i < NISLANDS_DCCAC_MAX_LEVELS; i++)
  2688. ni_pi->dc_cac_table[i] = ni_pi->cac_weights->dc_cac[i];
  2689. for (i = 0; i < SMC_NISLANDS_BIF_LUT_NUM_OF_ENTRIES; i++)
  2690. cac_tables->cac_bif_lut[i] = ni_pi->cac_weights->pcie_cac[i];
  2691. ni_pi->cac_data.i_leakage = rdev->pm.dpm.cac_leakage;
  2692. ni_pi->cac_data.pwr_const = 0;
  2693. ni_pi->cac_data.dc_cac_value = ni_pi->dc_cac_table[NISLANDS_DCCAC_LEVEL_0];
  2694. ni_pi->cac_data.bif_cac_value = 0;
  2695. ni_pi->cac_data.mc_wr_weight = ni_pi->cac_weights->mc_write_weight;
  2696. ni_pi->cac_data.mc_rd_weight = ni_pi->cac_weights->mc_read_weight;
  2697. ni_pi->cac_data.allow_ovrflw = 0;
  2698. ni_pi->cac_data.l2num_win_tdp = ni_pi->lta_window_size;
  2699. ni_pi->cac_data.num_win_tdp = 0;
  2700. ni_pi->cac_data.lts_truncate_n = ni_pi->lts_truncate;
  2701. if (ni_pi->driver_calculate_cac_leakage)
  2702. ret = ni_init_driver_calculated_leakage_table(rdev, cac_tables);
  2703. else
  2704. ret = ni_init_simplified_leakage_table(rdev, cac_tables);
  2705. if (ret)
  2706. goto done_free;
  2707. cac_tables->pwr_const = cpu_to_be32(ni_pi->cac_data.pwr_const);
  2708. cac_tables->dc_cacValue = cpu_to_be32(ni_pi->cac_data.dc_cac_value);
  2709. cac_tables->bif_cacValue = cpu_to_be32(ni_pi->cac_data.bif_cac_value);
  2710. cac_tables->AllowOvrflw = ni_pi->cac_data.allow_ovrflw;
  2711. cac_tables->MCWrWeight = ni_pi->cac_data.mc_wr_weight;
  2712. cac_tables->MCRdWeight = ni_pi->cac_data.mc_rd_weight;
  2713. cac_tables->numWin_TDP = ni_pi->cac_data.num_win_tdp;
  2714. cac_tables->l2numWin_TDP = ni_pi->cac_data.l2num_win_tdp;
  2715. cac_tables->lts_truncate_n = ni_pi->cac_data.lts_truncate_n;
  2716. ret = rv770_copy_bytes_to_smc(rdev, ni_pi->cac_table_start, (u8 *)cac_tables,
  2717. sizeof(PP_NIslands_CACTABLES), pi->sram_end);
  2718. done_free:
  2719. if (ret) {
  2720. ni_pi->enable_cac = false;
  2721. ni_pi->enable_power_containment = false;
  2722. }
  2723. kfree(cac_tables);
  2724. return 0;
  2725. }
  2726. static int ni_initialize_hardware_cac_manager(struct radeon_device *rdev)
  2727. {
  2728. struct ni_power_info *ni_pi = ni_get_pi(rdev);
  2729. u32 reg;
  2730. if (!ni_pi->enable_cac ||
  2731. !ni_pi->cac_configuration_required)
  2732. return 0;
  2733. if (ni_pi->cac_weights == NULL)
  2734. return -EINVAL;
  2735. reg = RREG32_CG(CG_CAC_REGION_1_WEIGHT_0) & ~(WEIGHT_TCP_SIG0_MASK |
  2736. WEIGHT_TCP_SIG1_MASK |
  2737. WEIGHT_TA_SIG_MASK);
  2738. reg |= (WEIGHT_TCP_SIG0(ni_pi->cac_weights->weight_tcp_sig0) |
  2739. WEIGHT_TCP_SIG1(ni_pi->cac_weights->weight_tcp_sig1) |
  2740. WEIGHT_TA_SIG(ni_pi->cac_weights->weight_ta_sig));
  2741. WREG32_CG(CG_CAC_REGION_1_WEIGHT_0, reg);
  2742. reg = RREG32_CG(CG_CAC_REGION_1_WEIGHT_1) & ~(WEIGHT_TCC_EN0_MASK |
  2743. WEIGHT_TCC_EN1_MASK |
  2744. WEIGHT_TCC_EN2_MASK);
  2745. reg |= (WEIGHT_TCC_EN0(ni_pi->cac_weights->weight_tcc_en0) |
  2746. WEIGHT_TCC_EN1(ni_pi->cac_weights->weight_tcc_en1) |
  2747. WEIGHT_TCC_EN2(ni_pi->cac_weights->weight_tcc_en2));
  2748. WREG32_CG(CG_CAC_REGION_1_WEIGHT_1, reg);
  2749. reg = RREG32_CG(CG_CAC_REGION_2_WEIGHT_0) & ~(WEIGHT_CB_EN0_MASK |
  2750. WEIGHT_CB_EN1_MASK |
  2751. WEIGHT_CB_EN2_MASK |
  2752. WEIGHT_CB_EN3_MASK);
  2753. reg |= (WEIGHT_CB_EN0(ni_pi->cac_weights->weight_cb_en0) |
  2754. WEIGHT_CB_EN1(ni_pi->cac_weights->weight_cb_en1) |
  2755. WEIGHT_CB_EN2(ni_pi->cac_weights->weight_cb_en2) |
  2756. WEIGHT_CB_EN3(ni_pi->cac_weights->weight_cb_en3));
  2757. WREG32_CG(CG_CAC_REGION_2_WEIGHT_0, reg);
  2758. reg = RREG32_CG(CG_CAC_REGION_2_WEIGHT_1) & ~(WEIGHT_DB_SIG0_MASK |
  2759. WEIGHT_DB_SIG1_MASK |
  2760. WEIGHT_DB_SIG2_MASK |
  2761. WEIGHT_DB_SIG3_MASK);
  2762. reg |= (WEIGHT_DB_SIG0(ni_pi->cac_weights->weight_db_sig0) |
  2763. WEIGHT_DB_SIG1(ni_pi->cac_weights->weight_db_sig1) |
  2764. WEIGHT_DB_SIG2(ni_pi->cac_weights->weight_db_sig2) |
  2765. WEIGHT_DB_SIG3(ni_pi->cac_weights->weight_db_sig3));
  2766. WREG32_CG(CG_CAC_REGION_2_WEIGHT_1, reg);
  2767. reg = RREG32_CG(CG_CAC_REGION_2_WEIGHT_2) & ~(WEIGHT_SXM_SIG0_MASK |
  2768. WEIGHT_SXM_SIG1_MASK |
  2769. WEIGHT_SXM_SIG2_MASK |
  2770. WEIGHT_SXS_SIG0_MASK |
  2771. WEIGHT_SXS_SIG1_MASK);
  2772. reg |= (WEIGHT_SXM_SIG0(ni_pi->cac_weights->weight_sxm_sig0) |
  2773. WEIGHT_SXM_SIG1(ni_pi->cac_weights->weight_sxm_sig1) |
  2774. WEIGHT_SXM_SIG2(ni_pi->cac_weights->weight_sxm_sig2) |
  2775. WEIGHT_SXS_SIG0(ni_pi->cac_weights->weight_sxs_sig0) |
  2776. WEIGHT_SXS_SIG1(ni_pi->cac_weights->weight_sxs_sig1));
  2777. WREG32_CG(CG_CAC_REGION_2_WEIGHT_2, reg);
  2778. reg = RREG32_CG(CG_CAC_REGION_3_WEIGHT_0) & ~(WEIGHT_XBR_0_MASK |
  2779. WEIGHT_XBR_1_MASK |
  2780. WEIGHT_XBR_2_MASK |
  2781. WEIGHT_SPI_SIG0_MASK);
  2782. reg |= (WEIGHT_XBR_0(ni_pi->cac_weights->weight_xbr_0) |
  2783. WEIGHT_XBR_1(ni_pi->cac_weights->weight_xbr_1) |
  2784. WEIGHT_XBR_2(ni_pi->cac_weights->weight_xbr_2) |
  2785. WEIGHT_SPI_SIG0(ni_pi->cac_weights->weight_spi_sig0));
  2786. WREG32_CG(CG_CAC_REGION_3_WEIGHT_0, reg);
  2787. reg = RREG32_CG(CG_CAC_REGION_3_WEIGHT_1) & ~(WEIGHT_SPI_SIG1_MASK |
  2788. WEIGHT_SPI_SIG2_MASK |
  2789. WEIGHT_SPI_SIG3_MASK |
  2790. WEIGHT_SPI_SIG4_MASK |
  2791. WEIGHT_SPI_SIG5_MASK);
  2792. reg |= (WEIGHT_SPI_SIG1(ni_pi->cac_weights->weight_spi_sig1) |
  2793. WEIGHT_SPI_SIG2(ni_pi->cac_weights->weight_spi_sig2) |
  2794. WEIGHT_SPI_SIG3(ni_pi->cac_weights->weight_spi_sig3) |
  2795. WEIGHT_SPI_SIG4(ni_pi->cac_weights->weight_spi_sig4) |
  2796. WEIGHT_SPI_SIG5(ni_pi->cac_weights->weight_spi_sig5));
  2797. WREG32_CG(CG_CAC_REGION_3_WEIGHT_1, reg);
  2798. reg = RREG32_CG(CG_CAC_REGION_4_WEIGHT_0) & ~(WEIGHT_LDS_SIG0_MASK |
  2799. WEIGHT_LDS_SIG1_MASK |
  2800. WEIGHT_SC_MASK);
  2801. reg |= (WEIGHT_LDS_SIG0(ni_pi->cac_weights->weight_lds_sig0) |
  2802. WEIGHT_LDS_SIG1(ni_pi->cac_weights->weight_lds_sig1) |
  2803. WEIGHT_SC(ni_pi->cac_weights->weight_sc));
  2804. WREG32_CG(CG_CAC_REGION_4_WEIGHT_0, reg);
  2805. reg = RREG32_CG(CG_CAC_REGION_4_WEIGHT_1) & ~(WEIGHT_BIF_MASK |
  2806. WEIGHT_CP_MASK |
  2807. WEIGHT_PA_SIG0_MASK |
  2808. WEIGHT_PA_SIG1_MASK |
  2809. WEIGHT_VGT_SIG0_MASK);
  2810. reg |= (WEIGHT_BIF(ni_pi->cac_weights->weight_bif) |
  2811. WEIGHT_CP(ni_pi->cac_weights->weight_cp) |
  2812. WEIGHT_PA_SIG0(ni_pi->cac_weights->weight_pa_sig0) |
  2813. WEIGHT_PA_SIG1(ni_pi->cac_weights->weight_pa_sig1) |
  2814. WEIGHT_VGT_SIG0(ni_pi->cac_weights->weight_vgt_sig0));
  2815. WREG32_CG(CG_CAC_REGION_4_WEIGHT_1, reg);
  2816. reg = RREG32_CG(CG_CAC_REGION_4_WEIGHT_2) & ~(WEIGHT_VGT_SIG1_MASK |
  2817. WEIGHT_VGT_SIG2_MASK |
  2818. WEIGHT_DC_SIG0_MASK |
  2819. WEIGHT_DC_SIG1_MASK |
  2820. WEIGHT_DC_SIG2_MASK);
  2821. reg |= (WEIGHT_VGT_SIG1(ni_pi->cac_weights->weight_vgt_sig1) |
  2822. WEIGHT_VGT_SIG2(ni_pi->cac_weights->weight_vgt_sig2) |
  2823. WEIGHT_DC_SIG0(ni_pi->cac_weights->weight_dc_sig0) |
  2824. WEIGHT_DC_SIG1(ni_pi->cac_weights->weight_dc_sig1) |
  2825. WEIGHT_DC_SIG2(ni_pi->cac_weights->weight_dc_sig2));
  2826. WREG32_CG(CG_CAC_REGION_4_WEIGHT_2, reg);
  2827. reg = RREG32_CG(CG_CAC_REGION_4_WEIGHT_3) & ~(WEIGHT_DC_SIG3_MASK |
  2828. WEIGHT_UVD_SIG0_MASK |
  2829. WEIGHT_UVD_SIG1_MASK |
  2830. WEIGHT_SPARE0_MASK |
  2831. WEIGHT_SPARE1_MASK);
  2832. reg |= (WEIGHT_DC_SIG3(ni_pi->cac_weights->weight_dc_sig3) |
  2833. WEIGHT_UVD_SIG0(ni_pi->cac_weights->weight_uvd_sig0) |
  2834. WEIGHT_UVD_SIG1(ni_pi->cac_weights->weight_uvd_sig1) |
  2835. WEIGHT_SPARE0(ni_pi->cac_weights->weight_spare0) |
  2836. WEIGHT_SPARE1(ni_pi->cac_weights->weight_spare1));
  2837. WREG32_CG(CG_CAC_REGION_4_WEIGHT_3, reg);
  2838. reg = RREG32_CG(CG_CAC_REGION_5_WEIGHT_0) & ~(WEIGHT_SQ_VSP_MASK |
  2839. WEIGHT_SQ_VSP0_MASK);
  2840. reg |= (WEIGHT_SQ_VSP(ni_pi->cac_weights->weight_sq_vsp) |
  2841. WEIGHT_SQ_VSP0(ni_pi->cac_weights->weight_sq_vsp0));
  2842. WREG32_CG(CG_CAC_REGION_5_WEIGHT_0, reg);
  2843. reg = RREG32_CG(CG_CAC_REGION_5_WEIGHT_1) & ~(WEIGHT_SQ_GPR_MASK);
  2844. reg |= WEIGHT_SQ_GPR(ni_pi->cac_weights->weight_sq_gpr);
  2845. WREG32_CG(CG_CAC_REGION_5_WEIGHT_1, reg);
  2846. reg = RREG32_CG(CG_CAC_REGION_4_OVERRIDE_4) & ~(OVR_MODE_SPARE_0_MASK |
  2847. OVR_VAL_SPARE_0_MASK |
  2848. OVR_MODE_SPARE_1_MASK |
  2849. OVR_VAL_SPARE_1_MASK);
  2850. reg |= (OVR_MODE_SPARE_0(ni_pi->cac_weights->ovr_mode_spare_0) |
  2851. OVR_VAL_SPARE_0(ni_pi->cac_weights->ovr_val_spare_0) |
  2852. OVR_MODE_SPARE_1(ni_pi->cac_weights->ovr_mode_spare_1) |
  2853. OVR_VAL_SPARE_1(ni_pi->cac_weights->ovr_val_spare_1));
  2854. WREG32_CG(CG_CAC_REGION_4_OVERRIDE_4, reg);
  2855. reg = RREG32(SQ_CAC_THRESHOLD) & ~(VSP_MASK |
  2856. VSP0_MASK |
  2857. GPR_MASK);
  2858. reg |= (VSP(ni_pi->cac_weights->vsp) |
  2859. VSP0(ni_pi->cac_weights->vsp0) |
  2860. GPR(ni_pi->cac_weights->gpr));
  2861. WREG32(SQ_CAC_THRESHOLD, reg);
  2862. reg = (MCDW_WR_ENABLE |
  2863. MCDX_WR_ENABLE |
  2864. MCDY_WR_ENABLE |
  2865. MCDZ_WR_ENABLE |
  2866. INDEX(0x09D4));
  2867. WREG32(MC_CG_CONFIG, reg);
  2868. reg = (READ_WEIGHT(ni_pi->cac_weights->mc_read_weight) |
  2869. WRITE_WEIGHT(ni_pi->cac_weights->mc_write_weight) |
  2870. ALLOW_OVERFLOW);
  2871. WREG32(MC_CG_DATAPORT, reg);
  2872. return 0;
  2873. }
  2874. static int ni_enable_smc_cac(struct radeon_device *rdev,
  2875. struct radeon_ps *radeon_new_state,
  2876. bool enable)
  2877. {
  2878. struct ni_power_info *ni_pi = ni_get_pi(rdev);
  2879. int ret = 0;
  2880. PPSMC_Result smc_result;
  2881. if (ni_pi->enable_cac) {
  2882. if (enable) {
  2883. if (!r600_is_uvd_state(radeon_new_state->class, radeon_new_state->class2)) {
  2884. smc_result = rv770_send_msg_to_smc(rdev, PPSMC_MSG_CollectCAC_PowerCorreln);
  2885. if (ni_pi->support_cac_long_term_average) {
  2886. smc_result = rv770_send_msg_to_smc(rdev, PPSMC_CACLongTermAvgEnable);
  2887. if (PPSMC_Result_OK != smc_result)
  2888. ni_pi->support_cac_long_term_average = false;
  2889. }
  2890. smc_result = rv770_send_msg_to_smc(rdev, PPSMC_MSG_EnableCac);
  2891. if (PPSMC_Result_OK != smc_result)
  2892. ret = -EINVAL;
  2893. ni_pi->cac_enabled = (PPSMC_Result_OK == smc_result) ? true : false;
  2894. }
  2895. } else if (ni_pi->cac_enabled) {
  2896. smc_result = rv770_send_msg_to_smc(rdev, PPSMC_MSG_DisableCac);
  2897. ni_pi->cac_enabled = false;
  2898. if (ni_pi->support_cac_long_term_average) {
  2899. smc_result = rv770_send_msg_to_smc(rdev, PPSMC_CACLongTermAvgDisable);
  2900. if (PPSMC_Result_OK != smc_result)
  2901. ni_pi->support_cac_long_term_average = false;
  2902. }
  2903. }
  2904. }
  2905. return ret;
  2906. }
  2907. static int ni_pcie_performance_request(struct radeon_device *rdev,
  2908. u8 perf_req, bool advertise)
  2909. {
  2910. #if defined(CONFIG_ACPI)
  2911. struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
  2912. if ((perf_req == PCIE_PERF_REQ_PECI_GEN1) ||
  2913. (perf_req == PCIE_PERF_REQ_PECI_GEN2)) {
  2914. if (eg_pi->pcie_performance_request_registered == false)
  2915. radeon_acpi_pcie_notify_device_ready(rdev);
  2916. eg_pi->pcie_performance_request_registered = true;
  2917. return radeon_acpi_pcie_performance_request(rdev, perf_req, advertise);
  2918. } else if ((perf_req == PCIE_PERF_REQ_REMOVE_REGISTRY) &&
  2919. eg_pi->pcie_performance_request_registered) {
  2920. eg_pi->pcie_performance_request_registered = false;
  2921. return radeon_acpi_pcie_performance_request(rdev, perf_req, advertise);
  2922. }
  2923. #endif
  2924. return 0;
  2925. }
  2926. static int ni_advertise_gen2_capability(struct radeon_device *rdev)
  2927. {
  2928. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  2929. u32 tmp;
  2930. tmp = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  2931. if ((tmp & LC_OTHER_SIDE_EVER_SENT_GEN2) &&
  2932. (tmp & LC_OTHER_SIDE_SUPPORTS_GEN2))
  2933. pi->pcie_gen2 = true;
  2934. else
  2935. pi->pcie_gen2 = false;
  2936. if (!pi->pcie_gen2)
  2937. ni_pcie_performance_request(rdev, PCIE_PERF_REQ_PECI_GEN2, true);
  2938. return 0;
  2939. }
  2940. static void ni_enable_bif_dynamic_pcie_gen2(struct radeon_device *rdev,
  2941. bool enable)
  2942. {
  2943. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  2944. u32 tmp, bif;
  2945. tmp = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  2946. if ((tmp & LC_OTHER_SIDE_EVER_SENT_GEN2) &&
  2947. (tmp & LC_OTHER_SIDE_SUPPORTS_GEN2)) {
  2948. if (enable) {
  2949. if (!pi->boot_in_gen2) {
  2950. bif = RREG32(CG_BIF_REQ_AND_RSP) & ~CG_CLIENT_REQ_MASK;
  2951. bif |= CG_CLIENT_REQ(0xd);
  2952. WREG32(CG_BIF_REQ_AND_RSP, bif);
  2953. }
  2954. tmp &= ~LC_HW_VOLTAGE_IF_CONTROL_MASK;
  2955. tmp |= LC_HW_VOLTAGE_IF_CONTROL(1);
  2956. tmp |= LC_GEN2_EN_STRAP;
  2957. tmp |= LC_CLR_FAILED_SPD_CHANGE_CNT;
  2958. WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, tmp);
  2959. udelay(10);
  2960. tmp &= ~LC_CLR_FAILED_SPD_CHANGE_CNT;
  2961. WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, tmp);
  2962. } else {
  2963. if (!pi->boot_in_gen2) {
  2964. bif = RREG32(CG_BIF_REQ_AND_RSP) & ~CG_CLIENT_REQ_MASK;
  2965. bif |= CG_CLIENT_REQ(0xd);
  2966. WREG32(CG_BIF_REQ_AND_RSP, bif);
  2967. tmp &= ~LC_HW_VOLTAGE_IF_CONTROL_MASK;
  2968. tmp &= ~LC_GEN2_EN_STRAP;
  2969. }
  2970. WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, tmp);
  2971. }
  2972. }
  2973. }
  2974. static void ni_enable_dynamic_pcie_gen2(struct radeon_device *rdev,
  2975. bool enable)
  2976. {
  2977. ni_enable_bif_dynamic_pcie_gen2(rdev, enable);
  2978. if (enable)
  2979. WREG32_P(GENERAL_PWRMGT, ENABLE_GEN2PCIE, ~ENABLE_GEN2PCIE);
  2980. else
  2981. WREG32_P(GENERAL_PWRMGT, 0, ~ENABLE_GEN2PCIE);
  2982. }
  2983. void ni_set_uvd_clock_before_set_eng_clock(struct radeon_device *rdev,
  2984. struct radeon_ps *new_ps,
  2985. struct radeon_ps *old_ps)
  2986. {
  2987. struct ni_ps *new_state = ni_get_ps(new_ps);
  2988. struct ni_ps *current_state = ni_get_ps(old_ps);
  2989. if ((new_ps->vclk == old_ps->vclk) &&
  2990. (new_ps->dclk == old_ps->dclk))
  2991. return;
  2992. if (new_state->performance_levels[new_state->performance_level_count - 1].sclk >=
  2993. current_state->performance_levels[current_state->performance_level_count - 1].sclk)
  2994. return;
  2995. radeon_set_uvd_clocks(rdev, new_ps->vclk, new_ps->dclk);
  2996. }
  2997. void ni_set_uvd_clock_after_set_eng_clock(struct radeon_device *rdev,
  2998. struct radeon_ps *new_ps,
  2999. struct radeon_ps *old_ps)
  3000. {
  3001. struct ni_ps *new_state = ni_get_ps(new_ps);
  3002. struct ni_ps *current_state = ni_get_ps(old_ps);
  3003. if ((new_ps->vclk == old_ps->vclk) &&
  3004. (new_ps->dclk == old_ps->dclk))
  3005. return;
  3006. if (new_state->performance_levels[new_state->performance_level_count - 1].sclk <
  3007. current_state->performance_levels[current_state->performance_level_count - 1].sclk)
  3008. return;
  3009. radeon_set_uvd_clocks(rdev, new_ps->vclk, new_ps->dclk);
  3010. }
  3011. void ni_dpm_setup_asic(struct radeon_device *rdev)
  3012. {
  3013. struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
  3014. int r;
  3015. r = ni_mc_load_microcode(rdev);
  3016. if (r)
  3017. DRM_ERROR("Failed to load MC firmware!\n");
  3018. ni_read_clock_registers(rdev);
  3019. btc_read_arb_registers(rdev);
  3020. rv770_get_memory_type(rdev);
  3021. if (eg_pi->pcie_performance_request)
  3022. ni_advertise_gen2_capability(rdev);
  3023. rv770_get_pcie_gen2_status(rdev);
  3024. rv770_enable_acpi_pm(rdev);
  3025. }
  3026. void ni_update_current_ps(struct radeon_device *rdev,
  3027. struct radeon_ps *rps)
  3028. {
  3029. struct ni_ps *new_ps = ni_get_ps(rps);
  3030. struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
  3031. struct ni_power_info *ni_pi = ni_get_pi(rdev);
  3032. eg_pi->current_rps = *rps;
  3033. ni_pi->current_ps = *new_ps;
  3034. eg_pi->current_rps.ps_priv = &ni_pi->current_ps;
  3035. }
  3036. void ni_update_requested_ps(struct radeon_device *rdev,
  3037. struct radeon_ps *rps)
  3038. {
  3039. struct ni_ps *new_ps = ni_get_ps(rps);
  3040. struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
  3041. struct ni_power_info *ni_pi = ni_get_pi(rdev);
  3042. eg_pi->requested_rps = *rps;
  3043. ni_pi->requested_ps = *new_ps;
  3044. eg_pi->requested_rps.ps_priv = &ni_pi->requested_ps;
  3045. }
  3046. int ni_dpm_enable(struct radeon_device *rdev)
  3047. {
  3048. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  3049. struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
  3050. struct radeon_ps *boot_ps = rdev->pm.dpm.boot_ps;
  3051. int ret;
  3052. if (pi->gfx_clock_gating)
  3053. ni_cg_clockgating_default(rdev);
  3054. if (btc_dpm_enabled(rdev))
  3055. return -EINVAL;
  3056. if (pi->mg_clock_gating)
  3057. ni_mg_clockgating_default(rdev);
  3058. if (eg_pi->ls_clock_gating)
  3059. ni_ls_clockgating_default(rdev);
  3060. if (pi->voltage_control) {
  3061. rv770_enable_voltage_control(rdev, true);
  3062. ret = cypress_construct_voltage_tables(rdev);
  3063. if (ret) {
  3064. DRM_ERROR("cypress_construct_voltage_tables failed\n");
  3065. return ret;
  3066. }
  3067. }
  3068. if (eg_pi->dynamic_ac_timing) {
  3069. ret = ni_initialize_mc_reg_table(rdev);
  3070. if (ret)
  3071. eg_pi->dynamic_ac_timing = false;
  3072. }
  3073. if (pi->dynamic_ss)
  3074. cypress_enable_spread_spectrum(rdev, true);
  3075. if (pi->thermal_protection)
  3076. rv770_enable_thermal_protection(rdev, true);
  3077. rv770_setup_bsp(rdev);
  3078. rv770_program_git(rdev);
  3079. rv770_program_tp(rdev);
  3080. rv770_program_tpp(rdev);
  3081. rv770_program_sstp(rdev);
  3082. cypress_enable_display_gap(rdev);
  3083. rv770_program_vc(rdev);
  3084. if (pi->dynamic_pcie_gen2)
  3085. ni_enable_dynamic_pcie_gen2(rdev, true);
  3086. ret = rv770_upload_firmware(rdev);
  3087. if (ret) {
  3088. DRM_ERROR("rv770_upload_firmware failed\n");
  3089. return ret;
  3090. }
  3091. ret = ni_process_firmware_header(rdev);
  3092. if (ret) {
  3093. DRM_ERROR("ni_process_firmware_header failed\n");
  3094. return ret;
  3095. }
  3096. ret = ni_initial_switch_from_arb_f0_to_f1(rdev);
  3097. if (ret) {
  3098. DRM_ERROR("ni_initial_switch_from_arb_f0_to_f1 failed\n");
  3099. return ret;
  3100. }
  3101. ret = ni_init_smc_table(rdev);
  3102. if (ret) {
  3103. DRM_ERROR("ni_init_smc_table failed\n");
  3104. return ret;
  3105. }
  3106. ret = ni_init_smc_spll_table(rdev);
  3107. if (ret) {
  3108. DRM_ERROR("ni_init_smc_spll_table failed\n");
  3109. return ret;
  3110. }
  3111. ret = ni_init_arb_table_index(rdev);
  3112. if (ret) {
  3113. DRM_ERROR("ni_init_arb_table_index failed\n");
  3114. return ret;
  3115. }
  3116. if (eg_pi->dynamic_ac_timing) {
  3117. ret = ni_populate_mc_reg_table(rdev, boot_ps);
  3118. if (ret) {
  3119. DRM_ERROR("ni_populate_mc_reg_table failed\n");
  3120. return ret;
  3121. }
  3122. }
  3123. ret = ni_initialize_smc_cac_tables(rdev);
  3124. if (ret) {
  3125. DRM_ERROR("ni_initialize_smc_cac_tables failed\n");
  3126. return ret;
  3127. }
  3128. ret = ni_initialize_hardware_cac_manager(rdev);
  3129. if (ret) {
  3130. DRM_ERROR("ni_initialize_hardware_cac_manager failed\n");
  3131. return ret;
  3132. }
  3133. ret = ni_populate_smc_tdp_limits(rdev, boot_ps);
  3134. if (ret) {
  3135. DRM_ERROR("ni_populate_smc_tdp_limits failed\n");
  3136. return ret;
  3137. }
  3138. ni_program_response_times(rdev);
  3139. r7xx_start_smc(rdev);
  3140. ret = cypress_notify_smc_display_change(rdev, false);
  3141. if (ret) {
  3142. DRM_ERROR("cypress_notify_smc_display_change failed\n");
  3143. return ret;
  3144. }
  3145. cypress_enable_sclk_control(rdev, true);
  3146. if (eg_pi->memory_transition)
  3147. cypress_enable_mclk_control(rdev, true);
  3148. cypress_start_dpm(rdev);
  3149. if (pi->gfx_clock_gating)
  3150. ni_gfx_clockgating_enable(rdev, true);
  3151. if (pi->mg_clock_gating)
  3152. ni_mg_clockgating_enable(rdev, true);
  3153. if (eg_pi->ls_clock_gating)
  3154. ni_ls_clockgating_enable(rdev, true);
  3155. rv770_enable_auto_throttle_source(rdev, RADEON_DPM_AUTO_THROTTLE_SRC_THERMAL, true);
  3156. ni_update_current_ps(rdev, boot_ps);
  3157. return 0;
  3158. }
  3159. void ni_dpm_disable(struct radeon_device *rdev)
  3160. {
  3161. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  3162. struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
  3163. struct radeon_ps *boot_ps = rdev->pm.dpm.boot_ps;
  3164. if (!btc_dpm_enabled(rdev))
  3165. return;
  3166. rv770_clear_vc(rdev);
  3167. if (pi->thermal_protection)
  3168. rv770_enable_thermal_protection(rdev, false);
  3169. ni_enable_power_containment(rdev, boot_ps, false);
  3170. ni_enable_smc_cac(rdev, boot_ps, false);
  3171. cypress_enable_spread_spectrum(rdev, false);
  3172. rv770_enable_auto_throttle_source(rdev, RADEON_DPM_AUTO_THROTTLE_SRC_THERMAL, false);
  3173. if (pi->dynamic_pcie_gen2)
  3174. ni_enable_dynamic_pcie_gen2(rdev, false);
  3175. if (rdev->irq.installed &&
  3176. r600_is_internal_thermal_sensor(rdev->pm.int_thermal_type)) {
  3177. rdev->irq.dpm_thermal = false;
  3178. radeon_irq_set(rdev);
  3179. }
  3180. if (pi->gfx_clock_gating)
  3181. ni_gfx_clockgating_enable(rdev, false);
  3182. if (pi->mg_clock_gating)
  3183. ni_mg_clockgating_enable(rdev, false);
  3184. if (eg_pi->ls_clock_gating)
  3185. ni_ls_clockgating_enable(rdev, false);
  3186. ni_stop_dpm(rdev);
  3187. btc_reset_to_default(rdev);
  3188. ni_stop_smc(rdev);
  3189. ni_force_switch_to_arb_f0(rdev);
  3190. ni_update_current_ps(rdev, boot_ps);
  3191. }
  3192. static int ni_power_control_set_level(struct radeon_device *rdev)
  3193. {
  3194. struct radeon_ps *new_ps = rdev->pm.dpm.requested_ps;
  3195. int ret;
  3196. ret = ni_restrict_performance_levels_before_switch(rdev);
  3197. if (ret)
  3198. return ret;
  3199. ret = rv770_halt_smc(rdev);
  3200. if (ret)
  3201. return ret;
  3202. ret = ni_populate_smc_tdp_limits(rdev, new_ps);
  3203. if (ret)
  3204. return ret;
  3205. ret = rv770_resume_smc(rdev);
  3206. if (ret)
  3207. return ret;
  3208. ret = rv770_set_sw_state(rdev);
  3209. if (ret)
  3210. return ret;
  3211. return 0;
  3212. }
  3213. int ni_dpm_pre_set_power_state(struct radeon_device *rdev)
  3214. {
  3215. struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
  3216. struct radeon_ps requested_ps = *rdev->pm.dpm.requested_ps;
  3217. struct radeon_ps *new_ps = &requested_ps;
  3218. ni_update_requested_ps(rdev, new_ps);
  3219. ni_apply_state_adjust_rules(rdev, &eg_pi->requested_rps);
  3220. return 0;
  3221. }
  3222. int ni_dpm_set_power_state(struct radeon_device *rdev)
  3223. {
  3224. struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
  3225. struct radeon_ps *new_ps = &eg_pi->requested_rps;
  3226. struct radeon_ps *old_ps = &eg_pi->current_rps;
  3227. int ret;
  3228. ret = ni_restrict_performance_levels_before_switch(rdev);
  3229. if (ret) {
  3230. DRM_ERROR("ni_restrict_performance_levels_before_switch failed\n");
  3231. return ret;
  3232. }
  3233. ni_set_uvd_clock_before_set_eng_clock(rdev, new_ps, old_ps);
  3234. ret = ni_enable_power_containment(rdev, new_ps, false);
  3235. if (ret) {
  3236. DRM_ERROR("ni_enable_power_containment failed\n");
  3237. return ret;
  3238. }
  3239. ret = ni_enable_smc_cac(rdev, new_ps, false);
  3240. if (ret) {
  3241. DRM_ERROR("ni_enable_smc_cac failed\n");
  3242. return ret;
  3243. }
  3244. ret = rv770_halt_smc(rdev);
  3245. if (ret) {
  3246. DRM_ERROR("rv770_halt_smc failed\n");
  3247. return ret;
  3248. }
  3249. if (eg_pi->smu_uvd_hs)
  3250. btc_notify_uvd_to_smc(rdev, new_ps);
  3251. ret = ni_upload_sw_state(rdev, new_ps);
  3252. if (ret) {
  3253. DRM_ERROR("ni_upload_sw_state failed\n");
  3254. return ret;
  3255. }
  3256. if (eg_pi->dynamic_ac_timing) {
  3257. ret = ni_upload_mc_reg_table(rdev, new_ps);
  3258. if (ret) {
  3259. DRM_ERROR("ni_upload_mc_reg_table failed\n");
  3260. return ret;
  3261. }
  3262. }
  3263. ret = ni_program_memory_timing_parameters(rdev, new_ps);
  3264. if (ret) {
  3265. DRM_ERROR("ni_program_memory_timing_parameters failed\n");
  3266. return ret;
  3267. }
  3268. ret = rv770_resume_smc(rdev);
  3269. if (ret) {
  3270. DRM_ERROR("rv770_resume_smc failed\n");
  3271. return ret;
  3272. }
  3273. ret = rv770_set_sw_state(rdev);
  3274. if (ret) {
  3275. DRM_ERROR("rv770_set_sw_state failed\n");
  3276. return ret;
  3277. }
  3278. ni_set_uvd_clock_after_set_eng_clock(rdev, new_ps, old_ps);
  3279. ret = ni_enable_smc_cac(rdev, new_ps, true);
  3280. if (ret) {
  3281. DRM_ERROR("ni_enable_smc_cac failed\n");
  3282. return ret;
  3283. }
  3284. ret = ni_enable_power_containment(rdev, new_ps, true);
  3285. if (ret) {
  3286. DRM_ERROR("ni_enable_power_containment failed\n");
  3287. return ret;
  3288. }
  3289. /* update tdp */
  3290. ret = ni_power_control_set_level(rdev);
  3291. if (ret) {
  3292. DRM_ERROR("ni_power_control_set_level failed\n");
  3293. return ret;
  3294. }
  3295. return 0;
  3296. }
  3297. void ni_dpm_post_set_power_state(struct radeon_device *rdev)
  3298. {
  3299. struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
  3300. struct radeon_ps *new_ps = &eg_pi->requested_rps;
  3301. ni_update_current_ps(rdev, new_ps);
  3302. }
  3303. #if 0
  3304. void ni_dpm_reset_asic(struct radeon_device *rdev)
  3305. {
  3306. ni_restrict_performance_levels_before_switch(rdev);
  3307. rv770_set_boot_state(rdev);
  3308. }
  3309. #endif
  3310. union power_info {
  3311. struct _ATOM_POWERPLAY_INFO info;
  3312. struct _ATOM_POWERPLAY_INFO_V2 info_2;
  3313. struct _ATOM_POWERPLAY_INFO_V3 info_3;
  3314. struct _ATOM_PPLIB_POWERPLAYTABLE pplib;
  3315. struct _ATOM_PPLIB_POWERPLAYTABLE2 pplib2;
  3316. struct _ATOM_PPLIB_POWERPLAYTABLE3 pplib3;
  3317. };
  3318. union pplib_clock_info {
  3319. struct _ATOM_PPLIB_R600_CLOCK_INFO r600;
  3320. struct _ATOM_PPLIB_RS780_CLOCK_INFO rs780;
  3321. struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO evergreen;
  3322. struct _ATOM_PPLIB_SUMO_CLOCK_INFO sumo;
  3323. };
  3324. union pplib_power_state {
  3325. struct _ATOM_PPLIB_STATE v1;
  3326. struct _ATOM_PPLIB_STATE_V2 v2;
  3327. };
  3328. static void ni_parse_pplib_non_clock_info(struct radeon_device *rdev,
  3329. struct radeon_ps *rps,
  3330. struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info,
  3331. u8 table_rev)
  3332. {
  3333. rps->caps = le32_to_cpu(non_clock_info->ulCapsAndSettings);
  3334. rps->class = le16_to_cpu(non_clock_info->usClassification);
  3335. rps->class2 = le16_to_cpu(non_clock_info->usClassification2);
  3336. if (ATOM_PPLIB_NONCLOCKINFO_VER1 < table_rev) {
  3337. rps->vclk = le32_to_cpu(non_clock_info->ulVCLK);
  3338. rps->dclk = le32_to_cpu(non_clock_info->ulDCLK);
  3339. } else if (r600_is_uvd_state(rps->class, rps->class2)) {
  3340. rps->vclk = RV770_DEFAULT_VCLK_FREQ;
  3341. rps->dclk = RV770_DEFAULT_DCLK_FREQ;
  3342. } else {
  3343. rps->vclk = 0;
  3344. rps->dclk = 0;
  3345. }
  3346. if (rps->class & ATOM_PPLIB_CLASSIFICATION_BOOT)
  3347. rdev->pm.dpm.boot_ps = rps;
  3348. if (rps->class & ATOM_PPLIB_CLASSIFICATION_UVDSTATE)
  3349. rdev->pm.dpm.uvd_ps = rps;
  3350. }
  3351. static void ni_parse_pplib_clock_info(struct radeon_device *rdev,
  3352. struct radeon_ps *rps, int index,
  3353. union pplib_clock_info *clock_info)
  3354. {
  3355. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  3356. struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
  3357. struct ni_ps *ps = ni_get_ps(rps);
  3358. struct rv7xx_pl *pl = &ps->performance_levels[index];
  3359. ps->performance_level_count = index + 1;
  3360. pl->sclk = le16_to_cpu(clock_info->evergreen.usEngineClockLow);
  3361. pl->sclk |= clock_info->evergreen.ucEngineClockHigh << 16;
  3362. pl->mclk = le16_to_cpu(clock_info->evergreen.usMemoryClockLow);
  3363. pl->mclk |= clock_info->evergreen.ucMemoryClockHigh << 16;
  3364. pl->vddc = le16_to_cpu(clock_info->evergreen.usVDDC);
  3365. pl->vddci = le16_to_cpu(clock_info->evergreen.usVDDCI);
  3366. pl->flags = le32_to_cpu(clock_info->evergreen.ulFlags);
  3367. /* patch up vddc if necessary */
  3368. if (pl->vddc == 0xff01) {
  3369. if (pi->max_vddc)
  3370. pl->vddc = pi->max_vddc;
  3371. }
  3372. if (rps->class & ATOM_PPLIB_CLASSIFICATION_ACPI) {
  3373. pi->acpi_vddc = pl->vddc;
  3374. eg_pi->acpi_vddci = pl->vddci;
  3375. if (ps->performance_levels[0].flags & ATOM_PPLIB_R600_FLAGS_PCIEGEN2)
  3376. pi->acpi_pcie_gen2 = true;
  3377. else
  3378. pi->acpi_pcie_gen2 = false;
  3379. }
  3380. if (rps->class2 & ATOM_PPLIB_CLASSIFICATION2_ULV) {
  3381. eg_pi->ulv.supported = true;
  3382. eg_pi->ulv.pl = pl;
  3383. }
  3384. if (pi->min_vddc_in_table > pl->vddc)
  3385. pi->min_vddc_in_table = pl->vddc;
  3386. if (pi->max_vddc_in_table < pl->vddc)
  3387. pi->max_vddc_in_table = pl->vddc;
  3388. /* patch up boot state */
  3389. if (rps->class & ATOM_PPLIB_CLASSIFICATION_BOOT) {
  3390. u16 vddc, vddci, mvdd;
  3391. radeon_atombios_get_default_voltages(rdev, &vddc, &vddci, &mvdd);
  3392. pl->mclk = rdev->clock.default_mclk;
  3393. pl->sclk = rdev->clock.default_sclk;
  3394. pl->vddc = vddc;
  3395. pl->vddci = vddci;
  3396. }
  3397. if ((rps->class & ATOM_PPLIB_CLASSIFICATION_UI_MASK) ==
  3398. ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE) {
  3399. rdev->pm.dpm.dyn_state.max_clock_voltage_on_ac.sclk = pl->sclk;
  3400. rdev->pm.dpm.dyn_state.max_clock_voltage_on_ac.mclk = pl->mclk;
  3401. rdev->pm.dpm.dyn_state.max_clock_voltage_on_ac.vddc = pl->vddc;
  3402. rdev->pm.dpm.dyn_state.max_clock_voltage_on_ac.vddci = pl->vddci;
  3403. }
  3404. }
  3405. static int ni_parse_power_table(struct radeon_device *rdev)
  3406. {
  3407. struct radeon_mode_info *mode_info = &rdev->mode_info;
  3408. struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info;
  3409. union pplib_power_state *power_state;
  3410. int i, j;
  3411. union pplib_clock_info *clock_info;
  3412. union power_info *power_info;
  3413. int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
  3414. u16 data_offset;
  3415. u8 frev, crev;
  3416. struct ni_ps *ps;
  3417. if (!atom_parse_data_header(mode_info->atom_context, index, NULL,
  3418. &frev, &crev, &data_offset))
  3419. return -EINVAL;
  3420. power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
  3421. rdev->pm.dpm.ps = kzalloc(sizeof(struct radeon_ps) *
  3422. power_info->pplib.ucNumStates, GFP_KERNEL);
  3423. if (!rdev->pm.dpm.ps)
  3424. return -ENOMEM;
  3425. for (i = 0; i < power_info->pplib.ucNumStates; i++) {
  3426. power_state = (union pplib_power_state *)
  3427. (mode_info->atom_context->bios + data_offset +
  3428. le16_to_cpu(power_info->pplib.usStateArrayOffset) +
  3429. i * power_info->pplib.ucStateEntrySize);
  3430. non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
  3431. (mode_info->atom_context->bios + data_offset +
  3432. le16_to_cpu(power_info->pplib.usNonClockInfoArrayOffset) +
  3433. (power_state->v1.ucNonClockStateIndex *
  3434. power_info->pplib.ucNonClockSize));
  3435. if (power_info->pplib.ucStateEntrySize - 1) {
  3436. u8 *idx;
  3437. ps = kzalloc(sizeof(struct ni_ps), GFP_KERNEL);
  3438. if (ps == NULL) {
  3439. kfree(rdev->pm.dpm.ps);
  3440. return -ENOMEM;
  3441. }
  3442. rdev->pm.dpm.ps[i].ps_priv = ps;
  3443. ni_parse_pplib_non_clock_info(rdev, &rdev->pm.dpm.ps[i],
  3444. non_clock_info,
  3445. power_info->pplib.ucNonClockSize);
  3446. idx = (u8 *)&power_state->v1.ucClockStateIndices[0];
  3447. for (j = 0; j < (power_info->pplib.ucStateEntrySize - 1); j++) {
  3448. clock_info = (union pplib_clock_info *)
  3449. (mode_info->atom_context->bios + data_offset +
  3450. le16_to_cpu(power_info->pplib.usClockInfoArrayOffset) +
  3451. (idx[j] * power_info->pplib.ucClockInfoSize));
  3452. ni_parse_pplib_clock_info(rdev,
  3453. &rdev->pm.dpm.ps[i], j,
  3454. clock_info);
  3455. }
  3456. }
  3457. }
  3458. rdev->pm.dpm.num_ps = power_info->pplib.ucNumStates;
  3459. return 0;
  3460. }
  3461. int ni_dpm_init(struct radeon_device *rdev)
  3462. {
  3463. struct rv7xx_power_info *pi;
  3464. struct evergreen_power_info *eg_pi;
  3465. struct ni_power_info *ni_pi;
  3466. struct atom_clock_dividers dividers;
  3467. int ret;
  3468. ni_pi = kzalloc(sizeof(struct ni_power_info), GFP_KERNEL);
  3469. if (ni_pi == NULL)
  3470. return -ENOMEM;
  3471. rdev->pm.dpm.priv = ni_pi;
  3472. eg_pi = &ni_pi->eg;
  3473. pi = &eg_pi->rv7xx;
  3474. rv770_get_max_vddc(rdev);
  3475. eg_pi->ulv.supported = false;
  3476. pi->acpi_vddc = 0;
  3477. eg_pi->acpi_vddci = 0;
  3478. pi->min_vddc_in_table = 0;
  3479. pi->max_vddc_in_table = 0;
  3480. ret = r600_get_platform_caps(rdev);
  3481. if (ret)
  3482. return ret;
  3483. ret = ni_parse_power_table(rdev);
  3484. if (ret)
  3485. return ret;
  3486. ret = r600_parse_extended_power_table(rdev);
  3487. if (ret)
  3488. return ret;
  3489. rdev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries =
  3490. kzalloc(4 * sizeof(struct radeon_clock_voltage_dependency_entry), GFP_KERNEL);
  3491. if (!rdev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries) {
  3492. r600_free_extended_power_table(rdev);
  3493. return -ENOMEM;
  3494. }
  3495. rdev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.count = 4;
  3496. rdev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries[0].clk = 0;
  3497. rdev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries[0].v = 0;
  3498. rdev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries[1].clk = 36000;
  3499. rdev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries[1].v = 720;
  3500. rdev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries[2].clk = 54000;
  3501. rdev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries[2].v = 810;
  3502. rdev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries[3].clk = 72000;
  3503. rdev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries[3].v = 900;
  3504. ni_patch_dependency_tables_based_on_leakage(rdev);
  3505. if (rdev->pm.dpm.voltage_response_time == 0)
  3506. rdev->pm.dpm.voltage_response_time = R600_VOLTAGERESPONSETIME_DFLT;
  3507. if (rdev->pm.dpm.backbias_response_time == 0)
  3508. rdev->pm.dpm.backbias_response_time = R600_BACKBIASRESPONSETIME_DFLT;
  3509. ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM,
  3510. 0, false, &dividers);
  3511. if (ret)
  3512. pi->ref_div = dividers.ref_div + 1;
  3513. else
  3514. pi->ref_div = R600_REFERENCEDIVIDER_DFLT;
  3515. pi->rlp = RV770_RLP_DFLT;
  3516. pi->rmp = RV770_RMP_DFLT;
  3517. pi->lhp = RV770_LHP_DFLT;
  3518. pi->lmp = RV770_LMP_DFLT;
  3519. eg_pi->ats[0].rlp = RV770_RLP_DFLT;
  3520. eg_pi->ats[0].rmp = RV770_RMP_DFLT;
  3521. eg_pi->ats[0].lhp = RV770_LHP_DFLT;
  3522. eg_pi->ats[0].lmp = RV770_LMP_DFLT;
  3523. eg_pi->ats[1].rlp = BTC_RLP_UVD_DFLT;
  3524. eg_pi->ats[1].rmp = BTC_RMP_UVD_DFLT;
  3525. eg_pi->ats[1].lhp = BTC_LHP_UVD_DFLT;
  3526. eg_pi->ats[1].lmp = BTC_LMP_UVD_DFLT;
  3527. eg_pi->smu_uvd_hs = true;
  3528. if (rdev->pdev->device == 0x6707) {
  3529. pi->mclk_strobe_mode_threshold = 55000;
  3530. pi->mclk_edc_enable_threshold = 55000;
  3531. eg_pi->mclk_edc_wr_enable_threshold = 55000;
  3532. } else {
  3533. pi->mclk_strobe_mode_threshold = 40000;
  3534. pi->mclk_edc_enable_threshold = 40000;
  3535. eg_pi->mclk_edc_wr_enable_threshold = 40000;
  3536. }
  3537. ni_pi->mclk_rtt_mode_threshold = eg_pi->mclk_edc_wr_enable_threshold;
  3538. pi->voltage_control =
  3539. radeon_atom_is_voltage_gpio(rdev, SET_VOLTAGE_TYPE_ASIC_VDDC, 0);
  3540. pi->mvdd_control =
  3541. radeon_atom_is_voltage_gpio(rdev, SET_VOLTAGE_TYPE_ASIC_MVDDC, 0);
  3542. eg_pi->vddci_control =
  3543. radeon_atom_is_voltage_gpio(rdev, SET_VOLTAGE_TYPE_ASIC_VDDCI, 0);
  3544. rv770_get_engine_memory_ss(rdev);
  3545. pi->asi = RV770_ASI_DFLT;
  3546. pi->pasi = CYPRESS_HASI_DFLT;
  3547. pi->vrc = CYPRESS_VRC_DFLT;
  3548. pi->power_gating = false;
  3549. pi->gfx_clock_gating = true;
  3550. pi->mg_clock_gating = true;
  3551. pi->mgcgtssm = true;
  3552. eg_pi->ls_clock_gating = false;
  3553. eg_pi->sclk_deep_sleep = false;
  3554. pi->dynamic_pcie_gen2 = true;
  3555. if (rdev->pm.int_thermal_type != THERMAL_TYPE_NONE)
  3556. pi->thermal_protection = true;
  3557. else
  3558. pi->thermal_protection = false;
  3559. pi->display_gap = true;
  3560. pi->dcodt = true;
  3561. pi->ulps = true;
  3562. eg_pi->dynamic_ac_timing = true;
  3563. eg_pi->abm = true;
  3564. eg_pi->mcls = true;
  3565. eg_pi->light_sleep = true;
  3566. eg_pi->memory_transition = true;
  3567. #if defined(CONFIG_ACPI)
  3568. eg_pi->pcie_performance_request =
  3569. radeon_acpi_is_pcie_performance_request_supported(rdev);
  3570. #else
  3571. eg_pi->pcie_performance_request = false;
  3572. #endif
  3573. eg_pi->dll_default_on = false;
  3574. eg_pi->sclk_deep_sleep = false;
  3575. pi->mclk_stutter_mode_threshold = 0;
  3576. pi->sram_end = SMC_RAM_END;
  3577. rdev->pm.dpm.dyn_state.mclk_sclk_ratio = 3;
  3578. rdev->pm.dpm.dyn_state.vddc_vddci_delta = 200;
  3579. rdev->pm.dpm.dyn_state.min_vddc_for_pcie_gen2 = 900;
  3580. rdev->pm.dpm.dyn_state.valid_sclk_values.count = ARRAY_SIZE(btc_valid_sclk);
  3581. rdev->pm.dpm.dyn_state.valid_sclk_values.values = btc_valid_sclk;
  3582. rdev->pm.dpm.dyn_state.valid_mclk_values.count = 0;
  3583. rdev->pm.dpm.dyn_state.valid_mclk_values.values = NULL;
  3584. rdev->pm.dpm.dyn_state.sclk_mclk_delta = 12500;
  3585. ni_pi->cac_data.leakage_coefficients.at = 516;
  3586. ni_pi->cac_data.leakage_coefficients.bt = 18;
  3587. ni_pi->cac_data.leakage_coefficients.av = 51;
  3588. ni_pi->cac_data.leakage_coefficients.bv = 2957;
  3589. switch (rdev->pdev->device) {
  3590. case 0x6700:
  3591. case 0x6701:
  3592. case 0x6702:
  3593. case 0x6703:
  3594. case 0x6718:
  3595. ni_pi->cac_weights = &cac_weights_cayman_xt;
  3596. break;
  3597. case 0x6705:
  3598. case 0x6719:
  3599. case 0x671D:
  3600. case 0x671C:
  3601. default:
  3602. ni_pi->cac_weights = &cac_weights_cayman_pro;
  3603. break;
  3604. case 0x6704:
  3605. case 0x6706:
  3606. case 0x6707:
  3607. case 0x6708:
  3608. case 0x6709:
  3609. ni_pi->cac_weights = &cac_weights_cayman_le;
  3610. break;
  3611. }
  3612. if (ni_pi->cac_weights->enable_power_containment_by_default) {
  3613. ni_pi->enable_power_containment = true;
  3614. ni_pi->enable_cac = true;
  3615. ni_pi->enable_sq_ramping = true;
  3616. } else {
  3617. ni_pi->enable_power_containment = false;
  3618. ni_pi->enable_cac = false;
  3619. ni_pi->enable_sq_ramping = false;
  3620. }
  3621. ni_pi->driver_calculate_cac_leakage = false;
  3622. ni_pi->cac_configuration_required = true;
  3623. if (ni_pi->cac_configuration_required) {
  3624. ni_pi->support_cac_long_term_average = true;
  3625. ni_pi->lta_window_size = ni_pi->cac_weights->l2_lta_window_size;
  3626. ni_pi->lts_truncate = ni_pi->cac_weights->lts_truncate;
  3627. } else {
  3628. ni_pi->support_cac_long_term_average = false;
  3629. ni_pi->lta_window_size = 0;
  3630. ni_pi->lts_truncate = 0;
  3631. }
  3632. ni_pi->use_power_boost_limit = true;
  3633. /* make sure dc limits are valid */
  3634. if ((rdev->pm.dpm.dyn_state.max_clock_voltage_on_dc.sclk == 0) ||
  3635. (rdev->pm.dpm.dyn_state.max_clock_voltage_on_dc.mclk == 0))
  3636. rdev->pm.dpm.dyn_state.max_clock_voltage_on_dc =
  3637. rdev->pm.dpm.dyn_state.max_clock_voltage_on_ac;
  3638. return 0;
  3639. }
  3640. void ni_dpm_fini(struct radeon_device *rdev)
  3641. {
  3642. int i;
  3643. for (i = 0; i < rdev->pm.dpm.num_ps; i++) {
  3644. kfree(rdev->pm.dpm.ps[i].ps_priv);
  3645. }
  3646. kfree(rdev->pm.dpm.ps);
  3647. kfree(rdev->pm.dpm.priv);
  3648. kfree(rdev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries);
  3649. r600_free_extended_power_table(rdev);
  3650. }
  3651. void ni_dpm_print_power_state(struct radeon_device *rdev,
  3652. struct radeon_ps *rps)
  3653. {
  3654. struct ni_ps *ps = ni_get_ps(rps);
  3655. struct rv7xx_pl *pl;
  3656. int i;
  3657. r600_dpm_print_class_info(rps->class, rps->class2);
  3658. r600_dpm_print_cap_info(rps->caps);
  3659. printk("\tuvd vclk: %d dclk: %d\n", rps->vclk, rps->dclk);
  3660. for (i = 0; i < ps->performance_level_count; i++) {
  3661. pl = &ps->performance_levels[i];
  3662. if (rdev->family >= CHIP_TAHITI)
  3663. printk("\t\tpower level %d sclk: %u mclk: %u vddc: %u vddci: %u pcie gen: %u\n",
  3664. i, pl->sclk, pl->mclk, pl->vddc, pl->vddci, pl->pcie_gen + 1);
  3665. else
  3666. printk("\t\tpower level %d sclk: %u mclk: %u vddc: %u vddci: %u\n",
  3667. i, pl->sclk, pl->mclk, pl->vddc, pl->vddci);
  3668. }
  3669. r600_dpm_print_ps_status(rdev, rps);
  3670. }
  3671. void ni_dpm_debugfs_print_current_performance_level(struct radeon_device *rdev,
  3672. struct seq_file *m)
  3673. {
  3674. struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
  3675. struct radeon_ps *rps = &eg_pi->current_rps;
  3676. struct ni_ps *ps = ni_get_ps(rps);
  3677. struct rv7xx_pl *pl;
  3678. u32 current_index =
  3679. (RREG32(TARGET_AND_CURRENT_PROFILE_INDEX) & CURRENT_STATE_INDEX_MASK) >>
  3680. CURRENT_STATE_INDEX_SHIFT;
  3681. if (current_index >= ps->performance_level_count) {
  3682. seq_printf(m, "invalid dpm profile %d\n", current_index);
  3683. } else {
  3684. pl = &ps->performance_levels[current_index];
  3685. seq_printf(m, "uvd vclk: %d dclk: %d\n", rps->vclk, rps->dclk);
  3686. seq_printf(m, "power level %d sclk: %u mclk: %u vddc: %u vddci: %u\n",
  3687. current_index, pl->sclk, pl->mclk, pl->vddc, pl->vddci);
  3688. }
  3689. }
  3690. u32 ni_dpm_get_current_sclk(struct radeon_device *rdev)
  3691. {
  3692. struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
  3693. struct radeon_ps *rps = &eg_pi->current_rps;
  3694. struct ni_ps *ps = ni_get_ps(rps);
  3695. struct rv7xx_pl *pl;
  3696. u32 current_index =
  3697. (RREG32(TARGET_AND_CURRENT_PROFILE_INDEX) & CURRENT_STATE_INDEX_MASK) >>
  3698. CURRENT_STATE_INDEX_SHIFT;
  3699. if (current_index >= ps->performance_level_count) {
  3700. return 0;
  3701. } else {
  3702. pl = &ps->performance_levels[current_index];
  3703. return pl->sclk;
  3704. }
  3705. }
  3706. u32 ni_dpm_get_current_mclk(struct radeon_device *rdev)
  3707. {
  3708. struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
  3709. struct radeon_ps *rps = &eg_pi->current_rps;
  3710. struct ni_ps *ps = ni_get_ps(rps);
  3711. struct rv7xx_pl *pl;
  3712. u32 current_index =
  3713. (RREG32(TARGET_AND_CURRENT_PROFILE_INDEX) & CURRENT_STATE_INDEX_MASK) >>
  3714. CURRENT_STATE_INDEX_SHIFT;
  3715. if (current_index >= ps->performance_level_count) {
  3716. return 0;
  3717. } else {
  3718. pl = &ps->performance_levels[current_index];
  3719. return pl->mclk;
  3720. }
  3721. }
  3722. u32 ni_dpm_get_sclk(struct radeon_device *rdev, bool low)
  3723. {
  3724. struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
  3725. struct ni_ps *requested_state = ni_get_ps(&eg_pi->requested_rps);
  3726. if (low)
  3727. return requested_state->performance_levels[0].sclk;
  3728. else
  3729. return requested_state->performance_levels[requested_state->performance_level_count - 1].sclk;
  3730. }
  3731. u32 ni_dpm_get_mclk(struct radeon_device *rdev, bool low)
  3732. {
  3733. struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
  3734. struct ni_ps *requested_state = ni_get_ps(&eg_pi->requested_rps);
  3735. if (low)
  3736. return requested_state->performance_levels[0].mclk;
  3737. else
  3738. return requested_state->performance_levels[requested_state->performance_level_count - 1].mclk;
  3739. }