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 "gc/gc_9_0_sh_mask.h"
35 #include "dce/dce_12_0_offset.h"
36 #include "dce/dce_12_0_sh_mask.h"
37 #include "vega10_enum.h"
38 #include "mmhub/mmhub_1_0_offset.h"
39 #include "athub/athub_1_0_sh_mask.h"
40 #include "athub/athub_1_0_offset.h"
41 #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"
53 #include "mmhub_v1_7.h"
57 #include "ivsrcid/vmc/irqsrcs_vmc_1_0.h"
59 #include "amdgpu_ras.h"
60 #include "amdgpu_xgmi.h"
62 /* add these here since we already include dce12 headers and these are for DCN */
63 #define mmHUBP0_DCSURF_PRI_VIEWPORT_DIMENSION 0x055d
64 #define mmHUBP0_DCSURF_PRI_VIEWPORT_DIMENSION_BASE_IDX 2
65 #define HUBP0_DCSURF_PRI_VIEWPORT_DIMENSION__PRI_VIEWPORT_WIDTH__SHIFT 0x0
66 #define HUBP0_DCSURF_PRI_VIEWPORT_DIMENSION__PRI_VIEWPORT_HEIGHT__SHIFT 0x10
67 #define HUBP0_DCSURF_PRI_VIEWPORT_DIMENSION__PRI_VIEWPORT_WIDTH_MASK 0x00003FFFL
68 #define HUBP0_DCSURF_PRI_VIEWPORT_DIMENSION__PRI_VIEWPORT_HEIGHT_MASK 0x3FFF0000L
69 #define mmDCHUBBUB_SDPIF_MMIO_CNTRL_0 0x049d
70 #define mmDCHUBBUB_SDPIF_MMIO_CNTRL_0_BASE_IDX 2
73 static const char *gfxhub_client_ids[] = {
89 static const char *mmhub_client_ids_raven[][2] = {
114 static const char *mmhub_client_ids_renoir[][2] = {
142 static const char *mmhub_client_ids_vega10[][2] = {
155 [32+14][0] = "SDMA0",
168 [32+4][1] = "DCEDWB",
171 [32+14][1] = "SDMA1",
174 static const char *mmhub_client_ids_vega12[][2] = {
187 [32+15][0] = "SDMA0",
197 [32+1][1] = "DCEDWB",
203 [32+15][1] = "SDMA1",
206 static const char *mmhub_client_ids_vega20[][2] = {
220 [32+12][0] = "UTCL2",
221 [32+14][0] = "SDMA1",
239 [32+14][1] = "SDMA1",
242 static const char *mmhub_client_ids_arcturus[][2] = {
283 static const char *mmhub_client_ids_aldebaran[][2] = {
286 [32+1][0] = "DBGU_IO0",
287 [32+2][0] = "DBGU_IO2",
289 [96+11][0] = "JPEG0",
291 [96+13][0] = "VCNU0",
292 [128+11][0] = "JPEG1",
293 [128+12][0] = "VCN1",
294 [128+13][0] = "VCNU1",
297 [256+0][0] = "SDMA0",
298 [256+1][0] = "SDMA1",
299 [256+2][0] = "SDMA2",
300 [256+3][0] = "SDMA3",
301 [256+4][0] = "SDMA4",
305 [32+1][1] = "DBGU_IO0",
306 [32+2][1] = "DBGU_IO2",
308 [96+11][1] = "JPEG0",
310 [96+13][1] = "VCNU0",
311 [128+11][1] = "JPEG1",
312 [128+12][1] = "VCN1",
313 [128+13][1] = "VCNU1",
316 [256+0][1] = "SDMA0",
317 [256+1][1] = "SDMA1",
318 [256+2][1] = "SDMA2",
319 [256+3][1] = "SDMA3",
320 [256+4][1] = "SDMA4",
324 static const struct soc15_reg_golden golden_settings_mmhub_1_0_0[] =
326 SOC15_REG_GOLDEN_VALUE(MMHUB, 0, mmDAGB1_WRCLI2, 0x00000007, 0xfe5fe0fa),
327 SOC15_REG_GOLDEN_VALUE(MMHUB, 0, mmMMEA1_DRAM_WR_CLI2GRP_MAP0, 0x00000030, 0x55555565)
330 static const struct soc15_reg_golden golden_settings_athub_1_0_0[] =
332 SOC15_REG_GOLDEN_VALUE(ATHUB, 0, mmRPB_ARB_CNTL, 0x0000ff00, 0x00000800),
333 SOC15_REG_GOLDEN_VALUE(ATHUB, 0, mmRPB_ARB_CNTL2, 0x00ff00ff, 0x00080008)
336 static const uint32_t ecc_umc_mcumc_ctrl_addrs[] = {
337 (0x000143c0 + 0x00000000),
338 (0x000143c0 + 0x00000800),
339 (0x000143c0 + 0x00001000),
340 (0x000143c0 + 0x00001800),
341 (0x000543c0 + 0x00000000),
342 (0x000543c0 + 0x00000800),
343 (0x000543c0 + 0x00001000),
344 (0x000543c0 + 0x00001800),
345 (0x000943c0 + 0x00000000),
346 (0x000943c0 + 0x00000800),
347 (0x000943c0 + 0x00001000),
348 (0x000943c0 + 0x00001800),
349 (0x000d43c0 + 0x00000000),
350 (0x000d43c0 + 0x00000800),
351 (0x000d43c0 + 0x00001000),
352 (0x000d43c0 + 0x00001800),
353 (0x001143c0 + 0x00000000),
354 (0x001143c0 + 0x00000800),
355 (0x001143c0 + 0x00001000),
356 (0x001143c0 + 0x00001800),
357 (0x001543c0 + 0x00000000),
358 (0x001543c0 + 0x00000800),
359 (0x001543c0 + 0x00001000),
360 (0x001543c0 + 0x00001800),
361 (0x001943c0 + 0x00000000),
362 (0x001943c0 + 0x00000800),
363 (0x001943c0 + 0x00001000),
364 (0x001943c0 + 0x00001800),
365 (0x001d43c0 + 0x00000000),
366 (0x001d43c0 + 0x00000800),
367 (0x001d43c0 + 0x00001000),
368 (0x001d43c0 + 0x00001800),
371 static const uint32_t ecc_umc_mcumc_ctrl_mask_addrs[] = {
372 (0x000143e0 + 0x00000000),
373 (0x000143e0 + 0x00000800),
374 (0x000143e0 + 0x00001000),
375 (0x000143e0 + 0x00001800),
376 (0x000543e0 + 0x00000000),
377 (0x000543e0 + 0x00000800),
378 (0x000543e0 + 0x00001000),
379 (0x000543e0 + 0x00001800),
380 (0x000943e0 + 0x00000000),
381 (0x000943e0 + 0x00000800),
382 (0x000943e0 + 0x00001000),
383 (0x000943e0 + 0x00001800),
384 (0x000d43e0 + 0x00000000),
385 (0x000d43e0 + 0x00000800),
386 (0x000d43e0 + 0x00001000),
387 (0x000d43e0 + 0x00001800),
388 (0x001143e0 + 0x00000000),
389 (0x001143e0 + 0x00000800),
390 (0x001143e0 + 0x00001000),
391 (0x001143e0 + 0x00001800),
392 (0x001543e0 + 0x00000000),
393 (0x001543e0 + 0x00000800),
394 (0x001543e0 + 0x00001000),
395 (0x001543e0 + 0x00001800),
396 (0x001943e0 + 0x00000000),
397 (0x001943e0 + 0x00000800),
398 (0x001943e0 + 0x00001000),
399 (0x001943e0 + 0x00001800),
400 (0x001d43e0 + 0x00000000),
401 (0x001d43e0 + 0x00000800),
402 (0x001d43e0 + 0x00001000),
403 (0x001d43e0 + 0x00001800),
406 static int gmc_v9_0_ecc_interrupt_state(struct amdgpu_device *adev,
407 struct amdgpu_irq_src *src,
409 enum amdgpu_interrupt_state state)
411 u32 bits, i, tmp, reg;
413 /* Devices newer then VEGA10/12 shall have these programming
414 sequences performed by PSP BL */
415 if (adev->asic_type >= CHIP_VEGA20)
421 case AMDGPU_IRQ_STATE_DISABLE:
422 for (i = 0; i < ARRAY_SIZE(ecc_umc_mcumc_ctrl_addrs); i++) {
423 reg = ecc_umc_mcumc_ctrl_addrs[i];
428 for (i = 0; i < ARRAY_SIZE(ecc_umc_mcumc_ctrl_mask_addrs); i++) {
429 reg = ecc_umc_mcumc_ctrl_mask_addrs[i];
435 case AMDGPU_IRQ_STATE_ENABLE:
436 for (i = 0; i < ARRAY_SIZE(ecc_umc_mcumc_ctrl_addrs); i++) {
437 reg = ecc_umc_mcumc_ctrl_addrs[i];
442 for (i = 0; i < ARRAY_SIZE(ecc_umc_mcumc_ctrl_mask_addrs); i++) {
443 reg = ecc_umc_mcumc_ctrl_mask_addrs[i];
456 static int gmc_v9_0_vm_fault_interrupt_state(struct amdgpu_device *adev,
457 struct amdgpu_irq_src *src,
459 enum amdgpu_interrupt_state state)
461 struct amdgpu_vmhub *hub;
462 u32 tmp, reg, bits, i, j;
464 bits = VM_CONTEXT1_CNTL__RANGE_PROTECTION_FAULT_ENABLE_INTERRUPT_MASK |
465 VM_CONTEXT1_CNTL__DUMMY_PAGE_PROTECTION_FAULT_ENABLE_INTERRUPT_MASK |
466 VM_CONTEXT1_CNTL__PDE0_PROTECTION_FAULT_ENABLE_INTERRUPT_MASK |
467 VM_CONTEXT1_CNTL__VALID_PROTECTION_FAULT_ENABLE_INTERRUPT_MASK |
468 VM_CONTEXT1_CNTL__READ_PROTECTION_FAULT_ENABLE_INTERRUPT_MASK |
469 VM_CONTEXT1_CNTL__WRITE_PROTECTION_FAULT_ENABLE_INTERRUPT_MASK |
470 VM_CONTEXT1_CNTL__EXECUTE_PROTECTION_FAULT_ENABLE_INTERRUPT_MASK;
473 case AMDGPU_IRQ_STATE_DISABLE:
474 for (j = 0; j < adev->num_vmhubs; j++) {
475 hub = &adev->vmhub[j];
476 for (i = 0; i < 16; i++) {
477 reg = hub->vm_context0_cntl + i;
484 case AMDGPU_IRQ_STATE_ENABLE:
485 for (j = 0; j < adev->num_vmhubs; j++) {
486 hub = &adev->vmhub[j];
487 for (i = 0; i < 16; i++) {
488 reg = hub->vm_context0_cntl + i;
502 static int gmc_v9_0_process_interrupt(struct amdgpu_device *adev,
503 struct amdgpu_irq_src *source,
504 struct amdgpu_iv_entry *entry)
506 bool retry_fault = !!(entry->src_data[1] & 0x80);
507 uint32_t status = 0, cid = 0, rw = 0;
508 struct amdgpu_task_info task_info;
509 struct amdgpu_vmhub *hub;
510 const char *mmhub_cid;
511 const char *hub_name;
514 addr = (u64)entry->src_data[0] << 12;
515 addr |= ((u64)entry->src_data[1] & 0xf) << 44;
518 /* Returning 1 here also prevents sending the IV to the KFD */
520 /* Process it onyl if it's the first fault for this address */
521 if (entry->ih != &adev->irq.ih_soft &&
522 amdgpu_gmc_filter_faults(adev, addr, entry->pasid,
526 /* Delegate it to a different ring if the hardware hasn't
529 if (entry->ih == &adev->irq.ih) {
530 amdgpu_irq_delegate(adev, entry, 8);
534 /* Try to handle the recoverable page faults by filling page
537 if (amdgpu_vm_handle_fault(adev, entry->pasid, addr))
541 if (!printk_ratelimit())
544 if (entry->client_id == SOC15_IH_CLIENTID_VMC) {
546 hub = &adev->vmhub[AMDGPU_MMHUB_0];
547 } else if (entry->client_id == SOC15_IH_CLIENTID_VMC1) {
549 hub = &adev->vmhub[AMDGPU_MMHUB_1];
551 hub_name = "gfxhub0";
552 hub = &adev->vmhub[AMDGPU_GFXHUB_0];
555 memset(&task_info, 0, sizeof(struct amdgpu_task_info));
556 amdgpu_vm_get_task_info(adev, entry->pasid, &task_info);
559 "[%s] %s page fault (src_id:%u ring:%u vmid:%u "
560 "pasid:%u, for process %s pid %d thread %s pid %d)\n",
561 hub_name, retry_fault ? "retry" : "no-retry",
562 entry->src_id, entry->ring_id, entry->vmid,
563 entry->pasid, task_info.process_name, task_info.tgid,
564 task_info.task_name, task_info.pid);
565 dev_err(adev->dev, " in page starting at address 0x%016llx from IH client 0x%x (%s)\n",
566 addr, entry->client_id,
567 soc15_ih_clientid_name[entry->client_id]);
569 if (amdgpu_sriov_vf(adev))
573 * Issue a dummy read to wait for the status register to
574 * be updated to avoid reading an incorrect value due to
575 * the new fast GRBM interface.
577 if (entry->vmid_src == AMDGPU_GFXHUB_0)
578 RREG32(hub->vm_l2_pro_fault_status);
580 status = RREG32(hub->vm_l2_pro_fault_status);
581 cid = REG_GET_FIELD(status, VM_L2_PROTECTION_FAULT_STATUS, CID);
582 rw = REG_GET_FIELD(status, VM_L2_PROTECTION_FAULT_STATUS, RW);
583 WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1);
587 "VM_L2_PROTECTION_FAULT_STATUS:0x%08X\n",
589 if (hub == &adev->vmhub[AMDGPU_GFXHUB_0]) {
590 dev_err(adev->dev, "\t Faulty UTCL2 client ID: %s (0x%x)\n",
591 cid >= ARRAY_SIZE(gfxhub_client_ids) ? "unknown" :
592 gfxhub_client_ids[cid],
595 switch (adev->asic_type) {
597 mmhub_cid = mmhub_client_ids_vega10[cid][rw];
600 mmhub_cid = mmhub_client_ids_vega12[cid][rw];
603 mmhub_cid = mmhub_client_ids_vega20[cid][rw];
606 mmhub_cid = mmhub_client_ids_arcturus[cid][rw];
609 mmhub_cid = mmhub_client_ids_raven[cid][rw];
612 mmhub_cid = mmhub_client_ids_renoir[cid][rw];
615 mmhub_cid = mmhub_client_ids_aldebaran[cid][rw];
621 dev_err(adev->dev, "\t Faulty UTCL2 client ID: %s (0x%x)\n",
622 mmhub_cid ? mmhub_cid : "unknown", cid);
624 dev_err(adev->dev, "\t MORE_FAULTS: 0x%lx\n",
625 REG_GET_FIELD(status,
626 VM_L2_PROTECTION_FAULT_STATUS, MORE_FAULTS));
627 dev_err(adev->dev, "\t WALKER_ERROR: 0x%lx\n",
628 REG_GET_FIELD(status,
629 VM_L2_PROTECTION_FAULT_STATUS, WALKER_ERROR));
630 dev_err(adev->dev, "\t PERMISSION_FAULTS: 0x%lx\n",
631 REG_GET_FIELD(status,
632 VM_L2_PROTECTION_FAULT_STATUS, PERMISSION_FAULTS));
633 dev_err(adev->dev, "\t MAPPING_ERROR: 0x%lx\n",
634 REG_GET_FIELD(status,
635 VM_L2_PROTECTION_FAULT_STATUS, MAPPING_ERROR));
636 dev_err(adev->dev, "\t RW: 0x%x\n", rw);
640 static const struct amdgpu_irq_src_funcs gmc_v9_0_irq_funcs = {
641 .set = gmc_v9_0_vm_fault_interrupt_state,
642 .process = gmc_v9_0_process_interrupt,
646 static const struct amdgpu_irq_src_funcs gmc_v9_0_ecc_funcs = {
647 .set = gmc_v9_0_ecc_interrupt_state,
648 .process = amdgpu_umc_process_ecc_irq,
651 static void gmc_v9_0_set_irq_funcs(struct amdgpu_device *adev)
653 adev->gmc.vm_fault.num_types = 1;
654 adev->gmc.vm_fault.funcs = &gmc_v9_0_irq_funcs;
656 if (!amdgpu_sriov_vf(adev)) {
657 adev->gmc.ecc_irq.num_types = 1;
658 adev->gmc.ecc_irq.funcs = &gmc_v9_0_ecc_funcs;
662 static uint32_t gmc_v9_0_get_invalidate_req(unsigned int vmid,
667 req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ,
668 PER_VMID_INVALIDATE_REQ, 1 << vmid);
669 req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ, FLUSH_TYPE, flush_type);
670 req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ, INVALIDATE_L2_PTES, 1);
671 req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ, INVALIDATE_L2_PDE0, 1);
672 req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ, INVALIDATE_L2_PDE1, 1);
673 req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ, INVALIDATE_L2_PDE2, 1);
674 req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ, INVALIDATE_L1_PTES, 1);
675 req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ,
676 CLEAR_PROTECTION_FAULT_STATUS_ADDR, 0);
682 * gmc_v9_0_use_invalidate_semaphore - judge whether to use semaphore
684 * @adev: amdgpu_device pointer
688 static bool gmc_v9_0_use_invalidate_semaphore(struct amdgpu_device *adev,
691 if (adev->asic_type == CHIP_ALDEBARAN)
694 return ((vmhub == AMDGPU_MMHUB_0 ||
695 vmhub == AMDGPU_MMHUB_1) &&
696 (!amdgpu_sriov_vf(adev)) &&
697 (!(!(adev->apu_flags & AMD_APU_IS_RAVEN2) &&
698 (adev->apu_flags & AMD_APU_IS_PICASSO))));
701 static bool gmc_v9_0_get_atc_vmid_pasid_mapping_info(struct amdgpu_device *adev,
702 uint8_t vmid, uint16_t *p_pasid)
706 value = RREG32(SOC15_REG_OFFSET(ATHUB, 0, mmATC_VMID0_PASID_MAPPING)
708 *p_pasid = value & ATC_VMID0_PASID_MAPPING__PASID_MASK;
710 return !!(value & ATC_VMID0_PASID_MAPPING__VALID_MASK);
715 * VMID 0 is the physical GPU addresses as used by the kernel.
716 * VMIDs 1-15 are used for userspace clients and are handled
717 * by the amdgpu vm/hsa code.
721 * gmc_v9_0_flush_gpu_tlb - tlb flush with certain type
723 * @adev: amdgpu_device pointer
724 * @vmid: vm instance to flush
725 * @vmhub: which hub to flush
726 * @flush_type: the flush type
728 * Flush the TLB for the requested page table using certain type.
730 static void gmc_v9_0_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid,
731 uint32_t vmhub, uint32_t flush_type)
733 bool use_semaphore = gmc_v9_0_use_invalidate_semaphore(adev, vmhub);
734 const unsigned eng = 17;
735 u32 j, inv_req, inv_req2, tmp;
736 struct amdgpu_vmhub *hub;
738 BUG_ON(vmhub >= adev->num_vmhubs);
740 hub = &adev->vmhub[vmhub];
741 if (adev->gmc.xgmi.num_physical_nodes &&
742 adev->asic_type == CHIP_VEGA20) {
743 /* Vega20+XGMI caches PTEs in TC and TLB. Add a
744 * heavy-weight TLB flush (type 2), which flushes
745 * both. Due to a race condition with concurrent
746 * memory accesses using the same TLB cache line, we
747 * still need a second TLB flush after this.
749 inv_req = gmc_v9_0_get_invalidate_req(vmid, 2);
750 inv_req2 = gmc_v9_0_get_invalidate_req(vmid, flush_type);
752 inv_req = gmc_v9_0_get_invalidate_req(vmid, flush_type);
756 /* This is necessary for a HW workaround under SRIOV as well
757 * as GFXOFF under bare metal
759 if (adev->gfx.kiq.ring.sched.ready &&
760 (amdgpu_sriov_runtime(adev) || !amdgpu_sriov_vf(adev)) &&
761 down_read_trylock(&adev->reset_sem)) {
762 uint32_t req = hub->vm_inv_eng0_req + hub->eng_distance * eng;
763 uint32_t ack = hub->vm_inv_eng0_ack + hub->eng_distance * eng;
765 amdgpu_virt_kiq_reg_write_reg_wait(adev, req, ack, inv_req,
767 up_read(&adev->reset_sem);
771 spin_lock(&adev->gmc.invalidate_lock);
774 * It may lose gpuvm invalidate acknowldege state across power-gating
775 * off cycle, add semaphore acquire before invalidation and semaphore
776 * release after invalidation to avoid entering power gated state
780 /* TODO: It needs to continue working on debugging with semaphore for GFXHUB as well. */
782 for (j = 0; j < adev->usec_timeout; j++) {
783 /* a read return value of 1 means semaphore acuqire */
784 tmp = RREG32_NO_KIQ(hub->vm_inv_eng0_sem +
785 hub->eng_distance * eng);
791 if (j >= adev->usec_timeout)
792 DRM_ERROR("Timeout waiting for sem acquire in VM flush!\n");
796 WREG32_NO_KIQ(hub->vm_inv_eng0_req +
797 hub->eng_distance * eng, inv_req);
800 * Issue a dummy read to wait for the ACK register to
801 * be cleared to avoid a false ACK due to the new fast
804 if (vmhub == AMDGPU_GFXHUB_0)
805 RREG32_NO_KIQ(hub->vm_inv_eng0_req +
806 hub->eng_distance * eng);
808 for (j = 0; j < adev->usec_timeout; j++) {
809 tmp = RREG32_NO_KIQ(hub->vm_inv_eng0_ack +
810 hub->eng_distance * eng);
811 if (tmp & (1 << vmid))
820 /* TODO: It needs to continue working on debugging with semaphore for GFXHUB as well. */
823 * add semaphore release after invalidation,
824 * write with 0 means semaphore release
826 WREG32_NO_KIQ(hub->vm_inv_eng0_sem +
827 hub->eng_distance * eng, 0);
829 spin_unlock(&adev->gmc.invalidate_lock);
831 if (j < adev->usec_timeout)
834 DRM_ERROR("Timeout waiting for VM flush ACK!\n");
838 * gmc_v9_0_flush_gpu_tlb_pasid - tlb flush via pasid
840 * @adev: amdgpu_device pointer
841 * @pasid: pasid to be flush
842 * @flush_type: the flush type
843 * @all_hub: flush all hubs
845 * Flush the TLB for the requested pasid.
847 static int gmc_v9_0_flush_gpu_tlb_pasid(struct amdgpu_device *adev,
848 uint16_t pasid, uint32_t flush_type,
854 uint16_t queried_pasid;
856 struct amdgpu_ring *ring = &adev->gfx.kiq.ring;
857 struct amdgpu_kiq *kiq = &adev->gfx.kiq;
859 if (amdgpu_in_reset(adev))
862 if (ring->sched.ready && down_read_trylock(&adev->reset_sem)) {
863 /* Vega20+XGMI caches PTEs in TC and TLB. Add a
864 * heavy-weight TLB flush (type 2), which flushes
865 * both. Due to a race condition with concurrent
866 * memory accesses using the same TLB cache line, we
867 * still need a second TLB flush after this.
869 bool vega20_xgmi_wa = (adev->gmc.xgmi.num_physical_nodes &&
870 adev->asic_type == CHIP_VEGA20);
871 /* 2 dwords flush + 8 dwords fence */
872 unsigned int ndw = kiq->pmf->invalidate_tlbs_size + 8;
875 ndw += kiq->pmf->invalidate_tlbs_size;
877 spin_lock(&adev->gfx.kiq.ring_lock);
878 /* 2 dwords flush + 8 dwords fence */
879 amdgpu_ring_alloc(ring, ndw);
881 kiq->pmf->kiq_invalidate_tlbs(ring,
883 kiq->pmf->kiq_invalidate_tlbs(ring,
884 pasid, flush_type, all_hub);
885 r = amdgpu_fence_emit_polling(ring, &seq, MAX_KIQ_REG_WAIT);
887 amdgpu_ring_undo(ring);
888 spin_unlock(&adev->gfx.kiq.ring_lock);
889 up_read(&adev->reset_sem);
893 amdgpu_ring_commit(ring);
894 spin_unlock(&adev->gfx.kiq.ring_lock);
895 r = amdgpu_fence_wait_polling(ring, seq, adev->usec_timeout);
897 dev_err(adev->dev, "wait for kiq fence error: %ld.\n", r);
898 up_read(&adev->reset_sem);
901 up_read(&adev->reset_sem);
905 for (vmid = 1; vmid < 16; vmid++) {
907 ret = gmc_v9_0_get_atc_vmid_pasid_mapping_info(adev, vmid,
909 if (ret && queried_pasid == pasid) {
911 for (i = 0; i < adev->num_vmhubs; i++)
912 gmc_v9_0_flush_gpu_tlb(adev, vmid,
915 gmc_v9_0_flush_gpu_tlb(adev, vmid,
916 AMDGPU_GFXHUB_0, flush_type);
926 static uint64_t gmc_v9_0_emit_flush_gpu_tlb(struct amdgpu_ring *ring,
927 unsigned vmid, uint64_t pd_addr)
929 bool use_semaphore = gmc_v9_0_use_invalidate_semaphore(ring->adev, ring->funcs->vmhub);
930 struct amdgpu_device *adev = ring->adev;
931 struct amdgpu_vmhub *hub = &adev->vmhub[ring->funcs->vmhub];
932 uint32_t req = gmc_v9_0_get_invalidate_req(vmid, 0);
933 unsigned eng = ring->vm_inv_eng;
936 * It may lose gpuvm invalidate acknowldege state across power-gating
937 * off cycle, add semaphore acquire before invalidation and semaphore
938 * release after invalidation to avoid entering power gated state
942 /* TODO: It needs to continue working on debugging with semaphore for GFXHUB as well. */
944 /* a read return value of 1 means semaphore acuqire */
945 amdgpu_ring_emit_reg_wait(ring,
946 hub->vm_inv_eng0_sem +
947 hub->eng_distance * eng, 0x1, 0x1);
949 amdgpu_ring_emit_wreg(ring, hub->ctx0_ptb_addr_lo32 +
950 (hub->ctx_addr_distance * vmid),
951 lower_32_bits(pd_addr));
953 amdgpu_ring_emit_wreg(ring, hub->ctx0_ptb_addr_hi32 +
954 (hub->ctx_addr_distance * vmid),
955 upper_32_bits(pd_addr));
957 amdgpu_ring_emit_reg_write_reg_wait(ring, hub->vm_inv_eng0_req +
958 hub->eng_distance * eng,
959 hub->vm_inv_eng0_ack +
960 hub->eng_distance * eng,
963 /* TODO: It needs to continue working on debugging with semaphore for GFXHUB as well. */
966 * add semaphore release after invalidation,
967 * write with 0 means semaphore release
969 amdgpu_ring_emit_wreg(ring, hub->vm_inv_eng0_sem +
970 hub->eng_distance * eng, 0);
975 static void gmc_v9_0_emit_pasid_mapping(struct amdgpu_ring *ring, unsigned vmid,
978 struct amdgpu_device *adev = ring->adev;
981 /* Do nothing because there's no lut register for mmhub1. */
982 if (ring->funcs->vmhub == AMDGPU_MMHUB_1)
985 if (ring->funcs->vmhub == AMDGPU_GFXHUB_0)
986 reg = SOC15_REG_OFFSET(OSSSYS, 0, mmIH_VMID_0_LUT) + vmid;
988 reg = SOC15_REG_OFFSET(OSSSYS, 0, mmIH_VMID_0_LUT_MM) + vmid;
990 amdgpu_ring_emit_wreg(ring, reg, pasid);
994 * PTE format on VEGA 10:
1003 * 47:12 4k physical page base address
1013 * PDE format on VEGA 10:
1014 * 63:59 block fragment size
1018 * 47:6 physical base address of PD or PTE
1025 static uint64_t gmc_v9_0_map_mtype(struct amdgpu_device *adev, uint32_t flags)
1029 case AMDGPU_VM_MTYPE_DEFAULT:
1030 return AMDGPU_PTE_MTYPE_VG10(MTYPE_NC);
1031 case AMDGPU_VM_MTYPE_NC:
1032 return AMDGPU_PTE_MTYPE_VG10(MTYPE_NC);
1033 case AMDGPU_VM_MTYPE_WC:
1034 return AMDGPU_PTE_MTYPE_VG10(MTYPE_WC);
1035 case AMDGPU_VM_MTYPE_RW:
1036 return AMDGPU_PTE_MTYPE_VG10(MTYPE_RW);
1037 case AMDGPU_VM_MTYPE_CC:
1038 return AMDGPU_PTE_MTYPE_VG10(MTYPE_CC);
1039 case AMDGPU_VM_MTYPE_UC:
1040 return AMDGPU_PTE_MTYPE_VG10(MTYPE_UC);
1042 return AMDGPU_PTE_MTYPE_VG10(MTYPE_NC);
1046 static void gmc_v9_0_get_vm_pde(struct amdgpu_device *adev, int level,
1047 uint64_t *addr, uint64_t *flags)
1049 if (!(*flags & AMDGPU_PDE_PTE) && !(*flags & AMDGPU_PTE_SYSTEM))
1050 *addr = adev->vm_manager.vram_base_offset + *addr -
1051 adev->gmc.vram_start;
1052 BUG_ON(*addr & 0xFFFF00000000003FULL);
1054 if (!adev->gmc.translate_further)
1057 if (level == AMDGPU_VM_PDB1) {
1058 /* Set the block fragment size */
1059 if (!(*flags & AMDGPU_PDE_PTE))
1060 *flags |= AMDGPU_PDE_BFS(0x9);
1062 } else if (level == AMDGPU_VM_PDB0) {
1063 if (*flags & AMDGPU_PDE_PTE)
1064 *flags &= ~AMDGPU_PDE_PTE;
1066 *flags |= AMDGPU_PTE_TF;
1070 static void gmc_v9_0_get_vm_pte(struct amdgpu_device *adev,
1071 struct amdgpu_bo_va_mapping *mapping,
1074 *flags &= ~AMDGPU_PTE_EXECUTABLE;
1075 *flags |= mapping->flags & AMDGPU_PTE_EXECUTABLE;
1077 *flags &= ~AMDGPU_PTE_MTYPE_VG10_MASK;
1078 *flags |= mapping->flags & AMDGPU_PTE_MTYPE_VG10_MASK;
1080 if (mapping->flags & AMDGPU_PTE_PRT) {
1081 *flags |= AMDGPU_PTE_PRT;
1082 *flags &= ~AMDGPU_PTE_VALID;
1085 if ((adev->asic_type == CHIP_ARCTURUS ||
1086 adev->asic_type == CHIP_ALDEBARAN) &&
1087 !(*flags & AMDGPU_PTE_SYSTEM) &&
1088 mapping->bo_va->is_xgmi)
1089 *flags |= AMDGPU_PTE_SNOOPED;
1091 if (adev->asic_type == CHIP_ALDEBARAN)
1092 *flags |= mapping->flags & AMDGPU_PTE_SNOOPED;
1095 static unsigned gmc_v9_0_get_vbios_fb_size(struct amdgpu_device *adev)
1097 u32 d1vga_control = RREG32_SOC15(DCE, 0, mmD1VGA_CONTROL);
1100 if (REG_GET_FIELD(d1vga_control, D1VGA_CONTROL, D1VGA_MODE_ENABLE)) {
1101 size = AMDGPU_VBIOS_VGA_ALLOCATION;
1105 switch (adev->asic_type) {
1108 viewport = RREG32_SOC15(DCE, 0, mmHUBP0_DCSURF_PRI_VIEWPORT_DIMENSION);
1109 size = (REG_GET_FIELD(viewport,
1110 HUBP0_DCSURF_PRI_VIEWPORT_DIMENSION, PRI_VIEWPORT_HEIGHT) *
1111 REG_GET_FIELD(viewport,
1112 HUBP0_DCSURF_PRI_VIEWPORT_DIMENSION, PRI_VIEWPORT_WIDTH) *
1119 viewport = RREG32_SOC15(DCE, 0, mmSCL0_VIEWPORT_SIZE);
1120 size = (REG_GET_FIELD(viewport, SCL0_VIEWPORT_SIZE, VIEWPORT_HEIGHT) *
1121 REG_GET_FIELD(viewport, SCL0_VIEWPORT_SIZE, VIEWPORT_WIDTH) *
1130 static const struct amdgpu_gmc_funcs gmc_v9_0_gmc_funcs = {
1131 .flush_gpu_tlb = gmc_v9_0_flush_gpu_tlb,
1132 .flush_gpu_tlb_pasid = gmc_v9_0_flush_gpu_tlb_pasid,
1133 .emit_flush_gpu_tlb = gmc_v9_0_emit_flush_gpu_tlb,
1134 .emit_pasid_mapping = gmc_v9_0_emit_pasid_mapping,
1135 .map_mtype = gmc_v9_0_map_mtype,
1136 .get_vm_pde = gmc_v9_0_get_vm_pde,
1137 .get_vm_pte = gmc_v9_0_get_vm_pte,
1138 .get_vbios_fb_size = gmc_v9_0_get_vbios_fb_size,
1141 static void gmc_v9_0_set_gmc_funcs(struct amdgpu_device *adev)
1143 adev->gmc.gmc_funcs = &gmc_v9_0_gmc_funcs;
1146 static void gmc_v9_0_set_umc_funcs(struct amdgpu_device *adev)
1148 switch (adev->asic_type) {
1150 adev->umc.funcs = &umc_v6_0_funcs;
1153 adev->umc.max_ras_err_cnt_per_query = UMC_V6_1_TOTAL_CHANNEL_NUM;
1154 adev->umc.channel_inst_num = UMC_V6_1_CHANNEL_INSTANCE_NUM;
1155 adev->umc.umc_inst_num = UMC_V6_1_UMC_INSTANCE_NUM;
1156 adev->umc.channel_offs = UMC_V6_1_PER_CHANNEL_OFFSET_VG20;
1157 adev->umc.channel_idx_tbl = &umc_v6_1_channel_idx_tbl[0][0];
1158 adev->umc.funcs = &umc_v6_1_funcs;
1161 adev->umc.max_ras_err_cnt_per_query = UMC_V6_1_TOTAL_CHANNEL_NUM;
1162 adev->umc.channel_inst_num = UMC_V6_1_CHANNEL_INSTANCE_NUM;
1163 adev->umc.umc_inst_num = UMC_V6_1_UMC_INSTANCE_NUM;
1164 adev->umc.channel_offs = UMC_V6_1_PER_CHANNEL_OFFSET_ARCT;
1165 adev->umc.channel_idx_tbl = &umc_v6_1_channel_idx_tbl[0][0];
1166 adev->umc.funcs = &umc_v6_1_funcs;
1173 static void gmc_v9_0_set_mmhub_funcs(struct amdgpu_device *adev)
1175 switch (adev->asic_type) {
1177 adev->mmhub.funcs = &mmhub_v9_4_funcs;
1179 case CHIP_ALDEBARAN:
1180 adev->mmhub.funcs = &mmhub_v1_7_funcs;
1183 adev->mmhub.funcs = &mmhub_v1_0_funcs;
1188 static void gmc_v9_0_set_gfxhub_funcs(struct amdgpu_device *adev)
1190 adev->gfxhub.funcs = &gfxhub_v1_0_funcs;
1193 static int gmc_v9_0_early_init(void *handle)
1195 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1197 gmc_v9_0_set_gmc_funcs(adev);
1198 gmc_v9_0_set_irq_funcs(adev);
1199 gmc_v9_0_set_umc_funcs(adev);
1200 gmc_v9_0_set_mmhub_funcs(adev);
1201 gmc_v9_0_set_gfxhub_funcs(adev);
1203 if (adev->asic_type == CHIP_VEGA20 ||
1204 adev->asic_type == CHIP_ARCTURUS)
1205 adev->gmc.xgmi.supported = true;
1207 if (adev->asic_type == CHIP_ALDEBARAN) {
1208 adev->gmc.xgmi.supported = true;
1209 adev->gmc.xgmi.connected_to_cpu =
1210 adev->smuio.funcs->is_host_gpu_xgmi_supported(adev);
1213 adev->gmc.shared_aperture_start = 0x2000000000000000ULL;
1214 adev->gmc.shared_aperture_end =
1215 adev->gmc.shared_aperture_start + (4ULL << 30) - 1;
1216 adev->gmc.private_aperture_start = 0x1000000000000000ULL;
1217 adev->gmc.private_aperture_end =
1218 adev->gmc.private_aperture_start + (4ULL << 30) - 1;
1223 static int gmc_v9_0_late_init(void *handle)
1225 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1228 r = amdgpu_gmc_allocate_vm_inv_eng(adev);
1233 * Workaround performance drop issue with VBIOS enables partial
1234 * writes, while disables HBM ECC for vega10.
1236 if (!amdgpu_sriov_vf(adev) && (adev->asic_type == CHIP_VEGA10)) {
1237 if (!(adev->ras_features & (1 << AMDGPU_RAS_BLOCK__UMC))) {
1238 if (adev->df.funcs->enable_ecc_force_par_wr_rmw)
1239 adev->df.funcs->enable_ecc_force_par_wr_rmw(adev, false);
1243 if (adev->mmhub.funcs && adev->mmhub.funcs->reset_ras_error_count)
1244 adev->mmhub.funcs->reset_ras_error_count(adev);
1246 r = amdgpu_gmc_ras_late_init(adev);
1250 return amdgpu_irq_get(adev, &adev->gmc.vm_fault, 0);
1253 static void gmc_v9_0_vram_gtt_location(struct amdgpu_device *adev,
1254 struct amdgpu_gmc *mc)
1258 if (!amdgpu_sriov_vf(adev))
1259 base = adev->mmhub.funcs->get_fb_location(adev);
1261 /* add the xgmi offset of the physical node */
1262 base += adev->gmc.xgmi.physical_node_id * adev->gmc.xgmi.node_segment_size;
1263 if (adev->gmc.xgmi.connected_to_cpu) {
1264 amdgpu_gmc_sysvm_location(adev, mc);
1266 amdgpu_gmc_vram_location(adev, mc, base);
1267 amdgpu_gmc_gart_location(adev, mc);
1268 amdgpu_gmc_agp_location(adev, mc);
1270 /* base offset of vram pages */
1271 adev->vm_manager.vram_base_offset = adev->gfxhub.funcs->get_mc_fb_offset(adev);
1273 /* XXX: add the xgmi offset of the physical node? */
1274 adev->vm_manager.vram_base_offset +=
1275 adev->gmc.xgmi.physical_node_id * adev->gmc.xgmi.node_segment_size;
1279 * gmc_v9_0_mc_init - initialize the memory controller driver params
1281 * @adev: amdgpu_device pointer
1283 * Look up the amount of vram, vram width, and decide how to place
1284 * vram and gart within the GPU's physical address space.
1285 * Returns 0 for success.
1287 static int gmc_v9_0_mc_init(struct amdgpu_device *adev)
1291 /* size in MB on si */
1292 adev->gmc.mc_vram_size =
1293 adev->nbio.funcs->get_memsize(adev) * 1024ULL * 1024ULL;
1294 adev->gmc.real_vram_size = adev->gmc.mc_vram_size;
1296 if (!(adev->flags & AMD_IS_APU) &&
1297 !adev->gmc.xgmi.connected_to_cpu) {
1298 r = amdgpu_device_resize_fb_bar(adev);
1302 adev->gmc.aper_base = pci_resource_start(adev->pdev, 0);
1303 adev->gmc.aper_size = pci_resource_len(adev->pdev, 0);
1305 #ifdef CONFIG_X86_64
1307 * AMD Accelerated Processing Platform (APP) supporting GPU-HOST xgmi
1308 * interface can use VRAM through here as it appears system reserved
1309 * memory in host address space.
1311 * For APUs, VRAM is just the stolen system memory and can be accessed
1314 * Otherwise, use the legacy Host Data Path (HDP) through PCIe BAR.
1317 /* check whether both host-gpu and gpu-gpu xgmi links exist */
1318 if ((adev->flags & AMD_IS_APU) ||
1319 (adev->gmc.xgmi.supported &&
1320 adev->gmc.xgmi.connected_to_cpu)) {
1321 adev->gmc.aper_base =
1322 adev->gfxhub.funcs->get_mc_fb_offset(adev) +
1323 adev->gmc.xgmi.physical_node_id *
1324 adev->gmc.xgmi.node_segment_size;
1325 adev->gmc.aper_size = adev->gmc.real_vram_size;
1329 /* In case the PCI BAR is larger than the actual amount of vram */
1330 adev->gmc.visible_vram_size = adev->gmc.aper_size;
1331 if (adev->gmc.visible_vram_size > adev->gmc.real_vram_size)
1332 adev->gmc.visible_vram_size = adev->gmc.real_vram_size;
1334 /* set the gart size */
1335 if (amdgpu_gart_size == -1) {
1336 switch (adev->asic_type) {
1337 case CHIP_VEGA10: /* all engines support GPUVM */
1338 case CHIP_VEGA12: /* all engines support GPUVM */
1341 case CHIP_ALDEBARAN:
1343 adev->gmc.gart_size = 512ULL << 20;
1345 case CHIP_RAVEN: /* DCE SG support */
1347 adev->gmc.gart_size = 1024ULL << 20;
1351 adev->gmc.gart_size = (u64)amdgpu_gart_size << 20;
1354 adev->gmc.gart_size += adev->pm.smu_prv_buffer_size;
1356 gmc_v9_0_vram_gtt_location(adev, &adev->gmc);
1361 static int gmc_v9_0_gart_init(struct amdgpu_device *adev)
1365 if (adev->gart.bo) {
1366 WARN(1, "VEGA10 PCIE GART already initialized\n");
1370 if (adev->gmc.xgmi.connected_to_cpu) {
1371 adev->gmc.vmid0_page_table_depth = 1;
1372 adev->gmc.vmid0_page_table_block_size = 12;
1374 adev->gmc.vmid0_page_table_depth = 0;
1375 adev->gmc.vmid0_page_table_block_size = 0;
1378 /* Initialize common gart structure */
1379 r = amdgpu_gart_init(adev);
1382 adev->gart.table_size = adev->gart.num_gpu_pages * 8;
1383 adev->gart.gart_pte_flags = AMDGPU_PTE_MTYPE_VG10(MTYPE_UC) |
1384 AMDGPU_PTE_EXECUTABLE;
1386 r = amdgpu_gart_table_vram_alloc(adev);
1390 if (adev->gmc.xgmi.connected_to_cpu) {
1391 r = amdgpu_gmc_pdb0_alloc(adev);
1398 * gmc_v9_0_save_registers - saves regs
1400 * @adev: amdgpu_device pointer
1402 * This saves potential register values that should be
1403 * restored upon resume
1405 static void gmc_v9_0_save_registers(struct amdgpu_device *adev)
1407 if (adev->asic_type == CHIP_RAVEN)
1408 adev->gmc.sdpif_register = RREG32_SOC15(DCE, 0, mmDCHUBBUB_SDPIF_MMIO_CNTRL_0);
1411 static int gmc_v9_0_sw_init(void *handle)
1413 int r, vram_width = 0, vram_type = 0, vram_vendor = 0;
1414 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1416 adev->gfxhub.funcs->init(adev);
1418 adev->mmhub.funcs->init(adev);
1420 spin_lock_init(&adev->gmc.invalidate_lock);
1422 r = amdgpu_atomfirmware_get_vram_info(adev,
1423 &vram_width, &vram_type, &vram_vendor);
1424 if (amdgpu_sriov_vf(adev))
1425 /* For Vega10 SR-IOV, vram_width can't be read from ATOM as RAVEN,
1426 * and DF related registers is not readable, seems hardcord is the
1427 * only way to set the correct vram_width
1429 adev->gmc.vram_width = 2048;
1430 else if (amdgpu_emu_mode != 1)
1431 adev->gmc.vram_width = vram_width;
1433 if (!adev->gmc.vram_width) {
1434 int chansize, numchan;
1436 /* hbm memory channel size */
1437 if (adev->flags & AMD_IS_APU)
1442 numchan = adev->df.funcs->get_hbm_channel_number(adev);
1443 adev->gmc.vram_width = numchan * chansize;
1446 adev->gmc.vram_type = vram_type;
1447 adev->gmc.vram_vendor = vram_vendor;
1448 switch (adev->asic_type) {
1450 adev->num_vmhubs = 2;
1452 if (adev->rev_id == 0x0 || adev->rev_id == 0x1) {
1453 amdgpu_vm_adjust_size(adev, 256 * 1024, 9, 3, 48);
1455 /* vm_size is 128TB + 512GB for legacy 3-level page support */
1456 amdgpu_vm_adjust_size(adev, 128 * 1024 + 512, 9, 2, 48);
1457 adev->gmc.translate_further =
1458 adev->vm_manager.num_level > 1;
1465 case CHIP_ALDEBARAN:
1466 adev->num_vmhubs = 2;
1470 * To fulfill 4-level page support,
1471 * vm size is 256TB (48bit), maximum size of Vega10,
1472 * block size 512 (9bit)
1474 /* sriov restrict max_pfn below AMDGPU_GMC_HOLE */
1475 if (amdgpu_sriov_vf(adev))
1476 amdgpu_vm_adjust_size(adev, 256 * 1024, 9, 3, 47);
1478 amdgpu_vm_adjust_size(adev, 256 * 1024, 9, 3, 48);
1481 adev->num_vmhubs = 3;
1483 /* Keep the vm size same with Vega20 */
1484 amdgpu_vm_adjust_size(adev, 256 * 1024, 9, 3, 48);
1490 /* This interrupt is VMC page fault.*/
1491 r = amdgpu_irq_add_id(adev, SOC15_IH_CLIENTID_VMC, VMC_1_0__SRCID__VM_FAULT,
1492 &adev->gmc.vm_fault);
1496 if (adev->asic_type == CHIP_ARCTURUS) {
1497 r = amdgpu_irq_add_id(adev, SOC15_IH_CLIENTID_VMC1, VMC_1_0__SRCID__VM_FAULT,
1498 &adev->gmc.vm_fault);
1503 r = amdgpu_irq_add_id(adev, SOC15_IH_CLIENTID_UTCL2, UTCL2_1_0__SRCID__FAULT,
1504 &adev->gmc.vm_fault);
1509 if (!amdgpu_sriov_vf(adev)) {
1510 /* interrupt sent to DF. */
1511 r = amdgpu_irq_add_id(adev, SOC15_IH_CLIENTID_DF, 0,
1512 &adev->gmc.ecc_irq);
1517 /* Set the internal MC address mask
1518 * This is the max address of the GPU's
1519 * internal address space.
1521 adev->gmc.mc_mask = 0xffffffffffffULL; /* 48 bit MC */
1523 r = dma_set_mask_and_coherent(adev->dev, DMA_BIT_MASK(44));
1525 printk(KERN_WARNING "amdgpu: No suitable DMA available.\n");
1528 adev->need_swiotlb = drm_need_swiotlb(44);
1530 if (adev->gmc.xgmi.supported) {
1531 r = adev->gfxhub.funcs->get_xgmi_info(adev);
1536 r = gmc_v9_0_mc_init(adev);
1540 amdgpu_gmc_get_vbios_allocations(adev);
1542 /* Memory manager */
1543 r = amdgpu_bo_init(adev);
1547 r = gmc_v9_0_gart_init(adev);
1553 * VMID 0 is reserved for System
1554 * amdgpu graphics/compute will use VMIDs 1..n-1
1555 * amdkfd will use VMIDs n..15
1557 * The first KFD VMID is 8 for GPUs with graphics, 3 for
1558 * compute-only GPUs. On compute-only GPUs that leaves 2 VMIDs
1559 * for video processing.
1561 adev->vm_manager.first_kfd_vmid =
1562 (adev->asic_type == CHIP_ARCTURUS ||
1563 adev->asic_type == CHIP_ALDEBARAN) ? 3 : 8;
1565 amdgpu_vm_manager_init(adev);
1567 gmc_v9_0_save_registers(adev);
1572 static int gmc_v9_0_sw_fini(void *handle)
1574 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1576 amdgpu_gmc_ras_fini(adev);
1577 amdgpu_gem_force_release(adev);
1578 amdgpu_vm_manager_fini(adev);
1579 amdgpu_gart_table_vram_free(adev);
1580 amdgpu_bo_unref(&adev->gmc.pdb0_bo);
1581 amdgpu_bo_fini(adev);
1582 amdgpu_gart_fini(adev);
1587 static void gmc_v9_0_init_golden_registers(struct amdgpu_device *adev)
1590 switch (adev->asic_type) {
1592 if (amdgpu_sriov_vf(adev))
1596 soc15_program_register_sequence(adev,
1597 golden_settings_mmhub_1_0_0,
1598 ARRAY_SIZE(golden_settings_mmhub_1_0_0));
1599 soc15_program_register_sequence(adev,
1600 golden_settings_athub_1_0_0,
1601 ARRAY_SIZE(golden_settings_athub_1_0_0));
1606 /* TODO for renoir */
1607 soc15_program_register_sequence(adev,
1608 golden_settings_athub_1_0_0,
1609 ARRAY_SIZE(golden_settings_athub_1_0_0));
1617 * gmc_v9_0_restore_registers - restores regs
1619 * @adev: amdgpu_device pointer
1621 * This restores register values, saved at suspend.
1623 void gmc_v9_0_restore_registers(struct amdgpu_device *adev)
1625 if (adev->asic_type == CHIP_RAVEN) {
1626 WREG32_SOC15(DCE, 0, mmDCHUBBUB_SDPIF_MMIO_CNTRL_0, adev->gmc.sdpif_register);
1627 WARN_ON(adev->gmc.sdpif_register !=
1628 RREG32_SOC15(DCE, 0, mmDCHUBBUB_SDPIF_MMIO_CNTRL_0));
1633 * gmc_v9_0_gart_enable - gart enable
1635 * @adev: amdgpu_device pointer
1637 static int gmc_v9_0_gart_enable(struct amdgpu_device *adev)
1641 if (adev->gmc.xgmi.connected_to_cpu)
1642 amdgpu_gmc_init_pdb0(adev);
1644 if (adev->gart.bo == NULL) {
1645 dev_err(adev->dev, "No VRAM object for PCIE GART.\n");
1649 r = amdgpu_gart_table_vram_pin(adev);
1653 r = adev->gfxhub.funcs->gart_enable(adev);
1657 r = adev->mmhub.funcs->gart_enable(adev);
1661 DRM_INFO("PCIE GART of %uM enabled.\n",
1662 (unsigned)(adev->gmc.gart_size >> 20));
1663 if (adev->gmc.pdb0_bo)
1664 DRM_INFO("PDB0 located at 0x%016llX\n",
1665 (unsigned long long)amdgpu_bo_gpu_offset(adev->gmc.pdb0_bo));
1666 DRM_INFO("PTB located at 0x%016llX\n",
1667 (unsigned long long)amdgpu_bo_gpu_offset(adev->gart.bo));
1669 adev->gart.ready = true;
1673 static int gmc_v9_0_hw_init(void *handle)
1675 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1679 /* The sequence of these two function calls matters.*/
1680 gmc_v9_0_init_golden_registers(adev);
1682 if (adev->mode_info.num_crtc) {
1683 /* Lockout access through VGA aperture*/
1684 WREG32_FIELD15(DCE, 0, VGA_HDP_CONTROL, VGA_MEMORY_DISABLE, 1);
1685 /* disable VGA render */
1686 WREG32_FIELD15(DCE, 0, VGA_RENDER_CONTROL, VGA_VSTATUS_CNTL, 0);
1689 if (adev->mmhub.funcs->update_power_gating)
1690 adev->mmhub.funcs->update_power_gating(adev, true);
1692 adev->hdp.funcs->init_registers(adev);
1694 /* After HDP is initialized, flush HDP.*/
1695 adev->hdp.funcs->flush_hdp(adev, NULL);
1697 if (amdgpu_vm_fault_stop == AMDGPU_VM_FAULT_STOP_ALWAYS)
1702 if (!amdgpu_sriov_vf(adev)) {
1703 adev->gfxhub.funcs->set_fault_enable_default(adev, value);
1704 adev->mmhub.funcs->set_fault_enable_default(adev, value);
1706 for (i = 0; i < adev->num_vmhubs; ++i)
1707 gmc_v9_0_flush_gpu_tlb(adev, 0, i, 0);
1709 if (adev->umc.funcs && adev->umc.funcs->init_registers)
1710 adev->umc.funcs->init_registers(adev);
1712 r = gmc_v9_0_gart_enable(adev);
1718 * gmc_v9_0_gart_disable - gart disable
1720 * @adev: amdgpu_device pointer
1722 * This disables all VM page table.
1724 static void gmc_v9_0_gart_disable(struct amdgpu_device *adev)
1726 adev->gfxhub.funcs->gart_disable(adev);
1727 adev->mmhub.funcs->gart_disable(adev);
1728 amdgpu_gart_table_vram_unpin(adev);
1731 static int gmc_v9_0_hw_fini(void *handle)
1733 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1735 if (amdgpu_sriov_vf(adev)) {
1736 /* full access mode, so don't touch any GMC register */
1737 DRM_DEBUG("For SRIOV client, shouldn't do anything.\n");
1741 amdgpu_irq_put(adev, &adev->gmc.ecc_irq, 0);
1742 amdgpu_irq_put(adev, &adev->gmc.vm_fault, 0);
1743 gmc_v9_0_gart_disable(adev);
1748 static int gmc_v9_0_suspend(void *handle)
1750 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1752 return gmc_v9_0_hw_fini(adev);
1755 static int gmc_v9_0_resume(void *handle)
1758 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1760 r = gmc_v9_0_hw_init(adev);
1764 amdgpu_vmid_reset_all(adev);
1769 static bool gmc_v9_0_is_idle(void *handle)
1771 /* MC is always ready in GMC v9.*/
1775 static int gmc_v9_0_wait_for_idle(void *handle)
1777 /* There is no need to wait for MC idle in GMC v9.*/
1781 static int gmc_v9_0_soft_reset(void *handle)
1783 /* XXX for emulation.*/
1787 static int gmc_v9_0_set_clockgating_state(void *handle,
1788 enum amd_clockgating_state state)
1790 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1792 adev->mmhub.funcs->set_clockgating(adev, state);
1794 athub_v1_0_set_clockgating(adev, state);
1799 static void gmc_v9_0_get_clockgating_state(void *handle, u32 *flags)
1801 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1803 adev->mmhub.funcs->get_clockgating(adev, flags);
1805 athub_v1_0_get_clockgating(adev, flags);
1808 static int gmc_v9_0_set_powergating_state(void *handle,
1809 enum amd_powergating_state state)
1814 const struct amd_ip_funcs gmc_v9_0_ip_funcs = {
1816 .early_init = gmc_v9_0_early_init,
1817 .late_init = gmc_v9_0_late_init,
1818 .sw_init = gmc_v9_0_sw_init,
1819 .sw_fini = gmc_v9_0_sw_fini,
1820 .hw_init = gmc_v9_0_hw_init,
1821 .hw_fini = gmc_v9_0_hw_fini,
1822 .suspend = gmc_v9_0_suspend,
1823 .resume = gmc_v9_0_resume,
1824 .is_idle = gmc_v9_0_is_idle,
1825 .wait_for_idle = gmc_v9_0_wait_for_idle,
1826 .soft_reset = gmc_v9_0_soft_reset,
1827 .set_clockgating_state = gmc_v9_0_set_clockgating_state,
1828 .set_powergating_state = gmc_v9_0_set_powergating_state,
1829 .get_clockgating_state = gmc_v9_0_get_clockgating_state,
1832 const struct amdgpu_ip_block_version gmc_v9_0_ip_block =
1834 .type = AMD_IP_BLOCK_TYPE_GMC,
1838 .funcs = &gmc_v9_0_ip_funcs,