hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/gpu/drm/amd/amdgpu/soc15.c
....@@ -23,7 +23,8 @@
2323 #include <linux/firmware.h>
2424 #include <linux/slab.h>
2525 #include <linux/module.h>
26
-#include <drm/drmP.h>
26
+#include <linux/pci.h>
27
+
2728 #include "amdgpu.h"
2829 #include "amdgpu_atombios.h"
2930 #include "amdgpu_ih.h"
....@@ -43,6 +44,11 @@
4344 #include "hdp/hdp_4_0_sh_mask.h"
4445 #include "smuio/smuio_9_0_offset.h"
4546 #include "smuio/smuio_9_0_sh_mask.h"
47
+#include "nbio/nbio_7_0_default.h"
48
+#include "nbio/nbio_7_0_offset.h"
49
+#include "nbio/nbio_7_0_sh_mask.h"
50
+#include "nbio/nbio_7_0_smn.h"
51
+#include "mp/mp_9_0_offset.h"
4652
4753 #include "soc15.h"
4854 #include "soc15_common.h"
....@@ -52,50 +58,83 @@
5258 #include "mmhub_v1_0.h"
5359 #include "df_v1_7.h"
5460 #include "df_v3_6.h"
61
+#include "nbio_v6_1.h"
62
+#include "nbio_v7_0.h"
63
+#include "nbio_v7_4.h"
5564 #include "vega10_ih.h"
5665 #include "sdma_v4_0.h"
5766 #include "uvd_v7_0.h"
5867 #include "vce_v4_0.h"
5968 #include "vcn_v1_0.h"
69
+#include "vcn_v2_0.h"
70
+#include "jpeg_v2_0.h"
71
+#include "vcn_v2_5.h"
72
+#include "jpeg_v2_5.h"
6073 #include "dce_virtual.h"
6174 #include "mxgpu_ai.h"
75
+#include "amdgpu_smu.h"
76
+#include "amdgpu_ras.h"
77
+#include "amdgpu_xgmi.h"
78
+#include <uapi/linux/kfd_ioctl.h>
6279
6380 #define mmMP0_MISC_CGTT_CTRL0 0x01b9
6481 #define mmMP0_MISC_CGTT_CTRL0_BASE_IDX 0
6582 #define mmMP0_MISC_LIGHT_SLEEP_CTRL 0x01ba
6683 #define mmMP0_MISC_LIGHT_SLEEP_CTRL_BASE_IDX 0
6784
85
+/* for Vega20 register name change */
86
+#define mmHDP_MEM_POWER_CTRL 0x00d4
87
+#define HDP_MEM_POWER_CTRL__IPH_MEM_POWER_CTRL_EN_MASK 0x00000001L
88
+#define HDP_MEM_POWER_CTRL__IPH_MEM_POWER_LS_EN_MASK 0x00000002L
89
+#define HDP_MEM_POWER_CTRL__RC_MEM_POWER_CTRL_EN_MASK 0x00010000L
90
+#define HDP_MEM_POWER_CTRL__RC_MEM_POWER_LS_EN_MASK 0x00020000L
91
+#define mmHDP_MEM_POWER_CTRL_BASE_IDX 0
92
+
93
+/* for Vega20/arcturus regiter offset change */
94
+#define mmROM_INDEX_VG20 0x00e4
95
+#define mmROM_INDEX_VG20_BASE_IDX 0
96
+#define mmROM_DATA_VG20 0x00e5
97
+#define mmROM_DATA_VG20_BASE_IDX 0
98
+
6899 /*
69100 * Indirect registers accessor
70101 */
71102 static u32 soc15_pcie_rreg(struct amdgpu_device *adev, u32 reg)
72103 {
73
- unsigned long flags, address, data;
74
- u32 r;
75
- address = adev->nbio_funcs->get_pcie_index_offset(adev);
76
- data = adev->nbio_funcs->get_pcie_data_offset(adev);
104
+ unsigned long address, data;
105
+ address = adev->nbio.funcs->get_pcie_index_offset(adev);
106
+ data = adev->nbio.funcs->get_pcie_data_offset(adev);
77107
78
- spin_lock_irqsave(&adev->pcie_idx_lock, flags);
79
- WREG32(address, reg);
80
- (void)RREG32(address);
81
- r = RREG32(data);
82
- spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
83
- return r;
108
+ return amdgpu_device_indirect_rreg(adev, address, data, reg);
84109 }
85110
86111 static void soc15_pcie_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
87112 {
88
- unsigned long flags, address, data;
113
+ unsigned long address, data;
89114
90
- address = adev->nbio_funcs->get_pcie_index_offset(adev);
91
- data = adev->nbio_funcs->get_pcie_data_offset(adev);
115
+ address = adev->nbio.funcs->get_pcie_index_offset(adev);
116
+ data = adev->nbio.funcs->get_pcie_data_offset(adev);
92117
93
- spin_lock_irqsave(&adev->pcie_idx_lock, flags);
94
- WREG32(address, reg);
95
- (void)RREG32(address);
96
- WREG32(data, v);
97
- (void)RREG32(data);
98
- spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
118
+ amdgpu_device_indirect_wreg(adev, address, data, reg, v);
119
+}
120
+
121
+static u64 soc15_pcie_rreg64(struct amdgpu_device *adev, u32 reg)
122
+{
123
+ unsigned long address, data;
124
+ address = adev->nbio.funcs->get_pcie_index_offset(adev);
125
+ data = adev->nbio.funcs->get_pcie_data_offset(adev);
126
+
127
+ return amdgpu_device_indirect_rreg64(adev, address, data, reg);
128
+}
129
+
130
+static void soc15_pcie_wreg64(struct amdgpu_device *adev, u32 reg, u64 v)
131
+{
132
+ unsigned long address, data;
133
+
134
+ address = adev->nbio.funcs->get_pcie_index_offset(adev);
135
+ data = adev->nbio.funcs->get_pcie_data_offset(adev);
136
+
137
+ amdgpu_device_indirect_wreg64(adev, address, data, reg, v);
99138 }
100139
101140 static u32 soc15_uvd_ctx_rreg(struct amdgpu_device *adev, u32 reg)
....@@ -200,13 +239,15 @@
200239
201240 static u32 soc15_get_config_memsize(struct amdgpu_device *adev)
202241 {
203
- return adev->nbio_funcs->get_memsize(adev);
242
+ return adev->nbio.funcs->get_memsize(adev);
204243 }
205244
206245 static u32 soc15_get_xclk(struct amdgpu_device *adev)
207246 {
208247 u32 reference_clock = adev->clock.spll.reference_freq;
209248
249
+ if (adev->asic_type == CHIP_RENOIR)
250
+ return 10000;
210251 if (adev->asic_type == CHIP_RAVEN)
211252 return reference_clock / 4;
212253
....@@ -223,7 +264,7 @@
223264 grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, VMID, vmid);
224265 grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, QUEUEID, queue);
225266
226
- WREG32(SOC15_REG_OFFSET(GC, 0, mmGRBM_GFX_CNTL), grbm_gfx_cntl);
267
+ WREG32_SOC15_RLC_SHADOW(GC, 0, mmGRBM_GFX_CNTL, grbm_gfx_cntl);
227268 }
228269
229270 static void soc15_vga_set_state(struct amdgpu_device *adev, bool state)
....@@ -242,6 +283,8 @@
242283 {
243284 u32 *dw_ptr;
244285 u32 i, length_dw;
286
+ uint32_t rom_index_offset;
287
+ uint32_t rom_data_offset;
245288
246289 if (bios == NULL)
247290 return false;
....@@ -254,23 +297,26 @@
254297 dw_ptr = (u32 *)bios;
255298 length_dw = ALIGN(length_bytes, 4) / 4;
256299
300
+ switch (adev->asic_type) {
301
+ case CHIP_VEGA20:
302
+ case CHIP_ARCTURUS:
303
+ rom_index_offset = SOC15_REG_OFFSET(SMUIO, 0, mmROM_INDEX_VG20);
304
+ rom_data_offset = SOC15_REG_OFFSET(SMUIO, 0, mmROM_DATA_VG20);
305
+ break;
306
+ default:
307
+ rom_index_offset = SOC15_REG_OFFSET(SMUIO, 0, mmROM_INDEX);
308
+ rom_data_offset = SOC15_REG_OFFSET(SMUIO, 0, mmROM_DATA);
309
+ break;
310
+ }
311
+
257312 /* set rom index to 0 */
258
- WREG32(SOC15_REG_OFFSET(SMUIO, 0, mmROM_INDEX), 0);
313
+ WREG32(rom_index_offset, 0);
259314 /* read out the rom data */
260315 for (i = 0; i < length_dw; i++)
261
- dw_ptr[i] = RREG32(SOC15_REG_OFFSET(SMUIO, 0, mmROM_DATA));
316
+ dw_ptr[i] = RREG32(rom_data_offset);
262317
263318 return true;
264319 }
265
-
266
-struct soc15_allowed_register_entry {
267
- uint32_t hwip;
268
- uint32_t inst;
269
- uint32_t seg;
270
- uint32_t reg_offset;
271
- bool grbm_indexed;
272
-};
273
-
274320
275321 static struct soc15_allowed_register_entry soc15_allowed_read_registers[] = {
276322 { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS)},
....@@ -288,6 +334,7 @@
288334 { SOC15_REG_ENTRY(GC, 0, mmCP_CPF_BUSY_STAT)},
289335 { SOC15_REG_ENTRY(GC, 0, mmCP_CPF_STALLED_STAT1)},
290336 { SOC15_REG_ENTRY(GC, 0, mmCP_CPF_STATUS)},
337
+ { SOC15_REG_ENTRY(GC, 0, mmCP_CPC_BUSY_STAT)},
291338 { SOC15_REG_ENTRY(GC, 0, mmCP_CPC_STALLED_STAT1)},
292339 { SOC15_REG_ENTRY(GC, 0, mmCP_CPC_STATUS)},
293340 { SOC15_REG_ENTRY(GC, 0, mmGB_ADDR_CONFIG)},
....@@ -335,7 +382,8 @@
335382 *value = 0;
336383 for (i = 0; i < ARRAY_SIZE(soc15_allowed_read_registers); i++) {
337384 en = &soc15_allowed_read_registers[i];
338
- if (reg_offset != (adev->reg_offset[en->hwip][en->inst][en->seg]
385
+ if (adev->reg_offset[en->hwip][en->inst] &&
386
+ reg_offset != (adev->reg_offset[en->hwip][en->inst][en->seg]
339387 + en->reg_offset))
340388 continue;
341389
....@@ -376,34 +424,44 @@
376424 } else {
377425 tmp = RREG32(reg);
378426 tmp &= ~(entry->and_mask);
379
- tmp |= entry->or_mask;
427
+ tmp |= (entry->or_mask & entry->and_mask);
380428 }
381
- WREG32(reg, tmp);
429
+
430
+ if (reg == SOC15_REG_OFFSET(GC, 0, mmPA_SC_BINNER_EVENT_CNTL_3) ||
431
+ reg == SOC15_REG_OFFSET(GC, 0, mmPA_SC_ENHANCE) ||
432
+ reg == SOC15_REG_OFFSET(GC, 0, mmPA_SC_ENHANCE_1) ||
433
+ reg == SOC15_REG_OFFSET(GC, 0, mmSH_MEM_CONFIG))
434
+ WREG32_RLC(reg, tmp);
435
+ else
436
+ WREG32(reg, tmp);
437
+
382438 }
383439
384440 }
385441
386
-
387
-static int soc15_asic_reset(struct amdgpu_device *adev)
442
+static int soc15_asic_mode1_reset(struct amdgpu_device *adev)
388443 {
389444 u32 i;
445
+ int ret = 0;
390446
391447 amdgpu_atombios_scratch_regs_engine_hung(adev, true);
392448
393
- dev_info(adev->dev, "GPU reset\n");
449
+ dev_info(adev->dev, "GPU mode1 reset\n");
394450
395451 /* disable BM */
396452 pci_clear_master(adev->pdev);
397453
398
- pci_save_state(adev->pdev);
454
+ amdgpu_device_cache_pci_state(adev->pdev);
399455
400
- psp_gpu_reset(adev);
456
+ ret = psp_gpu_reset(adev);
457
+ if (ret)
458
+ dev_err(adev->dev, "GPU mode1 reset failed\n");
401459
402
- pci_restore_state(adev->pdev);
460
+ amdgpu_device_load_pci_state(adev->pdev);
403461
404462 /* wait for asic to come out of reset */
405463 for (i = 0; i < adev->usec_timeout; i++) {
406
- u32 memsize = adev->nbio_funcs->get_memsize(adev);
464
+ u32 memsize = adev->nbio.funcs->get_memsize(adev);
407465
408466 if (memsize != 0xffffffff)
409467 break;
....@@ -412,7 +470,108 @@
412470
413471 amdgpu_atombios_scratch_regs_engine_hung(adev, false);
414472
473
+ return ret;
474
+}
475
+
476
+static int soc15_asic_baco_reset(struct amdgpu_device *adev)
477
+{
478
+ struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
479
+ int ret = 0;
480
+
481
+ /* avoid NBIF got stuck when do RAS recovery in BACO reset */
482
+ if (ras && ras->supported)
483
+ adev->nbio.funcs->enable_doorbell_interrupt(adev, false);
484
+
485
+ ret = amdgpu_dpm_baco_reset(adev);
486
+ if (ret)
487
+ return ret;
488
+
489
+ /* re-enable doorbell interrupt after BACO exit */
490
+ if (ras && ras->supported)
491
+ adev->nbio.funcs->enable_doorbell_interrupt(adev, true);
492
+
415493 return 0;
494
+}
495
+
496
+static enum amd_reset_method
497
+soc15_asic_reset_method(struct amdgpu_device *adev)
498
+{
499
+ bool baco_reset = false;
500
+ struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
501
+
502
+ if (amdgpu_reset_method == AMD_RESET_METHOD_MODE1 ||
503
+ amdgpu_reset_method == AMD_RESET_METHOD_MODE2 ||
504
+ amdgpu_reset_method == AMD_RESET_METHOD_BACO)
505
+ return amdgpu_reset_method;
506
+
507
+ if (amdgpu_reset_method != -1)
508
+ dev_warn(adev->dev, "Specified reset method:%d isn't supported, using AUTO instead.\n",
509
+ amdgpu_reset_method);
510
+
511
+ switch (adev->asic_type) {
512
+ case CHIP_RAVEN:
513
+ case CHIP_RENOIR:
514
+ return AMD_RESET_METHOD_MODE2;
515
+ case CHIP_VEGA10:
516
+ case CHIP_VEGA12:
517
+ case CHIP_ARCTURUS:
518
+ baco_reset = amdgpu_dpm_is_baco_supported(adev);
519
+ break;
520
+ case CHIP_VEGA20:
521
+ if (adev->psp.sos_fw_version >= 0x80067)
522
+ baco_reset = amdgpu_dpm_is_baco_supported(adev);
523
+
524
+ /*
525
+ * 1. PMFW version > 0x284300: all cases use baco
526
+ * 2. PMFW version <= 0x284300: only sGPU w/o RAS use baco
527
+ */
528
+ if ((ras && ras->supported) && adev->pm.fw_version <= 0x283400)
529
+ baco_reset = false;
530
+ break;
531
+ default:
532
+ break;
533
+ }
534
+
535
+ if (baco_reset)
536
+ return AMD_RESET_METHOD_BACO;
537
+ else
538
+ return AMD_RESET_METHOD_MODE1;
539
+}
540
+
541
+static int soc15_asic_reset(struct amdgpu_device *adev)
542
+{
543
+ /* original raven doesn't have full asic reset */
544
+ if ((adev->apu_flags & AMD_APU_IS_RAVEN) &&
545
+ !(adev->apu_flags & AMD_APU_IS_RAVEN2))
546
+ return 0;
547
+
548
+ switch (soc15_asic_reset_method(adev)) {
549
+ case AMD_RESET_METHOD_BACO:
550
+ dev_info(adev->dev, "BACO reset\n");
551
+ return soc15_asic_baco_reset(adev);
552
+ case AMD_RESET_METHOD_MODE2:
553
+ dev_info(adev->dev, "MODE2 reset\n");
554
+ return amdgpu_dpm_mode2_reset(adev);
555
+ default:
556
+ dev_info(adev->dev, "MODE1 reset\n");
557
+ return soc15_asic_mode1_reset(adev);
558
+ }
559
+}
560
+
561
+static bool soc15_supports_baco(struct amdgpu_device *adev)
562
+{
563
+ switch (adev->asic_type) {
564
+ case CHIP_VEGA10:
565
+ case CHIP_VEGA12:
566
+ case CHIP_ARCTURUS:
567
+ return amdgpu_dpm_is_baco_supported(adev);
568
+ case CHIP_VEGA20:
569
+ if (adev->psp.sos_fw_version >= 0x80067)
570
+ return amdgpu_dpm_is_baco_supported(adev);
571
+ return false;
572
+ default:
573
+ return false;
574
+ }
416575 }
417576
418577 /*static int soc15_set_uvd_clock(struct amdgpu_device *adev, u32 clock,
....@@ -471,8 +630,8 @@
471630 static void soc15_enable_doorbell_aperture(struct amdgpu_device *adev,
472631 bool enable)
473632 {
474
- adev->nbio_funcs->enable_doorbell_aperture(adev, enable);
475
- adev->nbio_funcs->enable_doorbell_selfring_aperture(adev, enable);
633
+ adev->nbio.funcs->enable_doorbell_aperture(adev, enable);
634
+ adev->nbio.funcs->enable_doorbell_selfring_aperture(adev, enable);
476635 }
477636
478637 static const struct amdgpu_ip_block_version vega10_common_ip_block =
....@@ -484,8 +643,15 @@
484643 .funcs = &soc15_common_ip_funcs,
485644 };
486645
487
-int soc15_set_ip_blocks(struct amdgpu_device *adev)
646
+static uint32_t soc15_get_rev_id(struct amdgpu_device *adev)
488647 {
648
+ return adev->nbio.funcs->get_rev_id(adev);
649
+}
650
+
651
+static void soc15_reg_base_init(struct amdgpu_device *adev)
652
+{
653
+ int r;
654
+
489655 /* Set IP register base before any HW register access */
490656 switch (adev->asic_type) {
491657 case CHIP_VEGA10:
....@@ -493,28 +659,67 @@
493659 case CHIP_RAVEN:
494660 vega10_reg_base_init(adev);
495661 break;
662
+ case CHIP_RENOIR:
663
+ /* It's safe to do ip discovery here for Renior,
664
+ * it doesn't support SRIOV. */
665
+ if (amdgpu_discovery) {
666
+ r = amdgpu_discovery_reg_base_init(adev);
667
+ if (r == 0)
668
+ break;
669
+ DRM_WARN("failed to init reg base from ip discovery table, "
670
+ "fallback to legacy init method\n");
671
+ }
672
+ vega10_reg_base_init(adev);
673
+ break;
496674 case CHIP_VEGA20:
497675 vega20_reg_base_init(adev);
498676 break;
677
+ case CHIP_ARCTURUS:
678
+ arct_reg_base_init(adev);
679
+ break;
499680 default:
500
- return -EINVAL;
681
+ DRM_ERROR("Unsupported asic type: %d!\n", adev->asic_type);
682
+ break;
683
+ }
684
+}
685
+
686
+void soc15_set_virt_ops(struct amdgpu_device *adev)
687
+{
688
+ adev->virt.ops = &xgpu_ai_virt_ops;
689
+
690
+ /* init soc15 reg base early enough so we can
691
+ * request request full access for sriov before
692
+ * set_ip_blocks. */
693
+ soc15_reg_base_init(adev);
694
+}
695
+
696
+int soc15_set_ip_blocks(struct amdgpu_device *adev)
697
+{
698
+ /* for bare metal case */
699
+ if (!amdgpu_sriov_vf(adev))
700
+ soc15_reg_base_init(adev);
701
+
702
+ if (adev->asic_type == CHIP_VEGA20 || adev->asic_type == CHIP_ARCTURUS)
703
+ adev->gmc.xgmi.supported = true;
704
+
705
+ if (adev->flags & AMD_IS_APU) {
706
+ adev->nbio.funcs = &nbio_v7_0_funcs;
707
+ adev->nbio.hdp_flush_reg = &nbio_v7_0_hdp_flush_reg;
708
+ } else if (adev->asic_type == CHIP_VEGA20 ||
709
+ adev->asic_type == CHIP_ARCTURUS) {
710
+ adev->nbio.funcs = &nbio_v7_4_funcs;
711
+ adev->nbio.hdp_flush_reg = &nbio_v7_4_hdp_flush_reg;
712
+ } else {
713
+ adev->nbio.funcs = &nbio_v6_1_funcs;
714
+ adev->nbio.hdp_flush_reg = &nbio_v6_1_hdp_flush_reg;
501715 }
502716
503
- if (adev->flags & AMD_IS_APU)
504
- adev->nbio_funcs = &nbio_v7_0_funcs;
505
- else if (adev->asic_type == CHIP_VEGA20)
506
- adev->nbio_funcs = &nbio_v7_0_funcs;
717
+ if (adev->asic_type == CHIP_VEGA20 || adev->asic_type == CHIP_ARCTURUS)
718
+ adev->df.funcs = &df_v3_6_funcs;
507719 else
508
- adev->nbio_funcs = &nbio_v6_1_funcs;
720
+ adev->df.funcs = &df_v1_7_funcs;
509721
510
- if (adev->asic_type == CHIP_VEGA20)
511
- adev->df_funcs = &df_v3_6_funcs;
512
- else
513
- adev->df_funcs = &df_v1_7_funcs;
514
- adev->nbio_funcs->detect_hw_virt(adev);
515
-
516
- if (amdgpu_sriov_vf(adev))
517
- adev->virt.ops = &xgpu_ai_virt_ops;
722
+ adev->rev_id = soc15_get_rev_id(adev);
518723
519724 switch (adev->asic_type) {
520725 case CHIP_VEGA10:
....@@ -522,42 +727,107 @@
522727 case CHIP_VEGA20:
523728 amdgpu_device_ip_block_add(adev, &vega10_common_ip_block);
524729 amdgpu_device_ip_block_add(adev, &gmc_v9_0_ip_block);
525
- amdgpu_device_ip_block_add(adev, &vega10_ih_ip_block);
526
- if (adev->asic_type != CHIP_VEGA20) {
527
- amdgpu_device_ip_block_add(adev, &psp_v3_1_ip_block);
730
+
731
+ /* For Vega10 SR-IOV, PSP need to be initialized before IH */
732
+ if (amdgpu_sriov_vf(adev)) {
733
+ if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP)) {
734
+ if (adev->asic_type == CHIP_VEGA20)
735
+ amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block);
736
+ else
737
+ amdgpu_device_ip_block_add(adev, &psp_v3_1_ip_block);
738
+ }
739
+ amdgpu_device_ip_block_add(adev, &vega10_ih_ip_block);
740
+ } else {
741
+ amdgpu_device_ip_block_add(adev, &vega10_ih_ip_block);
742
+ if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP)) {
743
+ if (adev->asic_type == CHIP_VEGA20)
744
+ amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block);
745
+ else
746
+ amdgpu_device_ip_block_add(adev, &psp_v3_1_ip_block);
747
+ }
748
+ }
749
+ amdgpu_device_ip_block_add(adev, &gfx_v9_0_ip_block);
750
+ amdgpu_device_ip_block_add(adev, &sdma_v4_0_ip_block);
751
+ if (is_support_sw_smu(adev)) {
528752 if (!amdgpu_sriov_vf(adev))
529
- amdgpu_device_ip_block_add(adev, &pp_smu_ip_block);
753
+ amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
754
+ } else {
755
+ amdgpu_device_ip_block_add(adev, &pp_smu_ip_block);
530756 }
531757 if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
532758 amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
533759 #if defined(CONFIG_DRM_AMD_DC)
534760 else if (amdgpu_device_has_dc_support(adev))
535761 amdgpu_device_ip_block_add(adev, &dm_ip_block);
536
-#else
537
-# warning "Enable CONFIG_DRM_AMD_DC for display support on SOC15."
538762 #endif
539
- amdgpu_device_ip_block_add(adev, &gfx_v9_0_ip_block);
540
- amdgpu_device_ip_block_add(adev, &sdma_v4_0_ip_block);
541
- amdgpu_device_ip_block_add(adev, &uvd_v7_0_ip_block);
542
- amdgpu_device_ip_block_add(adev, &vce_v4_0_ip_block);
763
+ if (!(adev->asic_type == CHIP_VEGA20 && amdgpu_sriov_vf(adev))) {
764
+ amdgpu_device_ip_block_add(adev, &uvd_v7_0_ip_block);
765
+ amdgpu_device_ip_block_add(adev, &vce_v4_0_ip_block);
766
+ }
543767 break;
544768 case CHIP_RAVEN:
545769 amdgpu_device_ip_block_add(adev, &vega10_common_ip_block);
546770 amdgpu_device_ip_block_add(adev, &gmc_v9_0_ip_block);
547771 amdgpu_device_ip_block_add(adev, &vega10_ih_ip_block);
548
- amdgpu_device_ip_block_add(adev, &psp_v10_0_ip_block);
772
+ if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP))
773
+ amdgpu_device_ip_block_add(adev, &psp_v10_0_ip_block);
774
+ amdgpu_device_ip_block_add(adev, &gfx_v9_0_ip_block);
775
+ amdgpu_device_ip_block_add(adev, &sdma_v4_0_ip_block);
549776 amdgpu_device_ip_block_add(adev, &pp_smu_ip_block);
550777 if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
551778 amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
552779 #if defined(CONFIG_DRM_AMD_DC)
553780 else if (amdgpu_device_has_dc_support(adev))
554781 amdgpu_device_ip_block_add(adev, &dm_ip_block);
555
-#else
556
-# warning "Enable CONFIG_DRM_AMD_DC for display support on SOC15."
557782 #endif
783
+ amdgpu_device_ip_block_add(adev, &vcn_v1_0_ip_block);
784
+ break;
785
+ case CHIP_ARCTURUS:
786
+ amdgpu_device_ip_block_add(adev, &vega10_common_ip_block);
787
+ amdgpu_device_ip_block_add(adev, &gmc_v9_0_ip_block);
788
+
789
+ if (amdgpu_sriov_vf(adev)) {
790
+ if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP))
791
+ amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block);
792
+ amdgpu_device_ip_block_add(adev, &vega10_ih_ip_block);
793
+ } else {
794
+ amdgpu_device_ip_block_add(adev, &vega10_ih_ip_block);
795
+ if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP))
796
+ amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block);
797
+ }
798
+
799
+ if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
800
+ amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
558801 amdgpu_device_ip_block_add(adev, &gfx_v9_0_ip_block);
559802 amdgpu_device_ip_block_add(adev, &sdma_v4_0_ip_block);
560
- amdgpu_device_ip_block_add(adev, &vcn_v1_0_ip_block);
803
+ amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
804
+
805
+ if (amdgpu_sriov_vf(adev)) {
806
+ if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP))
807
+ amdgpu_device_ip_block_add(adev, &vcn_v2_5_ip_block);
808
+ } else {
809
+ amdgpu_device_ip_block_add(adev, &vcn_v2_5_ip_block);
810
+ }
811
+ if (!amdgpu_sriov_vf(adev))
812
+ amdgpu_device_ip_block_add(adev, &jpeg_v2_5_ip_block);
813
+ break;
814
+ case CHIP_RENOIR:
815
+ amdgpu_device_ip_block_add(adev, &vega10_common_ip_block);
816
+ amdgpu_device_ip_block_add(adev, &gmc_v9_0_ip_block);
817
+ amdgpu_device_ip_block_add(adev, &vega10_ih_ip_block);
818
+ if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP))
819
+ amdgpu_device_ip_block_add(adev, &psp_v12_0_ip_block);
820
+ amdgpu_device_ip_block_add(adev, &smu_v12_0_ip_block);
821
+ amdgpu_device_ip_block_add(adev, &gfx_v9_0_ip_block);
822
+ amdgpu_device_ip_block_add(adev, &sdma_v4_0_ip_block);
823
+ if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
824
+ amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
825
+#if defined(CONFIG_DRM_AMD_DC)
826
+ else if (amdgpu_device_has_dc_support(adev))
827
+ amdgpu_device_ip_block_add(adev, &dm_ip_block);
828
+#endif
829
+ amdgpu_device_ip_block_add(adev, &vcn_v2_0_ip_block);
830
+ amdgpu_device_ip_block_add(adev, &jpeg_v2_0_ip_block);
561831 break;
562832 default:
563833 return -EINVAL;
....@@ -566,21 +836,16 @@
566836 return 0;
567837 }
568838
569
-static uint32_t soc15_get_rev_id(struct amdgpu_device *adev)
570
-{
571
- return adev->nbio_funcs->get_rev_id(adev);
572
-}
573
-
574839 static void soc15_flush_hdp(struct amdgpu_device *adev, struct amdgpu_ring *ring)
575840 {
576
- adev->nbio_funcs->hdp_flush(adev, ring);
841
+ adev->nbio.funcs->hdp_flush(adev, ring);
577842 }
578843
579844 static void soc15_invalidate_hdp(struct amdgpu_device *adev,
580845 struct amdgpu_ring *ring)
581846 {
582847 if (!ring || !ring->funcs->emit_wreg)
583
- WREG32_SOC15_NO_KIQ(NBIO, 0, mmHDP_READ_CACHE_INVALIDATE, 1);
848
+ WREG32_SOC15_NO_KIQ(HDP, 0, mmHDP_READ_CACHE_INVALIDATE, 1);
584849 else
585850 amdgpu_ring_emit_wreg(ring, SOC15_REG_OFFSET(
586851 HDP, 0, mmHDP_READ_CACHE_INVALIDATE), 1);
....@@ -592,12 +857,157 @@
592857 return true;
593858 }
594859
860
+static void vega20_reset_hdp_ras_error_count(struct amdgpu_device *adev)
861
+{
862
+ if (!amdgpu_ras_is_supported(adev, AMDGPU_RAS_BLOCK__HDP))
863
+ return;
864
+ /*read back hdp ras counter to reset it to 0 */
865
+ RREG32_SOC15(HDP, 0, mmHDP_EDC_CNT);
866
+}
867
+
868
+static void soc15_get_pcie_usage(struct amdgpu_device *adev, uint64_t *count0,
869
+ uint64_t *count1)
870
+{
871
+ uint32_t perfctr = 0;
872
+ uint64_t cnt0_of, cnt1_of;
873
+ int tmp;
874
+
875
+ /* This reports 0 on APUs, so return to avoid writing/reading registers
876
+ * that may or may not be different from their GPU counterparts
877
+ */
878
+ if (adev->flags & AMD_IS_APU)
879
+ return;
880
+
881
+ /* Set the 2 events that we wish to watch, defined above */
882
+ /* Reg 40 is # received msgs */
883
+ /* Reg 104 is # of posted requests sent */
884
+ perfctr = REG_SET_FIELD(perfctr, PCIE_PERF_CNTL_TXCLK, EVENT0_SEL, 40);
885
+ perfctr = REG_SET_FIELD(perfctr, PCIE_PERF_CNTL_TXCLK, EVENT1_SEL, 104);
886
+
887
+ /* Write to enable desired perf counters */
888
+ WREG32_PCIE(smnPCIE_PERF_CNTL_TXCLK, perfctr);
889
+ /* Zero out and enable the perf counters
890
+ * Write 0x5:
891
+ * Bit 0 = Start all counters(1)
892
+ * Bit 2 = Global counter reset enable(1)
893
+ */
894
+ WREG32_PCIE(smnPCIE_PERF_COUNT_CNTL, 0x00000005);
895
+
896
+ msleep(1000);
897
+
898
+ /* Load the shadow and disable the perf counters
899
+ * Write 0x2:
900
+ * Bit 0 = Stop counters(0)
901
+ * Bit 1 = Load the shadow counters(1)
902
+ */
903
+ WREG32_PCIE(smnPCIE_PERF_COUNT_CNTL, 0x00000002);
904
+
905
+ /* Read register values to get any >32bit overflow */
906
+ tmp = RREG32_PCIE(smnPCIE_PERF_CNTL_TXCLK);
907
+ cnt0_of = REG_GET_FIELD(tmp, PCIE_PERF_CNTL_TXCLK, COUNTER0_UPPER);
908
+ cnt1_of = REG_GET_FIELD(tmp, PCIE_PERF_CNTL_TXCLK, COUNTER1_UPPER);
909
+
910
+ /* Get the values and add the overflow */
911
+ *count0 = RREG32_PCIE(smnPCIE_PERF_COUNT0_TXCLK) | (cnt0_of << 32);
912
+ *count1 = RREG32_PCIE(smnPCIE_PERF_COUNT1_TXCLK) | (cnt1_of << 32);
913
+}
914
+
915
+static void vega20_get_pcie_usage(struct amdgpu_device *adev, uint64_t *count0,
916
+ uint64_t *count1)
917
+{
918
+ uint32_t perfctr = 0;
919
+ uint64_t cnt0_of, cnt1_of;
920
+ int tmp;
921
+
922
+ /* This reports 0 on APUs, so return to avoid writing/reading registers
923
+ * that may or may not be different from their GPU counterparts
924
+ */
925
+ if (adev->flags & AMD_IS_APU)
926
+ return;
927
+
928
+ /* Set the 2 events that we wish to watch, defined above */
929
+ /* Reg 40 is # received msgs */
930
+ /* Reg 108 is # of posted requests sent on VG20 */
931
+ perfctr = REG_SET_FIELD(perfctr, PCIE_PERF_CNTL_TXCLK3,
932
+ EVENT0_SEL, 40);
933
+ perfctr = REG_SET_FIELD(perfctr, PCIE_PERF_CNTL_TXCLK3,
934
+ EVENT1_SEL, 108);
935
+
936
+ /* Write to enable desired perf counters */
937
+ WREG32_PCIE(smnPCIE_PERF_CNTL_TXCLK3, perfctr);
938
+ /* Zero out and enable the perf counters
939
+ * Write 0x5:
940
+ * Bit 0 = Start all counters(1)
941
+ * Bit 2 = Global counter reset enable(1)
942
+ */
943
+ WREG32_PCIE(smnPCIE_PERF_COUNT_CNTL, 0x00000005);
944
+
945
+ msleep(1000);
946
+
947
+ /* Load the shadow and disable the perf counters
948
+ * Write 0x2:
949
+ * Bit 0 = Stop counters(0)
950
+ * Bit 1 = Load the shadow counters(1)
951
+ */
952
+ WREG32_PCIE(smnPCIE_PERF_COUNT_CNTL, 0x00000002);
953
+
954
+ /* Read register values to get any >32bit overflow */
955
+ tmp = RREG32_PCIE(smnPCIE_PERF_CNTL_TXCLK3);
956
+ cnt0_of = REG_GET_FIELD(tmp, PCIE_PERF_CNTL_TXCLK3, COUNTER0_UPPER);
957
+ cnt1_of = REG_GET_FIELD(tmp, PCIE_PERF_CNTL_TXCLK3, COUNTER1_UPPER);
958
+
959
+ /* Get the values and add the overflow */
960
+ *count0 = RREG32_PCIE(smnPCIE_PERF_COUNT0_TXCLK3) | (cnt0_of << 32);
961
+ *count1 = RREG32_PCIE(smnPCIE_PERF_COUNT1_TXCLK3) | (cnt1_of << 32);
962
+}
963
+
964
+static bool soc15_need_reset_on_init(struct amdgpu_device *adev)
965
+{
966
+ u32 sol_reg;
967
+
968
+ /* Just return false for soc15 GPUs. Reset does not seem to
969
+ * be necessary.
970
+ */
971
+ if (!amdgpu_passthrough(adev))
972
+ return false;
973
+
974
+ if (adev->flags & AMD_IS_APU)
975
+ return false;
976
+
977
+ /* Check sOS sign of life register to confirm sys driver and sOS
978
+ * are already been loaded.
979
+ */
980
+ sol_reg = RREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_81);
981
+ if (sol_reg)
982
+ return true;
983
+
984
+ return false;
985
+}
986
+
987
+static uint64_t soc15_get_pcie_replay_count(struct amdgpu_device *adev)
988
+{
989
+ uint64_t nak_r, nak_g;
990
+
991
+ /* Get the number of NAKs received and generated */
992
+ nak_r = RREG32_PCIE(smnPCIE_RX_NUM_NAK);
993
+ nak_g = RREG32_PCIE(smnPCIE_RX_NUM_NAK_GENERATED);
994
+
995
+ /* Add the total number of NAKs, i.e the number of replays */
996
+ return (nak_r + nak_g);
997
+}
998
+
999
+static void soc15_pre_asic_init(struct amdgpu_device *adev)
1000
+{
1001
+ gmc_v9_0_restore_registers(adev);
1002
+}
1003
+
5951004 static const struct amdgpu_asic_funcs soc15_asic_funcs =
5961005 {
5971006 .read_disabled_bios = &soc15_read_disabled_bios,
5981007 .read_bios_from_rom = &soc15_read_bios_from_rom,
5991008 .read_register = &soc15_read_register,
6001009 .reset = &soc15_asic_reset,
1010
+ .reset_method = &soc15_asic_reset_method,
6011011 .set_vga_state = &soc15_vga_set_state,
6021012 .get_xclk = &soc15_get_xclk,
6031013 .set_uvd_clocks = &soc15_set_uvd_clocks,
....@@ -606,16 +1016,51 @@
6061016 .flush_hdp = &soc15_flush_hdp,
6071017 .invalidate_hdp = &soc15_invalidate_hdp,
6081018 .need_full_reset = &soc15_need_full_reset,
1019
+ .init_doorbell_index = &vega10_doorbell_index_init,
1020
+ .get_pcie_usage = &soc15_get_pcie_usage,
1021
+ .need_reset_on_init = &soc15_need_reset_on_init,
1022
+ .get_pcie_replay_count = &soc15_get_pcie_replay_count,
1023
+ .supports_baco = &soc15_supports_baco,
1024
+ .pre_asic_init = &soc15_pre_asic_init,
1025
+};
1026
+
1027
+static const struct amdgpu_asic_funcs vega20_asic_funcs =
1028
+{
1029
+ .read_disabled_bios = &soc15_read_disabled_bios,
1030
+ .read_bios_from_rom = &soc15_read_bios_from_rom,
1031
+ .read_register = &soc15_read_register,
1032
+ .reset = &soc15_asic_reset,
1033
+ .reset_method = &soc15_asic_reset_method,
1034
+ .set_vga_state = &soc15_vga_set_state,
1035
+ .get_xclk = &soc15_get_xclk,
1036
+ .set_uvd_clocks = &soc15_set_uvd_clocks,
1037
+ .set_vce_clocks = &soc15_set_vce_clocks,
1038
+ .get_config_memsize = &soc15_get_config_memsize,
1039
+ .flush_hdp = &soc15_flush_hdp,
1040
+ .invalidate_hdp = &soc15_invalidate_hdp,
1041
+ .reset_hdp_ras_error_count = &vega20_reset_hdp_ras_error_count,
1042
+ .need_full_reset = &soc15_need_full_reset,
1043
+ .init_doorbell_index = &vega20_doorbell_index_init,
1044
+ .get_pcie_usage = &vega20_get_pcie_usage,
1045
+ .need_reset_on_init = &soc15_need_reset_on_init,
1046
+ .get_pcie_replay_count = &soc15_get_pcie_replay_count,
1047
+ .supports_baco = &soc15_supports_baco,
1048
+ .pre_asic_init = &soc15_pre_asic_init,
6091049 };
6101050
6111051 static int soc15_common_early_init(void *handle)
6121052 {
1053
+#define MMIO_REG_HOLE_OFFSET (0x80000 - PAGE_SIZE)
6131054 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
6141055
1056
+ adev->rmmio_remap.reg_offset = MMIO_REG_HOLE_OFFSET;
1057
+ adev->rmmio_remap.bus_addr = adev->rmmio_base + MMIO_REG_HOLE_OFFSET;
6151058 adev->smc_rreg = NULL;
6161059 adev->smc_wreg = NULL;
6171060 adev->pcie_rreg = &soc15_pcie_rreg;
6181061 adev->pcie_wreg = &soc15_pcie_wreg;
1062
+ adev->pcie_rreg64 = &soc15_pcie_rreg64;
1063
+ adev->pcie_wreg64 = &soc15_pcie_wreg64;
6191064 adev->uvd_ctx_rreg = &soc15_uvd_ctx_rreg;
6201065 adev->uvd_ctx_wreg = &soc15_uvd_ctx_wreg;
6211066 adev->didt_rreg = &soc15_didt_rreg;
....@@ -625,12 +1070,11 @@
6251070 adev->se_cac_rreg = &soc15_se_cac_rreg;
6261071 adev->se_cac_wreg = &soc15_se_cac_wreg;
6271072
628
- adev->asic_funcs = &soc15_asic_funcs;
6291073
630
- adev->rev_id = soc15_get_rev_id(adev);
6311074 adev->external_rev_id = 0xFF;
6321075 switch (adev->asic_type) {
6331076 case CHIP_VEGA10:
1077
+ adev->asic_funcs = &soc15_asic_funcs;
6341078 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
6351079 AMD_CG_SUPPORT_GFX_MGLS |
6361080 AMD_CG_SUPPORT_GFX_RLC_LS |
....@@ -654,6 +1098,7 @@
6541098 adev->external_rev_id = 0x1;
6551099 break;
6561100 case CHIP_VEGA12:
1101
+ adev->asic_funcs = &soc15_asic_funcs;
6571102 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
6581103 AMD_CG_SUPPORT_GFX_MGLS |
6591104 AMD_CG_SUPPORT_GFX_CGCG |
....@@ -676,6 +1121,7 @@
6761121 adev->external_rev_id = adev->rev_id + 0x14;
6771122 break;
6781123 case CHIP_VEGA20:
1124
+ adev->asic_funcs = &vega20_asic_funcs;
6791125 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
6801126 AMD_CG_SUPPORT_GFX_MGLS |
6811127 AMD_CG_SUPPORT_GFX_CGCG |
....@@ -698,35 +1144,141 @@
6981144 adev->external_rev_id = adev->rev_id + 0x28;
6991145 break;
7001146 case CHIP_RAVEN:
1147
+ adev->asic_funcs = &soc15_asic_funcs;
1148
+ if (adev->pdev->device == 0x15dd)
1149
+ adev->apu_flags |= AMD_APU_IS_RAVEN;
1150
+ if (adev->pdev->device == 0x15d8)
1151
+ adev->apu_flags |= AMD_APU_IS_PICASSO;
1152
+ if (adev->rev_id >= 0x8)
1153
+ adev->apu_flags |= AMD_APU_IS_RAVEN2;
1154
+
1155
+ if (adev->apu_flags & AMD_APU_IS_RAVEN2)
1156
+ adev->external_rev_id = adev->rev_id + 0x79;
1157
+ else if (adev->apu_flags & AMD_APU_IS_PICASSO)
1158
+ adev->external_rev_id = adev->rev_id + 0x41;
1159
+ else if (adev->rev_id == 1)
1160
+ adev->external_rev_id = adev->rev_id + 0x20;
1161
+ else
1162
+ adev->external_rev_id = adev->rev_id + 0x01;
1163
+
1164
+ if (adev->apu_flags & AMD_APU_IS_RAVEN2) {
1165
+ adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1166
+ AMD_CG_SUPPORT_GFX_MGLS |
1167
+ AMD_CG_SUPPORT_GFX_CP_LS |
1168
+ AMD_CG_SUPPORT_GFX_3D_CGCG |
1169
+ AMD_CG_SUPPORT_GFX_3D_CGLS |
1170
+ AMD_CG_SUPPORT_GFX_CGCG |
1171
+ AMD_CG_SUPPORT_GFX_CGLS |
1172
+ AMD_CG_SUPPORT_BIF_LS |
1173
+ AMD_CG_SUPPORT_HDP_LS |
1174
+ AMD_CG_SUPPORT_ROM_MGCG |
1175
+ AMD_CG_SUPPORT_MC_MGCG |
1176
+ AMD_CG_SUPPORT_MC_LS |
1177
+ AMD_CG_SUPPORT_SDMA_MGCG |
1178
+ AMD_CG_SUPPORT_SDMA_LS |
1179
+ AMD_CG_SUPPORT_VCN_MGCG;
1180
+
1181
+ adev->pg_flags = AMD_PG_SUPPORT_SDMA | AMD_PG_SUPPORT_VCN;
1182
+ } else if (adev->apu_flags & AMD_APU_IS_PICASSO) {
1183
+ adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1184
+ AMD_CG_SUPPORT_GFX_MGLS |
1185
+ AMD_CG_SUPPORT_GFX_CP_LS |
1186
+ AMD_CG_SUPPORT_GFX_3D_CGLS |
1187
+ AMD_CG_SUPPORT_GFX_CGCG |
1188
+ AMD_CG_SUPPORT_GFX_CGLS |
1189
+ AMD_CG_SUPPORT_BIF_LS |
1190
+ AMD_CG_SUPPORT_HDP_LS |
1191
+ AMD_CG_SUPPORT_ROM_MGCG |
1192
+ AMD_CG_SUPPORT_MC_MGCG |
1193
+ AMD_CG_SUPPORT_MC_LS |
1194
+ AMD_CG_SUPPORT_SDMA_MGCG |
1195
+ AMD_CG_SUPPORT_SDMA_LS;
1196
+
1197
+ /*
1198
+ * MMHUB PG needs to be disabled for Picasso for
1199
+ * stability reasons.
1200
+ */
1201
+ adev->pg_flags = AMD_PG_SUPPORT_SDMA |
1202
+ AMD_PG_SUPPORT_VCN;
1203
+ } else {
1204
+ adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1205
+ AMD_CG_SUPPORT_GFX_MGLS |
1206
+ AMD_CG_SUPPORT_GFX_RLC_LS |
1207
+ AMD_CG_SUPPORT_GFX_CP_LS |
1208
+ AMD_CG_SUPPORT_GFX_3D_CGLS |
1209
+ AMD_CG_SUPPORT_GFX_CGCG |
1210
+ AMD_CG_SUPPORT_GFX_CGLS |
1211
+ AMD_CG_SUPPORT_BIF_MGCG |
1212
+ AMD_CG_SUPPORT_BIF_LS |
1213
+ AMD_CG_SUPPORT_HDP_MGCG |
1214
+ AMD_CG_SUPPORT_HDP_LS |
1215
+ AMD_CG_SUPPORT_DRM_MGCG |
1216
+ AMD_CG_SUPPORT_DRM_LS |
1217
+ AMD_CG_SUPPORT_ROM_MGCG |
1218
+ AMD_CG_SUPPORT_MC_MGCG |
1219
+ AMD_CG_SUPPORT_MC_LS |
1220
+ AMD_CG_SUPPORT_SDMA_MGCG |
1221
+ AMD_CG_SUPPORT_SDMA_LS |
1222
+ AMD_CG_SUPPORT_VCN_MGCG;
1223
+
1224
+ adev->pg_flags = AMD_PG_SUPPORT_SDMA | AMD_PG_SUPPORT_VCN;
1225
+ }
1226
+ break;
1227
+ case CHIP_ARCTURUS:
1228
+ adev->asic_funcs = &vega20_asic_funcs;
7011229 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
7021230 AMD_CG_SUPPORT_GFX_MGLS |
703
- AMD_CG_SUPPORT_GFX_RLC_LS |
704
- AMD_CG_SUPPORT_GFX_CP_LS |
705
- AMD_CG_SUPPORT_GFX_3D_CGCG |
706
- AMD_CG_SUPPORT_GFX_3D_CGLS |
7071231 AMD_CG_SUPPORT_GFX_CGCG |
7081232 AMD_CG_SUPPORT_GFX_CGLS |
709
- AMD_CG_SUPPORT_BIF_MGCG |
710
- AMD_CG_SUPPORT_BIF_LS |
1233
+ AMD_CG_SUPPORT_GFX_CP_LS |
7111234 AMD_CG_SUPPORT_HDP_MGCG |
7121235 AMD_CG_SUPPORT_HDP_LS |
713
- AMD_CG_SUPPORT_DRM_MGCG |
714
- AMD_CG_SUPPORT_DRM_LS |
715
- AMD_CG_SUPPORT_ROM_MGCG |
716
- AMD_CG_SUPPORT_MC_MGCG |
717
- AMD_CG_SUPPORT_MC_LS |
7181236 AMD_CG_SUPPORT_SDMA_MGCG |
7191237 AMD_CG_SUPPORT_SDMA_LS |
720
- AMD_CG_SUPPORT_VCN_MGCG;
1238
+ AMD_CG_SUPPORT_MC_MGCG |
1239
+ AMD_CG_SUPPORT_MC_LS |
1240
+ AMD_CG_SUPPORT_IH_CG |
1241
+ AMD_CG_SUPPORT_VCN_MGCG |
1242
+ AMD_CG_SUPPORT_JPEG_MGCG;
1243
+ adev->pg_flags = AMD_PG_SUPPORT_VCN | AMD_PG_SUPPORT_VCN_DPG;
1244
+ adev->external_rev_id = adev->rev_id + 0x32;
1245
+ break;
1246
+ case CHIP_RENOIR:
1247
+ adev->asic_funcs = &soc15_asic_funcs;
1248
+ if ((adev->pdev->device == 0x1636) ||
1249
+ (adev->pdev->device == 0x164c))
1250
+ adev->apu_flags |= AMD_APU_IS_RENOIR;
1251
+ else
1252
+ adev->apu_flags |= AMD_APU_IS_GREEN_SARDINE;
7211253
722
- adev->pg_flags = AMD_PG_SUPPORT_SDMA | AMD_PG_SUPPORT_VCN;
723
-
724
- if (adev->powerplay.pp_feature & PP_GFXOFF_MASK)
725
- adev->pg_flags |= AMD_PG_SUPPORT_GFX_PG |
726
- AMD_PG_SUPPORT_CP |
727
- AMD_PG_SUPPORT_RLC_SMU_HS;
728
-
729
- adev->external_rev_id = 0x1;
1254
+ if (adev->apu_flags & AMD_APU_IS_RENOIR)
1255
+ adev->external_rev_id = adev->rev_id + 0x91;
1256
+ else
1257
+ adev->external_rev_id = adev->rev_id + 0xa1;
1258
+ adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1259
+ AMD_CG_SUPPORT_GFX_MGLS |
1260
+ AMD_CG_SUPPORT_GFX_3D_CGCG |
1261
+ AMD_CG_SUPPORT_GFX_3D_CGLS |
1262
+ AMD_CG_SUPPORT_GFX_CGCG |
1263
+ AMD_CG_SUPPORT_GFX_CGLS |
1264
+ AMD_CG_SUPPORT_GFX_CP_LS |
1265
+ AMD_CG_SUPPORT_MC_MGCG |
1266
+ AMD_CG_SUPPORT_MC_LS |
1267
+ AMD_CG_SUPPORT_SDMA_MGCG |
1268
+ AMD_CG_SUPPORT_SDMA_LS |
1269
+ AMD_CG_SUPPORT_BIF_LS |
1270
+ AMD_CG_SUPPORT_HDP_LS |
1271
+ AMD_CG_SUPPORT_ROM_MGCG |
1272
+ AMD_CG_SUPPORT_VCN_MGCG |
1273
+ AMD_CG_SUPPORT_JPEG_MGCG |
1274
+ AMD_CG_SUPPORT_IH_CG |
1275
+ AMD_CG_SUPPORT_ATHUB_LS |
1276
+ AMD_CG_SUPPORT_ATHUB_MGCG |
1277
+ AMD_CG_SUPPORT_DF_MGCG;
1278
+ adev->pg_flags = AMD_PG_SUPPORT_SDMA |
1279
+ AMD_PG_SUPPORT_VCN |
1280
+ AMD_PG_SUPPORT_JPEG |
1281
+ AMD_PG_SUPPORT_VCN_DPG;
7301282 break;
7311283 default:
7321284 /* FIXME: not supported yet */
....@@ -744,11 +1296,19 @@
7441296 static int soc15_common_late_init(void *handle)
7451297 {
7461298 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1299
+ int r = 0;
7471300
7481301 if (amdgpu_sriov_vf(adev))
7491302 xgpu_ai_mailbox_get_irq(adev);
7501303
751
- return 0;
1304
+ if (adev->asic_funcs &&
1305
+ adev->asic_funcs->reset_hdp_ras_error_count)
1306
+ adev->asic_funcs->reset_hdp_ras_error_count(adev);
1307
+
1308
+ if (adev->nbio.funcs->ras_late_init)
1309
+ r = adev->nbio.funcs->ras_late_init(adev);
1310
+
1311
+ return r;
7521312 }
7531313
7541314 static int soc15_common_sw_init(void *handle)
....@@ -758,12 +1318,37 @@
7581318 if (amdgpu_sriov_vf(adev))
7591319 xgpu_ai_mailbox_add_irq_id(adev);
7601320
1321
+ adev->df.funcs->sw_init(adev);
1322
+
7611323 return 0;
7621324 }
7631325
7641326 static int soc15_common_sw_fini(void *handle)
7651327 {
1328
+ struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1329
+
1330
+ amdgpu_nbio_ras_fini(adev);
1331
+ adev->df.funcs->sw_fini(adev);
7661332 return 0;
1333
+}
1334
+
1335
+static void soc15_doorbell_range_init(struct amdgpu_device *adev)
1336
+{
1337
+ int i;
1338
+ struct amdgpu_ring *ring;
1339
+
1340
+ /* sdma/ih doorbell range are programed by hypervisor */
1341
+ if (!amdgpu_sriov_vf(adev)) {
1342
+ for (i = 0; i < adev->sdma.num_instances; i++) {
1343
+ ring = &adev->sdma.instance[i].ring;
1344
+ adev->nbio.funcs->sdma_doorbell_range(adev, i,
1345
+ ring->use_doorbell, ring->doorbell_index,
1346
+ adev->doorbell_index.sdma_doorbell_range);
1347
+ }
1348
+
1349
+ adev->nbio.funcs->ih_doorbell_range(adev, adev->irq.ih.use_doorbell,
1350
+ adev->irq.ih.doorbell_index);
1351
+ }
7671352 }
7681353
7691354 static int soc15_common_hw_init(void *handle)
....@@ -775,9 +1360,22 @@
7751360 /* enable aspm */
7761361 soc15_program_aspm(adev);
7771362 /* setup nbio registers */
778
- adev->nbio_funcs->init_registers(adev);
1363
+ adev->nbio.funcs->init_registers(adev);
1364
+ /* remap HDP registers to a hole in mmio space,
1365
+ * for the purpose of expose those registers
1366
+ * to process space
1367
+ */
1368
+ if (adev->nbio.funcs->remap_hdp_registers)
1369
+ adev->nbio.funcs->remap_hdp_registers(adev);
1370
+
7791371 /* enable the doorbell aperture */
7801372 soc15_enable_doorbell_aperture(adev, true);
1373
+ /* HW doorbell routing policy: doorbell writing not
1374
+ * in SDMA/IH/MM/ACV range will be routed to CP. So
1375
+ * we need to init SDMA/IH/MM/ACV doorbell range prior
1376
+ * to CP ip block init and ring test.
1377
+ */
1378
+ soc15_doorbell_range_init(adev);
7811379
7821380 return 0;
7831381 }
....@@ -790,6 +1388,14 @@
7901388 soc15_enable_doorbell_aperture(adev, false);
7911389 if (amdgpu_sriov_vf(adev))
7921390 xgpu_ai_mailbox_put_irq(adev);
1391
+
1392
+ if (adev->nbio.ras_if &&
1393
+ amdgpu_ras_is_supported(adev, adev->nbio.ras_if->block)) {
1394
+ if (adev->nbio.funcs->init_ras_controller_interrupt)
1395
+ amdgpu_irq_put(adev, &adev->nbio.ras_controller_irq, 0);
1396
+ if (adev->nbio.funcs->init_ras_err_event_athub_interrupt)
1397
+ amdgpu_irq_put(adev, &adev->nbio.ras_err_event_athub_irq, 0);
1398
+ }
7931399
7941400 return 0;
7951401 }
....@@ -827,15 +1433,35 @@
8271433 {
8281434 uint32_t def, data;
8291435
830
- def = data = RREG32(SOC15_REG_OFFSET(HDP, 0, mmHDP_MEM_POWER_LS));
1436
+ if (adev->asic_type == CHIP_VEGA20 ||
1437
+ adev->asic_type == CHIP_ARCTURUS ||
1438
+ adev->asic_type == CHIP_RENOIR) {
1439
+ def = data = RREG32(SOC15_REG_OFFSET(HDP, 0, mmHDP_MEM_POWER_CTRL));
8311440
832
- if (enable && (adev->cg_flags & AMD_CG_SUPPORT_HDP_LS))
833
- data |= HDP_MEM_POWER_LS__LS_ENABLE_MASK;
834
- else
835
- data &= ~HDP_MEM_POWER_LS__LS_ENABLE_MASK;
1441
+ if (enable && (adev->cg_flags & AMD_CG_SUPPORT_HDP_LS))
1442
+ data |= HDP_MEM_POWER_CTRL__IPH_MEM_POWER_CTRL_EN_MASK |
1443
+ HDP_MEM_POWER_CTRL__IPH_MEM_POWER_LS_EN_MASK |
1444
+ HDP_MEM_POWER_CTRL__RC_MEM_POWER_CTRL_EN_MASK |
1445
+ HDP_MEM_POWER_CTRL__RC_MEM_POWER_LS_EN_MASK;
1446
+ else
1447
+ data &= ~(HDP_MEM_POWER_CTRL__IPH_MEM_POWER_CTRL_EN_MASK |
1448
+ HDP_MEM_POWER_CTRL__IPH_MEM_POWER_LS_EN_MASK |
1449
+ HDP_MEM_POWER_CTRL__RC_MEM_POWER_CTRL_EN_MASK |
1450
+ HDP_MEM_POWER_CTRL__RC_MEM_POWER_LS_EN_MASK);
8361451
837
- if (def != data)
838
- WREG32(SOC15_REG_OFFSET(HDP, 0, mmHDP_MEM_POWER_LS), data);
1452
+ if (def != data)
1453
+ WREG32(SOC15_REG_OFFSET(HDP, 0, mmHDP_MEM_POWER_CTRL), data);
1454
+ } else {
1455
+ def = data = RREG32(SOC15_REG_OFFSET(HDP, 0, mmHDP_MEM_POWER_LS));
1456
+
1457
+ if (enable && (adev->cg_flags & AMD_CG_SUPPORT_HDP_LS))
1458
+ data |= HDP_MEM_POWER_LS__LS_ENABLE_MASK;
1459
+ else
1460
+ data &= ~HDP_MEM_POWER_LS__LS_ENABLE_MASK;
1461
+
1462
+ if (def != data)
1463
+ WREG32(SOC15_REG_OFFSET(HDP, 0, mmHDP_MEM_POWER_LS), data);
1464
+ }
8391465 }
8401466
8411467 static void soc15_update_drm_clock_gating(struct amdgpu_device *adev, bool enable)
....@@ -912,34 +1538,39 @@
9121538 case CHIP_VEGA10:
9131539 case CHIP_VEGA12:
9141540 case CHIP_VEGA20:
915
- adev->nbio_funcs->update_medium_grain_clock_gating(adev,
916
- state == AMD_CG_STATE_GATE ? true : false);
917
- adev->nbio_funcs->update_medium_grain_light_sleep(adev,
918
- state == AMD_CG_STATE_GATE ? true : false);
1541
+ adev->nbio.funcs->update_medium_grain_clock_gating(adev,
1542
+ state == AMD_CG_STATE_GATE);
1543
+ adev->nbio.funcs->update_medium_grain_light_sleep(adev,
1544
+ state == AMD_CG_STATE_GATE);
9191545 soc15_update_hdp_light_sleep(adev,
920
- state == AMD_CG_STATE_GATE ? true : false);
1546
+ state == AMD_CG_STATE_GATE);
9211547 soc15_update_drm_clock_gating(adev,
922
- state == AMD_CG_STATE_GATE ? true : false);
1548
+ state == AMD_CG_STATE_GATE);
9231549 soc15_update_drm_light_sleep(adev,
924
- state == AMD_CG_STATE_GATE ? true : false);
1550
+ state == AMD_CG_STATE_GATE);
9251551 soc15_update_rom_medium_grain_clock_gating(adev,
926
- state == AMD_CG_STATE_GATE ? true : false);
927
- adev->df_funcs->update_medium_grain_clock_gating(adev,
928
- state == AMD_CG_STATE_GATE ? true : false);
1552
+ state == AMD_CG_STATE_GATE);
1553
+ adev->df.funcs->update_medium_grain_clock_gating(adev,
1554
+ state == AMD_CG_STATE_GATE);
9291555 break;
9301556 case CHIP_RAVEN:
931
- adev->nbio_funcs->update_medium_grain_clock_gating(adev,
932
- state == AMD_CG_STATE_GATE ? true : false);
933
- adev->nbio_funcs->update_medium_grain_light_sleep(adev,
934
- state == AMD_CG_STATE_GATE ? true : false);
1557
+ case CHIP_RENOIR:
1558
+ adev->nbio.funcs->update_medium_grain_clock_gating(adev,
1559
+ state == AMD_CG_STATE_GATE);
1560
+ adev->nbio.funcs->update_medium_grain_light_sleep(adev,
1561
+ state == AMD_CG_STATE_GATE);
9351562 soc15_update_hdp_light_sleep(adev,
936
- state == AMD_CG_STATE_GATE ? true : false);
1563
+ state == AMD_CG_STATE_GATE);
9371564 soc15_update_drm_clock_gating(adev,
938
- state == AMD_CG_STATE_GATE ? true : false);
1565
+ state == AMD_CG_STATE_GATE);
9391566 soc15_update_drm_light_sleep(adev,
940
- state == AMD_CG_STATE_GATE ? true : false);
1567
+ state == AMD_CG_STATE_GATE);
9411568 soc15_update_rom_medium_grain_clock_gating(adev,
942
- state == AMD_CG_STATE_GATE ? true : false);
1569
+ state == AMD_CG_STATE_GATE);
1570
+ break;
1571
+ case CHIP_ARCTURUS:
1572
+ soc15_update_hdp_light_sleep(adev,
1573
+ state == AMD_CG_STATE_GATE);
9431574 break;
9441575 default:
9451576 break;
....@@ -955,7 +1586,7 @@
9551586 if (amdgpu_sriov_vf(adev))
9561587 *flags = 0;
9571588
958
- adev->nbio_funcs->get_clockgating_state(adev, flags);
1589
+ adev->nbio.funcs->get_clockgating_state(adev, flags);
9591590
9601591 /* AMD_CG_SUPPORT_HDP_LS */
9611592 data = RREG32(SOC15_REG_OFFSET(HDP, 0, mmHDP_MEM_POWER_LS));
....@@ -977,7 +1608,7 @@
9771608 if (!(data & CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK))
9781609 *flags |= AMD_CG_SUPPORT_ROM_MGCG;
9791610
980
- adev->df_funcs->get_clockgating_state(adev, flags);
1611
+ adev->df.funcs->get_clockgating_state(adev, flags);
9811612 }
9821613
9831614 static int soc15_common_set_powergating_state(void *handle,