2 * Copyright 2021 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_v11_0.h"
31 #include "umc_v8_10.h"
32 #include "athub/athub_3_0_0_sh_mask.h"
33 #include "athub/athub_3_0_0_offset.h"
34 #include "oss/osssys_6_0_0_offset.h"
35 #include "ivsrcid/vmc/irqsrcs_vmc_1_0.h"
36 #include "navi10_enum.h"
39 #include "soc15_common.h"
40 #include "nbio_v4_3.h"
41 #include "gfxhub_v3_0.h"
42 #include "gfxhub_v3_0_3.h"
43 #include "mmhub_v3_0.h"
44 #include "mmhub_v3_0_1.h"
45 #include "mmhub_v3_0_2.h"
46 #include "athub_v3_0.h"
49 static int gmc_v11_0_ecc_interrupt_state(struct amdgpu_device *adev,
50 struct amdgpu_irq_src *src,
52 enum amdgpu_interrupt_state state)
58 gmc_v11_0_vm_fault_interrupt_state(struct amdgpu_device *adev,
59 struct amdgpu_irq_src *src, unsigned type,
60 enum amdgpu_interrupt_state state)
63 case AMDGPU_IRQ_STATE_DISABLE:
65 amdgpu_gmc_set_vm_fault_masks(adev, AMDGPU_MMHUB_0, false);
67 /* This works because this interrupt is only
68 * enabled at init/resume and disabled in
69 * fini/suspend, so the overall state doesn't
70 * change over the course of suspend/resume.
73 amdgpu_gmc_set_vm_fault_masks(adev, AMDGPU_GFXHUB_0, false);
75 case AMDGPU_IRQ_STATE_ENABLE:
77 amdgpu_gmc_set_vm_fault_masks(adev, AMDGPU_MMHUB_0, true);
79 /* This works because this interrupt is only
80 * enabled at init/resume and disabled in
81 * fini/suspend, so the overall state doesn't
82 * change over the course of suspend/resume.
85 amdgpu_gmc_set_vm_fault_masks(adev, AMDGPU_GFXHUB_0, true);
94 static int gmc_v11_0_process_interrupt(struct amdgpu_device *adev,
95 struct amdgpu_irq_src *source,
96 struct amdgpu_iv_entry *entry)
98 struct amdgpu_vmhub *hub = &adev->vmhub[entry->vmid_src];
102 addr = (u64)entry->src_data[0] << 12;
103 addr |= ((u64)entry->src_data[1] & 0xf) << 44;
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);
118 if (printk_ratelimit()) {
119 struct amdgpu_task_info task_info;
121 memset(&task_info, 0, sizeof(struct amdgpu_task_info));
122 amdgpu_vm_get_task_info(adev, entry->pasid, &task_info);
125 "[%s] page fault (src_id:%u ring:%u vmid:%u pasid:%u, "
126 "for process %s pid %d thread %s pid %d)\n",
127 entry->vmid_src ? "mmhub" : "gfxhub",
128 entry->src_id, entry->ring_id, entry->vmid,
129 entry->pasid, task_info.process_name, task_info.tgid,
130 task_info.task_name, task_info.pid);
131 dev_err(adev->dev, " in page starting at address 0x%016llx from client %d\n",
132 addr, entry->client_id);
133 if (!amdgpu_sriov_vf(adev))
134 hub->vmhub_funcs->print_l2_protection_fault_status(adev, status);
140 static const struct amdgpu_irq_src_funcs gmc_v11_0_irq_funcs = {
141 .set = gmc_v11_0_vm_fault_interrupt_state,
142 .process = gmc_v11_0_process_interrupt,
145 static const struct amdgpu_irq_src_funcs gmc_v11_0_ecc_funcs = {
146 .set = gmc_v11_0_ecc_interrupt_state,
147 .process = amdgpu_umc_process_ecc_irq,
150 static void gmc_v11_0_set_irq_funcs(struct amdgpu_device *adev)
152 adev->gmc.vm_fault.num_types = 1;
153 adev->gmc.vm_fault.funcs = &gmc_v11_0_irq_funcs;
155 if (!amdgpu_sriov_vf(adev)) {
156 adev->gmc.ecc_irq.num_types = 1;
157 adev->gmc.ecc_irq.funcs = &gmc_v11_0_ecc_funcs;
162 * gmc_v11_0_use_invalidate_semaphore - judge whether to use semaphore
164 * @adev: amdgpu_device pointer
168 static bool gmc_v11_0_use_invalidate_semaphore(struct amdgpu_device *adev,
171 return ((vmhub == AMDGPU_MMHUB_0) &&
172 (!amdgpu_sriov_vf(adev)));
175 static bool gmc_v11_0_get_vmid_pasid_mapping_info(
176 struct amdgpu_device *adev,
177 uint8_t vmid, uint16_t *p_pasid)
179 *p_pasid = RREG32(SOC15_REG_OFFSET(OSSSYS, 0, regIH_VMID_0_LUT) + vmid) & 0xffff;
186 * VMID 0 is the physical GPU addresses as used by the kernel.
187 * VMIDs 1-15 are used for userspace clients and are handled
188 * by the amdgpu vm/hsa code.
191 static void gmc_v11_0_flush_vm_hub(struct amdgpu_device *adev, uint32_t vmid,
192 unsigned int vmhub, uint32_t flush_type)
194 bool use_semaphore = gmc_v11_0_use_invalidate_semaphore(adev, vmhub);
195 struct amdgpu_vmhub *hub = &adev->vmhub[vmhub];
196 u32 inv_req = hub->vmhub_funcs->get_invalidate_req(vmid, flush_type);
198 /* Use register 17 for GART */
199 const unsigned eng = 17;
201 unsigned char hub_ip = 0;
203 hub_ip = (vmhub == AMDGPU_GFXHUB_0) ?
204 GC_HWIP : MMHUB_HWIP;
206 spin_lock(&adev->gmc.invalidate_lock);
208 * It may lose gpuvm invalidate acknowldege state across power-gating
209 * off cycle, add semaphore acquire before invalidation and semaphore
210 * release after invalidation to avoid entering power gated state
214 /* TODO: It needs to continue working on debugging with semaphore for GFXHUB as well. */
216 for (i = 0; i < adev->usec_timeout; i++) {
217 /* a read return value of 1 means semaphore acuqire */
218 tmp = RREG32_RLC_NO_KIQ(hub->vm_inv_eng0_sem +
219 hub->eng_distance * eng, hub_ip);
225 if (i >= adev->usec_timeout)
226 DRM_ERROR("Timeout waiting for sem acquire in VM flush!\n");
229 WREG32_RLC_NO_KIQ(hub->vm_inv_eng0_req + hub->eng_distance * eng, inv_req, hub_ip);
231 /* Wait for ACK with a delay.*/
232 for (i = 0; i < adev->usec_timeout; i++) {
233 tmp = RREG32_RLC_NO_KIQ(hub->vm_inv_eng0_ack +
234 hub->eng_distance * eng, hub_ip);
242 /* TODO: It needs to continue working on debugging with semaphore for GFXHUB as well. */
245 * add semaphore release after invalidation,
246 * write with 0 means semaphore release
248 WREG32_RLC_NO_KIQ(hub->vm_inv_eng0_sem +
249 hub->eng_distance * eng, 0, hub_ip);
251 /* Issue additional private vm invalidation to MMHUB */
252 if ((vmhub != AMDGPU_GFXHUB_0) &&
253 (hub->vm_l2_bank_select_reserved_cid2) &&
254 !amdgpu_sriov_vf(adev)) {
255 inv_req = RREG32_NO_KIQ(hub->vm_l2_bank_select_reserved_cid2);
256 /* bit 25: RSERVED_CACHE_PRIVATE_INVALIDATION */
257 inv_req |= (1 << 25);
258 /* Issue private invalidation */
259 WREG32_NO_KIQ(hub->vm_l2_bank_select_reserved_cid2, inv_req);
260 /* Read back to ensure invalidation is done*/
261 RREG32_NO_KIQ(hub->vm_l2_bank_select_reserved_cid2);
264 spin_unlock(&adev->gmc.invalidate_lock);
266 if (i < adev->usec_timeout)
269 DRM_ERROR("Timeout waiting for VM flush ACK!\n");
273 * gmc_v11_0_flush_gpu_tlb - gart tlb flush callback
275 * @adev: amdgpu_device pointer
276 * @vmid: vm instance to flush
278 * Flush the TLB for the requested page table.
280 static void gmc_v11_0_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid,
281 uint32_t vmhub, uint32_t flush_type)
283 if ((vmhub == AMDGPU_GFXHUB_0) && !adev->gfx.is_poweron)
286 /* flush hdp cache */
287 adev->hdp.funcs->flush_hdp(adev, NULL);
289 /* For SRIOV run time, driver shouldn't access the register through MMIO
290 * Directly use kiq to do the vm invalidation instead
292 if ((adev->gfx.kiq.ring.sched.ready || adev->mes.ring.sched.ready) &&
293 (amdgpu_sriov_runtime(adev) || !amdgpu_sriov_vf(adev))) {
294 struct amdgpu_vmhub *hub = &adev->vmhub[vmhub];
295 const unsigned eng = 17;
296 u32 inv_req = hub->vmhub_funcs->get_invalidate_req(vmid, flush_type);
297 u32 req = hub->vm_inv_eng0_req + hub->eng_distance * eng;
298 u32 ack = hub->vm_inv_eng0_ack + hub->eng_distance * eng;
300 amdgpu_virt_kiq_reg_write_reg_wait(adev, req, ack, inv_req,
305 mutex_lock(&adev->mman.gtt_window_lock);
306 gmc_v11_0_flush_vm_hub(adev, vmid, vmhub, 0);
307 mutex_unlock(&adev->mman.gtt_window_lock);
312 * gmc_v11_0_flush_gpu_tlb_pasid - tlb flush via pasid
314 * @adev: amdgpu_device pointer
315 * @pasid: pasid to be flush
317 * Flush the TLB for the requested pasid.
319 static int gmc_v11_0_flush_gpu_tlb_pasid(struct amdgpu_device *adev,
320 uint16_t pasid, uint32_t flush_type,
326 uint16_t queried_pasid;
328 struct amdgpu_ring *ring = &adev->gfx.kiq.ring;
329 struct amdgpu_kiq *kiq = &adev->gfx.kiq;
331 if (amdgpu_emu_mode == 0 && ring->sched.ready) {
332 spin_lock(&adev->gfx.kiq.ring_lock);
333 /* 2 dwords flush + 8 dwords fence */
334 amdgpu_ring_alloc(ring, kiq->pmf->invalidate_tlbs_size + 8);
335 kiq->pmf->kiq_invalidate_tlbs(ring,
336 pasid, flush_type, all_hub);
337 r = amdgpu_fence_emit_polling(ring, &seq, MAX_KIQ_REG_WAIT);
339 amdgpu_ring_undo(ring);
340 spin_unlock(&adev->gfx.kiq.ring_lock);
344 amdgpu_ring_commit(ring);
345 spin_unlock(&adev->gfx.kiq.ring_lock);
346 r = amdgpu_fence_wait_polling(ring, seq, adev->usec_timeout);
348 dev_err(adev->dev, "wait for kiq fence error: %ld.\n", r);
355 for (vmid = 1; vmid < 16; vmid++) {
357 ret = gmc_v11_0_get_vmid_pasid_mapping_info(adev, vmid,
359 if (ret && queried_pasid == pasid) {
361 for (i = 0; i < adev->num_vmhubs; i++)
362 gmc_v11_0_flush_gpu_tlb(adev, vmid,
365 gmc_v11_0_flush_gpu_tlb(adev, vmid,
366 AMDGPU_GFXHUB_0, flush_type);
374 static uint64_t gmc_v11_0_emit_flush_gpu_tlb(struct amdgpu_ring *ring,
375 unsigned vmid, uint64_t pd_addr)
377 bool use_semaphore = gmc_v11_0_use_invalidate_semaphore(ring->adev, ring->funcs->vmhub);
378 struct amdgpu_vmhub *hub = &ring->adev->vmhub[ring->funcs->vmhub];
379 uint32_t req = hub->vmhub_funcs->get_invalidate_req(vmid, 0);
380 unsigned eng = ring->vm_inv_eng;
383 * It may lose gpuvm invalidate acknowldege state across power-gating
384 * off cycle, add semaphore acquire before invalidation and semaphore
385 * release after invalidation to avoid entering power gated state
389 /* TODO: It needs to continue working on debugging with semaphore for GFXHUB as well. */
391 /* a read return value of 1 means semaphore acuqire */
392 amdgpu_ring_emit_reg_wait(ring,
393 hub->vm_inv_eng0_sem +
394 hub->eng_distance * eng, 0x1, 0x1);
396 amdgpu_ring_emit_wreg(ring, hub->ctx0_ptb_addr_lo32 +
397 (hub->ctx_addr_distance * vmid),
398 lower_32_bits(pd_addr));
400 amdgpu_ring_emit_wreg(ring, hub->ctx0_ptb_addr_hi32 +
401 (hub->ctx_addr_distance * vmid),
402 upper_32_bits(pd_addr));
404 amdgpu_ring_emit_reg_write_reg_wait(ring, hub->vm_inv_eng0_req +
405 hub->eng_distance * eng,
406 hub->vm_inv_eng0_ack +
407 hub->eng_distance * eng,
410 /* TODO: It needs to continue working on debugging with semaphore for GFXHUB as well. */
413 * add semaphore release after invalidation,
414 * write with 0 means semaphore release
416 amdgpu_ring_emit_wreg(ring, hub->vm_inv_eng0_sem +
417 hub->eng_distance * eng, 0);
422 static void gmc_v11_0_emit_pasid_mapping(struct amdgpu_ring *ring, unsigned vmid,
425 struct amdgpu_device *adev = ring->adev;
428 /* MES fw manages IH_VMID_x_LUT updating */
429 if (ring->is_mes_queue)
432 if (ring->funcs->vmhub == AMDGPU_GFXHUB_0)
433 reg = SOC15_REG_OFFSET(OSSSYS, 0, regIH_VMID_0_LUT) + vmid;
435 reg = SOC15_REG_OFFSET(OSSSYS, 0, regIH_VMID_0_LUT_MM) + vmid;
437 amdgpu_ring_emit_wreg(ring, reg, pasid);
450 * 47:12 4k physical page base address
461 * 63:59 block fragment size
465 * 47:6 physical base address of PD or PTE
472 static uint64_t gmc_v11_0_map_mtype(struct amdgpu_device *adev, uint32_t flags)
475 case AMDGPU_VM_MTYPE_DEFAULT:
476 return AMDGPU_PTE_MTYPE_NV10(MTYPE_NC);
477 case AMDGPU_VM_MTYPE_NC:
478 return AMDGPU_PTE_MTYPE_NV10(MTYPE_NC);
479 case AMDGPU_VM_MTYPE_WC:
480 return AMDGPU_PTE_MTYPE_NV10(MTYPE_WC);
481 case AMDGPU_VM_MTYPE_CC:
482 return AMDGPU_PTE_MTYPE_NV10(MTYPE_CC);
483 case AMDGPU_VM_MTYPE_UC:
484 return AMDGPU_PTE_MTYPE_NV10(MTYPE_UC);
486 return AMDGPU_PTE_MTYPE_NV10(MTYPE_NC);
490 static void gmc_v11_0_get_vm_pde(struct amdgpu_device *adev, int level,
491 uint64_t *addr, uint64_t *flags)
493 if (!(*flags & AMDGPU_PDE_PTE) && !(*flags & AMDGPU_PTE_SYSTEM))
494 *addr = adev->vm_manager.vram_base_offset + *addr -
495 adev->gmc.vram_start;
496 BUG_ON(*addr & 0xFFFF00000000003FULL);
498 if (!adev->gmc.translate_further)
501 if (level == AMDGPU_VM_PDB1) {
502 /* Set the block fragment size */
503 if (!(*flags & AMDGPU_PDE_PTE))
504 *flags |= AMDGPU_PDE_BFS(0x9);
506 } else if (level == AMDGPU_VM_PDB0) {
507 if (*flags & AMDGPU_PDE_PTE)
508 *flags &= ~AMDGPU_PDE_PTE;
510 *flags |= AMDGPU_PTE_TF;
514 static void gmc_v11_0_get_vm_pte(struct amdgpu_device *adev,
515 struct amdgpu_bo_va_mapping *mapping,
518 struct amdgpu_bo *bo = mapping->bo_va->base.bo;
520 *flags &= ~AMDGPU_PTE_EXECUTABLE;
521 *flags |= mapping->flags & AMDGPU_PTE_EXECUTABLE;
523 *flags &= ~AMDGPU_PTE_MTYPE_NV10_MASK;
524 *flags |= (mapping->flags & AMDGPU_PTE_MTYPE_NV10_MASK);
526 *flags &= ~AMDGPU_PTE_NOALLOC;
527 *flags |= (mapping->flags & AMDGPU_PTE_NOALLOC);
529 if (mapping->flags & AMDGPU_PTE_PRT) {
530 *flags |= AMDGPU_PTE_PRT;
531 *flags |= AMDGPU_PTE_SNOOPED;
532 *flags |= AMDGPU_PTE_LOG;
533 *flags |= AMDGPU_PTE_SYSTEM;
534 *flags &= ~AMDGPU_PTE_VALID;
537 if (bo && bo->flags & (AMDGPU_GEM_CREATE_COHERENT |
538 AMDGPU_GEM_CREATE_UNCACHED))
539 *flags = (*flags & ~AMDGPU_PTE_MTYPE_NV10_MASK) |
540 AMDGPU_PTE_MTYPE_NV10(MTYPE_UC);
543 static unsigned gmc_v11_0_get_vbios_fb_size(struct amdgpu_device *adev)
548 static const struct amdgpu_gmc_funcs gmc_v11_0_gmc_funcs = {
549 .flush_gpu_tlb = gmc_v11_0_flush_gpu_tlb,
550 .flush_gpu_tlb_pasid = gmc_v11_0_flush_gpu_tlb_pasid,
551 .emit_flush_gpu_tlb = gmc_v11_0_emit_flush_gpu_tlb,
552 .emit_pasid_mapping = gmc_v11_0_emit_pasid_mapping,
553 .map_mtype = gmc_v11_0_map_mtype,
554 .get_vm_pde = gmc_v11_0_get_vm_pde,
555 .get_vm_pte = gmc_v11_0_get_vm_pte,
556 .get_vbios_fb_size = gmc_v11_0_get_vbios_fb_size,
559 static void gmc_v11_0_set_gmc_funcs(struct amdgpu_device *adev)
561 adev->gmc.gmc_funcs = &gmc_v11_0_gmc_funcs;
564 static void gmc_v11_0_set_umc_funcs(struct amdgpu_device *adev)
566 switch (adev->ip_versions[UMC_HWIP][0]) {
567 case IP_VERSION(8, 10, 0):
568 adev->umc.channel_inst_num = UMC_V8_10_CHANNEL_INSTANCE_NUM;
569 adev->umc.umc_inst_num = UMC_V8_10_UMC_INSTANCE_NUM;
570 adev->umc.node_inst_num = adev->gmc.num_umc;
571 adev->umc.max_ras_err_cnt_per_query = UMC_V8_10_TOTAL_CHANNEL_NUM(adev);
572 adev->umc.channel_offs = UMC_V8_10_PER_CHANNEL_OFFSET;
573 if (adev->umc.node_inst_num == 4)
574 adev->umc.channel_idx_tbl = &umc_v8_10_channel_idx_tbl_ext0[0][0][0];
576 adev->umc.channel_idx_tbl = &umc_v8_10_channel_idx_tbl[0][0][0];
577 adev->umc.ras = &umc_v8_10_ras;
579 case IP_VERSION(8, 11, 0):
586 amdgpu_ras_register_ras_block(adev, &adev->umc.ras->ras_block);
588 strcpy(adev->umc.ras->ras_block.ras_comm.name, "umc");
589 adev->umc.ras->ras_block.ras_comm.block = AMDGPU_RAS_BLOCK__UMC;
590 adev->umc.ras->ras_block.ras_comm.type = AMDGPU_RAS_ERROR__MULTI_UNCORRECTABLE;
591 adev->umc.ras_if = &adev->umc.ras->ras_block.ras_comm;
593 /* If don't define special ras_late_init function, use default ras_late_init */
594 if (!adev->umc.ras->ras_block.ras_late_init)
595 adev->umc.ras->ras_block.ras_late_init = amdgpu_umc_ras_late_init;
597 /* If not define special ras_cb function, use default ras_cb */
598 if (!adev->umc.ras->ras_block.ras_cb)
599 adev->umc.ras->ras_block.ras_cb = amdgpu_umc_process_ras_data_cb;
604 static void gmc_v11_0_set_mmhub_funcs(struct amdgpu_device *adev)
606 switch (adev->ip_versions[MMHUB_HWIP][0]) {
607 case IP_VERSION(3, 0, 1):
608 adev->mmhub.funcs = &mmhub_v3_0_1_funcs;
610 case IP_VERSION(3, 0, 2):
611 adev->mmhub.funcs = &mmhub_v3_0_2_funcs;
614 adev->mmhub.funcs = &mmhub_v3_0_funcs;
619 static void gmc_v11_0_set_gfxhub_funcs(struct amdgpu_device *adev)
621 switch (adev->ip_versions[GC_HWIP][0]) {
622 case IP_VERSION(11, 0, 3):
623 adev->gfxhub.funcs = &gfxhub_v3_0_3_funcs;
626 adev->gfxhub.funcs = &gfxhub_v3_0_funcs;
631 static int gmc_v11_0_early_init(void *handle)
633 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
635 gmc_v11_0_set_gfxhub_funcs(adev);
636 gmc_v11_0_set_mmhub_funcs(adev);
637 gmc_v11_0_set_gmc_funcs(adev);
638 gmc_v11_0_set_irq_funcs(adev);
639 gmc_v11_0_set_umc_funcs(adev);
641 adev->gmc.shared_aperture_start = 0x2000000000000000ULL;
642 adev->gmc.shared_aperture_end =
643 adev->gmc.shared_aperture_start + (4ULL << 30) - 1;
644 adev->gmc.private_aperture_start = 0x1000000000000000ULL;
645 adev->gmc.private_aperture_end =
646 adev->gmc.private_aperture_start + (4ULL << 30) - 1;
651 static int gmc_v11_0_late_init(void *handle)
653 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
656 r = amdgpu_gmc_allocate_vm_inv_eng(adev);
660 r = amdgpu_gmc_ras_late_init(adev);
664 return amdgpu_irq_get(adev, &adev->gmc.vm_fault, 0);
667 static void gmc_v11_0_vram_gtt_location(struct amdgpu_device *adev,
668 struct amdgpu_gmc *mc)
672 base = adev->mmhub.funcs->get_fb_location(adev);
674 amdgpu_gmc_vram_location(adev, &adev->gmc, base);
675 amdgpu_gmc_gart_location(adev, mc);
677 /* base offset of vram pages */
678 if (amdgpu_sriov_vf(adev))
679 adev->vm_manager.vram_base_offset = 0;
681 adev->vm_manager.vram_base_offset = adev->mmhub.funcs->get_mc_fb_offset(adev);
685 * gmc_v11_0_mc_init - initialize the memory controller driver params
687 * @adev: amdgpu_device pointer
689 * Look up the amount of vram, vram width, and decide how to place
690 * vram and gart within the GPU's physical address space.
691 * Returns 0 for success.
693 static int gmc_v11_0_mc_init(struct amdgpu_device *adev)
697 /* size in MB on si */
698 adev->gmc.mc_vram_size =
699 adev->nbio.funcs->get_memsize(adev) * 1024ULL * 1024ULL;
700 adev->gmc.real_vram_size = adev->gmc.mc_vram_size;
702 if (!(adev->flags & AMD_IS_APU)) {
703 r = amdgpu_device_resize_fb_bar(adev);
707 adev->gmc.aper_base = pci_resource_start(adev->pdev, 0);
708 adev->gmc.aper_size = pci_resource_len(adev->pdev, 0);
711 if ((adev->flags & AMD_IS_APU) && !amdgpu_passthrough(adev)) {
712 adev->gmc.aper_base = adev->mmhub.funcs->get_mc_fb_offset(adev);
713 adev->gmc.aper_size = adev->gmc.real_vram_size;
716 /* In case the PCI BAR is larger than the actual amount of vram */
717 adev->gmc.visible_vram_size = adev->gmc.aper_size;
718 if (adev->gmc.visible_vram_size > adev->gmc.real_vram_size)
719 adev->gmc.visible_vram_size = adev->gmc.real_vram_size;
721 /* set the gart size */
722 if (amdgpu_gart_size == -1) {
723 adev->gmc.gart_size = 512ULL << 20;
725 adev->gmc.gart_size = (u64)amdgpu_gart_size << 20;
727 gmc_v11_0_vram_gtt_location(adev, &adev->gmc);
732 static int gmc_v11_0_gart_init(struct amdgpu_device *adev)
737 WARN(1, "PCIE GART already initialized\n");
741 /* Initialize common gart structure */
742 r = amdgpu_gart_init(adev);
746 adev->gart.table_size = adev->gart.num_gpu_pages * 8;
747 adev->gart.gart_pte_flags = AMDGPU_PTE_MTYPE_NV10(MTYPE_UC) |
748 AMDGPU_PTE_EXECUTABLE;
750 return amdgpu_gart_table_vram_alloc(adev);
753 static int gmc_v11_0_sw_init(void *handle)
755 int r, vram_width = 0, vram_type = 0, vram_vendor = 0;
756 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
758 adev->mmhub.funcs->init(adev);
760 spin_lock_init(&adev->gmc.invalidate_lock);
762 r = amdgpu_atomfirmware_get_vram_info(adev,
763 &vram_width, &vram_type, &vram_vendor);
764 adev->gmc.vram_width = vram_width;
766 adev->gmc.vram_type = vram_type;
767 adev->gmc.vram_vendor = vram_vendor;
769 switch (adev->ip_versions[GC_HWIP][0]) {
770 case IP_VERSION(11, 0, 0):
771 case IP_VERSION(11, 0, 1):
772 case IP_VERSION(11, 0, 2):
773 case IP_VERSION(11, 0, 3):
774 case IP_VERSION(11, 0, 4):
775 adev->num_vmhubs = 2;
777 * To fulfill 4-level page support,
778 * vm size is 256TB (48bit), maximum size,
779 * block size 512 (9bit)
781 amdgpu_vm_adjust_size(adev, 256 * 1024, 9, 3, 48);
787 /* This interrupt is VMC page fault.*/
788 r = amdgpu_irq_add_id(adev, SOC21_IH_CLIENTID_VMC,
789 VMC_1_0__SRCID__VM_FAULT,
790 &adev->gmc.vm_fault);
795 r = amdgpu_irq_add_id(adev, SOC21_IH_CLIENTID_GFX,
796 UTCL2_1_0__SRCID__FAULT,
797 &adev->gmc.vm_fault);
801 if (!amdgpu_sriov_vf(adev)) {
802 /* interrupt sent to DF. */
803 r = amdgpu_irq_add_id(adev, SOC21_IH_CLIENTID_DF, 0,
810 * Set the internal MC address mask This is the max address of the GPU's
811 * internal address space.
813 adev->gmc.mc_mask = 0xffffffffffffULL; /* 48 bit MC */
815 r = dma_set_mask_and_coherent(adev->dev, DMA_BIT_MASK(44));
817 printk(KERN_WARNING "amdgpu: No suitable DMA available.\n");
821 adev->need_swiotlb = drm_need_swiotlb(44);
823 r = gmc_v11_0_mc_init(adev);
827 amdgpu_gmc_get_vbios_allocations(adev);
830 r = amdgpu_bo_init(adev);
834 r = gmc_v11_0_gart_init(adev);
840 * VMID 0 is reserved for System
841 * amdgpu graphics/compute will use VMIDs 1-7
842 * amdkfd will use VMIDs 8-15
844 adev->vm_manager.first_kfd_vmid = 8;
846 amdgpu_vm_manager_init(adev);
852 * gmc_v11_0_gart_fini - vm fini callback
854 * @adev: amdgpu_device pointer
856 * Tears down the driver GART/VM setup (CIK).
858 static void gmc_v11_0_gart_fini(struct amdgpu_device *adev)
860 amdgpu_gart_table_vram_free(adev);
863 static int gmc_v11_0_sw_fini(void *handle)
865 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
867 amdgpu_vm_manager_fini(adev);
868 gmc_v11_0_gart_fini(adev);
869 amdgpu_gem_force_release(adev);
870 amdgpu_bo_fini(adev);
875 static void gmc_v11_0_init_golden_registers(struct amdgpu_device *adev)
880 * gmc_v11_0_gart_enable - gart enable
882 * @adev: amdgpu_device pointer
884 static int gmc_v11_0_gart_enable(struct amdgpu_device *adev)
889 if (adev->gart.bo == NULL) {
890 dev_err(adev->dev, "No VRAM object for PCIE GART.\n");
894 amdgpu_gtt_mgr_recover(&adev->mman.gtt_mgr);
896 r = adev->mmhub.funcs->gart_enable(adev);
900 /* Flush HDP after it is initialized */
901 adev->hdp.funcs->flush_hdp(adev, NULL);
903 value = (amdgpu_vm_fault_stop == AMDGPU_VM_FAULT_STOP_ALWAYS) ?
906 adev->mmhub.funcs->set_fault_enable_default(adev, value);
907 gmc_v11_0_flush_gpu_tlb(adev, 0, AMDGPU_MMHUB_0, 0);
909 DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
910 (unsigned)(adev->gmc.gart_size >> 20),
911 (unsigned long long)amdgpu_bo_gpu_offset(adev->gart.bo));
916 static int gmc_v11_0_hw_init(void *handle)
919 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
921 /* The sequence of these two function calls matters.*/
922 gmc_v11_0_init_golden_registers(adev);
924 r = gmc_v11_0_gart_enable(adev);
928 if (adev->umc.funcs && adev->umc.funcs->init_registers)
929 adev->umc.funcs->init_registers(adev);
935 * gmc_v11_0_gart_disable - gart disable
937 * @adev: amdgpu_device pointer
939 * This disables all VM page table.
941 static void gmc_v11_0_gart_disable(struct amdgpu_device *adev)
943 adev->mmhub.funcs->gart_disable(adev);
946 static int gmc_v11_0_hw_fini(void *handle)
948 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
950 if (amdgpu_sriov_vf(adev)) {
951 /* full access mode, so don't touch any GMC register */
952 DRM_DEBUG("For SRIOV client, shouldn't do anything.\n");
956 amdgpu_irq_put(adev, &adev->gmc.ecc_irq, 0);
957 amdgpu_irq_put(adev, &adev->gmc.vm_fault, 0);
958 gmc_v11_0_gart_disable(adev);
963 static int gmc_v11_0_suspend(void *handle)
965 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
967 gmc_v11_0_hw_fini(adev);
972 static int gmc_v11_0_resume(void *handle)
975 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
977 r = gmc_v11_0_hw_init(adev);
981 amdgpu_vmid_reset_all(adev);
986 static bool gmc_v11_0_is_idle(void *handle)
988 /* MC is always ready in GMC v11.*/
992 static int gmc_v11_0_wait_for_idle(void *handle)
994 /* There is no need to wait for MC idle in GMC v11.*/
998 static int gmc_v11_0_soft_reset(void *handle)
1003 static int gmc_v11_0_set_clockgating_state(void *handle,
1004 enum amd_clockgating_state state)
1007 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1009 r = adev->mmhub.funcs->set_clockgating(adev, state);
1013 return athub_v3_0_set_clockgating(adev, state);
1016 static void gmc_v11_0_get_clockgating_state(void *handle, u64 *flags)
1018 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1020 adev->mmhub.funcs->get_clockgating(adev, flags);
1022 athub_v3_0_get_clockgating(adev, flags);
1025 static int gmc_v11_0_set_powergating_state(void *handle,
1026 enum amd_powergating_state state)
1031 const struct amd_ip_funcs gmc_v11_0_ip_funcs = {
1032 .name = "gmc_v11_0",
1033 .early_init = gmc_v11_0_early_init,
1034 .sw_init = gmc_v11_0_sw_init,
1035 .hw_init = gmc_v11_0_hw_init,
1036 .late_init = gmc_v11_0_late_init,
1037 .sw_fini = gmc_v11_0_sw_fini,
1038 .hw_fini = gmc_v11_0_hw_fini,
1039 .suspend = gmc_v11_0_suspend,
1040 .resume = gmc_v11_0_resume,
1041 .is_idle = gmc_v11_0_is_idle,
1042 .wait_for_idle = gmc_v11_0_wait_for_idle,
1043 .soft_reset = gmc_v11_0_soft_reset,
1044 .set_clockgating_state = gmc_v11_0_set_clockgating_state,
1045 .set_powergating_state = gmc_v11_0_set_powergating_state,
1046 .get_clockgating_state = gmc_v11_0_get_clockgating_state,
1049 const struct amdgpu_ip_block_version gmc_v11_0_ip_block = {
1050 .type = AMD_IP_BLOCK_TYPE_GMC,
1054 .funcs = &gmc_v11_0_ip_funcs,