2 * Copyright 2016 Advanced Micro Devices, Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
24 #include "mmhub_v1_0.h"
26 #include "mmhub/mmhub_1_0_offset.h"
27 #include "mmhub/mmhub_1_0_sh_mask.h"
28 #include "mmhub/mmhub_1_0_default.h"
29 #include "athub/athub_1_0_offset.h"
30 #include "athub/athub_1_0_sh_mask.h"
31 #include "vega10_enum.h"
33 #include "soc15_common.h"
35 #define mmDAGB0_CNTL_MISC2_RV 0x008f
36 #define mmDAGB0_CNTL_MISC2_RV_BASE_IDX 0
38 u64 mmhub_v1_0_get_fb_location(struct amdgpu_device *adev)
40 u64 base = RREG32_SOC15(MMHUB, 0, mmMC_VM_FB_LOCATION_BASE);
41 u64 top = RREG32_SOC15(MMHUB, 0, mmMC_VM_FB_LOCATION_TOP);
43 base &= MC_VM_FB_LOCATION_BASE__FB_BASE_MASK;
46 top &= MC_VM_FB_LOCATION_TOP__FB_TOP_MASK;
49 adev->gmc.fb_start = base;
50 adev->gmc.fb_end = top;
55 static void mmhub_v1_0_init_gart_pt_regs(struct amdgpu_device *adev)
57 uint64_t value = amdgpu_gmc_pd_addr(adev->gart.bo);
59 WREG32_SOC15(MMHUB, 0, mmVM_CONTEXT0_PAGE_TABLE_BASE_ADDR_LO32,
60 lower_32_bits(value));
62 WREG32_SOC15(MMHUB, 0, mmVM_CONTEXT0_PAGE_TABLE_BASE_ADDR_HI32,
63 upper_32_bits(value));
66 static void mmhub_v1_0_init_gart_aperture_regs(struct amdgpu_device *adev)
68 mmhub_v1_0_init_gart_pt_regs(adev);
70 WREG32_SOC15(MMHUB, 0, mmVM_CONTEXT0_PAGE_TABLE_START_ADDR_LO32,
71 (u32)(adev->gmc.gart_start >> 12));
72 WREG32_SOC15(MMHUB, 0, mmVM_CONTEXT0_PAGE_TABLE_START_ADDR_HI32,
73 (u32)(adev->gmc.gart_start >> 44));
75 WREG32_SOC15(MMHUB, 0, mmVM_CONTEXT0_PAGE_TABLE_END_ADDR_LO32,
76 (u32)(adev->gmc.gart_end >> 12));
77 WREG32_SOC15(MMHUB, 0, mmVM_CONTEXT0_PAGE_TABLE_END_ADDR_HI32,
78 (u32)(adev->gmc.gart_end >> 44));
81 static void mmhub_v1_0_init_system_aperture_regs(struct amdgpu_device *adev)
86 /* Program the AGP BAR */
87 WREG32_SOC15(MMHUB, 0, mmMC_VM_AGP_BASE, 0);
88 WREG32_SOC15(MMHUB, 0, mmMC_VM_AGP_BOT, adev->gmc.agp_start >> 24);
89 WREG32_SOC15(MMHUB, 0, mmMC_VM_AGP_TOP, adev->gmc.agp_end >> 24);
91 /* Program the system aperture low logical page number. */
92 WREG32_SOC15(MMHUB, 0, mmMC_VM_SYSTEM_APERTURE_LOW_ADDR,
93 min(adev->gmc.vram_start, adev->gmc.agp_start) >> 18);
95 if (adev->asic_type == CHIP_RAVEN && adev->rev_id >= 0x8)
97 * Raven2 has a HW issue that it is unable to use the vram which
98 * is out of MC_VM_SYSTEM_APERTURE_HIGH_ADDR. So here is the
99 * workaround that increase system aperture high address (add 1)
100 * to get rid of the VM fault and hardware hang.
102 WREG32_SOC15(MMHUB, 0, mmMC_VM_SYSTEM_APERTURE_HIGH_ADDR,
103 max((adev->gmc.vram_end >> 18) + 0x1,
104 adev->gmc.agp_end >> 18));
106 WREG32_SOC15(MMHUB, 0, mmMC_VM_SYSTEM_APERTURE_HIGH_ADDR,
107 max(adev->gmc.vram_end, adev->gmc.agp_end) >> 18);
109 /* Set default page address. */
110 value = adev->vram_scratch.gpu_addr - adev->gmc.vram_start +
111 adev->vm_manager.vram_base_offset;
112 WREG32_SOC15(MMHUB, 0, mmMC_VM_SYSTEM_APERTURE_DEFAULT_ADDR_LSB,
114 WREG32_SOC15(MMHUB, 0, mmMC_VM_SYSTEM_APERTURE_DEFAULT_ADDR_MSB,
117 /* Program "protection fault". */
118 WREG32_SOC15(MMHUB, 0, mmVM_L2_PROTECTION_FAULT_DEFAULT_ADDR_LO32,
119 (u32)(adev->dummy_page_addr >> 12));
120 WREG32_SOC15(MMHUB, 0, mmVM_L2_PROTECTION_FAULT_DEFAULT_ADDR_HI32,
121 (u32)((u64)adev->dummy_page_addr >> 44));
123 tmp = RREG32_SOC15(MMHUB, 0, mmVM_L2_PROTECTION_FAULT_CNTL2);
124 tmp = REG_SET_FIELD(tmp, VM_L2_PROTECTION_FAULT_CNTL2,
125 ACTIVE_PAGE_MIGRATION_PTE_READ_RETRY, 1);
126 WREG32_SOC15(MMHUB, 0, mmVM_L2_PROTECTION_FAULT_CNTL2, tmp);
129 static void mmhub_v1_0_init_tlb_regs(struct amdgpu_device *adev)
133 /* Setup TLB control */
134 tmp = RREG32_SOC15(MMHUB, 0, mmMC_VM_MX_L1_TLB_CNTL);
136 tmp = REG_SET_FIELD(tmp, MC_VM_MX_L1_TLB_CNTL, ENABLE_L1_TLB, 1);
137 tmp = REG_SET_FIELD(tmp, MC_VM_MX_L1_TLB_CNTL, SYSTEM_ACCESS_MODE, 3);
138 tmp = REG_SET_FIELD(tmp, MC_VM_MX_L1_TLB_CNTL,
139 ENABLE_ADVANCED_DRIVER_MODEL, 1);
140 tmp = REG_SET_FIELD(tmp, MC_VM_MX_L1_TLB_CNTL,
141 SYSTEM_APERTURE_UNMAPPED_ACCESS, 0);
142 tmp = REG_SET_FIELD(tmp, MC_VM_MX_L1_TLB_CNTL, ECO_BITS, 0);
143 tmp = REG_SET_FIELD(tmp, MC_VM_MX_L1_TLB_CNTL,
144 MTYPE, MTYPE_UC);/* XXX for emulation. */
145 tmp = REG_SET_FIELD(tmp, MC_VM_MX_L1_TLB_CNTL, ATC_EN, 1);
147 WREG32_SOC15(MMHUB, 0, mmMC_VM_MX_L1_TLB_CNTL, tmp);
150 static void mmhub_v1_0_init_cache_regs(struct amdgpu_device *adev)
155 tmp = RREG32_SOC15(MMHUB, 0, mmVM_L2_CNTL);
156 tmp = REG_SET_FIELD(tmp, VM_L2_CNTL, ENABLE_L2_CACHE, 1);
157 tmp = REG_SET_FIELD(tmp, VM_L2_CNTL, ENABLE_L2_FRAGMENT_PROCESSING, 1);
158 /* XXX for emulation, Refer to closed source code.*/
159 tmp = REG_SET_FIELD(tmp, VM_L2_CNTL, L2_PDE0_CACHE_TAG_GENERATION_MODE,
161 tmp = REG_SET_FIELD(tmp, VM_L2_CNTL, PDE_FAULT_CLASSIFICATION, 1);
162 tmp = REG_SET_FIELD(tmp, VM_L2_CNTL, CONTEXT1_IDENTITY_ACCESS_MODE, 1);
163 tmp = REG_SET_FIELD(tmp, VM_L2_CNTL, IDENTITY_MODE_FRAGMENT_SIZE, 0);
164 WREG32_SOC15(MMHUB, 0, mmVM_L2_CNTL, tmp);
166 tmp = RREG32_SOC15(MMHUB, 0, mmVM_L2_CNTL2);
167 tmp = REG_SET_FIELD(tmp, VM_L2_CNTL2, INVALIDATE_ALL_L1_TLBS, 1);
168 tmp = REG_SET_FIELD(tmp, VM_L2_CNTL2, INVALIDATE_L2_CACHE, 1);
169 WREG32_SOC15(MMHUB, 0, mmVM_L2_CNTL2, tmp);
171 if (adev->gmc.translate_further) {
172 tmp = REG_SET_FIELD(tmp, VM_L2_CNTL3, BANK_SELECT, 12);
173 tmp = REG_SET_FIELD(tmp, VM_L2_CNTL3,
174 L2_CACHE_BIGK_FRAGMENT_SIZE, 9);
176 tmp = REG_SET_FIELD(tmp, VM_L2_CNTL3, BANK_SELECT, 9);
177 tmp = REG_SET_FIELD(tmp, VM_L2_CNTL3,
178 L2_CACHE_BIGK_FRAGMENT_SIZE, 6);
181 tmp = mmVM_L2_CNTL4_DEFAULT;
182 tmp = REG_SET_FIELD(tmp, VM_L2_CNTL4, VMC_TAP_PDE_REQUEST_PHYSICAL, 0);
183 tmp = REG_SET_FIELD(tmp, VM_L2_CNTL4, VMC_TAP_PTE_REQUEST_PHYSICAL, 0);
184 WREG32_SOC15(MMHUB, 0, mmVM_L2_CNTL4, tmp);
187 static void mmhub_v1_0_enable_system_domain(struct amdgpu_device *adev)
191 tmp = RREG32_SOC15(MMHUB, 0, mmVM_CONTEXT0_CNTL);
192 tmp = REG_SET_FIELD(tmp, VM_CONTEXT0_CNTL, ENABLE_CONTEXT, 1);
193 tmp = REG_SET_FIELD(tmp, VM_CONTEXT0_CNTL, PAGE_TABLE_DEPTH, 0);
194 WREG32_SOC15(MMHUB, 0, mmVM_CONTEXT0_CNTL, tmp);
197 static void mmhub_v1_0_disable_identity_aperture(struct amdgpu_device *adev)
199 WREG32_SOC15(MMHUB, 0, mmVM_L2_CONTEXT1_IDENTITY_APERTURE_LOW_ADDR_LO32,
201 WREG32_SOC15(MMHUB, 0, mmVM_L2_CONTEXT1_IDENTITY_APERTURE_LOW_ADDR_HI32,
204 WREG32_SOC15(MMHUB, 0,
205 mmVM_L2_CONTEXT1_IDENTITY_APERTURE_HIGH_ADDR_LO32, 0);
206 WREG32_SOC15(MMHUB, 0,
207 mmVM_L2_CONTEXT1_IDENTITY_APERTURE_HIGH_ADDR_HI32, 0);
209 WREG32_SOC15(MMHUB, 0, mmVM_L2_CONTEXT_IDENTITY_PHYSICAL_OFFSET_LO32,
211 WREG32_SOC15(MMHUB, 0, mmVM_L2_CONTEXT_IDENTITY_PHYSICAL_OFFSET_HI32,
215 static void mmhub_v1_0_setup_vmid_config(struct amdgpu_device *adev)
217 unsigned num_level, block_size;
221 num_level = adev->vm_manager.num_level;
222 block_size = adev->vm_manager.block_size;
223 if (adev->gmc.translate_further)
228 for (i = 0; i <= 14; i++) {
229 tmp = RREG32_SOC15_OFFSET(MMHUB, 0, mmVM_CONTEXT1_CNTL, i);
230 tmp = REG_SET_FIELD(tmp, VM_CONTEXT1_CNTL, ENABLE_CONTEXT, 1);
231 tmp = REG_SET_FIELD(tmp, VM_CONTEXT1_CNTL, PAGE_TABLE_DEPTH,
233 tmp = REG_SET_FIELD(tmp, VM_CONTEXT1_CNTL,
234 RANGE_PROTECTION_FAULT_ENABLE_DEFAULT, 1);
235 tmp = REG_SET_FIELD(tmp, VM_CONTEXT1_CNTL,
236 DUMMY_PAGE_PROTECTION_FAULT_ENABLE_DEFAULT,
238 tmp = REG_SET_FIELD(tmp, VM_CONTEXT1_CNTL,
239 PDE0_PROTECTION_FAULT_ENABLE_DEFAULT, 1);
240 tmp = REG_SET_FIELD(tmp, VM_CONTEXT1_CNTL,
241 VALID_PROTECTION_FAULT_ENABLE_DEFAULT, 1);
242 tmp = REG_SET_FIELD(tmp, VM_CONTEXT1_CNTL,
243 READ_PROTECTION_FAULT_ENABLE_DEFAULT, 1);
244 tmp = REG_SET_FIELD(tmp, VM_CONTEXT1_CNTL,
245 WRITE_PROTECTION_FAULT_ENABLE_DEFAULT, 1);
246 tmp = REG_SET_FIELD(tmp, VM_CONTEXT1_CNTL,
247 EXECUTE_PROTECTION_FAULT_ENABLE_DEFAULT, 1);
248 tmp = REG_SET_FIELD(tmp, VM_CONTEXT1_CNTL,
249 PAGE_TABLE_BLOCK_SIZE,
251 /* Send no-retry XNACK on fault to suppress VM fault storm. */
252 tmp = REG_SET_FIELD(tmp, VM_CONTEXT1_CNTL,
253 RETRY_PERMISSION_OR_INVALID_PAGE_FAULT, 0);
254 WREG32_SOC15_OFFSET(MMHUB, 0, mmVM_CONTEXT1_CNTL, i, tmp);
255 WREG32_SOC15_OFFSET(MMHUB, 0, mmVM_CONTEXT1_PAGE_TABLE_START_ADDR_LO32, i*2, 0);
256 WREG32_SOC15_OFFSET(MMHUB, 0, mmVM_CONTEXT1_PAGE_TABLE_START_ADDR_HI32, i*2, 0);
257 WREG32_SOC15_OFFSET(MMHUB, 0, mmVM_CONTEXT1_PAGE_TABLE_END_ADDR_LO32, i*2,
258 lower_32_bits(adev->vm_manager.max_pfn - 1));
259 WREG32_SOC15_OFFSET(MMHUB, 0, mmVM_CONTEXT1_PAGE_TABLE_END_ADDR_HI32, i*2,
260 upper_32_bits(adev->vm_manager.max_pfn - 1));
264 static void mmhub_v1_0_program_invalidation(struct amdgpu_device *adev)
268 for (i = 0; i < 18; ++i) {
269 WREG32_SOC15_OFFSET(MMHUB, 0, mmVM_INVALIDATE_ENG0_ADDR_RANGE_LO32,
271 WREG32_SOC15_OFFSET(MMHUB, 0, mmVM_INVALIDATE_ENG0_ADDR_RANGE_HI32,
276 void mmhub_v1_0_update_power_gating(struct amdgpu_device *adev,
279 if (amdgpu_sriov_vf(adev))
282 if (enable && adev->pg_flags & AMD_PG_SUPPORT_MMHUB) {
283 if (adev->powerplay.pp_funcs->set_powergating_by_smu)
284 amdgpu_dpm_set_powergating_by_smu(adev, AMD_IP_BLOCK_TYPE_GMC, true);
289 int mmhub_v1_0_gart_enable(struct amdgpu_device *adev)
291 if (amdgpu_sriov_vf(adev)) {
293 * MC_VM_FB_LOCATION_BASE/TOP is NULL for VF, becuase they are
294 * VF copy registers so vbios post doesn't program them, for
295 * SRIOV driver need to program them
297 WREG32_SOC15(MMHUB, 0, mmMC_VM_FB_LOCATION_BASE,
298 adev->gmc.vram_start >> 24);
299 WREG32_SOC15(MMHUB, 0, mmMC_VM_FB_LOCATION_TOP,
300 adev->gmc.vram_end >> 24);
304 mmhub_v1_0_init_gart_aperture_regs(adev);
305 mmhub_v1_0_init_system_aperture_regs(adev);
306 mmhub_v1_0_init_tlb_regs(adev);
307 mmhub_v1_0_init_cache_regs(adev);
309 mmhub_v1_0_enable_system_domain(adev);
310 mmhub_v1_0_disable_identity_aperture(adev);
311 mmhub_v1_0_setup_vmid_config(adev);
312 mmhub_v1_0_program_invalidation(adev);
317 void mmhub_v1_0_gart_disable(struct amdgpu_device *adev)
322 /* Disable all tables */
323 for (i = 0; i < 16; i++)
324 WREG32_SOC15_OFFSET(MMHUB, 0, mmVM_CONTEXT0_CNTL, i, 0);
326 /* Setup TLB control */
327 tmp = RREG32_SOC15(MMHUB, 0, mmMC_VM_MX_L1_TLB_CNTL);
328 tmp = REG_SET_FIELD(tmp, MC_VM_MX_L1_TLB_CNTL, ENABLE_L1_TLB, 0);
329 tmp = REG_SET_FIELD(tmp,
330 MC_VM_MX_L1_TLB_CNTL,
331 ENABLE_ADVANCED_DRIVER_MODEL,
333 WREG32_SOC15(MMHUB, 0, mmMC_VM_MX_L1_TLB_CNTL, tmp);
336 tmp = RREG32_SOC15(MMHUB, 0, mmVM_L2_CNTL);
337 tmp = REG_SET_FIELD(tmp, VM_L2_CNTL, ENABLE_L2_CACHE, 0);
338 WREG32_SOC15(MMHUB, 0, mmVM_L2_CNTL, tmp);
339 WREG32_SOC15(MMHUB, 0, mmVM_L2_CNTL3, 0);
343 * mmhub_v1_0_set_fault_enable_default - update GART/VM fault handling
345 * @adev: amdgpu_device pointer
346 * @value: true redirects VM faults to the default page
348 void mmhub_v1_0_set_fault_enable_default(struct amdgpu_device *adev, bool value)
351 tmp = RREG32_SOC15(MMHUB, 0, mmVM_L2_PROTECTION_FAULT_CNTL);
352 tmp = REG_SET_FIELD(tmp, VM_L2_PROTECTION_FAULT_CNTL,
353 RANGE_PROTECTION_FAULT_ENABLE_DEFAULT, value);
354 tmp = REG_SET_FIELD(tmp, VM_L2_PROTECTION_FAULT_CNTL,
355 PDE0_PROTECTION_FAULT_ENABLE_DEFAULT, value);
356 tmp = REG_SET_FIELD(tmp, VM_L2_PROTECTION_FAULT_CNTL,
357 PDE1_PROTECTION_FAULT_ENABLE_DEFAULT, value);
358 tmp = REG_SET_FIELD(tmp, VM_L2_PROTECTION_FAULT_CNTL,
359 PDE2_PROTECTION_FAULT_ENABLE_DEFAULT, value);
360 tmp = REG_SET_FIELD(tmp,
361 VM_L2_PROTECTION_FAULT_CNTL,
362 TRANSLATE_FURTHER_PROTECTION_FAULT_ENABLE_DEFAULT,
364 tmp = REG_SET_FIELD(tmp, VM_L2_PROTECTION_FAULT_CNTL,
365 NACK_PROTECTION_FAULT_ENABLE_DEFAULT, value);
366 tmp = REG_SET_FIELD(tmp, VM_L2_PROTECTION_FAULT_CNTL,
367 DUMMY_PAGE_PROTECTION_FAULT_ENABLE_DEFAULT, value);
368 tmp = REG_SET_FIELD(tmp, VM_L2_PROTECTION_FAULT_CNTL,
369 VALID_PROTECTION_FAULT_ENABLE_DEFAULT, value);
370 tmp = REG_SET_FIELD(tmp, VM_L2_PROTECTION_FAULT_CNTL,
371 READ_PROTECTION_FAULT_ENABLE_DEFAULT, value);
372 tmp = REG_SET_FIELD(tmp, VM_L2_PROTECTION_FAULT_CNTL,
373 WRITE_PROTECTION_FAULT_ENABLE_DEFAULT, value);
374 tmp = REG_SET_FIELD(tmp, VM_L2_PROTECTION_FAULT_CNTL,
375 EXECUTE_PROTECTION_FAULT_ENABLE_DEFAULT, value);
377 tmp = REG_SET_FIELD(tmp, VM_L2_PROTECTION_FAULT_CNTL,
378 CRASH_ON_NO_RETRY_FAULT, 1);
379 tmp = REG_SET_FIELD(tmp, VM_L2_PROTECTION_FAULT_CNTL,
380 CRASH_ON_RETRY_FAULT, 1);
383 WREG32_SOC15(MMHUB, 0, mmVM_L2_PROTECTION_FAULT_CNTL, tmp);
386 void mmhub_v1_0_init(struct amdgpu_device *adev)
388 struct amdgpu_vmhub *hub = &adev->vmhub[AMDGPU_MMHUB];
390 hub->ctx0_ptb_addr_lo32 =
391 SOC15_REG_OFFSET(MMHUB, 0,
392 mmVM_CONTEXT0_PAGE_TABLE_BASE_ADDR_LO32);
393 hub->ctx0_ptb_addr_hi32 =
394 SOC15_REG_OFFSET(MMHUB, 0,
395 mmVM_CONTEXT0_PAGE_TABLE_BASE_ADDR_HI32);
396 hub->vm_inv_eng0_req =
397 SOC15_REG_OFFSET(MMHUB, 0, mmVM_INVALIDATE_ENG0_REQ);
398 hub->vm_inv_eng0_ack =
399 SOC15_REG_OFFSET(MMHUB, 0, mmVM_INVALIDATE_ENG0_ACK);
400 hub->vm_context0_cntl =
401 SOC15_REG_OFFSET(MMHUB, 0, mmVM_CONTEXT0_CNTL);
402 hub->vm_l2_pro_fault_status =
403 SOC15_REG_OFFSET(MMHUB, 0, mmVM_L2_PROTECTION_FAULT_STATUS);
404 hub->vm_l2_pro_fault_cntl =
405 SOC15_REG_OFFSET(MMHUB, 0, mmVM_L2_PROTECTION_FAULT_CNTL);
409 static void mmhub_v1_0_update_medium_grain_clock_gating(struct amdgpu_device *adev,
412 uint32_t def, data, def1, data1, def2 = 0, data2 = 0;
414 def = data = RREG32_SOC15(MMHUB, 0, mmATC_L2_MISC_CG);
416 if (adev->asic_type != CHIP_RAVEN) {
417 def1 = data1 = RREG32_SOC15(MMHUB, 0, mmDAGB0_CNTL_MISC2);
418 def2 = data2 = RREG32_SOC15(MMHUB, 0, mmDAGB1_CNTL_MISC2);
420 def1 = data1 = RREG32_SOC15(MMHUB, 0, mmDAGB0_CNTL_MISC2_RV);
422 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_MC_MGCG)) {
423 data |= ATC_L2_MISC_CG__ENABLE_MASK;
425 data1 &= ~(DAGB0_CNTL_MISC2__DISABLE_WRREQ_CG_MASK |
426 DAGB0_CNTL_MISC2__DISABLE_WRRET_CG_MASK |
427 DAGB0_CNTL_MISC2__DISABLE_RDREQ_CG_MASK |
428 DAGB0_CNTL_MISC2__DISABLE_RDRET_CG_MASK |
429 DAGB0_CNTL_MISC2__DISABLE_TLBWR_CG_MASK |
430 DAGB0_CNTL_MISC2__DISABLE_TLBRD_CG_MASK);
432 if (adev->asic_type != CHIP_RAVEN)
433 data2 &= ~(DAGB1_CNTL_MISC2__DISABLE_WRREQ_CG_MASK |
434 DAGB1_CNTL_MISC2__DISABLE_WRRET_CG_MASK |
435 DAGB1_CNTL_MISC2__DISABLE_RDREQ_CG_MASK |
436 DAGB1_CNTL_MISC2__DISABLE_RDRET_CG_MASK |
437 DAGB1_CNTL_MISC2__DISABLE_TLBWR_CG_MASK |
438 DAGB1_CNTL_MISC2__DISABLE_TLBRD_CG_MASK);
440 data &= ~ATC_L2_MISC_CG__ENABLE_MASK;
442 data1 |= (DAGB0_CNTL_MISC2__DISABLE_WRREQ_CG_MASK |
443 DAGB0_CNTL_MISC2__DISABLE_WRRET_CG_MASK |
444 DAGB0_CNTL_MISC2__DISABLE_RDREQ_CG_MASK |
445 DAGB0_CNTL_MISC2__DISABLE_RDRET_CG_MASK |
446 DAGB0_CNTL_MISC2__DISABLE_TLBWR_CG_MASK |
447 DAGB0_CNTL_MISC2__DISABLE_TLBRD_CG_MASK);
449 if (adev->asic_type != CHIP_RAVEN)
450 data2 |= (DAGB1_CNTL_MISC2__DISABLE_WRREQ_CG_MASK |
451 DAGB1_CNTL_MISC2__DISABLE_WRRET_CG_MASK |
452 DAGB1_CNTL_MISC2__DISABLE_RDREQ_CG_MASK |
453 DAGB1_CNTL_MISC2__DISABLE_RDRET_CG_MASK |
454 DAGB1_CNTL_MISC2__DISABLE_TLBWR_CG_MASK |
455 DAGB1_CNTL_MISC2__DISABLE_TLBRD_CG_MASK);
459 WREG32_SOC15(MMHUB, 0, mmATC_L2_MISC_CG, data);
462 if (adev->asic_type != CHIP_RAVEN)
463 WREG32_SOC15(MMHUB, 0, mmDAGB0_CNTL_MISC2, data1);
465 WREG32_SOC15(MMHUB, 0, mmDAGB0_CNTL_MISC2_RV, data1);
468 if (adev->asic_type != CHIP_RAVEN && def2 != data2)
469 WREG32_SOC15(MMHUB, 0, mmDAGB1_CNTL_MISC2, data2);
472 static void athub_update_medium_grain_clock_gating(struct amdgpu_device *adev,
477 def = data = RREG32_SOC15(ATHUB, 0, mmATHUB_MISC_CNTL);
479 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_MC_MGCG))
480 data |= ATHUB_MISC_CNTL__CG_ENABLE_MASK;
482 data &= ~ATHUB_MISC_CNTL__CG_ENABLE_MASK;
485 WREG32_SOC15(ATHUB, 0, mmATHUB_MISC_CNTL, data);
488 static void mmhub_v1_0_update_medium_grain_light_sleep(struct amdgpu_device *adev,
493 def = data = RREG32_SOC15(MMHUB, 0, mmATC_L2_MISC_CG);
495 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_MC_LS))
496 data |= ATC_L2_MISC_CG__MEM_LS_ENABLE_MASK;
498 data &= ~ATC_L2_MISC_CG__MEM_LS_ENABLE_MASK;
501 WREG32_SOC15(MMHUB, 0, mmATC_L2_MISC_CG, data);
504 static void athub_update_medium_grain_light_sleep(struct amdgpu_device *adev,
509 def = data = RREG32_SOC15(ATHUB, 0, mmATHUB_MISC_CNTL);
511 if (enable && (adev->cg_flags & AMD_CG_SUPPORT_MC_LS) &&
512 (adev->cg_flags & AMD_CG_SUPPORT_HDP_LS))
513 data |= ATHUB_MISC_CNTL__CG_MEM_LS_ENABLE_MASK;
515 data &= ~ATHUB_MISC_CNTL__CG_MEM_LS_ENABLE_MASK;
518 WREG32_SOC15(ATHUB, 0, mmATHUB_MISC_CNTL, data);
521 int mmhub_v1_0_set_clockgating(struct amdgpu_device *adev,
522 enum amd_clockgating_state state)
524 if (amdgpu_sriov_vf(adev))
527 switch (adev->asic_type) {
532 mmhub_v1_0_update_medium_grain_clock_gating(adev,
533 state == AMD_CG_STATE_GATE ? true : false);
534 athub_update_medium_grain_clock_gating(adev,
535 state == AMD_CG_STATE_GATE ? true : false);
536 mmhub_v1_0_update_medium_grain_light_sleep(adev,
537 state == AMD_CG_STATE_GATE ? true : false);
538 athub_update_medium_grain_light_sleep(adev,
539 state == AMD_CG_STATE_GATE ? true : false);
548 void mmhub_v1_0_get_clockgating(struct amdgpu_device *adev, u32 *flags)
552 if (amdgpu_sriov_vf(adev))
555 /* AMD_CG_SUPPORT_MC_MGCG */
556 data = RREG32_SOC15(ATHUB, 0, mmATHUB_MISC_CNTL);
557 if (data & ATHUB_MISC_CNTL__CG_ENABLE_MASK)
558 *flags |= AMD_CG_SUPPORT_MC_MGCG;
560 /* AMD_CG_SUPPORT_MC_LS */
561 data = RREG32_SOC15(MMHUB, 0, mmATC_L2_MISC_CG);
562 if (data & ATC_L2_MISC_CG__MEM_LS_ENABLE_MASK)
563 *flags |= AMD_CG_SUPPORT_MC_LS;