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 <linux/firmware.h>
25 #include <linux/pci.h>
27 #include <drm/drm_cache.h>
31 #include "amdgpu_atomfirmware.h"
32 #include "amdgpu_gem.h"
34 #include "hdp/hdp_4_0_offset.h"
35 #include "hdp/hdp_4_0_sh_mask.h"
36 #include "gc/gc_9_0_sh_mask.h"
37 #include "dce/dce_12_0_offset.h"
38 #include "dce/dce_12_0_sh_mask.h"
39 #include "vega10_enum.h"
40 #include "mmhub/mmhub_1_0_offset.h"
41 #include "athub/athub_1_0_offset.h"
42 #include "oss/osssys_4_0_offset.h"
45 #include "soc15_common.h"
46 #include "umc/umc_6_0_sh_mask.h"
48 #include "gfxhub_v1_0.h"
49 #include "mmhub_v1_0.h"
50 #include "athub_v1_0.h"
51 #include "gfxhub_v1_1.h"
52 #include "mmhub_v9_4.h"
55 #include "ivsrcid/vmc/irqsrcs_vmc_1_0.h"
57 #include "amdgpu_ras.h"
59 /* add these here since we already include dce12 headers and these are for DCN */
60 #define mmHUBP0_DCSURF_PRI_VIEWPORT_DIMENSION 0x055d
61 #define mmHUBP0_DCSURF_PRI_VIEWPORT_DIMENSION_BASE_IDX 2
62 #define HUBP0_DCSURF_PRI_VIEWPORT_DIMENSION__PRI_VIEWPORT_WIDTH__SHIFT 0x0
63 #define HUBP0_DCSURF_PRI_VIEWPORT_DIMENSION__PRI_VIEWPORT_HEIGHT__SHIFT 0x10
64 #define HUBP0_DCSURF_PRI_VIEWPORT_DIMENSION__PRI_VIEWPORT_WIDTH_MASK 0x00003FFFL
65 #define HUBP0_DCSURF_PRI_VIEWPORT_DIMENSION__PRI_VIEWPORT_HEIGHT_MASK 0x3FFF0000L
67 /* XXX Move this macro to VEGA10 header file, which is like vid.h for VI.*/
68 #define AMDGPU_NUM_OF_VMIDS 8
70 static const u32 golden_settings_vega10_hdp[] =
72 0xf64, 0x0fffffff, 0x00000000,
73 0xf65, 0x0fffffff, 0x00000000,
74 0xf66, 0x0fffffff, 0x00000000,
75 0xf67, 0x0fffffff, 0x00000000,
76 0xf68, 0x0fffffff, 0x00000000,
77 0xf6a, 0x0fffffff, 0x00000000,
78 0xf6b, 0x0fffffff, 0x00000000,
79 0xf6c, 0x0fffffff, 0x00000000,
80 0xf6d, 0x0fffffff, 0x00000000,
81 0xf6e, 0x0fffffff, 0x00000000,
84 static const struct soc15_reg_golden golden_settings_mmhub_1_0_0[] =
86 SOC15_REG_GOLDEN_VALUE(MMHUB, 0, mmDAGB1_WRCLI2, 0x00000007, 0xfe5fe0fa),
87 SOC15_REG_GOLDEN_VALUE(MMHUB, 0, mmMMEA1_DRAM_WR_CLI2GRP_MAP0, 0x00000030, 0x55555565)
90 static const struct soc15_reg_golden golden_settings_athub_1_0_0[] =
92 SOC15_REG_GOLDEN_VALUE(ATHUB, 0, mmRPB_ARB_CNTL, 0x0000ff00, 0x00000800),
93 SOC15_REG_GOLDEN_VALUE(ATHUB, 0, mmRPB_ARB_CNTL2, 0x00ff00ff, 0x00080008)
96 static const uint32_t ecc_umc_mcumc_ctrl_addrs[] = {
97 (0x000143c0 + 0x00000000),
98 (0x000143c0 + 0x00000800),
99 (0x000143c0 + 0x00001000),
100 (0x000143c0 + 0x00001800),
101 (0x000543c0 + 0x00000000),
102 (0x000543c0 + 0x00000800),
103 (0x000543c0 + 0x00001000),
104 (0x000543c0 + 0x00001800),
105 (0x000943c0 + 0x00000000),
106 (0x000943c0 + 0x00000800),
107 (0x000943c0 + 0x00001000),
108 (0x000943c0 + 0x00001800),
109 (0x000d43c0 + 0x00000000),
110 (0x000d43c0 + 0x00000800),
111 (0x000d43c0 + 0x00001000),
112 (0x000d43c0 + 0x00001800),
113 (0x001143c0 + 0x00000000),
114 (0x001143c0 + 0x00000800),
115 (0x001143c0 + 0x00001000),
116 (0x001143c0 + 0x00001800),
117 (0x001543c0 + 0x00000000),
118 (0x001543c0 + 0x00000800),
119 (0x001543c0 + 0x00001000),
120 (0x001543c0 + 0x00001800),
121 (0x001943c0 + 0x00000000),
122 (0x001943c0 + 0x00000800),
123 (0x001943c0 + 0x00001000),
124 (0x001943c0 + 0x00001800),
125 (0x001d43c0 + 0x00000000),
126 (0x001d43c0 + 0x00000800),
127 (0x001d43c0 + 0x00001000),
128 (0x001d43c0 + 0x00001800),
131 static const uint32_t ecc_umc_mcumc_ctrl_mask_addrs[] = {
132 (0x000143e0 + 0x00000000),
133 (0x000143e0 + 0x00000800),
134 (0x000143e0 + 0x00001000),
135 (0x000143e0 + 0x00001800),
136 (0x000543e0 + 0x00000000),
137 (0x000543e0 + 0x00000800),
138 (0x000543e0 + 0x00001000),
139 (0x000543e0 + 0x00001800),
140 (0x000943e0 + 0x00000000),
141 (0x000943e0 + 0x00000800),
142 (0x000943e0 + 0x00001000),
143 (0x000943e0 + 0x00001800),
144 (0x000d43e0 + 0x00000000),
145 (0x000d43e0 + 0x00000800),
146 (0x000d43e0 + 0x00001000),
147 (0x000d43e0 + 0x00001800),
148 (0x001143e0 + 0x00000000),
149 (0x001143e0 + 0x00000800),
150 (0x001143e0 + 0x00001000),
151 (0x001143e0 + 0x00001800),
152 (0x001543e0 + 0x00000000),
153 (0x001543e0 + 0x00000800),
154 (0x001543e0 + 0x00001000),
155 (0x001543e0 + 0x00001800),
156 (0x001943e0 + 0x00000000),
157 (0x001943e0 + 0x00000800),
158 (0x001943e0 + 0x00001000),
159 (0x001943e0 + 0x00001800),
160 (0x001d43e0 + 0x00000000),
161 (0x001d43e0 + 0x00000800),
162 (0x001d43e0 + 0x00001000),
163 (0x001d43e0 + 0x00001800),
166 static const uint32_t ecc_umc_mcumc_status_addrs[] = {
167 (0x000143c2 + 0x00000000),
168 (0x000143c2 + 0x00000800),
169 (0x000143c2 + 0x00001000),
170 (0x000143c2 + 0x00001800),
171 (0x000543c2 + 0x00000000),
172 (0x000543c2 + 0x00000800),
173 (0x000543c2 + 0x00001000),
174 (0x000543c2 + 0x00001800),
175 (0x000943c2 + 0x00000000),
176 (0x000943c2 + 0x00000800),
177 (0x000943c2 + 0x00001000),
178 (0x000943c2 + 0x00001800),
179 (0x000d43c2 + 0x00000000),
180 (0x000d43c2 + 0x00000800),
181 (0x000d43c2 + 0x00001000),
182 (0x000d43c2 + 0x00001800),
183 (0x001143c2 + 0x00000000),
184 (0x001143c2 + 0x00000800),
185 (0x001143c2 + 0x00001000),
186 (0x001143c2 + 0x00001800),
187 (0x001543c2 + 0x00000000),
188 (0x001543c2 + 0x00000800),
189 (0x001543c2 + 0x00001000),
190 (0x001543c2 + 0x00001800),
191 (0x001943c2 + 0x00000000),
192 (0x001943c2 + 0x00000800),
193 (0x001943c2 + 0x00001000),
194 (0x001943c2 + 0x00001800),
195 (0x001d43c2 + 0x00000000),
196 (0x001d43c2 + 0x00000800),
197 (0x001d43c2 + 0x00001000),
198 (0x001d43c2 + 0x00001800),
201 static int gmc_v9_0_ecc_interrupt_state(struct amdgpu_device *adev,
202 struct amdgpu_irq_src *src,
204 enum amdgpu_interrupt_state state)
206 u32 bits, i, tmp, reg;
211 case AMDGPU_IRQ_STATE_DISABLE:
212 for (i = 0; i < ARRAY_SIZE(ecc_umc_mcumc_ctrl_addrs); i++) {
213 reg = ecc_umc_mcumc_ctrl_addrs[i];
218 for (i = 0; i < ARRAY_SIZE(ecc_umc_mcumc_ctrl_mask_addrs); i++) {
219 reg = ecc_umc_mcumc_ctrl_mask_addrs[i];
225 case AMDGPU_IRQ_STATE_ENABLE:
226 for (i = 0; i < ARRAY_SIZE(ecc_umc_mcumc_ctrl_addrs); i++) {
227 reg = ecc_umc_mcumc_ctrl_addrs[i];
232 for (i = 0; i < ARRAY_SIZE(ecc_umc_mcumc_ctrl_mask_addrs); i++) {
233 reg = ecc_umc_mcumc_ctrl_mask_addrs[i];
246 static int gmc_v9_0_process_ras_data_cb(struct amdgpu_device *adev,
247 struct ras_err_data *err_data,
248 struct amdgpu_iv_entry *entry)
250 kgd2kfd_set_sram_ecc_flag(adev->kfd.dev);
251 if (adev->umc.funcs->query_ras_error_count)
252 adev->umc.funcs->query_ras_error_count(adev, err_data);
253 /* umc query_ras_error_address is also responsible for clearing
256 if (adev->umc.funcs->query_ras_error_address)
257 adev->umc.funcs->query_ras_error_address(adev, err_data);
259 /* only uncorrectable error needs gpu reset */
260 if (err_data->ue_count)
261 amdgpu_ras_reset_gpu(adev, 0);
263 return AMDGPU_RAS_SUCCESS;
266 static int gmc_v9_0_process_ecc_irq(struct amdgpu_device *adev,
267 struct amdgpu_irq_src *source,
268 struct amdgpu_iv_entry *entry)
270 struct ras_common_if *ras_if = adev->gmc.umc_ras_if;
271 struct ras_dispatch_if ih_data = {
278 ih_data.head = *ras_if;
280 amdgpu_ras_interrupt_dispatch(adev, &ih_data);
284 static int gmc_v9_0_vm_fault_interrupt_state(struct amdgpu_device *adev,
285 struct amdgpu_irq_src *src,
287 enum amdgpu_interrupt_state state)
289 struct amdgpu_vmhub *hub;
290 u32 tmp, reg, bits, i, j;
292 bits = VM_CONTEXT1_CNTL__RANGE_PROTECTION_FAULT_ENABLE_INTERRUPT_MASK |
293 VM_CONTEXT1_CNTL__DUMMY_PAGE_PROTECTION_FAULT_ENABLE_INTERRUPT_MASK |
294 VM_CONTEXT1_CNTL__PDE0_PROTECTION_FAULT_ENABLE_INTERRUPT_MASK |
295 VM_CONTEXT1_CNTL__VALID_PROTECTION_FAULT_ENABLE_INTERRUPT_MASK |
296 VM_CONTEXT1_CNTL__READ_PROTECTION_FAULT_ENABLE_INTERRUPT_MASK |
297 VM_CONTEXT1_CNTL__WRITE_PROTECTION_FAULT_ENABLE_INTERRUPT_MASK |
298 VM_CONTEXT1_CNTL__EXECUTE_PROTECTION_FAULT_ENABLE_INTERRUPT_MASK;
301 case AMDGPU_IRQ_STATE_DISABLE:
302 for (j = 0; j < adev->num_vmhubs; j++) {
303 hub = &adev->vmhub[j];
304 for (i = 0; i < 16; i++) {
305 reg = hub->vm_context0_cntl + i;
312 case AMDGPU_IRQ_STATE_ENABLE:
313 for (j = 0; j < adev->num_vmhubs; j++) {
314 hub = &adev->vmhub[j];
315 for (i = 0; i < 16; i++) {
316 reg = hub->vm_context0_cntl + i;
329 static int gmc_v9_0_process_interrupt(struct amdgpu_device *adev,
330 struct amdgpu_irq_src *source,
331 struct amdgpu_iv_entry *entry)
333 struct amdgpu_vmhub *hub;
334 bool retry_fault = !!(entry->src_data[1] & 0x80);
339 addr = (u64)entry->src_data[0] << 12;
340 addr |= ((u64)entry->src_data[1] & 0xf) << 44;
342 if (retry_fault && amdgpu_gmc_filter_faults(adev, addr, entry->pasid,
344 return 1; /* This also prevents sending it to KFD */
346 if (entry->client_id == SOC15_IH_CLIENTID_VMC) {
347 snprintf(hub_name, sizeof(hub_name), "mmhub0");
348 hub = &adev->vmhub[AMDGPU_MMHUB_0];
349 } else if (entry->client_id == SOC15_IH_CLIENTID_VMC1) {
350 snprintf(hub_name, sizeof(hub_name), "mmhub1");
351 hub = &adev->vmhub[AMDGPU_MMHUB_1];
353 snprintf(hub_name, sizeof(hub_name), "gfxhub0");
354 hub = &adev->vmhub[AMDGPU_GFXHUB_0];
357 /* If it's the first fault for this address, process it normally */
358 if (!amdgpu_sriov_vf(adev)) {
359 status = RREG32(hub->vm_l2_pro_fault_status);
360 WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1);
363 if (printk_ratelimit()) {
364 struct amdgpu_task_info task_info;
366 memset(&task_info, 0, sizeof(struct amdgpu_task_info));
367 amdgpu_vm_get_task_info(adev, entry->pasid, &task_info);
370 "[%s] %s page fault (src_id:%u ring:%u vmid:%u "
371 "pasid:%u, for process %s pid %d thread %s pid %d)\n",
372 hub_name, retry_fault ? "retry" : "no-retry",
373 entry->src_id, entry->ring_id, entry->vmid,
374 entry->pasid, task_info.process_name, task_info.tgid,
375 task_info.task_name, task_info.pid);
376 dev_err(adev->dev, " in page starting at address 0x%016llx from client %d\n",
377 addr, entry->client_id);
378 if (!amdgpu_sriov_vf(adev)) {
380 "VM_L2_PROTECTION_FAULT_STATUS:0x%08X\n",
382 dev_err(adev->dev, "\t MORE_FAULTS: 0x%lx\n",
383 REG_GET_FIELD(status,
384 VM_L2_PROTECTION_FAULT_STATUS, MORE_FAULTS));
385 dev_err(adev->dev, "\t WALKER_ERROR: 0x%lx\n",
386 REG_GET_FIELD(status,
387 VM_L2_PROTECTION_FAULT_STATUS, WALKER_ERROR));
388 dev_err(adev->dev, "\t PERMISSION_FAULTS: 0x%lx\n",
389 REG_GET_FIELD(status,
390 VM_L2_PROTECTION_FAULT_STATUS, PERMISSION_FAULTS));
391 dev_err(adev->dev, "\t MAPPING_ERROR: 0x%lx\n",
392 REG_GET_FIELD(status,
393 VM_L2_PROTECTION_FAULT_STATUS, MAPPING_ERROR));
401 static const struct amdgpu_irq_src_funcs gmc_v9_0_irq_funcs = {
402 .set = gmc_v9_0_vm_fault_interrupt_state,
403 .process = gmc_v9_0_process_interrupt,
407 static const struct amdgpu_irq_src_funcs gmc_v9_0_ecc_funcs = {
408 .set = gmc_v9_0_ecc_interrupt_state,
409 .process = gmc_v9_0_process_ecc_irq,
412 static void gmc_v9_0_set_irq_funcs(struct amdgpu_device *adev)
414 adev->gmc.vm_fault.num_types = 1;
415 adev->gmc.vm_fault.funcs = &gmc_v9_0_irq_funcs;
417 adev->gmc.ecc_irq.num_types = 1;
418 adev->gmc.ecc_irq.funcs = &gmc_v9_0_ecc_funcs;
421 static uint32_t gmc_v9_0_get_invalidate_req(unsigned int vmid,
426 req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ,
427 PER_VMID_INVALIDATE_REQ, 1 << vmid);
428 req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ, FLUSH_TYPE, flush_type);
429 req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ, INVALIDATE_L2_PTES, 1);
430 req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ, INVALIDATE_L2_PDE0, 1);
431 req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ, INVALIDATE_L2_PDE1, 1);
432 req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ, INVALIDATE_L2_PDE2, 1);
433 req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ, INVALIDATE_L1_PTES, 1);
434 req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ,
435 CLEAR_PROTECTION_FAULT_STATUS_ADDR, 0);
442 * VMID 0 is the physical GPU addresses as used by the kernel.
443 * VMIDs 1-15 are used for userspace clients and are handled
444 * by the amdgpu vm/hsa code.
448 * gmc_v9_0_flush_gpu_tlb - tlb flush with certain type
450 * @adev: amdgpu_device pointer
451 * @vmid: vm instance to flush
452 * @flush_type: the flush type
454 * Flush the TLB for the requested page table using certain type.
456 static void gmc_v9_0_flush_gpu_tlb(struct amdgpu_device *adev,
457 uint32_t vmid, uint32_t flush_type)
459 const unsigned eng = 17;
462 for (i = 0; i < adev->num_vmhubs; ++i) {
463 struct amdgpu_vmhub *hub = &adev->vmhub[i];
464 u32 tmp = gmc_v9_0_get_invalidate_req(vmid, flush_type);
466 /* This is necessary for a HW workaround under SRIOV as well
467 * as GFXOFF under bare metal
469 if (adev->gfx.kiq.ring.sched.ready &&
470 (amdgpu_sriov_runtime(adev) || !amdgpu_sriov_vf(adev)) &&
471 !adev->in_gpu_reset) {
472 uint32_t req = hub->vm_inv_eng0_req + eng;
473 uint32_t ack = hub->vm_inv_eng0_ack + eng;
475 amdgpu_virt_kiq_reg_write_reg_wait(adev, req, ack, tmp,
480 spin_lock(&adev->gmc.invalidate_lock);
481 WREG32_NO_KIQ(hub->vm_inv_eng0_req + eng, tmp);
482 for (j = 0; j < adev->usec_timeout; j++) {
483 tmp = RREG32_NO_KIQ(hub->vm_inv_eng0_ack + eng);
484 if (tmp & (1 << vmid))
488 spin_unlock(&adev->gmc.invalidate_lock);
489 if (j < adev->usec_timeout)
492 DRM_ERROR("Timeout waiting for VM flush ACK!\n");
496 static uint64_t gmc_v9_0_emit_flush_gpu_tlb(struct amdgpu_ring *ring,
497 unsigned vmid, uint64_t pd_addr)
499 struct amdgpu_device *adev = ring->adev;
500 struct amdgpu_vmhub *hub = &adev->vmhub[ring->funcs->vmhub];
501 uint32_t req = gmc_v9_0_get_invalidate_req(vmid, 0);
502 unsigned eng = ring->vm_inv_eng;
504 amdgpu_ring_emit_wreg(ring, hub->ctx0_ptb_addr_lo32 + (2 * vmid),
505 lower_32_bits(pd_addr));
507 amdgpu_ring_emit_wreg(ring, hub->ctx0_ptb_addr_hi32 + (2 * vmid),
508 upper_32_bits(pd_addr));
510 amdgpu_ring_emit_reg_write_reg_wait(ring, hub->vm_inv_eng0_req + eng,
511 hub->vm_inv_eng0_ack + eng,
517 static void gmc_v9_0_emit_pasid_mapping(struct amdgpu_ring *ring, unsigned vmid,
520 struct amdgpu_device *adev = ring->adev;
523 /* Do nothing because there's no lut register for mmhub1. */
524 if (ring->funcs->vmhub == AMDGPU_MMHUB_1)
527 if (ring->funcs->vmhub == AMDGPU_GFXHUB_0)
528 reg = SOC15_REG_OFFSET(OSSSYS, 0, mmIH_VMID_0_LUT) + vmid;
530 reg = SOC15_REG_OFFSET(OSSSYS, 0, mmIH_VMID_0_LUT_MM) + vmid;
532 amdgpu_ring_emit_wreg(ring, reg, pasid);
536 * PTE format on VEGA 10:
545 * 47:12 4k physical page base address
555 * PDE format on VEGA 10:
556 * 63:59 block fragment size
560 * 47:6 physical base address of PD or PTE
567 static uint64_t gmc_v9_0_get_vm_pte_flags(struct amdgpu_device *adev,
571 uint64_t pte_flag = 0;
573 if (flags & AMDGPU_VM_PAGE_EXECUTABLE)
574 pte_flag |= AMDGPU_PTE_EXECUTABLE;
575 if (flags & AMDGPU_VM_PAGE_READABLE)
576 pte_flag |= AMDGPU_PTE_READABLE;
577 if (flags & AMDGPU_VM_PAGE_WRITEABLE)
578 pte_flag |= AMDGPU_PTE_WRITEABLE;
580 switch (flags & AMDGPU_VM_MTYPE_MASK) {
581 case AMDGPU_VM_MTYPE_DEFAULT:
582 pte_flag |= AMDGPU_PTE_MTYPE_VG10(MTYPE_NC);
584 case AMDGPU_VM_MTYPE_NC:
585 pte_flag |= AMDGPU_PTE_MTYPE_VG10(MTYPE_NC);
587 case AMDGPU_VM_MTYPE_WC:
588 pte_flag |= AMDGPU_PTE_MTYPE_VG10(MTYPE_WC);
590 case AMDGPU_VM_MTYPE_CC:
591 pte_flag |= AMDGPU_PTE_MTYPE_VG10(MTYPE_CC);
593 case AMDGPU_VM_MTYPE_UC:
594 pte_flag |= AMDGPU_PTE_MTYPE_VG10(MTYPE_UC);
597 pte_flag |= AMDGPU_PTE_MTYPE_VG10(MTYPE_NC);
601 if (flags & AMDGPU_VM_PAGE_PRT)
602 pte_flag |= AMDGPU_PTE_PRT;
607 static void gmc_v9_0_get_vm_pde(struct amdgpu_device *adev, int level,
608 uint64_t *addr, uint64_t *flags)
610 if (!(*flags & AMDGPU_PDE_PTE) && !(*flags & AMDGPU_PTE_SYSTEM))
611 *addr = adev->vm_manager.vram_base_offset + *addr -
612 adev->gmc.vram_start;
613 BUG_ON(*addr & 0xFFFF00000000003FULL);
615 if (!adev->gmc.translate_further)
618 if (level == AMDGPU_VM_PDB1) {
619 /* Set the block fragment size */
620 if (!(*flags & AMDGPU_PDE_PTE))
621 *flags |= AMDGPU_PDE_BFS(0x9);
623 } else if (level == AMDGPU_VM_PDB0) {
624 if (*flags & AMDGPU_PDE_PTE)
625 *flags &= ~AMDGPU_PDE_PTE;
627 *flags |= AMDGPU_PTE_TF;
631 static const struct amdgpu_gmc_funcs gmc_v9_0_gmc_funcs = {
632 .flush_gpu_tlb = gmc_v9_0_flush_gpu_tlb,
633 .emit_flush_gpu_tlb = gmc_v9_0_emit_flush_gpu_tlb,
634 .emit_pasid_mapping = gmc_v9_0_emit_pasid_mapping,
635 .get_vm_pte_flags = gmc_v9_0_get_vm_pte_flags,
636 .get_vm_pde = gmc_v9_0_get_vm_pde
639 static void gmc_v9_0_set_gmc_funcs(struct amdgpu_device *adev)
641 adev->gmc.gmc_funcs = &gmc_v9_0_gmc_funcs;
644 static void gmc_v9_0_set_umc_funcs(struct amdgpu_device *adev)
646 switch (adev->asic_type) {
648 adev->umc.max_ras_err_cnt_per_query = UMC_V6_1_TOTAL_CHANNEL_NUM;
649 adev->umc.channel_inst_num = UMC_V6_1_CHANNEL_INSTANCE_NUM;
650 adev->umc.umc_inst_num = UMC_V6_1_UMC_INSTANCE_NUM;
651 adev->umc.channel_offs = UMC_V6_1_PER_CHANNEL_OFFSET;
652 adev->umc.channel_idx_tbl = &umc_v6_1_channel_idx_tbl[0][0];
653 adev->umc.funcs = &umc_v6_1_funcs;
660 static void gmc_v9_0_set_mmhub_funcs(struct amdgpu_device *adev)
662 switch (adev->asic_type) {
664 adev->mmhub_funcs = &mmhub_v1_0_funcs;
671 static int gmc_v9_0_early_init(void *handle)
673 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
675 gmc_v9_0_set_gmc_funcs(adev);
676 gmc_v9_0_set_irq_funcs(adev);
677 gmc_v9_0_set_umc_funcs(adev);
678 gmc_v9_0_set_mmhub_funcs(adev);
680 adev->gmc.shared_aperture_start = 0x2000000000000000ULL;
681 adev->gmc.shared_aperture_end =
682 adev->gmc.shared_aperture_start + (4ULL << 30) - 1;
683 adev->gmc.private_aperture_start = 0x1000000000000000ULL;
684 adev->gmc.private_aperture_end =
685 adev->gmc.private_aperture_start + (4ULL << 30) - 1;
690 static bool gmc_v9_0_keep_stolen_memory(struct amdgpu_device *adev)
695 * Currently there is a bug where some memory client outside
696 * of the driver writes to first 8M of VRAM on S3 resume,
697 * this overrides GART which by default gets placed in first 8M and
698 * causes VM_FAULTS once GTT is accessed.
699 * Keep the stolen memory reservation until the while this is not solved.
700 * Also check code in gmc_v9_0_get_vbios_fb_size and gmc_v9_0_late_init
702 switch (adev->asic_type) {
715 static int gmc_v9_0_allocate_vm_inv_eng(struct amdgpu_device *adev)
717 struct amdgpu_ring *ring;
718 unsigned vm_inv_engs[AMDGPU_MAX_VMHUBS] =
719 {GFXHUB_FREE_VM_INV_ENGS_BITMAP, MMHUB_FREE_VM_INV_ENGS_BITMAP,
720 GFXHUB_FREE_VM_INV_ENGS_BITMAP};
722 unsigned vmhub, inv_eng;
724 for (i = 0; i < adev->num_rings; ++i) {
725 ring = adev->rings[i];
726 vmhub = ring->funcs->vmhub;
728 inv_eng = ffs(vm_inv_engs[vmhub]);
730 dev_err(adev->dev, "no VM inv eng for ring %s\n",
735 ring->vm_inv_eng = inv_eng - 1;
736 vm_inv_engs[vmhub] &= ~(1 << ring->vm_inv_eng);
738 dev_info(adev->dev, "ring %s uses VM inv eng %u on hub %u\n",
739 ring->name, ring->vm_inv_eng, ring->funcs->vmhub);
745 static int gmc_v9_0_ecc_ras_block_late_init(void *handle,
746 struct ras_fs_if *fs_info, struct ras_common_if *ras_block)
748 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
749 struct ras_common_if **ras_if = NULL;
750 struct ras_ih_if ih_info = {
751 .cb = gmc_v9_0_process_ras_data_cb,
755 if (ras_block->block == AMDGPU_RAS_BLOCK__UMC)
756 ras_if = &adev->gmc.umc_ras_if;
757 else if (ras_block->block == AMDGPU_RAS_BLOCK__MMHUB)
758 ras_if = &adev->gmc.mmhub_ras_if;
762 if (!amdgpu_ras_is_supported(adev, ras_block->block)) {
763 amdgpu_ras_feature_enable_on_boot(adev, ras_block, 0);
767 /* handle resume path. */
769 /* resend ras TA enable cmd during resume.
770 * prepare to handle failure.
772 ih_info.head = **ras_if;
773 r = amdgpu_ras_feature_enable_on_boot(adev, *ras_if, 1);
776 /* request a gpu reset. will run again. */
777 amdgpu_ras_request_reset_on_boot(adev,
781 /* fail to enable ras, cleanup all. */
784 /* enable successfully. continue. */
788 *ras_if = kmalloc(sizeof(**ras_if), GFP_KERNEL);
792 **ras_if = *ras_block;
794 r = amdgpu_ras_feature_enable_on_boot(adev, *ras_if, 1);
797 amdgpu_ras_request_reset_on_boot(adev,
804 ih_info.head = **ras_if;
805 fs_info->head = **ras_if;
807 if (ras_block->block == AMDGPU_RAS_BLOCK__UMC) {
808 r = amdgpu_ras_interrupt_add_handler(adev, &ih_info);
813 amdgpu_ras_debugfs_create(adev, fs_info);
815 r = amdgpu_ras_sysfs_create(adev, fs_info);
819 if (ras_block->block == AMDGPU_RAS_BLOCK__UMC) {
820 r = amdgpu_irq_get(adev, &adev->gmc.ecc_irq, 0);
827 amdgpu_ras_sysfs_remove(adev, *ras_if);
829 amdgpu_ras_debugfs_remove(adev, *ras_if);
830 if (ras_block->block == AMDGPU_RAS_BLOCK__UMC)
831 amdgpu_ras_interrupt_remove_handler(adev, &ih_info);
833 amdgpu_ras_feature_enable(adev, *ras_if, 0);
840 static int gmc_v9_0_ecc_late_init(void *handle)
844 struct ras_fs_if umc_fs_info = {
845 .sysfs_name = "umc_err_count",
846 .debugfs_name = "umc_err_inject",
848 struct ras_common_if umc_ras_block = {
849 .block = AMDGPU_RAS_BLOCK__UMC,
850 .type = AMDGPU_RAS_ERROR__MULTI_UNCORRECTABLE,
851 .sub_block_index = 0,
854 struct ras_fs_if mmhub_fs_info = {
855 .sysfs_name = "mmhub_err_count",
856 .debugfs_name = "mmhub_err_inject",
858 struct ras_common_if mmhub_ras_block = {
859 .block = AMDGPU_RAS_BLOCK__MMHUB,
860 .type = AMDGPU_RAS_ERROR__MULTI_UNCORRECTABLE,
861 .sub_block_index = 0,
865 r = gmc_v9_0_ecc_ras_block_late_init(handle,
866 &umc_fs_info, &umc_ras_block);
870 r = gmc_v9_0_ecc_ras_block_late_init(handle,
871 &mmhub_fs_info, &mmhub_ras_block);
875 static int gmc_v9_0_late_init(void *handle)
877 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
880 if (!gmc_v9_0_keep_stolen_memory(adev))
881 amdgpu_bo_late_init(adev);
883 r = gmc_v9_0_allocate_vm_inv_eng(adev);
886 /* Check if ecc is available */
887 if (!amdgpu_sriov_vf(adev)) {
888 switch (adev->asic_type) {
891 r = amdgpu_atomfirmware_mem_ecc_supported(adev);
893 DRM_INFO("ECC is not present.\n");
894 if (adev->df_funcs->enable_ecc_force_par_wr_rmw)
895 adev->df_funcs->enable_ecc_force_par_wr_rmw(adev, false);
897 DRM_INFO("ECC is active.\n");
900 r = amdgpu_atomfirmware_sram_ecc_supported(adev);
902 DRM_INFO("SRAM ECC is not present.\n");
904 DRM_INFO("SRAM ECC is active.\n");
912 r = gmc_v9_0_ecc_late_init(handle);
916 return amdgpu_irq_get(adev, &adev->gmc.vm_fault, 0);
919 static void gmc_v9_0_vram_gtt_location(struct amdgpu_device *adev,
920 struct amdgpu_gmc *mc)
923 if (!amdgpu_sriov_vf(adev)) {
924 if (adev->asic_type == CHIP_ARCTURUS)
925 base = mmhub_v9_4_get_fb_location(adev);
927 base = mmhub_v1_0_get_fb_location(adev);
929 /* add the xgmi offset of the physical node */
930 base += adev->gmc.xgmi.physical_node_id * adev->gmc.xgmi.node_segment_size;
931 amdgpu_gmc_vram_location(adev, mc, base);
932 amdgpu_gmc_gart_location(adev, mc);
933 if (!amdgpu_sriov_vf(adev))
934 amdgpu_gmc_agp_location(adev, mc);
935 /* base offset of vram pages */
936 adev->vm_manager.vram_base_offset = gfxhub_v1_0_get_mc_fb_offset(adev);
938 /* XXX: add the xgmi offset of the physical node? */
939 adev->vm_manager.vram_base_offset +=
940 adev->gmc.xgmi.physical_node_id * adev->gmc.xgmi.node_segment_size;
944 * gmc_v9_0_mc_init - initialize the memory controller driver params
946 * @adev: amdgpu_device pointer
948 * Look up the amount of vram, vram width, and decide how to place
949 * vram and gart within the GPU's physical address space.
950 * Returns 0 for success.
952 static int gmc_v9_0_mc_init(struct amdgpu_device *adev)
954 int chansize, numchan;
957 if (amdgpu_sriov_vf(adev)) {
958 /* For Vega10 SR-IOV, vram_width can't be read from ATOM as RAVEN,
959 * and DF related registers is not readable, seems hardcord is the
960 * only way to set the correct vram_width
962 adev->gmc.vram_width = 2048;
963 } else if (amdgpu_emu_mode != 1) {
964 adev->gmc.vram_width = amdgpu_atomfirmware_get_vram_width(adev);
967 if (!adev->gmc.vram_width) {
968 /* hbm memory channel size */
969 if (adev->flags & AMD_IS_APU)
974 numchan = adev->df_funcs->get_hbm_channel_number(adev);
975 adev->gmc.vram_width = numchan * chansize;
978 /* size in MB on si */
979 adev->gmc.mc_vram_size =
980 adev->nbio_funcs->get_memsize(adev) * 1024ULL * 1024ULL;
981 adev->gmc.real_vram_size = adev->gmc.mc_vram_size;
983 if (!(adev->flags & AMD_IS_APU)) {
984 r = amdgpu_device_resize_fb_bar(adev);
988 adev->gmc.aper_base = pci_resource_start(adev->pdev, 0);
989 adev->gmc.aper_size = pci_resource_len(adev->pdev, 0);
992 if (adev->flags & AMD_IS_APU) {
993 adev->gmc.aper_base = gfxhub_v1_0_get_mc_fb_offset(adev);
994 adev->gmc.aper_size = adev->gmc.real_vram_size;
997 /* In case the PCI BAR is larger than the actual amount of vram */
998 adev->gmc.visible_vram_size = adev->gmc.aper_size;
999 if (adev->gmc.visible_vram_size > adev->gmc.real_vram_size)
1000 adev->gmc.visible_vram_size = adev->gmc.real_vram_size;
1002 /* set the gart size */
1003 if (amdgpu_gart_size == -1) {
1004 switch (adev->asic_type) {
1005 case CHIP_VEGA10: /* all engines support GPUVM */
1006 case CHIP_VEGA12: /* all engines support GPUVM */
1010 adev->gmc.gart_size = 512ULL << 20;
1012 case CHIP_RAVEN: /* DCE SG support */
1014 adev->gmc.gart_size = 1024ULL << 20;
1018 adev->gmc.gart_size = (u64)amdgpu_gart_size << 20;
1021 gmc_v9_0_vram_gtt_location(adev, &adev->gmc);
1026 static int gmc_v9_0_gart_init(struct amdgpu_device *adev)
1030 if (adev->gart.bo) {
1031 WARN(1, "VEGA10 PCIE GART already initialized\n");
1034 /* Initialize common gart structure */
1035 r = amdgpu_gart_init(adev);
1038 adev->gart.table_size = adev->gart.num_gpu_pages * 8;
1039 adev->gart.gart_pte_flags = AMDGPU_PTE_MTYPE_VG10(MTYPE_UC) |
1040 AMDGPU_PTE_EXECUTABLE;
1041 return amdgpu_gart_table_vram_alloc(adev);
1044 static unsigned gmc_v9_0_get_vbios_fb_size(struct amdgpu_device *adev)
1050 * TODO Remove once GART corruption is resolved
1051 * Check related code in gmc_v9_0_sw_fini
1053 if (gmc_v9_0_keep_stolen_memory(adev))
1054 return 9 * 1024 * 1024;
1056 d1vga_control = RREG32_SOC15(DCE, 0, mmD1VGA_CONTROL);
1057 if (REG_GET_FIELD(d1vga_control, D1VGA_CONTROL, D1VGA_MODE_ENABLE)) {
1058 size = 9 * 1024 * 1024; /* reserve 8MB for vga emulator and 1 MB for FB */
1062 switch (adev->asic_type) {
1065 viewport = RREG32_SOC15(DCE, 0, mmHUBP0_DCSURF_PRI_VIEWPORT_DIMENSION);
1066 size = (REG_GET_FIELD(viewport,
1067 HUBP0_DCSURF_PRI_VIEWPORT_DIMENSION, PRI_VIEWPORT_HEIGHT) *
1068 REG_GET_FIELD(viewport,
1069 HUBP0_DCSURF_PRI_VIEWPORT_DIMENSION, PRI_VIEWPORT_WIDTH) *
1076 viewport = RREG32_SOC15(DCE, 0, mmSCL0_VIEWPORT_SIZE);
1077 size = (REG_GET_FIELD(viewport, SCL0_VIEWPORT_SIZE, VIEWPORT_HEIGHT) *
1078 REG_GET_FIELD(viewport, SCL0_VIEWPORT_SIZE, VIEWPORT_WIDTH) *
1083 /* return 0 if the pre-OS buffer uses up most of vram */
1084 if ((adev->gmc.real_vram_size - size) < (8 * 1024 * 1024))
1090 static int gmc_v9_0_sw_init(void *handle)
1093 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1095 gfxhub_v1_0_init(adev);
1096 if (adev->asic_type == CHIP_ARCTURUS)
1097 mmhub_v9_4_init(adev);
1099 mmhub_v1_0_init(adev);
1101 spin_lock_init(&adev->gmc.invalidate_lock);
1103 adev->gmc.vram_type = amdgpu_atomfirmware_get_vram_type(adev);
1104 switch (adev->asic_type) {
1106 adev->num_vmhubs = 2;
1108 if (adev->rev_id == 0x0 || adev->rev_id == 0x1) {
1109 amdgpu_vm_adjust_size(adev, 256 * 1024, 9, 3, 48);
1111 /* vm_size is 128TB + 512GB for legacy 3-level page support */
1112 amdgpu_vm_adjust_size(adev, 128 * 1024 + 512, 9, 2, 48);
1113 adev->gmc.translate_further =
1114 adev->vm_manager.num_level > 1;
1121 adev->num_vmhubs = 2;
1125 * To fulfill 4-level page support,
1126 * vm size is 256TB (48bit), maximum size of Vega10,
1127 * block size 512 (9bit)
1129 /* sriov restrict max_pfn below AMDGPU_GMC_HOLE */
1130 if (amdgpu_sriov_vf(adev))
1131 amdgpu_vm_adjust_size(adev, 256 * 1024, 9, 3, 47);
1133 amdgpu_vm_adjust_size(adev, 256 * 1024, 9, 3, 48);
1136 adev->num_vmhubs = 3;
1138 /* Keep the vm size same with Vega20 */
1139 amdgpu_vm_adjust_size(adev, 256 * 1024, 9, 3, 48);
1145 /* This interrupt is VMC page fault.*/
1146 r = amdgpu_irq_add_id(adev, SOC15_IH_CLIENTID_VMC, VMC_1_0__SRCID__VM_FAULT,
1147 &adev->gmc.vm_fault);
1151 if (adev->asic_type == CHIP_ARCTURUS) {
1152 r = amdgpu_irq_add_id(adev, SOC15_IH_CLIENTID_VMC1, VMC_1_0__SRCID__VM_FAULT,
1153 &adev->gmc.vm_fault);
1158 r = amdgpu_irq_add_id(adev, SOC15_IH_CLIENTID_UTCL2, UTCL2_1_0__SRCID__FAULT,
1159 &adev->gmc.vm_fault);
1164 /* interrupt sent to DF. */
1165 r = amdgpu_irq_add_id(adev, SOC15_IH_CLIENTID_DF, 0,
1166 &adev->gmc.ecc_irq);
1170 /* Set the internal MC address mask
1171 * This is the max address of the GPU's
1172 * internal address space.
1174 adev->gmc.mc_mask = 0xffffffffffffULL; /* 48 bit MC */
1176 r = dma_set_mask_and_coherent(adev->dev, DMA_BIT_MASK(44));
1178 printk(KERN_WARNING "amdgpu: No suitable DMA available.\n");
1181 adev->need_swiotlb = drm_need_swiotlb(44);
1183 if (adev->gmc.xgmi.supported) {
1184 r = gfxhub_v1_1_get_xgmi_info(adev);
1189 r = gmc_v9_0_mc_init(adev);
1193 adev->gmc.stolen_size = gmc_v9_0_get_vbios_fb_size(adev);
1195 /* Memory manager */
1196 r = amdgpu_bo_init(adev);
1200 r = gmc_v9_0_gart_init(adev);
1206 * VMID 0 is reserved for System
1207 * amdgpu graphics/compute will use VMIDs 1-7
1208 * amdkfd will use VMIDs 8-15
1210 adev->vm_manager.id_mgr[AMDGPU_GFXHUB_0].num_ids = AMDGPU_NUM_OF_VMIDS;
1211 adev->vm_manager.id_mgr[AMDGPU_MMHUB_0].num_ids = AMDGPU_NUM_OF_VMIDS;
1212 adev->vm_manager.id_mgr[AMDGPU_MMHUB_1].num_ids = AMDGPU_NUM_OF_VMIDS;
1214 amdgpu_vm_manager_init(adev);
1219 static int gmc_v9_0_sw_fini(void *handle)
1221 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1223 if (amdgpu_ras_is_supported(adev, AMDGPU_RAS_BLOCK__UMC) &&
1224 adev->gmc.umc_ras_if) {
1225 struct ras_common_if *ras_if = adev->gmc.umc_ras_if;
1226 struct ras_ih_if ih_info = {
1230 /* remove fs first */
1231 amdgpu_ras_debugfs_remove(adev, ras_if);
1232 amdgpu_ras_sysfs_remove(adev, ras_if);
1234 amdgpu_ras_interrupt_remove_handler(adev, &ih_info);
1235 amdgpu_ras_feature_enable(adev, ras_if, 0);
1239 if (amdgpu_ras_is_supported(adev, AMDGPU_RAS_BLOCK__MMHUB) &&
1240 adev->gmc.mmhub_ras_if) {
1241 struct ras_common_if *ras_if = adev->gmc.mmhub_ras_if;
1243 /* remove fs and disable ras feature */
1244 amdgpu_ras_debugfs_remove(adev, ras_if);
1245 amdgpu_ras_sysfs_remove(adev, ras_if);
1246 amdgpu_ras_feature_enable(adev, ras_if, 0);
1250 amdgpu_gem_force_release(adev);
1251 amdgpu_vm_manager_fini(adev);
1253 if (gmc_v9_0_keep_stolen_memory(adev))
1254 amdgpu_bo_free_kernel(&adev->stolen_vga_memory, NULL, NULL);
1256 amdgpu_gart_table_vram_free(adev);
1257 amdgpu_bo_fini(adev);
1258 amdgpu_gart_fini(adev);
1263 static void gmc_v9_0_init_golden_registers(struct amdgpu_device *adev)
1266 switch (adev->asic_type) {
1268 if (amdgpu_sriov_vf(adev))
1272 soc15_program_register_sequence(adev,
1273 golden_settings_mmhub_1_0_0,
1274 ARRAY_SIZE(golden_settings_mmhub_1_0_0));
1275 soc15_program_register_sequence(adev,
1276 golden_settings_athub_1_0_0,
1277 ARRAY_SIZE(golden_settings_athub_1_0_0));
1282 /* TODO for renoir */
1283 soc15_program_register_sequence(adev,
1284 golden_settings_athub_1_0_0,
1285 ARRAY_SIZE(golden_settings_athub_1_0_0));
1293 * gmc_v9_0_gart_enable - gart enable
1295 * @adev: amdgpu_device pointer
1297 static int gmc_v9_0_gart_enable(struct amdgpu_device *adev)
1303 amdgpu_device_program_register_sequence(adev,
1304 golden_settings_vega10_hdp,
1305 ARRAY_SIZE(golden_settings_vega10_hdp));
1307 if (adev->gart.bo == NULL) {
1308 dev_err(adev->dev, "No VRAM object for PCIE GART.\n");
1311 r = amdgpu_gart_table_vram_pin(adev);
1315 switch (adev->asic_type) {
1317 /* TODO for renoir */
1318 mmhub_v1_0_update_power_gating(adev, true);
1324 r = gfxhub_v1_0_gart_enable(adev);
1328 if (adev->asic_type == CHIP_ARCTURUS)
1329 r = mmhub_v9_4_gart_enable(adev);
1331 r = mmhub_v1_0_gart_enable(adev);
1335 WREG32_FIELD15(HDP, 0, HDP_MISC_CNTL, FLUSH_INVALIDATE_CACHE, 1);
1337 tmp = RREG32_SOC15(HDP, 0, mmHDP_HOST_PATH_CNTL);
1338 WREG32_SOC15(HDP, 0, mmHDP_HOST_PATH_CNTL, tmp);
1340 WREG32_SOC15(HDP, 0, mmHDP_NONSURFACE_BASE, (adev->gmc.vram_start >> 8));
1341 WREG32_SOC15(HDP, 0, mmHDP_NONSURFACE_BASE_HI, (adev->gmc.vram_start >> 40));
1343 /* After HDP is initialized, flush HDP.*/
1344 adev->nbio_funcs->hdp_flush(adev, NULL);
1346 if (amdgpu_vm_fault_stop == AMDGPU_VM_FAULT_STOP_ALWAYS)
1351 gfxhub_v1_0_set_fault_enable_default(adev, value);
1352 if (adev->asic_type == CHIP_ARCTURUS)
1353 mmhub_v9_4_set_fault_enable_default(adev, value);
1355 mmhub_v1_0_set_fault_enable_default(adev, value);
1356 gmc_v9_0_flush_gpu_tlb(adev, 0, 0);
1358 DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
1359 (unsigned)(adev->gmc.gart_size >> 20),
1360 (unsigned long long)amdgpu_bo_gpu_offset(adev->gart.bo));
1361 adev->gart.ready = true;
1365 static int gmc_v9_0_hw_init(void *handle)
1368 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1370 /* The sequence of these two function calls matters.*/
1371 gmc_v9_0_init_golden_registers(adev);
1373 if (adev->mode_info.num_crtc) {
1374 /* Lockout access through VGA aperture*/
1375 WREG32_FIELD15(DCE, 0, VGA_HDP_CONTROL, VGA_MEMORY_DISABLE, 1);
1377 /* disable VGA render */
1378 WREG32_FIELD15(DCE, 0, VGA_RENDER_CONTROL, VGA_VSTATUS_CNTL, 0);
1381 r = gmc_v9_0_gart_enable(adev);
1387 * gmc_v9_0_gart_disable - gart disable
1389 * @adev: amdgpu_device pointer
1391 * This disables all VM page table.
1393 static void gmc_v9_0_gart_disable(struct amdgpu_device *adev)
1395 gfxhub_v1_0_gart_disable(adev);
1396 if (adev->asic_type == CHIP_ARCTURUS)
1397 mmhub_v9_4_gart_disable(adev);
1399 mmhub_v1_0_gart_disable(adev);
1400 amdgpu_gart_table_vram_unpin(adev);
1403 static int gmc_v9_0_hw_fini(void *handle)
1405 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1407 if (amdgpu_sriov_vf(adev)) {
1408 /* full access mode, so don't touch any GMC register */
1409 DRM_DEBUG("For SRIOV client, shouldn't do anything.\n");
1413 amdgpu_irq_put(adev, &adev->gmc.ecc_irq, 0);
1414 amdgpu_irq_put(adev, &adev->gmc.vm_fault, 0);
1415 gmc_v9_0_gart_disable(adev);
1420 static int gmc_v9_0_suspend(void *handle)
1422 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1424 return gmc_v9_0_hw_fini(adev);
1427 static int gmc_v9_0_resume(void *handle)
1430 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1432 r = gmc_v9_0_hw_init(adev);
1436 amdgpu_vmid_reset_all(adev);
1441 static bool gmc_v9_0_is_idle(void *handle)
1443 /* MC is always ready in GMC v9.*/
1447 static int gmc_v9_0_wait_for_idle(void *handle)
1449 /* There is no need to wait for MC idle in GMC v9.*/
1453 static int gmc_v9_0_soft_reset(void *handle)
1455 /* XXX for emulation.*/
1459 static int gmc_v9_0_set_clockgating_state(void *handle,
1460 enum amd_clockgating_state state)
1462 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1464 if (adev->asic_type == CHIP_ARCTURUS)
1465 mmhub_v9_4_set_clockgating(adev, state);
1467 mmhub_v1_0_set_clockgating(adev, state);
1469 athub_v1_0_set_clockgating(adev, state);
1474 static void gmc_v9_0_get_clockgating_state(void *handle, u32 *flags)
1476 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1478 if (adev->asic_type == CHIP_ARCTURUS)
1479 mmhub_v9_4_get_clockgating(adev, flags);
1481 mmhub_v1_0_get_clockgating(adev, flags);
1483 athub_v1_0_get_clockgating(adev, flags);
1486 static int gmc_v9_0_set_powergating_state(void *handle,
1487 enum amd_powergating_state state)
1492 const struct amd_ip_funcs gmc_v9_0_ip_funcs = {
1494 .early_init = gmc_v9_0_early_init,
1495 .late_init = gmc_v9_0_late_init,
1496 .sw_init = gmc_v9_0_sw_init,
1497 .sw_fini = gmc_v9_0_sw_fini,
1498 .hw_init = gmc_v9_0_hw_init,
1499 .hw_fini = gmc_v9_0_hw_fini,
1500 .suspend = gmc_v9_0_suspend,
1501 .resume = gmc_v9_0_resume,
1502 .is_idle = gmc_v9_0_is_idle,
1503 .wait_for_idle = gmc_v9_0_wait_for_idle,
1504 .soft_reset = gmc_v9_0_soft_reset,
1505 .set_clockgating_state = gmc_v9_0_set_clockgating_state,
1506 .set_powergating_state = gmc_v9_0_set_powergating_state,
1507 .get_clockgating_state = gmc_v9_0_get_clockgating_state,
1510 const struct amdgpu_ip_block_version gmc_v9_0_ip_block =
1512 .type = AMD_IP_BLOCK_TYPE_GMC,
1516 .funcs = &gmc_v9_0_ip_funcs,