cik.c 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249
  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. * Authors: Alex Deucher
  23. */
  24. #include <linux/firmware.h>
  25. #include <linux/slab.h>
  26. #include <linux/module.h>
  27. #include "drmP.h"
  28. #include "amdgpu.h"
  29. #include "amdgpu_atombios.h"
  30. #include "amdgpu_ih.h"
  31. #include "amdgpu_uvd.h"
  32. #include "amdgpu_vce.h"
  33. #include "cikd.h"
  34. #include "atom.h"
  35. #include "amd_pcie.h"
  36. #include "cik.h"
  37. #include "gmc_v7_0.h"
  38. #include "cik_ih.h"
  39. #include "dce_v8_0.h"
  40. #include "gfx_v7_0.h"
  41. #include "cik_sdma.h"
  42. #include "uvd_v4_2.h"
  43. #include "vce_v2_0.h"
  44. #include "cik_dpm.h"
  45. #include "uvd/uvd_4_2_d.h"
  46. #include "smu/smu_7_0_1_d.h"
  47. #include "smu/smu_7_0_1_sh_mask.h"
  48. #include "dce/dce_8_0_d.h"
  49. #include "dce/dce_8_0_sh_mask.h"
  50. #include "bif/bif_4_1_d.h"
  51. #include "bif/bif_4_1_sh_mask.h"
  52. #include "gca/gfx_7_2_d.h"
  53. #include "gca/gfx_7_2_enum.h"
  54. #include "gca/gfx_7_2_sh_mask.h"
  55. #include "gmc/gmc_7_1_d.h"
  56. #include "gmc/gmc_7_1_sh_mask.h"
  57. #include "oss/oss_2_0_d.h"
  58. #include "oss/oss_2_0_sh_mask.h"
  59. #include "amdgpu_amdkfd.h"
  60. #include "amdgpu_powerplay.h"
  61. /*
  62. * Indirect registers accessor
  63. */
  64. static u32 cik_pcie_rreg(struct amdgpu_device *adev, u32 reg)
  65. {
  66. unsigned long flags;
  67. u32 r;
  68. spin_lock_irqsave(&adev->pcie_idx_lock, flags);
  69. WREG32(mmPCIE_INDEX, reg);
  70. (void)RREG32(mmPCIE_INDEX);
  71. r = RREG32(mmPCIE_DATA);
  72. spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
  73. return r;
  74. }
  75. static void cik_pcie_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
  76. {
  77. unsigned long flags;
  78. spin_lock_irqsave(&adev->pcie_idx_lock, flags);
  79. WREG32(mmPCIE_INDEX, reg);
  80. (void)RREG32(mmPCIE_INDEX);
  81. WREG32(mmPCIE_DATA, v);
  82. (void)RREG32(mmPCIE_DATA);
  83. spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
  84. }
  85. static u32 cik_smc_rreg(struct amdgpu_device *adev, u32 reg)
  86. {
  87. unsigned long flags;
  88. u32 r;
  89. spin_lock_irqsave(&adev->smc_idx_lock, flags);
  90. WREG32(mmSMC_IND_INDEX_0, (reg));
  91. r = RREG32(mmSMC_IND_DATA_0);
  92. spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
  93. return r;
  94. }
  95. static void cik_smc_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
  96. {
  97. unsigned long flags;
  98. spin_lock_irqsave(&adev->smc_idx_lock, flags);
  99. WREG32(mmSMC_IND_INDEX_0, (reg));
  100. WREG32(mmSMC_IND_DATA_0, (v));
  101. spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
  102. }
  103. static u32 cik_uvd_ctx_rreg(struct amdgpu_device *adev, u32 reg)
  104. {
  105. unsigned long flags;
  106. u32 r;
  107. spin_lock_irqsave(&adev->uvd_ctx_idx_lock, flags);
  108. WREG32(mmUVD_CTX_INDEX, ((reg) & 0x1ff));
  109. r = RREG32(mmUVD_CTX_DATA);
  110. spin_unlock_irqrestore(&adev->uvd_ctx_idx_lock, flags);
  111. return r;
  112. }
  113. static void cik_uvd_ctx_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
  114. {
  115. unsigned long flags;
  116. spin_lock_irqsave(&adev->uvd_ctx_idx_lock, flags);
  117. WREG32(mmUVD_CTX_INDEX, ((reg) & 0x1ff));
  118. WREG32(mmUVD_CTX_DATA, (v));
  119. spin_unlock_irqrestore(&adev->uvd_ctx_idx_lock, flags);
  120. }
  121. static u32 cik_didt_rreg(struct amdgpu_device *adev, u32 reg)
  122. {
  123. unsigned long flags;
  124. u32 r;
  125. spin_lock_irqsave(&adev->didt_idx_lock, flags);
  126. WREG32(mmDIDT_IND_INDEX, (reg));
  127. r = RREG32(mmDIDT_IND_DATA);
  128. spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
  129. return r;
  130. }
  131. static void cik_didt_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
  132. {
  133. unsigned long flags;
  134. spin_lock_irqsave(&adev->didt_idx_lock, flags);
  135. WREG32(mmDIDT_IND_INDEX, (reg));
  136. WREG32(mmDIDT_IND_DATA, (v));
  137. spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
  138. }
  139. static const u32 bonaire_golden_spm_registers[] =
  140. {
  141. 0xc200, 0xe0ffffff, 0xe0000000
  142. };
  143. static const u32 bonaire_golden_common_registers[] =
  144. {
  145. 0x31dc, 0xffffffff, 0x00000800,
  146. 0x31dd, 0xffffffff, 0x00000800,
  147. 0x31e6, 0xffffffff, 0x00007fbf,
  148. 0x31e7, 0xffffffff, 0x00007faf
  149. };
  150. static const u32 bonaire_golden_registers[] =
  151. {
  152. 0xcd5, 0x00000333, 0x00000333,
  153. 0xcd4, 0x000c0fc0, 0x00040200,
  154. 0x2684, 0x00010000, 0x00058208,
  155. 0xf000, 0xffff1fff, 0x00140000,
  156. 0xf080, 0xfdfc0fff, 0x00000100,
  157. 0xf08d, 0x40000000, 0x40000200,
  158. 0x260c, 0xffffffff, 0x00000000,
  159. 0x260d, 0xf00fffff, 0x00000400,
  160. 0x260e, 0x0002021c, 0x00020200,
  161. 0x31e, 0x00000080, 0x00000000,
  162. 0x16ec, 0x000000f0, 0x00000070,
  163. 0x16f0, 0xf0311fff, 0x80300000,
  164. 0x263e, 0x73773777, 0x12010001,
  165. 0xd43, 0x00810000, 0x408af000,
  166. 0x1c0c, 0x31000111, 0x00000011,
  167. 0xbd2, 0x73773777, 0x12010001,
  168. 0x883, 0x00007fb6, 0x0021a1b1,
  169. 0x884, 0x00007fb6, 0x002021b1,
  170. 0x860, 0x00007fb6, 0x00002191,
  171. 0x886, 0x00007fb6, 0x002121b1,
  172. 0x887, 0x00007fb6, 0x002021b1,
  173. 0x877, 0x00007fb6, 0x00002191,
  174. 0x878, 0x00007fb6, 0x00002191,
  175. 0xd8a, 0x0000003f, 0x0000000a,
  176. 0xd8b, 0x0000003f, 0x0000000a,
  177. 0xab9, 0x00073ffe, 0x000022a2,
  178. 0x903, 0x000007ff, 0x00000000,
  179. 0x2285, 0xf000003f, 0x00000007,
  180. 0x22fc, 0x00002001, 0x00000001,
  181. 0x22c9, 0xffffffff, 0x00ffffff,
  182. 0xc281, 0x0000ff0f, 0x00000000,
  183. 0xa293, 0x07ffffff, 0x06000000,
  184. 0x136, 0x00000fff, 0x00000100,
  185. 0xf9e, 0x00000001, 0x00000002,
  186. 0x2440, 0x03000000, 0x0362c688,
  187. 0x2300, 0x000000ff, 0x00000001,
  188. 0x390, 0x00001fff, 0x00001fff,
  189. 0x2418, 0x0000007f, 0x00000020,
  190. 0x2542, 0x00010000, 0x00010000,
  191. 0x2b05, 0x000003ff, 0x000000f3,
  192. 0x2b03, 0xffffffff, 0x00001032
  193. };
  194. static const u32 bonaire_mgcg_cgcg_init[] =
  195. {
  196. 0x3108, 0xffffffff, 0xfffffffc,
  197. 0xc200, 0xffffffff, 0xe0000000,
  198. 0xf0a8, 0xffffffff, 0x00000100,
  199. 0xf082, 0xffffffff, 0x00000100,
  200. 0xf0b0, 0xffffffff, 0xc0000100,
  201. 0xf0b2, 0xffffffff, 0xc0000100,
  202. 0xf0b1, 0xffffffff, 0xc0000100,
  203. 0x1579, 0xffffffff, 0x00600100,
  204. 0xf0a0, 0xffffffff, 0x00000100,
  205. 0xf085, 0xffffffff, 0x06000100,
  206. 0xf088, 0xffffffff, 0x00000100,
  207. 0xf086, 0xffffffff, 0x06000100,
  208. 0xf081, 0xffffffff, 0x00000100,
  209. 0xf0b8, 0xffffffff, 0x00000100,
  210. 0xf089, 0xffffffff, 0x00000100,
  211. 0xf080, 0xffffffff, 0x00000100,
  212. 0xf08c, 0xffffffff, 0x00000100,
  213. 0xf08d, 0xffffffff, 0x00000100,
  214. 0xf094, 0xffffffff, 0x00000100,
  215. 0xf095, 0xffffffff, 0x00000100,
  216. 0xf096, 0xffffffff, 0x00000100,
  217. 0xf097, 0xffffffff, 0x00000100,
  218. 0xf098, 0xffffffff, 0x00000100,
  219. 0xf09f, 0xffffffff, 0x00000100,
  220. 0xf09e, 0xffffffff, 0x00000100,
  221. 0xf084, 0xffffffff, 0x06000100,
  222. 0xf0a4, 0xffffffff, 0x00000100,
  223. 0xf09d, 0xffffffff, 0x00000100,
  224. 0xf0ad, 0xffffffff, 0x00000100,
  225. 0xf0ac, 0xffffffff, 0x00000100,
  226. 0xf09c, 0xffffffff, 0x00000100,
  227. 0xc200, 0xffffffff, 0xe0000000,
  228. 0xf008, 0xffffffff, 0x00010000,
  229. 0xf009, 0xffffffff, 0x00030002,
  230. 0xf00a, 0xffffffff, 0x00040007,
  231. 0xf00b, 0xffffffff, 0x00060005,
  232. 0xf00c, 0xffffffff, 0x00090008,
  233. 0xf00d, 0xffffffff, 0x00010000,
  234. 0xf00e, 0xffffffff, 0x00030002,
  235. 0xf00f, 0xffffffff, 0x00040007,
  236. 0xf010, 0xffffffff, 0x00060005,
  237. 0xf011, 0xffffffff, 0x00090008,
  238. 0xf012, 0xffffffff, 0x00010000,
  239. 0xf013, 0xffffffff, 0x00030002,
  240. 0xf014, 0xffffffff, 0x00040007,
  241. 0xf015, 0xffffffff, 0x00060005,
  242. 0xf016, 0xffffffff, 0x00090008,
  243. 0xf017, 0xffffffff, 0x00010000,
  244. 0xf018, 0xffffffff, 0x00030002,
  245. 0xf019, 0xffffffff, 0x00040007,
  246. 0xf01a, 0xffffffff, 0x00060005,
  247. 0xf01b, 0xffffffff, 0x00090008,
  248. 0xf01c, 0xffffffff, 0x00010000,
  249. 0xf01d, 0xffffffff, 0x00030002,
  250. 0xf01e, 0xffffffff, 0x00040007,
  251. 0xf01f, 0xffffffff, 0x00060005,
  252. 0xf020, 0xffffffff, 0x00090008,
  253. 0xf021, 0xffffffff, 0x00010000,
  254. 0xf022, 0xffffffff, 0x00030002,
  255. 0xf023, 0xffffffff, 0x00040007,
  256. 0xf024, 0xffffffff, 0x00060005,
  257. 0xf025, 0xffffffff, 0x00090008,
  258. 0xf026, 0xffffffff, 0x00010000,
  259. 0xf027, 0xffffffff, 0x00030002,
  260. 0xf028, 0xffffffff, 0x00040007,
  261. 0xf029, 0xffffffff, 0x00060005,
  262. 0xf02a, 0xffffffff, 0x00090008,
  263. 0xf000, 0xffffffff, 0x96e00200,
  264. 0x21c2, 0xffffffff, 0x00900100,
  265. 0x3109, 0xffffffff, 0x0020003f,
  266. 0xe, 0xffffffff, 0x0140001c,
  267. 0xf, 0x000f0000, 0x000f0000,
  268. 0x88, 0xffffffff, 0xc060000c,
  269. 0x89, 0xc0000fff, 0x00000100,
  270. 0x3e4, 0xffffffff, 0x00000100,
  271. 0x3e6, 0x00000101, 0x00000000,
  272. 0x82a, 0xffffffff, 0x00000104,
  273. 0x1579, 0xff000fff, 0x00000100,
  274. 0xc33, 0xc0000fff, 0x00000104,
  275. 0x3079, 0x00000001, 0x00000001,
  276. 0x3403, 0xff000ff0, 0x00000100,
  277. 0x3603, 0xff000ff0, 0x00000100
  278. };
  279. static const u32 spectre_golden_spm_registers[] =
  280. {
  281. 0xc200, 0xe0ffffff, 0xe0000000
  282. };
  283. static const u32 spectre_golden_common_registers[] =
  284. {
  285. 0x31dc, 0xffffffff, 0x00000800,
  286. 0x31dd, 0xffffffff, 0x00000800,
  287. 0x31e6, 0xffffffff, 0x00007fbf,
  288. 0x31e7, 0xffffffff, 0x00007faf
  289. };
  290. static const u32 spectre_golden_registers[] =
  291. {
  292. 0xf000, 0xffff1fff, 0x96940200,
  293. 0xf003, 0xffff0001, 0xff000000,
  294. 0xf080, 0xfffc0fff, 0x00000100,
  295. 0x1bb6, 0x00010101, 0x00010000,
  296. 0x260d, 0xf00fffff, 0x00000400,
  297. 0x260e, 0xfffffffc, 0x00020200,
  298. 0x16ec, 0x000000f0, 0x00000070,
  299. 0x16f0, 0xf0311fff, 0x80300000,
  300. 0x263e, 0x73773777, 0x12010001,
  301. 0x26df, 0x00ff0000, 0x00fc0000,
  302. 0xbd2, 0x73773777, 0x12010001,
  303. 0x2285, 0xf000003f, 0x00000007,
  304. 0x22c9, 0xffffffff, 0x00ffffff,
  305. 0xa0d4, 0x3f3f3fff, 0x00000082,
  306. 0xa0d5, 0x0000003f, 0x00000000,
  307. 0xf9e, 0x00000001, 0x00000002,
  308. 0x244f, 0xffff03df, 0x00000004,
  309. 0x31da, 0x00000008, 0x00000008,
  310. 0x2300, 0x000008ff, 0x00000800,
  311. 0x2542, 0x00010000, 0x00010000,
  312. 0x2b03, 0xffffffff, 0x54763210,
  313. 0x853e, 0x01ff01ff, 0x00000002,
  314. 0x8526, 0x007ff800, 0x00200000,
  315. 0x8057, 0xffffffff, 0x00000f40,
  316. 0xc24d, 0xffffffff, 0x00000001
  317. };
  318. static const u32 spectre_mgcg_cgcg_init[] =
  319. {
  320. 0x3108, 0xffffffff, 0xfffffffc,
  321. 0xc200, 0xffffffff, 0xe0000000,
  322. 0xf0a8, 0xffffffff, 0x00000100,
  323. 0xf082, 0xffffffff, 0x00000100,
  324. 0xf0b0, 0xffffffff, 0x00000100,
  325. 0xf0b2, 0xffffffff, 0x00000100,
  326. 0xf0b1, 0xffffffff, 0x00000100,
  327. 0x1579, 0xffffffff, 0x00600100,
  328. 0xf0a0, 0xffffffff, 0x00000100,
  329. 0xf085, 0xffffffff, 0x06000100,
  330. 0xf088, 0xffffffff, 0x00000100,
  331. 0xf086, 0xffffffff, 0x06000100,
  332. 0xf081, 0xffffffff, 0x00000100,
  333. 0xf0b8, 0xffffffff, 0x00000100,
  334. 0xf089, 0xffffffff, 0x00000100,
  335. 0xf080, 0xffffffff, 0x00000100,
  336. 0xf08c, 0xffffffff, 0x00000100,
  337. 0xf08d, 0xffffffff, 0x00000100,
  338. 0xf094, 0xffffffff, 0x00000100,
  339. 0xf095, 0xffffffff, 0x00000100,
  340. 0xf096, 0xffffffff, 0x00000100,
  341. 0xf097, 0xffffffff, 0x00000100,
  342. 0xf098, 0xffffffff, 0x00000100,
  343. 0xf09f, 0xffffffff, 0x00000100,
  344. 0xf09e, 0xffffffff, 0x00000100,
  345. 0xf084, 0xffffffff, 0x06000100,
  346. 0xf0a4, 0xffffffff, 0x00000100,
  347. 0xf09d, 0xffffffff, 0x00000100,
  348. 0xf0ad, 0xffffffff, 0x00000100,
  349. 0xf0ac, 0xffffffff, 0x00000100,
  350. 0xf09c, 0xffffffff, 0x00000100,
  351. 0xc200, 0xffffffff, 0xe0000000,
  352. 0xf008, 0xffffffff, 0x00010000,
  353. 0xf009, 0xffffffff, 0x00030002,
  354. 0xf00a, 0xffffffff, 0x00040007,
  355. 0xf00b, 0xffffffff, 0x00060005,
  356. 0xf00c, 0xffffffff, 0x00090008,
  357. 0xf00d, 0xffffffff, 0x00010000,
  358. 0xf00e, 0xffffffff, 0x00030002,
  359. 0xf00f, 0xffffffff, 0x00040007,
  360. 0xf010, 0xffffffff, 0x00060005,
  361. 0xf011, 0xffffffff, 0x00090008,
  362. 0xf012, 0xffffffff, 0x00010000,
  363. 0xf013, 0xffffffff, 0x00030002,
  364. 0xf014, 0xffffffff, 0x00040007,
  365. 0xf015, 0xffffffff, 0x00060005,
  366. 0xf016, 0xffffffff, 0x00090008,
  367. 0xf017, 0xffffffff, 0x00010000,
  368. 0xf018, 0xffffffff, 0x00030002,
  369. 0xf019, 0xffffffff, 0x00040007,
  370. 0xf01a, 0xffffffff, 0x00060005,
  371. 0xf01b, 0xffffffff, 0x00090008,
  372. 0xf01c, 0xffffffff, 0x00010000,
  373. 0xf01d, 0xffffffff, 0x00030002,
  374. 0xf01e, 0xffffffff, 0x00040007,
  375. 0xf01f, 0xffffffff, 0x00060005,
  376. 0xf020, 0xffffffff, 0x00090008,
  377. 0xf021, 0xffffffff, 0x00010000,
  378. 0xf022, 0xffffffff, 0x00030002,
  379. 0xf023, 0xffffffff, 0x00040007,
  380. 0xf024, 0xffffffff, 0x00060005,
  381. 0xf025, 0xffffffff, 0x00090008,
  382. 0xf026, 0xffffffff, 0x00010000,
  383. 0xf027, 0xffffffff, 0x00030002,
  384. 0xf028, 0xffffffff, 0x00040007,
  385. 0xf029, 0xffffffff, 0x00060005,
  386. 0xf02a, 0xffffffff, 0x00090008,
  387. 0xf02b, 0xffffffff, 0x00010000,
  388. 0xf02c, 0xffffffff, 0x00030002,
  389. 0xf02d, 0xffffffff, 0x00040007,
  390. 0xf02e, 0xffffffff, 0x00060005,
  391. 0xf02f, 0xffffffff, 0x00090008,
  392. 0xf000, 0xffffffff, 0x96e00200,
  393. 0x21c2, 0xffffffff, 0x00900100,
  394. 0x3109, 0xffffffff, 0x0020003f,
  395. 0xe, 0xffffffff, 0x0140001c,
  396. 0xf, 0x000f0000, 0x000f0000,
  397. 0x88, 0xffffffff, 0xc060000c,
  398. 0x89, 0xc0000fff, 0x00000100,
  399. 0x3e4, 0xffffffff, 0x00000100,
  400. 0x3e6, 0x00000101, 0x00000000,
  401. 0x82a, 0xffffffff, 0x00000104,
  402. 0x1579, 0xff000fff, 0x00000100,
  403. 0xc33, 0xc0000fff, 0x00000104,
  404. 0x3079, 0x00000001, 0x00000001,
  405. 0x3403, 0xff000ff0, 0x00000100,
  406. 0x3603, 0xff000ff0, 0x00000100
  407. };
  408. static const u32 kalindi_golden_spm_registers[] =
  409. {
  410. 0xc200, 0xe0ffffff, 0xe0000000
  411. };
  412. static const u32 kalindi_golden_common_registers[] =
  413. {
  414. 0x31dc, 0xffffffff, 0x00000800,
  415. 0x31dd, 0xffffffff, 0x00000800,
  416. 0x31e6, 0xffffffff, 0x00007fbf,
  417. 0x31e7, 0xffffffff, 0x00007faf
  418. };
  419. static const u32 kalindi_golden_registers[] =
  420. {
  421. 0xf000, 0xffffdfff, 0x6e944040,
  422. 0x1579, 0xff607fff, 0xfc000100,
  423. 0xf088, 0xff000fff, 0x00000100,
  424. 0xf089, 0xff000fff, 0x00000100,
  425. 0xf080, 0xfffc0fff, 0x00000100,
  426. 0x1bb6, 0x00010101, 0x00010000,
  427. 0x260c, 0xffffffff, 0x00000000,
  428. 0x260d, 0xf00fffff, 0x00000400,
  429. 0x16ec, 0x000000f0, 0x00000070,
  430. 0x16f0, 0xf0311fff, 0x80300000,
  431. 0x263e, 0x73773777, 0x12010001,
  432. 0x263f, 0xffffffff, 0x00000010,
  433. 0x26df, 0x00ff0000, 0x00fc0000,
  434. 0x200c, 0x00001f0f, 0x0000100a,
  435. 0xbd2, 0x73773777, 0x12010001,
  436. 0x902, 0x000fffff, 0x000c007f,
  437. 0x2285, 0xf000003f, 0x00000007,
  438. 0x22c9, 0x3fff3fff, 0x00ffcfff,
  439. 0xc281, 0x0000ff0f, 0x00000000,
  440. 0xa293, 0x07ffffff, 0x06000000,
  441. 0x136, 0x00000fff, 0x00000100,
  442. 0xf9e, 0x00000001, 0x00000002,
  443. 0x31da, 0x00000008, 0x00000008,
  444. 0x2300, 0x000000ff, 0x00000003,
  445. 0x853e, 0x01ff01ff, 0x00000002,
  446. 0x8526, 0x007ff800, 0x00200000,
  447. 0x8057, 0xffffffff, 0x00000f40,
  448. 0x2231, 0x001f3ae3, 0x00000082,
  449. 0x2235, 0x0000001f, 0x00000010,
  450. 0xc24d, 0xffffffff, 0x00000000
  451. };
  452. static const u32 kalindi_mgcg_cgcg_init[] =
  453. {
  454. 0x3108, 0xffffffff, 0xfffffffc,
  455. 0xc200, 0xffffffff, 0xe0000000,
  456. 0xf0a8, 0xffffffff, 0x00000100,
  457. 0xf082, 0xffffffff, 0x00000100,
  458. 0xf0b0, 0xffffffff, 0x00000100,
  459. 0xf0b2, 0xffffffff, 0x00000100,
  460. 0xf0b1, 0xffffffff, 0x00000100,
  461. 0x1579, 0xffffffff, 0x00600100,
  462. 0xf0a0, 0xffffffff, 0x00000100,
  463. 0xf085, 0xffffffff, 0x06000100,
  464. 0xf088, 0xffffffff, 0x00000100,
  465. 0xf086, 0xffffffff, 0x06000100,
  466. 0xf081, 0xffffffff, 0x00000100,
  467. 0xf0b8, 0xffffffff, 0x00000100,
  468. 0xf089, 0xffffffff, 0x00000100,
  469. 0xf080, 0xffffffff, 0x00000100,
  470. 0xf08c, 0xffffffff, 0x00000100,
  471. 0xf08d, 0xffffffff, 0x00000100,
  472. 0xf094, 0xffffffff, 0x00000100,
  473. 0xf095, 0xffffffff, 0x00000100,
  474. 0xf096, 0xffffffff, 0x00000100,
  475. 0xf097, 0xffffffff, 0x00000100,
  476. 0xf098, 0xffffffff, 0x00000100,
  477. 0xf09f, 0xffffffff, 0x00000100,
  478. 0xf09e, 0xffffffff, 0x00000100,
  479. 0xf084, 0xffffffff, 0x06000100,
  480. 0xf0a4, 0xffffffff, 0x00000100,
  481. 0xf09d, 0xffffffff, 0x00000100,
  482. 0xf0ad, 0xffffffff, 0x00000100,
  483. 0xf0ac, 0xffffffff, 0x00000100,
  484. 0xf09c, 0xffffffff, 0x00000100,
  485. 0xc200, 0xffffffff, 0xe0000000,
  486. 0xf008, 0xffffffff, 0x00010000,
  487. 0xf009, 0xffffffff, 0x00030002,
  488. 0xf00a, 0xffffffff, 0x00040007,
  489. 0xf00b, 0xffffffff, 0x00060005,
  490. 0xf00c, 0xffffffff, 0x00090008,
  491. 0xf00d, 0xffffffff, 0x00010000,
  492. 0xf00e, 0xffffffff, 0x00030002,
  493. 0xf00f, 0xffffffff, 0x00040007,
  494. 0xf010, 0xffffffff, 0x00060005,
  495. 0xf011, 0xffffffff, 0x00090008,
  496. 0xf000, 0xffffffff, 0x96e00200,
  497. 0x21c2, 0xffffffff, 0x00900100,
  498. 0x3109, 0xffffffff, 0x0020003f,
  499. 0xe, 0xffffffff, 0x0140001c,
  500. 0xf, 0x000f0000, 0x000f0000,
  501. 0x88, 0xffffffff, 0xc060000c,
  502. 0x89, 0xc0000fff, 0x00000100,
  503. 0x82a, 0xffffffff, 0x00000104,
  504. 0x1579, 0xff000fff, 0x00000100,
  505. 0xc33, 0xc0000fff, 0x00000104,
  506. 0x3079, 0x00000001, 0x00000001,
  507. 0x3403, 0xff000ff0, 0x00000100,
  508. 0x3603, 0xff000ff0, 0x00000100
  509. };
  510. static const u32 hawaii_golden_spm_registers[] =
  511. {
  512. 0xc200, 0xe0ffffff, 0xe0000000
  513. };
  514. static const u32 hawaii_golden_common_registers[] =
  515. {
  516. 0xc200, 0xffffffff, 0xe0000000,
  517. 0xa0d4, 0xffffffff, 0x3a00161a,
  518. 0xa0d5, 0xffffffff, 0x0000002e,
  519. 0x2684, 0xffffffff, 0x00018208,
  520. 0x263e, 0xffffffff, 0x12011003
  521. };
  522. static const u32 hawaii_golden_registers[] =
  523. {
  524. 0xcd5, 0x00000333, 0x00000333,
  525. 0x2684, 0x00010000, 0x00058208,
  526. 0x260c, 0xffffffff, 0x00000000,
  527. 0x260d, 0xf00fffff, 0x00000400,
  528. 0x260e, 0x0002021c, 0x00020200,
  529. 0x31e, 0x00000080, 0x00000000,
  530. 0x16ec, 0x000000f0, 0x00000070,
  531. 0x16f0, 0xf0311fff, 0x80300000,
  532. 0xd43, 0x00810000, 0x408af000,
  533. 0x1c0c, 0x31000111, 0x00000011,
  534. 0xbd2, 0x73773777, 0x12010001,
  535. 0x848, 0x0000007f, 0x0000001b,
  536. 0x877, 0x00007fb6, 0x00002191,
  537. 0xd8a, 0x0000003f, 0x0000000a,
  538. 0xd8b, 0x0000003f, 0x0000000a,
  539. 0xab9, 0x00073ffe, 0x000022a2,
  540. 0x903, 0x000007ff, 0x00000000,
  541. 0x22fc, 0x00002001, 0x00000001,
  542. 0x22c9, 0xffffffff, 0x00ffffff,
  543. 0xc281, 0x0000ff0f, 0x00000000,
  544. 0xa293, 0x07ffffff, 0x06000000,
  545. 0xf9e, 0x00000001, 0x00000002,
  546. 0x31da, 0x00000008, 0x00000008,
  547. 0x31dc, 0x00000f00, 0x00000800,
  548. 0x31dd, 0x00000f00, 0x00000800,
  549. 0x31e6, 0x00ffffff, 0x00ff7fbf,
  550. 0x31e7, 0x00ffffff, 0x00ff7faf,
  551. 0x2300, 0x000000ff, 0x00000800,
  552. 0x390, 0x00001fff, 0x00001fff,
  553. 0x2418, 0x0000007f, 0x00000020,
  554. 0x2542, 0x00010000, 0x00010000,
  555. 0x2b80, 0x00100000, 0x000ff07c,
  556. 0x2b05, 0x000003ff, 0x0000000f,
  557. 0x2b04, 0xffffffff, 0x7564fdec,
  558. 0x2b03, 0xffffffff, 0x3120b9a8,
  559. 0x2b02, 0x20000000, 0x0f9c0000
  560. };
  561. static const u32 hawaii_mgcg_cgcg_init[] =
  562. {
  563. 0x3108, 0xffffffff, 0xfffffffd,
  564. 0xc200, 0xffffffff, 0xe0000000,
  565. 0xf0a8, 0xffffffff, 0x00000100,
  566. 0xf082, 0xffffffff, 0x00000100,
  567. 0xf0b0, 0xffffffff, 0x00000100,
  568. 0xf0b2, 0xffffffff, 0x00000100,
  569. 0xf0b1, 0xffffffff, 0x00000100,
  570. 0x1579, 0xffffffff, 0x00200100,
  571. 0xf0a0, 0xffffffff, 0x00000100,
  572. 0xf085, 0xffffffff, 0x06000100,
  573. 0xf088, 0xffffffff, 0x00000100,
  574. 0xf086, 0xffffffff, 0x06000100,
  575. 0xf081, 0xffffffff, 0x00000100,
  576. 0xf0b8, 0xffffffff, 0x00000100,
  577. 0xf089, 0xffffffff, 0x00000100,
  578. 0xf080, 0xffffffff, 0x00000100,
  579. 0xf08c, 0xffffffff, 0x00000100,
  580. 0xf08d, 0xffffffff, 0x00000100,
  581. 0xf094, 0xffffffff, 0x00000100,
  582. 0xf095, 0xffffffff, 0x00000100,
  583. 0xf096, 0xffffffff, 0x00000100,
  584. 0xf097, 0xffffffff, 0x00000100,
  585. 0xf098, 0xffffffff, 0x00000100,
  586. 0xf09f, 0xffffffff, 0x00000100,
  587. 0xf09e, 0xffffffff, 0x00000100,
  588. 0xf084, 0xffffffff, 0x06000100,
  589. 0xf0a4, 0xffffffff, 0x00000100,
  590. 0xf09d, 0xffffffff, 0x00000100,
  591. 0xf0ad, 0xffffffff, 0x00000100,
  592. 0xf0ac, 0xffffffff, 0x00000100,
  593. 0xf09c, 0xffffffff, 0x00000100,
  594. 0xc200, 0xffffffff, 0xe0000000,
  595. 0xf008, 0xffffffff, 0x00010000,
  596. 0xf009, 0xffffffff, 0x00030002,
  597. 0xf00a, 0xffffffff, 0x00040007,
  598. 0xf00b, 0xffffffff, 0x00060005,
  599. 0xf00c, 0xffffffff, 0x00090008,
  600. 0xf00d, 0xffffffff, 0x00010000,
  601. 0xf00e, 0xffffffff, 0x00030002,
  602. 0xf00f, 0xffffffff, 0x00040007,
  603. 0xf010, 0xffffffff, 0x00060005,
  604. 0xf011, 0xffffffff, 0x00090008,
  605. 0xf012, 0xffffffff, 0x00010000,
  606. 0xf013, 0xffffffff, 0x00030002,
  607. 0xf014, 0xffffffff, 0x00040007,
  608. 0xf015, 0xffffffff, 0x00060005,
  609. 0xf016, 0xffffffff, 0x00090008,
  610. 0xf017, 0xffffffff, 0x00010000,
  611. 0xf018, 0xffffffff, 0x00030002,
  612. 0xf019, 0xffffffff, 0x00040007,
  613. 0xf01a, 0xffffffff, 0x00060005,
  614. 0xf01b, 0xffffffff, 0x00090008,
  615. 0xf01c, 0xffffffff, 0x00010000,
  616. 0xf01d, 0xffffffff, 0x00030002,
  617. 0xf01e, 0xffffffff, 0x00040007,
  618. 0xf01f, 0xffffffff, 0x00060005,
  619. 0xf020, 0xffffffff, 0x00090008,
  620. 0xf021, 0xffffffff, 0x00010000,
  621. 0xf022, 0xffffffff, 0x00030002,
  622. 0xf023, 0xffffffff, 0x00040007,
  623. 0xf024, 0xffffffff, 0x00060005,
  624. 0xf025, 0xffffffff, 0x00090008,
  625. 0xf026, 0xffffffff, 0x00010000,
  626. 0xf027, 0xffffffff, 0x00030002,
  627. 0xf028, 0xffffffff, 0x00040007,
  628. 0xf029, 0xffffffff, 0x00060005,
  629. 0xf02a, 0xffffffff, 0x00090008,
  630. 0xf02b, 0xffffffff, 0x00010000,
  631. 0xf02c, 0xffffffff, 0x00030002,
  632. 0xf02d, 0xffffffff, 0x00040007,
  633. 0xf02e, 0xffffffff, 0x00060005,
  634. 0xf02f, 0xffffffff, 0x00090008,
  635. 0xf030, 0xffffffff, 0x00010000,
  636. 0xf031, 0xffffffff, 0x00030002,
  637. 0xf032, 0xffffffff, 0x00040007,
  638. 0xf033, 0xffffffff, 0x00060005,
  639. 0xf034, 0xffffffff, 0x00090008,
  640. 0xf035, 0xffffffff, 0x00010000,
  641. 0xf036, 0xffffffff, 0x00030002,
  642. 0xf037, 0xffffffff, 0x00040007,
  643. 0xf038, 0xffffffff, 0x00060005,
  644. 0xf039, 0xffffffff, 0x00090008,
  645. 0xf03a, 0xffffffff, 0x00010000,
  646. 0xf03b, 0xffffffff, 0x00030002,
  647. 0xf03c, 0xffffffff, 0x00040007,
  648. 0xf03d, 0xffffffff, 0x00060005,
  649. 0xf03e, 0xffffffff, 0x00090008,
  650. 0x30c6, 0xffffffff, 0x00020200,
  651. 0xcd4, 0xffffffff, 0x00000200,
  652. 0x570, 0xffffffff, 0x00000400,
  653. 0x157a, 0xffffffff, 0x00000000,
  654. 0xbd4, 0xffffffff, 0x00000902,
  655. 0xf000, 0xffffffff, 0x96940200,
  656. 0x21c2, 0xffffffff, 0x00900100,
  657. 0x3109, 0xffffffff, 0x0020003f,
  658. 0xe, 0xffffffff, 0x0140001c,
  659. 0xf, 0x000f0000, 0x000f0000,
  660. 0x88, 0xffffffff, 0xc060000c,
  661. 0x89, 0xc0000fff, 0x00000100,
  662. 0x3e4, 0xffffffff, 0x00000100,
  663. 0x3e6, 0x00000101, 0x00000000,
  664. 0x82a, 0xffffffff, 0x00000104,
  665. 0x1579, 0xff000fff, 0x00000100,
  666. 0xc33, 0xc0000fff, 0x00000104,
  667. 0x3079, 0x00000001, 0x00000001,
  668. 0x3403, 0xff000ff0, 0x00000100,
  669. 0x3603, 0xff000ff0, 0x00000100
  670. };
  671. static const u32 godavari_golden_registers[] =
  672. {
  673. 0x1579, 0xff607fff, 0xfc000100,
  674. 0x1bb6, 0x00010101, 0x00010000,
  675. 0x260c, 0xffffffff, 0x00000000,
  676. 0x260c0, 0xf00fffff, 0x00000400,
  677. 0x184c, 0xffffffff, 0x00010000,
  678. 0x16ec, 0x000000f0, 0x00000070,
  679. 0x16f0, 0xf0311fff, 0x80300000,
  680. 0x263e, 0x73773777, 0x12010001,
  681. 0x263f, 0xffffffff, 0x00000010,
  682. 0x200c, 0x00001f0f, 0x0000100a,
  683. 0xbd2, 0x73773777, 0x12010001,
  684. 0x902, 0x000fffff, 0x000c007f,
  685. 0x2285, 0xf000003f, 0x00000007,
  686. 0x22c9, 0xffffffff, 0x00ff0fff,
  687. 0xc281, 0x0000ff0f, 0x00000000,
  688. 0xa293, 0x07ffffff, 0x06000000,
  689. 0x136, 0x00000fff, 0x00000100,
  690. 0x3405, 0x00010000, 0x00810001,
  691. 0x3605, 0x00010000, 0x00810001,
  692. 0xf9e, 0x00000001, 0x00000002,
  693. 0x31da, 0x00000008, 0x00000008,
  694. 0x31dc, 0x00000f00, 0x00000800,
  695. 0x31dd, 0x00000f00, 0x00000800,
  696. 0x31e6, 0x00ffffff, 0x00ff7fbf,
  697. 0x31e7, 0x00ffffff, 0x00ff7faf,
  698. 0x2300, 0x000000ff, 0x00000001,
  699. 0x853e, 0x01ff01ff, 0x00000002,
  700. 0x8526, 0x007ff800, 0x00200000,
  701. 0x8057, 0xffffffff, 0x00000f40,
  702. 0x2231, 0x001f3ae3, 0x00000082,
  703. 0x2235, 0x0000001f, 0x00000010,
  704. 0xc24d, 0xffffffff, 0x00000000
  705. };
  706. static void cik_init_golden_registers(struct amdgpu_device *adev)
  707. {
  708. /* Some of the registers might be dependent on GRBM_GFX_INDEX */
  709. mutex_lock(&adev->grbm_idx_mutex);
  710. switch (adev->asic_type) {
  711. case CHIP_BONAIRE:
  712. amdgpu_program_register_sequence(adev,
  713. bonaire_mgcg_cgcg_init,
  714. (const u32)ARRAY_SIZE(bonaire_mgcg_cgcg_init));
  715. amdgpu_program_register_sequence(adev,
  716. bonaire_golden_registers,
  717. (const u32)ARRAY_SIZE(bonaire_golden_registers));
  718. amdgpu_program_register_sequence(adev,
  719. bonaire_golden_common_registers,
  720. (const u32)ARRAY_SIZE(bonaire_golden_common_registers));
  721. amdgpu_program_register_sequence(adev,
  722. bonaire_golden_spm_registers,
  723. (const u32)ARRAY_SIZE(bonaire_golden_spm_registers));
  724. break;
  725. case CHIP_KABINI:
  726. amdgpu_program_register_sequence(adev,
  727. kalindi_mgcg_cgcg_init,
  728. (const u32)ARRAY_SIZE(kalindi_mgcg_cgcg_init));
  729. amdgpu_program_register_sequence(adev,
  730. kalindi_golden_registers,
  731. (const u32)ARRAY_SIZE(kalindi_golden_registers));
  732. amdgpu_program_register_sequence(adev,
  733. kalindi_golden_common_registers,
  734. (const u32)ARRAY_SIZE(kalindi_golden_common_registers));
  735. amdgpu_program_register_sequence(adev,
  736. kalindi_golden_spm_registers,
  737. (const u32)ARRAY_SIZE(kalindi_golden_spm_registers));
  738. break;
  739. case CHIP_MULLINS:
  740. amdgpu_program_register_sequence(adev,
  741. kalindi_mgcg_cgcg_init,
  742. (const u32)ARRAY_SIZE(kalindi_mgcg_cgcg_init));
  743. amdgpu_program_register_sequence(adev,
  744. godavari_golden_registers,
  745. (const u32)ARRAY_SIZE(godavari_golden_registers));
  746. amdgpu_program_register_sequence(adev,
  747. kalindi_golden_common_registers,
  748. (const u32)ARRAY_SIZE(kalindi_golden_common_registers));
  749. amdgpu_program_register_sequence(adev,
  750. kalindi_golden_spm_registers,
  751. (const u32)ARRAY_SIZE(kalindi_golden_spm_registers));
  752. break;
  753. case CHIP_KAVERI:
  754. amdgpu_program_register_sequence(adev,
  755. spectre_mgcg_cgcg_init,
  756. (const u32)ARRAY_SIZE(spectre_mgcg_cgcg_init));
  757. amdgpu_program_register_sequence(adev,
  758. spectre_golden_registers,
  759. (const u32)ARRAY_SIZE(spectre_golden_registers));
  760. amdgpu_program_register_sequence(adev,
  761. spectre_golden_common_registers,
  762. (const u32)ARRAY_SIZE(spectre_golden_common_registers));
  763. amdgpu_program_register_sequence(adev,
  764. spectre_golden_spm_registers,
  765. (const u32)ARRAY_SIZE(spectre_golden_spm_registers));
  766. break;
  767. case CHIP_HAWAII:
  768. amdgpu_program_register_sequence(adev,
  769. hawaii_mgcg_cgcg_init,
  770. (const u32)ARRAY_SIZE(hawaii_mgcg_cgcg_init));
  771. amdgpu_program_register_sequence(adev,
  772. hawaii_golden_registers,
  773. (const u32)ARRAY_SIZE(hawaii_golden_registers));
  774. amdgpu_program_register_sequence(adev,
  775. hawaii_golden_common_registers,
  776. (const u32)ARRAY_SIZE(hawaii_golden_common_registers));
  777. amdgpu_program_register_sequence(adev,
  778. hawaii_golden_spm_registers,
  779. (const u32)ARRAY_SIZE(hawaii_golden_spm_registers));
  780. break;
  781. default:
  782. break;
  783. }
  784. mutex_unlock(&adev->grbm_idx_mutex);
  785. }
  786. /**
  787. * cik_get_xclk - get the xclk
  788. *
  789. * @adev: amdgpu_device pointer
  790. *
  791. * Returns the reference clock used by the gfx engine
  792. * (CIK).
  793. */
  794. static u32 cik_get_xclk(struct amdgpu_device *adev)
  795. {
  796. u32 reference_clock = adev->clock.spll.reference_freq;
  797. if (adev->flags & AMD_IS_APU) {
  798. if (RREG32_SMC(ixGENERAL_PWRMGT) & GENERAL_PWRMGT__GPU_COUNTER_CLK_MASK)
  799. return reference_clock / 2;
  800. } else {
  801. if (RREG32_SMC(ixCG_CLKPIN_CNTL) & CG_CLKPIN_CNTL__XTALIN_DIVIDE_MASK)
  802. return reference_clock / 4;
  803. }
  804. return reference_clock;
  805. }
  806. /**
  807. * cik_srbm_select - select specific register instances
  808. *
  809. * @adev: amdgpu_device pointer
  810. * @me: selected ME (micro engine)
  811. * @pipe: pipe
  812. * @queue: queue
  813. * @vmid: VMID
  814. *
  815. * Switches the currently active registers instances. Some
  816. * registers are instanced per VMID, others are instanced per
  817. * me/pipe/queue combination.
  818. */
  819. void cik_srbm_select(struct amdgpu_device *adev,
  820. u32 me, u32 pipe, u32 queue, u32 vmid)
  821. {
  822. u32 srbm_gfx_cntl =
  823. (((pipe << SRBM_GFX_CNTL__PIPEID__SHIFT) & SRBM_GFX_CNTL__PIPEID_MASK)|
  824. ((me << SRBM_GFX_CNTL__MEID__SHIFT) & SRBM_GFX_CNTL__MEID_MASK)|
  825. ((vmid << SRBM_GFX_CNTL__VMID__SHIFT) & SRBM_GFX_CNTL__VMID_MASK)|
  826. ((queue << SRBM_GFX_CNTL__QUEUEID__SHIFT) & SRBM_GFX_CNTL__QUEUEID_MASK));
  827. WREG32(mmSRBM_GFX_CNTL, srbm_gfx_cntl);
  828. }
  829. static void cik_vga_set_state(struct amdgpu_device *adev, bool state)
  830. {
  831. uint32_t tmp;
  832. tmp = RREG32(mmCONFIG_CNTL);
  833. if (state == false)
  834. tmp |= CONFIG_CNTL__VGA_DIS_MASK;
  835. else
  836. tmp &= ~CONFIG_CNTL__VGA_DIS_MASK;
  837. WREG32(mmCONFIG_CNTL, tmp);
  838. }
  839. static bool cik_read_disabled_bios(struct amdgpu_device *adev)
  840. {
  841. u32 bus_cntl;
  842. u32 d1vga_control = 0;
  843. u32 d2vga_control = 0;
  844. u32 vga_render_control = 0;
  845. u32 rom_cntl;
  846. bool r;
  847. bus_cntl = RREG32(mmBUS_CNTL);
  848. if (adev->mode_info.num_crtc) {
  849. d1vga_control = RREG32(mmD1VGA_CONTROL);
  850. d2vga_control = RREG32(mmD2VGA_CONTROL);
  851. vga_render_control = RREG32(mmVGA_RENDER_CONTROL);
  852. }
  853. rom_cntl = RREG32_SMC(ixROM_CNTL);
  854. /* enable the rom */
  855. WREG32(mmBUS_CNTL, (bus_cntl & ~BUS_CNTL__BIOS_ROM_DIS_MASK));
  856. if (adev->mode_info.num_crtc) {
  857. /* Disable VGA mode */
  858. WREG32(mmD1VGA_CONTROL,
  859. (d1vga_control & ~(D1VGA_CONTROL__D1VGA_MODE_ENABLE_MASK |
  860. D1VGA_CONTROL__D1VGA_TIMING_SELECT_MASK)));
  861. WREG32(mmD2VGA_CONTROL,
  862. (d2vga_control & ~(D1VGA_CONTROL__D1VGA_MODE_ENABLE_MASK |
  863. D1VGA_CONTROL__D1VGA_TIMING_SELECT_MASK)));
  864. WREG32(mmVGA_RENDER_CONTROL,
  865. (vga_render_control & ~VGA_RENDER_CONTROL__VGA_VSTATUS_CNTL_MASK));
  866. }
  867. WREG32_SMC(ixROM_CNTL, rom_cntl | ROM_CNTL__SCK_OVERWRITE_MASK);
  868. r = amdgpu_read_bios(adev);
  869. /* restore regs */
  870. WREG32(mmBUS_CNTL, bus_cntl);
  871. if (adev->mode_info.num_crtc) {
  872. WREG32(mmD1VGA_CONTROL, d1vga_control);
  873. WREG32(mmD2VGA_CONTROL, d2vga_control);
  874. WREG32(mmVGA_RENDER_CONTROL, vga_render_control);
  875. }
  876. WREG32_SMC(ixROM_CNTL, rom_cntl);
  877. return r;
  878. }
  879. static bool cik_read_bios_from_rom(struct amdgpu_device *adev,
  880. u8 *bios, u32 length_bytes)
  881. {
  882. u32 *dw_ptr;
  883. unsigned long flags;
  884. u32 i, length_dw;
  885. if (bios == NULL)
  886. return false;
  887. if (length_bytes == 0)
  888. return false;
  889. /* APU vbios image is part of sbios image */
  890. if (adev->flags & AMD_IS_APU)
  891. return false;
  892. dw_ptr = (u32 *)bios;
  893. length_dw = ALIGN(length_bytes, 4) / 4;
  894. /* take the smc lock since we are using the smc index */
  895. spin_lock_irqsave(&adev->smc_idx_lock, flags);
  896. /* set rom index to 0 */
  897. WREG32(mmSMC_IND_INDEX_0, ixROM_INDEX);
  898. WREG32(mmSMC_IND_DATA_0, 0);
  899. /* set index to data for continous read */
  900. WREG32(mmSMC_IND_INDEX_0, ixROM_DATA);
  901. for (i = 0; i < length_dw; i++)
  902. dw_ptr[i] = RREG32(mmSMC_IND_DATA_0);
  903. spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
  904. return true;
  905. }
  906. static const struct amdgpu_allowed_register_entry cik_allowed_read_registers[] = {
  907. {mmGRBM_STATUS, false},
  908. {mmGB_ADDR_CONFIG, false},
  909. {mmMC_ARB_RAMCFG, false},
  910. {mmGB_TILE_MODE0, false},
  911. {mmGB_TILE_MODE1, false},
  912. {mmGB_TILE_MODE2, false},
  913. {mmGB_TILE_MODE3, false},
  914. {mmGB_TILE_MODE4, false},
  915. {mmGB_TILE_MODE5, false},
  916. {mmGB_TILE_MODE6, false},
  917. {mmGB_TILE_MODE7, false},
  918. {mmGB_TILE_MODE8, false},
  919. {mmGB_TILE_MODE9, false},
  920. {mmGB_TILE_MODE10, false},
  921. {mmGB_TILE_MODE11, false},
  922. {mmGB_TILE_MODE12, false},
  923. {mmGB_TILE_MODE13, false},
  924. {mmGB_TILE_MODE14, false},
  925. {mmGB_TILE_MODE15, false},
  926. {mmGB_TILE_MODE16, false},
  927. {mmGB_TILE_MODE17, false},
  928. {mmGB_TILE_MODE18, false},
  929. {mmGB_TILE_MODE19, false},
  930. {mmGB_TILE_MODE20, false},
  931. {mmGB_TILE_MODE21, false},
  932. {mmGB_TILE_MODE22, false},
  933. {mmGB_TILE_MODE23, false},
  934. {mmGB_TILE_MODE24, false},
  935. {mmGB_TILE_MODE25, false},
  936. {mmGB_TILE_MODE26, false},
  937. {mmGB_TILE_MODE27, false},
  938. {mmGB_TILE_MODE28, false},
  939. {mmGB_TILE_MODE29, false},
  940. {mmGB_TILE_MODE30, false},
  941. {mmGB_TILE_MODE31, false},
  942. {mmGB_MACROTILE_MODE0, false},
  943. {mmGB_MACROTILE_MODE1, false},
  944. {mmGB_MACROTILE_MODE2, false},
  945. {mmGB_MACROTILE_MODE3, false},
  946. {mmGB_MACROTILE_MODE4, false},
  947. {mmGB_MACROTILE_MODE5, false},
  948. {mmGB_MACROTILE_MODE6, false},
  949. {mmGB_MACROTILE_MODE7, false},
  950. {mmGB_MACROTILE_MODE8, false},
  951. {mmGB_MACROTILE_MODE9, false},
  952. {mmGB_MACROTILE_MODE10, false},
  953. {mmGB_MACROTILE_MODE11, false},
  954. {mmGB_MACROTILE_MODE12, false},
  955. {mmGB_MACROTILE_MODE13, false},
  956. {mmGB_MACROTILE_MODE14, false},
  957. {mmGB_MACROTILE_MODE15, false},
  958. {mmCC_RB_BACKEND_DISABLE, false, true},
  959. {mmGC_USER_RB_BACKEND_DISABLE, false, true},
  960. {mmGB_BACKEND_MAP, false, false},
  961. {mmPA_SC_RASTER_CONFIG, false, true},
  962. {mmPA_SC_RASTER_CONFIG_1, false, true},
  963. };
  964. static uint32_t cik_read_indexed_register(struct amdgpu_device *adev,
  965. u32 se_num, u32 sh_num,
  966. u32 reg_offset)
  967. {
  968. uint32_t val;
  969. mutex_lock(&adev->grbm_idx_mutex);
  970. if (se_num != 0xffffffff || sh_num != 0xffffffff)
  971. gfx_v7_0_select_se_sh(adev, se_num, sh_num);
  972. val = RREG32(reg_offset);
  973. if (se_num != 0xffffffff || sh_num != 0xffffffff)
  974. gfx_v7_0_select_se_sh(adev, 0xffffffff, 0xffffffff);
  975. mutex_unlock(&adev->grbm_idx_mutex);
  976. return val;
  977. }
  978. static int cik_read_register(struct amdgpu_device *adev, u32 se_num,
  979. u32 sh_num, u32 reg_offset, u32 *value)
  980. {
  981. uint32_t i;
  982. *value = 0;
  983. for (i = 0; i < ARRAY_SIZE(cik_allowed_read_registers); i++) {
  984. if (reg_offset != cik_allowed_read_registers[i].reg_offset)
  985. continue;
  986. if (!cik_allowed_read_registers[i].untouched)
  987. *value = cik_allowed_read_registers[i].grbm_indexed ?
  988. cik_read_indexed_register(adev, se_num,
  989. sh_num, reg_offset) :
  990. RREG32(reg_offset);
  991. return 0;
  992. }
  993. return -EINVAL;
  994. }
  995. struct kv_reset_save_regs {
  996. u32 gmcon_reng_execute;
  997. u32 gmcon_misc;
  998. u32 gmcon_misc3;
  999. };
  1000. static void kv_save_regs_for_reset(struct amdgpu_device *adev,
  1001. struct kv_reset_save_regs *save)
  1002. {
  1003. save->gmcon_reng_execute = RREG32(mmGMCON_RENG_EXECUTE);
  1004. save->gmcon_misc = RREG32(mmGMCON_MISC);
  1005. save->gmcon_misc3 = RREG32(mmGMCON_MISC3);
  1006. WREG32(mmGMCON_RENG_EXECUTE, save->gmcon_reng_execute &
  1007. ~GMCON_RENG_EXECUTE__RENG_EXECUTE_ON_PWR_UP_MASK);
  1008. WREG32(mmGMCON_MISC, save->gmcon_misc &
  1009. ~(GMCON_MISC__RENG_EXECUTE_ON_REG_UPDATE_MASK |
  1010. GMCON_MISC__STCTRL_STUTTER_EN_MASK));
  1011. }
  1012. static void kv_restore_regs_for_reset(struct amdgpu_device *adev,
  1013. struct kv_reset_save_regs *save)
  1014. {
  1015. int i;
  1016. WREG32(mmGMCON_PGFSM_WRITE, 0);
  1017. WREG32(mmGMCON_PGFSM_CONFIG, 0x200010ff);
  1018. for (i = 0; i < 5; i++)
  1019. WREG32(mmGMCON_PGFSM_WRITE, 0);
  1020. WREG32(mmGMCON_PGFSM_WRITE, 0);
  1021. WREG32(mmGMCON_PGFSM_CONFIG, 0x300010ff);
  1022. for (i = 0; i < 5; i++)
  1023. WREG32(mmGMCON_PGFSM_WRITE, 0);
  1024. WREG32(mmGMCON_PGFSM_WRITE, 0x210000);
  1025. WREG32(mmGMCON_PGFSM_CONFIG, 0xa00010ff);
  1026. for (i = 0; i < 5; i++)
  1027. WREG32(mmGMCON_PGFSM_WRITE, 0);
  1028. WREG32(mmGMCON_PGFSM_WRITE, 0x21003);
  1029. WREG32(mmGMCON_PGFSM_CONFIG, 0xb00010ff);
  1030. for (i = 0; i < 5; i++)
  1031. WREG32(mmGMCON_PGFSM_WRITE, 0);
  1032. WREG32(mmGMCON_PGFSM_WRITE, 0x2b00);
  1033. WREG32(mmGMCON_PGFSM_CONFIG, 0xc00010ff);
  1034. for (i = 0; i < 5; i++)
  1035. WREG32(mmGMCON_PGFSM_WRITE, 0);
  1036. WREG32(mmGMCON_PGFSM_WRITE, 0);
  1037. WREG32(mmGMCON_PGFSM_CONFIG, 0xd00010ff);
  1038. for (i = 0; i < 5; i++)
  1039. WREG32(mmGMCON_PGFSM_WRITE, 0);
  1040. WREG32(mmGMCON_PGFSM_WRITE, 0x420000);
  1041. WREG32(mmGMCON_PGFSM_CONFIG, 0x100010ff);
  1042. for (i = 0; i < 5; i++)
  1043. WREG32(mmGMCON_PGFSM_WRITE, 0);
  1044. WREG32(mmGMCON_PGFSM_WRITE, 0x120202);
  1045. WREG32(mmGMCON_PGFSM_CONFIG, 0x500010ff);
  1046. for (i = 0; i < 5; i++)
  1047. WREG32(mmGMCON_PGFSM_WRITE, 0);
  1048. WREG32(mmGMCON_PGFSM_WRITE, 0x3e3e36);
  1049. WREG32(mmGMCON_PGFSM_CONFIG, 0x600010ff);
  1050. for (i = 0; i < 5; i++)
  1051. WREG32(mmGMCON_PGFSM_WRITE, 0);
  1052. WREG32(mmGMCON_PGFSM_WRITE, 0x373f3e);
  1053. WREG32(mmGMCON_PGFSM_CONFIG, 0x700010ff);
  1054. for (i = 0; i < 5; i++)
  1055. WREG32(mmGMCON_PGFSM_WRITE, 0);
  1056. WREG32(mmGMCON_PGFSM_WRITE, 0x3e1332);
  1057. WREG32(mmGMCON_PGFSM_CONFIG, 0xe00010ff);
  1058. WREG32(mmGMCON_MISC3, save->gmcon_misc3);
  1059. WREG32(mmGMCON_MISC, save->gmcon_misc);
  1060. WREG32(mmGMCON_RENG_EXECUTE, save->gmcon_reng_execute);
  1061. }
  1062. static void cik_gpu_pci_config_reset(struct amdgpu_device *adev)
  1063. {
  1064. struct kv_reset_save_regs kv_save = { 0 };
  1065. u32 i;
  1066. dev_info(adev->dev, "GPU pci config reset\n");
  1067. if (adev->flags & AMD_IS_APU)
  1068. kv_save_regs_for_reset(adev, &kv_save);
  1069. /* disable BM */
  1070. pci_clear_master(adev->pdev);
  1071. /* reset */
  1072. amdgpu_pci_config_reset(adev);
  1073. udelay(100);
  1074. /* wait for asic to come out of reset */
  1075. for (i = 0; i < adev->usec_timeout; i++) {
  1076. if (RREG32(mmCONFIG_MEMSIZE) != 0xffffffff)
  1077. break;
  1078. udelay(1);
  1079. }
  1080. /* does asic init need to be run first??? */
  1081. if (adev->flags & AMD_IS_APU)
  1082. kv_restore_regs_for_reset(adev, &kv_save);
  1083. }
  1084. static void cik_set_bios_scratch_engine_hung(struct amdgpu_device *adev, bool hung)
  1085. {
  1086. u32 tmp = RREG32(mmBIOS_SCRATCH_3);
  1087. if (hung)
  1088. tmp |= ATOM_S3_ASIC_GUI_ENGINE_HUNG;
  1089. else
  1090. tmp &= ~ATOM_S3_ASIC_GUI_ENGINE_HUNG;
  1091. WREG32(mmBIOS_SCRATCH_3, tmp);
  1092. }
  1093. /**
  1094. * cik_asic_reset - soft reset GPU
  1095. *
  1096. * @adev: amdgpu_device pointer
  1097. *
  1098. * Look up which blocks are hung and attempt
  1099. * to reset them.
  1100. * Returns 0 for success.
  1101. */
  1102. static int cik_asic_reset(struct amdgpu_device *adev)
  1103. {
  1104. cik_set_bios_scratch_engine_hung(adev, true);
  1105. cik_gpu_pci_config_reset(adev);
  1106. cik_set_bios_scratch_engine_hung(adev, false);
  1107. return 0;
  1108. }
  1109. static int cik_set_uvd_clock(struct amdgpu_device *adev, u32 clock,
  1110. u32 cntl_reg, u32 status_reg)
  1111. {
  1112. int r, i;
  1113. struct atom_clock_dividers dividers;
  1114. uint32_t tmp;
  1115. r = amdgpu_atombios_get_clock_dividers(adev,
  1116. COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK,
  1117. clock, false, &dividers);
  1118. if (r)
  1119. return r;
  1120. tmp = RREG32_SMC(cntl_reg);
  1121. tmp &= ~(CG_DCLK_CNTL__DCLK_DIR_CNTL_EN_MASK |
  1122. CG_DCLK_CNTL__DCLK_DIVIDER_MASK);
  1123. tmp |= dividers.post_divider;
  1124. WREG32_SMC(cntl_reg, tmp);
  1125. for (i = 0; i < 100; i++) {
  1126. if (RREG32_SMC(status_reg) & CG_DCLK_STATUS__DCLK_STATUS_MASK)
  1127. break;
  1128. mdelay(10);
  1129. }
  1130. if (i == 100)
  1131. return -ETIMEDOUT;
  1132. return 0;
  1133. }
  1134. static int cik_set_uvd_clocks(struct amdgpu_device *adev, u32 vclk, u32 dclk)
  1135. {
  1136. int r = 0;
  1137. r = cik_set_uvd_clock(adev, vclk, ixCG_VCLK_CNTL, ixCG_VCLK_STATUS);
  1138. if (r)
  1139. return r;
  1140. r = cik_set_uvd_clock(adev, dclk, ixCG_DCLK_CNTL, ixCG_DCLK_STATUS);
  1141. return r;
  1142. }
  1143. static int cik_set_vce_clocks(struct amdgpu_device *adev, u32 evclk, u32 ecclk)
  1144. {
  1145. int r, i;
  1146. struct atom_clock_dividers dividers;
  1147. u32 tmp;
  1148. r = amdgpu_atombios_get_clock_dividers(adev,
  1149. COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK,
  1150. ecclk, false, &dividers);
  1151. if (r)
  1152. return r;
  1153. for (i = 0; i < 100; i++) {
  1154. if (RREG32_SMC(ixCG_ECLK_STATUS) & CG_ECLK_STATUS__ECLK_STATUS_MASK)
  1155. break;
  1156. mdelay(10);
  1157. }
  1158. if (i == 100)
  1159. return -ETIMEDOUT;
  1160. tmp = RREG32_SMC(ixCG_ECLK_CNTL);
  1161. tmp &= ~(CG_ECLK_CNTL__ECLK_DIR_CNTL_EN_MASK |
  1162. CG_ECLK_CNTL__ECLK_DIVIDER_MASK);
  1163. tmp |= dividers.post_divider;
  1164. WREG32_SMC(ixCG_ECLK_CNTL, tmp);
  1165. for (i = 0; i < 100; i++) {
  1166. if (RREG32_SMC(ixCG_ECLK_STATUS) & CG_ECLK_STATUS__ECLK_STATUS_MASK)
  1167. break;
  1168. mdelay(10);
  1169. }
  1170. if (i == 100)
  1171. return -ETIMEDOUT;
  1172. return 0;
  1173. }
  1174. static void cik_pcie_gen3_enable(struct amdgpu_device *adev)
  1175. {
  1176. struct pci_dev *root = adev->pdev->bus->self;
  1177. int bridge_pos, gpu_pos;
  1178. u32 speed_cntl, current_data_rate;
  1179. int i;
  1180. u16 tmp16;
  1181. if (pci_is_root_bus(adev->pdev->bus))
  1182. return;
  1183. if (amdgpu_pcie_gen2 == 0)
  1184. return;
  1185. if (adev->flags & AMD_IS_APU)
  1186. return;
  1187. if (!(adev->pm.pcie_gen_mask & (CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2 |
  1188. CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3)))
  1189. return;
  1190. speed_cntl = RREG32_PCIE(ixPCIE_LC_SPEED_CNTL);
  1191. current_data_rate = (speed_cntl & PCIE_LC_SPEED_CNTL__LC_CURRENT_DATA_RATE_MASK) >>
  1192. PCIE_LC_SPEED_CNTL__LC_CURRENT_DATA_RATE__SHIFT;
  1193. if (adev->pm.pcie_gen_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3) {
  1194. if (current_data_rate == 2) {
  1195. DRM_INFO("PCIE gen 3 link speeds already enabled\n");
  1196. return;
  1197. }
  1198. DRM_INFO("enabling PCIE gen 3 link speeds, disable with amdgpu.pcie_gen2=0\n");
  1199. } else if (adev->pm.pcie_gen_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2) {
  1200. if (current_data_rate == 1) {
  1201. DRM_INFO("PCIE gen 2 link speeds already enabled\n");
  1202. return;
  1203. }
  1204. DRM_INFO("enabling PCIE gen 2 link speeds, disable with amdgpu.pcie_gen2=0\n");
  1205. }
  1206. bridge_pos = pci_pcie_cap(root);
  1207. if (!bridge_pos)
  1208. return;
  1209. gpu_pos = pci_pcie_cap(adev->pdev);
  1210. if (!gpu_pos)
  1211. return;
  1212. if (adev->pm.pcie_gen_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3) {
  1213. /* re-try equalization if gen3 is not already enabled */
  1214. if (current_data_rate != 2) {
  1215. u16 bridge_cfg, gpu_cfg;
  1216. u16 bridge_cfg2, gpu_cfg2;
  1217. u32 max_lw, current_lw, tmp;
  1218. pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL, &bridge_cfg);
  1219. pci_read_config_word(adev->pdev, gpu_pos + PCI_EXP_LNKCTL, &gpu_cfg);
  1220. tmp16 = bridge_cfg | PCI_EXP_LNKCTL_HAWD;
  1221. pci_write_config_word(root, bridge_pos + PCI_EXP_LNKCTL, tmp16);
  1222. tmp16 = gpu_cfg | PCI_EXP_LNKCTL_HAWD;
  1223. pci_write_config_word(adev->pdev, gpu_pos + PCI_EXP_LNKCTL, tmp16);
  1224. tmp = RREG32_PCIE(ixPCIE_LC_STATUS1);
  1225. max_lw = (tmp & PCIE_LC_STATUS1__LC_DETECTED_LINK_WIDTH_MASK) >>
  1226. PCIE_LC_STATUS1__LC_DETECTED_LINK_WIDTH__SHIFT;
  1227. current_lw = (tmp & PCIE_LC_STATUS1__LC_OPERATING_LINK_WIDTH_MASK)
  1228. >> PCIE_LC_STATUS1__LC_OPERATING_LINK_WIDTH__SHIFT;
  1229. if (current_lw < max_lw) {
  1230. tmp = RREG32_PCIE(ixPCIE_LC_LINK_WIDTH_CNTL);
  1231. if (tmp & PCIE_LC_LINK_WIDTH_CNTL__LC_RENEGOTIATION_SUPPORT_MASK) {
  1232. tmp &= ~(PCIE_LC_LINK_WIDTH_CNTL__LC_LINK_WIDTH_MASK |
  1233. PCIE_LC_LINK_WIDTH_CNTL__LC_UPCONFIGURE_DIS_MASK);
  1234. tmp |= (max_lw <<
  1235. PCIE_LC_LINK_WIDTH_CNTL__LC_LINK_WIDTH__SHIFT);
  1236. tmp |= PCIE_LC_LINK_WIDTH_CNTL__LC_UPCONFIGURE_SUPPORT_MASK |
  1237. PCIE_LC_LINK_WIDTH_CNTL__LC_RENEGOTIATE_EN_MASK |
  1238. PCIE_LC_LINK_WIDTH_CNTL__LC_RECONFIG_NOW_MASK;
  1239. WREG32_PCIE(ixPCIE_LC_LINK_WIDTH_CNTL, tmp);
  1240. }
  1241. }
  1242. for (i = 0; i < 10; i++) {
  1243. /* check status */
  1244. pci_read_config_word(adev->pdev, gpu_pos + PCI_EXP_DEVSTA, &tmp16);
  1245. if (tmp16 & PCI_EXP_DEVSTA_TRPND)
  1246. break;
  1247. pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL, &bridge_cfg);
  1248. pci_read_config_word(adev->pdev, gpu_pos + PCI_EXP_LNKCTL, &gpu_cfg);
  1249. pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL2, &bridge_cfg2);
  1250. pci_read_config_word(adev->pdev, gpu_pos + PCI_EXP_LNKCTL2, &gpu_cfg2);
  1251. tmp = RREG32_PCIE(ixPCIE_LC_CNTL4);
  1252. tmp |= PCIE_LC_CNTL4__LC_SET_QUIESCE_MASK;
  1253. WREG32_PCIE(ixPCIE_LC_CNTL4, tmp);
  1254. tmp = RREG32_PCIE(ixPCIE_LC_CNTL4);
  1255. tmp |= PCIE_LC_CNTL4__LC_REDO_EQ_MASK;
  1256. WREG32_PCIE(ixPCIE_LC_CNTL4, tmp);
  1257. mdelay(100);
  1258. /* linkctl */
  1259. pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL, &tmp16);
  1260. tmp16 &= ~PCI_EXP_LNKCTL_HAWD;
  1261. tmp16 |= (bridge_cfg & PCI_EXP_LNKCTL_HAWD);
  1262. pci_write_config_word(root, bridge_pos + PCI_EXP_LNKCTL, tmp16);
  1263. pci_read_config_word(adev->pdev, gpu_pos + PCI_EXP_LNKCTL, &tmp16);
  1264. tmp16 &= ~PCI_EXP_LNKCTL_HAWD;
  1265. tmp16 |= (gpu_cfg & PCI_EXP_LNKCTL_HAWD);
  1266. pci_write_config_word(adev->pdev, gpu_pos + PCI_EXP_LNKCTL, tmp16);
  1267. /* linkctl2 */
  1268. pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL2, &tmp16);
  1269. tmp16 &= ~((1 << 4) | (7 << 9));
  1270. tmp16 |= (bridge_cfg2 & ((1 << 4) | (7 << 9)));
  1271. pci_write_config_word(root, bridge_pos + PCI_EXP_LNKCTL2, tmp16);
  1272. pci_read_config_word(adev->pdev, gpu_pos + PCI_EXP_LNKCTL2, &tmp16);
  1273. tmp16 &= ~((1 << 4) | (7 << 9));
  1274. tmp16 |= (gpu_cfg2 & ((1 << 4) | (7 << 9)));
  1275. pci_write_config_word(adev->pdev, gpu_pos + PCI_EXP_LNKCTL2, tmp16);
  1276. tmp = RREG32_PCIE(ixPCIE_LC_CNTL4);
  1277. tmp &= ~PCIE_LC_CNTL4__LC_SET_QUIESCE_MASK;
  1278. WREG32_PCIE(ixPCIE_LC_CNTL4, tmp);
  1279. }
  1280. }
  1281. }
  1282. /* set the link speed */
  1283. speed_cntl |= PCIE_LC_SPEED_CNTL__LC_FORCE_EN_SW_SPEED_CHANGE_MASK |
  1284. PCIE_LC_SPEED_CNTL__LC_FORCE_DIS_HW_SPEED_CHANGE_MASK;
  1285. speed_cntl &= ~PCIE_LC_SPEED_CNTL__LC_FORCE_DIS_SW_SPEED_CHANGE_MASK;
  1286. WREG32_PCIE(ixPCIE_LC_SPEED_CNTL, speed_cntl);
  1287. pci_read_config_word(adev->pdev, gpu_pos + PCI_EXP_LNKCTL2, &tmp16);
  1288. tmp16 &= ~0xf;
  1289. if (adev->pm.pcie_gen_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3)
  1290. tmp16 |= 3; /* gen3 */
  1291. else if (adev->pm.pcie_gen_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2)
  1292. tmp16 |= 2; /* gen2 */
  1293. else
  1294. tmp16 |= 1; /* gen1 */
  1295. pci_write_config_word(adev->pdev, gpu_pos + PCI_EXP_LNKCTL2, tmp16);
  1296. speed_cntl = RREG32_PCIE(ixPCIE_LC_SPEED_CNTL);
  1297. speed_cntl |= PCIE_LC_SPEED_CNTL__LC_INITIATE_LINK_SPEED_CHANGE_MASK;
  1298. WREG32_PCIE(ixPCIE_LC_SPEED_CNTL, speed_cntl);
  1299. for (i = 0; i < adev->usec_timeout; i++) {
  1300. speed_cntl = RREG32_PCIE(ixPCIE_LC_SPEED_CNTL);
  1301. if ((speed_cntl & PCIE_LC_SPEED_CNTL__LC_INITIATE_LINK_SPEED_CHANGE_MASK) == 0)
  1302. break;
  1303. udelay(1);
  1304. }
  1305. }
  1306. static void cik_program_aspm(struct amdgpu_device *adev)
  1307. {
  1308. u32 data, orig;
  1309. bool disable_l0s = false, disable_l1 = false, disable_plloff_in_l1 = false;
  1310. bool disable_clkreq = false;
  1311. if (amdgpu_aspm == 0)
  1312. return;
  1313. if (pci_is_root_bus(adev->pdev->bus))
  1314. return;
  1315. /* XXX double check APUs */
  1316. if (adev->flags & AMD_IS_APU)
  1317. return;
  1318. orig = data = RREG32_PCIE(ixPCIE_LC_N_FTS_CNTL);
  1319. data &= ~PCIE_LC_N_FTS_CNTL__LC_XMIT_N_FTS_MASK;
  1320. data |= (0x24 << PCIE_LC_N_FTS_CNTL__LC_XMIT_N_FTS__SHIFT) |
  1321. PCIE_LC_N_FTS_CNTL__LC_XMIT_N_FTS_OVERRIDE_EN_MASK;
  1322. if (orig != data)
  1323. WREG32_PCIE(ixPCIE_LC_N_FTS_CNTL, data);
  1324. orig = data = RREG32_PCIE(ixPCIE_LC_CNTL3);
  1325. data |= PCIE_LC_CNTL3__LC_GO_TO_RECOVERY_MASK;
  1326. if (orig != data)
  1327. WREG32_PCIE(ixPCIE_LC_CNTL3, data);
  1328. orig = data = RREG32_PCIE(ixPCIE_P_CNTL);
  1329. data |= PCIE_P_CNTL__P_IGNORE_EDB_ERR_MASK;
  1330. if (orig != data)
  1331. WREG32_PCIE(ixPCIE_P_CNTL, data);
  1332. orig = data = RREG32_PCIE(ixPCIE_LC_CNTL);
  1333. data &= ~(PCIE_LC_CNTL__LC_L0S_INACTIVITY_MASK |
  1334. PCIE_LC_CNTL__LC_L1_INACTIVITY_MASK);
  1335. data |= PCIE_LC_CNTL__LC_PMI_TO_L1_DIS_MASK;
  1336. if (!disable_l0s)
  1337. data |= (7 << PCIE_LC_CNTL__LC_L0S_INACTIVITY__SHIFT);
  1338. if (!disable_l1) {
  1339. data |= (7 << PCIE_LC_CNTL__LC_L1_INACTIVITY__SHIFT);
  1340. data &= ~PCIE_LC_CNTL__LC_PMI_TO_L1_DIS_MASK;
  1341. if (orig != data)
  1342. WREG32_PCIE(ixPCIE_LC_CNTL, data);
  1343. if (!disable_plloff_in_l1) {
  1344. bool clk_req_support;
  1345. orig = data = RREG32_PCIE(ixPB0_PIF_PWRDOWN_0);
  1346. data &= ~(PB0_PIF_PWRDOWN_0__PLL_POWER_STATE_IN_OFF_0_MASK |
  1347. PB0_PIF_PWRDOWN_0__PLL_POWER_STATE_IN_TXS2_0_MASK);
  1348. data |= (7 << PB0_PIF_PWRDOWN_0__PLL_POWER_STATE_IN_OFF_0__SHIFT) |
  1349. (7 << PB0_PIF_PWRDOWN_0__PLL_POWER_STATE_IN_TXS2_0__SHIFT);
  1350. if (orig != data)
  1351. WREG32_PCIE(ixPB0_PIF_PWRDOWN_0, data);
  1352. orig = data = RREG32_PCIE(ixPB0_PIF_PWRDOWN_1);
  1353. data &= ~(PB0_PIF_PWRDOWN_1__PLL_POWER_STATE_IN_OFF_1_MASK |
  1354. PB0_PIF_PWRDOWN_1__PLL_POWER_STATE_IN_TXS2_1_MASK);
  1355. data |= (7 << PB0_PIF_PWRDOWN_1__PLL_POWER_STATE_IN_OFF_1__SHIFT) |
  1356. (7 << PB0_PIF_PWRDOWN_1__PLL_POWER_STATE_IN_TXS2_1__SHIFT);
  1357. if (orig != data)
  1358. WREG32_PCIE(ixPB0_PIF_PWRDOWN_1, data);
  1359. orig = data = RREG32_PCIE(ixPB1_PIF_PWRDOWN_0);
  1360. data &= ~(PB1_PIF_PWRDOWN_0__PLL_POWER_STATE_IN_OFF_0_MASK |
  1361. PB1_PIF_PWRDOWN_0__PLL_POWER_STATE_IN_TXS2_0_MASK);
  1362. data |= (7 << PB1_PIF_PWRDOWN_0__PLL_POWER_STATE_IN_OFF_0__SHIFT) |
  1363. (7 << PB1_PIF_PWRDOWN_0__PLL_POWER_STATE_IN_TXS2_0__SHIFT);
  1364. if (orig != data)
  1365. WREG32_PCIE(ixPB1_PIF_PWRDOWN_0, data);
  1366. orig = data = RREG32_PCIE(ixPB1_PIF_PWRDOWN_1);
  1367. data &= ~(PB1_PIF_PWRDOWN_1__PLL_POWER_STATE_IN_OFF_1_MASK |
  1368. PB1_PIF_PWRDOWN_1__PLL_POWER_STATE_IN_TXS2_1_MASK);
  1369. data |= (7 << PB1_PIF_PWRDOWN_1__PLL_POWER_STATE_IN_OFF_1__SHIFT) |
  1370. (7 << PB1_PIF_PWRDOWN_1__PLL_POWER_STATE_IN_TXS2_1__SHIFT);
  1371. if (orig != data)
  1372. WREG32_PCIE(ixPB1_PIF_PWRDOWN_1, data);
  1373. orig = data = RREG32_PCIE(ixPCIE_LC_LINK_WIDTH_CNTL);
  1374. data &= ~PCIE_LC_LINK_WIDTH_CNTL__LC_DYN_LANES_PWR_STATE_MASK;
  1375. data |= ~(3 << PCIE_LC_LINK_WIDTH_CNTL__LC_DYN_LANES_PWR_STATE__SHIFT);
  1376. if (orig != data)
  1377. WREG32_PCIE(ixPCIE_LC_LINK_WIDTH_CNTL, data);
  1378. if (!disable_clkreq) {
  1379. struct pci_dev *root = adev->pdev->bus->self;
  1380. u32 lnkcap;
  1381. clk_req_support = false;
  1382. pcie_capability_read_dword(root, PCI_EXP_LNKCAP, &lnkcap);
  1383. if (lnkcap & PCI_EXP_LNKCAP_CLKPM)
  1384. clk_req_support = true;
  1385. } else {
  1386. clk_req_support = false;
  1387. }
  1388. if (clk_req_support) {
  1389. orig = data = RREG32_PCIE(ixPCIE_LC_CNTL2);
  1390. data |= PCIE_LC_CNTL2__LC_ALLOW_PDWN_IN_L1_MASK |
  1391. PCIE_LC_CNTL2__LC_ALLOW_PDWN_IN_L23_MASK;
  1392. if (orig != data)
  1393. WREG32_PCIE(ixPCIE_LC_CNTL2, data);
  1394. orig = data = RREG32_SMC(ixTHM_CLK_CNTL);
  1395. data &= ~(THM_CLK_CNTL__CMON_CLK_SEL_MASK |
  1396. THM_CLK_CNTL__TMON_CLK_SEL_MASK);
  1397. data |= (1 << THM_CLK_CNTL__CMON_CLK_SEL__SHIFT) |
  1398. (1 << THM_CLK_CNTL__TMON_CLK_SEL__SHIFT);
  1399. if (orig != data)
  1400. WREG32_SMC(ixTHM_CLK_CNTL, data);
  1401. orig = data = RREG32_SMC(ixMISC_CLK_CTRL);
  1402. data &= ~(MISC_CLK_CTRL__DEEP_SLEEP_CLK_SEL_MASK |
  1403. MISC_CLK_CTRL__ZCLK_SEL_MASK);
  1404. data |= (1 << MISC_CLK_CTRL__DEEP_SLEEP_CLK_SEL__SHIFT) |
  1405. (1 << MISC_CLK_CTRL__ZCLK_SEL__SHIFT);
  1406. if (orig != data)
  1407. WREG32_SMC(ixMISC_CLK_CTRL, data);
  1408. orig = data = RREG32_SMC(ixCG_CLKPIN_CNTL);
  1409. data &= ~CG_CLKPIN_CNTL__BCLK_AS_XCLK_MASK;
  1410. if (orig != data)
  1411. WREG32_SMC(ixCG_CLKPIN_CNTL, data);
  1412. orig = data = RREG32_SMC(ixCG_CLKPIN_CNTL_2);
  1413. data &= ~CG_CLKPIN_CNTL_2__FORCE_BIF_REFCLK_EN_MASK;
  1414. if (orig != data)
  1415. WREG32_SMC(ixCG_CLKPIN_CNTL_2, data);
  1416. orig = data = RREG32_SMC(ixMPLL_BYPASSCLK_SEL);
  1417. data &= ~MPLL_BYPASSCLK_SEL__MPLL_CLKOUT_SEL_MASK;
  1418. data |= (4 << MPLL_BYPASSCLK_SEL__MPLL_CLKOUT_SEL__SHIFT);
  1419. if (orig != data)
  1420. WREG32_SMC(ixMPLL_BYPASSCLK_SEL, data);
  1421. }
  1422. }
  1423. } else {
  1424. if (orig != data)
  1425. WREG32_PCIE(ixPCIE_LC_CNTL, data);
  1426. }
  1427. orig = data = RREG32_PCIE(ixPCIE_CNTL2);
  1428. data |= PCIE_CNTL2__SLV_MEM_LS_EN_MASK |
  1429. PCIE_CNTL2__MST_MEM_LS_EN_MASK |
  1430. PCIE_CNTL2__REPLAY_MEM_LS_EN_MASK;
  1431. if (orig != data)
  1432. WREG32_PCIE(ixPCIE_CNTL2, data);
  1433. if (!disable_l0s) {
  1434. data = RREG32_PCIE(ixPCIE_LC_N_FTS_CNTL);
  1435. if ((data & PCIE_LC_N_FTS_CNTL__LC_N_FTS_MASK) ==
  1436. PCIE_LC_N_FTS_CNTL__LC_N_FTS_MASK) {
  1437. data = RREG32_PCIE(ixPCIE_LC_STATUS1);
  1438. if ((data & PCIE_LC_STATUS1__LC_REVERSE_XMIT_MASK) &&
  1439. (data & PCIE_LC_STATUS1__LC_REVERSE_RCVR_MASK)) {
  1440. orig = data = RREG32_PCIE(ixPCIE_LC_CNTL);
  1441. data &= ~PCIE_LC_CNTL__LC_L0S_INACTIVITY_MASK;
  1442. if (orig != data)
  1443. WREG32_PCIE(ixPCIE_LC_CNTL, data);
  1444. }
  1445. }
  1446. }
  1447. }
  1448. static uint32_t cik_get_rev_id(struct amdgpu_device *adev)
  1449. {
  1450. return (RREG32(mmCC_DRM_ID_STRAPS) & CC_DRM_ID_STRAPS__ATI_REV_ID_MASK)
  1451. >> CC_DRM_ID_STRAPS__ATI_REV_ID__SHIFT;
  1452. }
  1453. static const struct amdgpu_ip_block_version bonaire_ip_blocks[] =
  1454. {
  1455. /* ORDER MATTERS! */
  1456. {
  1457. .type = AMD_IP_BLOCK_TYPE_COMMON,
  1458. .major = 1,
  1459. .minor = 0,
  1460. .rev = 0,
  1461. .funcs = &cik_common_ip_funcs,
  1462. },
  1463. {
  1464. .type = AMD_IP_BLOCK_TYPE_GMC,
  1465. .major = 7,
  1466. .minor = 0,
  1467. .rev = 0,
  1468. .funcs = &gmc_v7_0_ip_funcs,
  1469. },
  1470. {
  1471. .type = AMD_IP_BLOCK_TYPE_IH,
  1472. .major = 2,
  1473. .minor = 0,
  1474. .rev = 0,
  1475. .funcs = &cik_ih_ip_funcs,
  1476. },
  1477. {
  1478. .type = AMD_IP_BLOCK_TYPE_SMC,
  1479. .major = 7,
  1480. .minor = 0,
  1481. .rev = 0,
  1482. .funcs = &amdgpu_pp_ip_funcs,
  1483. },
  1484. {
  1485. .type = AMD_IP_BLOCK_TYPE_DCE,
  1486. .major = 8,
  1487. .minor = 2,
  1488. .rev = 0,
  1489. .funcs = &dce_v8_0_ip_funcs,
  1490. },
  1491. {
  1492. .type = AMD_IP_BLOCK_TYPE_GFX,
  1493. .major = 7,
  1494. .minor = 2,
  1495. .rev = 0,
  1496. .funcs = &gfx_v7_0_ip_funcs,
  1497. },
  1498. {
  1499. .type = AMD_IP_BLOCK_TYPE_SDMA,
  1500. .major = 2,
  1501. .minor = 0,
  1502. .rev = 0,
  1503. .funcs = &cik_sdma_ip_funcs,
  1504. },
  1505. {
  1506. .type = AMD_IP_BLOCK_TYPE_UVD,
  1507. .major = 4,
  1508. .minor = 2,
  1509. .rev = 0,
  1510. .funcs = &uvd_v4_2_ip_funcs,
  1511. },
  1512. {
  1513. .type = AMD_IP_BLOCK_TYPE_VCE,
  1514. .major = 2,
  1515. .minor = 0,
  1516. .rev = 0,
  1517. .funcs = &vce_v2_0_ip_funcs,
  1518. },
  1519. };
  1520. static const struct amdgpu_ip_block_version hawaii_ip_blocks[] =
  1521. {
  1522. /* ORDER MATTERS! */
  1523. {
  1524. .type = AMD_IP_BLOCK_TYPE_COMMON,
  1525. .major = 1,
  1526. .minor = 0,
  1527. .rev = 0,
  1528. .funcs = &cik_common_ip_funcs,
  1529. },
  1530. {
  1531. .type = AMD_IP_BLOCK_TYPE_GMC,
  1532. .major = 7,
  1533. .minor = 0,
  1534. .rev = 0,
  1535. .funcs = &gmc_v7_0_ip_funcs,
  1536. },
  1537. {
  1538. .type = AMD_IP_BLOCK_TYPE_IH,
  1539. .major = 2,
  1540. .minor = 0,
  1541. .rev = 0,
  1542. .funcs = &cik_ih_ip_funcs,
  1543. },
  1544. {
  1545. .type = AMD_IP_BLOCK_TYPE_SMC,
  1546. .major = 7,
  1547. .minor = 0,
  1548. .rev = 0,
  1549. .funcs = &amdgpu_pp_ip_funcs,
  1550. },
  1551. {
  1552. .type = AMD_IP_BLOCK_TYPE_DCE,
  1553. .major = 8,
  1554. .minor = 5,
  1555. .rev = 0,
  1556. .funcs = &dce_v8_0_ip_funcs,
  1557. },
  1558. {
  1559. .type = AMD_IP_BLOCK_TYPE_GFX,
  1560. .major = 7,
  1561. .minor = 3,
  1562. .rev = 0,
  1563. .funcs = &gfx_v7_0_ip_funcs,
  1564. },
  1565. {
  1566. .type = AMD_IP_BLOCK_TYPE_SDMA,
  1567. .major = 2,
  1568. .minor = 0,
  1569. .rev = 0,
  1570. .funcs = &cik_sdma_ip_funcs,
  1571. },
  1572. {
  1573. .type = AMD_IP_BLOCK_TYPE_UVD,
  1574. .major = 4,
  1575. .minor = 2,
  1576. .rev = 0,
  1577. .funcs = &uvd_v4_2_ip_funcs,
  1578. },
  1579. {
  1580. .type = AMD_IP_BLOCK_TYPE_VCE,
  1581. .major = 2,
  1582. .minor = 0,
  1583. .rev = 0,
  1584. .funcs = &vce_v2_0_ip_funcs,
  1585. },
  1586. };
  1587. static const struct amdgpu_ip_block_version kabini_ip_blocks[] =
  1588. {
  1589. /* ORDER MATTERS! */
  1590. {
  1591. .type = AMD_IP_BLOCK_TYPE_COMMON,
  1592. .major = 1,
  1593. .minor = 0,
  1594. .rev = 0,
  1595. .funcs = &cik_common_ip_funcs,
  1596. },
  1597. {
  1598. .type = AMD_IP_BLOCK_TYPE_GMC,
  1599. .major = 7,
  1600. .minor = 0,
  1601. .rev = 0,
  1602. .funcs = &gmc_v7_0_ip_funcs,
  1603. },
  1604. {
  1605. .type = AMD_IP_BLOCK_TYPE_IH,
  1606. .major = 2,
  1607. .minor = 0,
  1608. .rev = 0,
  1609. .funcs = &cik_ih_ip_funcs,
  1610. },
  1611. {
  1612. .type = AMD_IP_BLOCK_TYPE_SMC,
  1613. .major = 7,
  1614. .minor = 0,
  1615. .rev = 0,
  1616. .funcs = &amdgpu_pp_ip_funcs,
  1617. },
  1618. {
  1619. .type = AMD_IP_BLOCK_TYPE_DCE,
  1620. .major = 8,
  1621. .minor = 3,
  1622. .rev = 0,
  1623. .funcs = &dce_v8_0_ip_funcs,
  1624. },
  1625. {
  1626. .type = AMD_IP_BLOCK_TYPE_GFX,
  1627. .major = 7,
  1628. .minor = 2,
  1629. .rev = 0,
  1630. .funcs = &gfx_v7_0_ip_funcs,
  1631. },
  1632. {
  1633. .type = AMD_IP_BLOCK_TYPE_SDMA,
  1634. .major = 2,
  1635. .minor = 0,
  1636. .rev = 0,
  1637. .funcs = &cik_sdma_ip_funcs,
  1638. },
  1639. {
  1640. .type = AMD_IP_BLOCK_TYPE_UVD,
  1641. .major = 4,
  1642. .minor = 2,
  1643. .rev = 0,
  1644. .funcs = &uvd_v4_2_ip_funcs,
  1645. },
  1646. {
  1647. .type = AMD_IP_BLOCK_TYPE_VCE,
  1648. .major = 2,
  1649. .minor = 0,
  1650. .rev = 0,
  1651. .funcs = &vce_v2_0_ip_funcs,
  1652. },
  1653. };
  1654. static const struct amdgpu_ip_block_version mullins_ip_blocks[] =
  1655. {
  1656. /* ORDER MATTERS! */
  1657. {
  1658. .type = AMD_IP_BLOCK_TYPE_COMMON,
  1659. .major = 1,
  1660. .minor = 0,
  1661. .rev = 0,
  1662. .funcs = &cik_common_ip_funcs,
  1663. },
  1664. {
  1665. .type = AMD_IP_BLOCK_TYPE_GMC,
  1666. .major = 7,
  1667. .minor = 0,
  1668. .rev = 0,
  1669. .funcs = &gmc_v7_0_ip_funcs,
  1670. },
  1671. {
  1672. .type = AMD_IP_BLOCK_TYPE_IH,
  1673. .major = 2,
  1674. .minor = 0,
  1675. .rev = 0,
  1676. .funcs = &cik_ih_ip_funcs,
  1677. },
  1678. {
  1679. .type = AMD_IP_BLOCK_TYPE_SMC,
  1680. .major = 7,
  1681. .minor = 0,
  1682. .rev = 0,
  1683. .funcs = &amdgpu_pp_ip_funcs,
  1684. },
  1685. {
  1686. .type = AMD_IP_BLOCK_TYPE_DCE,
  1687. .major = 8,
  1688. .minor = 3,
  1689. .rev = 0,
  1690. .funcs = &dce_v8_0_ip_funcs,
  1691. },
  1692. {
  1693. .type = AMD_IP_BLOCK_TYPE_GFX,
  1694. .major = 7,
  1695. .minor = 2,
  1696. .rev = 0,
  1697. .funcs = &gfx_v7_0_ip_funcs,
  1698. },
  1699. {
  1700. .type = AMD_IP_BLOCK_TYPE_SDMA,
  1701. .major = 2,
  1702. .minor = 0,
  1703. .rev = 0,
  1704. .funcs = &cik_sdma_ip_funcs,
  1705. },
  1706. {
  1707. .type = AMD_IP_BLOCK_TYPE_UVD,
  1708. .major = 4,
  1709. .minor = 2,
  1710. .rev = 0,
  1711. .funcs = &uvd_v4_2_ip_funcs,
  1712. },
  1713. {
  1714. .type = AMD_IP_BLOCK_TYPE_VCE,
  1715. .major = 2,
  1716. .minor = 0,
  1717. .rev = 0,
  1718. .funcs = &vce_v2_0_ip_funcs,
  1719. },
  1720. };
  1721. static const struct amdgpu_ip_block_version kaveri_ip_blocks[] =
  1722. {
  1723. /* ORDER MATTERS! */
  1724. {
  1725. .type = AMD_IP_BLOCK_TYPE_COMMON,
  1726. .major = 1,
  1727. .minor = 0,
  1728. .rev = 0,
  1729. .funcs = &cik_common_ip_funcs,
  1730. },
  1731. {
  1732. .type = AMD_IP_BLOCK_TYPE_GMC,
  1733. .major = 7,
  1734. .minor = 0,
  1735. .rev = 0,
  1736. .funcs = &gmc_v7_0_ip_funcs,
  1737. },
  1738. {
  1739. .type = AMD_IP_BLOCK_TYPE_IH,
  1740. .major = 2,
  1741. .minor = 0,
  1742. .rev = 0,
  1743. .funcs = &cik_ih_ip_funcs,
  1744. },
  1745. {
  1746. .type = AMD_IP_BLOCK_TYPE_SMC,
  1747. .major = 7,
  1748. .minor = 0,
  1749. .rev = 0,
  1750. .funcs = &amdgpu_pp_ip_funcs,
  1751. },
  1752. {
  1753. .type = AMD_IP_BLOCK_TYPE_DCE,
  1754. .major = 8,
  1755. .minor = 1,
  1756. .rev = 0,
  1757. .funcs = &dce_v8_0_ip_funcs,
  1758. },
  1759. {
  1760. .type = AMD_IP_BLOCK_TYPE_GFX,
  1761. .major = 7,
  1762. .minor = 1,
  1763. .rev = 0,
  1764. .funcs = &gfx_v7_0_ip_funcs,
  1765. },
  1766. {
  1767. .type = AMD_IP_BLOCK_TYPE_SDMA,
  1768. .major = 2,
  1769. .minor = 0,
  1770. .rev = 0,
  1771. .funcs = &cik_sdma_ip_funcs,
  1772. },
  1773. {
  1774. .type = AMD_IP_BLOCK_TYPE_UVD,
  1775. .major = 4,
  1776. .minor = 2,
  1777. .rev = 0,
  1778. .funcs = &uvd_v4_2_ip_funcs,
  1779. },
  1780. {
  1781. .type = AMD_IP_BLOCK_TYPE_VCE,
  1782. .major = 2,
  1783. .minor = 0,
  1784. .rev = 0,
  1785. .funcs = &vce_v2_0_ip_funcs,
  1786. },
  1787. };
  1788. int cik_set_ip_blocks(struct amdgpu_device *adev)
  1789. {
  1790. switch (adev->asic_type) {
  1791. case CHIP_BONAIRE:
  1792. adev->ip_blocks = bonaire_ip_blocks;
  1793. adev->num_ip_blocks = ARRAY_SIZE(bonaire_ip_blocks);
  1794. break;
  1795. case CHIP_HAWAII:
  1796. adev->ip_blocks = hawaii_ip_blocks;
  1797. adev->num_ip_blocks = ARRAY_SIZE(hawaii_ip_blocks);
  1798. break;
  1799. case CHIP_KAVERI:
  1800. adev->ip_blocks = kaveri_ip_blocks;
  1801. adev->num_ip_blocks = ARRAY_SIZE(kaveri_ip_blocks);
  1802. break;
  1803. case CHIP_KABINI:
  1804. adev->ip_blocks = kabini_ip_blocks;
  1805. adev->num_ip_blocks = ARRAY_SIZE(kabini_ip_blocks);
  1806. break;
  1807. case CHIP_MULLINS:
  1808. adev->ip_blocks = mullins_ip_blocks;
  1809. adev->num_ip_blocks = ARRAY_SIZE(mullins_ip_blocks);
  1810. break;
  1811. default:
  1812. /* FIXME: not supported yet */
  1813. return -EINVAL;
  1814. }
  1815. return 0;
  1816. }
  1817. static const struct amdgpu_asic_funcs cik_asic_funcs =
  1818. {
  1819. .read_disabled_bios = &cik_read_disabled_bios,
  1820. .read_bios_from_rom = &cik_read_bios_from_rom,
  1821. .read_register = &cik_read_register,
  1822. .reset = &cik_asic_reset,
  1823. .set_vga_state = &cik_vga_set_state,
  1824. .get_xclk = &cik_get_xclk,
  1825. .set_uvd_clocks = &cik_set_uvd_clocks,
  1826. .set_vce_clocks = &cik_set_vce_clocks,
  1827. .get_cu_info = &gfx_v7_0_get_cu_info,
  1828. /* these should be moved to their own ip modules */
  1829. .get_gpu_clock_counter = &gfx_v7_0_get_gpu_clock_counter,
  1830. .wait_for_mc_idle = &gmc_v7_0_mc_wait_for_idle,
  1831. };
  1832. static int cik_common_early_init(void *handle)
  1833. {
  1834. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  1835. adev->smc_rreg = &cik_smc_rreg;
  1836. adev->smc_wreg = &cik_smc_wreg;
  1837. adev->pcie_rreg = &cik_pcie_rreg;
  1838. adev->pcie_wreg = &cik_pcie_wreg;
  1839. adev->uvd_ctx_rreg = &cik_uvd_ctx_rreg;
  1840. adev->uvd_ctx_wreg = &cik_uvd_ctx_wreg;
  1841. adev->didt_rreg = &cik_didt_rreg;
  1842. adev->didt_wreg = &cik_didt_wreg;
  1843. adev->asic_funcs = &cik_asic_funcs;
  1844. adev->rev_id = cik_get_rev_id(adev);
  1845. adev->external_rev_id = 0xFF;
  1846. switch (adev->asic_type) {
  1847. case CHIP_BONAIRE:
  1848. adev->cg_flags =
  1849. AMD_CG_SUPPORT_GFX_MGCG |
  1850. AMD_CG_SUPPORT_GFX_MGLS |
  1851. /*AMD_CG_SUPPORT_GFX_CGCG |*/
  1852. AMD_CG_SUPPORT_GFX_CGLS |
  1853. AMD_CG_SUPPORT_GFX_CGTS |
  1854. AMD_CG_SUPPORT_GFX_CGTS_LS |
  1855. AMD_CG_SUPPORT_GFX_CP_LS |
  1856. AMD_CG_SUPPORT_MC_LS |
  1857. AMD_CG_SUPPORT_MC_MGCG |
  1858. AMD_CG_SUPPORT_SDMA_MGCG |
  1859. AMD_CG_SUPPORT_SDMA_LS |
  1860. AMD_CG_SUPPORT_BIF_LS |
  1861. AMD_CG_SUPPORT_VCE_MGCG |
  1862. AMD_CG_SUPPORT_UVD_MGCG |
  1863. AMD_CG_SUPPORT_HDP_LS |
  1864. AMD_CG_SUPPORT_HDP_MGCG;
  1865. adev->pg_flags = 0;
  1866. adev->external_rev_id = adev->rev_id + 0x14;
  1867. break;
  1868. case CHIP_HAWAII:
  1869. adev->cg_flags =
  1870. AMD_CG_SUPPORT_GFX_MGCG |
  1871. AMD_CG_SUPPORT_GFX_MGLS |
  1872. /*AMD_CG_SUPPORT_GFX_CGCG |*/
  1873. AMD_CG_SUPPORT_GFX_CGLS |
  1874. AMD_CG_SUPPORT_GFX_CGTS |
  1875. AMD_CG_SUPPORT_GFX_CP_LS |
  1876. AMD_CG_SUPPORT_MC_LS |
  1877. AMD_CG_SUPPORT_MC_MGCG |
  1878. AMD_CG_SUPPORT_SDMA_MGCG |
  1879. AMD_CG_SUPPORT_SDMA_LS |
  1880. AMD_CG_SUPPORT_BIF_LS |
  1881. AMD_CG_SUPPORT_VCE_MGCG |
  1882. AMD_CG_SUPPORT_UVD_MGCG |
  1883. AMD_CG_SUPPORT_HDP_LS |
  1884. AMD_CG_SUPPORT_HDP_MGCG;
  1885. adev->pg_flags = 0;
  1886. adev->external_rev_id = 0x28;
  1887. break;
  1888. case CHIP_KAVERI:
  1889. adev->cg_flags =
  1890. AMD_CG_SUPPORT_GFX_MGCG |
  1891. AMD_CG_SUPPORT_GFX_MGLS |
  1892. /*AMD_CG_SUPPORT_GFX_CGCG |*/
  1893. AMD_CG_SUPPORT_GFX_CGLS |
  1894. AMD_CG_SUPPORT_GFX_CGTS |
  1895. AMD_CG_SUPPORT_GFX_CGTS_LS |
  1896. AMD_CG_SUPPORT_GFX_CP_LS |
  1897. AMD_CG_SUPPORT_SDMA_MGCG |
  1898. AMD_CG_SUPPORT_SDMA_LS |
  1899. AMD_CG_SUPPORT_BIF_LS |
  1900. AMD_CG_SUPPORT_VCE_MGCG |
  1901. AMD_CG_SUPPORT_UVD_MGCG |
  1902. AMD_CG_SUPPORT_HDP_LS |
  1903. AMD_CG_SUPPORT_HDP_MGCG;
  1904. adev->pg_flags =
  1905. /*AMD_PG_SUPPORT_GFX_PG |
  1906. AMD_PG_SUPPORT_GFX_SMG |
  1907. AMD_PG_SUPPORT_GFX_DMG |*/
  1908. AMD_PG_SUPPORT_UVD |
  1909. /*AMD_PG_SUPPORT_VCE |
  1910. AMD_PG_SUPPORT_CP |
  1911. AMD_PG_SUPPORT_GDS |
  1912. AMD_PG_SUPPORT_RLC_SMU_HS |
  1913. AMD_PG_SUPPORT_ACP |
  1914. AMD_PG_SUPPORT_SAMU |*/
  1915. 0;
  1916. if (adev->pdev->device == 0x1312 ||
  1917. adev->pdev->device == 0x1316 ||
  1918. adev->pdev->device == 0x1317)
  1919. adev->external_rev_id = 0x41;
  1920. else
  1921. adev->external_rev_id = 0x1;
  1922. break;
  1923. case CHIP_KABINI:
  1924. case CHIP_MULLINS:
  1925. adev->cg_flags =
  1926. AMD_CG_SUPPORT_GFX_MGCG |
  1927. AMD_CG_SUPPORT_GFX_MGLS |
  1928. /*AMD_CG_SUPPORT_GFX_CGCG |*/
  1929. AMD_CG_SUPPORT_GFX_CGLS |
  1930. AMD_CG_SUPPORT_GFX_CGTS |
  1931. AMD_CG_SUPPORT_GFX_CGTS_LS |
  1932. AMD_CG_SUPPORT_GFX_CP_LS |
  1933. AMD_CG_SUPPORT_SDMA_MGCG |
  1934. AMD_CG_SUPPORT_SDMA_LS |
  1935. AMD_CG_SUPPORT_BIF_LS |
  1936. AMD_CG_SUPPORT_VCE_MGCG |
  1937. AMD_CG_SUPPORT_UVD_MGCG |
  1938. AMD_CG_SUPPORT_HDP_LS |
  1939. AMD_CG_SUPPORT_HDP_MGCG;
  1940. adev->pg_flags =
  1941. /*AMD_PG_SUPPORT_GFX_PG |
  1942. AMD_PG_SUPPORT_GFX_SMG | */
  1943. AMD_PG_SUPPORT_UVD |
  1944. /*AMD_PG_SUPPORT_VCE |
  1945. AMD_PG_SUPPORT_CP |
  1946. AMD_PG_SUPPORT_GDS |
  1947. AMD_PG_SUPPORT_RLC_SMU_HS |
  1948. AMD_PG_SUPPORT_SAMU |*/
  1949. 0;
  1950. if (adev->asic_type == CHIP_KABINI) {
  1951. if (adev->rev_id == 0)
  1952. adev->external_rev_id = 0x81;
  1953. else if (adev->rev_id == 1)
  1954. adev->external_rev_id = 0x82;
  1955. else if (adev->rev_id == 2)
  1956. adev->external_rev_id = 0x85;
  1957. } else
  1958. adev->external_rev_id = adev->rev_id + 0xa1;
  1959. break;
  1960. default:
  1961. /* FIXME: not supported yet */
  1962. return -EINVAL;
  1963. }
  1964. amdgpu_get_pcie_info(adev);
  1965. return 0;
  1966. }
  1967. static int cik_common_sw_init(void *handle)
  1968. {
  1969. return 0;
  1970. }
  1971. static int cik_common_sw_fini(void *handle)
  1972. {
  1973. return 0;
  1974. }
  1975. static int cik_common_hw_init(void *handle)
  1976. {
  1977. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  1978. /* move the golden regs per IP block */
  1979. cik_init_golden_registers(adev);
  1980. /* enable pcie gen2/3 link */
  1981. cik_pcie_gen3_enable(adev);
  1982. /* enable aspm */
  1983. cik_program_aspm(adev);
  1984. return 0;
  1985. }
  1986. static int cik_common_hw_fini(void *handle)
  1987. {
  1988. return 0;
  1989. }
  1990. static int cik_common_suspend(void *handle)
  1991. {
  1992. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  1993. amdgpu_amdkfd_suspend(adev);
  1994. return cik_common_hw_fini(adev);
  1995. }
  1996. static int cik_common_resume(void *handle)
  1997. {
  1998. int r;
  1999. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  2000. r = cik_common_hw_init(adev);
  2001. if (r)
  2002. return r;
  2003. return amdgpu_amdkfd_resume(adev);
  2004. }
  2005. static bool cik_common_is_idle(void *handle)
  2006. {
  2007. return true;
  2008. }
  2009. static int cik_common_wait_for_idle(void *handle)
  2010. {
  2011. return 0;
  2012. }
  2013. static int cik_common_soft_reset(void *handle)
  2014. {
  2015. /* XXX hard reset?? */
  2016. return 0;
  2017. }
  2018. static int cik_common_set_clockgating_state(void *handle,
  2019. enum amd_clockgating_state state)
  2020. {
  2021. return 0;
  2022. }
  2023. static int cik_common_set_powergating_state(void *handle,
  2024. enum amd_powergating_state state)
  2025. {
  2026. return 0;
  2027. }
  2028. const struct amd_ip_funcs cik_common_ip_funcs = {
  2029. .early_init = cik_common_early_init,
  2030. .late_init = NULL,
  2031. .sw_init = cik_common_sw_init,
  2032. .sw_fini = cik_common_sw_fini,
  2033. .hw_init = cik_common_hw_init,
  2034. .hw_fini = cik_common_hw_fini,
  2035. .suspend = cik_common_suspend,
  2036. .resume = cik_common_resume,
  2037. .is_idle = cik_common_is_idle,
  2038. .wait_for_idle = cik_common_wait_for_idle,
  2039. .soft_reset = cik_common_soft_reset,
  2040. .set_clockgating_state = cik_common_set_clockgating_state,
  2041. .set_powergating_state = cik_common_set_powergating_state,
  2042. };