soc15.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871
  1. /*
  2. * Copyright 2016 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 "amdgpu_psp.h"
  34. #include "atom.h"
  35. #include "amd_pcie.h"
  36. #include "vega10/soc15ip.h"
  37. #include "vega10/UVD/uvd_7_0_offset.h"
  38. #include "vega10/GC/gc_9_0_offset.h"
  39. #include "vega10/GC/gc_9_0_sh_mask.h"
  40. #include "vega10/SDMA0/sdma0_4_0_offset.h"
  41. #include "vega10/SDMA1/sdma1_4_0_offset.h"
  42. #include "vega10/HDP/hdp_4_0_offset.h"
  43. #include "vega10/HDP/hdp_4_0_sh_mask.h"
  44. #include "vega10/MP/mp_9_0_offset.h"
  45. #include "vega10/MP/mp_9_0_sh_mask.h"
  46. #include "vega10/SMUIO/smuio_9_0_offset.h"
  47. #include "vega10/SMUIO/smuio_9_0_sh_mask.h"
  48. #include "soc15.h"
  49. #include "soc15_common.h"
  50. #include "gfx_v9_0.h"
  51. #include "gmc_v9_0.h"
  52. #include "gfxhub_v1_0.h"
  53. #include "mmhub_v1_0.h"
  54. #include "vega10_ih.h"
  55. #include "sdma_v4_0.h"
  56. #include "uvd_v7_0.h"
  57. #include "vce_v4_0.h"
  58. #include "amdgpu_powerplay.h"
  59. #include "dce_virtual.h"
  60. #include "mxgpu_ai.h"
  61. MODULE_FIRMWARE("amdgpu/vega10_smc.bin");
  62. #define mmFabricConfigAccessControl 0x0410
  63. #define mmFabricConfigAccessControl_BASE_IDX 0
  64. #define mmFabricConfigAccessControl_DEFAULT 0x00000000
  65. //FabricConfigAccessControl
  66. #define FabricConfigAccessControl__CfgRegInstAccEn__SHIFT 0x0
  67. #define FabricConfigAccessControl__CfgRegInstAccRegLock__SHIFT 0x1
  68. #define FabricConfigAccessControl__CfgRegInstID__SHIFT 0x10
  69. #define FabricConfigAccessControl__CfgRegInstAccEn_MASK 0x00000001L
  70. #define FabricConfigAccessControl__CfgRegInstAccRegLock_MASK 0x00000002L
  71. #define FabricConfigAccessControl__CfgRegInstID_MASK 0x00FF0000L
  72. #define mmDF_PIE_AON0_DfGlobalClkGater 0x00fc
  73. #define mmDF_PIE_AON0_DfGlobalClkGater_BASE_IDX 0
  74. //DF_PIE_AON0_DfGlobalClkGater
  75. #define DF_PIE_AON0_DfGlobalClkGater__MGCGMode__SHIFT 0x0
  76. #define DF_PIE_AON0_DfGlobalClkGater__MGCGMode_MASK 0x0000000FL
  77. enum {
  78. DF_MGCG_DISABLE = 0,
  79. DF_MGCG_ENABLE_00_CYCLE_DELAY =1,
  80. DF_MGCG_ENABLE_01_CYCLE_DELAY =2,
  81. DF_MGCG_ENABLE_15_CYCLE_DELAY =13,
  82. DF_MGCG_ENABLE_31_CYCLE_DELAY =14,
  83. DF_MGCG_ENABLE_63_CYCLE_DELAY =15
  84. };
  85. #define mmMP0_MISC_CGTT_CTRL0 0x01b9
  86. #define mmMP0_MISC_CGTT_CTRL0_BASE_IDX 0
  87. #define mmMP0_MISC_LIGHT_SLEEP_CTRL 0x01ba
  88. #define mmMP0_MISC_LIGHT_SLEEP_CTRL_BASE_IDX 0
  89. /*
  90. * Indirect registers accessor
  91. */
  92. static u32 soc15_pcie_rreg(struct amdgpu_device *adev, u32 reg)
  93. {
  94. unsigned long flags, address, data;
  95. u32 r;
  96. struct nbio_pcie_index_data *nbio_pcie_id;
  97. if (adev->asic_type == CHIP_VEGA10)
  98. nbio_pcie_id = &nbio_v6_1_pcie_index_data;
  99. address = nbio_pcie_id->index_offset;
  100. data = nbio_pcie_id->data_offset;
  101. spin_lock_irqsave(&adev->pcie_idx_lock, flags);
  102. WREG32(address, reg);
  103. (void)RREG32(address);
  104. r = RREG32(data);
  105. spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
  106. return r;
  107. }
  108. static void soc15_pcie_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
  109. {
  110. unsigned long flags, address, data;
  111. struct nbio_pcie_index_data *nbio_pcie_id;
  112. if (adev->asic_type == CHIP_VEGA10)
  113. nbio_pcie_id = &nbio_v6_1_pcie_index_data;
  114. address = nbio_pcie_id->index_offset;
  115. data = nbio_pcie_id->data_offset;
  116. spin_lock_irqsave(&adev->pcie_idx_lock, flags);
  117. WREG32(address, reg);
  118. (void)RREG32(address);
  119. WREG32(data, v);
  120. (void)RREG32(data);
  121. spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
  122. }
  123. static u32 soc15_uvd_ctx_rreg(struct amdgpu_device *adev, u32 reg)
  124. {
  125. unsigned long flags, address, data;
  126. u32 r;
  127. address = SOC15_REG_OFFSET(UVD, 0, mmUVD_CTX_INDEX);
  128. data = SOC15_REG_OFFSET(UVD, 0, mmUVD_CTX_DATA);
  129. spin_lock_irqsave(&adev->uvd_ctx_idx_lock, flags);
  130. WREG32(address, ((reg) & 0x1ff));
  131. r = RREG32(data);
  132. spin_unlock_irqrestore(&adev->uvd_ctx_idx_lock, flags);
  133. return r;
  134. }
  135. static void soc15_uvd_ctx_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
  136. {
  137. unsigned long flags, address, data;
  138. address = SOC15_REG_OFFSET(UVD, 0, mmUVD_CTX_INDEX);
  139. data = SOC15_REG_OFFSET(UVD, 0, mmUVD_CTX_DATA);
  140. spin_lock_irqsave(&adev->uvd_ctx_idx_lock, flags);
  141. WREG32(address, ((reg) & 0x1ff));
  142. WREG32(data, (v));
  143. spin_unlock_irqrestore(&adev->uvd_ctx_idx_lock, flags);
  144. }
  145. static u32 soc15_didt_rreg(struct amdgpu_device *adev, u32 reg)
  146. {
  147. unsigned long flags, address, data;
  148. u32 r;
  149. address = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_INDEX);
  150. data = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_DATA);
  151. spin_lock_irqsave(&adev->didt_idx_lock, flags);
  152. WREG32(address, (reg));
  153. r = RREG32(data);
  154. spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
  155. return r;
  156. }
  157. static void soc15_didt_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
  158. {
  159. unsigned long flags, address, data;
  160. address = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_INDEX);
  161. data = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_DATA);
  162. spin_lock_irqsave(&adev->didt_idx_lock, flags);
  163. WREG32(address, (reg));
  164. WREG32(data, (v));
  165. spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
  166. }
  167. static u32 soc15_get_config_memsize(struct amdgpu_device *adev)
  168. {
  169. return nbio_v6_1_get_memsize(adev);
  170. }
  171. static const u32 vega10_golden_init[] =
  172. {
  173. };
  174. static void soc15_init_golden_registers(struct amdgpu_device *adev)
  175. {
  176. /* Some of the registers might be dependent on GRBM_GFX_INDEX */
  177. mutex_lock(&adev->grbm_idx_mutex);
  178. switch (adev->asic_type) {
  179. case CHIP_VEGA10:
  180. amdgpu_program_register_sequence(adev,
  181. vega10_golden_init,
  182. (const u32)ARRAY_SIZE(vega10_golden_init));
  183. break;
  184. default:
  185. break;
  186. }
  187. mutex_unlock(&adev->grbm_idx_mutex);
  188. }
  189. static u32 soc15_get_xclk(struct amdgpu_device *adev)
  190. {
  191. if (adev->asic_type == CHIP_VEGA10)
  192. return adev->clock.spll.reference_freq/4;
  193. else
  194. return adev->clock.spll.reference_freq;
  195. }
  196. void soc15_grbm_select(struct amdgpu_device *adev,
  197. u32 me, u32 pipe, u32 queue, u32 vmid)
  198. {
  199. u32 grbm_gfx_cntl = 0;
  200. grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, PIPEID, pipe);
  201. grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, MEID, me);
  202. grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, VMID, vmid);
  203. grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, QUEUEID, queue);
  204. WREG32(SOC15_REG_OFFSET(GC, 0, mmGRBM_GFX_CNTL), grbm_gfx_cntl);
  205. }
  206. static void soc15_vga_set_state(struct amdgpu_device *adev, bool state)
  207. {
  208. /* todo */
  209. }
  210. static bool soc15_read_disabled_bios(struct amdgpu_device *adev)
  211. {
  212. /* todo */
  213. return false;
  214. }
  215. static bool soc15_read_bios_from_rom(struct amdgpu_device *adev,
  216. u8 *bios, u32 length_bytes)
  217. {
  218. u32 *dw_ptr;
  219. u32 i, length_dw;
  220. if (bios == NULL)
  221. return false;
  222. if (length_bytes == 0)
  223. return false;
  224. /* APU vbios image is part of sbios image */
  225. if (adev->flags & AMD_IS_APU)
  226. return false;
  227. dw_ptr = (u32 *)bios;
  228. length_dw = ALIGN(length_bytes, 4) / 4;
  229. /* set rom index to 0 */
  230. WREG32(SOC15_REG_OFFSET(SMUIO, 0, mmROM_INDEX), 0);
  231. /* read out the rom data */
  232. for (i = 0; i < length_dw; i++)
  233. dw_ptr[i] = RREG32(SOC15_REG_OFFSET(SMUIO, 0, mmROM_DATA));
  234. return true;
  235. }
  236. static struct amdgpu_allowed_register_entry vega10_allowed_read_registers[] = {
  237. /* todo */
  238. };
  239. static struct amdgpu_allowed_register_entry soc15_allowed_read_registers[] = {
  240. { SOC15_REG_OFFSET(GC, 0, mmGRBM_STATUS), false},
  241. { SOC15_REG_OFFSET(GC, 0, mmGRBM_STATUS2), false},
  242. { SOC15_REG_OFFSET(GC, 0, mmGRBM_STATUS_SE0), false},
  243. { SOC15_REG_OFFSET(GC, 0, mmGRBM_STATUS_SE1), false},
  244. { SOC15_REG_OFFSET(GC, 0, mmGRBM_STATUS_SE2), false},
  245. { SOC15_REG_OFFSET(GC, 0, mmGRBM_STATUS_SE3), false},
  246. { SOC15_REG_OFFSET(SDMA0, 0, mmSDMA0_STATUS_REG), false},
  247. { SOC15_REG_OFFSET(SDMA1, 0, mmSDMA1_STATUS_REG), false},
  248. { SOC15_REG_OFFSET(GC, 0, mmCP_STAT), false},
  249. { SOC15_REG_OFFSET(GC, 0, mmCP_STALLED_STAT1), false},
  250. { SOC15_REG_OFFSET(GC, 0, mmCP_STALLED_STAT2), false},
  251. { SOC15_REG_OFFSET(GC, 0, mmCP_STALLED_STAT3), false},
  252. { SOC15_REG_OFFSET(GC, 0, mmCP_CPF_BUSY_STAT), false},
  253. { SOC15_REG_OFFSET(GC, 0, mmCP_CPF_STALLED_STAT1), false},
  254. { SOC15_REG_OFFSET(GC, 0, mmCP_CPF_STATUS), false},
  255. { SOC15_REG_OFFSET(GC, 0, mmCP_CPC_STALLED_STAT1), false},
  256. { SOC15_REG_OFFSET(GC, 0, mmCP_CPC_STATUS), false},
  257. { SOC15_REG_OFFSET(GC, 0, mmGB_ADDR_CONFIG), false},
  258. };
  259. static uint32_t soc15_read_indexed_register(struct amdgpu_device *adev, u32 se_num,
  260. u32 sh_num, u32 reg_offset)
  261. {
  262. uint32_t val;
  263. mutex_lock(&adev->grbm_idx_mutex);
  264. if (se_num != 0xffffffff || sh_num != 0xffffffff)
  265. amdgpu_gfx_select_se_sh(adev, se_num, sh_num, 0xffffffff);
  266. val = RREG32(reg_offset);
  267. if (se_num != 0xffffffff || sh_num != 0xffffffff)
  268. amdgpu_gfx_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
  269. mutex_unlock(&adev->grbm_idx_mutex);
  270. return val;
  271. }
  272. static uint32_t soc15_get_register_value(struct amdgpu_device *adev,
  273. bool indexed, u32 se_num,
  274. u32 sh_num, u32 reg_offset)
  275. {
  276. if (indexed) {
  277. return soc15_read_indexed_register(adev, se_num, sh_num, reg_offset);
  278. } else {
  279. switch (reg_offset) {
  280. case SOC15_REG_OFFSET(GC, 0, mmGB_ADDR_CONFIG):
  281. return adev->gfx.config.gb_addr_config;
  282. default:
  283. return RREG32(reg_offset);
  284. }
  285. }
  286. }
  287. static int soc15_read_register(struct amdgpu_device *adev, u32 se_num,
  288. u32 sh_num, u32 reg_offset, u32 *value)
  289. {
  290. struct amdgpu_allowed_register_entry *asic_register_table = NULL;
  291. struct amdgpu_allowed_register_entry *asic_register_entry;
  292. uint32_t size, i;
  293. *value = 0;
  294. switch (adev->asic_type) {
  295. case CHIP_VEGA10:
  296. asic_register_table = vega10_allowed_read_registers;
  297. size = ARRAY_SIZE(vega10_allowed_read_registers);
  298. break;
  299. default:
  300. return -EINVAL;
  301. }
  302. if (asic_register_table) {
  303. for (i = 0; i < size; i++) {
  304. asic_register_entry = asic_register_table + i;
  305. if (reg_offset != asic_register_entry->reg_offset)
  306. continue;
  307. if (!asic_register_entry->untouched)
  308. *value = soc15_get_register_value(adev,
  309. asic_register_entry->grbm_indexed,
  310. se_num, sh_num, reg_offset);
  311. return 0;
  312. }
  313. }
  314. for (i = 0; i < ARRAY_SIZE(soc15_allowed_read_registers); i++) {
  315. if (reg_offset != soc15_allowed_read_registers[i].reg_offset)
  316. continue;
  317. if (!soc15_allowed_read_registers[i].untouched)
  318. *value = soc15_get_register_value(adev,
  319. soc15_allowed_read_registers[i].grbm_indexed,
  320. se_num, sh_num, reg_offset);
  321. return 0;
  322. }
  323. return -EINVAL;
  324. }
  325. static void soc15_gpu_pci_config_reset(struct amdgpu_device *adev)
  326. {
  327. u32 i;
  328. dev_info(adev->dev, "GPU pci config reset\n");
  329. /* disable BM */
  330. pci_clear_master(adev->pdev);
  331. /* reset */
  332. amdgpu_pci_config_reset(adev);
  333. udelay(100);
  334. /* wait for asic to come out of reset */
  335. for (i = 0; i < adev->usec_timeout; i++) {
  336. if (nbio_v6_1_get_memsize(adev) != 0xffffffff)
  337. break;
  338. udelay(1);
  339. }
  340. }
  341. static int soc15_asic_reset(struct amdgpu_device *adev)
  342. {
  343. amdgpu_atombios_scratch_regs_engine_hung(adev, true);
  344. soc15_gpu_pci_config_reset(adev);
  345. amdgpu_atombios_scratch_regs_engine_hung(adev, false);
  346. return 0;
  347. }
  348. /*static int soc15_set_uvd_clock(struct amdgpu_device *adev, u32 clock,
  349. u32 cntl_reg, u32 status_reg)
  350. {
  351. return 0;
  352. }*/
  353. static int soc15_set_uvd_clocks(struct amdgpu_device *adev, u32 vclk, u32 dclk)
  354. {
  355. /*int r;
  356. r = soc15_set_uvd_clock(adev, vclk, ixCG_VCLK_CNTL, ixCG_VCLK_STATUS);
  357. if (r)
  358. return r;
  359. r = soc15_set_uvd_clock(adev, dclk, ixCG_DCLK_CNTL, ixCG_DCLK_STATUS);
  360. */
  361. return 0;
  362. }
  363. static int soc15_set_vce_clocks(struct amdgpu_device *adev, u32 evclk, u32 ecclk)
  364. {
  365. /* todo */
  366. return 0;
  367. }
  368. static void soc15_pcie_gen3_enable(struct amdgpu_device *adev)
  369. {
  370. if (pci_is_root_bus(adev->pdev->bus))
  371. return;
  372. if (amdgpu_pcie_gen2 == 0)
  373. return;
  374. if (adev->flags & AMD_IS_APU)
  375. return;
  376. if (!(adev->pm.pcie_gen_mask & (CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2 |
  377. CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3)))
  378. return;
  379. /* todo */
  380. }
  381. static void soc15_program_aspm(struct amdgpu_device *adev)
  382. {
  383. if (amdgpu_aspm == 0)
  384. return;
  385. /* todo */
  386. }
  387. static void soc15_enable_doorbell_aperture(struct amdgpu_device *adev,
  388. bool enable)
  389. {
  390. nbio_v6_1_enable_doorbell_aperture(adev, enable);
  391. nbio_v6_1_enable_doorbell_selfring_aperture(adev, enable);
  392. }
  393. static const struct amdgpu_ip_block_version vega10_common_ip_block =
  394. {
  395. .type = AMD_IP_BLOCK_TYPE_COMMON,
  396. .major = 2,
  397. .minor = 0,
  398. .rev = 0,
  399. .funcs = &soc15_common_ip_funcs,
  400. };
  401. int soc15_set_ip_blocks(struct amdgpu_device *adev)
  402. {
  403. nbio_v6_1_detect_hw_virt(adev);
  404. if (amdgpu_sriov_vf(adev))
  405. adev->virt.ops = &xgpu_ai_virt_ops;
  406. switch (adev->asic_type) {
  407. case CHIP_VEGA10:
  408. amdgpu_ip_block_add(adev, &vega10_common_ip_block);
  409. amdgpu_ip_block_add(adev, &gfxhub_v1_0_ip_block);
  410. amdgpu_ip_block_add(adev, &mmhub_v1_0_ip_block);
  411. amdgpu_ip_block_add(adev, &gmc_v9_0_ip_block);
  412. amdgpu_ip_block_add(adev, &vega10_ih_ip_block);
  413. amdgpu_ip_block_add(adev, &psp_v3_1_ip_block);
  414. if (!amdgpu_sriov_vf(adev))
  415. amdgpu_ip_block_add(adev, &amdgpu_pp_ip_block);
  416. if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
  417. amdgpu_ip_block_add(adev, &dce_virtual_ip_block);
  418. amdgpu_ip_block_add(adev, &gfx_v9_0_ip_block);
  419. amdgpu_ip_block_add(adev, &sdma_v4_0_ip_block);
  420. if (!amdgpu_sriov_vf(adev))
  421. amdgpu_ip_block_add(adev, &uvd_v7_0_ip_block);
  422. amdgpu_ip_block_add(adev, &vce_v4_0_ip_block);
  423. break;
  424. default:
  425. return -EINVAL;
  426. }
  427. return 0;
  428. }
  429. static uint32_t soc15_get_rev_id(struct amdgpu_device *adev)
  430. {
  431. return nbio_v6_1_get_rev_id(adev);
  432. }
  433. int gmc_v9_0_mc_wait_for_idle(struct amdgpu_device *adev)
  434. {
  435. /* to be implemented in MC IP*/
  436. return 0;
  437. }
  438. static const struct amdgpu_asic_funcs soc15_asic_funcs =
  439. {
  440. .read_disabled_bios = &soc15_read_disabled_bios,
  441. .read_bios_from_rom = &soc15_read_bios_from_rom,
  442. .read_register = &soc15_read_register,
  443. .reset = &soc15_asic_reset,
  444. .set_vga_state = &soc15_vga_set_state,
  445. .get_xclk = &soc15_get_xclk,
  446. .set_uvd_clocks = &soc15_set_uvd_clocks,
  447. .set_vce_clocks = &soc15_set_vce_clocks,
  448. .get_config_memsize = &soc15_get_config_memsize,
  449. };
  450. static int soc15_common_early_init(void *handle)
  451. {
  452. bool psp_enabled = false;
  453. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  454. adev->smc_rreg = NULL;
  455. adev->smc_wreg = NULL;
  456. adev->pcie_rreg = &soc15_pcie_rreg;
  457. adev->pcie_wreg = &soc15_pcie_wreg;
  458. adev->uvd_ctx_rreg = &soc15_uvd_ctx_rreg;
  459. adev->uvd_ctx_wreg = &soc15_uvd_ctx_wreg;
  460. adev->didt_rreg = &soc15_didt_rreg;
  461. adev->didt_wreg = &soc15_didt_wreg;
  462. adev->asic_funcs = &soc15_asic_funcs;
  463. if (amdgpu_get_ip_block(adev, AMD_IP_BLOCK_TYPE_PSP) &&
  464. (amdgpu_ip_block_mask & (1 << AMD_IP_BLOCK_TYPE_PSP)))
  465. psp_enabled = true;
  466. if (amdgpu_sriov_vf(adev)) {
  467. amdgpu_virt_init_setting(adev);
  468. }
  469. /*
  470. * nbio need be used for both sdma and gfx9, but only
  471. * initializes once
  472. */
  473. switch(adev->asic_type) {
  474. case CHIP_VEGA10:
  475. nbio_v6_1_init(adev);
  476. break;
  477. default:
  478. return -EINVAL;
  479. }
  480. adev->rev_id = soc15_get_rev_id(adev);
  481. adev->external_rev_id = 0xFF;
  482. switch (adev->asic_type) {
  483. case CHIP_VEGA10:
  484. adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
  485. AMD_CG_SUPPORT_GFX_MGLS |
  486. AMD_CG_SUPPORT_GFX_RLC_LS |
  487. AMD_CG_SUPPORT_GFX_CP_LS |
  488. AMD_CG_SUPPORT_GFX_3D_CGCG |
  489. AMD_CG_SUPPORT_GFX_3D_CGLS |
  490. AMD_CG_SUPPORT_GFX_CGCG |
  491. AMD_CG_SUPPORT_GFX_CGLS |
  492. AMD_CG_SUPPORT_BIF_MGCG |
  493. AMD_CG_SUPPORT_BIF_LS |
  494. AMD_CG_SUPPORT_HDP_LS |
  495. AMD_CG_SUPPORT_DRM_MGCG |
  496. AMD_CG_SUPPORT_DRM_LS |
  497. AMD_CG_SUPPORT_ROM_MGCG |
  498. AMD_CG_SUPPORT_DF_MGCG |
  499. AMD_CG_SUPPORT_SDMA_MGCG |
  500. AMD_CG_SUPPORT_SDMA_LS |
  501. AMD_CG_SUPPORT_MC_MGCG |
  502. AMD_CG_SUPPORT_MC_LS;
  503. adev->pg_flags = 0;
  504. adev->external_rev_id = 0x1;
  505. break;
  506. default:
  507. /* FIXME: not supported yet */
  508. return -EINVAL;
  509. }
  510. adev->firmware.load_type = amdgpu_ucode_get_load_type(adev, amdgpu_fw_load_type);
  511. amdgpu_get_pcie_info(adev);
  512. return 0;
  513. }
  514. static int soc15_common_sw_init(void *handle)
  515. {
  516. return 0;
  517. }
  518. static int soc15_common_sw_fini(void *handle)
  519. {
  520. return 0;
  521. }
  522. static int soc15_common_hw_init(void *handle)
  523. {
  524. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  525. /* move the golden regs per IP block */
  526. soc15_init_golden_registers(adev);
  527. /* enable pcie gen2/3 link */
  528. soc15_pcie_gen3_enable(adev);
  529. /* enable aspm */
  530. soc15_program_aspm(adev);
  531. /* enable the doorbell aperture */
  532. soc15_enable_doorbell_aperture(adev, true);
  533. return 0;
  534. }
  535. static int soc15_common_hw_fini(void *handle)
  536. {
  537. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  538. /* disable the doorbell aperture */
  539. soc15_enable_doorbell_aperture(adev, false);
  540. return 0;
  541. }
  542. static int soc15_common_suspend(void *handle)
  543. {
  544. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  545. return soc15_common_hw_fini(adev);
  546. }
  547. static int soc15_common_resume(void *handle)
  548. {
  549. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  550. return soc15_common_hw_init(adev);
  551. }
  552. static bool soc15_common_is_idle(void *handle)
  553. {
  554. return true;
  555. }
  556. static int soc15_common_wait_for_idle(void *handle)
  557. {
  558. return 0;
  559. }
  560. static int soc15_common_soft_reset(void *handle)
  561. {
  562. return 0;
  563. }
  564. static void soc15_update_hdp_light_sleep(struct amdgpu_device *adev, bool enable)
  565. {
  566. uint32_t def, data;
  567. def = data = RREG32(SOC15_REG_OFFSET(HDP, 0, mmHDP_MEM_POWER_LS));
  568. if (enable && (adev->cg_flags & AMD_CG_SUPPORT_HDP_LS))
  569. data |= HDP_MEM_POWER_LS__LS_ENABLE_MASK;
  570. else
  571. data &= ~HDP_MEM_POWER_LS__LS_ENABLE_MASK;
  572. if (def != data)
  573. WREG32(SOC15_REG_OFFSET(HDP, 0, mmHDP_MEM_POWER_LS), data);
  574. }
  575. static void soc15_update_drm_clock_gating(struct amdgpu_device *adev, bool enable)
  576. {
  577. uint32_t def, data;
  578. def = data = RREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_CGTT_CTRL0));
  579. if (enable && (adev->cg_flags & AMD_CG_SUPPORT_DRM_MGCG))
  580. data &= ~(0x01000000 |
  581. 0x02000000 |
  582. 0x04000000 |
  583. 0x08000000 |
  584. 0x10000000 |
  585. 0x20000000 |
  586. 0x40000000 |
  587. 0x80000000);
  588. else
  589. data |= (0x01000000 |
  590. 0x02000000 |
  591. 0x04000000 |
  592. 0x08000000 |
  593. 0x10000000 |
  594. 0x20000000 |
  595. 0x40000000 |
  596. 0x80000000);
  597. if (def != data)
  598. WREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_CGTT_CTRL0), data);
  599. }
  600. static void soc15_update_drm_light_sleep(struct amdgpu_device *adev, bool enable)
  601. {
  602. uint32_t def, data;
  603. def = data = RREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_LIGHT_SLEEP_CTRL));
  604. if (enable && (adev->cg_flags & AMD_CG_SUPPORT_DRM_LS))
  605. data |= 1;
  606. else
  607. data &= ~1;
  608. if (def != data)
  609. WREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_LIGHT_SLEEP_CTRL), data);
  610. }
  611. static void soc15_update_rom_medium_grain_clock_gating(struct amdgpu_device *adev,
  612. bool enable)
  613. {
  614. uint32_t def, data;
  615. def = data = RREG32(SOC15_REG_OFFSET(SMUIO, 0, mmCGTT_ROM_CLK_CTRL0));
  616. if (enable && (adev->cg_flags & AMD_CG_SUPPORT_ROM_MGCG))
  617. data &= ~(CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK |
  618. CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE1_MASK);
  619. else
  620. data |= CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK |
  621. CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE1_MASK;
  622. if (def != data)
  623. WREG32(SOC15_REG_OFFSET(SMUIO, 0, mmCGTT_ROM_CLK_CTRL0), data);
  624. }
  625. static void soc15_update_df_medium_grain_clock_gating(struct amdgpu_device *adev,
  626. bool enable)
  627. {
  628. uint32_t data;
  629. /* Put DF on broadcast mode */
  630. data = RREG32(SOC15_REG_OFFSET(DF, 0, mmFabricConfigAccessControl));
  631. data &= ~FabricConfigAccessControl__CfgRegInstAccEn_MASK;
  632. WREG32(SOC15_REG_OFFSET(DF, 0, mmFabricConfigAccessControl), data);
  633. if (enable && (adev->cg_flags & AMD_CG_SUPPORT_DF_MGCG)) {
  634. data = RREG32(SOC15_REG_OFFSET(DF, 0, mmDF_PIE_AON0_DfGlobalClkGater));
  635. data &= ~DF_PIE_AON0_DfGlobalClkGater__MGCGMode_MASK;
  636. data |= DF_MGCG_ENABLE_15_CYCLE_DELAY;
  637. WREG32(SOC15_REG_OFFSET(DF, 0, mmDF_PIE_AON0_DfGlobalClkGater), data);
  638. } else {
  639. data = RREG32(SOC15_REG_OFFSET(DF, 0, mmDF_PIE_AON0_DfGlobalClkGater));
  640. data &= ~DF_PIE_AON0_DfGlobalClkGater__MGCGMode_MASK;
  641. data |= DF_MGCG_DISABLE;
  642. WREG32(SOC15_REG_OFFSET(DF, 0, mmDF_PIE_AON0_DfGlobalClkGater), data);
  643. }
  644. WREG32(SOC15_REG_OFFSET(DF, 0, mmFabricConfigAccessControl),
  645. mmFabricConfigAccessControl_DEFAULT);
  646. }
  647. static int soc15_common_set_clockgating_state(void *handle,
  648. enum amd_clockgating_state state)
  649. {
  650. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  651. if (amdgpu_sriov_vf(adev))
  652. return 0;
  653. switch (adev->asic_type) {
  654. case CHIP_VEGA10:
  655. nbio_v6_1_update_medium_grain_clock_gating(adev,
  656. state == AMD_CG_STATE_GATE ? true : false);
  657. nbio_v6_1_update_medium_grain_light_sleep(adev,
  658. state == AMD_CG_STATE_GATE ? true : false);
  659. soc15_update_hdp_light_sleep(adev,
  660. state == AMD_CG_STATE_GATE ? true : false);
  661. soc15_update_drm_clock_gating(adev,
  662. state == AMD_CG_STATE_GATE ? true : false);
  663. soc15_update_drm_light_sleep(adev,
  664. state == AMD_CG_STATE_GATE ? true : false);
  665. soc15_update_rom_medium_grain_clock_gating(adev,
  666. state == AMD_CG_STATE_GATE ? true : false);
  667. soc15_update_df_medium_grain_clock_gating(adev,
  668. state == AMD_CG_STATE_GATE ? true : false);
  669. break;
  670. default:
  671. break;
  672. }
  673. return 0;
  674. }
  675. static void soc15_common_get_clockgating_state(void *handle, u32 *flags)
  676. {
  677. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  678. int data;
  679. if (amdgpu_sriov_vf(adev))
  680. *flags = 0;
  681. nbio_v6_1_get_clockgating_state(adev, flags);
  682. /* AMD_CG_SUPPORT_HDP_LS */
  683. data = RREG32(SOC15_REG_OFFSET(HDP, 0, mmHDP_MEM_POWER_LS));
  684. if (data & HDP_MEM_POWER_LS__LS_ENABLE_MASK)
  685. *flags |= AMD_CG_SUPPORT_HDP_LS;
  686. /* AMD_CG_SUPPORT_DRM_MGCG */
  687. data = RREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_CGTT_CTRL0));
  688. if (!(data & 0x01000000))
  689. *flags |= AMD_CG_SUPPORT_DRM_MGCG;
  690. /* AMD_CG_SUPPORT_DRM_LS */
  691. data = RREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_LIGHT_SLEEP_CTRL));
  692. if (data & 0x1)
  693. *flags |= AMD_CG_SUPPORT_DRM_LS;
  694. /* AMD_CG_SUPPORT_ROM_MGCG */
  695. data = RREG32(SOC15_REG_OFFSET(SMUIO, 0, mmCGTT_ROM_CLK_CTRL0));
  696. if (!(data & CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK))
  697. *flags |= AMD_CG_SUPPORT_ROM_MGCG;
  698. /* AMD_CG_SUPPORT_DF_MGCG */
  699. data = RREG32(SOC15_REG_OFFSET(DF, 0, mmDF_PIE_AON0_DfGlobalClkGater));
  700. if (data & DF_MGCG_ENABLE_15_CYCLE_DELAY)
  701. *flags |= AMD_CG_SUPPORT_DF_MGCG;
  702. }
  703. static int soc15_common_set_powergating_state(void *handle,
  704. enum amd_powergating_state state)
  705. {
  706. /* todo */
  707. return 0;
  708. }
  709. const struct amd_ip_funcs soc15_common_ip_funcs = {
  710. .name = "soc15_common",
  711. .early_init = soc15_common_early_init,
  712. .late_init = NULL,
  713. .sw_init = soc15_common_sw_init,
  714. .sw_fini = soc15_common_sw_fini,
  715. .hw_init = soc15_common_hw_init,
  716. .hw_fini = soc15_common_hw_fini,
  717. .suspend = soc15_common_suspend,
  718. .resume = soc15_common_resume,
  719. .is_idle = soc15_common_is_idle,
  720. .wait_for_idle = soc15_common_wait_for_idle,
  721. .soft_reset = soc15_common_soft_reset,
  722. .set_clockgating_state = soc15_common_set_clockgating_state,
  723. .set_powergating_state = soc15_common_set_powergating_state,
  724. .get_clockgating_state= soc15_common_get_clockgating_state,
  725. };