cik.c 56 KB

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