2 * Copyright 2023 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>
24 #include <linux/pci.h>
26 #include <drm/drm_cache.h>
29 #include "amdgpu_atomfirmware.h"
30 #include "gmc_v12_0.h"
31 #include "athub/athub_4_1_0_sh_mask.h"
32 #include "athub/athub_4_1_0_offset.h"
33 #include "oss/osssys_7_0_0_offset.h"
34 #include "ivsrcid/vmc/irqsrcs_vmc_1_0.h"
35 #include "soc24_enum.h"
38 #include "soc15_common.h"
39 #include "nbif_v6_3_1.h"
40 #include "gfxhub_v12_0.h"
41 #include "mmhub_v4_1_0.h"
42 #include "athub_v4_1_0.h"
45 static int gmc_v12_0_ecc_interrupt_state(struct amdgpu_device *adev,
46 struct amdgpu_irq_src *src,
48 enum amdgpu_interrupt_state state)
53 static int gmc_v12_0_vm_fault_interrupt_state(struct amdgpu_device *adev,
54 struct amdgpu_irq_src *src, unsigned type,
55 enum amdgpu_interrupt_state state)
58 case AMDGPU_IRQ_STATE_DISABLE:
60 amdgpu_gmc_set_vm_fault_masks(adev, AMDGPU_MMHUB0(0), false);
62 /* This works because this interrupt is only
63 * enabled at init/resume and disabled in
64 * fini/suspend, so the overall state doesn't
65 * change over the course of suspend/resume.
68 amdgpu_gmc_set_vm_fault_masks(adev, AMDGPU_GFXHUB(0), false);
70 case AMDGPU_IRQ_STATE_ENABLE:
72 amdgpu_gmc_set_vm_fault_masks(adev, AMDGPU_MMHUB0(0), true);
74 /* This works because this interrupt is only
75 * enabled at init/resume and disabled in
76 * fini/suspend, so the overall state doesn't
77 * change over the course of suspend/resume.
80 amdgpu_gmc_set_vm_fault_masks(adev, AMDGPU_GFXHUB(0), true);
89 static int gmc_v12_0_process_interrupt(struct amdgpu_device *adev,
90 struct amdgpu_irq_src *source,
91 struct amdgpu_iv_entry *entry)
93 struct amdgpu_vmhub *hub;
97 addr = (u64)entry->src_data[0] << 12;
98 addr |= ((u64)entry->src_data[1] & 0xf) << 44;
100 if (entry->client_id == SOC21_IH_CLIENTID_VMC)
101 hub = &adev->vmhub[AMDGPU_MMHUB0(0)];
103 hub = &adev->vmhub[AMDGPU_GFXHUB(0)];
105 if (!amdgpu_sriov_vf(adev)) {
107 * Issue a dummy read to wait for the status register to
108 * be updated to avoid reading an incorrect value due to
109 * the new fast GRBM interface.
111 if (entry->vmid_src == AMDGPU_GFXHUB(0))
112 RREG32(hub->vm_l2_pro_fault_status);
114 status = RREG32(hub->vm_l2_pro_fault_status);
115 WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1);
117 amdgpu_vm_update_fault_cache(adev, entry->pasid, addr, status,
118 entry->vmid_src ? AMDGPU_MMHUB0(0) : AMDGPU_GFXHUB(0));
121 if (printk_ratelimit()) {
122 struct amdgpu_task_info *task_info;
125 "[%s] page fault (src_id:%u ring:%u vmid:%u pasid:%u)\n",
126 entry->vmid_src ? "mmhub" : "gfxhub",
127 entry->src_id, entry->ring_id, entry->vmid, entry->pasid);
128 task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
131 " in process %s pid %d thread %s pid %d)\n",
132 task_info->process_name, task_info->tgid,
133 task_info->task_name, task_info->pid);
134 amdgpu_vm_put_task_info(task_info);
137 dev_err(adev->dev, " in page starting at address 0x%016llx from client %d\n",
138 addr, entry->client_id);
140 if (!amdgpu_sriov_vf(adev))
141 hub->vmhub_funcs->print_l2_protection_fault_status(adev, status);
147 static const struct amdgpu_irq_src_funcs gmc_v12_0_irq_funcs = {
148 .set = gmc_v12_0_vm_fault_interrupt_state,
149 .process = gmc_v12_0_process_interrupt,
152 static const struct amdgpu_irq_src_funcs gmc_v12_0_ecc_funcs = {
153 .set = gmc_v12_0_ecc_interrupt_state,
154 .process = amdgpu_umc_process_ecc_irq,
157 static void gmc_v12_0_set_irq_funcs(struct amdgpu_device *adev)
159 adev->gmc.vm_fault.num_types = 1;
160 adev->gmc.vm_fault.funcs = &gmc_v12_0_irq_funcs;
162 if (!amdgpu_sriov_vf(adev)) {
163 adev->gmc.ecc_irq.num_types = 1;
164 adev->gmc.ecc_irq.funcs = &gmc_v12_0_ecc_funcs;
169 * gmc_v12_0_use_invalidate_semaphore - judge whether to use semaphore
171 * @adev: amdgpu_device pointer
175 static bool gmc_v12_0_use_invalidate_semaphore(struct amdgpu_device *adev,
178 return ((vmhub == AMDGPU_MMHUB0(0)) &&
179 (!amdgpu_sriov_vf(adev)));
182 static bool gmc_v12_0_get_vmid_pasid_mapping_info(
183 struct amdgpu_device *adev,
184 uint8_t vmid, uint16_t *p_pasid)
186 *p_pasid = RREG32(SOC15_REG_OFFSET(OSSSYS, 0, regIH_VMID_0_LUT) + vmid) & 0xffff;
193 * VMID 0 is the physical GPU addresses as used by the kernel.
194 * VMIDs 1-15 are used for userspace clients and are handled
195 * by the amdgpu vm/hsa code.
198 static void gmc_v12_0_flush_vm_hub(struct amdgpu_device *adev, uint32_t vmid,
199 unsigned int vmhub, uint32_t flush_type)
201 bool use_semaphore = gmc_v12_0_use_invalidate_semaphore(adev, vmhub);
202 struct amdgpu_vmhub *hub = &adev->vmhub[vmhub];
203 u32 inv_req = hub->vmhub_funcs->get_invalidate_req(vmid, flush_type);
205 /* Use register 17 for GART */
206 const unsigned eng = 17;
208 unsigned char hub_ip = 0;
210 hub_ip = (vmhub == AMDGPU_GFXHUB(0)) ?
211 GC_HWIP : MMHUB_HWIP;
213 spin_lock(&adev->gmc.invalidate_lock);
215 * It may lose gpuvm invalidate acknowldege state across power-gating
216 * off cycle, add semaphore acquire before invalidation and semaphore
217 * release after invalidation to avoid entering power gated state
221 /* TODO: It needs to continue working on debugging with semaphore for GFXHUB as well. */
223 for (i = 0; i < adev->usec_timeout; i++) {
224 /* a read return value of 1 means semaphore acuqire */
225 tmp = RREG32_RLC_NO_KIQ(hub->vm_inv_eng0_sem +
226 hub->eng_distance * eng, hub_ip);
232 if (i >= adev->usec_timeout)
234 "Timeout waiting for sem acquire in VM flush!\n");
237 WREG32_RLC_NO_KIQ(hub->vm_inv_eng0_req + hub->eng_distance * eng, inv_req, hub_ip);
239 /* Wait for ACK with a delay.*/
240 for (i = 0; i < adev->usec_timeout; i++) {
241 tmp = RREG32_RLC_NO_KIQ(hub->vm_inv_eng0_ack +
242 hub->eng_distance * eng, hub_ip);
250 /* TODO: It needs to continue working on debugging with semaphore for GFXHUB as well. */
253 * add semaphore release after invalidation,
254 * write with 0 means semaphore release
256 WREG32_RLC_NO_KIQ(hub->vm_inv_eng0_sem +
257 hub->eng_distance * eng, 0, hub_ip);
259 /* Issue additional private vm invalidation to MMHUB */
260 if ((vmhub != AMDGPU_GFXHUB(0)) &&
261 (hub->vm_l2_bank_select_reserved_cid2) &&
262 !amdgpu_sriov_vf(adev)) {
263 inv_req = RREG32_NO_KIQ(hub->vm_l2_bank_select_reserved_cid2);
264 /* bit 25: RSERVED_CACHE_PRIVATE_INVALIDATION */
265 inv_req |= (1 << 25);
266 /* Issue private invalidation */
267 WREG32_NO_KIQ(hub->vm_l2_bank_select_reserved_cid2, inv_req);
268 /* Read back to ensure invalidation is done*/
269 RREG32_NO_KIQ(hub->vm_l2_bank_select_reserved_cid2);
272 spin_unlock(&adev->gmc.invalidate_lock);
274 if (i < adev->usec_timeout)
277 dev_err(adev->dev, "Timeout waiting for VM flush ACK!\n");
281 * gmc_v12_0_flush_gpu_tlb - gart tlb flush callback
283 * @adev: amdgpu_device pointer
284 * @vmid: vm instance to flush
285 * @vmhub: which hub to flush
286 * @flush_type: the flush type
288 * Flush the TLB for the requested page table.
290 static void gmc_v12_0_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid,
291 uint32_t vmhub, uint32_t flush_type)
293 if ((vmhub == AMDGPU_GFXHUB(0)) && !adev->gfx.is_poweron)
296 /* flush hdp cache */
297 adev->hdp.funcs->flush_hdp(adev, NULL);
299 /* This is necessary for SRIOV as well as for GFXOFF to function
300 * properly under bare metal
302 if ((adev->gfx.kiq[0].ring.sched.ready || adev->mes.ring.sched.ready) &&
303 (amdgpu_sriov_runtime(adev) || !amdgpu_sriov_vf(adev))) {
304 struct amdgpu_vmhub *hub = &adev->vmhub[vmhub];
305 const unsigned eng = 17;
306 u32 inv_req = hub->vmhub_funcs->get_invalidate_req(vmid, flush_type);
307 u32 req = hub->vm_inv_eng0_req + hub->eng_distance * eng;
308 u32 ack = hub->vm_inv_eng0_ack + hub->eng_distance * eng;
310 amdgpu_gmc_fw_reg_write_reg_wait(adev, req, ack, inv_req,
311 1 << vmid, GET_INST(GC, 0));
315 mutex_lock(&adev->mman.gtt_window_lock);
316 gmc_v12_0_flush_vm_hub(adev, vmid, vmhub, 0);
317 mutex_unlock(&adev->mman.gtt_window_lock);
322 * gmc_v12_0_flush_gpu_tlb_pasid - tlb flush via pasid
324 * @adev: amdgpu_device pointer
325 * @pasid: pasid to be flush
326 * @flush_type: the flush type
327 * @all_hub: flush all hubs
328 * @inst: is used to select which instance of KIQ to use for the invalidation
330 * Flush the TLB for the requested pasid.
332 static void gmc_v12_0_flush_gpu_tlb_pasid(struct amdgpu_device *adev,
333 uint16_t pasid, uint32_t flush_type,
334 bool all_hub, uint32_t inst)
339 for (vmid = 1; vmid < 16; vmid++) {
342 valid = gmc_v12_0_get_vmid_pasid_mapping_info(adev, vmid,
344 if (!valid || queried != pasid)
348 for_each_set_bit(i, adev->vmhubs_mask,
350 gmc_v12_0_flush_gpu_tlb(adev, vmid, i,
353 gmc_v12_0_flush_gpu_tlb(adev, vmid, AMDGPU_GFXHUB(0),
359 static uint64_t gmc_v12_0_emit_flush_gpu_tlb(struct amdgpu_ring *ring,
360 unsigned vmid, uint64_t pd_addr)
362 bool use_semaphore = gmc_v12_0_use_invalidate_semaphore(ring->adev, ring->vm_hub);
363 struct amdgpu_vmhub *hub = &ring->adev->vmhub[ring->vm_hub];
364 uint32_t req = hub->vmhub_funcs->get_invalidate_req(vmid, 0);
365 unsigned eng = ring->vm_inv_eng;
368 * It may lose gpuvm invalidate acknowldege state across power-gating
369 * off cycle, add semaphore acquire before invalidation and semaphore
370 * release after invalidation to avoid entering power gated state
374 /* TODO: It needs to continue working on debugging with semaphore for GFXHUB as well. */
376 /* a read return value of 1 means semaphore acuqire */
377 amdgpu_ring_emit_reg_wait(ring,
378 hub->vm_inv_eng0_sem +
379 hub->eng_distance * eng, 0x1, 0x1);
381 amdgpu_ring_emit_wreg(ring, hub->ctx0_ptb_addr_lo32 +
382 (hub->ctx_addr_distance * vmid),
383 lower_32_bits(pd_addr));
385 amdgpu_ring_emit_wreg(ring, hub->ctx0_ptb_addr_hi32 +
386 (hub->ctx_addr_distance * vmid),
387 upper_32_bits(pd_addr));
389 amdgpu_ring_emit_reg_write_reg_wait(ring, hub->vm_inv_eng0_req +
390 hub->eng_distance * eng,
391 hub->vm_inv_eng0_ack +
392 hub->eng_distance * eng,
395 /* TODO: It needs to continue working on debugging with semaphore for GFXHUB as well. */
398 * add semaphore release after invalidation,
399 * write with 0 means semaphore release
401 amdgpu_ring_emit_wreg(ring, hub->vm_inv_eng0_sem +
402 hub->eng_distance * eng, 0);
407 static void gmc_v12_0_emit_pasid_mapping(struct amdgpu_ring *ring, unsigned vmid,
410 struct amdgpu_device *adev = ring->adev;
413 /* MES fw manages IH_VMID_x_LUT updating */
414 if (ring->is_mes_queue)
417 if (ring->vm_hub == AMDGPU_GFXHUB(0))
418 reg = SOC15_REG_OFFSET(OSSSYS, 0, regIH_VMID_0_LUT) + vmid;
420 reg = SOC15_REG_OFFSET(OSSSYS, 0, regIH_VMID_0_LUT_MM) + vmid;
422 amdgpu_ring_emit_wreg(ring, reg, pasid);
434 * 51:48 reserved for future
435 * 47:12 4k physical page base address
447 * 62:58 block fragment size
452 * 51:48 reserved for future
453 * 47:6 physical base address of PD or PTE
460 static uint64_t gmc_v12_0_map_mtype(struct amdgpu_device *adev, uint32_t flags)
463 case AMDGPU_VM_MTYPE_DEFAULT:
464 return AMDGPU_PTE_MTYPE_GFX12(0ULL, MTYPE_NC);
465 case AMDGPU_VM_MTYPE_NC:
466 return AMDGPU_PTE_MTYPE_GFX12(0ULL, MTYPE_NC);
467 case AMDGPU_VM_MTYPE_UC:
468 return AMDGPU_PTE_MTYPE_GFX12(0ULL, MTYPE_UC);
470 return AMDGPU_PTE_MTYPE_GFX12(0ULL, MTYPE_NC);
474 static void gmc_v12_0_get_vm_pde(struct amdgpu_device *adev, int level,
475 uint64_t *addr, uint64_t *flags)
477 if (!(*flags & AMDGPU_PDE_PTE_GFX12) && !(*flags & AMDGPU_PTE_SYSTEM))
478 *addr = adev->vm_manager.vram_base_offset + *addr -
479 adev->gmc.vram_start;
480 BUG_ON(*addr & 0xFFFF00000000003FULL);
482 if (!adev->gmc.translate_further)
485 if (level == AMDGPU_VM_PDB1) {
486 /* Set the block fragment size */
487 if (!(*flags & AMDGPU_PDE_PTE_GFX12))
488 *flags |= AMDGPU_PDE_BFS_GFX12(0x9);
490 } else if (level == AMDGPU_VM_PDB0) {
491 if (*flags & AMDGPU_PDE_PTE_GFX12)
492 *flags &= ~AMDGPU_PDE_PTE_GFX12;
496 static void gmc_v12_0_get_vm_pte(struct amdgpu_device *adev,
497 struct amdgpu_bo_va_mapping *mapping,
500 struct amdgpu_bo *bo = mapping->bo_va->base.bo;
501 struct amdgpu_device *bo_adev;
502 bool coherent, is_system;
505 *flags &= ~AMDGPU_PTE_EXECUTABLE;
506 *flags |= mapping->flags & AMDGPU_PTE_EXECUTABLE;
508 *flags &= ~AMDGPU_PTE_MTYPE_GFX12_MASK;
509 *flags |= (mapping->flags & AMDGPU_PTE_MTYPE_GFX12_MASK);
511 if (mapping->flags & AMDGPU_PTE_PRT_GFX12) {
512 *flags |= AMDGPU_PTE_PRT_GFX12;
513 *flags |= AMDGPU_PTE_SNOOPED;
514 *flags |= AMDGPU_PTE_SYSTEM;
515 *flags |= AMDGPU_PTE_IS_PTE;
516 *flags &= ~AMDGPU_PTE_VALID;
522 if (bo->flags & (AMDGPU_GEM_CREATE_COHERENT |
523 AMDGPU_GEM_CREATE_UNCACHED))
524 *flags = AMDGPU_PTE_MTYPE_GFX12(*flags, MTYPE_UC);
526 bo_adev = amdgpu_ttm_adev(bo->tbo.bdev);
527 coherent = bo->flags & AMDGPU_GEM_CREATE_COHERENT;
528 is_system = (bo->tbo.resource->mem_type == TTM_PL_TT) ||
529 (bo->tbo.resource->mem_type == AMDGPU_PL_PREEMPT);
531 if (bo && bo->flags & AMDGPU_GEM_CREATE_GFX12_DCC)
532 *flags |= AMDGPU_PTE_DCC;
535 if (is_system || ((bo_adev != adev) && coherent))
536 *flags = AMDGPU_PTE_MTYPE_GFX12(*flags, MTYPE_NC);
540 static unsigned gmc_v12_0_get_vbios_fb_size(struct amdgpu_device *adev)
545 static const struct amdgpu_gmc_funcs gmc_v12_0_gmc_funcs = {
546 .flush_gpu_tlb = gmc_v12_0_flush_gpu_tlb,
547 .flush_gpu_tlb_pasid = gmc_v12_0_flush_gpu_tlb_pasid,
548 .emit_flush_gpu_tlb = gmc_v12_0_emit_flush_gpu_tlb,
549 .emit_pasid_mapping = gmc_v12_0_emit_pasid_mapping,
550 .map_mtype = gmc_v12_0_map_mtype,
551 .get_vm_pde = gmc_v12_0_get_vm_pde,
552 .get_vm_pte = gmc_v12_0_get_vm_pte,
553 .get_vbios_fb_size = gmc_v12_0_get_vbios_fb_size,
556 static void gmc_v12_0_set_gmc_funcs(struct amdgpu_device *adev)
558 adev->gmc.gmc_funcs = &gmc_v12_0_gmc_funcs;
561 static void gmc_v12_0_set_umc_funcs(struct amdgpu_device *adev)
566 static void gmc_v12_0_set_mmhub_funcs(struct amdgpu_device *adev)
568 switch (amdgpu_ip_version(adev, MMHUB_HWIP, 0)) {
569 case IP_VERSION(4, 1, 0):
570 adev->mmhub.funcs = &mmhub_v4_1_0_funcs;
577 static void gmc_v12_0_set_gfxhub_funcs(struct amdgpu_device *adev)
579 switch (amdgpu_ip_version(adev, GC_HWIP, 0)) {
580 case IP_VERSION(12, 0, 0):
581 case IP_VERSION(12, 0, 1):
582 adev->gfxhub.funcs = &gfxhub_v12_0_funcs;
589 static int gmc_v12_0_early_init(void *handle)
591 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
593 gmc_v12_0_set_gfxhub_funcs(adev);
594 gmc_v12_0_set_mmhub_funcs(adev);
595 gmc_v12_0_set_gmc_funcs(adev);
596 gmc_v12_0_set_irq_funcs(adev);
597 gmc_v12_0_set_umc_funcs(adev);
599 adev->gmc.shared_aperture_start = 0x2000000000000000ULL;
600 adev->gmc.shared_aperture_end =
601 adev->gmc.shared_aperture_start + (4ULL << 30) - 1;
602 adev->gmc.private_aperture_start = 0x1000000000000000ULL;
603 adev->gmc.private_aperture_end =
604 adev->gmc.private_aperture_start + (4ULL << 30) - 1;
609 static int gmc_v12_0_late_init(void *handle)
611 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
614 r = amdgpu_gmc_allocate_vm_inv_eng(adev);
618 r = amdgpu_gmc_ras_late_init(adev);
622 return amdgpu_irq_get(adev, &adev->gmc.vm_fault, 0);
625 static void gmc_v12_0_vram_gtt_location(struct amdgpu_device *adev,
626 struct amdgpu_gmc *mc)
630 base = adev->mmhub.funcs->get_fb_location(adev);
632 amdgpu_gmc_set_agp_default(adev, mc);
633 amdgpu_gmc_vram_location(adev, &adev->gmc, base);
634 amdgpu_gmc_gart_location(adev, mc, AMDGPU_GART_PLACEMENT_LOW);
635 if (!amdgpu_sriov_vf(adev) && (amdgpu_agp == 1))
636 amdgpu_gmc_agp_location(adev, mc);
638 /* base offset of vram pages */
639 if (amdgpu_sriov_vf(adev))
640 adev->vm_manager.vram_base_offset = 0;
642 adev->vm_manager.vram_base_offset = adev->mmhub.funcs->get_mc_fb_offset(adev);
646 * gmc_v12_0_mc_init - initialize the memory controller driver params
648 * @adev: amdgpu_device pointer
650 * Look up the amount of vram, vram width, and decide how to place
651 * vram and gart within the GPU's physical address space.
652 * Returns 0 for success.
654 static int gmc_v12_0_mc_init(struct amdgpu_device *adev)
658 /* size in MB on si */
659 adev->gmc.mc_vram_size =
660 adev->nbio.funcs->get_memsize(adev) * 1024ULL * 1024ULL;
661 adev->gmc.real_vram_size = adev->gmc.mc_vram_size;
663 if (!(adev->flags & AMD_IS_APU)) {
664 r = amdgpu_device_resize_fb_bar(adev);
669 adev->gmc.aper_base = pci_resource_start(adev->pdev, 0);
670 adev->gmc.aper_size = pci_resource_len(adev->pdev, 0);
673 if ((adev->flags & AMD_IS_APU) && !amdgpu_passthrough(adev)) {
674 adev->gmc.aper_base = adev->mmhub.funcs->get_mc_fb_offset(adev);
675 adev->gmc.aper_size = adev->gmc.real_vram_size;
678 /* In case the PCI BAR is larger than the actual amount of vram */
679 adev->gmc.visible_vram_size = adev->gmc.aper_size;
680 if (adev->gmc.visible_vram_size > adev->gmc.real_vram_size)
681 adev->gmc.visible_vram_size = adev->gmc.real_vram_size;
683 /* set the gart size */
684 if (amdgpu_gart_size == -1) {
685 adev->gmc.gart_size = 512ULL << 20;
687 adev->gmc.gart_size = (u64)amdgpu_gart_size << 20;
689 gmc_v12_0_vram_gtt_location(adev, &adev->gmc);
694 static int gmc_v12_0_gart_init(struct amdgpu_device *adev)
699 WARN(1, "PCIE GART already initialized\n");
703 /* Initialize common gart structure */
704 r = amdgpu_gart_init(adev);
708 adev->gart.table_size = adev->gart.num_gpu_pages * 8;
709 adev->gart.gart_pte_flags = AMDGPU_PTE_MTYPE_GFX12(0ULL, MTYPE_UC) |
710 AMDGPU_PTE_EXECUTABLE |
713 return amdgpu_gart_table_vram_alloc(adev);
716 static int gmc_v12_0_sw_init(void *handle)
718 int r, vram_width = 0, vram_type = 0, vram_vendor = 0;
719 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
721 adev->mmhub.funcs->init(adev);
723 adev->gfxhub.funcs->init(adev);
725 spin_lock_init(&adev->gmc.invalidate_lock);
727 r = amdgpu_atomfirmware_get_vram_info(adev,
728 &vram_width, &vram_type, &vram_vendor);
729 adev->gmc.vram_width = vram_width;
731 adev->gmc.vram_type = vram_type;
732 adev->gmc.vram_vendor = vram_vendor;
734 switch (amdgpu_ip_version(adev, GC_HWIP, 0)) {
735 case IP_VERSION(12, 0, 0):
736 case IP_VERSION(12, 0, 1):
737 set_bit(AMDGPU_GFXHUB(0), adev->vmhubs_mask);
738 set_bit(AMDGPU_MMHUB0(0), adev->vmhubs_mask);
740 * To fulfill 4-level page support,
741 * vm size is 256TB (48bit), maximum size,
742 * block size 512 (9bit)
744 amdgpu_vm_adjust_size(adev, 256 * 1024, 9, 3, 48);
750 /* This interrupt is VMC page fault.*/
751 r = amdgpu_irq_add_id(adev, SOC21_IH_CLIENTID_VMC,
752 VMC_1_0__SRCID__VM_FAULT,
753 &adev->gmc.vm_fault);
758 r = amdgpu_irq_add_id(adev, SOC21_IH_CLIENTID_GFX,
759 UTCL2_1_0__SRCID__FAULT,
760 &adev->gmc.vm_fault);
764 if (!amdgpu_sriov_vf(adev)) {
765 /* interrupt sent to DF. */
766 r = amdgpu_irq_add_id(adev, SOC21_IH_CLIENTID_DF, 0,
773 * Set the internal MC address mask This is the max address of the GPU's
774 * internal address space.
776 adev->gmc.mc_mask = 0xffffffffffffULL; /* 48 bit MC */
778 r = dma_set_mask_and_coherent(adev->dev, DMA_BIT_MASK(44));
780 printk(KERN_WARNING "amdgpu: No suitable DMA available.\n");
784 adev->need_swiotlb = drm_need_swiotlb(44);
786 r = gmc_v12_0_mc_init(adev);
790 amdgpu_gmc_get_vbios_allocations(adev);
793 r = amdgpu_bo_init(adev);
797 r = gmc_v12_0_gart_init(adev);
803 * VMID 0 is reserved for System
804 * amdgpu graphics/compute will use VMIDs 1-7
805 * amdkfd will use VMIDs 8-15
807 adev->vm_manager.first_kfd_vmid = 8;
809 amdgpu_vm_manager_init(adev);
815 * gmc_v12_0_gart_fini - vm fini callback
817 * @adev: amdgpu_device pointer
819 * Tears down the driver GART/VM setup (CIK).
821 static void gmc_v12_0_gart_fini(struct amdgpu_device *adev)
823 amdgpu_gart_table_vram_free(adev);
826 static int gmc_v12_0_sw_fini(void *handle)
828 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
830 amdgpu_vm_manager_fini(adev);
831 gmc_v12_0_gart_fini(adev);
832 amdgpu_gem_force_release(adev);
833 amdgpu_bo_fini(adev);
838 static void gmc_v12_0_init_golden_registers(struct amdgpu_device *adev)
843 * gmc_v12_0_gart_enable - gart enable
845 * @adev: amdgpu_device pointer
847 static int gmc_v12_0_gart_enable(struct amdgpu_device *adev)
852 if (adev->gart.bo == NULL) {
853 dev_err(adev->dev, "No VRAM object for PCIE GART.\n");
857 amdgpu_gtt_mgr_recover(&adev->mman.gtt_mgr);
859 r = adev->mmhub.funcs->gart_enable(adev);
863 /* Flush HDP after it is initialized */
864 adev->hdp.funcs->flush_hdp(adev, NULL);
866 value = (amdgpu_vm_fault_stop == AMDGPU_VM_FAULT_STOP_ALWAYS) ?
869 adev->mmhub.funcs->set_fault_enable_default(adev, value);
870 gmc_v12_0_flush_gpu_tlb(adev, 0, AMDGPU_MMHUB0(0), 0);
872 dev_info(adev->dev, "PCIE GART of %uM enabled (table at 0x%016llX).\n",
873 (unsigned)(adev->gmc.gart_size >> 20),
874 (unsigned long long)amdgpu_bo_gpu_offset(adev->gart.bo));
879 static int gmc_v12_0_hw_init(void *handle)
882 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
884 /* The sequence of these two function calls matters.*/
885 gmc_v12_0_init_golden_registers(adev);
887 r = gmc_v12_0_gart_enable(adev);
891 if (adev->umc.funcs && adev->umc.funcs->init_registers)
892 adev->umc.funcs->init_registers(adev);
898 * gmc_v12_0_gart_disable - gart disable
900 * @adev: amdgpu_device pointer
902 * This disables all VM page table.
904 static void gmc_v12_0_gart_disable(struct amdgpu_device *adev)
906 adev->mmhub.funcs->gart_disable(adev);
909 static int gmc_v12_0_hw_fini(void *handle)
911 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
913 if (amdgpu_sriov_vf(adev)) {
914 /* full access mode, so don't touch any GMC register */
915 DRM_DEBUG("For SRIOV client, shouldn't do anything.\n");
919 amdgpu_irq_put(adev, &adev->gmc.vm_fault, 0);
921 if (adev->gmc.ecc_irq.funcs &&
922 amdgpu_ras_is_supported(adev, AMDGPU_RAS_BLOCK__UMC))
923 amdgpu_irq_put(adev, &adev->gmc.ecc_irq, 0);
925 gmc_v12_0_gart_disable(adev);
930 static int gmc_v12_0_suspend(void *handle)
932 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
934 gmc_v12_0_hw_fini(adev);
939 static int gmc_v12_0_resume(void *handle)
942 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
944 r = gmc_v12_0_hw_init(adev);
948 amdgpu_vmid_reset_all(adev);
953 static bool gmc_v12_0_is_idle(void *handle)
955 /* MC is always ready in GMC v11.*/
959 static int gmc_v12_0_wait_for_idle(void *handle)
961 /* There is no need to wait for MC idle in GMC v11.*/
965 static int gmc_v12_0_soft_reset(void *handle)
970 static int gmc_v12_0_set_clockgating_state(void *handle,
971 enum amd_clockgating_state state)
974 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
976 r = adev->mmhub.funcs->set_clockgating(adev, state);
980 return athub_v4_1_0_set_clockgating(adev, state);
983 static void gmc_v12_0_get_clockgating_state(void *handle, u64 *flags)
985 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
987 adev->mmhub.funcs->get_clockgating(adev, flags);
989 athub_v4_1_0_get_clockgating(adev, flags);
992 static int gmc_v12_0_set_powergating_state(void *handle,
993 enum amd_powergating_state state)
998 const struct amd_ip_funcs gmc_v12_0_ip_funcs = {
1000 .early_init = gmc_v12_0_early_init,
1001 .sw_init = gmc_v12_0_sw_init,
1002 .hw_init = gmc_v12_0_hw_init,
1003 .late_init = gmc_v12_0_late_init,
1004 .sw_fini = gmc_v12_0_sw_fini,
1005 .hw_fini = gmc_v12_0_hw_fini,
1006 .suspend = gmc_v12_0_suspend,
1007 .resume = gmc_v12_0_resume,
1008 .is_idle = gmc_v12_0_is_idle,
1009 .wait_for_idle = gmc_v12_0_wait_for_idle,
1010 .soft_reset = gmc_v12_0_soft_reset,
1011 .set_clockgating_state = gmc_v12_0_set_clockgating_state,
1012 .set_powergating_state = gmc_v12_0_set_powergating_state,
1013 .get_clockgating_state = gmc_v12_0_get_clockgating_state,
1016 const struct amdgpu_ip_block_version gmc_v12_0_ip_block = {
1017 .type = AMD_IP_BLOCK_TYPE_GMC,
1021 .funcs = &gmc_v12_0_ip_funcs,