vi.c 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856
  1. /*
  2. * Copyright 2014 Advanced Micro Devices, Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. */
  23. #include <linux/firmware.h>
  24. #include <linux/slab.h>
  25. #include <linux/module.h>
  26. #include "drmP.h"
  27. #include "amdgpu.h"
  28. #include "amdgpu_atombios.h"
  29. #include "amdgpu_ih.h"
  30. #include "amdgpu_uvd.h"
  31. #include "amdgpu_vce.h"
  32. #include "amdgpu_ucode.h"
  33. #include "atom.h"
  34. #include "amd_pcie.h"
  35. #include "gmc/gmc_8_1_d.h"
  36. #include "gmc/gmc_8_1_sh_mask.h"
  37. #include "oss/oss_3_0_d.h"
  38. #include "oss/oss_3_0_sh_mask.h"
  39. #include "bif/bif_5_0_d.h"
  40. #include "bif/bif_5_0_sh_mask.h"
  41. #include "gca/gfx_8_0_d.h"
  42. #include "gca/gfx_8_0_sh_mask.h"
  43. #include "smu/smu_7_1_1_d.h"
  44. #include "smu/smu_7_1_1_sh_mask.h"
  45. #include "uvd/uvd_5_0_d.h"
  46. #include "uvd/uvd_5_0_sh_mask.h"
  47. #include "vce/vce_3_0_d.h"
  48. #include "vce/vce_3_0_sh_mask.h"
  49. #include "dce/dce_10_0_d.h"
  50. #include "dce/dce_10_0_sh_mask.h"
  51. #include "vid.h"
  52. #include "vi.h"
  53. #include "vi_dpm.h"
  54. #include "gmc_v8_0.h"
  55. #include "gmc_v7_0.h"
  56. #include "gfx_v8_0.h"
  57. #include "sdma_v2_4.h"
  58. #include "sdma_v3_0.h"
  59. #include "dce_v10_0.h"
  60. #include "dce_v11_0.h"
  61. #include "iceland_ih.h"
  62. #include "tonga_ih.h"
  63. #include "cz_ih.h"
  64. #include "uvd_v5_0.h"
  65. #include "uvd_v6_0.h"
  66. #include "vce_v3_0.h"
  67. #include "amdgpu_powerplay.h"
  68. #if defined(CONFIG_DRM_AMD_ACP)
  69. #include "amdgpu_acp.h"
  70. #endif
  71. #include "dce_virtual.h"
  72. MODULE_FIRMWARE("amdgpu/polaris10_smc.bin");
  73. MODULE_FIRMWARE("amdgpu/polaris10_smc_sk.bin");
  74. MODULE_FIRMWARE("amdgpu/polaris11_smc.bin");
  75. MODULE_FIRMWARE("amdgpu/polaris11_smc_sk.bin");
  76. /*
  77. * Indirect registers accessor
  78. */
  79. static u32 vi_pcie_rreg(struct amdgpu_device *adev, u32 reg)
  80. {
  81. unsigned long flags;
  82. u32 r;
  83. spin_lock_irqsave(&adev->pcie_idx_lock, flags);
  84. WREG32(mmPCIE_INDEX, reg);
  85. (void)RREG32(mmPCIE_INDEX);
  86. r = RREG32(mmPCIE_DATA);
  87. spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
  88. return r;
  89. }
  90. static void vi_pcie_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
  91. {
  92. unsigned long flags;
  93. spin_lock_irqsave(&adev->pcie_idx_lock, flags);
  94. WREG32(mmPCIE_INDEX, reg);
  95. (void)RREG32(mmPCIE_INDEX);
  96. WREG32(mmPCIE_DATA, v);
  97. (void)RREG32(mmPCIE_DATA);
  98. spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
  99. }
  100. static u32 vi_smc_rreg(struct amdgpu_device *adev, u32 reg)
  101. {
  102. unsigned long flags;
  103. u32 r;
  104. spin_lock_irqsave(&adev->smc_idx_lock, flags);
  105. WREG32(mmSMC_IND_INDEX_0, (reg));
  106. r = RREG32(mmSMC_IND_DATA_0);
  107. spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
  108. return r;
  109. }
  110. static void vi_smc_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
  111. {
  112. unsigned long flags;
  113. spin_lock_irqsave(&adev->smc_idx_lock, flags);
  114. WREG32(mmSMC_IND_INDEX_0, (reg));
  115. WREG32(mmSMC_IND_DATA_0, (v));
  116. spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
  117. }
  118. /* smu_8_0_d.h */
  119. #define mmMP0PUB_IND_INDEX 0x180
  120. #define mmMP0PUB_IND_DATA 0x181
  121. static u32 cz_smc_rreg(struct amdgpu_device *adev, u32 reg)
  122. {
  123. unsigned long flags;
  124. u32 r;
  125. spin_lock_irqsave(&adev->smc_idx_lock, flags);
  126. WREG32(mmMP0PUB_IND_INDEX, (reg));
  127. r = RREG32(mmMP0PUB_IND_DATA);
  128. spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
  129. return r;
  130. }
  131. static void cz_smc_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
  132. {
  133. unsigned long flags;
  134. spin_lock_irqsave(&adev->smc_idx_lock, flags);
  135. WREG32(mmMP0PUB_IND_INDEX, (reg));
  136. WREG32(mmMP0PUB_IND_DATA, (v));
  137. spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
  138. }
  139. static u32 vi_uvd_ctx_rreg(struct amdgpu_device *adev, u32 reg)
  140. {
  141. unsigned long flags;
  142. u32 r;
  143. spin_lock_irqsave(&adev->uvd_ctx_idx_lock, flags);
  144. WREG32(mmUVD_CTX_INDEX, ((reg) & 0x1ff));
  145. r = RREG32(mmUVD_CTX_DATA);
  146. spin_unlock_irqrestore(&adev->uvd_ctx_idx_lock, flags);
  147. return r;
  148. }
  149. static void vi_uvd_ctx_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
  150. {
  151. unsigned long flags;
  152. spin_lock_irqsave(&adev->uvd_ctx_idx_lock, flags);
  153. WREG32(mmUVD_CTX_INDEX, ((reg) & 0x1ff));
  154. WREG32(mmUVD_CTX_DATA, (v));
  155. spin_unlock_irqrestore(&adev->uvd_ctx_idx_lock, flags);
  156. }
  157. static u32 vi_didt_rreg(struct amdgpu_device *adev, u32 reg)
  158. {
  159. unsigned long flags;
  160. u32 r;
  161. spin_lock_irqsave(&adev->didt_idx_lock, flags);
  162. WREG32(mmDIDT_IND_INDEX, (reg));
  163. r = RREG32(mmDIDT_IND_DATA);
  164. spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
  165. return r;
  166. }
  167. static void vi_didt_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
  168. {
  169. unsigned long flags;
  170. spin_lock_irqsave(&adev->didt_idx_lock, flags);
  171. WREG32(mmDIDT_IND_INDEX, (reg));
  172. WREG32(mmDIDT_IND_DATA, (v));
  173. spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
  174. }
  175. static u32 vi_gc_cac_rreg(struct amdgpu_device *adev, u32 reg)
  176. {
  177. unsigned long flags;
  178. u32 r;
  179. spin_lock_irqsave(&adev->gc_cac_idx_lock, flags);
  180. WREG32(mmGC_CAC_IND_INDEX, (reg));
  181. r = RREG32(mmGC_CAC_IND_DATA);
  182. spin_unlock_irqrestore(&adev->gc_cac_idx_lock, flags);
  183. return r;
  184. }
  185. static void vi_gc_cac_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
  186. {
  187. unsigned long flags;
  188. spin_lock_irqsave(&adev->gc_cac_idx_lock, flags);
  189. WREG32(mmGC_CAC_IND_INDEX, (reg));
  190. WREG32(mmGC_CAC_IND_DATA, (v));
  191. spin_unlock_irqrestore(&adev->gc_cac_idx_lock, flags);
  192. }
  193. static const u32 tonga_mgcg_cgcg_init[] =
  194. {
  195. mmCGTT_DRM_CLK_CTRL0, 0xffffffff, 0x00600100,
  196. mmPCIE_INDEX, 0xffffffff, 0x0140001c,
  197. mmPCIE_DATA, 0x000f0000, 0x00000000,
  198. mmSMC_IND_INDEX_4, 0xffffffff, 0xC060000C,
  199. mmSMC_IND_DATA_4, 0xc0000fff, 0x00000100,
  200. mmCGTT_DRM_CLK_CTRL0, 0xff000fff, 0x00000100,
  201. mmHDP_XDP_CGTT_BLK_CTRL, 0xc0000fff, 0x00000104,
  202. };
  203. static const u32 fiji_mgcg_cgcg_init[] =
  204. {
  205. mmCGTT_DRM_CLK_CTRL0, 0xffffffff, 0x00600100,
  206. mmPCIE_INDEX, 0xffffffff, 0x0140001c,
  207. mmPCIE_DATA, 0x000f0000, 0x00000000,
  208. mmSMC_IND_INDEX_4, 0xffffffff, 0xC060000C,
  209. mmSMC_IND_DATA_4, 0xc0000fff, 0x00000100,
  210. mmCGTT_DRM_CLK_CTRL0, 0xff000fff, 0x00000100,
  211. mmHDP_XDP_CGTT_BLK_CTRL, 0xc0000fff, 0x00000104,
  212. };
  213. static const u32 iceland_mgcg_cgcg_init[] =
  214. {
  215. mmPCIE_INDEX, 0xffffffff, ixPCIE_CNTL2,
  216. mmPCIE_DATA, 0x000f0000, 0x00000000,
  217. mmSMC_IND_INDEX_4, 0xffffffff, ixCGTT_ROM_CLK_CTRL0,
  218. mmSMC_IND_DATA_4, 0xc0000fff, 0x00000100,
  219. mmHDP_XDP_CGTT_BLK_CTRL, 0xc0000fff, 0x00000104,
  220. };
  221. static const u32 cz_mgcg_cgcg_init[] =
  222. {
  223. mmCGTT_DRM_CLK_CTRL0, 0xffffffff, 0x00600100,
  224. mmPCIE_INDEX, 0xffffffff, 0x0140001c,
  225. mmPCIE_DATA, 0x000f0000, 0x00000000,
  226. mmCGTT_DRM_CLK_CTRL0, 0xff000fff, 0x00000100,
  227. mmHDP_XDP_CGTT_BLK_CTRL, 0xc0000fff, 0x00000104,
  228. };
  229. static const u32 stoney_mgcg_cgcg_init[] =
  230. {
  231. mmCGTT_DRM_CLK_CTRL0, 0xffffffff, 0x00000100,
  232. mmHDP_XDP_CGTT_BLK_CTRL, 0xffffffff, 0x00000104,
  233. mmHDP_HOST_PATH_CNTL, 0xffffffff, 0x0f000027,
  234. };
  235. static void vi_init_golden_registers(struct amdgpu_device *adev)
  236. {
  237. /* Some of the registers might be dependent on GRBM_GFX_INDEX */
  238. mutex_lock(&adev->grbm_idx_mutex);
  239. switch (adev->asic_type) {
  240. case CHIP_TOPAZ:
  241. amdgpu_program_register_sequence(adev,
  242. iceland_mgcg_cgcg_init,
  243. (const u32)ARRAY_SIZE(iceland_mgcg_cgcg_init));
  244. break;
  245. case CHIP_FIJI:
  246. amdgpu_program_register_sequence(adev,
  247. fiji_mgcg_cgcg_init,
  248. (const u32)ARRAY_SIZE(fiji_mgcg_cgcg_init));
  249. break;
  250. case CHIP_TONGA:
  251. amdgpu_program_register_sequence(adev,
  252. tonga_mgcg_cgcg_init,
  253. (const u32)ARRAY_SIZE(tonga_mgcg_cgcg_init));
  254. break;
  255. case CHIP_CARRIZO:
  256. amdgpu_program_register_sequence(adev,
  257. cz_mgcg_cgcg_init,
  258. (const u32)ARRAY_SIZE(cz_mgcg_cgcg_init));
  259. break;
  260. case CHIP_STONEY:
  261. amdgpu_program_register_sequence(adev,
  262. stoney_mgcg_cgcg_init,
  263. (const u32)ARRAY_SIZE(stoney_mgcg_cgcg_init));
  264. break;
  265. case CHIP_POLARIS11:
  266. case CHIP_POLARIS10:
  267. default:
  268. break;
  269. }
  270. mutex_unlock(&adev->grbm_idx_mutex);
  271. }
  272. /**
  273. * vi_get_xclk - get the xclk
  274. *
  275. * @adev: amdgpu_device pointer
  276. *
  277. * Returns the reference clock used by the gfx engine
  278. * (VI).
  279. */
  280. static u32 vi_get_xclk(struct amdgpu_device *adev)
  281. {
  282. u32 reference_clock = adev->clock.spll.reference_freq;
  283. u32 tmp;
  284. if (adev->flags & AMD_IS_APU)
  285. return reference_clock;
  286. tmp = RREG32_SMC(ixCG_CLKPIN_CNTL_2);
  287. if (REG_GET_FIELD(tmp, CG_CLKPIN_CNTL_2, MUX_TCLK_TO_XCLK))
  288. return 1000;
  289. tmp = RREG32_SMC(ixCG_CLKPIN_CNTL);
  290. if (REG_GET_FIELD(tmp, CG_CLKPIN_CNTL, XTALIN_DIVIDE))
  291. return reference_clock / 4;
  292. return reference_clock;
  293. }
  294. /**
  295. * vi_srbm_select - select specific register instances
  296. *
  297. * @adev: amdgpu_device pointer
  298. * @me: selected ME (micro engine)
  299. * @pipe: pipe
  300. * @queue: queue
  301. * @vmid: VMID
  302. *
  303. * Switches the currently active registers instances. Some
  304. * registers are instanced per VMID, others are instanced per
  305. * me/pipe/queue combination.
  306. */
  307. void vi_srbm_select(struct amdgpu_device *adev,
  308. u32 me, u32 pipe, u32 queue, u32 vmid)
  309. {
  310. u32 srbm_gfx_cntl = 0;
  311. srbm_gfx_cntl = REG_SET_FIELD(srbm_gfx_cntl, SRBM_GFX_CNTL, PIPEID, pipe);
  312. srbm_gfx_cntl = REG_SET_FIELD(srbm_gfx_cntl, SRBM_GFX_CNTL, MEID, me);
  313. srbm_gfx_cntl = REG_SET_FIELD(srbm_gfx_cntl, SRBM_GFX_CNTL, VMID, vmid);
  314. srbm_gfx_cntl = REG_SET_FIELD(srbm_gfx_cntl, SRBM_GFX_CNTL, QUEUEID, queue);
  315. WREG32(mmSRBM_GFX_CNTL, srbm_gfx_cntl);
  316. }
  317. static void vi_vga_set_state(struct amdgpu_device *adev, bool state)
  318. {
  319. /* todo */
  320. }
  321. static bool vi_read_disabled_bios(struct amdgpu_device *adev)
  322. {
  323. u32 bus_cntl;
  324. u32 d1vga_control = 0;
  325. u32 d2vga_control = 0;
  326. u32 vga_render_control = 0;
  327. u32 rom_cntl;
  328. bool r;
  329. bus_cntl = RREG32(mmBUS_CNTL);
  330. if (adev->mode_info.num_crtc) {
  331. d1vga_control = RREG32(mmD1VGA_CONTROL);
  332. d2vga_control = RREG32(mmD2VGA_CONTROL);
  333. vga_render_control = RREG32(mmVGA_RENDER_CONTROL);
  334. }
  335. rom_cntl = RREG32_SMC(ixROM_CNTL);
  336. /* enable the rom */
  337. WREG32(mmBUS_CNTL, (bus_cntl & ~BUS_CNTL__BIOS_ROM_DIS_MASK));
  338. if (adev->mode_info.num_crtc) {
  339. /* Disable VGA mode */
  340. WREG32(mmD1VGA_CONTROL,
  341. (d1vga_control & ~(D1VGA_CONTROL__D1VGA_MODE_ENABLE_MASK |
  342. D1VGA_CONTROL__D1VGA_TIMING_SELECT_MASK)));
  343. WREG32(mmD2VGA_CONTROL,
  344. (d2vga_control & ~(D2VGA_CONTROL__D2VGA_MODE_ENABLE_MASK |
  345. D2VGA_CONTROL__D2VGA_TIMING_SELECT_MASK)));
  346. WREG32(mmVGA_RENDER_CONTROL,
  347. (vga_render_control & ~VGA_RENDER_CONTROL__VGA_VSTATUS_CNTL_MASK));
  348. }
  349. WREG32_SMC(ixROM_CNTL, rom_cntl | ROM_CNTL__SCK_OVERWRITE_MASK);
  350. r = amdgpu_read_bios(adev);
  351. /* restore regs */
  352. WREG32(mmBUS_CNTL, bus_cntl);
  353. if (adev->mode_info.num_crtc) {
  354. WREG32(mmD1VGA_CONTROL, d1vga_control);
  355. WREG32(mmD2VGA_CONTROL, d2vga_control);
  356. WREG32(mmVGA_RENDER_CONTROL, vga_render_control);
  357. }
  358. WREG32_SMC(ixROM_CNTL, rom_cntl);
  359. return r;
  360. }
  361. static bool vi_read_bios_from_rom(struct amdgpu_device *adev,
  362. u8 *bios, u32 length_bytes)
  363. {
  364. u32 *dw_ptr;
  365. unsigned long flags;
  366. u32 i, length_dw;
  367. if (bios == NULL)
  368. return false;
  369. if (length_bytes == 0)
  370. return false;
  371. /* APU vbios image is part of sbios image */
  372. if (adev->flags & AMD_IS_APU)
  373. return false;
  374. dw_ptr = (u32 *)bios;
  375. length_dw = ALIGN(length_bytes, 4) / 4;
  376. /* take the smc lock since we are using the smc index */
  377. spin_lock_irqsave(&adev->smc_idx_lock, flags);
  378. /* set rom index to 0 */
  379. WREG32(mmSMC_IND_INDEX_0, ixROM_INDEX);
  380. WREG32(mmSMC_IND_DATA_0, 0);
  381. /* set index to data for continous read */
  382. WREG32(mmSMC_IND_INDEX_0, ixROM_DATA);
  383. for (i = 0; i < length_dw; i++)
  384. dw_ptr[i] = RREG32(mmSMC_IND_DATA_0);
  385. spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
  386. return true;
  387. }
  388. static u32 vi_get_virtual_caps(struct amdgpu_device *adev)
  389. {
  390. u32 caps = 0;
  391. u32 reg = RREG32(mmBIF_IOV_FUNC_IDENTIFIER);
  392. if (REG_GET_FIELD(reg, BIF_IOV_FUNC_IDENTIFIER, IOV_ENABLE))
  393. caps |= AMDGPU_VIRT_CAPS_SRIOV_EN;
  394. if (REG_GET_FIELD(reg, BIF_IOV_FUNC_IDENTIFIER, FUNC_IDENTIFIER))
  395. caps |= AMDGPU_VIRT_CAPS_IS_VF;
  396. return caps;
  397. }
  398. static const struct amdgpu_allowed_register_entry tonga_allowed_read_registers[] = {
  399. {mmGB_MACROTILE_MODE7, true},
  400. };
  401. static const struct amdgpu_allowed_register_entry cz_allowed_read_registers[] = {
  402. {mmGB_TILE_MODE7, true},
  403. {mmGB_TILE_MODE12, true},
  404. {mmGB_TILE_MODE17, true},
  405. {mmGB_TILE_MODE23, true},
  406. {mmGB_MACROTILE_MODE7, true},
  407. };
  408. static const struct amdgpu_allowed_register_entry vi_allowed_read_registers[] = {
  409. {mmGRBM_STATUS, false},
  410. {mmGRBM_STATUS2, false},
  411. {mmGRBM_STATUS_SE0, false},
  412. {mmGRBM_STATUS_SE1, false},
  413. {mmGRBM_STATUS_SE2, false},
  414. {mmGRBM_STATUS_SE3, false},
  415. {mmSRBM_STATUS, false},
  416. {mmSRBM_STATUS2, false},
  417. {mmSRBM_STATUS3, false},
  418. {mmSDMA0_STATUS_REG + SDMA0_REGISTER_OFFSET, false},
  419. {mmSDMA0_STATUS_REG + SDMA1_REGISTER_OFFSET, false},
  420. {mmCP_STAT, false},
  421. {mmCP_STALLED_STAT1, false},
  422. {mmCP_STALLED_STAT2, false},
  423. {mmCP_STALLED_STAT3, false},
  424. {mmCP_CPF_BUSY_STAT, false},
  425. {mmCP_CPF_STALLED_STAT1, false},
  426. {mmCP_CPF_STATUS, false},
  427. {mmCP_CPC_BUSY_STAT, false},
  428. {mmCP_CPC_STALLED_STAT1, false},
  429. {mmCP_CPC_STATUS, false},
  430. {mmGB_ADDR_CONFIG, false},
  431. {mmMC_ARB_RAMCFG, false},
  432. {mmGB_TILE_MODE0, false},
  433. {mmGB_TILE_MODE1, false},
  434. {mmGB_TILE_MODE2, false},
  435. {mmGB_TILE_MODE3, false},
  436. {mmGB_TILE_MODE4, false},
  437. {mmGB_TILE_MODE5, false},
  438. {mmGB_TILE_MODE6, false},
  439. {mmGB_TILE_MODE7, false},
  440. {mmGB_TILE_MODE8, false},
  441. {mmGB_TILE_MODE9, false},
  442. {mmGB_TILE_MODE10, false},
  443. {mmGB_TILE_MODE11, false},
  444. {mmGB_TILE_MODE12, false},
  445. {mmGB_TILE_MODE13, false},
  446. {mmGB_TILE_MODE14, false},
  447. {mmGB_TILE_MODE15, false},
  448. {mmGB_TILE_MODE16, false},
  449. {mmGB_TILE_MODE17, false},
  450. {mmGB_TILE_MODE18, false},
  451. {mmGB_TILE_MODE19, false},
  452. {mmGB_TILE_MODE20, false},
  453. {mmGB_TILE_MODE21, false},
  454. {mmGB_TILE_MODE22, false},
  455. {mmGB_TILE_MODE23, false},
  456. {mmGB_TILE_MODE24, false},
  457. {mmGB_TILE_MODE25, false},
  458. {mmGB_TILE_MODE26, false},
  459. {mmGB_TILE_MODE27, false},
  460. {mmGB_TILE_MODE28, false},
  461. {mmGB_TILE_MODE29, false},
  462. {mmGB_TILE_MODE30, false},
  463. {mmGB_TILE_MODE31, false},
  464. {mmGB_MACROTILE_MODE0, false},
  465. {mmGB_MACROTILE_MODE1, false},
  466. {mmGB_MACROTILE_MODE2, false},
  467. {mmGB_MACROTILE_MODE3, false},
  468. {mmGB_MACROTILE_MODE4, false},
  469. {mmGB_MACROTILE_MODE5, false},
  470. {mmGB_MACROTILE_MODE6, false},
  471. {mmGB_MACROTILE_MODE7, false},
  472. {mmGB_MACROTILE_MODE8, false},
  473. {mmGB_MACROTILE_MODE9, false},
  474. {mmGB_MACROTILE_MODE10, false},
  475. {mmGB_MACROTILE_MODE11, false},
  476. {mmGB_MACROTILE_MODE12, false},
  477. {mmGB_MACROTILE_MODE13, false},
  478. {mmGB_MACROTILE_MODE14, false},
  479. {mmGB_MACROTILE_MODE15, false},
  480. {mmCC_RB_BACKEND_DISABLE, false, true},
  481. {mmGC_USER_RB_BACKEND_DISABLE, false, true},
  482. {mmGB_BACKEND_MAP, false, false},
  483. {mmPA_SC_RASTER_CONFIG, false, true},
  484. {mmPA_SC_RASTER_CONFIG_1, false, true},
  485. };
  486. static uint32_t vi_read_indexed_register(struct amdgpu_device *adev, u32 se_num,
  487. u32 sh_num, u32 reg_offset)
  488. {
  489. uint32_t val;
  490. mutex_lock(&adev->grbm_idx_mutex);
  491. if (se_num != 0xffffffff || sh_num != 0xffffffff)
  492. amdgpu_gfx_select_se_sh(adev, se_num, sh_num, 0xffffffff);
  493. val = RREG32(reg_offset);
  494. if (se_num != 0xffffffff || sh_num != 0xffffffff)
  495. amdgpu_gfx_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
  496. mutex_unlock(&adev->grbm_idx_mutex);
  497. return val;
  498. }
  499. static int vi_read_register(struct amdgpu_device *adev, u32 se_num,
  500. u32 sh_num, u32 reg_offset, u32 *value)
  501. {
  502. const struct amdgpu_allowed_register_entry *asic_register_table = NULL;
  503. const struct amdgpu_allowed_register_entry *asic_register_entry;
  504. uint32_t size, i;
  505. *value = 0;
  506. switch (adev->asic_type) {
  507. case CHIP_TOPAZ:
  508. asic_register_table = tonga_allowed_read_registers;
  509. size = ARRAY_SIZE(tonga_allowed_read_registers);
  510. break;
  511. case CHIP_FIJI:
  512. case CHIP_TONGA:
  513. case CHIP_POLARIS11:
  514. case CHIP_POLARIS10:
  515. case CHIP_CARRIZO:
  516. case CHIP_STONEY:
  517. asic_register_table = cz_allowed_read_registers;
  518. size = ARRAY_SIZE(cz_allowed_read_registers);
  519. break;
  520. default:
  521. return -EINVAL;
  522. }
  523. if (asic_register_table) {
  524. for (i = 0; i < size; i++) {
  525. asic_register_entry = asic_register_table + i;
  526. if (reg_offset != asic_register_entry->reg_offset)
  527. continue;
  528. if (!asic_register_entry->untouched)
  529. *value = asic_register_entry->grbm_indexed ?
  530. vi_read_indexed_register(adev, se_num,
  531. sh_num, reg_offset) :
  532. RREG32(reg_offset);
  533. return 0;
  534. }
  535. }
  536. for (i = 0; i < ARRAY_SIZE(vi_allowed_read_registers); i++) {
  537. if (reg_offset != vi_allowed_read_registers[i].reg_offset)
  538. continue;
  539. if (!vi_allowed_read_registers[i].untouched)
  540. *value = vi_allowed_read_registers[i].grbm_indexed ?
  541. vi_read_indexed_register(adev, se_num,
  542. sh_num, reg_offset) :
  543. RREG32(reg_offset);
  544. return 0;
  545. }
  546. return -EINVAL;
  547. }
  548. static int vi_gpu_pci_config_reset(struct amdgpu_device *adev)
  549. {
  550. u32 i;
  551. dev_info(adev->dev, "GPU pci config reset\n");
  552. /* disable BM */
  553. pci_clear_master(adev->pdev);
  554. /* reset */
  555. amdgpu_pci_config_reset(adev);
  556. udelay(100);
  557. /* wait for asic to come out of reset */
  558. for (i = 0; i < adev->usec_timeout; i++) {
  559. if (RREG32(mmCONFIG_MEMSIZE) != 0xffffffff) {
  560. /* enable BM */
  561. pci_set_master(adev->pdev);
  562. return 0;
  563. }
  564. udelay(1);
  565. }
  566. return -EINVAL;
  567. }
  568. static void vi_set_bios_scratch_engine_hung(struct amdgpu_device *adev, bool hung)
  569. {
  570. u32 tmp = RREG32(mmBIOS_SCRATCH_3);
  571. if (hung)
  572. tmp |= ATOM_S3_ASIC_GUI_ENGINE_HUNG;
  573. else
  574. tmp &= ~ATOM_S3_ASIC_GUI_ENGINE_HUNG;
  575. WREG32(mmBIOS_SCRATCH_3, tmp);
  576. }
  577. /**
  578. * vi_asic_reset - soft reset GPU
  579. *
  580. * @adev: amdgpu_device pointer
  581. *
  582. * Look up which blocks are hung and attempt
  583. * to reset them.
  584. * Returns 0 for success.
  585. */
  586. static int vi_asic_reset(struct amdgpu_device *adev)
  587. {
  588. int r;
  589. vi_set_bios_scratch_engine_hung(adev, true);
  590. r = vi_gpu_pci_config_reset(adev);
  591. vi_set_bios_scratch_engine_hung(adev, false);
  592. return r;
  593. }
  594. static int vi_set_uvd_clock(struct amdgpu_device *adev, u32 clock,
  595. u32 cntl_reg, u32 status_reg)
  596. {
  597. int r, i;
  598. struct atom_clock_dividers dividers;
  599. uint32_t tmp;
  600. r = amdgpu_atombios_get_clock_dividers(adev,
  601. COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK,
  602. clock, false, &dividers);
  603. if (r)
  604. return r;
  605. tmp = RREG32_SMC(cntl_reg);
  606. tmp &= ~(CG_DCLK_CNTL__DCLK_DIR_CNTL_EN_MASK |
  607. CG_DCLK_CNTL__DCLK_DIVIDER_MASK);
  608. tmp |= dividers.post_divider;
  609. WREG32_SMC(cntl_reg, tmp);
  610. for (i = 0; i < 100; i++) {
  611. if (RREG32_SMC(status_reg) & CG_DCLK_STATUS__DCLK_STATUS_MASK)
  612. break;
  613. mdelay(10);
  614. }
  615. if (i == 100)
  616. return -ETIMEDOUT;
  617. return 0;
  618. }
  619. static int vi_set_uvd_clocks(struct amdgpu_device *adev, u32 vclk, u32 dclk)
  620. {
  621. int r;
  622. r = vi_set_uvd_clock(adev, vclk, ixCG_VCLK_CNTL, ixCG_VCLK_STATUS);
  623. if (r)
  624. return r;
  625. r = vi_set_uvd_clock(adev, dclk, ixCG_DCLK_CNTL, ixCG_DCLK_STATUS);
  626. return 0;
  627. }
  628. static int vi_set_vce_clocks(struct amdgpu_device *adev, u32 evclk, u32 ecclk)
  629. {
  630. /* todo */
  631. return 0;
  632. }
  633. static void vi_pcie_gen3_enable(struct amdgpu_device *adev)
  634. {
  635. if (pci_is_root_bus(adev->pdev->bus))
  636. return;
  637. if (amdgpu_pcie_gen2 == 0)
  638. return;
  639. if (adev->flags & AMD_IS_APU)
  640. return;
  641. if (!(adev->pm.pcie_gen_mask & (CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2 |
  642. CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3)))
  643. return;
  644. /* todo */
  645. }
  646. static void vi_program_aspm(struct amdgpu_device *adev)
  647. {
  648. if (amdgpu_aspm == 0)
  649. return;
  650. /* todo */
  651. }
  652. static void vi_enable_doorbell_aperture(struct amdgpu_device *adev,
  653. bool enable)
  654. {
  655. u32 tmp;
  656. /* not necessary on CZ */
  657. if (adev->flags & AMD_IS_APU)
  658. return;
  659. tmp = RREG32(mmBIF_DOORBELL_APER_EN);
  660. if (enable)
  661. tmp = REG_SET_FIELD(tmp, BIF_DOORBELL_APER_EN, BIF_DOORBELL_APER_EN, 1);
  662. else
  663. tmp = REG_SET_FIELD(tmp, BIF_DOORBELL_APER_EN, BIF_DOORBELL_APER_EN, 0);
  664. WREG32(mmBIF_DOORBELL_APER_EN, tmp);
  665. }
  666. /* topaz has no DCE, UVD, VCE */
  667. static const struct amdgpu_ip_block_version topaz_ip_blocks[] =
  668. {
  669. /* ORDER MATTERS! */
  670. {
  671. .type = AMD_IP_BLOCK_TYPE_COMMON,
  672. .major = 2,
  673. .minor = 0,
  674. .rev = 0,
  675. .funcs = &vi_common_ip_funcs,
  676. },
  677. {
  678. .type = AMD_IP_BLOCK_TYPE_GMC,
  679. .major = 7,
  680. .minor = 4,
  681. .rev = 0,
  682. .funcs = &gmc_v7_0_ip_funcs,
  683. },
  684. {
  685. .type = AMD_IP_BLOCK_TYPE_IH,
  686. .major = 2,
  687. .minor = 4,
  688. .rev = 0,
  689. .funcs = &iceland_ih_ip_funcs,
  690. },
  691. {
  692. .type = AMD_IP_BLOCK_TYPE_SMC,
  693. .major = 7,
  694. .minor = 1,
  695. .rev = 0,
  696. .funcs = &amdgpu_pp_ip_funcs,
  697. },
  698. {
  699. .type = AMD_IP_BLOCK_TYPE_GFX,
  700. .major = 8,
  701. .minor = 0,
  702. .rev = 0,
  703. .funcs = &gfx_v8_0_ip_funcs,
  704. },
  705. {
  706. .type = AMD_IP_BLOCK_TYPE_SDMA,
  707. .major = 2,
  708. .minor = 4,
  709. .rev = 0,
  710. .funcs = &sdma_v2_4_ip_funcs,
  711. },
  712. };
  713. static const struct amdgpu_ip_block_version topaz_ip_blocks_vd[] =
  714. {
  715. /* ORDER MATTERS! */
  716. {
  717. .type = AMD_IP_BLOCK_TYPE_COMMON,
  718. .major = 2,
  719. .minor = 0,
  720. .rev = 0,
  721. .funcs = &vi_common_ip_funcs,
  722. },
  723. {
  724. .type = AMD_IP_BLOCK_TYPE_GMC,
  725. .major = 7,
  726. .minor = 4,
  727. .rev = 0,
  728. .funcs = &gmc_v7_0_ip_funcs,
  729. },
  730. {
  731. .type = AMD_IP_BLOCK_TYPE_IH,
  732. .major = 2,
  733. .minor = 4,
  734. .rev = 0,
  735. .funcs = &iceland_ih_ip_funcs,
  736. },
  737. {
  738. .type = AMD_IP_BLOCK_TYPE_SMC,
  739. .major = 7,
  740. .minor = 1,
  741. .rev = 0,
  742. .funcs = &amdgpu_pp_ip_funcs,
  743. },
  744. {
  745. .type = AMD_IP_BLOCK_TYPE_DCE,
  746. .major = 1,
  747. .minor = 0,
  748. .rev = 0,
  749. .funcs = &dce_virtual_ip_funcs,
  750. },
  751. {
  752. .type = AMD_IP_BLOCK_TYPE_GFX,
  753. .major = 8,
  754. .minor = 0,
  755. .rev = 0,
  756. .funcs = &gfx_v8_0_ip_funcs,
  757. },
  758. {
  759. .type = AMD_IP_BLOCK_TYPE_SDMA,
  760. .major = 2,
  761. .minor = 4,
  762. .rev = 0,
  763. .funcs = &sdma_v2_4_ip_funcs,
  764. },
  765. };
  766. static const struct amdgpu_ip_block_version tonga_ip_blocks[] =
  767. {
  768. /* ORDER MATTERS! */
  769. {
  770. .type = AMD_IP_BLOCK_TYPE_COMMON,
  771. .major = 2,
  772. .minor = 0,
  773. .rev = 0,
  774. .funcs = &vi_common_ip_funcs,
  775. },
  776. {
  777. .type = AMD_IP_BLOCK_TYPE_GMC,
  778. .major = 8,
  779. .minor = 0,
  780. .rev = 0,
  781. .funcs = &gmc_v8_0_ip_funcs,
  782. },
  783. {
  784. .type = AMD_IP_BLOCK_TYPE_IH,
  785. .major = 3,
  786. .minor = 0,
  787. .rev = 0,
  788. .funcs = &tonga_ih_ip_funcs,
  789. },
  790. {
  791. .type = AMD_IP_BLOCK_TYPE_SMC,
  792. .major = 7,
  793. .minor = 1,
  794. .rev = 0,
  795. .funcs = &amdgpu_pp_ip_funcs,
  796. },
  797. {
  798. .type = AMD_IP_BLOCK_TYPE_DCE,
  799. .major = 10,
  800. .minor = 0,
  801. .rev = 0,
  802. .funcs = &dce_v10_0_ip_funcs,
  803. },
  804. {
  805. .type = AMD_IP_BLOCK_TYPE_GFX,
  806. .major = 8,
  807. .minor = 0,
  808. .rev = 0,
  809. .funcs = &gfx_v8_0_ip_funcs,
  810. },
  811. {
  812. .type = AMD_IP_BLOCK_TYPE_SDMA,
  813. .major = 3,
  814. .minor = 0,
  815. .rev = 0,
  816. .funcs = &sdma_v3_0_ip_funcs,
  817. },
  818. {
  819. .type = AMD_IP_BLOCK_TYPE_UVD,
  820. .major = 5,
  821. .minor = 0,
  822. .rev = 0,
  823. .funcs = &uvd_v5_0_ip_funcs,
  824. },
  825. {
  826. .type = AMD_IP_BLOCK_TYPE_VCE,
  827. .major = 3,
  828. .minor = 0,
  829. .rev = 0,
  830. .funcs = &vce_v3_0_ip_funcs,
  831. },
  832. };
  833. static const struct amdgpu_ip_block_version tonga_ip_blocks_vd[] =
  834. {
  835. /* ORDER MATTERS! */
  836. {
  837. .type = AMD_IP_BLOCK_TYPE_COMMON,
  838. .major = 2,
  839. .minor = 0,
  840. .rev = 0,
  841. .funcs = &vi_common_ip_funcs,
  842. },
  843. {
  844. .type = AMD_IP_BLOCK_TYPE_GMC,
  845. .major = 8,
  846. .minor = 0,
  847. .rev = 0,
  848. .funcs = &gmc_v8_0_ip_funcs,
  849. },
  850. {
  851. .type = AMD_IP_BLOCK_TYPE_IH,
  852. .major = 3,
  853. .minor = 0,
  854. .rev = 0,
  855. .funcs = &tonga_ih_ip_funcs,
  856. },
  857. {
  858. .type = AMD_IP_BLOCK_TYPE_SMC,
  859. .major = 7,
  860. .minor = 1,
  861. .rev = 0,
  862. .funcs = &amdgpu_pp_ip_funcs,
  863. },
  864. {
  865. .type = AMD_IP_BLOCK_TYPE_DCE,
  866. .major = 10,
  867. .minor = 0,
  868. .rev = 0,
  869. .funcs = &dce_virtual_ip_funcs,
  870. },
  871. {
  872. .type = AMD_IP_BLOCK_TYPE_GFX,
  873. .major = 8,
  874. .minor = 0,
  875. .rev = 0,
  876. .funcs = &gfx_v8_0_ip_funcs,
  877. },
  878. {
  879. .type = AMD_IP_BLOCK_TYPE_SDMA,
  880. .major = 3,
  881. .minor = 0,
  882. .rev = 0,
  883. .funcs = &sdma_v3_0_ip_funcs,
  884. },
  885. {
  886. .type = AMD_IP_BLOCK_TYPE_UVD,
  887. .major = 5,
  888. .minor = 0,
  889. .rev = 0,
  890. .funcs = &uvd_v5_0_ip_funcs,
  891. },
  892. {
  893. .type = AMD_IP_BLOCK_TYPE_VCE,
  894. .major = 3,
  895. .minor = 0,
  896. .rev = 0,
  897. .funcs = &vce_v3_0_ip_funcs,
  898. },
  899. };
  900. static const struct amdgpu_ip_block_version fiji_ip_blocks[] =
  901. {
  902. /* ORDER MATTERS! */
  903. {
  904. .type = AMD_IP_BLOCK_TYPE_COMMON,
  905. .major = 2,
  906. .minor = 0,
  907. .rev = 0,
  908. .funcs = &vi_common_ip_funcs,
  909. },
  910. {
  911. .type = AMD_IP_BLOCK_TYPE_GMC,
  912. .major = 8,
  913. .minor = 5,
  914. .rev = 0,
  915. .funcs = &gmc_v8_0_ip_funcs,
  916. },
  917. {
  918. .type = AMD_IP_BLOCK_TYPE_IH,
  919. .major = 3,
  920. .minor = 0,
  921. .rev = 0,
  922. .funcs = &tonga_ih_ip_funcs,
  923. },
  924. {
  925. .type = AMD_IP_BLOCK_TYPE_SMC,
  926. .major = 7,
  927. .minor = 1,
  928. .rev = 0,
  929. .funcs = &amdgpu_pp_ip_funcs,
  930. },
  931. {
  932. .type = AMD_IP_BLOCK_TYPE_DCE,
  933. .major = 10,
  934. .minor = 1,
  935. .rev = 0,
  936. .funcs = &dce_v10_0_ip_funcs,
  937. },
  938. {
  939. .type = AMD_IP_BLOCK_TYPE_GFX,
  940. .major = 8,
  941. .minor = 0,
  942. .rev = 0,
  943. .funcs = &gfx_v8_0_ip_funcs,
  944. },
  945. {
  946. .type = AMD_IP_BLOCK_TYPE_SDMA,
  947. .major = 3,
  948. .minor = 0,
  949. .rev = 0,
  950. .funcs = &sdma_v3_0_ip_funcs,
  951. },
  952. {
  953. .type = AMD_IP_BLOCK_TYPE_UVD,
  954. .major = 6,
  955. .minor = 0,
  956. .rev = 0,
  957. .funcs = &uvd_v6_0_ip_funcs,
  958. },
  959. {
  960. .type = AMD_IP_BLOCK_TYPE_VCE,
  961. .major = 3,
  962. .minor = 0,
  963. .rev = 0,
  964. .funcs = &vce_v3_0_ip_funcs,
  965. },
  966. };
  967. static const struct amdgpu_ip_block_version fiji_ip_blocks_vd[] =
  968. {
  969. /* ORDER MATTERS! */
  970. {
  971. .type = AMD_IP_BLOCK_TYPE_COMMON,
  972. .major = 2,
  973. .minor = 0,
  974. .rev = 0,
  975. .funcs = &vi_common_ip_funcs,
  976. },
  977. {
  978. .type = AMD_IP_BLOCK_TYPE_GMC,
  979. .major = 8,
  980. .minor = 5,
  981. .rev = 0,
  982. .funcs = &gmc_v8_0_ip_funcs,
  983. },
  984. {
  985. .type = AMD_IP_BLOCK_TYPE_IH,
  986. .major = 3,
  987. .minor = 0,
  988. .rev = 0,
  989. .funcs = &tonga_ih_ip_funcs,
  990. },
  991. {
  992. .type = AMD_IP_BLOCK_TYPE_SMC,
  993. .major = 7,
  994. .minor = 1,
  995. .rev = 0,
  996. .funcs = &amdgpu_pp_ip_funcs,
  997. },
  998. {
  999. .type = AMD_IP_BLOCK_TYPE_DCE,
  1000. .major = 10,
  1001. .minor = 1,
  1002. .rev = 0,
  1003. .funcs = &dce_virtual_ip_funcs,
  1004. },
  1005. {
  1006. .type = AMD_IP_BLOCK_TYPE_GFX,
  1007. .major = 8,
  1008. .minor = 0,
  1009. .rev = 0,
  1010. .funcs = &gfx_v8_0_ip_funcs,
  1011. },
  1012. {
  1013. .type = AMD_IP_BLOCK_TYPE_SDMA,
  1014. .major = 3,
  1015. .minor = 0,
  1016. .rev = 0,
  1017. .funcs = &sdma_v3_0_ip_funcs,
  1018. },
  1019. {
  1020. .type = AMD_IP_BLOCK_TYPE_UVD,
  1021. .major = 6,
  1022. .minor = 0,
  1023. .rev = 0,
  1024. .funcs = &uvd_v6_0_ip_funcs,
  1025. },
  1026. {
  1027. .type = AMD_IP_BLOCK_TYPE_VCE,
  1028. .major = 3,
  1029. .minor = 0,
  1030. .rev = 0,
  1031. .funcs = &vce_v3_0_ip_funcs,
  1032. },
  1033. };
  1034. static const struct amdgpu_ip_block_version polaris11_ip_blocks[] =
  1035. {
  1036. /* ORDER MATTERS! */
  1037. {
  1038. .type = AMD_IP_BLOCK_TYPE_COMMON,
  1039. .major = 2,
  1040. .minor = 0,
  1041. .rev = 0,
  1042. .funcs = &vi_common_ip_funcs,
  1043. },
  1044. {
  1045. .type = AMD_IP_BLOCK_TYPE_GMC,
  1046. .major = 8,
  1047. .minor = 1,
  1048. .rev = 0,
  1049. .funcs = &gmc_v8_0_ip_funcs,
  1050. },
  1051. {
  1052. .type = AMD_IP_BLOCK_TYPE_IH,
  1053. .major = 3,
  1054. .minor = 1,
  1055. .rev = 0,
  1056. .funcs = &tonga_ih_ip_funcs,
  1057. },
  1058. {
  1059. .type = AMD_IP_BLOCK_TYPE_SMC,
  1060. .major = 7,
  1061. .minor = 2,
  1062. .rev = 0,
  1063. .funcs = &amdgpu_pp_ip_funcs,
  1064. },
  1065. {
  1066. .type = AMD_IP_BLOCK_TYPE_DCE,
  1067. .major = 11,
  1068. .minor = 2,
  1069. .rev = 0,
  1070. .funcs = &dce_v11_0_ip_funcs,
  1071. },
  1072. {
  1073. .type = AMD_IP_BLOCK_TYPE_GFX,
  1074. .major = 8,
  1075. .minor = 0,
  1076. .rev = 0,
  1077. .funcs = &gfx_v8_0_ip_funcs,
  1078. },
  1079. {
  1080. .type = AMD_IP_BLOCK_TYPE_SDMA,
  1081. .major = 3,
  1082. .minor = 1,
  1083. .rev = 0,
  1084. .funcs = &sdma_v3_0_ip_funcs,
  1085. },
  1086. {
  1087. .type = AMD_IP_BLOCK_TYPE_UVD,
  1088. .major = 6,
  1089. .minor = 3,
  1090. .rev = 0,
  1091. .funcs = &uvd_v6_0_ip_funcs,
  1092. },
  1093. {
  1094. .type = AMD_IP_BLOCK_TYPE_VCE,
  1095. .major = 3,
  1096. .minor = 4,
  1097. .rev = 0,
  1098. .funcs = &vce_v3_0_ip_funcs,
  1099. },
  1100. };
  1101. static const struct amdgpu_ip_block_version polaris11_ip_blocks_vd[] =
  1102. {
  1103. /* ORDER MATTERS! */
  1104. {
  1105. .type = AMD_IP_BLOCK_TYPE_COMMON,
  1106. .major = 2,
  1107. .minor = 0,
  1108. .rev = 0,
  1109. .funcs = &vi_common_ip_funcs,
  1110. },
  1111. {
  1112. .type = AMD_IP_BLOCK_TYPE_GMC,
  1113. .major = 8,
  1114. .minor = 1,
  1115. .rev = 0,
  1116. .funcs = &gmc_v8_0_ip_funcs,
  1117. },
  1118. {
  1119. .type = AMD_IP_BLOCK_TYPE_IH,
  1120. .major = 3,
  1121. .minor = 1,
  1122. .rev = 0,
  1123. .funcs = &tonga_ih_ip_funcs,
  1124. },
  1125. {
  1126. .type = AMD_IP_BLOCK_TYPE_SMC,
  1127. .major = 7,
  1128. .minor = 2,
  1129. .rev = 0,
  1130. .funcs = &amdgpu_pp_ip_funcs,
  1131. },
  1132. {
  1133. .type = AMD_IP_BLOCK_TYPE_DCE,
  1134. .major = 11,
  1135. .minor = 2,
  1136. .rev = 0,
  1137. .funcs = &dce_virtual_ip_funcs,
  1138. },
  1139. {
  1140. .type = AMD_IP_BLOCK_TYPE_GFX,
  1141. .major = 8,
  1142. .minor = 0,
  1143. .rev = 0,
  1144. .funcs = &gfx_v8_0_ip_funcs,
  1145. },
  1146. {
  1147. .type = AMD_IP_BLOCK_TYPE_SDMA,
  1148. .major = 3,
  1149. .minor = 1,
  1150. .rev = 0,
  1151. .funcs = &sdma_v3_0_ip_funcs,
  1152. },
  1153. {
  1154. .type = AMD_IP_BLOCK_TYPE_UVD,
  1155. .major = 6,
  1156. .minor = 3,
  1157. .rev = 0,
  1158. .funcs = &uvd_v6_0_ip_funcs,
  1159. },
  1160. {
  1161. .type = AMD_IP_BLOCK_TYPE_VCE,
  1162. .major = 3,
  1163. .minor = 4,
  1164. .rev = 0,
  1165. .funcs = &vce_v3_0_ip_funcs,
  1166. },
  1167. };
  1168. static const struct amdgpu_ip_block_version cz_ip_blocks[] =
  1169. {
  1170. /* ORDER MATTERS! */
  1171. {
  1172. .type = AMD_IP_BLOCK_TYPE_COMMON,
  1173. .major = 2,
  1174. .minor = 0,
  1175. .rev = 0,
  1176. .funcs = &vi_common_ip_funcs,
  1177. },
  1178. {
  1179. .type = AMD_IP_BLOCK_TYPE_GMC,
  1180. .major = 8,
  1181. .minor = 0,
  1182. .rev = 0,
  1183. .funcs = &gmc_v8_0_ip_funcs,
  1184. },
  1185. {
  1186. .type = AMD_IP_BLOCK_TYPE_IH,
  1187. .major = 3,
  1188. .minor = 0,
  1189. .rev = 0,
  1190. .funcs = &cz_ih_ip_funcs,
  1191. },
  1192. {
  1193. .type = AMD_IP_BLOCK_TYPE_SMC,
  1194. .major = 8,
  1195. .minor = 0,
  1196. .rev = 0,
  1197. .funcs = &amdgpu_pp_ip_funcs
  1198. },
  1199. {
  1200. .type = AMD_IP_BLOCK_TYPE_DCE,
  1201. .major = 11,
  1202. .minor = 0,
  1203. .rev = 0,
  1204. .funcs = &dce_v11_0_ip_funcs,
  1205. },
  1206. {
  1207. .type = AMD_IP_BLOCK_TYPE_GFX,
  1208. .major = 8,
  1209. .minor = 0,
  1210. .rev = 0,
  1211. .funcs = &gfx_v8_0_ip_funcs,
  1212. },
  1213. {
  1214. .type = AMD_IP_BLOCK_TYPE_SDMA,
  1215. .major = 3,
  1216. .minor = 0,
  1217. .rev = 0,
  1218. .funcs = &sdma_v3_0_ip_funcs,
  1219. },
  1220. {
  1221. .type = AMD_IP_BLOCK_TYPE_UVD,
  1222. .major = 6,
  1223. .minor = 0,
  1224. .rev = 0,
  1225. .funcs = &uvd_v6_0_ip_funcs,
  1226. },
  1227. {
  1228. .type = AMD_IP_BLOCK_TYPE_VCE,
  1229. .major = 3,
  1230. .minor = 0,
  1231. .rev = 0,
  1232. .funcs = &vce_v3_0_ip_funcs,
  1233. },
  1234. #if defined(CONFIG_DRM_AMD_ACP)
  1235. {
  1236. .type = AMD_IP_BLOCK_TYPE_ACP,
  1237. .major = 2,
  1238. .minor = 2,
  1239. .rev = 0,
  1240. .funcs = &acp_ip_funcs,
  1241. },
  1242. #endif
  1243. };
  1244. static const struct amdgpu_ip_block_version cz_ip_blocks_vd[] =
  1245. {
  1246. /* ORDER MATTERS! */
  1247. {
  1248. .type = AMD_IP_BLOCK_TYPE_COMMON,
  1249. .major = 2,
  1250. .minor = 0,
  1251. .rev = 0,
  1252. .funcs = &vi_common_ip_funcs,
  1253. },
  1254. {
  1255. .type = AMD_IP_BLOCK_TYPE_GMC,
  1256. .major = 8,
  1257. .minor = 0,
  1258. .rev = 0,
  1259. .funcs = &gmc_v8_0_ip_funcs,
  1260. },
  1261. {
  1262. .type = AMD_IP_BLOCK_TYPE_IH,
  1263. .major = 3,
  1264. .minor = 0,
  1265. .rev = 0,
  1266. .funcs = &cz_ih_ip_funcs,
  1267. },
  1268. {
  1269. .type = AMD_IP_BLOCK_TYPE_SMC,
  1270. .major = 8,
  1271. .minor = 0,
  1272. .rev = 0,
  1273. .funcs = &amdgpu_pp_ip_funcs
  1274. },
  1275. {
  1276. .type = AMD_IP_BLOCK_TYPE_DCE,
  1277. .major = 11,
  1278. .minor = 0,
  1279. .rev = 0,
  1280. .funcs = &dce_virtual_ip_funcs,
  1281. },
  1282. {
  1283. .type = AMD_IP_BLOCK_TYPE_GFX,
  1284. .major = 8,
  1285. .minor = 0,
  1286. .rev = 0,
  1287. .funcs = &gfx_v8_0_ip_funcs,
  1288. },
  1289. {
  1290. .type = AMD_IP_BLOCK_TYPE_SDMA,
  1291. .major = 3,
  1292. .minor = 0,
  1293. .rev = 0,
  1294. .funcs = &sdma_v3_0_ip_funcs,
  1295. },
  1296. {
  1297. .type = AMD_IP_BLOCK_TYPE_UVD,
  1298. .major = 6,
  1299. .minor = 0,
  1300. .rev = 0,
  1301. .funcs = &uvd_v6_0_ip_funcs,
  1302. },
  1303. {
  1304. .type = AMD_IP_BLOCK_TYPE_VCE,
  1305. .major = 3,
  1306. .minor = 0,
  1307. .rev = 0,
  1308. .funcs = &vce_v3_0_ip_funcs,
  1309. },
  1310. #if defined(CONFIG_DRM_AMD_ACP)
  1311. {
  1312. .type = AMD_IP_BLOCK_TYPE_ACP,
  1313. .major = 2,
  1314. .minor = 2,
  1315. .rev = 0,
  1316. .funcs = &acp_ip_funcs,
  1317. },
  1318. #endif
  1319. };
  1320. int vi_set_ip_blocks(struct amdgpu_device *adev)
  1321. {
  1322. if (adev->enable_virtual_display) {
  1323. switch (adev->asic_type) {
  1324. case CHIP_TOPAZ:
  1325. adev->ip_blocks = topaz_ip_blocks_vd;
  1326. adev->num_ip_blocks = ARRAY_SIZE(topaz_ip_blocks_vd);
  1327. break;
  1328. case CHIP_FIJI:
  1329. adev->ip_blocks = fiji_ip_blocks_vd;
  1330. adev->num_ip_blocks = ARRAY_SIZE(fiji_ip_blocks_vd);
  1331. break;
  1332. case CHIP_TONGA:
  1333. adev->ip_blocks = tonga_ip_blocks_vd;
  1334. adev->num_ip_blocks = ARRAY_SIZE(tonga_ip_blocks_vd);
  1335. break;
  1336. case CHIP_POLARIS11:
  1337. case CHIP_POLARIS10:
  1338. adev->ip_blocks = polaris11_ip_blocks_vd;
  1339. adev->num_ip_blocks = ARRAY_SIZE(polaris11_ip_blocks_vd);
  1340. break;
  1341. case CHIP_CARRIZO:
  1342. case CHIP_STONEY:
  1343. adev->ip_blocks = cz_ip_blocks_vd;
  1344. adev->num_ip_blocks = ARRAY_SIZE(cz_ip_blocks_vd);
  1345. break;
  1346. default:
  1347. /* FIXME: not supported yet */
  1348. return -EINVAL;
  1349. }
  1350. } else {
  1351. switch (adev->asic_type) {
  1352. case CHIP_TOPAZ:
  1353. adev->ip_blocks = topaz_ip_blocks;
  1354. adev->num_ip_blocks = ARRAY_SIZE(topaz_ip_blocks);
  1355. break;
  1356. case CHIP_FIJI:
  1357. adev->ip_blocks = fiji_ip_blocks;
  1358. adev->num_ip_blocks = ARRAY_SIZE(fiji_ip_blocks);
  1359. break;
  1360. case CHIP_TONGA:
  1361. adev->ip_blocks = tonga_ip_blocks;
  1362. adev->num_ip_blocks = ARRAY_SIZE(tonga_ip_blocks);
  1363. break;
  1364. case CHIP_POLARIS11:
  1365. case CHIP_POLARIS10:
  1366. adev->ip_blocks = polaris11_ip_blocks;
  1367. adev->num_ip_blocks = ARRAY_SIZE(polaris11_ip_blocks);
  1368. break;
  1369. case CHIP_CARRIZO:
  1370. case CHIP_STONEY:
  1371. adev->ip_blocks = cz_ip_blocks;
  1372. adev->num_ip_blocks = ARRAY_SIZE(cz_ip_blocks);
  1373. break;
  1374. default:
  1375. /* FIXME: not supported yet */
  1376. return -EINVAL;
  1377. }
  1378. }
  1379. return 0;
  1380. }
  1381. #define ATI_REV_ID_FUSE_MACRO__ADDRESS 0xC0014044
  1382. #define ATI_REV_ID_FUSE_MACRO__SHIFT 9
  1383. #define ATI_REV_ID_FUSE_MACRO__MASK 0x00001E00
  1384. static uint32_t vi_get_rev_id(struct amdgpu_device *adev)
  1385. {
  1386. if (adev->flags & AMD_IS_APU)
  1387. return (RREG32_SMC(ATI_REV_ID_FUSE_MACRO__ADDRESS) & ATI_REV_ID_FUSE_MACRO__MASK)
  1388. >> ATI_REV_ID_FUSE_MACRO__SHIFT;
  1389. else
  1390. return (RREG32(mmPCIE_EFUSE4) & PCIE_EFUSE4__STRAP_BIF_ATI_REV_ID_MASK)
  1391. >> PCIE_EFUSE4__STRAP_BIF_ATI_REV_ID__SHIFT;
  1392. }
  1393. static const struct amdgpu_asic_funcs vi_asic_funcs =
  1394. {
  1395. .read_disabled_bios = &vi_read_disabled_bios,
  1396. .read_bios_from_rom = &vi_read_bios_from_rom,
  1397. .read_register = &vi_read_register,
  1398. .reset = &vi_asic_reset,
  1399. .set_vga_state = &vi_vga_set_state,
  1400. .get_xclk = &vi_get_xclk,
  1401. .set_uvd_clocks = &vi_set_uvd_clocks,
  1402. .set_vce_clocks = &vi_set_vce_clocks,
  1403. .get_virtual_caps = &vi_get_virtual_caps,
  1404. };
  1405. static int vi_common_early_init(void *handle)
  1406. {
  1407. bool smc_enabled = false;
  1408. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  1409. if (adev->flags & AMD_IS_APU) {
  1410. adev->smc_rreg = &cz_smc_rreg;
  1411. adev->smc_wreg = &cz_smc_wreg;
  1412. } else {
  1413. adev->smc_rreg = &vi_smc_rreg;
  1414. adev->smc_wreg = &vi_smc_wreg;
  1415. }
  1416. adev->pcie_rreg = &vi_pcie_rreg;
  1417. adev->pcie_wreg = &vi_pcie_wreg;
  1418. adev->uvd_ctx_rreg = &vi_uvd_ctx_rreg;
  1419. adev->uvd_ctx_wreg = &vi_uvd_ctx_wreg;
  1420. adev->didt_rreg = &vi_didt_rreg;
  1421. adev->didt_wreg = &vi_didt_wreg;
  1422. adev->gc_cac_rreg = &vi_gc_cac_rreg;
  1423. adev->gc_cac_wreg = &vi_gc_cac_wreg;
  1424. adev->asic_funcs = &vi_asic_funcs;
  1425. if (amdgpu_get_ip_block(adev, AMD_IP_BLOCK_TYPE_SMC) &&
  1426. (amdgpu_ip_block_mask & (1 << AMD_IP_BLOCK_TYPE_SMC)))
  1427. smc_enabled = true;
  1428. adev->rev_id = vi_get_rev_id(adev);
  1429. adev->external_rev_id = 0xFF;
  1430. switch (adev->asic_type) {
  1431. case CHIP_TOPAZ:
  1432. adev->cg_flags = 0;
  1433. adev->pg_flags = 0;
  1434. adev->external_rev_id = 0x1;
  1435. break;
  1436. case CHIP_FIJI:
  1437. adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
  1438. AMD_CG_SUPPORT_GFX_MGLS |
  1439. AMD_CG_SUPPORT_GFX_RLC_LS |
  1440. AMD_CG_SUPPORT_GFX_CP_LS |
  1441. AMD_CG_SUPPORT_GFX_CGTS |
  1442. AMD_CG_SUPPORT_GFX_CGTS_LS |
  1443. AMD_CG_SUPPORT_GFX_CGCG |
  1444. AMD_CG_SUPPORT_GFX_CGLS |
  1445. AMD_CG_SUPPORT_SDMA_MGCG |
  1446. AMD_CG_SUPPORT_SDMA_LS |
  1447. AMD_CG_SUPPORT_BIF_LS |
  1448. AMD_CG_SUPPORT_HDP_MGCG |
  1449. AMD_CG_SUPPORT_HDP_LS |
  1450. AMD_CG_SUPPORT_ROM_MGCG |
  1451. AMD_CG_SUPPORT_MC_MGCG |
  1452. AMD_CG_SUPPORT_MC_LS;
  1453. adev->pg_flags = 0;
  1454. adev->external_rev_id = adev->rev_id + 0x3c;
  1455. break;
  1456. case CHIP_TONGA:
  1457. adev->cg_flags = AMD_CG_SUPPORT_UVD_MGCG;
  1458. adev->pg_flags = 0;
  1459. adev->external_rev_id = adev->rev_id + 0x14;
  1460. break;
  1461. case CHIP_POLARIS11:
  1462. adev->cg_flags = 0;
  1463. adev->pg_flags = 0;
  1464. adev->external_rev_id = adev->rev_id + 0x5A;
  1465. break;
  1466. case CHIP_POLARIS10:
  1467. adev->cg_flags = 0;
  1468. adev->pg_flags = 0;
  1469. adev->external_rev_id = adev->rev_id + 0x50;
  1470. break;
  1471. case CHIP_CARRIZO:
  1472. adev->cg_flags = AMD_CG_SUPPORT_UVD_MGCG |
  1473. AMD_CG_SUPPORT_GFX_MGCG |
  1474. AMD_CG_SUPPORT_GFX_MGLS |
  1475. AMD_CG_SUPPORT_GFX_RLC_LS |
  1476. AMD_CG_SUPPORT_GFX_CP_LS |
  1477. AMD_CG_SUPPORT_GFX_CGTS |
  1478. AMD_CG_SUPPORT_GFX_MGLS |
  1479. AMD_CG_SUPPORT_GFX_CGTS_LS |
  1480. AMD_CG_SUPPORT_GFX_CGCG |
  1481. AMD_CG_SUPPORT_GFX_CGLS |
  1482. AMD_CG_SUPPORT_BIF_LS |
  1483. AMD_CG_SUPPORT_HDP_MGCG |
  1484. AMD_CG_SUPPORT_HDP_LS |
  1485. AMD_CG_SUPPORT_SDMA_MGCG |
  1486. AMD_CG_SUPPORT_SDMA_LS |
  1487. AMD_CG_SUPPORT_VCE_MGCG;
  1488. /* rev0 hardware requires workarounds to support PG */
  1489. adev->pg_flags = 0;
  1490. if (adev->rev_id != 0x00) {
  1491. adev->pg_flags |= AMD_PG_SUPPORT_GFX_PG |
  1492. AMD_PG_SUPPORT_GFX_SMG |
  1493. AMD_PG_SUPPORT_GFX_PIPELINE |
  1494. AMD_PG_SUPPORT_UVD |
  1495. AMD_PG_SUPPORT_VCE;
  1496. }
  1497. adev->external_rev_id = adev->rev_id + 0x1;
  1498. break;
  1499. case CHIP_STONEY:
  1500. adev->cg_flags = AMD_CG_SUPPORT_UVD_MGCG |
  1501. AMD_CG_SUPPORT_GFX_MGCG |
  1502. AMD_CG_SUPPORT_GFX_MGLS |
  1503. AMD_CG_SUPPORT_GFX_RLC_LS |
  1504. AMD_CG_SUPPORT_GFX_CP_LS |
  1505. AMD_CG_SUPPORT_GFX_CGTS |
  1506. AMD_CG_SUPPORT_GFX_MGLS |
  1507. AMD_CG_SUPPORT_GFX_CGTS_LS |
  1508. AMD_CG_SUPPORT_GFX_CGCG |
  1509. AMD_CG_SUPPORT_GFX_CGLS |
  1510. AMD_CG_SUPPORT_BIF_LS |
  1511. AMD_CG_SUPPORT_HDP_MGCG |
  1512. AMD_CG_SUPPORT_HDP_LS |
  1513. AMD_CG_SUPPORT_SDMA_MGCG |
  1514. AMD_CG_SUPPORT_SDMA_LS |
  1515. AMD_CG_SUPPORT_VCE_MGCG;
  1516. adev->pg_flags |= AMD_PG_SUPPORT_GFX_PG |
  1517. AMD_PG_SUPPORT_GFX_SMG |
  1518. AMD_PG_SUPPORT_GFX_PIPELINE |
  1519. AMD_PG_SUPPORT_UVD |
  1520. AMD_PG_SUPPORT_VCE;
  1521. adev->external_rev_id = adev->rev_id + 0x61;
  1522. break;
  1523. default:
  1524. /* FIXME: not supported yet */
  1525. return -EINVAL;
  1526. }
  1527. if (amdgpu_smc_load_fw && smc_enabled)
  1528. adev->firmware.smu_load = true;
  1529. amdgpu_get_pcie_info(adev);
  1530. return 0;
  1531. }
  1532. static int vi_common_sw_init(void *handle)
  1533. {
  1534. return 0;
  1535. }
  1536. static int vi_common_sw_fini(void *handle)
  1537. {
  1538. return 0;
  1539. }
  1540. static int vi_common_hw_init(void *handle)
  1541. {
  1542. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  1543. /* move the golden regs per IP block */
  1544. vi_init_golden_registers(adev);
  1545. /* enable pcie gen2/3 link */
  1546. vi_pcie_gen3_enable(adev);
  1547. /* enable aspm */
  1548. vi_program_aspm(adev);
  1549. /* enable the doorbell aperture */
  1550. vi_enable_doorbell_aperture(adev, true);
  1551. return 0;
  1552. }
  1553. static int vi_common_hw_fini(void *handle)
  1554. {
  1555. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  1556. /* enable the doorbell aperture */
  1557. vi_enable_doorbell_aperture(adev, false);
  1558. return 0;
  1559. }
  1560. static int vi_common_suspend(void *handle)
  1561. {
  1562. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  1563. return vi_common_hw_fini(adev);
  1564. }
  1565. static int vi_common_resume(void *handle)
  1566. {
  1567. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  1568. return vi_common_hw_init(adev);
  1569. }
  1570. static bool vi_common_is_idle(void *handle)
  1571. {
  1572. return true;
  1573. }
  1574. static int vi_common_wait_for_idle(void *handle)
  1575. {
  1576. return 0;
  1577. }
  1578. static int vi_common_soft_reset(void *handle)
  1579. {
  1580. return 0;
  1581. }
  1582. static void vi_update_bif_medium_grain_light_sleep(struct amdgpu_device *adev,
  1583. bool enable)
  1584. {
  1585. uint32_t temp, data;
  1586. temp = data = RREG32_PCIE(ixPCIE_CNTL2);
  1587. if (enable && (adev->cg_flags & AMD_CG_SUPPORT_BIF_LS))
  1588. data |= PCIE_CNTL2__SLV_MEM_LS_EN_MASK |
  1589. PCIE_CNTL2__MST_MEM_LS_EN_MASK |
  1590. PCIE_CNTL2__REPLAY_MEM_LS_EN_MASK;
  1591. else
  1592. data &= ~(PCIE_CNTL2__SLV_MEM_LS_EN_MASK |
  1593. PCIE_CNTL2__MST_MEM_LS_EN_MASK |
  1594. PCIE_CNTL2__REPLAY_MEM_LS_EN_MASK);
  1595. if (temp != data)
  1596. WREG32_PCIE(ixPCIE_CNTL2, data);
  1597. }
  1598. static void vi_update_hdp_medium_grain_clock_gating(struct amdgpu_device *adev,
  1599. bool enable)
  1600. {
  1601. uint32_t temp, data;
  1602. temp = data = RREG32(mmHDP_HOST_PATH_CNTL);
  1603. if (enable && (adev->cg_flags & AMD_CG_SUPPORT_HDP_MGCG))
  1604. data &= ~HDP_HOST_PATH_CNTL__CLOCK_GATING_DIS_MASK;
  1605. else
  1606. data |= HDP_HOST_PATH_CNTL__CLOCK_GATING_DIS_MASK;
  1607. if (temp != data)
  1608. WREG32(mmHDP_HOST_PATH_CNTL, data);
  1609. }
  1610. static void vi_update_hdp_light_sleep(struct amdgpu_device *adev,
  1611. bool enable)
  1612. {
  1613. uint32_t temp, data;
  1614. temp = data = RREG32(mmHDP_MEM_POWER_LS);
  1615. if (enable && (adev->cg_flags & AMD_CG_SUPPORT_HDP_LS))
  1616. data |= HDP_MEM_POWER_LS__LS_ENABLE_MASK;
  1617. else
  1618. data &= ~HDP_MEM_POWER_LS__LS_ENABLE_MASK;
  1619. if (temp != data)
  1620. WREG32(mmHDP_MEM_POWER_LS, data);
  1621. }
  1622. static void vi_update_rom_medium_grain_clock_gating(struct amdgpu_device *adev,
  1623. bool enable)
  1624. {
  1625. uint32_t temp, data;
  1626. temp = data = RREG32_SMC(ixCGTT_ROM_CLK_CTRL0);
  1627. if (enable && (adev->cg_flags & AMD_CG_SUPPORT_ROM_MGCG))
  1628. data &= ~(CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK |
  1629. CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE1_MASK);
  1630. else
  1631. data |= CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK |
  1632. CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE1_MASK;
  1633. if (temp != data)
  1634. WREG32_SMC(ixCGTT_ROM_CLK_CTRL0, data);
  1635. }
  1636. static int vi_common_set_clockgating_state(void *handle,
  1637. enum amd_clockgating_state state)
  1638. {
  1639. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  1640. switch (adev->asic_type) {
  1641. case CHIP_FIJI:
  1642. vi_update_bif_medium_grain_light_sleep(adev,
  1643. state == AMD_CG_STATE_GATE ? true : false);
  1644. vi_update_hdp_medium_grain_clock_gating(adev,
  1645. state == AMD_CG_STATE_GATE ? true : false);
  1646. vi_update_hdp_light_sleep(adev,
  1647. state == AMD_CG_STATE_GATE ? true : false);
  1648. vi_update_rom_medium_grain_clock_gating(adev,
  1649. state == AMD_CG_STATE_GATE ? true : false);
  1650. break;
  1651. case CHIP_CARRIZO:
  1652. case CHIP_STONEY:
  1653. vi_update_bif_medium_grain_light_sleep(adev,
  1654. state == AMD_CG_STATE_GATE ? true : false);
  1655. vi_update_hdp_medium_grain_clock_gating(adev,
  1656. state == AMD_CG_STATE_GATE ? true : false);
  1657. vi_update_hdp_light_sleep(adev,
  1658. state == AMD_CG_STATE_GATE ? true : false);
  1659. break;
  1660. default:
  1661. break;
  1662. }
  1663. return 0;
  1664. }
  1665. static int vi_common_set_powergating_state(void *handle,
  1666. enum amd_powergating_state state)
  1667. {
  1668. return 0;
  1669. }
  1670. const struct amd_ip_funcs vi_common_ip_funcs = {
  1671. .name = "vi_common",
  1672. .early_init = vi_common_early_init,
  1673. .late_init = NULL,
  1674. .sw_init = vi_common_sw_init,
  1675. .sw_fini = vi_common_sw_fini,
  1676. .hw_init = vi_common_hw_init,
  1677. .hw_fini = vi_common_hw_fini,
  1678. .suspend = vi_common_suspend,
  1679. .resume = vi_common_resume,
  1680. .is_idle = vi_common_is_idle,
  1681. .wait_for_idle = vi_common_wait_for_idle,
  1682. .soft_reset = vi_common_soft_reset,
  1683. .set_clockgating_state = vi_common_set_clockgating_state,
  1684. .set_powergating_state = vi_common_set_powergating_state,
  1685. };