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.
23 #include <linux/firmware.h>
26 #include "amdgpu_atomfirmware.h"
28 #include "vega10/soc15ip.h"
29 #include "vega10/HDP/hdp_4_0_offset.h"
30 #include "vega10/HDP/hdp_4_0_sh_mask.h"
31 #include "vega10/GC/gc_9_0_sh_mask.h"
32 #include "vega10/DC/dce_12_0_offset.h"
33 #include "vega10/DC/dce_12_0_sh_mask.h"
34 #include "vega10/vega10_enum.h"
36 #include "soc15_common.h"
38 #include "nbio_v6_1.h"
39 #include "nbio_v7_0.h"
40 #include "gfxhub_v1_0.h"
41 #include "mmhub_v1_0.h"
43 #define mmDF_CS_AON0_DramBaseAddress0 0x0044
44 #define mmDF_CS_AON0_DramBaseAddress0_BASE_IDX 0
45 //DF_CS_AON0_DramBaseAddress0
46 #define DF_CS_AON0_DramBaseAddress0__AddrRngVal__SHIFT 0x0
47 #define DF_CS_AON0_DramBaseAddress0__LgcyMmioHoleEn__SHIFT 0x1
48 #define DF_CS_AON0_DramBaseAddress0__IntLvNumChan__SHIFT 0x4
49 #define DF_CS_AON0_DramBaseAddress0__IntLvAddrSel__SHIFT 0x8
50 #define DF_CS_AON0_DramBaseAddress0__DramBaseAddr__SHIFT 0xc
51 #define DF_CS_AON0_DramBaseAddress0__AddrRngVal_MASK 0x00000001L
52 #define DF_CS_AON0_DramBaseAddress0__LgcyMmioHoleEn_MASK 0x00000002L
53 #define DF_CS_AON0_DramBaseAddress0__IntLvNumChan_MASK 0x000000F0L
54 #define DF_CS_AON0_DramBaseAddress0__IntLvAddrSel_MASK 0x00000700L
55 #define DF_CS_AON0_DramBaseAddress0__DramBaseAddr_MASK 0xFFFFF000L
57 /* XXX Move this macro to VEGA10 header file, which is like vid.h for VI.*/
58 #define AMDGPU_NUM_OF_VMIDS 8
60 static const u32 golden_settings_vega10_hdp[] =
62 0xf64, 0x0fffffff, 0x00000000,
63 0xf65, 0x0fffffff, 0x00000000,
64 0xf66, 0x0fffffff, 0x00000000,
65 0xf67, 0x0fffffff, 0x00000000,
66 0xf68, 0x0fffffff, 0x00000000,
67 0xf6a, 0x0fffffff, 0x00000000,
68 0xf6b, 0x0fffffff, 0x00000000,
69 0xf6c, 0x0fffffff, 0x00000000,
70 0xf6d, 0x0fffffff, 0x00000000,
71 0xf6e, 0x0fffffff, 0x00000000,
74 static int gmc_v9_0_vm_fault_interrupt_state(struct amdgpu_device *adev,
75 struct amdgpu_irq_src *src,
77 enum amdgpu_interrupt_state state)
79 struct amdgpu_vmhub *hub;
80 u32 tmp, reg, bits, i;
82 bits = VM_CONTEXT1_CNTL__RANGE_PROTECTION_FAULT_ENABLE_INTERRUPT_MASK |
83 VM_CONTEXT1_CNTL__DUMMY_PAGE_PROTECTION_FAULT_ENABLE_INTERRUPT_MASK |
84 VM_CONTEXT1_CNTL__PDE0_PROTECTION_FAULT_ENABLE_INTERRUPT_MASK |
85 VM_CONTEXT1_CNTL__VALID_PROTECTION_FAULT_ENABLE_INTERRUPT_MASK |
86 VM_CONTEXT1_CNTL__READ_PROTECTION_FAULT_ENABLE_INTERRUPT_MASK |
87 VM_CONTEXT1_CNTL__WRITE_PROTECTION_FAULT_ENABLE_INTERRUPT_MASK |
88 VM_CONTEXT1_CNTL__EXECUTE_PROTECTION_FAULT_ENABLE_INTERRUPT_MASK;
91 case AMDGPU_IRQ_STATE_DISABLE:
93 hub = &adev->vmhub[AMDGPU_MMHUB];
94 for (i = 0; i< 16; i++) {
95 reg = hub->vm_context0_cntl + i;
102 hub = &adev->vmhub[AMDGPU_GFXHUB];
103 for (i = 0; i < 16; i++) {
104 reg = hub->vm_context0_cntl + i;
110 case AMDGPU_IRQ_STATE_ENABLE:
112 hub = &adev->vmhub[AMDGPU_MMHUB];
113 for (i = 0; i< 16; i++) {
114 reg = hub->vm_context0_cntl + i;
121 hub = &adev->vmhub[AMDGPU_GFXHUB];
122 for (i = 0; i < 16; i++) {
123 reg = hub->vm_context0_cntl + i;
136 static int gmc_v9_0_process_interrupt(struct amdgpu_device *adev,
137 struct amdgpu_irq_src *source,
138 struct amdgpu_iv_entry *entry)
140 struct amdgpu_vmhub *hub = &adev->vmhub[entry->vm_id_src];
144 addr = (u64)entry->src_data[0] << 12;
145 addr |= ((u64)entry->src_data[1] & 0xf) << 44;
147 if (!amdgpu_sriov_vf(adev)) {
148 status = RREG32(hub->vm_l2_pro_fault_status);
149 WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1);
152 if (printk_ratelimit()) {
154 "[%s] VMC page fault (src_id:%u ring:%u vm_id:%u pas_id:%u)\n",
155 entry->vm_id_src ? "mmhub" : "gfxhub",
156 entry->src_id, entry->ring_id, entry->vm_id,
158 dev_err(adev->dev, " at page 0x%016llx from %d\n",
159 addr, entry->client_id);
160 if (!amdgpu_sriov_vf(adev))
162 "VM_L2_PROTECTION_FAULT_STATUS:0x%08X\n",
169 static const struct amdgpu_irq_src_funcs gmc_v9_0_irq_funcs = {
170 .set = gmc_v9_0_vm_fault_interrupt_state,
171 .process = gmc_v9_0_process_interrupt,
174 static void gmc_v9_0_set_irq_funcs(struct amdgpu_device *adev)
176 adev->mc.vm_fault.num_types = 1;
177 adev->mc.vm_fault.funcs = &gmc_v9_0_irq_funcs;
180 static uint32_t gmc_v9_0_get_invalidate_req(unsigned int vm_id)
184 /* invalidate using legacy mode on vm_id*/
185 req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ,
186 PER_VMID_INVALIDATE_REQ, 1 << vm_id);
187 req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ, FLUSH_TYPE, 0);
188 req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ, INVALIDATE_L2_PTES, 1);
189 req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ, INVALIDATE_L2_PDE0, 1);
190 req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ, INVALIDATE_L2_PDE1, 1);
191 req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ, INVALIDATE_L2_PDE2, 1);
192 req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ, INVALIDATE_L1_PTES, 1);
193 req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ,
194 CLEAR_PROTECTION_FAULT_STATUS_ADDR, 0);
201 * VMID 0 is the physical GPU addresses as used by the kernel.
202 * VMIDs 1-15 are used for userspace clients and are handled
203 * by the amdgpu vm/hsa code.
207 * gmc_v9_0_gart_flush_gpu_tlb - gart tlb flush callback
209 * @adev: amdgpu_device pointer
210 * @vmid: vm instance to flush
212 * Flush the TLB for the requested page table.
214 static void gmc_v9_0_gart_flush_gpu_tlb(struct amdgpu_device *adev,
217 /* Use register 17 for GART */
218 const unsigned eng = 17;
221 /* flush hdp cache */
222 if (adev->flags & AMD_IS_APU)
223 nbio_v7_0_hdp_flush(adev);
225 nbio_v6_1_hdp_flush(adev);
227 spin_lock(&adev->mc.invalidate_lock);
229 for (i = 0; i < AMDGPU_MAX_VMHUBS; ++i) {
230 struct amdgpu_vmhub *hub = &adev->vmhub[i];
231 u32 tmp = gmc_v9_0_get_invalidate_req(vmid);
233 WREG32_NO_KIQ(hub->vm_inv_eng0_req + eng, tmp);
235 /* Busy wait for ACK.*/
236 for (j = 0; j < 100; j++) {
237 tmp = RREG32_NO_KIQ(hub->vm_inv_eng0_ack + eng);
246 /* Wait for ACK with a delay.*/
247 for (j = 0; j < adev->usec_timeout; j++) {
248 tmp = RREG32_NO_KIQ(hub->vm_inv_eng0_ack + eng);
254 if (j < adev->usec_timeout)
257 DRM_ERROR("Timeout waiting for VM flush ACK!\n");
260 spin_unlock(&adev->mc.invalidate_lock);
264 * gmc_v9_0_gart_set_pte_pde - update the page tables using MMIO
266 * @adev: amdgpu_device pointer
267 * @cpu_pt_addr: cpu address of the page table
268 * @gpu_page_idx: entry in the page table to update
269 * @addr: dst addr to write into pte/pde
270 * @flags: access flags
272 * Update the page tables using the CPU.
274 static int gmc_v9_0_gart_set_pte_pde(struct amdgpu_device *adev,
276 uint32_t gpu_page_idx,
280 void __iomem *ptr = (void *)cpu_pt_addr;
284 * PTE format on VEGA 10:
293 * 47:12 4k physical page base address
303 * PDE format on VEGA 10:
304 * 63:59 block fragment size
308 * 47:6 physical base address of PD or PTE
316 * The following is for PTE only. GART does not have PDEs.
318 value = addr & 0x0000FFFFFFFFF000ULL;
320 writeq(value, ptr + (gpu_page_idx * 8));
324 static uint64_t gmc_v9_0_get_vm_pte_flags(struct amdgpu_device *adev,
328 uint64_t pte_flag = 0;
330 if (flags & AMDGPU_VM_PAGE_EXECUTABLE)
331 pte_flag |= AMDGPU_PTE_EXECUTABLE;
332 if (flags & AMDGPU_VM_PAGE_READABLE)
333 pte_flag |= AMDGPU_PTE_READABLE;
334 if (flags & AMDGPU_VM_PAGE_WRITEABLE)
335 pte_flag |= AMDGPU_PTE_WRITEABLE;
337 switch (flags & AMDGPU_VM_MTYPE_MASK) {
338 case AMDGPU_VM_MTYPE_DEFAULT:
339 pte_flag |= AMDGPU_PTE_MTYPE(MTYPE_NC);
341 case AMDGPU_VM_MTYPE_NC:
342 pte_flag |= AMDGPU_PTE_MTYPE(MTYPE_NC);
344 case AMDGPU_VM_MTYPE_WC:
345 pte_flag |= AMDGPU_PTE_MTYPE(MTYPE_WC);
347 case AMDGPU_VM_MTYPE_CC:
348 pte_flag |= AMDGPU_PTE_MTYPE(MTYPE_CC);
350 case AMDGPU_VM_MTYPE_UC:
351 pte_flag |= AMDGPU_PTE_MTYPE(MTYPE_UC);
354 pte_flag |= AMDGPU_PTE_MTYPE(MTYPE_NC);
358 if (flags & AMDGPU_VM_PAGE_PRT)
359 pte_flag |= AMDGPU_PTE_PRT;
364 static u64 gmc_v9_0_get_vm_pde(struct amdgpu_device *adev, u64 addr)
366 addr = adev->vm_manager.vram_base_offset + addr - adev->mc.vram_start;
367 BUG_ON(addr & 0xFFFF00000000003FULL);
371 static const struct amdgpu_gart_funcs gmc_v9_0_gart_funcs = {
372 .flush_gpu_tlb = gmc_v9_0_gart_flush_gpu_tlb,
373 .set_pte_pde = gmc_v9_0_gart_set_pte_pde,
374 .get_invalidate_req = gmc_v9_0_get_invalidate_req,
375 .get_vm_pte_flags = gmc_v9_0_get_vm_pte_flags,
376 .get_vm_pde = gmc_v9_0_get_vm_pde
379 static void gmc_v9_0_set_gart_funcs(struct amdgpu_device *adev)
381 if (adev->gart.gart_funcs == NULL)
382 adev->gart.gart_funcs = &gmc_v9_0_gart_funcs;
385 static int gmc_v9_0_early_init(void *handle)
387 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
389 gmc_v9_0_set_gart_funcs(adev);
390 gmc_v9_0_set_irq_funcs(adev);
395 static int gmc_v9_0_late_init(void *handle)
397 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
398 unsigned vm_inv_eng[AMDGPU_MAX_VMHUBS] = { 3, 3 };
401 for(i = 0; i < adev->num_rings; ++i) {
402 struct amdgpu_ring *ring = adev->rings[i];
403 unsigned vmhub = ring->funcs->vmhub;
405 ring->vm_inv_eng = vm_inv_eng[vmhub]++;
406 dev_info(adev->dev, "ring %u(%s) uses VM inv eng %u on hub %u\n",
407 ring->idx, ring->name, ring->vm_inv_eng,
411 /* Engine 17 is used for GART flushes */
412 for(i = 0; i < AMDGPU_MAX_VMHUBS; ++i)
413 BUG_ON(vm_inv_eng[i] > 17);
415 return amdgpu_irq_get(adev, &adev->mc.vm_fault, 0);
418 static void gmc_v9_0_vram_gtt_location(struct amdgpu_device *adev,
419 struct amdgpu_mc *mc)
422 if (!amdgpu_sriov_vf(adev))
423 base = mmhub_v1_0_get_fb_location(adev);
424 amdgpu_vram_location(adev, &adev->mc, base);
425 amdgpu_gart_location(adev, mc);
426 /* base offset of vram pages */
427 if (adev->flags & AMD_IS_APU)
428 adev->vm_manager.vram_base_offset = gfxhub_v1_0_get_mc_fb_offset(adev);
430 adev->vm_manager.vram_base_offset = 0;
434 * gmc_v9_0_mc_init - initialize the memory controller driver params
436 * @adev: amdgpu_device pointer
438 * Look up the amount of vram, vram width, and decide how to place
439 * vram and gart within the GPU's physical address space.
440 * Returns 0 for success.
442 static int gmc_v9_0_mc_init(struct amdgpu_device *adev)
445 int chansize, numchan;
447 adev->mc.vram_width = amdgpu_atomfirmware_get_vram_width(adev);
448 if (!adev->mc.vram_width) {
449 /* hbm memory channel size */
452 tmp = RREG32_SOC15(DF, 0, mmDF_CS_AON0_DramBaseAddress0);
453 tmp &= DF_CS_AON0_DramBaseAddress0__IntLvNumChan_MASK;
454 tmp >>= DF_CS_AON0_DramBaseAddress0__IntLvNumChan__SHIFT;
485 adev->mc.vram_width = numchan * chansize;
488 /* Could aper size report 0 ? */
489 adev->mc.aper_base = pci_resource_start(adev->pdev, 0);
490 adev->mc.aper_size = pci_resource_len(adev->pdev, 0);
491 /* size in MB on si */
492 adev->mc.mc_vram_size =
493 ((adev->flags & AMD_IS_APU) ? nbio_v7_0_get_memsize(adev) :
494 nbio_v6_1_get_memsize(adev)) * 1024ULL * 1024ULL;
495 adev->mc.real_vram_size = adev->mc.mc_vram_size;
496 adev->mc.visible_vram_size = adev->mc.aper_size;
498 /* In case the PCI BAR is larger than the actual amount of vram */
499 if (adev->mc.visible_vram_size > adev->mc.real_vram_size)
500 adev->mc.visible_vram_size = adev->mc.real_vram_size;
502 /* set the gart size */
503 if (amdgpu_gart_size == -1) {
504 switch (adev->asic_type) {
505 case CHIP_VEGA10: /* all engines support GPUVM */
507 adev->mc.gart_size = 256ULL << 20;
509 case CHIP_RAVEN: /* DCE SG support */
510 adev->mc.gart_size = 1024ULL << 20;
514 adev->mc.gart_size = (u64)amdgpu_gart_size << 20;
517 gmc_v9_0_vram_gtt_location(adev, &adev->mc);
522 static int gmc_v9_0_gart_init(struct amdgpu_device *adev)
526 if (adev->gart.robj) {
527 WARN(1, "VEGA10 PCIE GART already initialized\n");
530 /* Initialize common gart structure */
531 r = amdgpu_gart_init(adev);
534 adev->gart.table_size = adev->gart.num_gpu_pages * 8;
535 adev->gart.gart_pte_flags = AMDGPU_PTE_MTYPE(MTYPE_UC) |
536 AMDGPU_PTE_EXECUTABLE;
537 return amdgpu_gart_table_vram_alloc(adev);
540 static int gmc_v9_0_sw_init(void *handle)
544 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
546 gfxhub_v1_0_init(adev);
547 mmhub_v1_0_init(adev);
549 spin_lock_init(&adev->mc.invalidate_lock);
551 switch (adev->asic_type) {
553 adev->mc.vram_type = AMDGPU_VRAM_TYPE_UNKNOWN;
554 if (adev->rev_id == 0x0 || adev->rev_id == 0x1) {
555 adev->vm_manager.vm_size = 1U << 18;
556 adev->vm_manager.block_size = 9;
557 adev->vm_manager.num_level = 3;
558 amdgpu_vm_set_fragment_size(adev, 9);
560 /* vm_size is 64GB for legacy 2-level page support */
561 amdgpu_vm_adjust_size(adev, 64, 9);
562 adev->vm_manager.num_level = 1;
566 /* XXX Don't know how to get VRAM type yet. */
567 adev->mc.vram_type = AMDGPU_VRAM_TYPE_HBM;
569 * To fulfill 4-level page support,
570 * vm size is 256TB (48bit), maximum size of Vega10,
571 * block size 512 (9bit)
573 adev->vm_manager.vm_size = 1U << 18;
574 adev->vm_manager.block_size = 9;
575 adev->vm_manager.num_level = 3;
576 amdgpu_vm_set_fragment_size(adev, 9);
582 DRM_INFO("vm size is %llu GB, block size is %u-bit,fragment size is %u-bit\n",
583 adev->vm_manager.vm_size,
584 adev->vm_manager.block_size,
585 adev->vm_manager.fragment_size);
587 /* This interrupt is VMC page fault.*/
588 r = amdgpu_irq_add_id(adev, AMDGPU_IH_CLIENTID_VMC, 0,
590 r = amdgpu_irq_add_id(adev, AMDGPU_IH_CLIENTID_UTCL2, 0,
596 adev->vm_manager.max_pfn = adev->vm_manager.vm_size << 18;
598 /* Set the internal MC address mask
599 * This is the max address of the GPU's
600 * internal address space.
602 adev->mc.mc_mask = 0xffffffffffffULL; /* 48 bit MC */
605 * It needs to reserve 8M stolen memory for vega10
606 * TODO: Figure out how to avoid that...
608 adev->mc.stolen_size = 8 * 1024 * 1024;
610 /* set DMA mask + need_dma32 flags.
611 * PCIE - can handle 44-bits.
612 * IGP - can handle 44-bits
613 * PCI - dma32 for legacy pci gart, 44 bits on vega10
615 adev->need_dma32 = false;
616 dma_bits = adev->need_dma32 ? 32 : 44;
617 r = pci_set_dma_mask(adev->pdev, DMA_BIT_MASK(dma_bits));
619 adev->need_dma32 = true;
621 printk(KERN_WARNING "amdgpu: No suitable DMA available.\n");
623 r = pci_set_consistent_dma_mask(adev->pdev, DMA_BIT_MASK(dma_bits));
625 pci_set_consistent_dma_mask(adev->pdev, DMA_BIT_MASK(32));
626 printk(KERN_WARNING "amdgpu: No coherent DMA available.\n");
629 r = gmc_v9_0_mc_init(adev);
634 r = amdgpu_bo_init(adev);
638 r = gmc_v9_0_gart_init(adev);
644 * VMID 0 is reserved for System
645 * amdgpu graphics/compute will use VMIDs 1-7
646 * amdkfd will use VMIDs 8-15
648 adev->vm_manager.id_mgr[AMDGPU_GFXHUB].num_ids = AMDGPU_NUM_OF_VMIDS;
649 adev->vm_manager.id_mgr[AMDGPU_MMHUB].num_ids = AMDGPU_NUM_OF_VMIDS;
651 amdgpu_vm_manager_init(adev);
657 * gmc_v8_0_gart_fini - vm fini callback
659 * @adev: amdgpu_device pointer
661 * Tears down the driver GART/VM setup (CIK).
663 static void gmc_v9_0_gart_fini(struct amdgpu_device *adev)
665 amdgpu_gart_table_vram_free(adev);
666 amdgpu_gart_fini(adev);
669 static int gmc_v9_0_sw_fini(void *handle)
671 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
673 amdgpu_vm_manager_fini(adev);
674 gmc_v9_0_gart_fini(adev);
675 amdgpu_gem_force_release(adev);
676 amdgpu_bo_fini(adev);
681 static void gmc_v9_0_init_golden_registers(struct amdgpu_device *adev)
683 switch (adev->asic_type) {
694 * gmc_v9_0_gart_enable - gart enable
696 * @adev: amdgpu_device pointer
698 static int gmc_v9_0_gart_enable(struct amdgpu_device *adev)
704 amdgpu_program_register_sequence(adev,
705 golden_settings_vega10_hdp,
706 (const u32)ARRAY_SIZE(golden_settings_vega10_hdp));
708 if (adev->gart.robj == NULL) {
709 dev_err(adev->dev, "No VRAM object for PCIE GART.\n");
712 r = amdgpu_gart_table_vram_pin(adev);
716 /* After HDP is initialized, flush HDP.*/
717 if (adev->flags & AMD_IS_APU)
718 nbio_v7_0_hdp_flush(adev);
720 nbio_v6_1_hdp_flush(adev);
722 switch (adev->asic_type) {
724 mmhub_v1_0_initialize_power_gating(adev);
725 mmhub_v1_0_update_power_gating(adev, true);
731 r = gfxhub_v1_0_gart_enable(adev);
735 r = mmhub_v1_0_gart_enable(adev);
739 tmp = RREG32_SOC15(HDP, 0, mmHDP_MISC_CNTL);
740 tmp |= HDP_MISC_CNTL__FLUSH_INVALIDATE_CACHE_MASK;
741 WREG32_SOC15(HDP, 0, mmHDP_MISC_CNTL, tmp);
743 tmp = RREG32_SOC15(HDP, 0, mmHDP_HOST_PATH_CNTL);
744 WREG32_SOC15(HDP, 0, mmHDP_HOST_PATH_CNTL, tmp);
747 if (amdgpu_vm_fault_stop == AMDGPU_VM_FAULT_STOP_ALWAYS)
752 gfxhub_v1_0_set_fault_enable_default(adev, value);
753 mmhub_v1_0_set_fault_enable_default(adev, value);
755 gmc_v9_0_gart_flush_gpu_tlb(adev, 0);
757 DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
758 (unsigned)(adev->mc.gart_size >> 20),
759 (unsigned long long)adev->gart.table_addr);
760 adev->gart.ready = true;
764 static int gmc_v9_0_hw_init(void *handle)
767 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
769 /* The sequence of these two function calls matters.*/
770 gmc_v9_0_init_golden_registers(adev);
772 if (adev->mode_info.num_crtc) {
775 /* Lockout access through VGA aperture*/
776 tmp = RREG32_SOC15(DCE, 0, mmVGA_HDP_CONTROL);
777 tmp = REG_SET_FIELD(tmp, VGA_HDP_CONTROL, VGA_MEMORY_DISABLE, 1);
778 WREG32_SOC15(DCE, 0, mmVGA_HDP_CONTROL, tmp);
780 /* disable VGA render */
781 tmp = RREG32_SOC15(DCE, 0, mmVGA_RENDER_CONTROL);
782 tmp = REG_SET_FIELD(tmp, VGA_RENDER_CONTROL, VGA_VSTATUS_CNTL, 0);
783 WREG32_SOC15(DCE, 0, mmVGA_RENDER_CONTROL, tmp);
786 r = gmc_v9_0_gart_enable(adev);
792 * gmc_v9_0_gart_disable - gart disable
794 * @adev: amdgpu_device pointer
796 * This disables all VM page table.
798 static void gmc_v9_0_gart_disable(struct amdgpu_device *adev)
800 gfxhub_v1_0_gart_disable(adev);
801 mmhub_v1_0_gart_disable(adev);
802 amdgpu_gart_table_vram_unpin(adev);
805 static int gmc_v9_0_hw_fini(void *handle)
807 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
809 if (amdgpu_sriov_vf(adev)) {
810 /* full access mode, so don't touch any GMC register */
811 DRM_DEBUG("For SRIOV client, shouldn't do anything.\n");
815 amdgpu_irq_put(adev, &adev->mc.vm_fault, 0);
816 gmc_v9_0_gart_disable(adev);
821 static int gmc_v9_0_suspend(void *handle)
823 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
825 gmc_v9_0_hw_fini(adev);
830 static int gmc_v9_0_resume(void *handle)
833 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
835 r = gmc_v9_0_hw_init(adev);
839 amdgpu_vm_reset_all_ids(adev);
844 static bool gmc_v9_0_is_idle(void *handle)
846 /* MC is always ready in GMC v9.*/
850 static int gmc_v9_0_wait_for_idle(void *handle)
852 /* There is no need to wait for MC idle in GMC v9.*/
856 static int gmc_v9_0_soft_reset(void *handle)
858 /* XXX for emulation.*/
862 static int gmc_v9_0_set_clockgating_state(void *handle,
863 enum amd_clockgating_state state)
865 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
867 return mmhub_v1_0_set_clockgating(adev, state);
870 static void gmc_v9_0_get_clockgating_state(void *handle, u32 *flags)
872 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
874 mmhub_v1_0_get_clockgating(adev, flags);
877 static int gmc_v9_0_set_powergating_state(void *handle,
878 enum amd_powergating_state state)
883 const struct amd_ip_funcs gmc_v9_0_ip_funcs = {
885 .early_init = gmc_v9_0_early_init,
886 .late_init = gmc_v9_0_late_init,
887 .sw_init = gmc_v9_0_sw_init,
888 .sw_fini = gmc_v9_0_sw_fini,
889 .hw_init = gmc_v9_0_hw_init,
890 .hw_fini = gmc_v9_0_hw_fini,
891 .suspend = gmc_v9_0_suspend,
892 .resume = gmc_v9_0_resume,
893 .is_idle = gmc_v9_0_is_idle,
894 .wait_for_idle = gmc_v9_0_wait_for_idle,
895 .soft_reset = gmc_v9_0_soft_reset,
896 .set_clockgating_state = gmc_v9_0_set_clockgating_state,
897 .set_powergating_state = gmc_v9_0_set_powergating_state,
898 .get_clockgating_state = gmc_v9_0_get_clockgating_state,
901 const struct amdgpu_ip_block_version gmc_v9_0_ip_block =
903 .type = AMD_IP_BLOCK_TYPE_GMC,
907 .funcs = &gmc_v9_0_ip_funcs,