mmhub_v1_0.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  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 "amdgpu.h"
  24. #include "mmhub_v1_0.h"
  25. #include "vega10/soc15ip.h"
  26. #include "vega10/MMHUB/mmhub_1_0_offset.h"
  27. #include "vega10/MMHUB/mmhub_1_0_sh_mask.h"
  28. #include "vega10/MMHUB/mmhub_1_0_default.h"
  29. #include "vega10/ATHUB/athub_1_0_offset.h"
  30. #include "vega10/ATHUB/athub_1_0_sh_mask.h"
  31. #include "vega10/ATHUB/athub_1_0_default.h"
  32. #include "vega10/vega10_enum.h"
  33. #include "soc15_common.h"
  34. #define mmDAGB0_CNTL_MISC2_RV 0x008f
  35. #define mmDAGB0_CNTL_MISC2_RV_BASE_IDX 0
  36. u64 mmhub_v1_0_get_fb_location(struct amdgpu_device *adev)
  37. {
  38. u64 base = RREG32_SOC15(MMHUB, 0, mmMC_VM_FB_LOCATION_BASE);
  39. base &= MC_VM_FB_LOCATION_BASE__FB_BASE_MASK;
  40. base <<= 24;
  41. return base;
  42. }
  43. static void mmhub_v1_0_init_gart_pt_regs(struct amdgpu_device *adev)
  44. {
  45. uint64_t value;
  46. BUG_ON(adev->gart.table_addr & (~0x0000FFFFFFFFF000ULL));
  47. value = adev->gart.table_addr - adev->mc.vram_start +
  48. adev->vm_manager.vram_base_offset;
  49. value &= 0x0000FFFFFFFFF000ULL;
  50. value |= 0x1; /* valid bit */
  51. WREG32_SOC15(MMHUB, 0, mmVM_CONTEXT0_PAGE_TABLE_BASE_ADDR_LO32,
  52. lower_32_bits(value));
  53. WREG32_SOC15(MMHUB, 0, mmVM_CONTEXT0_PAGE_TABLE_BASE_ADDR_HI32,
  54. upper_32_bits(value));
  55. }
  56. static void mmhub_v1_0_init_gart_aperture_regs(struct amdgpu_device *adev)
  57. {
  58. mmhub_v1_0_init_gart_pt_regs(adev);
  59. WREG32_SOC15(MMHUB, 0, mmVM_CONTEXT0_PAGE_TABLE_START_ADDR_LO32,
  60. (u32)(adev->mc.gart_start >> 12));
  61. WREG32_SOC15(MMHUB, 0, mmVM_CONTEXT0_PAGE_TABLE_START_ADDR_HI32,
  62. (u32)(adev->mc.gart_start >> 44));
  63. WREG32_SOC15(MMHUB, 0, mmVM_CONTEXT0_PAGE_TABLE_END_ADDR_LO32,
  64. (u32)(adev->mc.gart_end >> 12));
  65. WREG32_SOC15(MMHUB, 0, mmVM_CONTEXT0_PAGE_TABLE_END_ADDR_HI32,
  66. (u32)(adev->mc.gart_end >> 44));
  67. }
  68. static void mmhub_v1_0_init_system_aperture_regs(struct amdgpu_device *adev)
  69. {
  70. uint64_t value;
  71. uint32_t tmp;
  72. /* Disable AGP. */
  73. WREG32_SOC15(MMHUB, 0, mmMC_VM_AGP_BASE, 0);
  74. WREG32_SOC15(MMHUB, 0, mmMC_VM_AGP_TOP, 0);
  75. WREG32_SOC15(MMHUB, 0, mmMC_VM_AGP_BOT, 0x00FFFFFF);
  76. /* Program the system aperture low logical page number. */
  77. WREG32_SOC15(MMHUB, 0, mmMC_VM_SYSTEM_APERTURE_LOW_ADDR,
  78. adev->mc.vram_start >> 18);
  79. WREG32_SOC15(MMHUB, 0, mmMC_VM_SYSTEM_APERTURE_HIGH_ADDR,
  80. adev->mc.vram_end >> 18);
  81. /* Set default page address. */
  82. value = adev->vram_scratch.gpu_addr - adev->mc.vram_start +
  83. adev->vm_manager.vram_base_offset;
  84. WREG32_SOC15(MMHUB, 0, mmMC_VM_SYSTEM_APERTURE_DEFAULT_ADDR_LSB,
  85. (u32)(value >> 12));
  86. WREG32_SOC15(MMHUB, 0, mmMC_VM_SYSTEM_APERTURE_DEFAULT_ADDR_MSB,
  87. (u32)(value >> 44));
  88. /* Program "protection fault". */
  89. WREG32_SOC15(MMHUB, 0, mmVM_L2_PROTECTION_FAULT_DEFAULT_ADDR_LO32,
  90. (u32)(adev->dummy_page.addr >> 12));
  91. WREG32_SOC15(MMHUB, 0, mmVM_L2_PROTECTION_FAULT_DEFAULT_ADDR_HI32,
  92. (u32)((u64)adev->dummy_page.addr >> 44));
  93. tmp = RREG32_SOC15(MMHUB, 0, mmVM_L2_PROTECTION_FAULT_CNTL2);
  94. tmp = REG_SET_FIELD(tmp, VM_L2_PROTECTION_FAULT_CNTL2,
  95. ACTIVE_PAGE_MIGRATION_PTE_READ_RETRY, 1);
  96. WREG32_SOC15(MMHUB, 0, mmVM_L2_PROTECTION_FAULT_CNTL2, tmp);
  97. }
  98. static void mmhub_v1_0_init_tlb_regs(struct amdgpu_device *adev)
  99. {
  100. uint32_t tmp;
  101. /* Setup TLB control */
  102. tmp = RREG32_SOC15(MMHUB, 0, mmMC_VM_MX_L1_TLB_CNTL);
  103. tmp = REG_SET_FIELD(tmp, MC_VM_MX_L1_TLB_CNTL, ENABLE_L1_TLB, 1);
  104. tmp = REG_SET_FIELD(tmp, MC_VM_MX_L1_TLB_CNTL, SYSTEM_ACCESS_MODE, 3);
  105. tmp = REG_SET_FIELD(tmp, MC_VM_MX_L1_TLB_CNTL,
  106. ENABLE_ADVANCED_DRIVER_MODEL, 1);
  107. tmp = REG_SET_FIELD(tmp, MC_VM_MX_L1_TLB_CNTL,
  108. SYSTEM_APERTURE_UNMAPPED_ACCESS, 0);
  109. tmp = REG_SET_FIELD(tmp, MC_VM_MX_L1_TLB_CNTL, ECO_BITS, 0);
  110. tmp = REG_SET_FIELD(tmp, MC_VM_MX_L1_TLB_CNTL,
  111. MTYPE, MTYPE_UC);/* XXX for emulation. */
  112. tmp = REG_SET_FIELD(tmp, MC_VM_MX_L1_TLB_CNTL, ATC_EN, 1);
  113. WREG32_SOC15(MMHUB, 0, mmMC_VM_MX_L1_TLB_CNTL, tmp);
  114. }
  115. static void mmhub_v1_0_init_cache_regs(struct amdgpu_device *adev)
  116. {
  117. uint32_t tmp;
  118. /* Setup L2 cache */
  119. tmp = RREG32_SOC15(MMHUB, 0, mmVM_L2_CNTL);
  120. tmp = REG_SET_FIELD(tmp, VM_L2_CNTL, ENABLE_L2_CACHE, 1);
  121. tmp = REG_SET_FIELD(tmp, VM_L2_CNTL, ENABLE_L2_FRAGMENT_PROCESSING, 1);
  122. /* XXX for emulation, Refer to closed source code.*/
  123. tmp = REG_SET_FIELD(tmp, VM_L2_CNTL, L2_PDE0_CACHE_TAG_GENERATION_MODE,
  124. 0);
  125. tmp = REG_SET_FIELD(tmp, VM_L2_CNTL, PDE_FAULT_CLASSIFICATION, 1);
  126. tmp = REG_SET_FIELD(tmp, VM_L2_CNTL, CONTEXT1_IDENTITY_ACCESS_MODE, 1);
  127. tmp = REG_SET_FIELD(tmp, VM_L2_CNTL, IDENTITY_MODE_FRAGMENT_SIZE, 0);
  128. WREG32_SOC15(MMHUB, 0, mmVM_L2_CNTL, tmp);
  129. tmp = RREG32_SOC15(MMHUB, 0, mmVM_L2_CNTL2);
  130. tmp = REG_SET_FIELD(tmp, VM_L2_CNTL2, INVALIDATE_ALL_L1_TLBS, 1);
  131. tmp = REG_SET_FIELD(tmp, VM_L2_CNTL2, INVALIDATE_L2_CACHE, 1);
  132. WREG32_SOC15(MMHUB, 0, mmVM_L2_CNTL2, tmp);
  133. tmp = mmVM_L2_CNTL3_DEFAULT;
  134. tmp = REG_SET_FIELD(tmp, VM_L2_CNTL3, BANK_SELECT, 9);
  135. tmp = REG_SET_FIELD(tmp, VM_L2_CNTL3, L2_CACHE_BIGK_FRAGMENT_SIZE, 6);
  136. WREG32_SOC15(MMHUB, 0, mmVM_L2_CNTL3, tmp);
  137. tmp = mmVM_L2_CNTL4_DEFAULT;
  138. tmp = REG_SET_FIELD(tmp, VM_L2_CNTL4, VMC_TAP_PDE_REQUEST_PHYSICAL, 0);
  139. tmp = REG_SET_FIELD(tmp, VM_L2_CNTL4, VMC_TAP_PTE_REQUEST_PHYSICAL, 0);
  140. WREG32_SOC15(MMHUB, 0, mmVM_L2_CNTL4, tmp);
  141. }
  142. static void mmhub_v1_0_enable_system_domain(struct amdgpu_device *adev)
  143. {
  144. uint32_t tmp;
  145. tmp = RREG32_SOC15(MMHUB, 0, mmVM_CONTEXT0_CNTL);
  146. tmp = REG_SET_FIELD(tmp, VM_CONTEXT0_CNTL, ENABLE_CONTEXT, 1);
  147. tmp = REG_SET_FIELD(tmp, VM_CONTEXT0_CNTL, PAGE_TABLE_DEPTH, 0);
  148. WREG32_SOC15(MMHUB, 0, mmVM_CONTEXT0_CNTL, tmp);
  149. }
  150. static void mmhub_v1_0_disable_identity_aperture(struct amdgpu_device *adev)
  151. {
  152. WREG32_SOC15(MMHUB, 0, mmVM_L2_CONTEXT1_IDENTITY_APERTURE_LOW_ADDR_LO32,
  153. 0XFFFFFFFF);
  154. WREG32_SOC15(MMHUB, 0, mmVM_L2_CONTEXT1_IDENTITY_APERTURE_LOW_ADDR_HI32,
  155. 0x0000000F);
  156. WREG32_SOC15(MMHUB, 0,
  157. mmVM_L2_CONTEXT1_IDENTITY_APERTURE_HIGH_ADDR_LO32, 0);
  158. WREG32_SOC15(MMHUB, 0,
  159. mmVM_L2_CONTEXT1_IDENTITY_APERTURE_HIGH_ADDR_HI32, 0);
  160. WREG32_SOC15(MMHUB, 0, mmVM_L2_CONTEXT_IDENTITY_PHYSICAL_OFFSET_LO32,
  161. 0);
  162. WREG32_SOC15(MMHUB, 0, mmVM_L2_CONTEXT_IDENTITY_PHYSICAL_OFFSET_HI32,
  163. 0);
  164. }
  165. static void mmhub_v1_0_setup_vmid_config(struct amdgpu_device *adev)
  166. {
  167. int i;
  168. uint32_t tmp;
  169. for (i = 0; i <= 14; i++) {
  170. tmp = RREG32_SOC15_OFFSET(MMHUB, 0, mmVM_CONTEXT1_CNTL, i);
  171. tmp = REG_SET_FIELD(tmp, VM_CONTEXT1_CNTL,
  172. ENABLE_CONTEXT, 1);
  173. tmp = REG_SET_FIELD(tmp, VM_CONTEXT1_CNTL,
  174. PAGE_TABLE_DEPTH, adev->vm_manager.num_level);
  175. tmp = REG_SET_FIELD(tmp, VM_CONTEXT1_CNTL,
  176. RANGE_PROTECTION_FAULT_ENABLE_DEFAULT, 1);
  177. tmp = REG_SET_FIELD(tmp, VM_CONTEXT1_CNTL,
  178. DUMMY_PAGE_PROTECTION_FAULT_ENABLE_DEFAULT, 1);
  179. tmp = REG_SET_FIELD(tmp, VM_CONTEXT1_CNTL,
  180. PDE0_PROTECTION_FAULT_ENABLE_DEFAULT, 1);
  181. tmp = REG_SET_FIELD(tmp, VM_CONTEXT1_CNTL,
  182. VALID_PROTECTION_FAULT_ENABLE_DEFAULT, 1);
  183. tmp = REG_SET_FIELD(tmp, VM_CONTEXT1_CNTL,
  184. READ_PROTECTION_FAULT_ENABLE_DEFAULT, 1);
  185. tmp = REG_SET_FIELD(tmp, VM_CONTEXT1_CNTL,
  186. WRITE_PROTECTION_FAULT_ENABLE_DEFAULT, 1);
  187. tmp = REG_SET_FIELD(tmp, VM_CONTEXT1_CNTL,
  188. EXECUTE_PROTECTION_FAULT_ENABLE_DEFAULT, 1);
  189. tmp = REG_SET_FIELD(tmp, VM_CONTEXT1_CNTL,
  190. PAGE_TABLE_BLOCK_SIZE,
  191. adev->vm_manager.block_size - 9);
  192. /* Send no-retry XNACK on fault to suppress VM fault storm. */
  193. tmp = REG_SET_FIELD(tmp, VM_CONTEXT1_CNTL,
  194. RETRY_PERMISSION_OR_INVALID_PAGE_FAULT, 0);
  195. WREG32_SOC15_OFFSET(MMHUB, 0, mmVM_CONTEXT1_CNTL, i, tmp);
  196. WREG32_SOC15_OFFSET(MMHUB, 0, mmVM_CONTEXT1_PAGE_TABLE_START_ADDR_LO32, i*2, 0);
  197. WREG32_SOC15_OFFSET(MMHUB, 0, mmVM_CONTEXT1_PAGE_TABLE_START_ADDR_HI32, i*2, 0);
  198. WREG32_SOC15_OFFSET(MMHUB, 0, mmVM_CONTEXT1_PAGE_TABLE_END_ADDR_LO32, i*2,
  199. lower_32_bits(adev->vm_manager.max_pfn - 1));
  200. WREG32_SOC15_OFFSET(MMHUB, 0, mmVM_CONTEXT1_PAGE_TABLE_END_ADDR_HI32, i*2,
  201. upper_32_bits(adev->vm_manager.max_pfn - 1));
  202. }
  203. }
  204. static void mmhub_v1_0_program_invalidation(struct amdgpu_device *adev)
  205. {
  206. unsigned i;
  207. for (i = 0; i < 18; ++i) {
  208. WREG32_SOC15_OFFSET(MMHUB, 0, mmVM_INVALIDATE_ENG0_ADDR_RANGE_LO32,
  209. 2 * i, 0xffffffff);
  210. WREG32_SOC15_OFFSET(MMHUB, 0, mmVM_INVALIDATE_ENG0_ADDR_RANGE_HI32,
  211. 2 * i, 0x1f);
  212. }
  213. }
  214. struct pctl_data {
  215. uint32_t index;
  216. uint32_t data;
  217. };
  218. static const struct pctl_data pctl0_data[] = {
  219. {0x0, 0x7a640},
  220. {0x9, 0x2a64a},
  221. {0xd, 0x2a680},
  222. {0x11, 0x6a684},
  223. {0x19, 0xea68e},
  224. {0x29, 0xa69e},
  225. {0x2b, 0x34a6c0},
  226. {0x61, 0x83a707},
  227. {0xe6, 0x8a7a4},
  228. {0xf0, 0x1a7b8},
  229. {0xf3, 0xfa7cc},
  230. {0x104, 0x17a7dd},
  231. {0x11d, 0xa7dc},
  232. {0x11f, 0x12a7f5},
  233. {0x133, 0xa808},
  234. {0x135, 0x12a810},
  235. {0x149, 0x7a82c}
  236. };
  237. #define PCTL0_DATA_LEN (sizeof(pctl0_data)/sizeof(pctl0_data[0]))
  238. #define PCTL0_RENG_EXEC_END_PTR 0x151
  239. #define PCTL0_STCTRL_REG_SAVE_RANGE0_BASE 0xa640
  240. #define PCTL0_STCTRL_REG_SAVE_RANGE0_LIMIT 0xa833
  241. static const struct pctl_data pctl1_data[] = {
  242. {0x0, 0x39a000},
  243. {0x3b, 0x44a040},
  244. {0x81, 0x2a08d},
  245. {0x85, 0x6ba094},
  246. {0xf2, 0x18a100},
  247. {0x10c, 0x4a132},
  248. {0x112, 0xca141},
  249. {0x120, 0x2fa158},
  250. {0x151, 0x17a1d0},
  251. {0x16a, 0x1a1e9},
  252. {0x16d, 0x13a1ec},
  253. {0x182, 0x7a201},
  254. {0x18b, 0x3a20a},
  255. {0x190, 0x7a580},
  256. {0x199, 0xa590},
  257. {0x19b, 0x4a594},
  258. {0x1a1, 0x1a59c},
  259. {0x1a4, 0x7a82c},
  260. {0x1ad, 0xfa7cc},
  261. {0x1be, 0x17a7dd},
  262. {0x1d7, 0x12a810},
  263. {0x1eb, 0x4000a7e1},
  264. {0x1ec, 0x5000a7f5},
  265. {0x1ed, 0x4000a7e2},
  266. {0x1ee, 0x5000a7dc},
  267. {0x1ef, 0x4000a7e3},
  268. {0x1f0, 0x5000a7f6},
  269. {0x1f1, 0x5000a7e4}
  270. };
  271. #define PCTL1_DATA_LEN (sizeof(pctl1_data)/sizeof(pctl1_data[0]))
  272. #define PCTL1_RENG_EXEC_END_PTR 0x1f1
  273. #define PCTL1_STCTRL_REG_SAVE_RANGE0_BASE 0xa000
  274. #define PCTL1_STCTRL_REG_SAVE_RANGE0_LIMIT 0xa20d
  275. #define PCTL1_STCTRL_REG_SAVE_RANGE1_BASE 0xa580
  276. #define PCTL1_STCTRL_REG_SAVE_RANGE1_LIMIT 0xa59d
  277. #define PCTL1_STCTRL_REG_SAVE_RANGE2_BASE 0xa82c
  278. #define PCTL1_STCTRL_REG_SAVE_RANGE2_LIMIT 0xa833
  279. static void mmhub_v1_0_power_gating_write_save_ranges(struct amdgpu_device *adev)
  280. {
  281. uint32_t tmp = 0;
  282. /* PCTL0_STCTRL_REGISTER_SAVE_RANGE0 */
  283. tmp = REG_SET_FIELD(tmp, PCTL0_STCTRL_REGISTER_SAVE_RANGE0,
  284. STCTRL_REGISTER_SAVE_BASE,
  285. PCTL0_STCTRL_REG_SAVE_RANGE0_BASE);
  286. tmp = REG_SET_FIELD(tmp, PCTL0_STCTRL_REGISTER_SAVE_RANGE0,
  287. STCTRL_REGISTER_SAVE_LIMIT,
  288. PCTL0_STCTRL_REG_SAVE_RANGE0_LIMIT);
  289. WREG32_SOC15(MMHUB, 0, mmPCTL0_STCTRL_REGISTER_SAVE_RANGE0, tmp);
  290. /* PCTL1_STCTRL_REGISTER_SAVE_RANGE0 */
  291. tmp = 0;
  292. tmp = REG_SET_FIELD(tmp, PCTL1_STCTRL_REGISTER_SAVE_RANGE0,
  293. STCTRL_REGISTER_SAVE_BASE,
  294. PCTL1_STCTRL_REG_SAVE_RANGE0_BASE);
  295. tmp = REG_SET_FIELD(tmp, PCTL1_STCTRL_REGISTER_SAVE_RANGE0,
  296. STCTRL_REGISTER_SAVE_LIMIT,
  297. PCTL1_STCTRL_REG_SAVE_RANGE0_LIMIT);
  298. WREG32_SOC15(MMHUB, 0, mmPCTL1_STCTRL_REGISTER_SAVE_RANGE0, tmp);
  299. /* PCTL1_STCTRL_REGISTER_SAVE_RANGE1 */
  300. tmp = 0;
  301. tmp = REG_SET_FIELD(tmp, PCTL1_STCTRL_REGISTER_SAVE_RANGE1,
  302. STCTRL_REGISTER_SAVE_BASE,
  303. PCTL1_STCTRL_REG_SAVE_RANGE1_BASE);
  304. tmp = REG_SET_FIELD(tmp, PCTL1_STCTRL_REGISTER_SAVE_RANGE1,
  305. STCTRL_REGISTER_SAVE_LIMIT,
  306. PCTL1_STCTRL_REG_SAVE_RANGE1_LIMIT);
  307. WREG32_SOC15(MMHUB, 0, mmPCTL1_STCTRL_REGISTER_SAVE_RANGE1, tmp);
  308. /* PCTL1_STCTRL_REGISTER_SAVE_RANGE2 */
  309. tmp = 0;
  310. tmp = REG_SET_FIELD(tmp, PCTL1_STCTRL_REGISTER_SAVE_RANGE2,
  311. STCTRL_REGISTER_SAVE_BASE,
  312. PCTL1_STCTRL_REG_SAVE_RANGE2_BASE);
  313. tmp = REG_SET_FIELD(tmp, PCTL1_STCTRL_REGISTER_SAVE_RANGE2,
  314. STCTRL_REGISTER_SAVE_LIMIT,
  315. PCTL1_STCTRL_REG_SAVE_RANGE2_LIMIT);
  316. WREG32_SOC15(MMHUB, 0, mmPCTL1_STCTRL_REGISTER_SAVE_RANGE2, tmp);
  317. }
  318. void mmhub_v1_0_initialize_power_gating(struct amdgpu_device *adev)
  319. {
  320. uint32_t pctl0_misc = 0;
  321. uint32_t pctl0_reng_execute = 0;
  322. uint32_t pctl1_misc = 0;
  323. uint32_t pctl1_reng_execute = 0;
  324. int i = 0;
  325. if (amdgpu_sriov_vf(adev))
  326. return;
  327. pctl0_misc = RREG32_SOC15(MMHUB, 0, mmPCTL0_MISC);
  328. pctl0_reng_execute = RREG32_SOC15(MMHUB, 0, mmPCTL0_RENG_EXECUTE);
  329. pctl1_misc = RREG32_SOC15(MMHUB, 0, mmPCTL1_MISC);
  330. pctl1_reng_execute = RREG32_SOC15(MMHUB, 0, mmPCTL1_RENG_EXECUTE);
  331. /* Light sleep must be disabled before writing to pctl0 registers */
  332. pctl0_misc &= ~PCTL0_MISC__RENG_MEM_LS_ENABLE_MASK;
  333. WREG32_SOC15(MMHUB, 0, mmPCTL0_MISC, pctl0_misc);
  334. /* Write data used to access ram of register engine */
  335. for (i = 0; i < PCTL0_DATA_LEN; i++) {
  336. WREG32_SOC15(MMHUB, 0, mmPCTL0_RENG_RAM_INDEX,
  337. pctl0_data[i].index);
  338. WREG32_SOC15(MMHUB, 0, mmPCTL0_RENG_RAM_DATA,
  339. pctl0_data[i].data);
  340. }
  341. /* Set the reng execute end ptr for pctl0 */
  342. pctl0_reng_execute = REG_SET_FIELD(pctl0_reng_execute,
  343. PCTL0_RENG_EXECUTE,
  344. RENG_EXECUTE_END_PTR,
  345. PCTL0_RENG_EXEC_END_PTR);
  346. WREG32_SOC15(MMHUB, 0, mmPCTL0_RENG_EXECUTE, pctl0_reng_execute);
  347. /* Light sleep must be disabled before writing to pctl1 registers */
  348. pctl1_misc &= ~PCTL1_MISC__RENG_MEM_LS_ENABLE_MASK;
  349. WREG32_SOC15(MMHUB, 0, mmPCTL1_MISC, pctl1_misc);
  350. /* Write data used to access ram of register engine */
  351. for (i = 0; i < PCTL1_DATA_LEN; i++) {
  352. WREG32_SOC15(MMHUB, 0, mmPCTL1_RENG_RAM_INDEX,
  353. pctl1_data[i].index);
  354. WREG32_SOC15(MMHUB, 0, mmPCTL1_RENG_RAM_DATA,
  355. pctl1_data[i].data);
  356. }
  357. /* Set the reng execute end ptr for pctl1 */
  358. pctl1_reng_execute = REG_SET_FIELD(pctl1_reng_execute,
  359. PCTL1_RENG_EXECUTE,
  360. RENG_EXECUTE_END_PTR,
  361. PCTL1_RENG_EXEC_END_PTR);
  362. WREG32_SOC15(MMHUB, 0, mmPCTL1_RENG_EXECUTE, pctl1_reng_execute);
  363. mmhub_v1_0_power_gating_write_save_ranges(adev);
  364. /* Re-enable light sleep */
  365. pctl0_misc |= PCTL0_MISC__RENG_MEM_LS_ENABLE_MASK;
  366. WREG32_SOC15(MMHUB, 0, mmPCTL0_MISC, pctl0_misc);
  367. pctl1_misc |= PCTL1_MISC__RENG_MEM_LS_ENABLE_MASK;
  368. WREG32_SOC15(MMHUB, 0, mmPCTL1_MISC, pctl1_misc);
  369. }
  370. void mmhub_v1_0_update_power_gating(struct amdgpu_device *adev,
  371. bool enable)
  372. {
  373. uint32_t pctl0_reng_execute = 0;
  374. uint32_t pctl1_reng_execute = 0;
  375. if (amdgpu_sriov_vf(adev))
  376. return;
  377. pctl0_reng_execute = RREG32_SOC15(MMHUB, 0, mmPCTL0_RENG_EXECUTE);
  378. pctl1_reng_execute = RREG32_SOC15(MMHUB, 0, mmPCTL1_RENG_EXECUTE);
  379. if (enable && adev->pg_flags & AMD_PG_SUPPORT_MMHUB) {
  380. pctl0_reng_execute = REG_SET_FIELD(pctl0_reng_execute,
  381. PCTL0_RENG_EXECUTE,
  382. RENG_EXECUTE_ON_PWR_UP, 1);
  383. pctl0_reng_execute = REG_SET_FIELD(pctl0_reng_execute,
  384. PCTL0_RENG_EXECUTE,
  385. RENG_EXECUTE_ON_REG_UPDATE, 1);
  386. WREG32_SOC15(MMHUB, 0, mmPCTL0_RENG_EXECUTE, pctl0_reng_execute);
  387. pctl1_reng_execute = REG_SET_FIELD(pctl1_reng_execute,
  388. PCTL1_RENG_EXECUTE,
  389. RENG_EXECUTE_ON_PWR_UP, 1);
  390. pctl1_reng_execute = REG_SET_FIELD(pctl1_reng_execute,
  391. PCTL1_RENG_EXECUTE,
  392. RENG_EXECUTE_ON_REG_UPDATE, 1);
  393. WREG32_SOC15(MMHUB, 0, mmPCTL1_RENG_EXECUTE, pctl1_reng_execute);
  394. } else {
  395. pctl0_reng_execute = REG_SET_FIELD(pctl0_reng_execute,
  396. PCTL0_RENG_EXECUTE,
  397. RENG_EXECUTE_ON_PWR_UP, 0);
  398. pctl0_reng_execute = REG_SET_FIELD(pctl0_reng_execute,
  399. PCTL0_RENG_EXECUTE,
  400. RENG_EXECUTE_ON_REG_UPDATE, 0);
  401. WREG32_SOC15(MMHUB, 0, mmPCTL0_RENG_EXECUTE, pctl0_reng_execute);
  402. pctl1_reng_execute = REG_SET_FIELD(pctl1_reng_execute,
  403. PCTL1_RENG_EXECUTE,
  404. RENG_EXECUTE_ON_PWR_UP, 0);
  405. pctl1_reng_execute = REG_SET_FIELD(pctl1_reng_execute,
  406. PCTL1_RENG_EXECUTE,
  407. RENG_EXECUTE_ON_REG_UPDATE, 0);
  408. WREG32_SOC15(MMHUB, 0, mmPCTL1_RENG_EXECUTE, pctl1_reng_execute);
  409. }
  410. }
  411. int mmhub_v1_0_gart_enable(struct amdgpu_device *adev)
  412. {
  413. if (amdgpu_sriov_vf(adev)) {
  414. /*
  415. * MC_VM_FB_LOCATION_BASE/TOP is NULL for VF, becuase they are
  416. * VF copy registers so vbios post doesn't program them, for
  417. * SRIOV driver need to program them
  418. */
  419. WREG32_SOC15(MMHUB, 0, mmMC_VM_FB_LOCATION_BASE,
  420. adev->mc.vram_start >> 24);
  421. WREG32_SOC15(MMHUB, 0, mmMC_VM_FB_LOCATION_TOP,
  422. adev->mc.vram_end >> 24);
  423. }
  424. /* GART Enable. */
  425. mmhub_v1_0_init_gart_aperture_regs(adev);
  426. mmhub_v1_0_init_system_aperture_regs(adev);
  427. mmhub_v1_0_init_tlb_regs(adev);
  428. mmhub_v1_0_init_cache_regs(adev);
  429. mmhub_v1_0_enable_system_domain(adev);
  430. mmhub_v1_0_disable_identity_aperture(adev);
  431. mmhub_v1_0_setup_vmid_config(adev);
  432. mmhub_v1_0_program_invalidation(adev);
  433. return 0;
  434. }
  435. void mmhub_v1_0_gart_disable(struct amdgpu_device *adev)
  436. {
  437. u32 tmp;
  438. u32 i;
  439. /* Disable all tables */
  440. for (i = 0; i < 16; i++)
  441. WREG32_SOC15_OFFSET(MMHUB, 0, mmVM_CONTEXT0_CNTL, i, 0);
  442. /* Setup TLB control */
  443. tmp = RREG32_SOC15(MMHUB, 0, mmMC_VM_MX_L1_TLB_CNTL);
  444. tmp = REG_SET_FIELD(tmp, MC_VM_MX_L1_TLB_CNTL, ENABLE_L1_TLB, 0);
  445. tmp = REG_SET_FIELD(tmp,
  446. MC_VM_MX_L1_TLB_CNTL,
  447. ENABLE_ADVANCED_DRIVER_MODEL,
  448. 0);
  449. WREG32_SOC15(MMHUB, 0, mmMC_VM_MX_L1_TLB_CNTL, tmp);
  450. /* Setup L2 cache */
  451. tmp = RREG32_SOC15(MMHUB, 0, mmVM_L2_CNTL);
  452. tmp = REG_SET_FIELD(tmp, VM_L2_CNTL, ENABLE_L2_CACHE, 0);
  453. WREG32_SOC15(MMHUB, 0, mmVM_L2_CNTL, tmp);
  454. WREG32_SOC15(MMHUB, 0, mmVM_L2_CNTL3, 0);
  455. }
  456. /**
  457. * mmhub_v1_0_set_fault_enable_default - update GART/VM fault handling
  458. *
  459. * @adev: amdgpu_device pointer
  460. * @value: true redirects VM faults to the default page
  461. */
  462. void mmhub_v1_0_set_fault_enable_default(struct amdgpu_device *adev, bool value)
  463. {
  464. u32 tmp;
  465. tmp = RREG32_SOC15(MMHUB, 0, mmVM_L2_PROTECTION_FAULT_CNTL);
  466. tmp = REG_SET_FIELD(tmp, VM_L2_PROTECTION_FAULT_CNTL,
  467. RANGE_PROTECTION_FAULT_ENABLE_DEFAULT, value);
  468. tmp = REG_SET_FIELD(tmp, VM_L2_PROTECTION_FAULT_CNTL,
  469. PDE0_PROTECTION_FAULT_ENABLE_DEFAULT, value);
  470. tmp = REG_SET_FIELD(tmp, VM_L2_PROTECTION_FAULT_CNTL,
  471. PDE1_PROTECTION_FAULT_ENABLE_DEFAULT, value);
  472. tmp = REG_SET_FIELD(tmp, VM_L2_PROTECTION_FAULT_CNTL,
  473. PDE2_PROTECTION_FAULT_ENABLE_DEFAULT, value);
  474. tmp = REG_SET_FIELD(tmp,
  475. VM_L2_PROTECTION_FAULT_CNTL,
  476. TRANSLATE_FURTHER_PROTECTION_FAULT_ENABLE_DEFAULT,
  477. value);
  478. tmp = REG_SET_FIELD(tmp, VM_L2_PROTECTION_FAULT_CNTL,
  479. NACK_PROTECTION_FAULT_ENABLE_DEFAULT, value);
  480. tmp = REG_SET_FIELD(tmp, VM_L2_PROTECTION_FAULT_CNTL,
  481. DUMMY_PAGE_PROTECTION_FAULT_ENABLE_DEFAULT, value);
  482. tmp = REG_SET_FIELD(tmp, VM_L2_PROTECTION_FAULT_CNTL,
  483. VALID_PROTECTION_FAULT_ENABLE_DEFAULT, value);
  484. tmp = REG_SET_FIELD(tmp, VM_L2_PROTECTION_FAULT_CNTL,
  485. READ_PROTECTION_FAULT_ENABLE_DEFAULT, value);
  486. tmp = REG_SET_FIELD(tmp, VM_L2_PROTECTION_FAULT_CNTL,
  487. WRITE_PROTECTION_FAULT_ENABLE_DEFAULT, value);
  488. tmp = REG_SET_FIELD(tmp, VM_L2_PROTECTION_FAULT_CNTL,
  489. EXECUTE_PROTECTION_FAULT_ENABLE_DEFAULT, value);
  490. WREG32_SOC15(MMHUB, 0, mmVM_L2_PROTECTION_FAULT_CNTL, tmp);
  491. }
  492. void mmhub_v1_0_init(struct amdgpu_device *adev)
  493. {
  494. struct amdgpu_vmhub *hub = &adev->vmhub[AMDGPU_MMHUB];
  495. hub->ctx0_ptb_addr_lo32 =
  496. SOC15_REG_OFFSET(MMHUB, 0,
  497. mmVM_CONTEXT0_PAGE_TABLE_BASE_ADDR_LO32);
  498. hub->ctx0_ptb_addr_hi32 =
  499. SOC15_REG_OFFSET(MMHUB, 0,
  500. mmVM_CONTEXT0_PAGE_TABLE_BASE_ADDR_HI32);
  501. hub->vm_inv_eng0_req =
  502. SOC15_REG_OFFSET(MMHUB, 0, mmVM_INVALIDATE_ENG0_REQ);
  503. hub->vm_inv_eng0_ack =
  504. SOC15_REG_OFFSET(MMHUB, 0, mmVM_INVALIDATE_ENG0_ACK);
  505. hub->vm_context0_cntl =
  506. SOC15_REG_OFFSET(MMHUB, 0, mmVM_CONTEXT0_CNTL);
  507. hub->vm_l2_pro_fault_status =
  508. SOC15_REG_OFFSET(MMHUB, 0, mmVM_L2_PROTECTION_FAULT_STATUS);
  509. hub->vm_l2_pro_fault_cntl =
  510. SOC15_REG_OFFSET(MMHUB, 0, mmVM_L2_PROTECTION_FAULT_CNTL);
  511. }
  512. static void mmhub_v1_0_update_medium_grain_clock_gating(struct amdgpu_device *adev,
  513. bool enable)
  514. {
  515. uint32_t def, data, def1, data1, def2 = 0, data2 = 0;
  516. def = data = RREG32_SOC15(MMHUB, 0, mmATC_L2_MISC_CG);
  517. if (adev->asic_type != CHIP_RAVEN) {
  518. def1 = data1 = RREG32_SOC15(MMHUB, 0, mmDAGB0_CNTL_MISC2);
  519. def2 = data2 = RREG32_SOC15(MMHUB, 0, mmDAGB1_CNTL_MISC2);
  520. } else
  521. def1 = data1 = RREG32_SOC15(MMHUB, 0, mmDAGB0_CNTL_MISC2_RV);
  522. if (enable && (adev->cg_flags & AMD_CG_SUPPORT_MC_MGCG)) {
  523. data |= ATC_L2_MISC_CG__ENABLE_MASK;
  524. data1 &= ~(DAGB0_CNTL_MISC2__DISABLE_WRREQ_CG_MASK |
  525. DAGB0_CNTL_MISC2__DISABLE_WRRET_CG_MASK |
  526. DAGB0_CNTL_MISC2__DISABLE_RDREQ_CG_MASK |
  527. DAGB0_CNTL_MISC2__DISABLE_RDRET_CG_MASK |
  528. DAGB0_CNTL_MISC2__DISABLE_TLBWR_CG_MASK |
  529. DAGB0_CNTL_MISC2__DISABLE_TLBRD_CG_MASK);
  530. if (adev->asic_type != CHIP_RAVEN)
  531. data2 &= ~(DAGB1_CNTL_MISC2__DISABLE_WRREQ_CG_MASK |
  532. DAGB1_CNTL_MISC2__DISABLE_WRRET_CG_MASK |
  533. DAGB1_CNTL_MISC2__DISABLE_RDREQ_CG_MASK |
  534. DAGB1_CNTL_MISC2__DISABLE_RDRET_CG_MASK |
  535. DAGB1_CNTL_MISC2__DISABLE_TLBWR_CG_MASK |
  536. DAGB1_CNTL_MISC2__DISABLE_TLBRD_CG_MASK);
  537. } else {
  538. data &= ~ATC_L2_MISC_CG__ENABLE_MASK;
  539. data1 |= (DAGB0_CNTL_MISC2__DISABLE_WRREQ_CG_MASK |
  540. DAGB0_CNTL_MISC2__DISABLE_WRRET_CG_MASK |
  541. DAGB0_CNTL_MISC2__DISABLE_RDREQ_CG_MASK |
  542. DAGB0_CNTL_MISC2__DISABLE_RDRET_CG_MASK |
  543. DAGB0_CNTL_MISC2__DISABLE_TLBWR_CG_MASK |
  544. DAGB0_CNTL_MISC2__DISABLE_TLBRD_CG_MASK);
  545. if (adev->asic_type != CHIP_RAVEN)
  546. data2 |= (DAGB1_CNTL_MISC2__DISABLE_WRREQ_CG_MASK |
  547. DAGB1_CNTL_MISC2__DISABLE_WRRET_CG_MASK |
  548. DAGB1_CNTL_MISC2__DISABLE_RDREQ_CG_MASK |
  549. DAGB1_CNTL_MISC2__DISABLE_RDRET_CG_MASK |
  550. DAGB1_CNTL_MISC2__DISABLE_TLBWR_CG_MASK |
  551. DAGB1_CNTL_MISC2__DISABLE_TLBRD_CG_MASK);
  552. }
  553. if (def != data)
  554. WREG32_SOC15(MMHUB, 0, mmATC_L2_MISC_CG, data);
  555. if (def1 != data1) {
  556. if (adev->asic_type != CHIP_RAVEN)
  557. WREG32_SOC15(MMHUB, 0, mmDAGB0_CNTL_MISC2, data1);
  558. else
  559. WREG32_SOC15(MMHUB, 0, mmDAGB0_CNTL_MISC2_RV, data1);
  560. }
  561. if (adev->asic_type != CHIP_RAVEN && def2 != data2)
  562. WREG32_SOC15(MMHUB, 0, mmDAGB1_CNTL_MISC2, data2);
  563. }
  564. static void athub_update_medium_grain_clock_gating(struct amdgpu_device *adev,
  565. bool enable)
  566. {
  567. uint32_t def, data;
  568. def = data = RREG32_SOC15(ATHUB, 0, mmATHUB_MISC_CNTL);
  569. if (enable && (adev->cg_flags & AMD_CG_SUPPORT_MC_MGCG))
  570. data |= ATHUB_MISC_CNTL__CG_ENABLE_MASK;
  571. else
  572. data &= ~ATHUB_MISC_CNTL__CG_ENABLE_MASK;
  573. if (def != data)
  574. WREG32_SOC15(ATHUB, 0, mmATHUB_MISC_CNTL, data);
  575. }
  576. static void mmhub_v1_0_update_medium_grain_light_sleep(struct amdgpu_device *adev,
  577. bool enable)
  578. {
  579. uint32_t def, data;
  580. def = data = RREG32_SOC15(MMHUB, 0, mmATC_L2_MISC_CG);
  581. if (enable && (adev->cg_flags & AMD_CG_SUPPORT_MC_LS))
  582. data |= ATC_L2_MISC_CG__MEM_LS_ENABLE_MASK;
  583. else
  584. data &= ~ATC_L2_MISC_CG__MEM_LS_ENABLE_MASK;
  585. if (def != data)
  586. WREG32_SOC15(MMHUB, 0, mmATC_L2_MISC_CG, data);
  587. }
  588. static void athub_update_medium_grain_light_sleep(struct amdgpu_device *adev,
  589. bool enable)
  590. {
  591. uint32_t def, data;
  592. def = data = RREG32_SOC15(ATHUB, 0, mmATHUB_MISC_CNTL);
  593. if (enable && (adev->cg_flags & AMD_CG_SUPPORT_MC_LS) &&
  594. (adev->cg_flags & AMD_CG_SUPPORT_HDP_LS))
  595. data |= ATHUB_MISC_CNTL__CG_MEM_LS_ENABLE_MASK;
  596. else
  597. data &= ~ATHUB_MISC_CNTL__CG_MEM_LS_ENABLE_MASK;
  598. if(def != data)
  599. WREG32_SOC15(ATHUB, 0, mmATHUB_MISC_CNTL, data);
  600. }
  601. int mmhub_v1_0_set_clockgating(struct amdgpu_device *adev,
  602. enum amd_clockgating_state state)
  603. {
  604. if (amdgpu_sriov_vf(adev))
  605. return 0;
  606. switch (adev->asic_type) {
  607. case CHIP_VEGA10:
  608. case CHIP_RAVEN:
  609. mmhub_v1_0_update_medium_grain_clock_gating(adev,
  610. state == AMD_CG_STATE_GATE ? true : false);
  611. athub_update_medium_grain_clock_gating(adev,
  612. state == AMD_CG_STATE_GATE ? true : false);
  613. mmhub_v1_0_update_medium_grain_light_sleep(adev,
  614. state == AMD_CG_STATE_GATE ? true : false);
  615. athub_update_medium_grain_light_sleep(adev,
  616. state == AMD_CG_STATE_GATE ? true : false);
  617. break;
  618. default:
  619. break;
  620. }
  621. return 0;
  622. }
  623. void mmhub_v1_0_get_clockgating(struct amdgpu_device *adev, u32 *flags)
  624. {
  625. int data;
  626. if (amdgpu_sriov_vf(adev))
  627. *flags = 0;
  628. /* AMD_CG_SUPPORT_MC_MGCG */
  629. data = RREG32_SOC15(ATHUB, 0, mmATHUB_MISC_CNTL);
  630. if (data & ATHUB_MISC_CNTL__CG_ENABLE_MASK)
  631. *flags |= AMD_CG_SUPPORT_MC_MGCG;
  632. /* AMD_CG_SUPPORT_MC_LS */
  633. data = RREG32_SOC15(MMHUB, 0, mmATC_L2_MISC_CG);
  634. if (data & ATC_L2_MISC_CG__MEM_LS_ENABLE_MASK)
  635. *flags |= AMD_CG_SUPPORT_MC_LS;
  636. }