soc15.c 25 KB

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