gfxhub_v1_0.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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 "gfxhub_v1_0.h"
  25. #include "vega10/soc15ip.h"
  26. #include "vega10/GC/gc_9_0_offset.h"
  27. #include "vega10/GC/gc_9_0_sh_mask.h"
  28. #include "vega10/GC/gc_9_0_default.h"
  29. #include "vega10/vega10_enum.h"
  30. #include "soc15_common.h"
  31. u64 gfxhub_v1_0_get_mc_fb_offset(struct amdgpu_device *adev)
  32. {
  33. return (u64)RREG32_SOC15(GC, 0, mmMC_VM_FB_OFFSET) << 24;
  34. }
  35. static void gfxhub_v1_0_init_gart_pt_regs(struct amdgpu_device *adev)
  36. {
  37. uint64_t value;
  38. BUG_ON(adev->gart.table_addr & (~0x0000FFFFFFFFF000ULL));
  39. value = adev->gart.table_addr - adev->mc.vram_start
  40. + adev->vm_manager.vram_base_offset;
  41. value &= 0x0000FFFFFFFFF000ULL;
  42. value |= 0x1; /*valid bit*/
  43. WREG32_SOC15(GC, 0, mmVM_CONTEXT0_PAGE_TABLE_BASE_ADDR_LO32,
  44. lower_32_bits(value));
  45. WREG32_SOC15(GC, 0, mmVM_CONTEXT0_PAGE_TABLE_BASE_ADDR_HI32,
  46. upper_32_bits(value));
  47. }
  48. static void gfxhub_v1_0_init_gart_aperture_regs(struct amdgpu_device *adev)
  49. {
  50. gfxhub_v1_0_init_gart_pt_regs(adev);
  51. WREG32_SOC15(GC, 0, mmVM_CONTEXT0_PAGE_TABLE_START_ADDR_LO32,
  52. (u32)(adev->mc.gart_start >> 12));
  53. WREG32_SOC15(GC, 0, mmVM_CONTEXT0_PAGE_TABLE_START_ADDR_HI32,
  54. (u32)(adev->mc.gart_start >> 44));
  55. WREG32_SOC15(GC, 0, mmVM_CONTEXT0_PAGE_TABLE_END_ADDR_LO32,
  56. (u32)(adev->mc.gart_end >> 12));
  57. WREG32_SOC15(GC, 0, mmVM_CONTEXT0_PAGE_TABLE_END_ADDR_HI32,
  58. (u32)(adev->mc.gart_end >> 44));
  59. }
  60. static void gfxhub_v1_0_init_system_aperture_regs(struct amdgpu_device *adev)
  61. {
  62. uint64_t value;
  63. /* Disable AGP. */
  64. WREG32_SOC15(GC, 0, mmMC_VM_AGP_BASE, 0);
  65. WREG32_SOC15(GC, 0, mmMC_VM_AGP_TOP, 0);
  66. WREG32_SOC15(GC, 0, mmMC_VM_AGP_BOT, 0xFFFFFFFF);
  67. /* Program the system aperture low logical page number. */
  68. WREG32_SOC15(GC, 0, mmMC_VM_SYSTEM_APERTURE_LOW_ADDR,
  69. adev->mc.vram_start >> 18);
  70. WREG32_SOC15(GC, 0, mmMC_VM_SYSTEM_APERTURE_HIGH_ADDR,
  71. adev->mc.vram_end >> 18);
  72. /* Set default page address. */
  73. value = adev->vram_scratch.gpu_addr - adev->mc.vram_start
  74. + adev->vm_manager.vram_base_offset;
  75. WREG32_SOC15(GC, 0, mmMC_VM_SYSTEM_APERTURE_DEFAULT_ADDR_LSB,
  76. (u32)(value >> 12));
  77. WREG32_SOC15(GC, 0, mmMC_VM_SYSTEM_APERTURE_DEFAULT_ADDR_MSB,
  78. (u32)(value >> 44));
  79. /* Program "protection fault". */
  80. WREG32_SOC15(GC, 0, mmVM_L2_PROTECTION_FAULT_DEFAULT_ADDR_LO32,
  81. (u32)(adev->dummy_page.addr >> 12));
  82. WREG32_SOC15(GC, 0, mmVM_L2_PROTECTION_FAULT_DEFAULT_ADDR_HI32,
  83. (u32)((u64)adev->dummy_page.addr >> 44));
  84. WREG32_FIELD15(GC, 0, VM_L2_PROTECTION_FAULT_CNTL2,
  85. ACTIVE_PAGE_MIGRATION_PTE_READ_RETRY, 1);
  86. }
  87. static void gfxhub_v1_0_init_tlb_regs(struct amdgpu_device *adev)
  88. {
  89. uint32_t tmp;
  90. /* Setup TLB control */
  91. tmp = RREG32_SOC15(GC, 0, mmMC_VM_MX_L1_TLB_CNTL);
  92. tmp = REG_SET_FIELD(tmp, MC_VM_MX_L1_TLB_CNTL, ENABLE_L1_TLB, 1);
  93. tmp = REG_SET_FIELD(tmp, MC_VM_MX_L1_TLB_CNTL, SYSTEM_ACCESS_MODE, 3);
  94. tmp = REG_SET_FIELD(tmp, MC_VM_MX_L1_TLB_CNTL,
  95. ENABLE_ADVANCED_DRIVER_MODEL, 1);
  96. tmp = REG_SET_FIELD(tmp, MC_VM_MX_L1_TLB_CNTL,
  97. SYSTEM_APERTURE_UNMAPPED_ACCESS, 0);
  98. tmp = REG_SET_FIELD(tmp, MC_VM_MX_L1_TLB_CNTL, ECO_BITS, 0);
  99. tmp = REG_SET_FIELD(tmp, MC_VM_MX_L1_TLB_CNTL,
  100. MTYPE, MTYPE_UC);/* XXX for emulation. */
  101. tmp = REG_SET_FIELD(tmp, MC_VM_MX_L1_TLB_CNTL, ATC_EN, 1);
  102. WREG32_SOC15(GC, 0, mmMC_VM_MX_L1_TLB_CNTL, tmp);
  103. }
  104. static void gfxhub_v1_0_init_cache_regs(struct amdgpu_device *adev)
  105. {
  106. uint32_t tmp;
  107. /* Setup L2 cache */
  108. tmp = RREG32_SOC15(GC, 0, mmVM_L2_CNTL);
  109. tmp = REG_SET_FIELD(tmp, VM_L2_CNTL, ENABLE_L2_CACHE, 1);
  110. tmp = REG_SET_FIELD(tmp, VM_L2_CNTL, ENABLE_L2_FRAGMENT_PROCESSING, 1);
  111. /* XXX for emulation, Refer to closed source code.*/
  112. tmp = REG_SET_FIELD(tmp, VM_L2_CNTL, L2_PDE0_CACHE_TAG_GENERATION_MODE,
  113. 0);
  114. tmp = REG_SET_FIELD(tmp, VM_L2_CNTL, PDE_FAULT_CLASSIFICATION, 1);
  115. tmp = REG_SET_FIELD(tmp, VM_L2_CNTL, CONTEXT1_IDENTITY_ACCESS_MODE, 1);
  116. tmp = REG_SET_FIELD(tmp, VM_L2_CNTL, IDENTITY_MODE_FRAGMENT_SIZE, 0);
  117. WREG32_SOC15(GC, 0, mmVM_L2_CNTL, tmp);
  118. tmp = RREG32_SOC15(GC, 0, mmVM_L2_CNTL2);
  119. tmp = REG_SET_FIELD(tmp, VM_L2_CNTL2, INVALIDATE_ALL_L1_TLBS, 1);
  120. tmp = REG_SET_FIELD(tmp, VM_L2_CNTL2, INVALIDATE_L2_CACHE, 1);
  121. WREG32_SOC15(GC, 0, mmVM_L2_CNTL2, tmp);
  122. tmp = mmVM_L2_CNTL3_DEFAULT;
  123. tmp = REG_SET_FIELD(tmp, VM_L2_CNTL3, BANK_SELECT, 9);
  124. tmp = REG_SET_FIELD(tmp, VM_L2_CNTL3, L2_CACHE_BIGK_FRAGMENT_SIZE, 6);
  125. WREG32_SOC15(GC, 0, mmVM_L2_CNTL3, tmp);
  126. tmp = mmVM_L2_CNTL4_DEFAULT;
  127. tmp = REG_SET_FIELD(tmp, VM_L2_CNTL4, VMC_TAP_PDE_REQUEST_PHYSICAL, 0);
  128. tmp = REG_SET_FIELD(tmp, VM_L2_CNTL4, VMC_TAP_PTE_REQUEST_PHYSICAL, 0);
  129. WREG32_SOC15(GC, 0, mmVM_L2_CNTL4, tmp);
  130. }
  131. static void gfxhub_v1_0_enable_system_domain(struct amdgpu_device *adev)
  132. {
  133. uint32_t tmp;
  134. tmp = RREG32_SOC15(GC, 0, mmVM_CONTEXT0_CNTL);
  135. tmp = REG_SET_FIELD(tmp, VM_CONTEXT0_CNTL, ENABLE_CONTEXT, 1);
  136. tmp = REG_SET_FIELD(tmp, VM_CONTEXT0_CNTL, PAGE_TABLE_DEPTH, 0);
  137. WREG32_SOC15(GC, 0, mmVM_CONTEXT0_CNTL, tmp);
  138. }
  139. static void gfxhub_v1_0_disable_identity_aperture(struct amdgpu_device *adev)
  140. {
  141. WREG32_SOC15(GC, 0, mmVM_L2_CONTEXT1_IDENTITY_APERTURE_LOW_ADDR_LO32,
  142. 0XFFFFFFFF);
  143. WREG32_SOC15(GC, 0, mmVM_L2_CONTEXT1_IDENTITY_APERTURE_LOW_ADDR_HI32,
  144. 0x0000000F);
  145. WREG32_SOC15(GC, 0, mmVM_L2_CONTEXT1_IDENTITY_APERTURE_HIGH_ADDR_LO32,
  146. 0);
  147. WREG32_SOC15(GC, 0, mmVM_L2_CONTEXT1_IDENTITY_APERTURE_HIGH_ADDR_HI32,
  148. 0);
  149. WREG32_SOC15(GC, 0, mmVM_L2_CONTEXT_IDENTITY_PHYSICAL_OFFSET_LO32, 0);
  150. WREG32_SOC15(GC, 0, mmVM_L2_CONTEXT_IDENTITY_PHYSICAL_OFFSET_HI32, 0);
  151. }
  152. static void gfxhub_v1_0_setup_vmid_config(struct amdgpu_device *adev)
  153. {
  154. int i;
  155. uint32_t tmp;
  156. for (i = 0; i <= 14; i++) {
  157. tmp = RREG32_SOC15_OFFSET(GC, 0, mmVM_CONTEXT1_CNTL, i);
  158. tmp = REG_SET_FIELD(tmp, VM_CONTEXT1_CNTL, ENABLE_CONTEXT, 1);
  159. tmp = REG_SET_FIELD(tmp, VM_CONTEXT1_CNTL, PAGE_TABLE_DEPTH,
  160. adev->vm_manager.num_level);
  161. tmp = REG_SET_FIELD(tmp, VM_CONTEXT1_CNTL,
  162. RANGE_PROTECTION_FAULT_ENABLE_DEFAULT, 1);
  163. tmp = REG_SET_FIELD(tmp, VM_CONTEXT1_CNTL,
  164. DUMMY_PAGE_PROTECTION_FAULT_ENABLE_DEFAULT, 1);
  165. tmp = REG_SET_FIELD(tmp, VM_CONTEXT1_CNTL,
  166. PDE0_PROTECTION_FAULT_ENABLE_DEFAULT, 1);
  167. tmp = REG_SET_FIELD(tmp, VM_CONTEXT1_CNTL,
  168. VALID_PROTECTION_FAULT_ENABLE_DEFAULT, 1);
  169. tmp = REG_SET_FIELD(tmp, VM_CONTEXT1_CNTL,
  170. READ_PROTECTION_FAULT_ENABLE_DEFAULT, 1);
  171. tmp = REG_SET_FIELD(tmp, VM_CONTEXT1_CNTL,
  172. WRITE_PROTECTION_FAULT_ENABLE_DEFAULT, 1);
  173. tmp = REG_SET_FIELD(tmp, VM_CONTEXT1_CNTL,
  174. EXECUTE_PROTECTION_FAULT_ENABLE_DEFAULT, 1);
  175. tmp = REG_SET_FIELD(tmp, VM_CONTEXT1_CNTL,
  176. PAGE_TABLE_BLOCK_SIZE,
  177. adev->vm_manager.block_size - 9);
  178. /* Send no-retry XNACK on fault to suppress VM fault storm. */
  179. tmp = REG_SET_FIELD(tmp, VM_CONTEXT1_CNTL,
  180. RETRY_PERMISSION_OR_INVALID_PAGE_FAULT, 0);
  181. WREG32_SOC15_OFFSET(GC, 0, mmVM_CONTEXT1_CNTL, i, tmp);
  182. WREG32_SOC15_OFFSET(GC, 0, mmVM_CONTEXT1_PAGE_TABLE_START_ADDR_LO32, i*2, 0);
  183. WREG32_SOC15_OFFSET(GC, 0, mmVM_CONTEXT1_PAGE_TABLE_START_ADDR_HI32, i*2, 0);
  184. WREG32_SOC15_OFFSET(GC, 0, mmVM_CONTEXT1_PAGE_TABLE_END_ADDR_LO32, i*2,
  185. lower_32_bits(adev->vm_manager.max_pfn - 1));
  186. WREG32_SOC15_OFFSET(GC, 0, mmVM_CONTEXT1_PAGE_TABLE_END_ADDR_HI32, i*2,
  187. upper_32_bits(adev->vm_manager.max_pfn - 1));
  188. }
  189. }
  190. static void gfxhub_v1_0_program_invalidation(struct amdgpu_device *adev)
  191. {
  192. unsigned i;
  193. for (i = 0 ; i < 18; ++i) {
  194. WREG32_SOC15_OFFSET(GC, 0, mmVM_INVALIDATE_ENG0_ADDR_RANGE_LO32,
  195. 2 * i, 0xffffffff);
  196. WREG32_SOC15_OFFSET(GC, 0, mmVM_INVALIDATE_ENG0_ADDR_RANGE_HI32,
  197. 2 * i, 0x1f);
  198. }
  199. }
  200. int gfxhub_v1_0_gart_enable(struct amdgpu_device *adev)
  201. {
  202. if (amdgpu_sriov_vf(adev)) {
  203. /*
  204. * MC_VM_FB_LOCATION_BASE/TOP is NULL for VF, becuase they are
  205. * VF copy registers so vbios post doesn't program them, for
  206. * SRIOV driver need to program them
  207. */
  208. WREG32_SOC15(GC, 0, mmMC_VM_FB_LOCATION_BASE,
  209. adev->mc.vram_start >> 24);
  210. WREG32_SOC15(GC, 0, mmMC_VM_FB_LOCATION_TOP,
  211. adev->mc.vram_end >> 24);
  212. }
  213. /* GART Enable. */
  214. gfxhub_v1_0_init_gart_aperture_regs(adev);
  215. gfxhub_v1_0_init_system_aperture_regs(adev);
  216. gfxhub_v1_0_init_tlb_regs(adev);
  217. gfxhub_v1_0_init_cache_regs(adev);
  218. gfxhub_v1_0_enable_system_domain(adev);
  219. gfxhub_v1_0_disable_identity_aperture(adev);
  220. gfxhub_v1_0_setup_vmid_config(adev);
  221. gfxhub_v1_0_program_invalidation(adev);
  222. return 0;
  223. }
  224. void gfxhub_v1_0_gart_disable(struct amdgpu_device *adev)
  225. {
  226. u32 tmp;
  227. u32 i;
  228. /* Disable all tables */
  229. for (i = 0; i < 16; i++)
  230. WREG32_SOC15_OFFSET(GC, 0, mmVM_CONTEXT0_CNTL, i, 0);
  231. /* Setup TLB control */
  232. tmp = RREG32_SOC15(GC, 0, mmMC_VM_MX_L1_TLB_CNTL);
  233. tmp = REG_SET_FIELD(tmp, MC_VM_MX_L1_TLB_CNTL, ENABLE_L1_TLB, 0);
  234. tmp = REG_SET_FIELD(tmp,
  235. MC_VM_MX_L1_TLB_CNTL,
  236. ENABLE_ADVANCED_DRIVER_MODEL,
  237. 0);
  238. WREG32_SOC15(GC, 0, mmMC_VM_MX_L1_TLB_CNTL, tmp);
  239. /* Setup L2 cache */
  240. WREG32_FIELD15(GC, 0, VM_L2_CNTL, ENABLE_L2_CACHE, 0);
  241. WREG32_SOC15(GC, 0, mmVM_L2_CNTL3, 0);
  242. }
  243. /**
  244. * gfxhub_v1_0_set_fault_enable_default - update GART/VM fault handling
  245. *
  246. * @adev: amdgpu_device pointer
  247. * @value: true redirects VM faults to the default page
  248. */
  249. void gfxhub_v1_0_set_fault_enable_default(struct amdgpu_device *adev,
  250. bool value)
  251. {
  252. u32 tmp;
  253. tmp = RREG32_SOC15(GC, 0, mmVM_L2_PROTECTION_FAULT_CNTL);
  254. tmp = REG_SET_FIELD(tmp, VM_L2_PROTECTION_FAULT_CNTL,
  255. RANGE_PROTECTION_FAULT_ENABLE_DEFAULT, value);
  256. tmp = REG_SET_FIELD(tmp, VM_L2_PROTECTION_FAULT_CNTL,
  257. PDE0_PROTECTION_FAULT_ENABLE_DEFAULT, value);
  258. tmp = REG_SET_FIELD(tmp, VM_L2_PROTECTION_FAULT_CNTL,
  259. PDE1_PROTECTION_FAULT_ENABLE_DEFAULT, value);
  260. tmp = REG_SET_FIELD(tmp, VM_L2_PROTECTION_FAULT_CNTL,
  261. PDE2_PROTECTION_FAULT_ENABLE_DEFAULT, value);
  262. tmp = REG_SET_FIELD(tmp,
  263. VM_L2_PROTECTION_FAULT_CNTL,
  264. TRANSLATE_FURTHER_PROTECTION_FAULT_ENABLE_DEFAULT,
  265. value);
  266. tmp = REG_SET_FIELD(tmp, VM_L2_PROTECTION_FAULT_CNTL,
  267. NACK_PROTECTION_FAULT_ENABLE_DEFAULT, value);
  268. tmp = REG_SET_FIELD(tmp, VM_L2_PROTECTION_FAULT_CNTL,
  269. DUMMY_PAGE_PROTECTION_FAULT_ENABLE_DEFAULT, value);
  270. tmp = REG_SET_FIELD(tmp, VM_L2_PROTECTION_FAULT_CNTL,
  271. VALID_PROTECTION_FAULT_ENABLE_DEFAULT, value);
  272. tmp = REG_SET_FIELD(tmp, VM_L2_PROTECTION_FAULT_CNTL,
  273. READ_PROTECTION_FAULT_ENABLE_DEFAULT, value);
  274. tmp = REG_SET_FIELD(tmp, VM_L2_PROTECTION_FAULT_CNTL,
  275. WRITE_PROTECTION_FAULT_ENABLE_DEFAULT, value);
  276. tmp = REG_SET_FIELD(tmp, VM_L2_PROTECTION_FAULT_CNTL,
  277. EXECUTE_PROTECTION_FAULT_ENABLE_DEFAULT, value);
  278. WREG32_SOC15(GC, 0, mmVM_L2_PROTECTION_FAULT_CNTL, tmp);
  279. }
  280. void gfxhub_v1_0_init(struct amdgpu_device *adev)
  281. {
  282. struct amdgpu_vmhub *hub = &adev->vmhub[AMDGPU_GFXHUB];
  283. hub->ctx0_ptb_addr_lo32 =
  284. SOC15_REG_OFFSET(GC, 0,
  285. mmVM_CONTEXT0_PAGE_TABLE_BASE_ADDR_LO32);
  286. hub->ctx0_ptb_addr_hi32 =
  287. SOC15_REG_OFFSET(GC, 0,
  288. mmVM_CONTEXT0_PAGE_TABLE_BASE_ADDR_HI32);
  289. hub->vm_inv_eng0_req =
  290. SOC15_REG_OFFSET(GC, 0, mmVM_INVALIDATE_ENG0_REQ);
  291. hub->vm_inv_eng0_ack =
  292. SOC15_REG_OFFSET(GC, 0, mmVM_INVALIDATE_ENG0_ACK);
  293. hub->vm_context0_cntl =
  294. SOC15_REG_OFFSET(GC, 0, mmVM_CONTEXT0_CNTL);
  295. hub->vm_l2_pro_fault_status =
  296. SOC15_REG_OFFSET(GC, 0, mmVM_L2_PROTECTION_FAULT_STATUS);
  297. hub->vm_l2_pro_fault_cntl =
  298. SOC15_REG_OFFSET(GC, 0, mmVM_L2_PROTECTION_FAULT_CNTL);
  299. }